15 #include <sbml/SBMLDocument.h>
18 #include <sedml/SedDocument.h>
21 #include <QtCore/QEvent>
22 #include <QtGui/QMenuBar>
23 #include <QtCore/QTimer>
24 #include <QtGui/QComboBox>
25 #include <QtGui/QToolBar>
26 #include <QtGui/QTextEdit>
27 #include <QtCore/QThread>
28 #include <QtGui/QFontDialog>
33 #ifdef COPASI_SBW_INTEGRATION
35 #endif // COPASI_SBW_INTEGRATION
71 #ifdef WITH_MERGEMODEL
80 #define AutoSaveInterval 10*60*1000
83 #include <QtCore/QtDebug>
89 QMainWindow*
getWindowByTitle(
const QList< QPointer< QMainWindow > > & list,
const QString& title)
91 for (
int index = 0; index < list.count(); ++index)
93 QMainWindow *window = list[index];
95 if (window == NULL)
continue;
97 if (window ->windowTitle() == title)
123 #ifdef COPASI_SBW_INTEGRATION
125 if (pWindow != NULL &&
128 pWindow->sbwConnect();
129 pWindow->sbwRegister();
132 #endif // COPASI_SBW_INTEGRATION
152 mpDataModelGUI(NULL),
154 mpBoxSelectFramework(NULL),
156 mpObjectBrowser(NULL),
157 mSaveAsRequired(true),
158 mpAutoSaveTimer(NULL),
159 mSuspendAutoSave(false),
160 mpMenuExamples(NULL),
161 mpMenuRecentFiles(NULL),
162 mRecentFilesActionMap(),
163 mpRecentFilesActionGroup(NULL),
164 mpMenuRecentSBMLFiles(NULL),
165 mRecentSBMLFilesActionMap(),
166 mpRecentSBMLFilesActionGroup(NULL),
167 mpWindowsActionGroup(NULL),
168 mpMIRIAMResources(NULL),
169 mpMainThread(QThread::currentThread()),
171 mCommitRequired(true),
172 mQuitApplication(false),
173 mSliderDialogEnabled(false),
174 mMessageShown(false),
177 #ifdef COPASI_SBW_INTEGRATION
179 , mSBWAnalyzerModules()
180 , mSBWAnalyzerServices()
182 , mpSBWActionGroup(NULL)
185 , mSBWIgnoreShutdownEvent(true)
189 , mpMenuSEDMLSupport(NULL)
190 , mpMenuRecentSEDMLFiles(NULL)
191 , mRecentSEDMLFilesActionMap()
192 , mpRecentSEDMLFilesActionGroup(NULL)
197 this->setAttribute(Qt::WA_DeleteOnClose);
215 setIconSize(QSize(18, 20));
224 mpaExportSEDML->setEnabled(
false);
269 setAcceptDrops(
true);
274 #ifdef COPASI_SBW_INTEGRATION
276 #endif // COPASI_SBW_INTEGRATION
278 QList< QPointer<QMainWindow> >::iterator it =
mWindows.begin();
279 QList< QPointer<QMainWindow> >::iterator end =
mWindows.end();
281 for (; it != end; ++it)
283 QPointer<QMainWindow> current = *it;
285 if (current == NULL)
continue;
303 connect(
mpaNew, SIGNAL(activated()),
this, SLOT(
newDoc()));
304 mpaNew->setShortcut(Qt::CTRL + Qt::Key_N);
308 mpaOpen->setShortcut(Qt::CTRL + Qt::Key_O);
320 mpaSave->setShortcut(Qt::CTRL + Qt::Key_S);
324 mpaSaveAs->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_S);
338 mpaQuit =
new QAction(
"&Quit",
this);
340 mpaQuit->setShortcut(Qt::CTRL + Qt::Key_Q);
365 mpaExpandModel =
new QAction(
"Create array of compartments (debug version)",
this);
374 connect(mpaOpenSEDMLFiles, SIGNAL(activated()),
this, SLOT(slotFileExamplesSEDMLFiles()));
378 connect(mpaImportSEDML, SIGNAL(activated()),
this, SLOT(slotImportSEDML()));
382 connect(mpaExportSEDML, SIGNAL(activated()),
this, SLOT(slotExportSEDML()));
387 #ifdef WITH_MERGEMODEL
389 mpaAddModel->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_A);
390 connect(mpaAddModel, SIGNAL(activated()),
this, SLOT(slotAddFileOpen()));
392 mpaMergeModels =
new QAction(
"&Merge ...",
this);
393 mpaMergeModels->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_M);
394 connect(mpaMergeModels, SIGNAL(activated()),
this, SLOT(slotMergeModels()));
413 if (dbFile.isEmpty())
415 C_INT32 Answer = QMessageBox::No;
417 while (Answer == QMessageBox::No)
421 "untitled.cpk",
"COPASI Function DB (*.cpk)",
424 if (dbFile.isEmpty())
return;
429 if (Answer == QMessageBox::Cancel)
return;
443 if (dbFile.isEmpty())
447 QString::null,
"COPASI Function DB (*.cpk)",
451 if (!dbFile.isEmpty())
459 QToolBar * tb = addToolBar(
"MainToolBar");
471 #ifdef WITH_MERGEMODEL
472 tb->addAction(mpaAddModel);
480 items <<
"Concentrations" <<
"Particle Numbers";
486 setUnifiedTitleAndToolBarOnMac(
true);
492 QMenu * pFileMenu = menuBar()->addMenu(
"&File");
494 pFileMenu->addAction(
mpaNew);
508 pFileMenu->addSeparator();
516 pFileMenu->addSeparator();
517 mpMenuSEDMLSupport = pFileMenu->addMenu(
"SED-ML Support");
518 mpMenuSEDMLSupport->addAction(mpaImportSEDML);
519 mpMenuSEDMLSupport->addAction(mpaExportSEDML);
521 mpMenuRecentSEDMLFiles = mpMenuSEDMLSupport->addMenu(
"Recent SED-ML Files");
522 refreshRecentSEDMLFileMenu();
525 #ifdef WITH_MERGEMODEL
526 pFileMenu->addAction(mpaAddModel);
530 pFileMenu->addSeparator();
534 pFileMenu->addSeparator();
542 pFileMenu->addSeparator();
548 mpTools = menuBar()->addMenu(
"&Tools");
554 #ifdef WITH_MERGEMODEL
555 mpTools->addAction(mpaMergeModels);
563 #endif // COPASI_DEBUG
568 #ifdef WITH_PE_EVENT_CREATION
569 mpTools->addAction(
"&Create Events For Timeseries Experiment",
this, SLOT(slotCreateEventsForTimeseries()));
572 #ifdef COPASI_SBW_INTEGRATION
574 mpSBWMenu =
new QMenu(
"&SBW",
this);
575 mpSBWAction =
mpTools->addMenu(mpSBWMenu);
576 #endif // COPASI_SBW_INTEGRATION
589 menuBar()->addSeparator();
591 QMenu * help = menuBar()->addMenu(
"&Help");
594 help->addSeparator();
595 help->addAction(
"&About",
this, SLOT(
about()), Qt::Key_F1);
596 help->addAction(
"&License",
this, SLOT(
license()));
597 help->addAction(
"About &Qt",
this, SLOT(
aboutQt()));
598 help->addSeparator();
608 C_INT32 Answer = QMessageBox::No;
611 if (str.isEmpty()) str =
"untitled.cps";
614 qDebug() <<
"Filename on slotFileSaveAs = " << str;
617 while (Answer == QMessageBox::No)
621 str,
"COPASI Files (*.cps)",
622 "Choose a filename to save under");
624 if (tmp.isEmpty())
return;
627 qDebug() <<
"tmp = " << tmp;
633 if (Answer == QMessageBox::Cancel)
return;
638 setCursor(Qt::WaitCursor);
660 QString
Message(
"Problem while saving file!\n\n");
673 QMessageBox::Ok, QMessageBox::Ok);
682 QMessageBox::Ok | QMessageBox::Default,
683 QMessageBox::NoButton);
714 "The document contains unsaved changes\n"
715 "Do you want to save the changes before exiting?",
716 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
719 case QMessageBox::Save:
729 case QMessageBox::Discard:
732 case QMessageBox::Cancel:
759 mpaExportSEDML->setEnabled(
true);
782 std::string ImportSBML;
791 std::string ImportSEDML;
807 #ifdef COPASI_SBW_INTEGRATION
809 #endif // COPASI_SBW_INTEGRATION
821 QString newFile =
"";
826 "COPASI Files (*.gps *.cps);;All Files (*)",
833 if (!newFile.isNull())
840 "The document contains unsaved changes\n"
841 "Do you want to save the changes before exiting?",
842 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
845 case QMessageBox::Save:
855 case QMessageBox::Discard:
858 case QMessageBox::Cancel:
872 this->setCursor(Qt::WaitCursor);
890 QString Message =
"Error while loading file " +
mNewFile + QString(
"!\n\n");
894 QMessageBox::Ok, QMessageBox::Ok);
901 (msg.
getText().find(
"'sbml'") != std::string::npos || msg.
getText().find(
":sbml'") != std::string::npos))
907 if (
CQMessageBox::question(
this, QString(
"Import SBML?"), QString(
"You tried to open an SBML file. COPASI is not able to open SBML files but is able to import it. Would you like to import it?"),
908 QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes)
921 (msg.
getText().find(
"'sedML'") != std::string::npos || msg.
getText().find(
":sedML'") != std::string::npos))
927 if (
CQMessageBox::question(
this, QString(
"Import SED-ML?"), QString(
"You tried to open an SED-ML file. COPASI is not able to open SED-ML files but is able to import it. Would you like to import it?"),
928 QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes)
942 QString Message =
"Problem while loading file " +
mNewFile + QString(
"!\n\n");
955 QMessageBox::Ok, QMessageBox::Ok);
979 mpaExportSEDML->setEnabled(
true);
1006 #ifdef WITH_MERGEMODEL
1007 void CopasiUI3Window::slotAddFileOpen(QString file)
1016 QString newFile =
"";
1021 "COPASI Files (*.gps *.cps);;All Files (*)",
1026 if (!newFile.isNull())
1032 this->setCursor(Qt::WaitCursor);
1037 connect(
mpDataModelGUI, SIGNAL(finished(
bool)),
this, SLOT(slotAddFileOpenFinished(
bool)));
1042 void CopasiUI3Window::slotAddFileOpenFinished(
bool success)
1044 disconnect(
mpDataModelGUI, SIGNAL(finished(
bool)),
this, SLOT(slotAddFileOpenFinished(
bool)));
1050 QString Message =
"Error while loading file " +
mNewFile + QString(
"!\n\n");
1054 QMessageBox::Ok, QMessageBox::Ok);
1063 QString Message =
"Problem while merging file " +
mNewFile + QString(
"!\n\n");
1076 QMessageBox::Ok, QMessageBox::Ok);
1087 mpaExportSEDML->setEnabled(
true);
1117 if (!Line.compare(0, 8,
"Version=") ||
1118 strcasecmp(FileName.c_str(),
".gps") == 0)
1123 "Confirm File Version Update",
1124 "You are to overwrite an existing Gepasi File.\n"
1125 "This will render the file unreadable for Gepasi",
1126 QMessageBox::Save | QMessageBox::Ok | QMessageBox::Cancel,
this);
1128 MessageBox.setDefaultButton(QMessageBox::Save);
1129 MessageBox.button(QMessageBox::Save)->
setText(
"Save As");
1130 MessageBox.button(QMessageBox::Save)->
setText(
"Overwrite");
1132 int choice = MessageBox.exec();
1136 case QMessageBox::Save:
1140 case QMessageBox::Ok:
1143 case QMessageBox::Cancel:
1151 setCursor(Qt::WaitCursor);
1163 "Please stop them first before closing COPASI.");
1178 "The document contains unsaved changes\n"
1179 "Do you want to save the changes before exiting?",
1180 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
1183 case QMessageBox::Save:
1187 case QMessageBox::Discard:
1191 case QMessageBox::Cancel:
1230 std::string tempDir;
1245 .arg(LIBSBML_DOTTED_VERSION);
1249 aboutDialog->exec();
1256 aboutDialog->exec();
1261 QMessageBox::aboutQt(
this,
"Qt");
1293 preferenceDialog->setAttribute(Qt::WA_DeleteOnClose);
1294 preferenceDialog->setModal(
true);
1295 preferenceDialog->show();
1302 tutorialWizard->show();
1312 if (!sbmlDocumentText.empty())
1319 "The document contains unsaved changes\n"
1320 "Do you want to save the changes before exiting?",
1321 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
1324 case QMessageBox::Save:
1329 case QMessageBox::Discard:
1332 case QMessageBox::Cancel:
1349 setCursor(Qt::WaitCursor);
1364 QString Message =
"Error while importing SBML model!\n\n";
1368 QMessageBox::Ok, QMessageBox::Ok);
1416 QString::null,
"XML Files (*.xml);;All Files (*)",
1421 if (!SBMLFile.isNull())
1428 "The document contains unsaved changes\n"
1429 "Do you want to save the changes before exiting?",
1430 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
1433 case QMessageBox::Save:
1443 case QMessageBox::Discard:
1446 case QMessageBox::Cancel:
1465 setCursor(Qt::WaitCursor);
1481 QString Message =
"Error while loading file " +
mNewFile + QString(
"!\n\n");
1485 QMessageBox::Ok, QMessageBox::Ok);
1520 C_INT32 Answer = QMessageBox::No;
1522 bool exportIncomplete =
false;
1524 int sbmlVersion = 4;
1526 while (Answer == QMessageBox::No)
1528 QString Default = QString::null;
1539 Default =
"untitled.xml";
1551 std::pair<QString, std::pair<unsigned C_INT32, unsigned C_INT32> > nameAndVersion =
1553 "Choose a filename and SBML version for SBML export.",
1556 tmp = nameAndVersion.first;
1557 sbmlLevel = nameAndVersion.second.first;
1558 sbmlVersion = nameAndVersion.second.second;
1560 if (tmp.isEmpty())
return;
1565 if (Answer == QMessageBox::Cancel)
return;
1570 setCursor(Qt::WaitCursor);
1589 C_INT32 Answer = QMessageBox::No;
1593 assert(pDataModel != NULL);
1595 QString *userFilter =
new QString;
1597 while (Answer == QMessageBox::No)
1599 QString Default = QString::null;
1607 Default =
"untitled.c";
1612 "C Files (*.c);;Berkeley Madonna Files (*.mmd);;XPPAUT (*.ode)",
1613 "Choose an export format", userFilter);
1615 if (tmp.isEmpty())
return;
1618 qDebug() <<
"user's filter pointer = " << *userFilter;
1624 if (Answer == QMessageBox::Cancel)
return;
1629 setCursor(Qt::WaitCursor);
1645 QMessageBox::Ok | QMessageBox::Default,
1646 QMessageBox::NoButton);
1650 #ifdef WITH_PE_EVENT_CREATION
1651 void CopasiUI3Window::slotCreateEventsForTimeseries()
1657 if (model == NULL)
return;
1664 if (!model->createEventsForTimeseries())
1708 QMessageBox::Ok | QMessageBox::Default,
1709 QMessageBox::NoButton);
1751 QString filteredText;
1752 unsigned int numMessages = 0;
1753 unsigned int numFilteredMessages = 0;
1757 if (msg_pending.
getType() & 128)
1759 ++numFilteredMessages;
1760 filteredText +=
"\n";
1773 if (numFilteredMessages != 0)
1776 text =
"There were no serious issues encountered during the import of SBML. "
1777 "However some minor issues have occurred, which can be viewed in the Minor "
1781 QString(
"COPASI Message"), text, QMessageBox::Ok,
this);
1782 box.setDefaultButton(QMessageBox::Ok);
1789 QMessageBox::Ok, QMessageBox::Ok);
1799 #ifdef WIN32 // Windows allows mixing of '/' and '\' as separator.
1800 FileName.replace(
"\\",
"/");
1803 if (FileName.length() > 40)
1806 QRegExp mask(
"^(([A-Z]:/)?[^/]+/).*(/[^/]+/[^/]+$)");
1808 QRegExp mask(
"^((/*)[^/]+/).*(/[^/]+/[^/]+$)");
1811 mask.indexIn(FileName);
1812 FileName = mask.cap(1) +
"..." + mask.cap(3);
1815 std::string BaseName;
1817 if (!FileName.isEmpty())
1850 std::string FileName =
1860 std::string FileName =
1891 for (; it != end; ++it, ++Index)
1924 for (; it != end; ++it, ++Index)
1938 setCursor(Qt::WaitCursor);
1952 QString Message =
"Error while exporting SBML model!\n\n";
1956 QMessageBox::Ok, QMessageBox::Ok);
1974 int index =
mWindows.indexOf(pWindow);
2011 for (
int index = 1; index <
mWindows.count(); ++index)
2013 QMainWindow* mainWindow =
mWindows[index];
2015 if (mainWindow == NULL)
continue;
2020 menu->addAction(pAction);
2021 menu->addSeparator();
2023 menu->addSeparator();
2027 for (
int index = 1; index <
mWindows.count(); ++index)
2029 QMainWindow* mActionWindow =
mWindows[index];
2031 if (mActionWindow == NULL)
continue;
2036 for (
int index1 = 1; index1 <
mWindows.count(); ++index1)
2038 QMainWindow* mainWindow =
mWindows[index1];
2040 if (mainWindow == NULL)
continue;
2044 menu->addAction(pAction);
2052 for (
int index =
mWindows.count() - 1; index >= 1 ; --index)
2054 QMainWindow* window =
mWindows[index];
2068 window ->activateWindow();
2087 std::ostringstream ss;
2093 checkModelWindow->setWindowTitle(
"Check Model");
2094 checkModelWindow->textEdit->setText(
FROM_UTF8(ss.str()));
2096 checkModelWindow->show();
2102 QCursor oldCursor = cursor();
2103 setCursor(Qt::WaitCursor);
2107 setCursor(oldCursor);
2108 QString Message =
"Error while updating MIRIAM" + QString(
"!\n\n");
2111 QMessageBox::Ok, QMessageBox::Ok);
2130 setCursor(oldCursor);
2135 bool success =
true;
2201 C_INT32 Answer = QMessageBox::No;
2204 while (Answer == QMessageBox::No)
2207 "Save File Dialog",
"untitled.png",
"PNG Files (*.png)",
"Save Capture as PNG file");
2209 if (fileName.isEmpty())
return;
2214 if (Answer == QMessageBox::Cancel)
return;
2217 pixmap.save(fileName,
"PNG");
2228 qApp->setFont(Font);
2234 qApp->setStyleSheet(
" * {font : }");
2235 qApp->setStyleSheet(
" * {font : }");
2241 if (pTaskWidget != NULL)
2254 if (ApplicationFont ==
"")
2259 QFont Font = qApp->font();
2261 if (ApplicationFont ==
TO_UTF8(Font.toString()))
2269 Font.fromString(
FROM_UTF8(ApplicationFont));
2270 qApp->setFont(Font);
2274 qApp->setStyleSheet(
" * {font : }");
2275 qApp->setStyleSheet(
" * {font : }");
2288 #ifdef WITH_MERGEMODEL
2292 void CopasiUI3Window::slotMergeModels()
2307 #ifdef COPASI_SBW_INTEGRATION
2310 CopasiUI3Window::QSBWSBMLEvent::QSBWSBMLEvent(
const std::string & SBMLModel):
2311 QEvent((QEvent::Type)65433),
2315 const std::string & CopasiUI3Window::QSBWSBMLEvent::getSBMLModel()
const
2318 CopasiUI3Window::QSBWShutdownEvent::QSBWShutdownEvent():
2319 QEvent((QEvent::Type)65434)
2322 void CopasiUI3Window::registerMethods(SystemsBiologyWorkbench::MethodTable< CopasiUI3Window > & table)
2324 table.addMethod(&CopasiUI3Window::sbwAnalysis,
2325 "void doAnalysis(string)",
2327 "Imports a given SBML Model into CopasiUI.");
2329 table.addMethod(&CopasiUI3Window::sbwGetSBML,
2332 "Retrieves the currently in CopasiUI loaded model in SBML format.");
2336 void CopasiUI3Window::onShutdown()
2338 QApplication::postEvent(
this,
new QSBWShutdownEvent());
2344 switch ((
int) event->type())
2350 QSBWSBMLEvent *sbwEvent =
static_cast< QSBWSBMLEvent *
>(event);
2360 if (!mSBWIgnoreShutdownEvent)
2363 mSBWIgnoreShutdownEvent =
true;
2368 void CopasiUI3Window::sbwConnect()
2379 std::string Category(
"Analysis");
2380 std::string Description(
"COPASI Analyzer - Imports an SBML model into CopasiUI");
2383 new SystemsBiologyWorkbench::ModuleImpl(FullName, FullName,
2384 SystemsBiologyWorkbench::UniqueModule,
2387 mpSBWModule->addServiceObject(FullName, FullName, Category,
this, Description);
2390 SBW::addListener(
this);
2393 mpSBWModule->enableModuleServices();
2405 void CopasiUI3Window::sbwDisconnect()
2407 if (mpSBWModule != NULL)
2411 SBWLowLevel::disconnect();
2422 void CopasiUI3Window::sbwRegister()
2424 if (mpSBWModule != NULL)
2432 mpSBWModule->setCommandLine(Self);
2433 mpSBWModule->registerModule();
2443 void CopasiUI3Window::sbwUnregister(
const std::string & moduleName)
const
2447 SystemsBiologyWorkbench::Module Module = SBW::getModuleInstance(
"BROKER");
2448 SystemsBiologyWorkbench::Service Service = Module.findServiceByName(
"BROKER");
2450 DataBlockWriter Arguments;
2451 Arguments.add(moduleName);
2452 Service.getMethod(
"void unregisterModule(string)").call(Arguments);
2460 void CopasiUI3Window::sbwRefreshMenu()
2462 if (mpSBWMenu == NULL)
return;
2464 bool Visible =
true;
2465 bool IsSBWRegistered =
false;
2467 mSBWAnalyzerModules.clear();
2468 mSBWAnalyzerServices.clear();
2470 mSBWActionMap.clear();
2472 if (mpSBWActionGroup != NULL)
2474 disconnect(mpSBWActionGroup, SIGNAL(triggered(QAction *)),
this, SLOT(sbwSlotMenuTriggered(QAction *)));
2475 mpSBWActionGroup->deleteLater();
2476 mpSBWActionGroup = NULL;
2479 mpSBWActionGroup =
new QActionGroup(
this);
2480 connect(mpSBWActionGroup, SIGNAL(triggered(QAction *)),
this, SLOT(sbwSlotMenuTriggered(QAction *)));
2484 std::vector<DataBlockReader> Services = sbwFindServices(
"Analysis",
true);
2485 std::vector<DataBlockReader>::const_iterator it = Services.begin();
2486 std::vector<DataBlockReader>::const_iterator end = Services.end();
2488 QMap< QString, int > SortedNames;
2489 QStringList ModuleList;
2490 QStringList ServiceList;
2497 for (; it != end; ++it)
2499 SystemsBiologyWorkbench::ServiceDescriptor Service(*it);
2500 SystemsBiologyWorkbench::ModuleDescriptor Module = Service.getModuleDescriptor();
2502 std::string ModuleName = Module.getName();
2503 std::string ServiceName = Service.getName();
2504 std::string MenuName = Service.getDisplayName();
2507 if (ServiceName.compare(0, 6,
"COPASI") == 0)
2509 std::string CommandLine = Module.getCommandLine();
2512 if (CommandLine.compare(0, Self.length(), Self) == 0)
2518 sbwUnregister(ModuleName);
2519 return sbwRegister();
2522 IsSBWRegistered =
true;
2528 std::string::size_type Length = CommandLine.find(
" -sbwmodule");
2530 if (Length != std::string::npos)
2532 CommandLine = CommandLine.substr(0, Length);
2537 sbwUnregister(ModuleName);
2544 ModuleList.append(
FROM_UTF8(ModuleName));
2545 ServiceList.append(
FROM_UTF8(ServiceName));
2549 if (!IsSBWRegistered)
2551 QAction* pAction =
new QAction(
"Register", mpSBWActionGroup);
2552 mpSBWMenu->addAction(pAction);
2553 mSBWActionMap[pAction] = SortedNames.size();
2555 mpSBWMenu->addSeparator();
2558 QMap< QString, int >::const_iterator itMap = SortedNames.begin();
2559 QMap< QString, int >::const_iterator endMap = SortedNames.end();
2561 for (i = 0; itMap != endMap; ++itMap, i++)
2563 mSBWAnalyzerModules.append(ModuleList[itMap.value()]);
2564 mSBWAnalyzerServices.append(ServiceList[itMap.value()]);
2566 QAction* pAction =
new QAction(itMap.key(), mpSBWActionGroup);
2567 mpSBWMenu->addAction(pAction);
2568 mSBWActionMap[pAction] = i;
2571 if (mSBWAnalyzerModules.empty())
2581 mpTools->removeAction(mpSBWAction);
2586 void CopasiUI3Window::sbwSlotMenuTriggered(QAction * pAction)
2590 mSBWActionId = mSBWActionMap[pAction];
2592 if (mSBWActionId == mSBWAnalyzerModules.size())
2598 connect(
mpDataModelGUI, SIGNAL(finished(
bool)),
this, SLOT(sbwSlotMenuTriggeredFinished(
bool)));
2603 void CopasiUI3Window::sbwSlotMenuTriggeredFinished(
bool success)
2605 disconnect(
mpDataModelGUI, SIGNAL(finished(
bool)),
this, SLOT(sbwSlotMenuTriggeredFinished(
bool)));
2611 int nModule = SBWLowLevel::getModuleInstance(
TO_UTF8(mSBWAnalyzerModules[mSBWActionId]));
2612 int nService = SBWLowLevel::moduleFindServiceByName(nModule,
TO_UTF8(mSBWAnalyzerServices[mSBWActionId]));
2613 int nMethod = SBWLowLevel::serviceGetMethod(nModule, nService,
"void doAnalysis(string)");
2615 DataBlockWriter args;
2616 args << mSBWDocumentString;
2617 SBWLowLevel::methodSend(nModule, nService, nMethod, args);
2620 catch (SBWException * pE)
2624 QMessageBox::Ok | QMessageBox::Default,
2625 QMessageBox::NoButton);
2629 mSBWDocumentString =
"";
2632 std::vector< DataBlockReader > CopasiUI3Window::sbwFindServices(
const std::string & category,
2633 const bool & recursive)
2635 std::vector< DataBlockReader > result;
2639 DataBlockWriter oArguments;
2640 oArguments.add(category);
2641 oArguments.add(recursive);
2643 Module oModule = SBW::getModuleInstance(
"BROKER");
2644 Service oService = oModule.findServiceByName(
"BROKER");
2645 oService.getMethod(
"{}[] findServices(string, boolean)").call(oArguments) >> result;
2657 SystemsBiologyWorkbench::DataBlockWriter CopasiUI3Window::sbwAnalysis(SystemsBiologyWorkbench::Module , SystemsBiologyWorkbench::DataBlockReader reader)
2661 std::string sSBMLModel;
2662 reader >> sSBMLModel;
2664 QSBWSBMLEvent *
event =
new QSBWSBMLEvent(sSBMLModel);
2665 QApplication::postEvent(
this, event);
2670 throw new SystemsBiologyWorkbench::SBWApplicationException(
"Error in doAnalysis");
2674 return SystemsBiologyWorkbench::DataBlockWriter();
2677 SystemsBiologyWorkbench::DataBlockWriter CopasiUI3Window::sbwGetSBML(SystemsBiologyWorkbench::Module , SystemsBiologyWorkbench::DataBlockReader )
2679 connect(
mpDataModelGUI, SIGNAL(finished(
bool)),
this, SLOT(sbwSlotGetSBMLFinished(
bool)));
2681 QMutexLocker Locker(&mSBWMutex);
2682 mSBWCallFinished =
false;
2686 if (!mSBWCallFinished)
2688 mSBWWaitSlot.wait(&mSBWMutex);
2691 SystemsBiologyWorkbench::DataBlockWriter result;
2698 result << mSBWDocumentString;
2699 mSBWDocumentString =
"";
2706 throw new SystemsBiologyWorkbench::SBWApplicationException(
"Error getting the SBML.");
2710 throw new SystemsBiologyWorkbench::SBWApplicationException(
"Error getting the SBML.");
2716 void CopasiUI3Window::sbwSlotGetSBMLFinished(
bool success)
2718 QMutexLocker Locker(&mSBWMutex);
2720 mSBWCallFinished =
true;
2721 mSBWSuccess = success;
2723 mSBWWaitSlot.wakeAll();
2729 #endif // COPASI_SBW_INTEGRATION
2730 #include <QtCore/QUrl>
2733 if (event->mimeData()->hasFormat(
"text/uri-list"))
2734 event->acceptProposedAction();
2744 QFile file(fileName);
2746 if (!file.open(QIODevice::ReadOnly))
2749 for (
int i = 0; i < 5; ++i)
2751 QByteArray array = file.readLine();
2753 if (QString(array).contains(
"<sbml"))
2764 QList<QUrl> urls =
event->mimeData()->urls();
2769 QString fileName = urls.first().toLocalFile();
2771 if (fileName.isEmpty())
2779 slotImportSEDML(fileName);
2814 bool isProabablySEDML(QString &fileName)
2816 QFile file(fileName);
2818 if (!file.open(QIODevice::ReadOnly))
2821 for (
int i = 0; i < 5; ++i)
2823 QByteArray array = file.readLine();
2825 if (QString(array).contains(
"<sedML"))
2834 void CopasiUI3Window::slotFileExamplesSEDMLFiles(QString file)
2837 slotImportSEDML(file);
2839 void CopasiUI3Window::slotImportSEDMLFromStringFinished(
bool success)
2841 disconnect(
mpDataModelGUI, SIGNAL(finished(
bool)),
this, SLOT(slotImportSEDMLFromStringFinished(
bool)));
2847 QString Message =
"Error while importing SED-ML model!\n\n";
2851 QMessageBox::Ok, QMessageBox::Ok);
2885 void CopasiUI3Window::slotImportSEDMLFinished(
bool success)
2887 disconnect(
mpDataModelGUI, SIGNAL(finished(
bool)),
this, SLOT(slotImportSEDMLFinished(
bool)));
2893 QString Message =
"Error while loading file " +
mNewFile + QString(
"!\n\n");
2897 QMessageBox::Ok, QMessageBox::Ok);
2910 mpaExportSEDML->setEnabled(
true);
2919 refreshRecentSEDMLFileMenu();
2927 void CopasiUI3Window::slotImportSEDML(QString file)
2929 disconnect(
this, SIGNAL(
signalLoadFile(QString)),
this, SLOT(slotImportSEDML(QString)));
2941 QString::null,
"SED-ML files (*.sedml *.xml);;All Files (*)",
2946 if (!SEDMLFile.isNull())
2953 "The document contains unsaved changes\n"
2954 "Do you want to save the changes before exiting?",
2955 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
2958 case QMessageBox::Save:
2959 connect(
this, SIGNAL(
signalLoadFile(QString)),
this, SLOT(slotImportSEDML(QString)));
2968 case QMessageBox::Discard:
2971 case QMessageBox::Cancel:
2990 setCursor(Qt::WaitCursor);
2991 connect(
mpDataModelGUI, SIGNAL(finished(
bool)),
this, SLOT(slotImportSEDMLFinished(
bool)));
2998 void CopasiUI3Window::refreshRecentSEDMLFileMenu()
3000 mpMenuRecentSEDMLFiles->clear();
3002 mRecentSEDMLFilesActionMap.clear();
3004 if (mpRecentSEDMLFilesActionGroup != NULL)
3006 disconnect(mpRecentSEDMLFilesActionGroup, SIGNAL(triggered(QAction *)),
this, SLOT(slotOpenRecentSEDMLFile(QAction *)));
3007 mpRecentSEDMLFilesActionGroup->deleteLater();
3008 mpRecentSEDMLFilesActionGroup = NULL;
3011 mpRecentSEDMLFilesActionGroup =
new QActionGroup(
this);
3012 connect(mpRecentSEDMLFilesActionGroup, SIGNAL(triggered(QAction *)),
this, SLOT(slotOpenRecentSEDMLFile(QAction *)));
3023 for (; it != end; ++it, ++Index)
3025 pAction =
new QAction(
FROM_UTF8(*(*it)->getValue().pSTRING), mpRecentSEDMLFilesActionGroup);
3026 mpMenuRecentSEDMLFiles->addAction(pAction);
3027 mRecentSEDMLFilesActionMap[pAction] = Index;
3032 void CopasiUI3Window::exportSEDMLToString(std::string & SEDML)
3038 setCursor(Qt::WaitCursor);
3039 connect(
mpDataModelGUI, SIGNAL(finished(
bool)),
this, SLOT(slotExportSEDMLToStringFinished(
bool)));
3045 void CopasiUI3Window::slotExportSEDMLToStringFinished(
bool success)
3048 disconnect(
mpDataModelGUI, SIGNAL(finished(
bool)),
this, SLOT(slotExportSEDMLToStringFinished(
bool)));
3052 QString Message =
"Error while exporting SED-ML model!\n\n";
3056 QMessageBox::Ok, QMessageBox::Ok);
3061 void CopasiUI3Window::slotExportSEDMLFinished(
bool )
3063 disconnect(
mpDataModelGUI, SIGNAL(finished(
bool)),
this, SLOT(slotExportSEDMLFinished(
bool)));
3067 refreshRecentSEDMLFileMenu();
3070 void CopasiUI3Window::slotExportSEDML()
3074 C_INT32 Answer = QMessageBox::No;
3076 bool exportIncomplete =
false;
3078 int sedmlVersion = 2;
3080 while (Answer == QMessageBox::No)
3082 QString Default = QString::null;
3093 Default =
"untitled.sedml";
3105 std::pair<QString, std::pair<unsigned C_INT32, unsigned C_INT32> > nameAndVersion =
3107 "Choose a filename and SED-ML version for SED-ML export.",
3110 tmp = nameAndVersion.first;
3111 sedmlLevel = nameAndVersion.second.first;
3112 sedmlVersion = nameAndVersion.second.second;
3114 if (tmp.isEmpty())
return;
3119 if (Answer == QMessageBox::Cancel)
return;
3124 setCursor(Qt::WaitCursor);
3125 connect(
mpDataModelGUI, SIGNAL(finished(
bool)),
this, SLOT(slotExportSEDMLFinished(
bool)));
3130 void CopasiUI3Window::slotOpenRecentSEDMLFile(QAction * pAction)
3132 int index = mRecentSEDMLFilesActionMap[pAction];
3134 std::string FileName =
ObjectBrowserDialog * mpObjectBrowser
void slotApplyInitialState()
static const CCopasiMessage & peekLastMessage()
const QList< QPointer< QMainWindow > > & getWindows() const
static bool remove(const std::string &path)
QActionGroup * mpWindowsActionGroup
void setApplicationFont()
static const char * getLicenseHTML()
virtual QMenu * getWindowMenu() const =0
QAction * mpaUpdateInitialState
void slotFileOpen(QString file=QString::null)
static void setMIRIAMResources(const CMIRIAMResources *pResources)
void importSBML(const std::string &fileName)
CopasiWidget * getCurrentWidget()
void listViewsFolderChanged(const QModelIndex &index)
QAction * mpaFontSelectionDialog
QMenu * mpMenuRecentFiles
void setFramework(int index)
void switchToOtherWidget(const size_t &id, const std::string &key)
bool updateMIRIAM(CMIRIAMResources &miriamResources)
QActionGroup * mpRecentSBMLFilesActionGroup
void loadFunctionDB(const std::string &fileName)
bool notify(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
QAction * mpaFunctionDBLoad
void setFilteredText(const QString &text)
QAction * mpaOpenSBMLFiles
void suspendAutoSave(const bool &suspend)
QSharedPointer< QFont > getFont(const CLText *item, const CLGroup *group, const CLRenderResolver *, const CLBoundingBox *pBB)
virtual void setCopasiMainWindow(QWidget *copasiMainWindow)
static bool isMainThread()
const std::string & getText() const
void loadModel(const std::string &fileName)
void slotExportMathModel()
void slotExportMathModelFinished(bool success)
void slotFunctionDBSave(QString str=QString::null)
void slotShowSliders(bool flag)
static std::pair< QString, std::pair< unsigned C_INT32, unsigned C_INT32 > > getSaveFileName(QWidget *parent, const char *name, const QString &startWith, const QString &caption, unsigned int sedmlLevel=1, unsigned int sedmlVersion=2)
void updateNonSimulatedValues(void)
QComboBox * mpBoxSelectFramework
void setInitialState(const CState &state)
const std::string getApplicationFont() const
static std::string getAllMessageText(const bool &chronological=true)
const size_t & getNumber() const
virtual void closeEvent(QCloseEvent *e)
void openInitialDocument(const QString &file)
QMenu * mpMenuRecentSBMLFiles
void exportSBML(const std::string &fileName, bool overwriteFile, int sbmlLevel, int sbmlVersion, bool exportIncomplete, bool exportCOPASIMIRIAM=true)
bool mSliderDialogEnabled
void disableSliders(bool disable)
index_iterator endIndex() const
CRecentFiles & getRecentFiles()
QAction * mpaObjectBrowser
QAction * mpaCloseAllWindows
static bool removeFiles(const std::string &pattern, const std::string &dir)
static StandardButton information(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
void slotUpdateInitialState()
QAction * mpaFunctionDBSave
void slotTutorialWizard()
void importSBMLFromString(const std::string &sbmlDocumentText)
QActionGroup * mpRecentFilesActionGroup
void slotObjectBrowserDialogWasClosed()
static CopasiUI3Window * getMainWindow()
static std::string baseName(const std::string &path)
void applyInitialValues()
void refreshRecentSBMLFileMenu()
void slotOpenRecentSBMLFile(QAction *pAction)
void setText(const QString &text)
static CopasiUI3Window * pMainWindow
void slotFunctionDBLoad(QString str=QString::null)
static std::string dirName(const std::string &path)
static void openExampleDir()
void setCurrentFolderId(size_t id)
void addWindow(QMainWindow *pWindow)
void slotFileSaveAs(QString str=QString::null)
const std::string & getFileName() const
static const nonOptionType & getNonOptions()
void slotExportSBMLFinished(bool success)
static StandardButton warning(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
static CConfigurationFile * getConfiguration()
void slotOpenRecentFile(QAction *pAction)
static bool compareValue(const std::string &name, const CType &value)
static CopasiUI3Window * create()
void slotActivateWindowTriggered(QAction *action)
const CCopasiMessage::Type & getType() const
void slotCloseAllWindows()
void slotImportSBMLFromStringFinished(bool success)
void saveFunctionDB(const std::string &fileName)
static bool exist(const std::string &path)
void slotFileOpenFinished(bool success)
static const std::string Separator
bool isProabablySBML(QString &fileName)
index_iterator beginIndex() const
Header file of class AboutDialog.
C_INT32 checkSelection(const QString &file)
static const QIcon & icon(const IconID &id)
void setChanged(bool changed)
void customEvent(QEvent *)
void setFramework(int framework)
void setParentWindow(CopasiUI3Window *pPW)
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
static bool isWritable(const std::string &path)
static QString getOpenFileName(QWidget *parent=0, const char *name=0, const QString &startWith=QString::null, const QString &filter=QString::null, const QString &caption=QString::null, QString *pSelectedFilter=NULL, QFileDialog::Options options=0)
void checkPendingMessages()
CRecentFiles & getRecentSBMLFiles()
CRecentFiles & getRecentSEDMLFiles()
void setApplicationFont(const std::string &applicationFont)
QMainWindow * getWindowByTitle(const QList< QPointer< QMainWindow > > &list, const QString &title)
void deregisterListView(ListViews *pListView)
void slotFileSaveFinished(bool success)
static void getValue(const std::string &name, CType &value)
QMap< QAction *, int > mRecentFilesActionMap
void refreshWindowsMenu()
void saveModel(const std::string &fileName, bool overwriteFile=false)
const bool & messageShown() const
QAction * mpaOpenCopasiFiles
static StandardButton critical(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
void exportSBMLToString(std::string &sbmlDocumentText)
void slotQuitFinished(bool success)
bool compileIfNecessary(CProcessReport *pProcessReport)
void exportSBMLToString(std::string &SBML)
void dropEvent(QDropEvent *event)
void slotConvertToIrreversible()
QAction * mpaApplyInitialState
void slotFileExamplesCopasiFiles(QString file=QString::null)
QAction * mpaUpdateMIRIAM
static CCopasiMessage getLastMessage()
ListViews * getMainWidget()
void registerListView(ListViews *pListView)
void signalLoadFile(QString newFile)
DataModelGUI * mpDataModelGUI
bool updateInitialValues()
const CCopasiParameter::Value & getValue(const std::string &name) const
DataModelGUI * getDataModel()
void slotFileExamplesSBMLFiles(QString file=QString::null)
void setMessageShown(const bool &shown)
QMap< QAction *, int > mRecentSBMLFilesActionMap
void importSBMLFromString(const std::string &sbmlDocumentText)
bool convert2NonReversible()
CCopasiParameterGroup * getGroup(const std::string &name)
void slotFrameworkChanged(int index)
void exportMathModel(const std::string &fileName, const std::string &filter, bool overwriteFile=false)
const CState & getState() const
static CLocaleString fromUtf8(const std::string &utf8)
void slotExportSBMLToStringFinished(bool success)
static std::pair< QString, std::pair< unsigned C_INT32, unsigned C_INT32 > > getSaveFileName(QWidget *parent, const char *name, const QString &startWith, const QString &caption, unsigned int sbmlLevel=2, unsigned int sbmlVersion=4)
void slotUpdateMIRIAMFinished(bool)
void updateMIRIAMResourceContents()
void dragEnterEvent(QDragEnterEvent *event)
void writeReport(std::ostream &os, bool rt, bool verbose) const
parameterGroup::iterator index_iterator
void slotImportSBML(QString file=QString::null)
static std::string suffix(const std::string &path)
virtual void updateAllSliders()
void slotShowObjectBrowserDialog(bool flag)
void slotImportSBMLFinished(bool success)
static StandardButton question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
static QString getSaveFileName(QWidget *parent=0, const char *name=0, const QString &startWith=QString::null, const QString &filter=QString::null, const QString &caption=QString::null, QString *pSelectedFilter=NULL, QFileDialog::Options options=0)
void refreshRecentFileMenu()
size_t getCurrentItemId()
void removeWindow(QMainWindow *pWindow)
QList< QPointer< QMainWindow > > mWindows
static const CVersion VERSION