bool CModelExpansion::expressionContainsObject(const CExpression* exp, const SetOfModelElements & sourceSet) { if (!exp) return false; //we loop through the complete expression std::vector< CEvaluationNode * >::const_iterator it = exp->getNodeList().begin(); std::vector< CEvaluationNode * >::const_iterator end = exp->getNodeList().end(); for (; it != end; ++it) { CEvaluationNodeObject * node = dynamic_cast<CEvaluationNodeObject*>(*it); if (!node) continue; //std::cout << node->getData() << std::endl; const CCopasiObject * pObj = dynamic_cast<const CCopasiObject*>(node->getObjectInterfacePtr()); if (pObj) { pObj = pObj->getObjectParent(); } //is the object one that should be copied? if (sourceSet.contains(pObj)) return true; } return false; }
void CModelExpansion::replaceInExpression(CExpression* exp, const ElementsMap & emap) { if (!exp) return; //we loop through the complete expression std::vector< CEvaluationNode * >::const_iterator it = exp->getNodeList().begin(); std::vector< CEvaluationNode * >::const_iterator end = exp->getNodeList().end(); for (; it != end; ++it) { CEvaluationNodeObject * node = dynamic_cast<CEvaluationNodeObject*>(*it); if (!node) continue; //std::cout << node->getData() << std::endl; const CCopasiObject * pObj = dynamic_cast<const CCopasiObject*>(node->getObjectInterfacePtr()); std::string refname = ""; std::string reftype = ""; if (pObj) { refname = pObj->getObjectName(); reftype = pObj->getObjectType(); pObj = pObj->getObjectParent(); } const CCopasiObject* duplicate = emap.getDuplicatePtr(pObj); if (duplicate) { //get the reference object const CCopasiObject* pRef = dynamic_cast<const CCopasiObject*>(duplicate->getObject(reftype + "=" + refname)); //update the node if (pRef) node->setData("<" + pRef->getCN() + ">"); //std::cout << node->getData() << std::endl; } } }
void CModelExpansion::updateExpression(CExpression* exp, const std::string & index, const SetOfModelElements & sourceSet, ElementsMap & emap) { if (!exp) return; //we loop through the complete expression std::vector< CEvaluationNode * >::const_iterator it = exp->getNodeList().begin(); std::vector< CEvaluationNode * >::const_iterator end = exp->getNodeList().end(); for (; it != end; ++it) { CEvaluationNodeObject * node = dynamic_cast<CEvaluationNodeObject*>(*it); if (!node) continue; //std::cout << node->getData() << std::endl; const CCopasiObject * pObj = dynamic_cast<const CCopasiObject*>(node->getObjectInterfacePtr()); std::string refname = ""; std::string reftype = ""; //when copying between models, pObj=NULL. This is because the expression could not be compiled //if it points to an object in a different model. //We try to fix this now: if (!pObj && mpSourceModel) { CCopasiObjectName cn = node->getObjectCN(); while (cn.getPrimary().getObjectType() != "Model" && !cn.empty()) { cn = cn.getRemainder(); } pObj = dynamic_cast<const CCopasiObject*>(mpSourceModel->getObject(cn)); } if (pObj) { refname = pObj->getObjectName(); reftype = pObj->getObjectType(); pObj = pObj->getObjectParent(); } //is the object one that is/should be copied? if (sourceSet.contains(pObj)) { if (!emap.exists(pObj)) { //we have to create the duplicate std::cout << "!!!" << std::endl; if (dynamic_cast<const CCompartment*>(pObj)) duplicateCompartment(dynamic_cast<const CCompartment*>(pObj), index, sourceSet, emap); if (dynamic_cast<const CMetab*>(pObj)) duplicateMetab(dynamic_cast<const CMetab*>(pObj), index, sourceSet, emap); if (dynamic_cast<const CModelValue*>(pObj)) duplicateGlobalQuantity(dynamic_cast<const CModelValue*>(pObj), index, sourceSet, emap); if (dynamic_cast<const CReaction*>(pObj)) duplicateReaction(dynamic_cast<const CReaction*>(pObj), index, sourceSet, emap); } //find the duplicate const CCopasiObject* duplicate = emap.getDuplicatePtr(pObj); if (duplicate) { //get the reference object const CCopasiObject* pRef = dynamic_cast<const CCopasiObject*>(duplicate->getObject(reftype + "=" + refname)); //update the node if (pRef) node->setData("<" + pRef->getCN() + ">"); //std::cout << node->getData() << std::endl; } } } }