PluginProgress* Perspective::progress(ProgressOptions options) { SimplePluginProgressDialog* dlg = new SimplePluginProgressDialog(_mainWindow); dlg->setWindowIcon(_mainWindow->windowIcon()); dlg->showPreview(options.testFlag(IsPreviewable)); dlg->setCancelButtonVisible(options.testFlag(IsCancellable)); dlg->setStopButtonVisible(options.testFlag(IsStoppable)); dlg->show(); QApplication::processEvents(); return dlg; }
int main(int argc,char **argv) { start_crash_handler(); QString appName("Tulip "); QString iconPath; // show patch number only if needed if (TULIP_INT_VERSION % 10) appName += TULIP_VERSION; else appName += TULIP_MM_VERSION; QApplication tulip_perspective(argc, argv); // the applicationName below is used to identify the location // of downloaded plugins, so it must be the same as in // tulip/main.cpp tulip_perspective.setApplicationName(appName); #if defined(__APPLE__) // allows to load qt imageformats plugin QApplication::addLibraryPath(QApplication::applicationDirPath() + "/.."); #endif // Check arguments QString perspectiveName,projectFilePath; QVariantMap extraParams; QRect windowGeometry; QString title = appName; PerspectiveContext* context = new PerspectiveContext(); QRegExp perspectiveRegexp("^\\-\\-perspective=(.*)"); QRegExp pRegexp("^\\-p"); QRegExp titleRegexp("^\\-\\-title=(.*)"); QRegExp iconRegexp("^\\-\\-icon=(.*)"); QRegExp portRegexp("^\\-\\-port=([0-9]*)"); QRegExp idRegexp("^\\-\\-id=([0-9]*)"); QRegExp geometryRegexp("^\\-\\-geometry=([0-9]*)\\,([0-9]*)\\,([0-9]*)\\,([0-9]*)"); QRegExp extraParametersRegexp("^\\-\\-([^=]*)=(.*)"); QStringList args = QApplication::arguments(); #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) QString dumpPath = QDir(QStandardPaths::standardLocations(QStandardPaths::TempLocation).at(0)).filePath("tulip_perspective-0.log"); #else QString dumpPath = QDir(QDesktopServices::storageLocation(QDesktopServices::TempLocation)).filePath("tulip_perspective-0.log"); #endif setDumpPath(dumpPath.toStdString()); for(int i=1; i < args.size(); ++i) { QString a = args[i]; if ((a == "--help")||(a=="-h")) { usage(""); } else if (perspectiveRegexp.exactMatch(a)) { perspectiveName = perspectiveRegexp.cap(1); } else if(pRegexp.exactMatch(a)) { perspectiveName = args[++i]; } else if (titleRegexp.exactMatch(a)) { title = titleRegexp.cap(1); } else if (iconRegexp.exactMatch(a)) { iconPath = iconRegexp.cap(1); } else if (geometryRegexp.exactMatch(a)) { windowGeometry = QRect(geometryRegexp.cap(1).toInt(),geometryRegexp.cap(2).toInt(),geometryRegexp.cap(3).toInt(),geometryRegexp.cap(4).toInt()); } else if (portRegexp.exactMatch(a)) { context->tulipPort = portRegexp.cap(1).toUInt(); } else if (idRegexp.exactMatch(a)) { context->id = idRegexp.cap(1).toUInt(); #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) QString dumpPath = QDir(QStandardPaths::standardLocations(QStandardPaths::TempLocation).at(0)).filePath("tulip_perspective-" + idRegexp.cap(1) + ".log"); #else QString dumpPath = QDir(QDesktopServices::storageLocation(QDesktopServices::TempLocation)).filePath("tulip_perspective-" + idRegexp.cap(1) + ".log"); #endif setDumpPath(dumpPath.toStdString()); } else if(extraParametersRegexp.exactMatch(a)) { extraParams[extraParametersRegexp.cap(1)] = extraParametersRegexp.cap(2); } else { projectFilePath = a; } } // Create perspective's window TulipPerspectiveProcessMainWindow *mainWindow = new TulipPerspectiveProcessMainWindow(title); mainWindow->setVisible(false); // Progress bar dialog SimplePluginProgressDialog *progress = new SimplePluginProgressDialog(mainWindow); progress->setStopButtonVisible(false); progress->setCancelButtonVisible(false); progress->showPreview(false); progress->resize(500,progress->height()); progress->setComment(QString("Initializing ") + title); progress->setWindowTitle(title); progress->progress(0,100); initTulipLib(QApplication::applicationDirPath().toUtf8().data()); QIcon icon = progress->windowIcon(); if (! iconPath.isEmpty()) { QString iconFullPath = QString::fromUtf8(TulipBitmapDir.c_str()) + iconPath; QIcon tmp(iconFullPath); if (tmp.pixmap(QSize(16,16)).isNull() == false) icon = tmp; else usage("Could not load icon : " + iconFullPath); } progress->setWindowIcon(icon); progress->show(); TulipProject *project = NULL; QString error; if(!projectFilePath.isEmpty() && !QFileInfo(projectFilePath).exists()) { usage("File "+projectFilePath+" not found"); } if (!projectFilePath.isEmpty() && projectFilePath.endsWith(".tlpx")) { project = TulipProject::openProject(projectFilePath,progress); if (!project->isValid()) { error = project->lastError(); delete project; project = NULL; } } if (project == NULL) { context->externalFile = projectFilePath; project = TulipProject::newProject(); } else if (perspectiveName.isEmpty()) { perspectiveName = project->perspective(); if(perspectiveName.isEmpty()) error = "No perspective given on the command line or in the project file"; } if (perspectiveName.isEmpty()) { usage("Could not determine the perspective to launch: \n"+ error); } context->project = project; context->parameters = extraParams; project->setPerspective(perspectiveName); // Init tulip PluginLoaderToProgress* loader = new PluginLoaderToProgress(); loader->_progress = progress; try { tlp::initTulipSoftware(loader); } catch(tlp::TulipException& e) { QMessageBox::warning(0,"Error", e.what()); exit(1); } delete loader; // Initialize main window. progress->progress(100,100); progress->setComment("Setting up GUI (this can take some time)"); context->mainWindow = mainWindow; // Create perspective object Perspective *perspective = PluginLister::instance()->getPluginObject<Perspective>(perspectiveName.toStdString(), context); if (perspective==NULL) { usage("Cannot open perspective: " + perspectiveName + "\nWrong plugin type or plugin not found."); } Perspective::setInstance(perspective); mainWindow->setProject(project); perspective->start(progress); mainWindow->projectFileChanged(projectFilePath); delete progress; mainWindow->setWindowIcon(icon); mainWindow->show(); // the delay of geometry update until perspective execution // seems to ensure that the four parameters (x,y,w,h) // are taken into account if (windowGeometry.isValid()) mainWindow->setGeometry(windowGeometry); int result = tulip_perspective.exec(); delete perspective; delete mainWindow; // We need to clear allocated Qt buffers and QGlWidget to remove a segfault when we close tulip QGlBufferManager::clearBuffers(); GlMainWidget::clearFirstQGLWidget(); #ifdef MEMORYCHECKER_ON memory_checker_print_report(); #endif // MEMORYCHECKER_ON return result; }