copasi/UI/DataModelGUI.cpp
/**
 * This method tries to import CellDesigner annotations.
 */
This method tries to import CellDesigner annotations.
This method tries to import CellDesigner annotations .
void DataModelGUI::importCellDesigner()
{
  assert(mpDataModel != NULL);
  if (mpDataModel != NULL)
    {
      SBMLDocument* pSBMLDocument = mpDataModel->getCurrentSBMLDocument();
      if (pSBMLDocument != NULL &&
          pSBMLDocument->getModel() != NULL &&
          pSBMLDocument->getModel()->getAnnotation() != NULL)
        {
          std::pair<bool, std::string> foundNamespace = CCellDesignerImporter::findCellDesignerNamespace(pSBMLDocument);
          if (foundNamespace.first == true)
            {
              const XMLNode* pAnno = CCellDesignerImporter::findCellDesignerAnnotation(pSBMLDocument, pSBMLDocument->getModel()->getAnnotation());
              if (pAnno != NULL)
                {
                  double version = CCellDesignerImporter::determineVersion(pAnno);
                  if (version < 4.0)
                    {
                      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.");
                    }
                  else
                    {
                      bool importCD = false;
                      LayoutModelPlugin* mplugin = (LayoutModelPlugin*)pSBMLDocument->getModel()->getPlugin("layout");
                      if (mplugin == NULL || (mplugin != NULL && mplugin->getNumLayouts() == 0))
                        importCD = true;
                      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)
                        {
                          CCellDesignerImporter cd_importer(pSBMLDocument);
                          if (cd_importer.getLayout() == NULL)
                            {
                              CCopasiMessage(CCopasiMessage::WARNING, "Sorry, CellDesigner annotations could not be imported.");
                            }
                          else
                            {
                              std::string s1, s2;
                              std::map<std::string, std::string> modelmap;
                              std::map<const CDataObject*, SBase*>::const_iterator it;
                              std::map<const CDataObject*, SBase*>::const_iterator itEnd = mpDataModel->getCopasi2SBMLMap().end();
                              for (it = mpDataModel->getCopasi2SBMLMap().begin(); it != itEnd; ++it)
                                {
                                  s1 = SBMLUtils::getIdFromSBase(it->second);
                                  if (it->first)
                                    {
                                      s2 = it->first->getKey();
                                    }
                                  else
                                    {
                                      s2 = "";
                                    }
                                  if ((s1 != "") && (s2 != ""))
                                    {
                                      modelmap[s1] = s2;
                                    }
                                }
                              std::map<std::string, std::string> layoutmap;
                              std::map<std::string, std::string> idToKeyMap;
                              CLayout* pLayout = SBMLDocumentLoader::createLayout(*cd_importer.getLayout(), modelmap, layoutmap, idToKeyMap);
                              if (pLayout != NULL && mpDataModel->getListOfLayouts() != NULL)
                                {
                                  std::map<std::string, std::string> tmp;
                                  mpDataModel->getListOfLayouts()->addLayout(pLayout, tmp);
                                }
                              else
                                {
                                  CCopasiMessage(CCopasiMessage::WARNING, "Sorry, Layout from CellDesigner annotations could not be created.");
                                }
                            }
                        }
                    }
                }
              else
                {
                  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.");
                }
            }
        }
    }
}
void DataModelGUI :: importCellDesigner ( ) { assert ( mpDataModel != NULL ) ; if ( mpDataModel != NULL ) { SBMLDocument * pSBMLDocument = mpDataModel -> getCurrentSBMLDocument ( ) ; if ( pSBMLDocument != NULL && pSBMLDocument -> getModel ( ) != NULL && pSBMLDocument -> getModel ( ) -> getAnnotation ( ) != NULL ) { std :: pair < bool , std :: string > foundNamespace = CCellDesignerImporter :: findCellDesignerNamespace ( pSBMLDocument ) ; if ( foundNamespace . first == true ) { const XMLNode * pAnno = CCellDesignerImporter :: findCellDesignerAnnotation ( pSBMLDocument , pSBMLDocument -> getModel ( ) -> getAnnotation ( ) ) ; if ( pAnno != NULL ) { double version = CCellDesignerImporter :: determineVersion ( pAnno ) ; if ( version < 4.0 ) { CCopasiMessage ( CCopasiMessage :: RAW , " \n " ) ; } else { bool importCD = false ; LayoutModelPlugin * mplugin = ( LayoutModelPlugin * ) pSBMLDocument -> getModel ( ) -> getPlugin ( " " ) ; if ( mplugin == NULL || ( mplugin != NULL && mplugin -> getNumLayouts ( ) == 0 ) ) importCD = true ; if ( importCD || CQMessageBox :: question ( NULL , " " , " \n " , QMessageBox :: Yes | QMessageBox :: No , QMessageBox :: No ) == QMessageBox :: Yes ) { CCellDesignerImporter cd_importer ( pSBMLDocument ) ; if ( cd_importer . getLayout ( ) == NULL ) { CCopasiMessage ( CCopasiMessage :: WARNING , " " ) ; } else { std :: string s1 , s2 ; std :: map < std :: string , std :: string > modelmap ; std :: map < const CDataObject * , SBase * > :: const_iterator it ; std :: map < const CDataObject * , SBase * > :: const_iterator itEnd = mpDataModel -> getCopasi2SBMLMap ( ) . end ( ) ; for ( it = mpDataModel -> getCopasi2SBMLMap ( ) . begin ( ) ; it != itEnd ; ++ it ) { s1 = SBMLUtils :: getIdFromSBase ( it -> second ) ; if ( it -> first ) { s2 = it -> first -> getKey ( ) ; } else { s2 = " " ; } if ( ( s1 != " " ) && ( s2 != " " ) ) { modelmap [ s1 ] = s2 ; } } std :: map < std :: string , std :: string > layoutmap ; std :: map < std :: string , std :: string > idToKeyMap ; CLayout * pLayout = SBMLDocumentLoader :: createLayout ( * cd_importer . getLayout ( ) , modelmap , layoutmap , idToKeyMap ) ; if ( pLayout != NULL && mpDataModel -> getListOfLayouts ( ) != NULL ) { std :: map < std :: string , std :: string > tmp ; mpDataModel -> getListOfLayouts ( ) -> addLayout ( pLayout , tmp ) ; } else { CCopasiMessage ( CCopasiMessage :: WARNING , " " ) ; } } } } } else { CCopasiMessage ( CCopasiMessage :: RAW , " \n " ) ; } } } } }
This method tries to import CellDesigner annotations.
This method tries to import CellDesigner annotations .
// add code to check for CellDesigner annotations // ask the user if the annotations should be imported // check for the CellDesigner namespace // first we check if there are supported cell designer annotations // check if the file contains the correct version // if we don't have a layout import it! // ask the user if the CellDesigner annotation should be imported // do the import // now we have to import the created layout // create the model map // the layout map and the id to key map can be empty // add the layout to the DataModel // the addLayout methods expects a map as the second argument which currently is // ignored, so we just pass an empty one // TODO maybe the methods actually expects one of the maps above (layoutmap or idToKeyMap), but // TODO this is not documented in CListOfLayouts