copasi/sedml/SEDMLImporter.cpp
/**
 * Function parses an SEDML document with libsedml and converts it to a COPASI CModel
 * object which is returned. Deletion of the returned pointer is up to the
 * caller.
 */
Function parses an SEDML document with libsedml and converts it to a COPASI CModel
object which is returned. Deletion of the returned pointer is up to the
caller.
Function parses an SEDML document with libsedml and converts it to a COPASI CModel object which is returned . Deletion of the returned pointer is up to the caller .
CModel*
SEDMLImporter::parseSEDML(const std::string& sedmlDocumentText,
                          CProcessReport* pImportHandler,
                          SBMLDocument *& pSBMLDocument,
                          SedDocument *& pSEDMLDocument,
                          std::map<CDataObject*, SedBase*>& copasi2sedmlmap,
                          std::map<CDataObject*, SBase*>& copasi2sbmlmap,
                          CListOfLayouts *& prLol,
                          COutputDefinitionVector * & pPlotList,
                          CDataModel* pDataModel)
{
  mReportMap.clear();
  this->mUsedSEDMLIdsPopulated = false;
  mpDataModel = pDataModel;
  assert(mpDataModel != NULL);
  this->mpCopasiModel = NULL;
  SedReader reader;
  mImportStep = 0;
  if (mpImportHandler)
    {
      mpImportHandler->setName("Importing SED-ML file...");
      mTotalSteps = 11;
      mhImportStep = mpImportHandler->addItem("Step", mImportStep,
                                              &mTotalSteps);
    }
  unsigned C_INT32 step = 0, totalSteps = 0;
  size_t hStep = C_INVALID_INDEX;
  if (this->mpImportHandler != 0)
    {
      step = 0;
      totalSteps = 1;
      hStep = mpImportHandler->addItem("Reading SED-ML file...", step,
                                       &totalSteps);
    }
  mpSEDMLDocument = reader.readSedMLFromString(sedmlDocumentText);
  assert(mpSEDMLDocument != NULL);
  if (mpImportHandler)
    mpImportHandler->finishItem(hStep);
  if (this->mpImportHandler != 0)
    {
      step = 0;
      totalSteps = 1;
      hStep = mpImportHandler->addItem("Checking consistency...", step,
                                       &totalSteps);
    }
  if (mpImportHandler)
    mpImportHandler->finishItem(hStep);
  int fatal = -1;
  unsigned int i, iMax = mpSEDMLDocument->getNumErrors();
  for (i = 0; (i < iMax) && (fatal == -1); ++i)
    {
      const SedError* pSEDMLError = mpSEDMLDocument->getError(i);
      CCopasiMessage::Type messageType = CCopasiMessage::RAW;
      switch (pSEDMLError->getSeverity())
        {
          case LIBSEDML_SEV_WARNING:
            if (pSEDMLError->getErrorId() == SedInvalidNamespaceOnSed)
              continue;
            if (mIgnoredSEDMLMessages.find(pSEDMLError->getErrorId())
                != mIgnoredSEDMLMessages.end())
              {
                messageType = CCopasiMessage::WARNING_FILTERED;
              }
            else
              {
                messageType = CCopasiMessage::WARNING;
              }
            CCopasiMessage(messageType, MCSEDML + 6, "WARNING",
                           pSEDMLError->getErrorId(), pSEDMLError->getLine(),
                           pSEDMLError->getColumn(),
                           pSEDMLError->getMessage().c_str());
            break;
          case LIBSEDML_SEV_ERROR:
            if (mIgnoredSEDMLMessages.find(pSEDMLError->getErrorId())
                != mIgnoredSEDMLMessages.end())
              {
                messageType = CCopasiMessage::ERROR_FILTERED;
              }
            CCopasiMessage(messageType, MCSEDML + 6, "ERROR",
                           pSEDMLError->getErrorId(), pSEDMLError->getLine(),
                           pSEDMLError->getColumn(),
                           pSEDMLError->getMessage().c_str());
            break;
          case LIBSEDML_SEV_FATAL:
          default:
            if (pSEDMLError->getErrorId() == 10804)
              {
                CCopasiMessage(messageType, MCSEDML + 6, "ERROR",
                               pSEDMLError->getErrorId(), pSEDMLError->getLine(),
                               pSEDMLError->getColumn(),
                               pSEDMLError->getMessage().c_str());
              }
            else
              {
                fatal = i;
              }
            break;
        }
    }
  if (fatal != -1)
    {
      const XMLError* pSEDMLError = mpSEDMLDocument->getError(fatal);
      CCopasiMessage Message(CCopasiMessage::EXCEPTION, MCXML + 2,
                             pSEDMLError->getLine(), pSEDMLError->getColumn(),
                             pSEDMLError->getMessage().c_str());
      if (mpImportHandler)
        mpImportHandler->finishItem(mhImportStep);
      return NULL;
    }
  if (mpSEDMLDocument->getListOfModels() == NULL)
    {
      CCopasiMessage Message(CCopasiMessage::ERROR, MCSEDML + 2);
      if (mpImportHandler)
        mpImportHandler->finishItem(mhImportStep);
      return NULL;
    }
  pSEDMLDocument = mpSEDMLDocument;
  this->mLevel = pSEDMLDocument->getLevel();
  this->mOriginalLevel = this->mLevel;
  this->mVersion = pSEDMLDocument->getVersion();
  importFirstSBMLModel(pImportHandler, pSBMLDocument, copasi2sbmlmap, prLol, pDataModel);
  pPlotList = new COutputDefinitionVector("OutputDefinitions", mpDataModel);
  readListOfPlotsFromSedMLOutput(pPlotList, mpCopasiModel, pSEDMLDocument, copasi2sedmlmap);
  importTasks(copasi2sedmlmap);
  if (mpImportHandler)
    mpImportHandler->finishItem(mhImportStep);
  return mpCopasiModel;
  return NULL;
}
CModel * SEDMLImporter :: parseSEDML ( const std :: string & sedmlDocumentText , CProcessReport * pImportHandler , SBMLDocument * & pSBMLDocument , SedDocument * & pSEDMLDocument , std :: map < CDataObject * , SedBase * > & copasi2sedmlmap , std :: map < CDataObject * , SBase * > & copasi2sbmlmap , CListOfLayouts * & prLol , COutputDefinitionVector * & pPlotList , CDataModel * pDataModel ) { mReportMap . clear ( ) ; this -> mUsedSEDMLIdsPopulated = false ; mpDataModel = pDataModel ; assert ( mpDataModel != NULL ) ; this -> mpCopasiModel = NULL ; SedReader reader ; mImportStep = 0 ; if ( mpImportHandler ) { mpImportHandler -> setName ( " " ) ; mTotalSteps = 11 ; mhImportStep = mpImportHandler -> addItem ( " " , mImportStep , & mTotalSteps ) ; } unsigned C_INT32 step = 0 , totalSteps = 0 ; size_t hStep = C_INVALID_INDEX ; if ( this -> mpImportHandler != 0 ) { step = 0 ; totalSteps = 1 ; hStep = mpImportHandler -> addItem ( " " , step , & totalSteps ) ; } mpSEDMLDocument = reader . readSedMLFromString ( sedmlDocumentText ) ; assert ( mpSEDMLDocument != NULL ) ; if ( mpImportHandler ) mpImportHandler -> finishItem ( hStep ) ; if ( this -> mpImportHandler != 0 ) { step = 0 ; totalSteps = 1 ; hStep = mpImportHandler -> addItem ( " " , step , & totalSteps ) ; } if ( mpImportHandler ) mpImportHandler -> finishItem ( hStep ) ; int fatal = -1 ; unsigned int i , iMax = mpSEDMLDocument -> getNumErrors ( ) ; for ( i = 0 ; ( i < iMax ) && ( fatal == -1 ) ; ++ i ) { const SedError * pSEDMLError = mpSEDMLDocument -> getError ( i ) ; CCopasiMessage :: Type messageType = CCopasiMessage :: RAW ; switch ( pSEDMLError -> getSeverity ( ) ) { case LIBSEDML_SEV_WARNING : if ( pSEDMLError -> getErrorId ( ) == SedInvalidNamespaceOnSed ) continue ; if ( mIgnoredSEDMLMessages . find ( pSEDMLError -> getErrorId ( ) ) != mIgnoredSEDMLMessages . end ( ) ) { messageType = CCopasiMessage :: WARNING_FILTERED ; } else { messageType = CCopasiMessage :: WARNING ; } CCopasiMessage ( messageType , MCSEDML + 6 , " " , pSEDMLError -> getErrorId ( ) , pSEDMLError -> getLine ( ) , pSEDMLError -> getColumn ( ) , pSEDMLError -> getMessage ( ) . c_str ( ) ) ; break ; case LIBSEDML_SEV_ERROR : if ( mIgnoredSEDMLMessages . find ( pSEDMLError -> getErrorId ( ) ) != mIgnoredSEDMLMessages . end ( ) ) { messageType = CCopasiMessage :: ERROR_FILTERED ; } CCopasiMessage ( messageType , MCSEDML + 6 , " " , pSEDMLError -> getErrorId ( ) , pSEDMLError -> getLine ( ) , pSEDMLError -> getColumn ( ) , pSEDMLError -> getMessage ( ) . c_str ( ) ) ; break ; case LIBSEDML_SEV_FATAL : default : if ( pSEDMLError -> getErrorId ( ) == 10804 ) { CCopasiMessage ( messageType , MCSEDML + 6 , " " , pSEDMLError -> getErrorId ( ) , pSEDMLError -> getLine ( ) , pSEDMLError -> getColumn ( ) , pSEDMLError -> getMessage ( ) . c_str ( ) ) ; } else { fatal = i ; } break ; } } if ( fatal != -1 ) { const XMLError * pSEDMLError = mpSEDMLDocument -> getError ( fatal ) ; CCopasiMessage Message ( CCopasiMessage :: EXCEPTION , MCXML + 2 , pSEDMLError -> getLine ( ) , pSEDMLError -> getColumn ( ) , pSEDMLError -> getMessage ( ) . c_str ( ) ) ; if ( mpImportHandler ) mpImportHandler -> finishItem ( mhImportStep ) ; return NULL ; } if ( mpSEDMLDocument -> getListOfModels ( ) == NULL ) { CCopasiMessage Message ( CCopasiMessage :: ERROR , MCSEDML + 2 ) ; if ( mpImportHandler ) mpImportHandler -> finishItem ( mhImportStep ) ; return NULL ; } pSEDMLDocument = mpSEDMLDocument ; this -> mLevel = pSEDMLDocument -> getLevel ( ) ; this -> mOriginalLevel = this -> mLevel ; this -> mVersion = pSEDMLDocument -> getVersion ( ) ; importFirstSBMLModel ( pImportHandler , pSBMLDocument , copasi2sbmlmap , prLol , pDataModel ) ; pPlotList = new COutputDefinitionVector ( " " , mpDataModel ) ; readListOfPlotsFromSedMLOutput ( pPlotList , mpCopasiModel , pSEDMLDocument , copasi2sedmlmap ) ; importTasks ( copasi2sedmlmap ) ; if ( mpImportHandler ) mpImportHandler -> finishItem ( mhImportStep ) ; return mpCopasiModel ; return NULL ; }
Function parses an SEDML document with libsedml and converts it to a COPASI CModel
 object which is returned.
Function parses an SEDML document with libsedml and converts it to a COPASI CModel object which is returned .
// if issued as warning, this message is to be disregarded, // it was a bug in earlier versions of libSEDML // treat unknown as fatal // this error indicates a problem with a notes element // although libsedml flags this as fatal, we would still // like to read the model //delete reader;