// input everything between \begin{} and \end{} void LatexTableModel::setContent(const QString &text) { QStringList sourceLines(text.split("\\\\")); for (int i=0; i<sourceLines.count(); i++) { QString pre; QString line = sourceLines.at(i).trimmed(); if (i==sourceLines.count()-1 && line.isEmpty()) break; // last empty line bool recheck = true; while (line.startsWith("\\") && recheck) { recheck = false; foreach (const QString &cmd, metaLineCommands) { if (line.startsWith(cmd)) { int behind; getCommandOptions(line, cmd.length(), &behind); pre.append(line.left(behind)); line = line.mid(behind).trimmed(); recheck = true; break; } } } LatexTableLine *ltl = new LatexTableLine(this); if (!pre.isEmpty()) ltl->setMetaLine(pre); if (!line.isEmpty()) ltl->setColLine(line); lines.append(ltl); } /* *** alternative more efficient ansatz *** int len = text.length(); int pos=skipWhitespace(text); int start = pos; LatexTableLine *ltl = new LatexTableLine(this); bool hasMetaContent = false; while (pos < len) { if (text.at(pos) == '\\') { if (pos < len && text.at(pos+1) == '\\') { ltl->setColStr(text.mid(start, pos-start)); pos+=2; start=pos; } else { QString cmd; int end = getCommand(text, cmd, pos); if (metaLineCommands.contains(cmd)) { QStringList args; getCommandOptions(text, end, end); hasMetaContent = true; } } } pos = skipWhitespace(pos); } */ }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- bool CorrectInitializerList( AbstractFilter::Pointer filter, const QString& hFile, const QString& cppFile) { QString contents; { // Read the Source File QFileInfo fi(cppFile); // if (fi.baseName().compare("RegisterPointSets") != 0) { return false; } QFile source(cppFile); source.open(QFile::ReadOnly); contents = source.readAll(); source.close(); } QStringList names; bool didReplace = false; QString searchString = filter->getNameOfClass() + "::" + filter->getNameOfClass(); QStringList outLines; QStringList list = contents.split(QRegExp("\\n")); QStringListIterator sourceLines(list); int index = 0; while (sourceLines.hasNext()) { QString line = sourceLines.next(); if(line.contains(searchString) ) { outLines.push_back(line); line = sourceLines.next(); outLines.push_back(line); // get the call to the superclass fixInitializerList(sourceLines, outLines, hFile, cppFile); didReplace = true; } else { outLines.push_back(line); } } writeOutput(didReplace, outLines, cppFile); index++; return didReplace; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FilterMaker::updateTestLocations() { QString filterName = this->filterName->text(); QString pluginDir = this->pluginDir->text(); QString testPath = pluginDir + "/Test/TestFileLocations.h.in"; testPath = QDir::toNativeSeparators(testPath); QFile source(testPath); source.open(QFile::ReadOnly); QString contents = source.readAll(); source.close(); QString namespaceStr = createNamespaceString(); // Check to make sure we don't already have this filter in the namespace if (contents.contains(namespaceStr) == true) { return; } QStringList outLines; QStringList list = contents.split(QRegExp("\\n")); QStringListIterator sourceLines(list); QString searchString = "#endif"; while (sourceLines.hasNext()) { QString line = sourceLines.next(); if (line.contains(searchString)) { QString str("namespace UnitTest\n{"); QTextStream outStream(&str); outStream << namespaceStr << "\n"; outStream << "}\n"; outLines.push_back(str); outLines.push_back(line); } else { outLines.push_back(line); } } source.remove(); if (source.open(QIODevice::WriteOnly)) { source.write(outLines.join("\n").toLatin1().data()); source.close(); } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- QString AdjustOutputDirectory(const QString& pipelineFile) { QString contents; // Read the Source File QFileInfo fi(pipelineFile); QFile source(pipelineFile); source.open(QFile::ReadOnly); contents = source.readAll(); source.close(); QString searchString = QString::fromLatin1("Data/Output/"); QStringList outLines; QStringList list = contents.split(QRegExp("\\n")); QStringListIterator sourceLines(list); while (sourceLines.hasNext()) { QString line = sourceLines.next(); if( line.contains(QString("Data/")) == true && line.contains(searchString) == false ) { line = line.replace(QString("Data/"), getDream3dDataDir() + "/Data/"); } if(line.contains(searchString) ) { line = line.replace(searchString, getTestTempDirectory()); } outLines.push_back(line); } QString outFile = getTestTempDirectory() + fi.fileName(); writeOutput(true, outLines, outFile); return outFile; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FilterMaker::updateSourceList() { QString filterName = this->filterName->text(); QString pluginDir = this->pluginDir->text(); QString pluginName = QFileInfo(pluginDir).baseName(); QString sourceListPath = pluginDir + "/" + pluginName + "Filters/SourceList.cmake"; sourceListPath = QDir::toNativeSeparators(sourceListPath); QFile source(sourceListPath); source.open(QFile::ReadOnly); QString contents = source.readAll(); source.close(); QString namespaceStr = createNamespaceString(); // Check to make sure we don't already have this filter in the namespace if (contents.contains(namespaceStr) == true) { return; } bool keepGoing = false; QStringList outLines; QStringList list = contents.split(QRegExp("\\n")); QStringListIterator sourceLines(list); QString searchString = "set(_PublicFilters"; if (!isPublic()) { searchString = "set(_PrivateFilters"; } while (sourceLines.hasNext()) { QString line = sourceLines.next(); if (line.contains(searchString) && !keepGoing) { outLines.push_back(line); while (sourceLines.hasNext()) { line = sourceLines.next(); if (line.contains(filterName) && !keepGoing) { outLines.push_back(line); keepGoing = true; } else if (line.contains(")")) { // We never found the filter name so lets add it back in if (!keepGoing) { outLines.push_back(" " + filterName); } outLines.push_back(line); keepGoing = true; break; } else { outLines.push_back(line); } } } else { outLines.push_back(line); } } source.remove(); if (source.open(QIODevice::WriteOnly)) { source.write(outLines.join("\n").toLatin1().data()); source.close(); } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- float positionInHeader(const QString hFile, const QString var, bool isPointer) { QString contents; { // Read the Source File QFileInfo fi(hFile); // if (fi.baseName().compare("FillBadData") != 0) // { // return false; // } QFile source(hFile); source.open(QFile::ReadOnly); contents = source.readAll(); source.close(); } //QStringList names; bool found = false; int lineNum = 1; QString searchString = var; QStringList list = contents.split(QRegExp("\\n")); QStringListIterator sourceLines(list); //Look for raw pointers FIRST otherwise we get the wrong line. if(found == false && isPointer == true) { searchString = var; list = contents.split(QRegExp("\\n")); sourceLines.toFront(); // reset the iterator to the beginning lineNum = 1; while (sourceLines.hasNext()) { QString line = sourceLines.next(); if(line.contains(searchString) && line.contains("DEFINE_DATAARRAY_VARIABLE") ) { int index = line.indexOf(var); // Verify we actually found the whole word if(line.at(index - 1).isSpace() ) { line = sourceLines.next(); found = true; return (float)lineNum + 0.1f; } } lineNum++; } } if(found == false && isPointer == true) { searchString = var; list = contents.split(QRegExp("\\n")); sourceLines.toFront(); // reset the iterator to the beginning lineNum = 1; while (sourceLines.hasNext()) { QString line = sourceLines.next(); if(line.contains(searchString) && line.contains("DEFINE_DATAARRAY_VARIABLE") ) { line = sourceLines.next(); found = true; return (float)lineNum + 0.1f; } lineNum++; } } searchString = var; list = contents.split(QRegExp("\\n")); sourceLines.toFront(); // reset the iterator to the beginning lineNum = 1; while (sourceLines.hasNext()) { QString line = sourceLines.next(); if(line.contains(searchString) ) { int offset = line.indexOf(searchString); int size = searchString.size(); // Make sure we find the whole word? if(line.at(offset + size).isLetterOrNumber()) { continue; } if(line.contains("Q_PROPERTY") ) { continue; } line = sourceLines.next(); found = true; return (float)lineNum; } lineNum++; } // Variable was not found so it _might_ be embedded in a macro if(found == false && var.contains("ArrayName")) { int offset = var.indexOf("ArrayName"); searchString = var.mid(0, offset); // extract out the variable name without the "ArrayName" on the end of it list = contents.split(QRegExp("\\n")); sourceLines.toFront(); // reset the iterator to the beginning lineNum = 1; while (sourceLines.hasNext()) { QString line = sourceLines.next(); if(line.contains(searchString) && line.contains("DEFINE_DATAARRAY_VARIABLE") ) { int index = line.indexOf(searchString); // Verify we actually found the whole word if(index > -1 && line.at(index - 1).isSpace() ) { line = sourceLines.next(); found = true; return (float)lineNum; } } lineNum++; } } if(found == false) { lineNum = -1; } return (float)lineNum; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int main (int argc, char* argv[]) { // Instantiate the QCoreApplication that we need to get the current path and load plugins. QCoreApplication app(argc, argv); QCoreApplication::setOrganizationName("BlueQuartz Software"); QCoreApplication::setOrganizationDomain("bluequartz.net"); QCoreApplication::setApplicationName("PipelineRunnerTest"); // We need to change our working directory into the "DREAM3D_Data" directory because all the pipelines use relative paths QDir dataDir = QDir(getDream3dDataDir()); #ifdef _MSC_VER _chdir(dataDir.absolutePath().toLatin1().constData()); #else chdir(dataDir.absolutePath().toLatin1().constData()); #endif // Register all the filters including trying to load those from Plugins FilterManager* fm = FilterManager::Instance(); SIMPLibPluginLoader::LoadPluginFilters(fm); // Send progress messages from PipelineBuilder to this object for display QMetaObjectUtilities::RegisterMetaTypes(); int err = 0; // Read in the contents of the PipelineList file which contains all the Pipelines that we want // to execute QString contents; { // Read the Source File QFileInfo fi(getPipelineListFile()); QFile source(getPipelineListFile()); source.open(QFile::ReadOnly); contents = source.readAll(); source.close(); } // Split the file into tokens using the newline character QStringList list = contents.split(QRegExp("\\n")); QStringListIterator sourceLines(list); // Iterate over all the entries in the file and process each pipeline. Note that the order of the // pipelines will probably matter int testNum = 0; while (sourceLines.hasNext()) { QString pipelineFile = sourceLines.next(); pipelineFile = pipelineFile.trimmed(); if(pipelineFile.isEmpty()) { continue; } try { QFileInfo fi(pipelineFile); pipelineFile = AdjustOutputDirectory(pipelineFile); DREAM3D::unittest::CurrentMethod = fi.fileName().toStdString(); DREAM3D::unittest::numTests++; std::cout << "\"" << testNum++ << "\": {" << std::endl; ExecutePipeline(pipelineFile); TestPassed(fi.fileName().toStdString()); std::cout << "}," << std::endl; DREAM3D::unittest::CurrentMethod = ""; } catch (TestException& e) { TestFailed(DREAM3D::unittest::CurrentMethod); std::cout << e.what() << std::endl; err = EXIT_FAILURE; } } QDir tempDir(getTestTempDirectory()); tempDir.removeRecursively(); return err; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- bool fixFile( AbstractFilter::Pointer filter, const QString& hFile, const QString& cppFile) { QString contents; { // Read the Source File QFileInfo fi(cppFile); // if (fi.baseName().compare("EBSDSegmentFeatures") != 0) // { // return false; // } QFile source(cppFile); source.open(QFile::ReadOnly); contents = source.readAll(); source.close(); } QStringList names; bool didReplace = false; QString searchString = "newFilterInstance(bool copyFilterParameters)"; QStringList outLines; QStringList list = contents.split(QRegExp("\\n")); QStringListIterator sourceLines(list); while (sourceLines.hasNext()) { QString line = sourceLines.next(); if(line.contains(searchString) ) // we found the filter parameter section { outLines.push_back(line); while(sourceLines.hasNext() ) { line = sourceLines.next(); if(line.contains("filter->set") ) { } else if(line.contains("}") ) { createNewFilterInstance(sourceLines, outLines); outLines.push_back(line); break; } else { outLines.push_back(line); } } didReplace = true; } else { outLines.push_back(line); } } writeOutput(didReplace, outLines, cppFile); return didReplace; }