COPASI API  4.16.103
DataModelGUI.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2015 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2004 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #include <cmath>
16 
17 #include "copasi.h"
18 
19 #include "DataModelGUI.h"
20 #include "DataModel.txt.h"
21 #include "CQThread.h"
22 #include "qtUtilities.h"
23 #include "utilities/CVector.h"
24 #include "CProgressBar.h"
25 #include "listviews.h"
26 #include "CQMessageBox.h"
27 #include "CQBrowserPaneDM.h"
28 
29 #include "function/CFunctionDB.h"
30 #include "model/CModel.h"
31 #include "model/CModelValue.h"
36 #include "scan/CScanTask.h"
38 #include "steadystate/CMCATask.h"
39 #include "lna/CLNATask.h"
41 #include "tssanalysis/CTSSATask.h"
42 
47 #include "utilities/CCopasiTree.h"
48 
49 //#include "model/CModelMerging.h"
50 #include "model/CModelExpansion.h"
51 
52 #define USE_LAYOUT 1
53 #define USE_RENDER 1
54 
55 #include <sbml/SBMLDocument.h>
56 #include <sbml/packages/render/sbml/RenderPoint.h>
57 #include <sbml/packages/render/sbml/Text.h>
58 #include <sbml/packages/layout/sbml/LineSegment.h>
59 
60 #include "layout/CLayout.h"
61 #include "layout/CListOfLayouts.h"
64 #include "sbml/SBMLUtils.h"
65 
66 #if LIBSBML_VERSION >= 50400
67 #include <sbml/packages/layout/extension/LayoutModelPlugin.h>
68 #endif
69 
70 #include <QByteArray>
71 #include <QNetworkAccessManager>
72 #include <QNetworkRequest>
73 #include <QNetworkReply>
74 
76 
77 //*****************************************************************************
78 
79 DataModelGUI::DataModelGUI(QObject * parent):
80  QObject(parent),
81  mpApp(NULL),
82  mOutputHandlerPlot(),
83  mListViews(),
84  mFramework(0),
85  mUpdateVector(),
86  mChangedObjects(),
87  mpThread(NULL),
88  mpProgressBar(NULL),
89  mSuccess(false),
90  mSBMLImportString(),
91  mpSBMLExportString(NULL),
92  mFileName(),
93  mOverWrite(false),
94  mSBMLLevel(2),
95  mSBMLVersion(4),
96  mSBMLExportIncomplete(true),
97  mSBMLExportCOPASIMIRIAM(true),
98  mExportFormat()
99 
100 #ifdef COPASI_SEDML
101  , mSEDMLImportString()
102  , mpSEDMLExportString(NULL)
103  , mSEDMLLevel(1)
104  , mSEDMLVersion(1)
105  , mSEDMLExportIncomplete(true)
106  , mSEDMLExportCOPASIMIRIAM(true)
107 #endif
108 
109 {
110  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
112 
113  //mpMathModel = NULL;
114  //mMathModelUpdateScheduled = false;
115 }
116 
118 {
119 }
120 
121 //************************************************************
122 
124 {
125  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
127  assert(pDataModel != NULL);
128 
129  std::set< ListViews * >::iterator it = mListViews.begin();
130  std::set< ListViews * >::iterator end = mListViews.end();
131 
132  for (; it != end; ++it)
133  {
134  (*it)->setDataModel(this);
135  }
136 
137  pDataModel->deleteOldData();
138 }
139 
140 //*****************************************************************
141 
142 //*****************************************************************
143 #ifdef WITH_MERGEMODEL
144 
145 void DataModelGUI::addModel(const std::string & fileName)
146 {
148 
149  mSuccess = true;
150  mFileName = fileName;
151 
152  mpThread = new CQThread(this, &DataModelGUI::addModelRun);
153  connect(mpThread, SIGNAL(finished()), this, SLOT(addModelFinished()));
154  mpThread->start();
155 }
156 
157 void DataModelGUI::addModelRun()
158 {
159  try
160  {
161  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
163  }
164 
165  catch (...)
166  {
167  mSuccess = false;
168  }
169 
170  CModel *pModel = (*CCopasiRootContainer::getDatamodelList())[0]->getModel();
171  CModel *pMergeModel = (*CCopasiRootContainer::getDatamodelList())[1]->getModel();
172 
173  //CModelAdd add(pModel, mModel);
174  //add.simpleCall();
175 
176  if (mSuccess && pModel && pMergeModel)
177  {
178  CModelExpansion expand(pModel);
179  (*CCopasiRootContainer::getDatamodelList())[0]->mLastAddedObjects = expand.copyCompleteModel(pMergeModel);
180  }
181 }
182 
183 void DataModelGUI::addModelFinished()
184 {
185  if (mSuccess)
186  {
187  //notify(ListViews::MODEL, ListViews::CHANGE, "");
188 
190  //linkDataModelToGUI();
191  }
192 
193  disconnect(mpThread, SIGNAL(finished()), this, SLOT(addModelFinished()));
194 
195  threadFinished();
196 }
197 
198 #endif
199 
201 {
202  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
203 
204  if (!(*CCopasiRootContainer::getDatamodelList())[0]->newModel(NULL, false)) return false;
205 
207 
209  return true;
210 }
211 
212 void DataModelGUI::loadModel(const std::string & fileName)
213 {
215 
216  mSuccess = true;
217  mFileName = fileName;
218 
220  connect(mpThread, SIGNAL(finished()), this, SLOT(loadModelFinished()));
221  mpThread->start();
222 }
223 
225 {
226  try
227  {
228  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
230  }
231 
232  catch (...)
233  {
234  mSuccess = false;
235  }
236 }
237 
239 {
240  if (mSuccess)
241  {
243 
246  }
247 
248  disconnect(mpThread, SIGNAL(finished()), this, SLOT(loadModelFinished()));
249 
250  threadFinished();
251 }
252 
253 void DataModelGUI::saveModel(const std::string & fileName, bool overwriteFile)
254 {
256 
257  mSuccess = true;
258  mFileName = fileName;
259  mOverWrite = overwriteFile;
260 
262  connect(mpThread, SIGNAL(finished()), this, SLOT(saveModelFinished()));
263  mpThread->start();
264 }
265 
267 {
268  try
269  {
270  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
272  }
273 
274  catch (...)
275  {
276  mSuccess = false;
277  }
278 }
279 
281 {
282  if (mSuccess)
284 
285  disconnect(mpThread, SIGNAL(finished()), this, SLOT(saveModelFinished()));
286 
287  threadFinished();
288 }
289 
290 void DataModelGUI::importSBMLFromString(const std::string & sbmlDocumentText)
291 {
293 
294  mSuccess = true;
295  mSBMLImportString = sbmlDocumentText;
296 
298  connect(mpThread, SIGNAL(finished()), this, SLOT(importSBMLFromStringFinished()));
299  mpThread->start();
300 }
301 
303 {
304  try
305  {
306  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
308  }
309 
310  catch (...)
311  {
312  mSuccess = false;
313  }
314 }
315 
317 {
318  mSBMLImportString = "";
319 
320  if (mSuccess)
321  {
322  // can't run this in a separate thread because it uses GUI routines
323  // TODO maybe put the main part of this routine in a separate thread after
324  // TODO asking the user
325  this->importCellDesigner();
328  }
329 
330  disconnect(mpThread, SIGNAL(finished()), this, SLOT(importSBMLFromStringFinished()));
331 
332  threadFinished();
333 }
334 
335 void DataModelGUI::saveFunctionDB(const std::string & fileName)
336 {
338 
339  if (pFunctionDB == NULL) return;
340 
341  pFunctionDB->save(fileName);
342 }
343 
344 void DataModelGUI::loadFunctionDB(const std::string & fileName)
345 {
347 
348  if (pFunctionDB == NULL) return;
349 
350  if (pFunctionDB->load(fileName))
352 }
353 
354 void DataModelGUI::importSBML(const std::string & fileName)
355 {
357 
358  mSuccess = true;
359  mFileName = fileName;
361  connect(mpThread, SIGNAL(finished()), this, SLOT(importSBMLFinished()));
362  mpThread->start();
363 }
364 
366 {
367  try
368  {
369  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
371  }
372 
373  catch (...)
374  {
375  mSuccess = false;
376  }
377 }
378 
380 {
381  if (mSuccess)
382  {
383  this->importCellDesigner();
385 
388  }
389 
390  disconnect(mpThread, SIGNAL(finished()), this, SLOT(importSBMLFinished()));
391 
392  threadFinished();
393 }
394 
395 void DataModelGUI::exportSBMLToString(std::string & sbmlDocumentText)
396 {
398 
399  mSuccess = true;
400  mpSBMLExportString = & sbmlDocumentText;
401 
403  connect(mpThread, SIGNAL(finished()), this, SLOT(exportSBMLToStringFinished()));
404  mpThread->start();
405 }
406 
408 {
409  try
410  {
411  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
413  }
414 
415  catch (...)
416  {
417  mSuccess = false;
418  }
419 }
420 
422 {
423  disconnect(mpThread, SIGNAL(finished()), this, SLOT(exportSBMLToStringFinished()));
424 
425  threadFinished();
426 }
427 
429 {
430  if (mpThread != NULL)
431  {
432  mpThread->deleteLater();
433  mpThread = NULL;
434  }
435 
436  if (mpProgressBar != NULL)
437  {
439  mpProgressBar->deleteLater();
440  mpProgressBar = NULL;
441  }
442 
443  emit finished(mSuccess);
444 }
445 
446 void DataModelGUI::exportSBML(const std::string & fileName, bool overwriteFile, int sbmlLevel, int sbmlVersion, bool exportIncomplete, bool exportCOPASIMIRIAM)
447 {
449 
450  mSuccess = true;
451  mFileName = fileName;
452  mOverWrite = overwriteFile;
453  mSBMLLevel = sbmlLevel;
454  mSBMLVersion = sbmlVersion;
455  mSBMLExportIncomplete = exportIncomplete;
456  mSBMLExportCOPASIMIRIAM = exportCOPASIMIRIAM;
457 
459  connect(mpThread, SIGNAL(finished()), this, SLOT(exportSBMLFinished()));
460  mpThread->start();
461 }
462 
464 {
465  try
466  {
467  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
469  }
470 
471  catch (...)
472  {
473  mSuccess = false;
474  }
475 }
476 
478 {
479  if (mSuccess)
481 
482  disconnect(mpThread, SIGNAL(finished()), this, SLOT(exportSBMLFinished()));
483 
484  threadFinished();
485 }
486 
487 void DataModelGUI::exportMathModel(const std::string & fileName, const std::string & filter, bool overwriteFile)
488 {
490 
491  mSuccess = true;
492  mFileName = fileName;
493  mOverWrite = overwriteFile;
494  mExportFormat = filter;
495 
497  connect(mpThread, SIGNAL(finished()), this, SLOT(exportMathModelFinished()));
498  mpThread->start();
499 }
500 
502 {
503  try
504  {
505  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
507  }
508 
509  catch (...)
510  {
511  mSuccess = false;
512  }
513 }
514 
516 {
517  disconnect(mpThread, SIGNAL(finished()), this, SLOT(exportMathModelFinished()));
518 
519  threadFinished();
520 }
521 
522 void DataModelGUI::miriamDownloadFinished(QNetworkReply* reply)
523 {
524  bool success = true;
525  mDownloadedBytes = 100;
527 
528  CMIRIAMResources & miriamResources = *mpMiriamResources;
529 
530  if (reply != NULL && reply->error() == QNetworkReply::NoError)
531  {
532  std::string filename;
533  COptions::getValue("ConfigDir", filename);
534  filename += "/miriam.xml";
535 
536  QFile *miriamFile = new QFile(filename.c_str());
537 
538  if (miriamFile->open(QFile::WriteOnly))
539  {
540  miriamFile->write(reply->readAll());
541  miriamFile->flush();
542  miriamFile->close();
543  success = miriamResources.updateMIRIAMResourcesFromFile(mpProgressBar, filename);
544  }
545 
546  delete miriamFile;
547  }
548  else
549  {
550  success = false;
551  }
552 
553  reply->deleteLater();
554 
556 
557  // notify UI to pick up
558  emit finished(success);
559 }
560 
561 void DataModelGUI::miriamDownloadProgress(qint64 received, qint64 total)
562 {
563  if (total != -1)
564  {
565  mDownloadedBytes = 100 * double(received) / double(total);
566  }
567  else
568  {
570  }
571 
573  {
574  QNetworkReply *reply = dynamic_cast<QNetworkReply*>(sender());
575 
576  if (reply != NULL) reply->abort();
577  }
578 }
579 
581 {
582  bool success = true;
583 
584  mpMiriamResources = &miriamResources;
585 
587  mpProgressBar->setName("MIRIAM Resources Update...");
589  mUpdateItem = ((CProcessReport*)mpProgressBar)->addItem("Download MIRIAM info", mDownloadedBytes, &mDownloadedTotalBytes);
590 
591  QNetworkAccessManager *manager = new QNetworkAccessManager(this);
592 
593  connect(manager, SIGNAL(finished(QNetworkReply*)),
594  this, SLOT(miriamDownloadFinished(QNetworkReply*)));
595 
596  QNetworkReply* reply = manager->get(QNetworkRequest(QUrl("http://www.ebi.ac.uk/miriam/main/export/xml/")));
597  connect(reply, SIGNAL(downloadProgress(qint64, qint64)),
598  this, SLOT(miriamDownloadProgress(qint64, qint64)));
599 
600  return success;
601 }
602 
603 //************** QApplication ***********************************************
604 
605 //************Model-View Architecture*****************************************
606 
608 {
609  // The GUI is inactive whenever a progress bar exist. We wait with updates
610  // until then.
611  if (mpProgressBar != NULL) return false;
612 
613  // update all initial value
614  if (action != ListViews::RENAME)
616 
617  emit notifyView(objectType, action, key);
618 
619  return true;
620 }
621 
623 {
624  pListView->setDataModel(this);
625  mListViews.insert(pListView);
626 }
627 
629 {
630  pListView->setDataModel(NULL);
631  mListViews.erase(pListView);
632 }
633 
635 {
636  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
637  CModel * pModel = (*CCopasiRootContainer::getDatamodelList())[0]->getModel();
638  pModel->compileIfNecessary(NULL);
639 
640  mChangedObjects.clear();
641 
642  CModelEntity ** ppEntity = pModel->getStateTemplate().getEntities();
643  CModelEntity ** ppEntityEnd = pModel->getStateTemplate().endFixed();
644 
645  CMetab * pMetab;
646  std::set< const CCopasiObject * > Objects;
647 
648  // The objects which are changed are all initial values of of all model entities including
649  // fixed and unused once. Additionally, all kinetic parameters are possibly changed.
650  // This is basically all the parameters in the parameter overview whose value is editable.
651 
652  // :TODO: Theoretically, it is possible that also task parameters influence the initial
653  // state of a model but that is currently not handled.
654 
655  for (; ppEntity != ppEntityEnd; ++ppEntity)
656  {
657  // If we have an initial expression we have no initial values
658  if ((*ppEntity)->getInitialExpression() != "" ||
659  (*ppEntity)->getStatus() == CModelEntity::ASSIGNMENT)
660  continue;
661 
662  // Metabolites have two initial values
663  if (mFramework == 0 &&
664  (pMetab = dynamic_cast< CMetab * >(*ppEntity)) != NULL)
665  {
666  // The concentration is assumed to be fix accept when this would lead to circular dependencies,
667  // for the parent's compartment's initial volume.
668  if (pMetab->isInitialConcentrationChangeAllowed() &&
669  !isnan(pMetab->getInitialConcentration()))
671  else
672  mChangedObjects.insert(pMetab->getInitialValueReference());
673  }
674  else
675  mChangedObjects.insert((*ppEntity)->getInitialValueReference());
676  }
677 
678  // The reaction parameters
681  size_t i, imax;
682 
683  for (; itReaction != endReaction; ++itReaction)
684  {
685  const CCopasiParameterGroup & Group = (*itReaction)->getParameters();
686 
687  for (i = 0, imax = Group.size(); i < imax; i++)
688  mChangedObjects.insert(static_cast< const CCopasiObject * >(Group.getParameter(i)->getObject(CCopasiObjectName("Reference=Value"))));
689  }
690 
691  // Fix for Issue 1170: We need to add elements of the stoichiometry, reduced stoichiometry,
692  // and link matrices.
693  const CArrayAnnotation * pMatrix = NULL;
694  pMatrix = dynamic_cast<const CArrayAnnotation *>(pModel->getObject(std::string("Array=Stoichiometry(ann)")));
695 
696  if (pMatrix != NULL)
698 
699  pMatrix = dynamic_cast<const CArrayAnnotation *>(pModel->getObject(std::string("Array=Reduced stoichiometry(ann)")));
700 
701  if (pMatrix != NULL)
703 
704  pMatrix = dynamic_cast<const CArrayAnnotation *>(pModel->getObject(std::string("Array=Link matrix(ann)")));
705 
706  if (pMatrix != NULL)
708 
709  try
710  {
712  }
713 
714  catch (...)
715  {
716  QString Message = "Error while updating the initial values!\n\n";
717  Message += FROM_UTF8(CCopasiMessage::getLastMessage().getText());
718 
719  CQMessageBox::critical(NULL, QString("COPASI Error"), Message,
720  QMessageBox::Ok, QMessageBox::Ok);
722 
723  mUpdateVector.clear();
724  return;
725  }
726 }
727 
729 {
731 
732  std::vector< Refresh * >::iterator it = mUpdateVector.begin();
733  std::vector< Refresh * >::iterator end = mUpdateVector.end();
734 
735  for (; it != end; ++it)
736  (**it)();
737 
738  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
739  CModel * pModel = (*CCopasiRootContainer::getDatamodelList())[0]->getModel();
740 
741  pModel->refreshActiveParameterSet();
742 }
743 
744 void DataModelGUI::setFramework(int framework)
745 {
746  mFramework = framework;
747 
748  std::set< ListViews * >::iterator it = mListViews.begin();
749  std::set< ListViews * >::iterator end = mListViews.end();
750 
751  for (; it != end; ++it)
752  {
753  (*it)->setFramework(mFramework);
754  }
755 }
756 
758 {
759  std::set< ListViews * >::iterator it = mListViews.begin();
760  std::set< ListViews * >::iterator end = mListViews.end();
761 
762  for (; it != end; ++it)
763  {
764  (*it)->updateMIRIAMResourceContents();
765  }
766 }
767 
769 {
770  std::set< ListViews * >::iterator it = mListViews.begin();
771  std::set< ListViews * >::iterator end = mListViews.end();
772 
773  for (; it != end; ++it)
774  {
775  (*it)->commit();
776  }
777 }
778 
779 /**
780  * This method tries to import CellDesigner annotations.
781  */
783 {
784  // add code to check for CellDesigner annotations
785  // ask the user if the annotations should be imported
787  assert(pDataModel != NULL);
788 
789  if (pDataModel != NULL)
790  {
791  SBMLDocument* pSBMLDocument = pDataModel->getCurrentSBMLDocument();
792 
793  if (pSBMLDocument != NULL &&
794  pSBMLDocument->getModel() != NULL &&
795  pSBMLDocument->getModel()->getAnnotation() != NULL)
796  {
797  // check for the CellDesigner namespace
798  std::pair<bool, std::string> foundNamespace = CCellDesignerImporter::findCellDesignerNamespace(pSBMLDocument);
799 
800  if (foundNamespace.first == true)
801  {
802  const XMLNode* pAnno = CCellDesignerImporter::findCellDesignerAnnotation(pSBMLDocument, pSBMLDocument->getModel()->getAnnotation());
803 
804  // first we check if there are supported cell designer annotations
805  if (pAnno != NULL)
806  {
807  // check if the file contains the correct version
808  double version = CCellDesignerImporter::determineVersion(pAnno);
809 
810  if (version < 4.0)
811  {
812  CCopasiMessage(CCopasiMessage::RAW, "CellDesigner annotation was found in the file, but the version is not supported.\nPlease open the file in the latest version of CellDesigner and save it again.");
813  }
814  else
815  {
816  bool importCD = false;
817 #if LIBSBML_VERSION >= 50400
818  // if we don't have a layout import it!
819  LayoutModelPlugin* mplugin = (LayoutModelPlugin*)pSBMLDocument->getModel()->getPlugin("layout");
820 
821  if (mplugin == NULL || (mplugin != NULL && mplugin->getNumLayouts() == 0))
822  importCD = true;
823 
824 #endif
825 
826  // ask the user if the CellDesigner annotation should be imported
827  if (importCD || CQMessageBox::question(NULL, "CellDesigner import", "A CellDesigner diagram was found in this file.\nDo you want to import the diagram?" , QMessageBox::Yes | QMessageBox::No , QMessageBox::No) == QMessageBox::Yes)
828  {
829  // do the import
830  CCellDesignerImporter cd_importer(pSBMLDocument);
831 
832  if (cd_importer.getLayout() == NULL)
833  {
834  CCopasiMessage(CCopasiMessage::WARNING, "Sorry, CellDesigner annotations could not be imported.");
835  }
836  else
837  {
838  // now we have to import the created layout
839  // create the model map
840  std::string s1, s2;
841  std::map<std::string, std::string> modelmap;
842  std::map<CCopasiObject*, SBase*>::const_iterator it;
843  std::map<CCopasiObject*, SBase*>::const_iterator itEnd = pDataModel->getCopasi2SBMLMap().end();
844 
845  for (it = pDataModel->getCopasi2SBMLMap().begin(); it != itEnd; ++it)
846  {
847  s1 = SBMLUtils::getIdFromSBase(it->second);
848 
849  if (it->first)
850  {
851  s2 = it->first->getKey();
852  }
853  else
854  {
855  s2 = "";
856  }
857 
858  if ((s1 != "") && (s2 != ""))
859  {
860  modelmap[s1] = s2;
861  }
862  }
863 
864  // the layout map and the id to key map can be empty
865  std::map<std::string, std::string> layoutmap;
866  std::map<std::string, std::string> idToKeyMap;
867  CLayout* pLayout = SBMLDocumentLoader::createLayout(*cd_importer.getLayout(), modelmap, layoutmap, idToKeyMap);
868 
869  // add the layout to the DataModel
870  if (pLayout != NULL && pDataModel->getListOfLayouts() != NULL)
871  {
872  // the addLayout methods expects a map as the second argument which currently is
873  // ignored, so we just pass an empty one
874  // TODO maybe the methods actually expects one of the maps above (layoutmap or idToKeyMap), but
875  // TODO this is not documented in CListOfLayouts
876  std::map<std::string, std::string> tmp;
877  pDataModel->getListOfLayouts()->addLayout(pLayout, tmp);
878  }
879  else
880  {
881  CCopasiMessage(CCopasiMessage::WARNING, "Sorry, Layout from CellDesigner annotations could not be created.");
882  }
883  }
884  }
885  }
886  }
887  else
888  {
889  CCopasiMessage(CCopasiMessage::RAW, "CellDesigner annotation was found in the file, but the version is not supported.\nPlease open the file in the latest version of CellDesigner and save it again.");
890  }
891  }
892  }
893  }
894 }
895 
896 //TODO SEDML
897 #ifdef COPASI_SEDML
898 void DataModelGUI::importSEDMLFromString(const std::string & sedmlDocumentText)
899 {
901 
902  mSuccess = true;
903  mSEDMLImportString = sedmlDocumentText;
904 
905  mpThread = new CQThread(this, &DataModelGUI::importSEDMLFromStringRun);
906  connect(mpThread, SIGNAL(finished()), this, SLOT(importSEDMLFromStringFinished()));
907  mpThread->start();
908 }
909 
910 void DataModelGUI::importSEDMLFromStringRun()
911 {
912  try
913  {
914  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
915  mSuccess = (*CCopasiRootContainer::getDatamodelList())[0]->importSEDMLFromString(mSEDMLImportString, mpProgressBar, false);
916  }
917 
918  catch (...)
919  {
920  mSuccess = false;
921  }
922 }
923 
924 void DataModelGUI::importSEDMLFromStringFinished()
925 {
926  mSEDMLImportString = "";
927 
928  if (mSuccess)
929  {
932  }
933 
934  disconnect(mpThread, SIGNAL(finished()), this, SLOT(importSEDMLFromStringFinished()));
935 
936  threadFinished();
937 }
938 void DataModelGUI::importSEDML(const std::string & fileName)
939 {
941 
942  mSuccess = true;
943  mFileName = fileName;
944  mpThread = new CQThread(this, &DataModelGUI::importSEDMLRun);
945  connect(mpThread, SIGNAL(finished()), this, SLOT(importSEDMLFinished()));
946  mpThread->start();
947 }
948 
949 void DataModelGUI::importSEDMLRun()
950 {
951  try
952  {
953  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
955  }
956 
957  catch (...)
958  {
959  mSuccess = false;
960  }
961 }
962 
963 void DataModelGUI::importSEDMLFinished()
964 {
965  if (mSuccess)
966  {
968 
971  }
972 
973  disconnect(mpThread, SIGNAL(finished()), this, SLOT(importSEDMLFinished()));
974 
975  threadFinished();
976 }
977 
978 void DataModelGUI::exportSEDML(const std::string & fileName, bool overwriteFile, int sedmlLevel, int sedmlVersion, bool exportIncomplete, bool exportCOPASIMIRIAM)
979 {
981 
982  mSuccess = true;
983  mFileName = fileName;
984  mOverWrite = overwriteFile;
985  mSEDMLLevel = sedmlLevel;
986  mSEDMLVersion = sedmlVersion;
987  mSEDMLExportIncomplete = exportIncomplete;
988  mSEDMLExportCOPASIMIRIAM = exportCOPASIMIRIAM;
989 
990  mpThread = new CQThread(this, &DataModelGUI::exportSEDMLRun);
991  connect(mpThread, SIGNAL(finished()), this, SLOT(exportSEDMLFinished()));
992  mpThread->start();
993 }
994 
995 void DataModelGUI::exportSEDMLFinished()
996 {
997  if (mSuccess)
999 
1000  disconnect(mpThread, SIGNAL(finished()), this, SLOT(exportSEDMLFinished()));
1001 
1002  threadFinished();
1003 }
1004 
1005 void DataModelGUI::exportSEDMLToString(std::string & sedmlDocumentText)
1006 {
1008 
1009  mSuccess = true;
1010  mpSEDMLExportString = & sedmlDocumentText;
1011 
1012  mpThread = new CQThread(this, &DataModelGUI::exportSEDMLToStringRun);
1013  connect(mpThread, SIGNAL(finished()), this, SLOT(exportSEDMLToStringFinished()));
1014  mpThread->start();
1015 }
1016 
1017 void DataModelGUI::exportSEDMLToStringRun()
1018 {
1019  try
1020  {
1021  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
1022  *mpSEDMLExportString = (*CCopasiRootContainer::getDatamodelList())[0]->exportSEDMLToString(mpProgressBar, 1, 1);
1023  }
1024 
1025  catch (...)
1026  {
1027  mSuccess = false;
1028  }
1029 }
1030 
1031 void DataModelGUI::exportSEDMLToStringFinished()
1032 {
1033  disconnect(mpThread, SIGNAL(finished()), this, SLOT(exportSEDMLToStringFinished()));
1034 
1035  threadFinished();
1036 }
1037 
1038 void DataModelGUI::exportSEDMLRun()
1039 {
1040  try
1041  {
1042  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
1043  mSuccess = (*CCopasiRootContainer::getDatamodelList())[0]->exportSEDML(mFileName, mOverWrite, mSEDMLLevel, mSEDMLVersion, mSEDMLExportIncomplete, mSEDMLExportCOPASIMIRIAM, mpProgressBar);
1044  }
1045 
1046  catch (...)
1047  {
1048  mSuccess = false;
1049  }
1050 }
1051 #endif //COPASI_SEDML
void importSBMLFromStringRun()
const Layout * getLayout() const
void threadFinished()
COutputHandlerPlot mOutputHandlerPlot
Definition: DataModelGUI.h:137
SBMLDocument * getCurrentSBMLDocument()
CMIRIAMResources * mpMiriamResources
Definition: DataModelGUI.h:155
void buildChangedObjects()
#define pdelete(p)
Definition: copasi.h:215
Header file of class CModelEntity and CModelValue.
objectType
void exportSBMLToStringFinished()
void importSBML(const std::string &fileName)
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
bool updateMIRIAM(CMIRIAMResources &miriamResources)
void loadFunctionDB(const std::string &fileName)
bool notify(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
void exportSBMLToStringRun()
void exportSBMLRun()
const C_FLOAT64 & getInitialConcentration() const
Definition: CMetab.cpp:220
void saveModelRun()
static const XMLNode * findCellDesignerAnnotation(SBMLDocument *pDocument, const XMLNode *pAnnotation)
void exportMathModelRun()
void setDataModel(DataModelGUI *pDM)
Definition: listviews.cpp:267
void loadModel(const std::string &fileName)
static CProgressBar * create(QWidget *parent=0, const char *name=0, Qt::WindowModality windowModality=Qt::WindowModal)
CCopasiObject * getInitialValueReference() const
iterator begin()
bool mSBMLExportIncomplete
Definition: DataModelGUI.h:152
COutputDefinitionVector & getPlotDefinitionList()
std::vector< Refresh * > mUpdateVector
Definition: DataModelGUI.h:140
void exportSBML(const std::string &fileName, bool overwriteFile, int sbmlLevel, int sbmlVersion, bool exportIncomplete, bool exportCOPASIMIRIAM=true)
void importSBMLFromStringFinished()
virtual bool progressItem(const size_t &handle)
CRecentFiles & getRecentFiles()
std::string mExportFormat
Definition: DataModelGUI.h:154
std::string mSBMLImportString
Definition: DataModelGUI.h:146
void miriamDownloadProgress(qint64 received, qint64 total)
size_t mUpdateItem
Definition: DataModelGUI.h:158
CQThread * mpThread
Definition: DataModelGUI.h:143
Definition: CMetab.h:178
bool updateMIRIAMResourcesFromFile(CProcessReport *pProcessReport, const std::string &filename)
static void clearDeque()
std::string mFileName
Definition: DataModelGUI.h:148
static CLayout * createLayout(const Layout &sbmlLayout, const std::map< std::string, std::string > &modelmap, std::map< std::string, std::string > &layoutmap, const std::map< std::string, std::string > &globalIdToKeyMap, const CCopasiContainer *pParent=NULL)
std::set< ListViews * > mListViews
Definition: DataModelGUI.h:138
void importSBMLFinished()
static std::pair< bool, std::string > findCellDesignerNamespace(const SBMLDocument *pDocument)
void miriamDownloadFinished(QNetworkReply *)
void loadModelFinished()
void exportSBMLFinished()
static CConfigurationFile * getConfiguration()
iterator end()
std::vector< CType * >::const_iterator const_iterator
Definition: CCopasiVector.h:57
unsigned int mDownloadedBytes
Definition: DataModelGUI.h:156
void exportMathModelFinished()
CModelEntity ** endFixed()
Definition: CState.cpp:213
const bool & isInitialConcentrationChangeAllowed() const
Definition: CMetab.cpp:664
void finished(bool success)
void saveFunctionDB(const std::string &fileName)
std::string * mpSBMLExportString
Definition: DataModelGUI.h:147
virtual bool setName(const std::string &name)
void refreshActiveParameterSet()
Definition: CModel.cpp:1105
void addFile(const std::string &file)
void setOutputDefinitionVector(COutputDefinitionVector *pDefinitionVector)
void notifyView(ListViews::ObjectType objectType, ListViews::Action action, std::string key="")
void appendElementReferences(std::set< const CCopasiObject * > &objects) const
void setFramework(int framework)
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
bool loadModel(std::istream &in, const std::string &pwd, CProcessReport *pProcessReport, const bool &deleteOldData=true)
void refreshInitialValues()
CRecentFiles & getRecentSBMLFiles()
CListOfLayouts * getListOfLayouts()
CCopasiParameter * getParameter(const std::string &name)
CRecentFiles & getRecentSEDMLFiles()
CProgressBar * mpProgressBar
Definition: DataModelGUI.h:144
void deregisterListView(ListViews *pListView)
void importSBMLRun()
static CFunctionDB * getFunctionList()
static void getValue(const std::string &name, CType &value)
Definition: COptions.h:124
bool save(const std::string &fileName)
Definition: CFunctionDB.cpp:91
bool createModel()
void loadModelRun()
void addLayout(CLayout *layout, const std::map< std::string, std::string > &m)
static CCopasiDataModel * addDatamodel()
void saveModel(const std::string &fileName, bool overwriteFile=false)
DataModelGUI(QObject *parent)
unsigned int mDownloadedTotalBytes
Definition: DataModelGUI.h:157
static std::string getIdFromSBase(const SBase *s)
Definition: SBMLUtils.cpp:32
static StandardButton critical(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
void exportSBMLToString(std::string &sbmlDocumentText)
bool compileIfNecessary(CProcessReport *pProcessReport)
Definition: CModel.cpp:612
virtual bool finish()
const CStateTemplate & getStateTemplate() const
Definition: CModel.cpp:1172
static CCopasiMessage getLastMessage()
void registerListView(ListViews *pListView)
void linkDataModelToGUI()
CCopasiVectorNS< CReaction > & getReactions()
Definition: CModel.cpp:1039
static double determineVersion(const XMLNode *pNode)
std::set< const CCopasiObject * > mChangedObjects
Definition: DataModelGUI.h:141
Definition: CModel.h:50
void importSBMLFromString(const std::string &sbmlDocumentText)
virtual const CObjectInterface * getObject(const CCopasiObjectName &cn) const
void exportMathModel(const std::string &fileName, const std::string &filter, bool overwriteFile=false)
void importCellDesigner()
CConcentrationReference * getInitialConcentrationReference() const
Definition: CMetab.cpp:861
std::vector< Refresh * > buildInitialRefreshSequence(std::set< const CCopasiObject * > &changedObjects)
Definition: CModel.cpp:4164
void updateMIRIAMResourceContents()
std::map< CCopasiObject *, SBase * > & getCopasi2SBMLMap()
void saveModelFinished()
CModelEntity ** getEntities()
Definition: CState.cpp:204
bool mSBMLExportCOPASIMIRIAM
Definition: DataModelGUI.h:153
static StandardButton question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
virtual ~DataModelGUI()