コード例 #1
0
// virtual
CXMLHandler * ModelValueHandler::processStart(const XML_Char * pszName,
    const XML_Char ** papszAttrs)
{
  CXMLHandler * pHandlerToCall = NULL;
  const char * Name;
  const char * simulationType;
  CModelEntity::Status SimulationType;
  bool AddNoise;

  switch (mCurrentElement.first)
    {
      case ModelValue:
        mKey = mpParser->getAttributeValue("key", papszAttrs);
        Name = mpParser->getAttributeValue("name", papszAttrs);
        simulationType = mpParser->getAttributeValue("simulationType", papszAttrs, false);

        // We need to handle old files which used the attribute status.
        if (!simulationType)
          {
            simulationType = mpParser->getAttributeValue("status", papszAttrs, false);

            if (!simulationType) // status and simulationType are both missing
              simulationType = mpParser->getAttributeValue("simulationType", papszAttrs);
          }

        SimulationType = toEnum(simulationType, CModelEntity::XMLStatus, CModelEntity::FIXED);
        AddNoise = mpParser->toBool(mpParser->getAttributeValue("addNoise", papszAttrs, "false"));

        mpMV = new CModelValue();
        addFix(mKey, mpMV);
        mpMV->setObjectName(Name);
        mpMV->setStatus(SimulationType);
        mpMV->setAddNoise(AddNoise);

        mpData->pModel->getModelValues().add(mpMV, true);
        break;

      case MiriamAnnotation:
      case Comment:
      case Expression:
      case MathML:
      case InitialExpression:
      case NoiseExpression:
      case Unit:
        pHandlerToCall = getHandler(mCurrentElement.second);
        break;

      case ListOfUnsupportedAnnotations:
        mpData->mUnsupportedAnnotations.clear();
        pHandlerToCall = getHandler(mCurrentElement.second);
        break;

      default:
        CCopasiMessage(CCopasiMessage::EXCEPTION, MCXML + 2,
                       mpParser->getCurrentLineNumber(), mpParser->getCurrentColumnNumber(), pszName);
        break;
    }

  return pHandlerToCall;
}
コード例 #2
0
// virtual
CXMLHandler * TaskHandler::processStart(const XML_Char * pszName,
                                        const XML_Char ** papszAttrs)
{
  CXMLHandler * pHandlerToCall = NULL;
  const char * Key;
  const char * type;
  CTaskEnum::Task Type;
  bool Scheduled = false;
  bool UpdateModel = false;

  switch (mCurrentElement.first)
    {
      case Task:
        mpData->pCurrentTask = NULL;

        Key = mpParser->getAttributeValue("key", papszAttrs, false);
        type = mpParser->getAttributeValue("type", papszAttrs);
        Type = toEnum(type, CTaskEnum::TaskXML, CTaskEnum::UnsetTask);
        Scheduled = mpParser->toBool(mpParser->getAttributeValue("scheduled", papszAttrs, "false"));
        UpdateModel = mpParser->toBool(mpParser->getAttributeValue("updateModel", papszAttrs, "false"));

        mpData->pCurrentTask = CTaskFactory::createTask(Type, mpData->pTaskList);

        if (mpData->pCurrentTask != NULL)
          {
            mpData->pCurrentTask->setScheduled(Scheduled);
            mpData->pCurrentTask->setUpdateModel(UpdateModel);
            mpData->pCurrentTask->setMathContainer(&mpData->pModel->getMathContainer());

            if (Key != NULL)
              {
                addFix(Key, mpData->pCurrentTask);
              }
          }
        else
          {
            CCopasiMessage(CCopasiMessage::WARNING, MCXML + 5, type, mpParser->getCurrentLineNumber());
            pHandlerToCall = getHandler(UNKNOWN);
          }

        break;

      case ReportTarget:
      case Method:
        pHandlerToCall = getHandler(mCurrentElement.second);
        break;

      case Problem:
        pHandlerToCall = getHandler(mCurrentElement.second);
        static_cast< ParameterGroupHandler * >(pHandlerToCall)->setDerivedElement(pszName, mpData->pCurrentTask->getProblem());
        break;

      default:
        CCopasiMessage(CCopasiMessage::EXCEPTION, MCXML + 2,
                       mpParser->getCurrentLineNumber(), mpParser->getCurrentColumnNumber(), pszName);
        break;
    }

  return pHandlerToCall;
}
コード例 #3
0
// virtual
CXMLHandler * ReactionGlyphHandler::processStart(const XML_Char * pszName,
    const XML_Char ** papszAttrs)
{
  CXMLHandler * pHandlerToCall = NULL;

  switch (mCurrentElement.first)
    {
      case ReactionGlyph:
      {
        //workload
        const char * key;
        const char * name;
        const char * reaction;
        key = mpParser->getAttributeValue("key", papszAttrs);
        name = mpParser->getAttributeValue("name", papszAttrs);
        reaction = mpParser->getAttributeValue("reaction", papszAttrs, false);

        mpData->pReactionGlyph = new CLReactionGlyph(name);
        const char * objectRole = mpParser->getAttributeValue("objectRole", papszAttrs, false);

        if (objectRole != NULL && objectRole[0] != 0)
          {
            mpData->pReactionGlyph->setObjectRole(objectRole);
          }

        if (reaction && reaction[0])
          {
            CReaction * pReaction = dynamic_cast< CReaction * >(mpData->mKeyMap.get(reaction));

            if (!pReaction)
              {
                CCopasiMessage(CCopasiMessage::WARNING, MCXML + 19, "ReactionGlyph" , key);
              }
            else
              {
                mpData->pReactionGlyph->setModelObjectKey(pReaction->getKey());
              }
          }

        mpData->pCurrentLayout->addReactionGlyph(mpData->pReactionGlyph);
        addFix(key, mpData->pReactionGlyph);
      }
      break;

      case BoundingBox:
      case Curve:
      case ListOfMetaboliteReferenceGlyphs:
        pHandlerToCall = getHandler(mCurrentElement.second);
        break;

      default:
        CCopasiMessage(CCopasiMessage::EXCEPTION, MCXML + 2,
                       mpParser->getCurrentLineNumber(), mpParser->getCurrentColumnNumber(), pszName);
        break;
    }

  return pHandlerToCall;
}
コード例 #4
0
// virtual
CXMLHandler * ReportDefinitionHandler::processStart(const XML_Char * pszName,
    const XML_Char ** papszAttrs)
{
  CXMLHandler * pHandlerToCall = NULL;
  const char * Key;
  const char * Name;
  const char * Separator;
  const char * Precision;
  CTaskEnum::Task type;

  switch (mCurrentElement.first)
    {
      case ReportDefinition:
        Key = mpParser->getAttributeValue("key", papszAttrs);
        Name = mpParser->getAttributeValue("name", papszAttrs);
        type = CTaskEnum::TaskXML.toEnum(mpParser->getAttributeValue("taskType", papszAttrs), CTaskEnum::Task::UnsetTask);

        Separator = mpParser->getAttributeValue("separator", papszAttrs, "\t");
        Precision = mpParser->getAttributeValue("precision", papszAttrs, "6");

        // create a new report
        mpData->pReport = new CReportDefinition();
        mpData->pReport->setTaskType(type);
        mpData->pReport->setSeparator(Separator);
        mpData->pReport->setPrecision(strToUnsignedInt(Precision));

        {
          // We need to make sure that the name is unique.
          std::string ValidName(Name);
          size_t Index = 1;

          while (mpData->pReportList->getIndex(ValidName) != C_INVALID_INDEX)
            {
              std::ostringstream ValidNameStream;
              ValidNameStream << Name << " " << Index++;
              ValidName = ValidNameStream.str();
            }

          mpData->pReport->setObjectName(ValidName);
        }

        /* We have a new report and add it to the list */
        mpData->pReportList->add(mpData->pReport, true);
        addFix(Key, mpData->pReport);
        break;

      case Comment:
        pHandlerToCall = getHandler(mCurrentElement.second);
        break;

      case Header:
      case Body:
      case Footer:
        mpData->pReport->setIsTable(false);
        pHandlerToCall = getHandler(mCurrentElement.second);
        break;

      case Table:
        mpData->pReport->setIsTable(true);
        pHandlerToCall = getHandler(mCurrentElement.second);

        break;

      default:
        CCopasiMessage(CCopasiMessage::EXCEPTION, MCXML + 2,
                       mpParser->getCurrentLineNumber(), mpParser->getCurrentColumnNumber(), pszName);
        break;
    }

  return pHandlerToCall;
}
コード例 #5
0
// virtual
CXMLHandler * MetaboliteHandler::processStart(const XML_Char * pszName,
    const XML_Char ** papszAttrs)
{
  CXMLHandler * pHandlerToCall = NULL;

  CCompartment * pCompartment = NULL;
  const char * Name;
  const char * simulationType;
  CModelEntity::Status SimulationType;
  const char reactions[] = "reactions";
  const char * Compartment;
  bool AddNoise;

  switch (mCurrentElement.first)
    {
      case Metabolite:
        mKey = mpParser->getAttributeValue("key", papszAttrs);
        Name = mpParser->getAttributeValue("name", papszAttrs);

        simulationType = mpParser->getAttributeValue("simulationType", papszAttrs, false);

        // We need to handle old files which used the attribute status.
        if (!simulationType)
          {
            simulationType = mpParser->getAttributeValue("status", papszAttrs, false);

            if (!simulationType) // status and simulationType are both missing
              simulationType = mpParser->getAttributeValue("simulationType", papszAttrs);
            else if (!strcmp(simulationType, "variable")) // reactions was named variable
              simulationType = reactions;
          }

        SimulationType = toEnum(simulationType, CModelEntity::XMLStatus, CModelEntity::REACTIONS);
        Compartment = mpParser->getAttributeValue("compartment", papszAttrs);
        AddNoise = mpParser->toBool(mpParser->getAttributeValue("addNoise", papszAttrs, "false"));

        mpMetabolite = new CMetab();
        addFix(mKey, mpMetabolite);
        mpMetabolite->setObjectName(Name);
        mpMetabolite->setStatus(SimulationType);
        mpMetabolite->setAddNoise(AddNoise);

        pCompartment =
          dynamic_cast< CCompartment* >(mpData->mKeyMap.get(Compartment));

        if (!pCompartment) fatalError();

        pCompartment->addMetabolite(mpMetabolite);
        mpData->pModel->getMetabolites().add(mpMetabolite, false);
        break;;

      case MiriamAnnotation:
      case Comment:
      case Expression:
      case InitialExpression:
      case NoiseExpression:
        pHandlerToCall = getHandler(mCurrentElement.second);
        break;

      case ListOfUnsupportedAnnotations:
        mpData->mUnsupportedAnnotations.clear();
        pHandlerToCall = getHandler(mCurrentElement.second);
        break;

      default:
        CCopasiMessage(CCopasiMessage::EXCEPTION, MCXML + 2,
                       mpParser->getCurrentLineNumber(), mpParser->getCurrentColumnNumber(), pszName);
        break;
    }

  return pHandlerToCall;
}