void CCopasiXMLParser::ModelParameterGroupElement::start(const XML_Char *pszName, const XML_Char **papszAttrs) { const char * CN; const char * pType; CModelParameter::Type Type; mpCurrentHandler = NULL; mCurrentElement = mLastKnownElement; while (mpCurrentHandler == NULL) { mCurrentElement++; /* We should always be on the next element */ switch (mCurrentElement) { case ModelParameterGroup: if (strcmp(pszName, "ModelParameterGroup")) CCopasiMessage(CCopasiMessage::EXCEPTION, MCXML + 10, pszName, "ModelParameterGroup", mParser.getCurrentLineNumber()); mLastKnownElement = ModelParameterGroup; // Element specific code. CN = mParser.getAttributeValue("cn", papszAttrs); pType = mParser.getAttributeValue("type", papszAttrs); Type = toEnum(pType, CModelParameter::TypeNames, CModelParameter::Group); { CModelParameterGroup * pModelParameterGroup = new CModelParameterGroup(mCommon.ModelParameterGroupStack.top(), Type); pModelParameterGroup->setCN(std::string(CN)); mCommon.ModelParameterGroupStack.push(pModelParameterGroup); } return; case Content: if (!strcmp(pszName, "ModelParameterGroup")) { /* If we do not have an etc element handler we create one. */ if (!mpModelParameterGroupElement) mpModelParameterGroupElement = new ModelParameterGroupElement(mParser, mCommon); mpCurrentHandler = mpModelParameterGroupElement; } else if (!strcmp(pszName, "ModelParameter")) { /* If we do not have an etc element handler we create one. */ if (!mpModelParameterElement) mpModelParameterElement = new ModelParameterElement(mParser, mCommon); mpCurrentHandler = mpModelParameterElement; } break; default: mCurrentElement = UNKNOWN_ELEMENT; mpCurrentHandler = &mParser.mUnknownElement; break; } } mParser.pushElementHandler(mpCurrentHandler); if (mpCurrentHandler != &mParser.mUnknownElement) { mLastKnownElement = mCurrentElement; } mParser.onStartElement(pszName, papszAttrs); return; }
void CModelParameterSet::createFromModel() { clear(); if (mpModel == NULL) { return; } CModelParameter * pParameter; CModelParameterGroup * pGroup; // TODO CRITICAL Create the proper structure that fits the parameter overview in the GUI pGroup = static_cast< CModelParameterGroup *>(CModelParameterGroup::add(Group)); pGroup->setCN(CCopasiStaticString("Initial Time").getCN()); pParameter = pGroup->add(Model); pParameter->setCN(mpModel->getCN()); pParameter->setValue(mpModel->getInitialTime(), ParticleNumbers); pGroup = static_cast< CModelParameterGroup *>(CModelParameterGroup::add(Group)); pGroup->setCN(CCopasiStaticString("Initial Compartment Sizes").getCN()); CCopasiVector< CCompartment >::const_iterator itCompartment = mpModel->getCompartments().begin(); CCopasiVector< CCompartment >::const_iterator endCompartment = mpModel->getCompartments().end(); for (; itCompartment != endCompartment; ++itCompartment) { pParameter = pGroup->add(Compartment); pParameter->setCN((*itCompartment)->getCN()); pParameter->setSimulationType((*itCompartment)->getStatus()); pParameter->setValue((*itCompartment)->getInitialValue(), ParticleNumbers); pParameter->setInitialExpression((*itCompartment)->getInitialExpression()); } pGroup = static_cast< CModelParameterGroup *>(CModelParameterGroup::add(Group)); pGroup->setCN(CCopasiStaticString("Initial Species Values").getCN()); CCopasiVector< CMetab >::const_iterator itSpecies = mpModel->getMetabolites().begin(); CCopasiVector< CMetab >::const_iterator endSpecies = mpModel->getMetabolites().end(); for (; itSpecies != endSpecies; ++itSpecies) { pParameter = pGroup->add(Species); pParameter->setCN((*itSpecies)->getCN()); pParameter->setSimulationType((*itSpecies)->getStatus()); pParameter->setValue((*itSpecies)->getInitialValue(), ParticleNumbers); pParameter->setInitialExpression((*itSpecies)->getInitialExpression()); } pGroup = static_cast< CModelParameterGroup *>(CModelParameterGroup::add(Group)); pGroup->setCN(CCopasiStaticString("Initial Global Quantities").getCN()); CCopasiVector< CModelValue >::const_iterator itModelValue = mpModel->getModelValues().begin(); CCopasiVector< CModelValue >::const_iterator endModelValue = mpModel->getModelValues().end(); for (; itModelValue != endModelValue; ++itModelValue) { pParameter = pGroup->add(ModelValue); pParameter->setCN((*itModelValue)->getCN()); pParameter->setSimulationType((*itModelValue)->getStatus()); pParameter->setValue((*itModelValue)->getInitialValue(), ParticleNumbers); pParameter->setInitialExpression((*itModelValue)->getInitialExpression()); } pGroup = static_cast< CModelParameterGroup *>(CModelParameterGroup::add(Group)); pGroup->setCN(CCopasiStaticString("Kinetic Parameters").getCN()); CCopasiVector< CReaction >::const_iterator itReaction = mpModel->getReactions().begin(); CCopasiVector< CReaction >::const_iterator endReaction = mpModel->getReactions().end(); for (; itReaction != endReaction; ++itReaction) { CModelParameterGroup * pReaction = static_cast< CModelParameterGroup *>(pGroup->add(Reaction)); pReaction->setCN((*itReaction)->getCN()); CCopasiParameterGroup::index_iterator itParameter = (*itReaction)->getParameters().beginIndex(); CCopasiParameterGroup::index_iterator endParameter = (*itReaction)->getParameters().endIndex(); for (; itParameter != endParameter; ++itParameter) { pParameter = pReaction->add(ReactionParameter); pParameter->setCN((*itParameter)->getCN()); // Check whether this refers to a global quantity. if ((*itReaction)->isLocalParameter((*itParameter)->getObjectName())) { pParameter->setSimulationType(CModelEntity::FIXED); pParameter->setValue(*(*itParameter)->getValue().pDOUBLE, ParticleNumbers); } else { pParameter->setSimulationType(CModelEntity::ASSIGNMENT); const std::vector<std::string> ModelValue = (*itReaction)->getParameterMapping((*itParameter)->getObjectName()); if (ModelValue.size() != 1) fatalError(); const CModelValue * pModelValue = static_cast< CModelValue * >(CCopasiRootContainer::getKeyFactory()->get(ModelValue[0])); if (pModelValue == NULL) fatalError(); pParameter->setValue(pModelValue->getInitialValue(), ParticleNumbers); pParameter->setInitialExpression("<" + pModelValue->getInitialValueReference()->getCN() + ">"); } } } compile(); }