/*! * Напечатать результируюющее дерево на XML-файл * \param[in] filename - название выходного файла * \param[in] root - указатель на корень результирующего дерева */ void printResult(QString filename, node* root){ // 1. Открыть XML файл с именем filename с режимом записи. QFile output(filename); output.open(QIODevice::WriteOnly); // 2. Создать поток stream для записи на XML file QXmlStreamWriter xmlStream(&output); xmlStream.setAutoFormatting(true); // <?xml> xmlStream.writeStartDocument(); // <test> xmlStream.writeStartElement("test"); // 3. Напечатать размер максимального общего поддерева двух входных деревьев между парой тегов <result> и </result> xmlStream.writeStartElement("result"); xmlStream.writeCharacters(root == NULL ? "0" : QString::number(root->size())); xmlStream.writeEndElement(); // <tree> xmlStream.writeStartElement("tree"); // 4. Вызвать функцию printNode с аргументами stream и root, чтобы напечатать каждую вершину общего поддерева printNode(xmlStream, root); xmlStream.writeEndElement(); xmlStream.writeEndDocument(); }
void Plotter::saveSettings() { QFile xmlFile("setting.xml"); if(!xmlFile.open(QIODevice::WriteOnly|QIODevice::Text)) { qDebug() << "unable to open"; return; } QDomDocument document; QDomElement d = document.createElement("document"); d.setAttribute("name" , "ColorSetting"); QDomElement color[15]; color[0] = document.createElement("backgroundcolor"); color[0].setAttribute("value",backgroundColor.name()); color[1] = document.createElement("textcolor"); color[1].setAttribute("value",textColor.name()); color[2] = document.createElement("gridcolor"); color[2].setAttribute("value",gridColor.name()); document.appendChild(d); d.appendChild(color[0]); d.appendChild(color[1]); d.appendChild(color[2]); for(int i=3;i<15;i++) { color[i] = document.createElement("color"+QString::number(i-3)); color[i].setAttribute("value",colorMap.value(i-3).name()); d.appendChild(color[i]); } QTextStream xmlStream(&xmlFile); xmlStream <<document.toString(); xmlFile.close(); }
bool QXmppStream::sendPacket(const QXmppStanza &packet) { // prepare packet QByteArray data; QXmlStreamWriter xmlStream(&data); packet.toXml(&xmlStream); // send packet return sendData(data); }
void mitk::InteractionTestHelper::LoadInteraction() { //load interaction pattern from xml file std::ifstream xmlStream(m_InteractionFilePath.c_str()); mitk::XML2EventParser parser(xmlStream); m_Events = parser.GetInteractions(); xmlStream.close(); // Avoid VTK warning: Trying to delete object with non-zero reference count. parser.SetReferenceCount(0); }
QString saxedText(StoryText* story) { std::ostringstream xmlString; SaxXML xmlStream(xmlString); xmlStream.beginDoc(); story->saxx(xmlStream, "SCRIBUSTEXT"); xmlStream.endDoc(); std::string xml(xmlString.str()); return QString(xml.c_str()); }
void QtSEnaMainWindow::apri() { QFile xmlFile(_apriFile->selectedFiles().at(0)); if(xmlFile.open(QIODevice::ReadOnly)) { QXmlStreamReader xmlStream(&xmlFile); while(!xmlStream.atEnd()) { xmlStream.readNext(); if(xmlStream.isStartElement() && xmlStream.name().toAscii() == "Elementi") { QStringList sElementi = QString(xmlStream.readElementText().toAscii()).split(QChar(',')); _grigliaNumeri->deselezionaTutti(); for (quint8 i = 0; i < sElementi.count(); i++) { _grigliaNumeri->selezionaValore(sElementi.at(i).toUShort() - 1); } } if(xmlStream.isStartElement() && xmlStream.name().toAscii() == "Somma") { ui->maxSum->setValue(xmlStream.attributes().value("max").toAscii().toInt()); ui->minSum->setValue(xmlStream.attributes().value("min").toAscii().toInt()); } if(xmlStream.isStartElement() && xmlStream.name().toAscii() == "Consecutivi") { QStringList sConsecutivi = QString(xmlStream.readElementText().toAscii()).split(QChar(',')); for (quint8 i = 0; i <= _NUMERO_ELEMENTI_COLONNA; i++) _consecutivi.at(i)->setChecked(false); for (quint8 i = 0; i < sConsecutivi.count(); i++) { _consecutivi.at(sConsecutivi.at(i).toUShort())->setChecked(true); } } if(xmlStream.isStartElement() && xmlStream.name().toAscii() == "Gemelli") { QStringList sGemelli = QString(xmlStream.readElementText().toAscii()).split(QChar(',')); for (quint8 i = 0; i <= _NUMERO_ELEMENTI_COLONNA; i++) _gemelli.at(i)->setChecked(false); for (quint8 i = 0; i < sGemelli.count(); i++) { _gemelli.at(sGemelli.at(i).toUShort())->setChecked(true); } } if(xmlStream.isStartElement() && xmlStream.name().toAscii() == "Pari") { QStringList sPari = QString(xmlStream.readElementText().toAscii()).split(QChar(',')); for (quint8 i = 0; i <= _NUMERO_ELEMENTI_COLONNA; i++) _pari.at(i)->setChecked(false); for (quint8 i = 0; i < sPari.count(); i++) { _pari.at(sPari.at(i).toUShort())->setChecked(true); } } } xmlFile.close(); #ifdef _DEBUG_FLAG_ENABLED if (xmlStream.hasError()){ qWarning() << "[QTSENAMAINWINDOW] - on_actionApri_triggered() - Errore: " << xmlStream.errorString(); } } else { qWarning() << "[QTSENAMAINWINDOW] - on_actionApri_triggered() - Impossibile leggere dal file " << _nomeFile; #endif //_DEBUG_FLAG_ENABLED } }
/// Sends an acknowledgement request as defined in XEP-0198. void QXmppStream::sendAcknowledgementRequest() { if (!d->streamManagementEnabled) return; // prepare packet QByteArray data; QXmlStreamWriter xmlStream(&data); QXmppStreamManagementReq::toXml(&xmlStream); // send packet sendData(data); }
/// Sends an acknowledgement as defined in XEP-0198. void QXmppStream::sendAcknowledgement() { if (!d->streamManagementEnabled) return; // prepare packet QByteArray data; QXmlStreamWriter xmlStream(&data); QXmppStreamManagementAck ack(d->lastIncomingSequenceNumber); ack.toXml(&xmlStream); // send packet sendData(data); }
void QtSEnaMainWindow::salva() { QFile xmlFile(_salvaFile->selectedFiles().at(0)); if(xmlFile.open(QIODevice::WriteOnly)) { QXmlStreamWriter xmlStream(&xmlFile); xmlStream.setAutoFormatting(true); xmlStream.writeStartDocument(); xmlStream.writeStartElement("Sistema"); QString sElementi = ""; for(quint8 i = 0; i < _grigliaNumeri->listaElementi().count(); i++) { sElementi.append(QString("%1,").arg(_grigliaNumeri->listaElementi().at(i))); } sElementi.chop(1); xmlStream.writeTextElement("Elementi", sElementi); xmlStream.writeStartElement("Condizionamento"); xmlStream.writeStartElement("Somma"); xmlStream.writeAttribute("max", QString("%1").arg(ui->maxSum->value())); xmlStream.writeAttribute("min", QString("%1").arg(ui->minSum->value())); xmlStream.writeEndElement(); // Somma QString sConsecutivi = ""; for (quint8 i = 0; i <= _NUMERO_ELEMENTI_COLONNA; i++) { if(_consecutivi.at(i)->isChecked()) sConsecutivi += QString("%1,").arg(i); } sConsecutivi.chop(1); xmlStream.writeTextElement("Consecutivi", sConsecutivi); QString sGemelli = ""; for (quint8 i = 0; i <= _NUMERO_ELEMENTI_COLONNA; i++) { if(_gemelli.at(i)->isChecked()) sGemelli += QString("%1,").arg(i); } sGemelli.chop(1); xmlStream.writeTextElement("Gemelli", sGemelli); QString sPari = ""; for (quint8 i = 0; i <= _NUMERO_ELEMENTI_COLONNA; i++) { if(_pari.at(i)->isChecked()) sPari += QString("%1,").arg(i); } sPari.chop(1); xmlStream.writeTextElement("Pari", sPari); xmlStream.writeEndElement(); // Condizionamento xmlStream.writeEndElement(); // Sistema xmlStream.writeEndDocument(); xmlFile.close(); #ifdef _DEBUG_FLAG_ENABLED } else { qWarning() << "[QTSENAMAINWINDOW] - on_actionSave_triggered() - Impossibile scrivere sul file " << _nomeFile; #endif //_DEBUG_FLAG_ENABLED } }
void InteractionEventRecorder::Play() { std::ifstream xmlStream(m_Controls.textFileName->text().toStdString().c_str()); mitk::XML2EventParser parser(xmlStream); mitk::XML2EventParser::EventContainerType events = parser.GetInteractions(); MITK_INFO << "parsed events"; for (int i=0; i < events.size(); ++i) { //this->GetRenderWindowPart()->GetQmitkRenderWindow("axial")->GetRenderer()->GetDispatcher()->ProcessEvent(events.at(i)); events.at(i)->GetSender()->GetDispatcher()->ProcessEvent(events.at(i)); } MITK_INFO << "DONE"; }
void D3MFImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) { D3MF::D3MFOpcPackage opcPackage(pIOHandler, pFile); std::unique_ptr<CIrrXML_IOStreamReader> xmlStream(new CIrrXML_IOStreamReader(opcPackage.RootStream())); std::unique_ptr<D3MF::XmlReader> xmlReader(irr::io::createIrrXMLReader(xmlStream.get())); D3MF::XmlSerializer xmlSerializer(xmlReader.get()); xmlSerializer.ImportXml(pScene); }
void OgreImporter::InternReadFile(const std::string &pFile, aiScene *pScene, Assimp::IOSystem *pIOHandler) { // Open source file IOStream *f = pIOHandler->Open(pFile, "rb"); if (!f) { throw DeadlyImportError("Failed to open file " + pFile); } // Binary .mesh import if (EndsWith(pFile, ".mesh", false)) { /// @note MemoryStreamReader takes ownership of f. MemoryStreamReader reader(f); // Import mesh boost::scoped_ptr<Mesh> mesh(OgreBinarySerializer::ImportMesh(&reader)); // Import skeleton OgreBinarySerializer::ImportSkeleton(pIOHandler, mesh.get()); // Import mesh referenced materials ReadMaterials(pFile, pIOHandler, pScene, mesh.get()); // Convert to Assimp mesh->ConvertToAssimpScene(pScene); } // XML .mesh.xml import else { /// @note XmlReader does not take ownership of f, hence the scoped ptr. boost::scoped_ptr<IOStream> scopedFile(f); boost::scoped_ptr<CIrrXML_IOStreamReader> xmlStream(new CIrrXML_IOStreamReader(scopedFile.get())); boost::scoped_ptr<XmlReader> reader(irr::io::createIrrXMLReader(xmlStream.get())); // Import mesh boost::scoped_ptr<MeshXml> mesh(OgreXmlSerializer::ImportMesh(reader.get())); // Import skeleton OgreXmlSerializer::ImportSkeleton(pIOHandler, mesh.get()); // Import mesh referenced materials ReadMaterials(pFile, pIOHandler, pScene, mesh.get()); // Convert to Assimp mesh->ConvertToAssimpScene(pScene); } }
bool QXmppStream::sendPacket(const QXmppStanza &packet) { // prepare packet QByteArray data; QXmlStreamWriter xmlStream(&data); packet.toXml(&xmlStream); bool isXmppStanza = packet.isXmppStanza(); if (isXmppStanza && d->streamManagementEnabled) d->unacknowledgedStanzas[++d->lastOutgoingSequenceNumber] = data; // send packet bool success = sendData(data); if (isXmppStanza) sendAcknowledgementRequest(); return success; }
FileFactory::FileError File_v2::save(QDataStream *stream) { *stream << (qint32)FileFactory::Version_1_2; stream->setVersion(QDataStream::Qt_4_7); if(!mInternalStitchSet) { mInternalStitchSet = new StitchSet(); mInternalStitchSet->isTemporary = true; mInternalStitchSet->stitchSetFileName = StitchLibrary::inst()->nextSetSaveFile(); StitchLibrary::inst()->addStitchSet(mInternalStitchSet); } else { mInternalStitchSet->clearStitches(); } //start xml save... QString *data = new QString(); QXmlStreamWriter xmlStream(data); xmlStream.setAutoFormatting(true); xmlStream.writeStartDocument(); xmlStream.writeStartElement("pattern"); //start pattern //TODO: dont need to set the version when saving into a binary file. xmlStream.writeAttribute("version", QString::number(FileFactory::Version_1_2)); //create the StitchSet then save the icons. saveCustomStitches(&xmlStream); mInternalStitchSet->saveIcons(stream); saveColors(&xmlStream); saveCharts(&xmlStream); xmlStream.writeEndElement(); xmlStream.writeEndDocument(); //put xml into binary file. *stream << data->toUtf8(); delete data; data = 0; return FileFactory::No_Error; }
FileFactory::FileError File_v1::load(QDataStream *stream) { mInternalStitchSet = new StitchSet(); mInternalStitchSet->isTemporary = true; mInternalStitchSet->stitchSetFileName = StitchLibrary::inst()->nextSetSaveFile(); QString dest = mInternalStitchSet->stitchSetFileName; QFileInfo info(dest); QDir(info.path()).mkpath(info.path() + "/" + info.baseName()); mInternalStitchSet->loadIcons(stream); QByteArray docData; *stream >> docData; QXmlStreamReader xmlStream(docData); if(xmlStream.hasError()) { qWarning() << "Error loading saved file: " << xmlStream.errorString(); return FileFactory::Err_GettingFileContents; } while (!xmlStream.atEnd() && !xmlStream.hasError()) { xmlStream.readNext(); if (xmlStream.isStartElement()) { QString name = xmlStream.name().toString(); if(name == "colors") { loadColors(&xmlStream); } else if(name == "chart") { loadChart(&xmlStream); } else if(name == "stitch_set") { mInternalStitchSet->loadXmlStitchSet(&xmlStream, true); } } } StitchLibrary::inst()->addStitchSet(mInternalStitchSet); return FileFactory::No_Error; }
void FeedValidator::TransformFeed(std::stringstream& xslStream, std::string& results) { std::stringstream result; xalanc_1_10::XalanTransformer trans; std::stringstream xmlStream(m_feedData); const xalanc_1_10::XSLTInputSource xmlIn(xmlStream); const xalanc_1_10::XSLTInputSource xslIn(xslStream); const xalanc_1_10::XSLTResultTarget xmlOut(result); int theResult = -1; theResult = trans.transform(xmlIn, xslIn, xmlOut); if (theResult != 0) { std::stringstream msg; msg << "An error occurred while applying XSLT transformation to feed: " << trans.getLastError(); throw feed_exception(msg.str()); } results = result.str(); }
TEST(loadXml, XmlReader) { std::stringstream xmlStream(SceneXml); Node root = Streamer::fromXml(xmlStream); CHECK_EQUAL("Scene", root.getName()); CHECK_EQUAL("800", root.getAttributes()["width"]); CHECK_EQUAL("600", root.getAttributes()["height"]); CHECK(root.getAttributes()["depth"].empty()); //Xml::AttributeMap attributes = root->getAttributes(); std::unordered_map<std::string, std::string> attributes = root.getAttributes(); CHECK(!attributes.empty()); CHECK_EQUAL(2, attributes.size()); CHECK_EQUAL("800", attributes["width"]); CHECK_EQUAL("600", attributes["height"]); //Xml::ElementList children = root->getChildElements(); std::vector<Node> children = root.getChildren(); CHECK(!children.empty()); CHECK_EQUAL(2, children.size()); Node layer0 = children[0]; CHECK_EQUAL("Layer", layer0.getName()); attributes = layer0.getAttributes(); CHECK(!attributes.empty()); CHECK_EQUAL(1, attributes.size()); CHECK_EQUAL("sky", attributes["alias"]); std::vector<Node> layerChildren = layer0.getChildren(); CHECK(!layerChildren.empty()); CHECK_EQUAL(2, layerChildren.size()); Node placedGraphic = layerChildren[0]; CHECK_EQUAL("PlacedGraphic", placedGraphic.getName()); attributes = placedGraphic.getAttributes(); CHECK(!attributes.empty()); CHECK_EQUAL(2, attributes.size()); CHECK_EQUAL("0", attributes["x"]); CHECK_EQUAL("0", attributes["y"]); }
void Imposition::changeDocFold() { if (isOK == true) { //create page if (foldIsBackSide->checkState() == Qt::Checked) targetDoc->createNewDocPages(2); else targetDoc->createNewDocPages(1); //copy layers for (int i = 1; i < srcDoc->layerCount(); i++) { targetDoc->addLayer(srcDoc->layerName(i)); } targetDoc->setCurrentPage(targetDoc->Pages->at(0)); Page* p = targetDoc->currentPage(); int firstPage = foldFrontPage->currentText().toInt() - 1; int lastPage = 0; if (foldFrontPage->currentIndex() < (foldFrontPage->count()-1)) { lastPage = foldFrontPage->itemText(foldFrontPage->currentIndex()+1).toInt() - 2; } else { lastPage = firstPage + srcDoc->currentPageLayout; } //make guides double allWidth = srcDoc->pageWidth * (srcDoc->currentPageLayout+1); double allHeight = srcDoc->pageHeight; double guide_x = (p->width() - allWidth)/2; //initial (left) guide p->guides.addVertical(guide_x, p->guides.Standard); for (int i = firstPage; i <= lastPage; i++) { guide_x += srcDoc->Pages->at(i)->width(); p->guides.addVertical(guide_x,p->guides.Standard); } double guide_y = (p->height() - allHeight)/2; p->guides.addHorizontal(guide_y, p->guides.Standard); guide_y += allHeight; p->guides.addHorizontal(guide_y, p->guides.Standard); //do the copying ScribusMainWindow* scMW = ScCore->primaryMainWindow(); scMW->view->requestMode(modeNormal); Selection* s = new Selection(scMW); //select items to copy for the first page for (int i = 0; i < srcDoc->Items->count(); i++) { if ( (srcDoc->OnPage(srcDoc->Items->at(i)) >= firstPage) && (srcDoc->OnPage(srcDoc->Items->at(i)) <= lastPage) ) s->addItem(srcDoc->Items->at(i),false); } if (s->count() > 0) { //move the selection to the clipboard std::ostringstream xmlString; SaxXML xmlStream(xmlString); Serializer::serializeObjects(*s, xmlStream); std::string xml(xmlString.str()); QByteArray ba(QByteArray(xml.c_str(), xml.length())); //paste Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba); targetDoc->moveGroup( p->guides.vertical(0, p->guides.Standard), p->guides.horizontal(0, p->guides.Standard), true, &pastedObjects ); } if (foldIsBackSide->checkState() != Qt::Checked) return; //do the second page s->clear(); firstPage = foldBackPage->currentText().toInt() - 1; if (foldBackPage->currentIndex() < (foldBackPage->count()-1)) { lastPage = foldBackPage->itemText(foldBackPage->currentIndex()+1).toInt() - 2; } else { lastPage = firstPage + srcDoc->currentPageLayout; } targetDoc->setCurrentPage(targetDoc->Pages->at(1)); p = targetDoc->currentPage(); guide_x = (p->width() - allWidth)/2; //initial (left) guide p->guides.addVertical(guide_x, p->guides.Standard); for (int i = firstPage; i <= lastPage; i++) { guide_x += srcDoc->Pages->at(i)->width(); p->guides.addVertical(guide_x,p->guides.Standard); } guide_y = (p->height() - allHeight)/2; p->guides.addHorizontal(guide_y, p->guides.Standard); guide_y += allHeight; p->guides.addHorizontal(guide_y, p->guides.Standard); for (int i = 0; i < srcDoc->Items->count(); i++) { if ( (srcDoc->OnPage(srcDoc->Items->at(i)) >= firstPage) && (srcDoc->OnPage(srcDoc->Items->at(i)) <= lastPage) ) s->addItem(srcDoc->Items->at(i),false); } if (s->count() > 0) { //move the selection to the clipboard std::ostringstream xmlString; SaxXML xmlStream(xmlString); Serializer::serializeObjects(*s, xmlStream); std::string xml(xmlString.str()); QByteArray ba(QByteArray(xml.c_str(), xml.length())); //paste Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba); targetDoc->moveGroup( p->guides.vertical(0, p->guides.Standard), p->guides.horizontal(0, p->guides.Standard), true, &pastedObjects ); } } }
bool XmlReport::createInformationLog( const QString& dir, const ER_EXCEPTIONRECORD& exceptionRecord, const ER_ADDITIONALINFO& info, const ER_PROCESSOR& processor, const ER_OPERATINGSYSTEM& os, const ER_MEMORY& memory, const MODULE_LIST& modules) { // // 生成 XML 文件的名字。 // QString logFileName("InforLog.xml"); QString filePath = dir + "\\" + logFileName; QFile logFile(filePath); bool opened = logFile.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text); if (!opened) { return false; } // 写 XML 文件的头。 QTextStream xmlStream(&logFile); xmlStream << "<Exception>"; // // 生成 ExceptionRecord 节点。 // QString xRecord = QString( "<ExceptionRecord ModuleName=\"%1\" " "ExceptionCode=\"%2\" " "ExceptionDescription=\"%3\" " "ExceptionAddress=\"%4\" " "ExceptionModuleName=\"%5\" " "/>").arg(exceptionRecord.ModuleName) .arg(exceptionRecord.ExceptionCode) .arg(exceptionRecord.ExceptionDescription) .arg(exceptionRecord.ExceptionAddress) .arg(exceptionRecord.ExceptionModuleName); xmlStream << xRecord; QString xInfo = QString( "<AdditionalInfomation Guid=\"%1\" DistSrc=\"%2\"/>").arg(info.Guid).arg(info.DistSrc); xmlStream << xInfo; // // 生成 Processor 节点。 // QString xProcessor = QString( "<Processor Architecture=\"%1\" Level=\"%2\" NumberOfProcessors=\"%3\"/>") .arg(processor.Architecture).arg(processor.Level) .arg(processor.NumberOfProcessors); xmlStream << xProcessor; // // 生成 OperatingSystem 节点。 // QString xOS = QString( "<OperatingSystem MajorVersion=\"%1\" " "MinorVersion=\"%2\" " "BuildNumber=\"%3\" " "CSDVersion=\"%4\" " "OSLanguage=\"%5\" " "/>").arg(os.MajorVersion).arg(os.MinorVersion).arg(os.BuildNumber).arg(os.CSDVersion) .arg(os.OSLanguage); xmlStream << xOS; // // 生成 Memory 节点。 // QString xMemory = QString( "<Memory MemoryLoad=\"%1%\" " "TotalPhys=\"%2 MB\" " "AvailPhys=\"%3 MB\" " "TotalPageFile=\"%4 MB\" " "AvailPageFile=\"%5 MB\" " "TotalVirtual=\"%6 MB\" " "AvailVirtual=\"%7 MB\" " "/>").arg(memory.MemoryLoad).arg(memory.TotalPhys).arg(memory.AvailPhys) .arg(memory.TotalPageFile).arg(memory.AvailPageFile).arg(memory.TotalVirtual) .arg(memory.AvailVirtual); xmlStream << xMemory; // // 生成 Modules 和 Module 节点。 // xmlStream << "<Modules>"; int count = modules.size(); for (int i = 0; i < count; ++i) { QString xModule = QString( "<Module FullPath=\"%1\" " "BaseAddress=\"%2\" " "Size=\"%3\" " "TimeStamp=\"%4\" " "FileVersion=\"%5\" " "ProductVersion=\"%6\" " "/>").arg(modules[i].FullPath).arg(modules[i].BaseAddress) .arg(modules[i].Size).arg(modules[i].TimeStamp).arg(modules[i].FileVersion) .arg(modules[i].ProductVersion); xmlStream << xModule; } xmlStream << "</Modules></Exception>"; return true; }
/** @brief 클러스터의 후보들 중 현재 클러스터에 가장 적합하게 연결될 클러스터를 찾는다 @param inClusterNo 현재 클러스터 번호 @param inClusterCandidates 뒤에 연결될 클러스터의 후보 @param inClustersHaveRecord 레코드를 가지고 있는 클러스터 @param outAlreadyAddedCluster 클러스터 후보들중에 이미 추가되기로 결정된 클러스터가 있는지 여부 */ std::vector<uint64_t> ClusterReassembler::findBestMatchingClusters(uint64_t inClusterNo, std::vector<CLUSTER_INFO>& inClusterCandidates, const stdext::hash_set<uint64_t>& inClustersHaveRecord, bool& outAlreadyAddedCluster) { std::vector<uint64_t> resultClusters; uint8_t clusterBuffer[CLUSTER_SIZE] = {0,}; uint8_t* mergedClusterBuffer = NULL; uint32_t clusterCandidateIndex = 0; uint32_t recordPos = 0; uint32_t nextClusterBufferPos = 0; outAlreadyAddedCluster = false; for (clusterCandidateIndex = 0; clusterCandidateIndex < inClusterCandidates.size(); ++clusterCandidateIndex) { if (inClusterNo == inClusterCandidates[clusterCandidateIndex].clusterNo) { outAlreadyAddedCluster = true; break; } } if (!outAlreadyAddedCluster) { nextClusterBufferPos = CLUSTER_SIZE; fragmentedFile_.readData(inClusterNo * CLUSTER_SIZE, clusterBuffer, CLUSTER_SIZE); uint32_t lastRecordPos = 0; EVTX_RECORD_HEADER* lastRecord = NULL; // 현재 클러스터에서(1클러스터) 가장 마지막 레코드를 찾는다 for (recordPos = 0; recordPos < CLUSTER_SIZE - EVTX_RECORD_HEADER_SIZE; recordPos += 8) { if (EvtxRecordValidator::isValidRecordHeader(clusterBuffer + recordPos)) { lastRecordPos = recordPos; break; } } lastRecord = (EVTX_RECORD_HEADER*)(clusterBuffer + lastRecordPos); // 가장 마지막 레코드가 3개 이상의 클러스터에 걸쳐져 있으면 if (lastRecordPos + lastRecord->length1 > CLUSTER_SIZE * 2) { uint32_t needClusterCount = 0; uint64_t checkClusterNo = 0; bool clustersHaveNoRecord = true; if (lastRecordPos + lastRecord->length1 % CLUSTER_SIZE == 0) { needClusterCount = ((lastRecordPos + lastRecord->length1) - CLUSTER_SIZE) / CLUSTER_SIZE; } else { needClusterCount = ((lastRecordPos + lastRecord->length1) - CLUSTER_SIZE) / CLUSTER_SIZE + 1; } mergedClusterBuffer = new uint8_t[CLUSTER_SIZE * (needClusterCount + 2)]; for (checkClusterNo = inClusterNo + 1; checkClusterNo < inClusterNo + 1 + needClusterCount; ++checkClusterNo) { if (inClustersHaveRecord.find(checkClusterNo) != inClustersHaveRecord.end()) { clustersHaveNoRecord = false; break; } } // 어쩔수 없이 레코드의 클러스터들이 연속되어 있다고 가정하고 맨처음과 마지막을 뺀 중간 클러스터 데이터들을 정한다 if (clustersHaveNoRecord) { for (uint64_t insertClusterNo = inClusterNo + 1; insertClusterNo < inClusterNo + 1 + needClusterCount; ++insertClusterNo) { resultClusters.push_back(insertClusterNo); fragmentedFile_.readData(insertClusterNo * CLUSTER_SIZE, mergedClusterBuffer + nextClusterBufferPos, CLUSTER_SIZE); nextClusterBufferPos += CLUSTER_SIZE; } } } else { mergedClusterBuffer = new uint8_t[CLUSTER_SIZE * 2]; } memcpy(mergedClusterBuffer, clusterBuffer, CLUSTER_SIZE); // 이어붙일 클러스터 후보군에 대하여 for (clusterCandidateIndex = 0; clusterCandidateIndex < inClusterCandidates.size(); ++clusterCandidateIndex) { uint32_t mergedLastRecordPos = 0; EVTX_RECORD_HEADER* mergedLastRecord = NULL; // 실제로 클러스터들을 조립하여 보고 fragmentedFile_.readData(inClusterCandidates[clusterCandidateIndex].clusterNo * CLUSTER_SIZE, (mergedClusterBuffer + nextClusterBufferPos), CLUSTER_SIZE); for (recordPos = 0; recordPos < CLUSTER_SIZE; recordPos += 8) { if (EvtxRecordValidator::isValidRecordHeader(mergedClusterBuffer + recordPos)) { mergedLastRecordPos = recordPos; break; } } // 올바른 레코드가 되는지 확인하여 올바른 레코드가 되면 가장 적합한 클러스터라 정한다 if (EvtxRecordValidator::isValidRecord(mergedClusterBuffer + mergedLastRecordPos, nextClusterBufferPos + CLUSTER_SIZE - mergedLastRecordPos)) { mergedLastRecord = (EVTX_RECORD_HEADER*)(mergedClusterBuffer + mergedLastRecordPos); uint32_t parseSize = 0; BinXmlStream xmlStream(mergedClusterBuffer + mergedLastRecordPos + EVTX_RECORD_HEADER_SIZE, (mergedLastRecord->length1 - 0x1C > nextClusterBufferPos) ? nextClusterBufferPos : (mergedLastRecord->length1 - 0x1C), mergedLastRecord->numLogRecord); xmlStream.parse(&parseSize); if (parseSize > nextClusterBufferPos || mergedLastRecord->length1 - 0x1C - parseSize < 8) { resultClusters.push_back(inClusterCandidates[clusterCandidateIndex].clusterNo); break; } } } if (mergedClusterBuffer != NULL) { delete [] mergedClusterBuffer; } } return resultClusters; }
void GeneOntology::writeOntologyFiles(){ ostringstream theFile; theFile<<m_parameters->getPrefix()<<"/BiologicalAbundances/_GeneOntology"; string directory=theFile.str(); createDirectory(directory.c_str()); theFile<<"/Terms"; ostringstream xmlFileStream; xmlFileStream<<theFile.str()<<".xml"; ostringstream tsvFileStream; tsvFileStream<<theFile.str()<<".tsv"; string xmlFile=xmlFileStream.str(); string tsvFile=tsvFileStream.str(); if(!m_gotGeneOntologyParameter){ return; } map<GeneOntologyIdentifier,int> modeCoverages; map<GeneOntologyIdentifier,double> meanCoverages; map<GeneOntologyIdentifier,double> estimatedProportions; ofstream xmlStream(xmlFile.c_str()); ostringstream operationBuffer; //------------- cout<<"TOTAL: "<<m_kmerObservationsWithGeneOntologies<<endl; operationBuffer<<"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"<<endl; operationBuffer<<"<root>"<<endl; LargeCount totalForTheGraph=m_searcher->getTotalNumberOfColoredKmerObservationsForANameSpace(COLOR_NAMESPACE_EMBL_CDS); operationBuffer<<"<totalColoredKmerObservations>"; operationBuffer<<totalForTheGraph<<"</totalColoredKmerObservations>"<<endl; // declare tsv files map<string,FILE*> tsvFiles; map<string,ostringstream*> tsvBuffers; for(map<GeneOntologyIdentifier,map<CoverageDepth,int> >::iterator i= m_ontologyTermFrequencies.begin();i!=m_ontologyTermFrequencies.end();i++){ GeneOntologyIdentifier handle=i->first; int mode=0; int modeCount=0; int total=0; LargeCount totalObservations=0; for(map<CoverageDepth,int>::iterator j=i->second.begin();j!=i->second.end();j++){ CoverageDepth coverage=j->first; int frequency=j->second; if(frequency>modeCount){ mode=coverage; modeCount=frequency; } total+=frequency; totalObservations+=coverage*frequency; } double mean=totalObservations; if(total!=0){ mean/=total; } #ifdef ASSERT assert(modeCoverages.count(handle)==0); assert(meanCoverages.count(handle)==0); #endif /**/ modeCoverages[handle]=mode; meanCoverages[handle]=mean; /**/ GeneOntologyDomain domain=getDomain(handle); string domainName=getDomainName(domain); operationBuffer<<"<geneOntologyTerm>"<<endl; operationBuffer<<"<identifier>"; operationBuffer<<getGeneOntologyIdentifier(handle)<<"</identifier><name>"; operationBuffer<<getGeneOntologyName(handle)<<"</name>"<<endl; operationBuffer<<"<domain>"<<domainName<<"</domain>"<<endl; /* print paths to root */ printPathsFromRoot(handle,&operationBuffer); operationBuffer<<"<modeKmerCoverage>"<<mode<<"</modeKmerCoverage>"; operationBuffer<<"<meanKmerCoverage>"<<mean<<"</meanKmerCoverage>"<<endl; operationBuffer<<"<totalColoredKmerObservations>"<<totalObservations<<"</totalColoredKmerObservations>"<<endl; double estimatedProportion=(0.0+totalObservations); if(totalForTheGraph!=0){ estimatedProportion/=totalForTheGraph; } estimatedProportions[handle]=estimatedProportion; m_termCounts[handle]=totalObservations; operationBuffer<<"<proportion>"<<estimatedProportion<<"</proportion>"<<endl; operationBuffer<<"<distribution>"<<endl; operationBuffer<<"#Coverage Frequency"<<endl; for(map<CoverageDepth,int>::iterator j=i->second.begin();j!=i->second.end();j++){ CoverageDepth coverage=j->first; int frequency=j->second; operationBuffer<<coverage<<" "<<frequency<<endl; } operationBuffer<<"</distribution></geneOntologyTerm>"<<endl; flushFileOperationBuffer(false,&operationBuffer,&xmlStream,CONFIG_FILE_IO_BUFFER_SIZE); // also output beautiful tsv file too if(tsvFiles.count(domainName)==0){ ostringstream theFile; theFile<<m_parameters->getPrefix()<<"/BiologicalAbundances/"; theFile<<"0.Profile.GeneOntologyDomain="<<domainName<<".tsv"; string tsvFile=theFile.str(); tsvFiles[domainName]=fopen(tsvFile.c_str(),"a"); tsvBuffers[domainName]=new ostringstream(); *(tsvBuffers[domainName])<<"#TermIdentifier TermName TermDomain TermProportion"<<endl; } *(tsvBuffers[domainName])<<getGeneOntologyIdentifier(handle)<<" "; *(tsvBuffers[domainName])<<getGeneOntologyName(handle)<<" "; *(tsvBuffers[domainName])<<domainName; *(tsvBuffers[domainName])<<" "<<estimatedProportion<<endl; } operationBuffer<<"</root>"<<endl; flushFileOperationBuffer(true,&operationBuffer,&xmlStream,CONFIG_FILE_IO_BUFFER_SIZE); xmlStream.close(); ofstream tsvStream(tsvFile.c_str()); operationBuffer<<"#Identifier Name Mode k-mer coverage Mean k-mer coverage Proportion"<<endl; // close tsv files for(map<string,FILE*>::iterator i=tsvFiles.begin();i!=tsvFiles.end();i++){ string category=i->first; FILE*file=i->second; string text=tsvBuffers[category]->str(); fprintf(file,"%s",text.c_str()); delete tsvBuffers[category]; fclose(file); } tsvBuffers.clear(); tsvFiles.clear(); for(map<GeneOntologyIdentifier,map<CoverageDepth,int> >::iterator i= m_ontologyTermFrequencies.begin();i!=m_ontologyTermFrequencies.end();i++){ GeneOntologyIdentifier handle=i->first; operationBuffer<<getGeneOntologyIdentifier(handle)<<" "; operationBuffer<<getGeneOntologyName(handle)<<" "; operationBuffer<<modeCoverages[handle]<<" "; operationBuffer<<meanCoverages[handle]<<" "; operationBuffer<<estimatedProportions[handle]<<endl; flushFileOperationBuffer(false,&operationBuffer,&tsvStream,CONFIG_FILE_IO_BUFFER_SIZE); } flushFileOperationBuffer(true,&operationBuffer,&tsvStream,CONFIG_FILE_IO_BUFFER_SIZE); tsvStream.close(); }
void Imposition::changeDocGrid() { //get first copied page Page* src = srcDoc->Pages->at(cbFront->currentIndex()); double realSrcWidth = src->width() + srcDoc->bleeds.Left + srcDoc->bleeds.Right; double realSrcHeight = src->height() + srcDoc->bleeds.Top + srcDoc->bleeds.Bottom; //check whether width fits if (isOK == true) { //count how many rows and cols will be needed int cols = (int)((targetDoc->pageWidth)/realSrcWidth); // how many columns do we have on page? int rows = (int)((targetDoc->pageHeight)/realSrcHeight); // how many rows do we have on page? //now count how many pages are needed and create them int countPages=0; countPages = (int)(boxCopies->value() / (cols * rows)) + 1; if ((boxCopies->value() % (cols * rows) ) == 0) countPages--; if (chb2Sides->checkState() == Qt::Checked) countPages = countPages * 2; //double pages! targetDoc->createNewDocPages(countPages); targetDoc->changeLayerName(0,srcDoc->layerName(0)); for (int i = 1; i < srcDoc->layerCount(); i++) { targetDoc->addLayer(srcDoc->layerName(i)); } // make guides for (int i = 0; i < countPages; i++) { Page* p = targetDoc->Pages->at(i); //vertical guides double vertDist = (p->width() - p->Margins.Left - p->Margins.Right - cols*src->width())/cols; p->guides.addVertical(p->Margins.Left + 0.5*vertDist, p->guides.Standard); p->guides.addVertical(p->width() - p->Margins.Right - 0.5*vertDist, p->guides.Standard); double left = p->Margins.Left + 0.5*vertDist; double right = p->width() - p->Margins.Right - 0.5*vertDist; for (int j = 0; j < cols; j++) { left = left + src->width() + vertDist; p->guides.addVertical(left, p->guides.Standard); right = right - src->width() - vertDist; p->guides.addVertical(right, p->guides.Standard); } //horizontal guides double horizDist = (p->height() - p->Margins.Top - p->Margins.Bottom - rows*src->height())/rows; p->guides.addHorizontal(p->Margins.Top + 0.5*horizDist, p->guides.Standard); p->guides.addHorizontal(p->height() - p->Margins.Bottom - 0.5*horizDist, p->guides.Standard); double top = p->Margins.Top + 0.5*horizDist; double bottom = p->height() - p->Margins.Bottom - 0.5*horizDist; for (int j = 0; j < rows; j++) { top = top + src->height() + horizDist; p->guides.addHorizontal(top, p->guides.Standard); bottom = bottom - src->height() - horizDist; p->guides.addHorizontal(bottom, p->guides.Standard); } } //copy the first page to the clipboard ScribusMainWindow* scMW = ScCore->primaryMainWindow(); scMW->view->requestMode(modeNormal); Selection* s = new Selection(scMW); //select items to copy for (int i = 0; i < srcDoc->Items->count(); i++) { if (srcDoc->OnPage(srcDoc->Items->at(i)) == src->pageNr()) s->addItem(srcDoc->Items->at(i),false); } //Now, as all the relevant items have been copied, move the selection to the clipboard // new version: std::ostringstream xmlString; SaxXML xmlStream(xmlString); Serializer::serializeObjects(*s, xmlStream); std::string xml(xmlString.str()); QByteArray ba(QByteArray(xml.c_str(), xml.length())); int currow = 0; int curcol = 0; targetDoc->setCurrentPage(targetDoc->Pages->at(0)); Page* cur = targetDoc->currentPage(); //now, start placing for (int j = 0; j < boxCopies->value(); j++) { Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba); targetDoc->moveGroup( cur->guides.vertical(curcol*2, cur->guides.Standard), cur->guides.horizontal(currow*2, cur->guides.Standard), true, &pastedObjects ); if ((curcol + 1) == cols) { curcol = 0; if ((currow + 1) == rows && (j+1 < boxCopies->value())) { currow = 0; if (chb2Sides->checkState() == Qt::Checked) { targetDoc->setCurrentPage(targetDoc->Pages->at(cur->pageNr()+2)); } else { targetDoc->setCurrentPage(targetDoc->Pages->at(cur->pageNr()+1)); } cur = targetDoc->currentPage(); } else { currow++; } } else { curcol++; } } delete s; if (chb2Sides->checkState() == Qt::Checked) { s = new Selection(scMW); targetDoc->setCurrentPage(targetDoc->Pages->at(1)); cur = targetDoc->currentPage(); src = srcDoc->Pages->at(cbBack->currentIndex()); //select items to copy for (int i = 0; i < srcDoc->Items->count(); i++) { if (srcDoc->OnPage(srcDoc->Items->at(i)) == src->pageNr()) s->addItem(srcDoc->Items->at(i),false); } //Now, as all the relevant items have been copied, move the selection to the clipboard // new version: std::ostringstream xmlString; SaxXML xmlStream(xmlString); Serializer::serializeObjects(*s, xmlStream); std::string xml(xmlString.str()); QByteArray ba(QByteArray(xml.c_str(), xml.length())); //start copying from the second page currow = 0; curcol = cols-1; for ( int j = 0; j < boxCopies->value(); j++ ) { Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba); targetDoc->moveGroup( cur->guides.vertical(curcol*2, cur->guides.Standard), cur->guides.horizontal(currow*2, cur->guides.Standard), true, &pastedObjects ); if ( curcol == 0 ) { curcol = cols - 1; if ( ( currow + 1 ) == rows && ( j+1 < boxCopies->value() ) ) { currow = 0; targetDoc->setCurrentPage ( targetDoc->Pages->at ( cur->pageNr() +2 ) ); cur = targetDoc->currentPage(); } else { currow++; } } else { curcol--; } } delete s; } view->Deselect(); srcDoc->view()->Deselect(); view->DrawNew(); srcDoc->view()->DrawNew(); } }
void Imposition::booklet4p(QList<int>* pages) { /* 4 page imposition looks like this: front: back: -------------------- -------------------- | | | | | | | | | | | | | | | | | | | 4 | 1 | | 2 | 3 | | | | | | | | | | | | | | | | | | | -------------------- -------------------- */ //fill the pages, so that it could be divided by for while ( (pages->count() % 4) != 0) { pages->append(0); } //create pages int targetSheets = (int)ceil(pages->count() / 4.0); //how many sheets do we have int targetPages = targetSheets * 2; //how many pages do we have targetDoc->createNewDocPages(targetPages); targetDoc->changeLayerName(0,srcDoc->layerName(0)); for (int i = 1; i < srcDoc->layerCount(); i++) { targetDoc->addLayer(srcDoc->layerName(i)); } //make guides for (int i = 0; i < targetDoc->Pages->count(); i++) { Page* p = targetDoc->Pages->at(i); //count the left guide: double guide_x = (p->width() - 2 * srcDoc->pageWidth)/2; p->guides.addVertical(guide_x, p->guides.Standard); //middle guide: guide_x += srcDoc->pageWidth; p->guides.addVertical(guide_x, p->guides.Standard); //and the right one: guide_x += srcDoc->pageWidth; p->guides.addVertical(guide_x, p->guides.Standard); //now, the top guide: double guide_y = (p->height() - srcDoc->pageHeight)/2; p->guides.addHorizontal(guide_y, p->guides.Standard); //and the bottom one: guide_y += srcDoc->pageHeight; p->guides.addHorizontal(guide_y, p->guides.Standard); } //start copying ScribusMainWindow* scMW = ScCore->primaryMainWindow(); scMW->slotSelect(); Selection* s = new Selection(scMW); //first, do the frontsides for (int i = 0; i < targetDoc->Pages->count(); i = i + 2) { targetDoc->setCurrentPage(targetDoc->Pages->at(i)); //copy the page to the clipboard //right side //make selections for (int j = 0; j < srcDoc->Items->count(); j++) { if (srcDoc->OnPage(srcDoc->Items->at(j)) == (pages->at(i)-1)) { s->addItem(srcDoc->Items->at(j),false); } } if (s->count() > 0) { std::ostringstream xmlString; SaxXML xmlStream(xmlString); Serializer::serializeObjects(*s, xmlStream); std::string xml(xmlString.str()); QByteArray ba(QByteArray(xml.c_str(), xml.length())); //paste page from clipboard Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba); targetDoc->moveGroup( targetDoc->Pages->at(i)->guides.vertical(1, targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(i)->guides.horizontal(0, targetDoc->Pages->at(i)->guides.Standard), false, &pastedObjects ); s->clear(); for (int j = 0; j < targetDoc->layerCount(); j++) { //create group out of all the items in the layer Selection* gs = new Selection(scMW); for (int k = 0; k < pastedObjects.count(); k++) { if (pastedObjects.itemAt(k)->LayerNr == j) gs->addItem(pastedObjects.itemAt(k)); } if (gs->count() > 0) { //create group targetDoc->itemSelection_GroupObjects(false, false, gs); //get group control signed int groupid = gs->itemAt(0)->Groups.at(0); PageItem* groupcontrol = NULL; for (int k = 0; k < targetDoc->Items->count(); k++) { if ( targetDoc->Items->at(k)->Groups.count() > 0 && targetDoc->Items->at(k)->Groups.at(0) == groupid && targetDoc->Items->at(k)->isGroupControl ) { groupcontrol = targetDoc->Items->at(k); break; } } groupcontrol->SetRectFrame(); double points[32] = { //left upper corner - left lower corner targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), //left lower corner - right lower corner targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), 100, 100, 100, 100, //right lower corner - right upper corner 100, 100, 100, 100, 0, 100, 0, 100, //right upper corner - left upper corner 0, 100, 0, 100, targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), }; double groupX = groupcontrol->xPos(); double groupY = groupcontrol->yPos() - targetDoc->Pages->at(i)->yOffset(); double groupWidth = groupcontrol->width(); double groupHeight = groupcontrol->height(); qDebug() << groupX << groupY << groupWidth << groupHeight; for (int k = 0; k < 12; k += 2) { if (points[k] < groupX) { points[k] = 0; } else if (points[k] - groupX > 100) { points[k] = 100; } else { points[k] = 100* (points[k] - groupX) / groupWidth; } if (points[k+1] < groupY) { points[k+1] = 0; } else if (points[k+1] - groupY > 100) { points[k+1] = 100; } else { points[k+1] = 100* (points[k+1] - groupY) / groupHeight; } qDebug() << "IMPOSITION: points[" << k << "] " << points[i] << "\n"; qDebug() << "IMPOSITION: points[" << k+1 << "] " << points[i+1] << "\n"; } for (int k = 28; k < 32; k += 2) { if (points[k] < groupX) { points[k] = 0; } else if (points[k] - groupX > 100) { points[k] = 100; } else { points[k] = 100* (points[k] - groupX) / groupWidth; } if (points[k+1] < groupY) { points[k+1] = 0; } else if (points[k+1] - groupY > 100) { points[k+1] = 100; } else { points[k+1] = 100* (points[k+1] - groupY) / groupHeight; } qDebug() << "IMPOSITION: points[" << k << "] " << points[i] << "\n"; qDebug() << "IMPOSITION: points[" << k+1 << "] " << points[i+1] << "\n"; } groupcontrol->SetFrameShape(32,points); } } } //left side for (int j = 0; j < srcDoc->Items->count(); j++) { if (srcDoc->OnPage(srcDoc->Items->at(j)) == (pages->at(pages->count()-i-1)-1)) { s->addItem(srcDoc->Items->at(j),false); } } if (s->count() > 0) { std::ostringstream xmlString; SaxXML xmlStream(xmlString); Serializer::serializeObjects(*s, xmlStream); std::string xml(xmlString.str()); QByteArray ba(QByteArray(xml.c_str(), xml.length())); //paste page from clipboard Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba); targetDoc->moveGroup( targetDoc->Pages->at(i)->guides.vertical(0, targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(i)->guides.horizontal(0, targetDoc->Pages->at(i)->guides.Standard), false, &pastedObjects ); s->clear(); //clipping layerwise for (int j = 0; j < targetDoc->layerCount(); j++) { //create group out of all the items in the layer Selection* gs = new Selection(scMW); for (int k = 0; k < pastedObjects.count(); k++) { if (pastedObjects.itemAt(k)->LayerNr == j) gs->addItem(pastedObjects.itemAt(k)); } if (gs->count() > 0) { //create group targetDoc->itemSelection_GroupObjects(false, false, gs); //get group control signed int groupid = gs->itemAt(0)->Groups.at(0); PageItem* groupcontrol = NULL; for (int k = 0; k < targetDoc->Items->count(); k++) { if ( targetDoc->Items->at(k)->Groups.count() > 0 && targetDoc->Items->at(k)->Groups.at(0) == groupid && targetDoc->Items->at(k)->isGroupControl ) { groupcontrol = targetDoc->Items->at(k); break; } } groupcontrol->SetRectFrame(); double points[32] = { //left upper corner - left lower corner 0, 0, 0, 0, 0, 100, 0, 100, //left lower corner - right lower corner 0, 100, 0, 100, targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), //right lower corner - right upper corner targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), //right upper corner - left upper corner targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), 0, 0, 0, 0 }; double groupX = groupcontrol->xPos(); double groupY = groupcontrol->yPos() - targetDoc->Pages->at(i)->yOffset(); double groupWidth = groupcontrol->width(); double groupHeight = groupcontrol->height(); qDebug() << groupX << groupY << groupWidth << groupHeight; for (int k = 13; k < 28; k += 2) { if (points[k] < groupX) { points[k] = 0; } else if (points[k] - groupX > 100) { points[k] = 100; } else { points[k] = 100* (points[k] - groupX) / groupWidth; } if (points[k+1] < groupY) { points[k+1] = 0; } else if (points[k+1] - groupY > 100) { points[k+1] = 100; } else { points[k+1] = 100* (points[k+1] - groupY) / groupHeight; } qDebug() << "IMPOSITION: points[" << k << "] " << points[i] << "\n"; qDebug() << "IMPOSITION: points[" << k+1 << "] " << points[i+1] << "\n"; } groupcontrol->SetFrameShape(32,points); } } } } //backsides for (int i = 1; i < targetDoc->Pages->count(); i = i + 2) { targetDoc->setCurrentPage(targetDoc->Pages->at(i)); //copy the page to the clipboard //left side //make selections for (int j = 0; j < srcDoc->Items->count(); j++) { if (srcDoc->OnPage(srcDoc->Items->at(j)) == (pages->at(i)-1)) { s->addItem(srcDoc->Items->at(j),false); } } if (s->count() > 0) { std::ostringstream xmlString; SaxXML xmlStream(xmlString); Serializer::serializeObjects(*s, xmlStream); std::string xml(xmlString.str()); QByteArray ba(QByteArray(xml.c_str(), xml.length())); //paste page from clipboard Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba); targetDoc->moveGroup( targetDoc->Pages->at(i)->guides.vertical(0, targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(i)->guides.horizontal(0, targetDoc->Pages->at(i)->guides.Standard), false, &pastedObjects ); s->clear(); //clipping layerwise for (int j = 0; j < targetDoc->layerCount(); j++) { //create group out of all the items in the layer Selection* gs = new Selection(scMW); for (int k = 0; k < pastedObjects.count(); k++) { if (pastedObjects.itemAt(k)->LayerNr == j) gs->addItem(pastedObjects.itemAt(k)); } if (gs->count() > 0) { //create group targetDoc->itemSelection_GroupObjects(false, false, gs); //get group control signed int groupid = gs->itemAt(0)->Groups.at(0); PageItem* groupcontrol = NULL; for (int k = 0; k < targetDoc->Items->count(); k++) { if ( targetDoc->Items->at(k)->Groups.count() > 0 && targetDoc->Items->at(k)->Groups.at(0) == groupid && targetDoc->Items->at(k)->isGroupControl ) { groupcontrol = targetDoc->Items->at(k); break; } } groupcontrol->SetRectFrame(); double points[32] = { //left upper corner - left lower corner 0, 0, 0, 0, 0, 100, 0, 100, //left lower corner - right lower corner 0, 100, 0, 100, targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), //right lower corner - right upper corner targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), //right upper corner - left upper corner targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), 0, 0, 0, 0 }; double groupX = groupcontrol->xPos(); double groupY = groupcontrol->yPos() - targetDoc->Pages->at(i)->yOffset(); double groupWidth = groupcontrol->width(); double groupHeight = groupcontrol->height(); qDebug() << groupX << groupY << groupWidth << groupHeight; for (int k = 13; k < 28; k += 2) { if (points[k] < groupX) { points[k] = 0; } else if (points[k] - groupX > 100) { points[k] = 100; } else { points[k] = 100* (points[k] - groupX) / groupWidth; } if (points[k+1] < groupY) { points[k+1] = 0; } else if (points[k+1] - groupY > 100) { points[k+1] = 100; } else { points[k+1] = 100* (points[k+1] - groupY) / groupHeight; } qDebug() << "IMPOSITION: points[" << k << "] " << points[i] << "\n"; qDebug() << "IMPOSITION: points[" << k+1 << "] " << points[i+1] << "\n"; } groupcontrol->SetFrameShape(32,points); } } } //right side for (int j = 0; j < srcDoc->Items->count(); j++) { if (srcDoc->OnPage(srcDoc->Items->at(j)) == (pages->at(pages->count()-i-1)-1)) { s->addItem(srcDoc->Items->at(j),false); } } if (s->count() > 0) { std::ostringstream xmlString; SaxXML xmlStream(xmlString); Serializer::serializeObjects(*s, xmlStream); std::string xml(xmlString.str()); QByteArray ba(QByteArray(xml.c_str(), xml.length())); //paste page from clipboard Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba); targetDoc->moveGroup( targetDoc->Pages->at(i)->guides.vertical(1, targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(i)->guides.horizontal(0, targetDoc->Pages->at(i)->guides.Standard), false, &pastedObjects ); s->clear(); for (int j = 0; j < targetDoc->layerCount(); j++) { //create group out of all the items in the layer Selection* gs = new Selection(scMW); for (int k = 0; k < pastedObjects.count(); k++) { if (pastedObjects.itemAt(k)->LayerNr == j) gs->addItem(pastedObjects.itemAt(k)); } if (gs->count() > 0) { //create group targetDoc->itemSelection_GroupObjects(false, false, gs); //get group control signed int groupid = gs->itemAt(0)->Groups.at(0); PageItem* groupcontrol = NULL; for (int k = 0; k < targetDoc->Items->count(); k++) { if ( targetDoc->Items->at(k)->Groups.count() > 0 && targetDoc->Items->at(k)->Groups.at(0) == groupid && targetDoc->Items->at(k)->isGroupControl ) { groupcontrol = targetDoc->Items->at(k); break; } } groupcontrol->SetRectFrame(); double points[32] = { //left upper corner - left lower corner targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), //left lower corner - right lower corner targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), 100, 100, 100, 100, //right lower corner - right upper corner 100, 100, 100, 100, 0, 100, 0, 100, //right upper corner - left upper corner 0, 100, 0, 100, targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), }; double groupX = groupcontrol->xPos(); double groupY = groupcontrol->yPos() - targetDoc->Pages->at(i)->yOffset(); double groupWidth = groupcontrol->width(); double groupHeight = groupcontrol->height(); qDebug() << groupX << groupY << groupWidth << groupHeight; for (int k = 0; k < 12; k += 2) { if (points[k] < groupX) { points[k] = 0; } else if (points[k] - groupX > 100) { points[k] = 100; } else { points[k] = 100* (points[k] - groupX) / groupWidth; } if (points[k+1] < groupY) { points[k+1] = 0; } else if (points[k+1] - groupY > 100) { points[k+1] = 100; } else { points[k+1] = 100* (points[k+1] - groupY) / groupHeight; } qDebug() << "IMPOSITION: points[" << k << "] " << points[i] << "\n"; qDebug() << "IMPOSITION: points[" << k+1 << "] " << points[i+1] << "\n"; } for (int k = 28; k < 32; k += 2) { if (points[k] < groupX) { points[k] = 0; } else if (points[k] - groupX > 100) { points[k] = 100; } else { points[k] = 100* (points[k] - groupX) / groupWidth; } if (points[k+1] < groupY) { points[k+1] = 0; } else if (points[k+1] - groupY > 100) { points[k+1] = 100; } else { points[k+1] = 100* (points[k+1] - groupY) / groupHeight; } qDebug() << "IMPOSITION: points[" << k << "] " << points[i] << "\n"; qDebug() << "IMPOSITION: points[" << k+1 << "] " << points[i+1] << "\n"; } groupcontrol->SetFrameShape(32,points); } } } } }
const AudioFileModel& AnalyzeTask::parseMediaInfo(const QByteArray &data, AudioFileModel &audioFile) { QXmlStreamReader xmlStream(data); bool firstMediaFile = true; if (findNextElement(QLatin1String("MediaInfo"), xmlStream)) { const QString versionXml = findAttribute(QLatin1String("Version"), xmlStream.attributes()); if (versionXml.isEmpty() || (!checkVersionStr(versionXml, 2U, 0U))) { qWarning("Invalid file format version property: \"%s\"", MUTILS_UTF8(versionXml)); return audioFile; } if (findNextElement(QLatin1String("CreatingLibrary"), xmlStream)) { const QString versionLib = findAttribute(QLatin1String("Version"), xmlStream.attributes()); const QString identifier = xmlStream.readElementText(QXmlStreamReader::SkipChildElements).simplified(); if (!STRICMP(identifier, QLatin1String("MediaInfoLib"))) { qWarning("Invalid library identiofier property: \"%s\"", MUTILS_UTF8(identifier)); return audioFile; } if (!versionLib.isEmpty()) { if (m_mediaInfoVer != UINT_MAX) { const quint32 mediaInfoVer = (m_mediaInfoVer > 9999U) ? m_mediaInfoVer / 10U : m_mediaInfoVer; if (!checkVersionStr(versionLib, mediaInfoVer / 100U, mediaInfoVer % 100U)) { qWarning("Invalid library version property: \"%s\"", MUTILS_UTF8(versionLib)); return audioFile; } } } else { qWarning("Library version property not found!"); return audioFile; } while (findNextElement(QLatin1String("Media"), xmlStream)) { if (firstMediaFile || audioFile.techInfo().containerType().isEmpty() || audioFile.techInfo().audioType().isEmpty()) { firstMediaFile = false; parseFileInfo(xmlStream, audioFile); } else { qWarning("Skipping non-primary file!"); xmlStream.skipCurrentElement(); } } } } if (!(audioFile.techInfo().containerType().isEmpty() || audioFile.techInfo().audioType().isEmpty())) { if (audioFile.metaInfo().title().isEmpty()) { QString baseName = QFileInfo(audioFile.filePath()).fileName(); int index; if ((index = baseName.lastIndexOf(".")) >= 0) { baseName = baseName.left(index); } baseName = baseName.replace("_", " ").simplified(); if ((index = baseName.lastIndexOf(" - ")) >= 0) { baseName = baseName.mid(index + 3).trimmed(); } audioFile.metaInfo().setTitle(baseName); } if ((audioFile.techInfo().audioType().compare("PCM", Qt::CaseInsensitive) == 0) && (audioFile.techInfo().audioProfile().compare("Float", Qt::CaseInsensitive) == 0)) { if (audioFile.techInfo().audioBitdepth() == 32) audioFile.techInfo().setAudioBitdepth(AudioFileModel::BITDEPTH_IEEE_FLOAT32); } } else { qWarning("Audio file format could *not* be recognized!"); } return audioFile; }