Exemple #1
0
bool CModelAdd::copyInitialExpression(const CModelEntity * sourceEntity, CModelEntity * newEntity)
{

  bool info = false;

  const CExpression* pExpression = sourceEntity->getInitialExpressionPtr();

  if (pExpression == NULL) return info;

  CExpression* tmp;
  tmp = new CExpression(*pExpression, mmModel);

  const std::vector<CEvaluationNode*>& objectNodes = tmp->getNodeList();
  size_t j, jmax = objectNodes.size();

  for (j = 0; j < jmax; ++j)
    {
      if (CEvaluationNode::type(objectNodes[j]->getType()) == CEvaluationNode::OBJECT)
        {
          CEvaluationNodeObject* pObjectNode = dynamic_cast<CEvaluationNodeObject*>(objectNodes[j]);

          if (pObjectNode == NULL) return info;

          CCopasiObjectName cn = pObjectNode->getObjectCN();

          const CCopasiObject* mObject =
            static_cast< const CCopasiObject * >(mmModel->getObjectDataModel()->getObject(cn));

          if (mObject == NULL) return info;

          std::string host = "";

          if (mObject->isReference())
            {
              host = ",Reference=" + mObject->getObjectName();
              mObject = mObject->getObjectParent();
            }

          if (mObject == NULL) return info;

          std::string key = keyMap[(dynamic_cast<const CModelEntity * >(mObject))->getKey()];
          CCopasiObject*  pObject = (CCopasiRootContainer::getKeyFactory()->get(key));

          cn = pObject->getCN() + host;

          pObjectNode->setData("<" + cn + ">");
        }
    }

  tmp->updateTree();

  newEntity->setInitialExpression(tmp->getInfix().c_str());

  return info;
}
Exemple #2
0
bool CModelMerging::mergeInExpression(std::string toKey, std::string key, CExpression *pExpression)
{

  bool info = false;

  if (pExpression == NULL) return info;

  const std::vector<CEvaluationNode*>& objectNodes = pExpression->getNodeList();
  size_t j, jmax = objectNodes.size();

  for (j = 0; j < jmax; ++j)
    {
      if (CEvaluationNode::type(objectNodes[j]->getType()) == CEvaluationNode::OBJECT)
        {
          CEvaluationNodeObject* pObjectNode = dynamic_cast<CEvaluationNodeObject*>(objectNodes[j]);

          if (pObjectNode == NULL) return info;

          CCopasiObjectName cn = pObjectNode->getObjectCN();

          const CCopasiObject* mObject =
            static_cast< const CCopasiObject * >(mpModel->getObjectDataModel()->getObject(cn));

          if (mObject == NULL) return info;

          std::string host = "";

          if (mObject->isReference())
            {
              host = ",Reference=" + mObject->getObjectName();
              mObject = mObject->getObjectParent();
            }

          if (mObject == NULL) return info;

          CCopasiObject* pObject;

          std::string ikey = (dynamic_cast<const CModelEntity * >(mObject))->getKey();

          if (ikey == key)
            {
              pObject = (CCopasiRootContainer::getKeyFactory()->get(toKey));

              cn = pObject->getCN() + host;

              pObjectNode->setData("<" + cn + ">");
            }
        }
    }

  pExpression->updateTree();

  return true;
}
Exemple #3
0
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;
            }
        }
    }
}