Example #1
0
void SliderDialog::editSlider()
{
  SliderSettingsDialog* pSettingsDialog = new SliderSettingsDialog(this);
  // set the list of sliders that is already known
  CCopasiObject* object = (CCopasiObject*)getTaskForFolderId(mCurrentFolderId);

  if (!object) return;

  CCopasiDataModel * pDataModel = object->getObjectDataModel();
  assert(pDataModel != NULL);
  pSettingsDialog->setModel(pDataModel->getModel());

  std::vector<CSlider*>* pVector = getCSlidersForCurrentFolderId();
  pSettingsDialog->setDefinedSliders(*pVector);

  //pSettingsDialog->disableObjectChoosing(true);

  pSettingsDialog->setSlider(mpCurrSlider->getCSlider());

  if (pSettingsDialog->exec() == QDialog::Accepted)
    {
      addSlider(pSettingsDialog->getSlider());
      mpCurrSlider->updateSliderData();
      /*
      if ((!mpCurrSlider->isEnabled()) && mpCurrSlider->getCSlider()->compile())
        {
          mpCurrSlider->setEnabled(true);
        }
        */
    }

  delete pSettingsDialog;
  delete pVector;
}
Example #2
0
/**
 * This method is used for the export of several layout elements.
 * Layout elements can reference model elements, but when a referenced model element
 * is deleted, the layout is not infomred about this yet, so we end up with dnagling
 * references.
 * In order to not write these dangling references to file, we check if the reference
 * belongs to a valid object in the same datamodel. If not, we issue a warning.
 * This warning is only issued once during a save process.
 *
 * If the key belongs to an object in the same datamodel, true is returned, else false is returned.
 */
bool CLGraphicalObject::hasValidModelReference() const
{
  bool result = false;
  // check if the object for this key actually exists
  // TODO This is only a workaround because it is theoretically
  // TODO possible that the key no longer belongs to the same object it
  // TODO originally did.
  CCopasiObject* pObj = CCopasiRootContainer::getKeyFactory()->get(this->mModelObjectKey);

  if (pObj != NULL)
    {
      // check if the object actually belongs to the same
      // model as the text glyph
      const CCopasiDataModel* pDM1 = NULL;
      const CCopasiDataModel* pDM2 = NULL;
      const CCopasiContainer* pParent = pObj->getObjectParent();

      while (pParent != NULL)
        {
          pDM1 = dynamic_cast<const CCopasiDataModel*>(pParent);

          if (pDM1 != NULL)
            {
              break;
            }

          pParent = pParent->getObjectParent();
        }

      pParent = this->getObjectParent();

      while (pParent != NULL)
        {
          pDM2 = dynamic_cast<const CCopasiDataModel*>(pParent);

          if (pDM2 != NULL)
            {
              break;
            }

          pParent = pParent->getObjectParent();
        }

      //assert(pDM2 != NULL);
      if (pDM1 != NULL && pDM2 == NULL)
        {
          // if we have been able to resolve the model reference, but
          // don't have a datamodel parent, that is good enough
          return true;
        }

      if (pDM1 != NULL && pDM1 == pDM2)
        {
          result = true;
        }
    }

  return result;
}
Example #3
0
std::string CLGraphicalObject::getModelObjectName() const
{
  CCopasiObject * tmp = getModelObject();

  if (tmp)
    return tmp->getObjectName();
  else
    return "";
}
Example #4
0
std::string
SEDMLUtils::getXPathForObject(const CCopasiObject& object)
{
  const std::string& type = object.getObjectName();
  const CCopasiDataModel* dm = object.getObjectDataModel();
  std::string yAxis = object.getObjectDisplayName();
  std::string targetXPathString = getXPathAndName(yAxis, type,
                                  dm->getModel(), *dm);
  return targetXPathString;
}
Example #5
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;
}
Example #6
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;
}
Example #7
0
void CMoiety::initObjects()
{
  mpINumberReference = new CTotalNumberReference("InitialValue", this, mINumber);
  mpNumberReference = new CTotalNumberReference("Value", this, mNumber);

  mpDNumberReference = new CDependentNumberReference("DependentValue", this, mNumber);
  mpDNumberReference->addDirectDependency(this);

  CCopasiObject * pObject = addObjectReference("Amount", mIAmount, CCopasiObject::ValueDbl);
  pObject->addDirectDependency(mpNumberReference);

  return;
}
Example #8
0
std::string CLGraphicalObject::getModelObjectDisplayName(bool /* regular */, bool /* richtext */) const
{
  CCopasiObject * tmp = getModelObject();

  if (tmp)
    {
      return tmp->getObjectName();
    }
  else
    {
      return "";
    }
}
Example #9
0
/**
 * Returns a pointer to the CCopasiDataModel the element belongs to.
 * If there is no instance of CCopasiDataModel in the ancestor tree, NULL
 * is returned.
 */
CCopasiDataModel* CCopasiObject::getObjectDataModel()
{
  CCopasiObject * pObject = this;

  while (pObject != NULL)
    {
      if (pObject->isDataModel())
        return static_cast<CCopasiDataModel *>(pObject);

      pObject = pObject->getObjectParent();
    }

  return NULL;
}
Example #10
0
void CMIRIAMInfo::load(const std::string& key)
{
  pdelete(mpRDFGraph);

  mKey = key;
  CCopasiObject * pCopasiObject = dynamic_cast< CCopasiObject * >(CCopasiRootContainer::getKeyFactory()->get(mKey));

  if (pCopasiObject != NULL)
    {
      const std::string * pMiriamAnnotation = NULL;

      CAnnotation * pAnnotation = CAnnotation::castObject(pCopasiObject);

      if (pAnnotation != NULL)
        {
          pMiriamAnnotation = &pAnnotation->getMiriamAnnotation();
        }

      if (pMiriamAnnotation && *pMiriamAnnotation != "")
        mpRDFGraph = CRDFParser::graphFromXml(*pMiriamAnnotation);
    }

  if (mpRDFGraph == NULL)
    mpRDFGraph = new CRDFGraph;

  // We make sure that we always have an about node.

  if (pCopasiObject != NULL)
    mTriplet.pObject = mpRDFGraph->createAboutNode(pCopasiObject->getKey());
  else
    mTriplet.pObject = mpRDFGraph->createAboutNode("");

  // Load the created date if set;
  CRDFPredicate::Path Path = mTriplet.pObject->getPath();
  std::set< CRDFTriplet > Triples =
    mTriplet.pObject->getDescendantsWithPredicate(CRDFPredicate::dcterms_created);

  if (Triples.size() > 0)
    mCreated = *Triples.begin();
  else
    mCreated = CRDFTriplet(); // This is an invalid triplet, i.e., !mCreated is true.

  loadCreators();
  loadReferences();
  loadModifications();
  loadBiologicalDescriptions();

  return;
}
void ObjectBrowserWidget::loadField(ObjectBrowserItem* parent, CCopasiVector <CCopasiObject>* copaParent)
{
  unsigned int i;
  ObjectBrowserItem* lastFieldItem = NULL;
  CCopasiObject* currentFieldObject = NULL;
  ObjectBrowserItem* lastObjectItem = NULL;
  CCopasiObject* currentObject = NULL;

  if ((copaParent->size() < 1) || (!(*copaParent)[0]->isContainer())) return; //empty list

  const CCopasiContainer::objectMap * pFieldList =
    &(static_cast< CCopasiContainer * >((*copaParent)[0])->getObjects());

  CCopasiContainer::objectMap::const_iterator fieldIt = pFieldList->begin();
  CCopasiContainer::objectMap::const_iterator fieldEnd = pFieldList->end();

  while (fieldIt != fieldEnd)
    {
      currentFieldObject = fieldIt->second;
      ObjectBrowserItem* currentFieldItem = new ObjectBrowserItem(parent, lastFieldItem, NULL, objectItemList);
      currentFieldItem->attachKey();
      currentFieldItem->setObjectType(FIELDATTR);
      currentFieldItem->setText(0, FROM_UTF8(currentFieldObject->getObjectName()));
      lastFieldItem = currentFieldItem;
      lastObjectItem = NULL;

      for (i = 0; i < copaParent->size(); i++)
        {
          CCopasiObject* pSubField;
          currentObject = (*static_cast< CCopasiVector < CCopasiObject > * >(copaParent))[i];

          if (currentObject->isContainer())
            pSubField =
              getFieldCopasiObject(static_cast< CCopasiContainer * >(currentObject),
                                   FROM_UTF8(currentFieldObject->getObjectName()));
          else
            {
              pSubField = NULL; // this shall be an exception error
            }

          ObjectBrowserItem* currentItem = new ObjectBrowserItem(currentFieldItem, lastObjectItem, pSubField, objectItemList);
          currentItem->setText(0, FROM_UTF8(currentObject->getObjectName()));
          //   if ((pSubField)&&(pSubField->isVector()))
          //            currentItem->setText(0, currentItem->text(0) + "[]");
          currentItem->setObjectType(FIELDATTR);
          currentItem->attachKey();

          if (pSubField)
            if (pSubField->isContainer()) //container field recursively to find all possible items
              {
                loadChild(currentItem, static_cast< CCopasiContainer * >(pSubField), false); // wont show the attribute and field list
              }

          lastObjectItem = currentItem;
        }

      fieldIt++;
    }
}
bool CExperimentObjectMap::compile(const std::vector< CCopasiContainer * > listOfContainer)
{
  size_t i, imax = size();
  size_t Column;

  // We need to find out the size of the object map
  if (imax == 0)
    mLastColumn = C_INVALID_INDEX;
  else
    {
      mLastColumn = strtoul(getName(0).c_str(), NULL, 0);

      for (i = 1; i < imax; i++)
        {
          Column = strtoul(getName(i).c_str(), NULL, 0);

          if (mLastColumn < Column)
            mLastColumn = Column;
        }
    }

  mObjects.resize(mLastColumn + 1);
  mObjects = NULL;

  CCopasiObject * pObject = NULL;
  std::string CN;

  for (i = 0; i < imax; i++)
    {
      if ((CN = getObjectCN(i)) == "") continue;

      if ((pObject =
             getObjectDataModel()->ObjectFromName(listOfContainer, CN)) != NULL &&
          pObject->isValueDbl())
        {
          Column = strtoul(getName(i).c_str(), NULL, 0);
          mObjects[Column] = pObject;
        }
      else
        return false;
    }

  return true;
}
Example #13
0
/**
 * Since labels are not part of the model, we can't use the new method for
 * getting the text but have to fall back to the old
 * behavior.
 * Hopefully I can get rid of this implementation sonner than later.
 */
std::string CLabel::getText() const
{
  if (mIsTextSet)
    {
      return mText;
    }
  else
    {
      CCopasiObject* pObject = CCopasiRootContainer::getKeyFactory()->get(this->mModelObjectKey);

      if (pObject)
        {
          return pObject->getObjectName();
        }
      else
        {
          return "unset";
        }
    }
}
Example #14
0
void printNameForKey(std::ostringstream& stream, CKeyFactory* kf, const std::string& key, const std::string prefix = "")
{
  CCopasiObject* obj = kf->get(key);

  if (obj != NULL)
    {
      stream << "\"" << prefix << obj->getObjectName() << "\", ";
    }
  else if (startsWith(key, "sm_"))
    {
      printNameForKey(stream, kf, key.substr(3), "");
    }
  else if (startsWith(key, "ode_"))
    {
      printNameForKey(stream, kf, key.substr(4), "ODE ");
    }
  else
    {
      stream << "\"" << prefix << key << "\", ";
    }
}
Example #15
0
std::vector<CCopasiObject*> CSensItem::getVariablesPointerList(CCopasiDataModel* pDataModel)
{
  std::vector<CCopasiObject*> ret;

  if (isSingleObject())
    {
      CCopasiObject * tmpObject = const_cast<CCopasiObject *>(pDataModel->getObject(getSingleObjectCN()));

      if (!tmpObject) {return ret;}  //return empty list

      if (!tmpObject->isValueDbl()) {return ret;}  //return empty list

      ret.push_back(tmpObject);
    }
  else
    {
      ret = CObjectLists::getListOfObjects(getListType(), pDataModel->getModel());
    }

  return ret;
}
Example #16
0
void DefaultPlotDialog::slotCreate()
{
  if (!mpTask) return;

  CCopasiDataModel* pDataModel = ListViews::dataModel(parent());
  assert(pDataModel != NULL);

  CCopasiObject* result = COutputAssistant::createDefaultOutput(mIndex, mpTask, pDataModel);

  if (result != NULL)
    {
      QString current = lineEditTitle->text();
      int count = 0;

      while (!result->setObjectName(TO_UTF8(current)))
        current = QString("%1 %2").arg(lineEditTitle->text()).arg(++count);

      this->accept();
    }
  else
    this->reject();
}
void ObjectBrowserWidget::loadChild(ObjectBrowserItem* parent,
                                    const CCopasiContainer* copaParent,
                                    bool nField)
{
  unsigned int i;
  ObjectBrowserItem* last = NULL;
  CCopasiObject* current = NULL;

  ObjectList* childStack = new ObjectList();

  const CCopasiContainer::objectMap * pObjectList = & copaParent->getObjects();
  CCopasiContainer::objectMap::const_iterator it = pObjectList->begin();
  CCopasiContainer::objectMap::const_iterator end = pObjectList->end();

  if ((copaParent->isVector()) && (nField))
    {
      if ((static_cast< const CCopasiVector < CCopasiObject > * >(copaParent)->size() >= 1) &&
          ((*static_cast< const CCopasiVector < CCopasiObject > * >(copaParent))[0]->isContainer()))
        {//add attribute list
          ObjectBrowserItem* fieldChild = new ObjectBrowserItem(parent, NULL, NULL, objectItemList);
          fieldChild->setObjectType(FIELDATTR);
          fieldChild->setText(0, "Select by attribute");
          fieldChild->setSelectable(false);
          loadField(fieldChild, const_cast<CCopasiVector < CCopasiObject > *>(static_cast< const CCopasiVector < CCopasiObject > * >(copaParent)));
          fieldChild->attachKey();
          last = fieldChild;
        }
    }

  if (copaParent->isVector())
    {
      for (i = 0; i < static_cast< const CCopasiVector < CCopasiObject > * >(copaParent)->size(); i++)
        {
          current = (*static_cast< const CCopasiVector < CCopasiObject > * >(copaParent))[i];
          ObjectBrowserItem* currentItem = new ObjectBrowserItem(parent, last, current, objectItemList);
          last = currentItem;
          currentItem->setText(0, FROM_UTF8(current->getObjectName()));

          if (current->isContainer())
            {
              currentItem->setObjectType(CONTAINERATTR);
              currentItem->attachKey();

              if (current->isVector())
                currentItem->setText(0, currentItem->text(0) + "[]");

              loadChild(currentItem, static_cast< CCopasiContainer * >(current), nField);
            }
          else
            {
              currentItem->setObjectType(OBJECTATTR);
              childStack->insert(currentItem);  //attach the key later
            }
        }
    }
  else
    {
      while (it != end)
        {
          current = it->second;

          // Skip all strings
          if (dynamic_cast<CCopasiStaticString *>(current))
            {
              it++;
              continue;
            }

          ObjectBrowserItem* currentItem = new ObjectBrowserItem(parent, last, current, objectItemList);
          last = currentItem;
          currentItem->setText(0, FROM_UTF8(current->getObjectName()));

          if (current->isContainer())
            {
              currentItem->setObjectType(CONTAINERATTR);
              currentItem->attachKey();

              if (current->isVector())
                currentItem->setText(0, currentItem->text(0) + "[]");

              loadChild(currentItem, static_cast< CCopasiContainer * >(current), nField);
            }
          else
            {
              currentItem->setObjectType(OBJECTATTR);
              childStack->insert(currentItem);  //attach the key later
            }

          it++;
        }
    }

  ObjectBrowserItem* pCurrent;

  while (childStack->len() > 0)
    {
      pCurrent = childStack->pop();
      pCurrent->attachKey();
    }

  pdelete(childStack);
}
Example #18
0
// virtual
bool COPASIHandler::processEnd(const XML_Char * pszName)
{
  bool finished = false;

  switch (mCurrentElement.first)
    {
      case COPASI:
      {
        // We need to handle the unmapped parameters of type key.
        std::vector< std::string >::iterator it = mpData->UnmappedKeyParameters.begin();
        std::vector< std::string >::iterator end = mpData->UnmappedKeyParameters.end();

        for (; it != end; ++it)
          {
            CCopasiParameter * pParameter =
              dynamic_cast< CCopasiParameter * >(CCopasiRootContainer::getKeyFactory()->get(*it));

            if (pParameter != NULL &&
                pParameter->getType() == CCopasiParameter::KEY)
              {
                CCopasiObject * pObject =
                  mpData->mKeyMap.get(pParameter->getValue< std::string >());

                if (pObject != NULL)
                  pParameter->setValue(pObject->getKey());
                else
                  pParameter->setValue(std::string(""));
              }
          }

        // We need to remove the no longer needed expression "Objective Function" from the function list.
        if (mpData->pFunctionList != NULL &&
            mpData->pFunctionList->getIndex("Objective Function") != C_INVALID_INDEX)
          {
            mpData->pFunctionList->remove("Objective Function");
          }
      }

      finished = true;
      break;

      case ParameterGroup:
        finished = true;
        break;

      case ListOfFunctions:
      case Model:
      case ListOfTasks:
      case ListOfReports:
      case ListOfPlots:
      case ListOfLayouts:
      case SBMLReference:
      case ListOfUnitDefinitions:
        break;

      case GUI:
        if (mpData->pGUI == NULL)
          {
            CCopasiMessage::getLastMessage();
          }

        break;

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

  return finished;
}
Example #19
0
// virtual
bool CModelParameter::updateModel()
{
    bool success = true;

    if (mpObject != NULL)
    {
        switch (mType)
        {
        case Model:
        {
            CModel * pModel = static_cast< CModel * >(mpObject);

            if (!pModel->isAutonomous())
            {
                pModel->setInitialValue(mValue);
            }
            else
            {
                pModel->setInitialValue(0.0);
            }
        }
        break;

        case Compartment:
        case Species:
        case ModelValue:
        {
            CModelEntity * pEntity = static_cast< CModelEntity * >(mpObject);

            if (pEntity->getStatus() != CModelEntity::ASSIGNMENT)
            {
                pEntity->setInitialValue(mValue);

                if (mIsInitialExpressionValid)
                {
                    pEntity->setInitialExpression(getInitialExpression());
                }
            }
        }
        break;

        case ReactionParameter:
        {
            CCopasiParameter * pParameter = static_cast< CCopasiParameter * >(mpObject);
            CReaction * pReaction = static_cast< CReaction * >(mpObject->getObjectAncestor("Reaction"));

            if (mIsInitialExpressionValid &&
                    getInitialExpression() != "")
            {
                CModel * pModel = mpParent->getModel();

                assert(pModel != NULL);

                std::vector< CCopasiContainer * > ListOfContainer;
                ListOfContainer.push_back(pModel);

                CCopasiObjectName CN = static_cast< CEvaluationNodeObject * >(mpInitialExpression->getRoot())->getObjectCN();
                CCopasiObject * pObject = pModel->getObjectDataModel()->ObjectFromName(ListOfContainer, CN);

                assert(pObject != NULL);

                // We assign the object value
                pParameter->setValue(* (C_FLOAT64 *) pObject->getValuePointer());

                // We map the parameter to the global quantity
                pReaction->setParameterMapping(pParameter->getObjectName(), pObject->getObjectParent()->getKey());
            }
            else
            {
                pParameter->setValue(mValue);

                // We need to remove the existing mapping to a global quantity1.
                pReaction->setParameterMapping(pParameter->getObjectName(), pParameter->getKey());
            }
        }
        break;

        default:
            success = false;
            break;
        }
    }

    return success;
}
Example #20
0
// virtual
CXMLHandler * ParameterHandler::processStart(const XML_Char * pszName,
    const XML_Char ** papszAttrs)
{
  CXMLHandler * pHandlerToCall = NULL;

  const char * cValue = NULL;
  const char * cType = NULL;

  std::string name;
  std::string sValue("");
  bool UnmappedKey = false;

  void * pValue = NULL;
  CCopasiParameter::Type type;

  C_FLOAT64 d;
  C_INT32 i;
  size_t ui;
  bool b;

  switch (mCurrentElement.first)
    {
      case Parameter:
        // Parameter has attributes name, type and value
        name = mpParser->getAttributeValue("name", papszAttrs);
        cType = mpParser->getAttributeValue("type", papszAttrs);
        type = toEnum(cType, CCopasiParameter::XMLType, CCopasiParameter::INVALID);
        cValue = mpParser->getAttributeValue("value", papszAttrs);

        if (cValue != NULL)
          {
            sValue = cValue;
          }

        switch (type)
          {
            case CCopasiParameter::DOUBLE:
              d = CCopasiXMLInterface::DBL(sValue.c_str());
              pValue = &d;
              break;

            case CCopasiParameter::UDOUBLE:
              d = CCopasiXMLInterface::DBL(sValue.c_str());
              pValue = &d;
              break;

            case CCopasiParameter::INT:
              i = strToInt(sValue.c_str());
              pValue = &i;
              break;

            case CCopasiParameter::UINT:
              ui = strToUnsignedInt(sValue.c_str());
              pValue = &ui;
              break;

            case CCopasiParameter::BOOL:

              if (sValue == "0" || sValue == "false")
                {
                  b = false;
                }
              else
                {
                  b = true;
                }

              pValue = &b;
              break;

            case CCopasiParameter::STRING:
            case CCopasiParameter::FILE:
            case CCopasiParameter::CN:
              pValue = &sValue;
              break;

            case CCopasiParameter::KEY:
            {
              if (sValue != "" &&
                  CKeyFactory::isValidKey(sValue))
                {
                  CCopasiObject * pObject = mpData->mKeyMap.get(sValue);

                  if (pObject)
                    {
                      sValue = pObject->getKey();
                    }
                  else
                    {
                      UnmappedKey = true;
                    }
                }

              pValue = &sValue;
            }
            break;

            default:
              CCopasiMessage(CCopasiMessage::ERROR, MCXML + 16, name.c_str(), cType, mpParser->getCurrentLineNumber());
              pValue = NULL;
              break;
          }

        mpData->pCurrentParameter = new CCopasiParameter(name, type, pValue);

        if (UnmappedKey)
          {
            mpData->UnmappedKeyParameters.push_back(mpData->pCurrentParameter->getKey());
          }

        break;

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

  return pHandlerToCall;
}
Example #21
0
bool CODEExporterC::exportTitleData(const CModel* copasiModel, std::ostream & os)
{

  size_t metab_size = copasiModel->getMetabolitesX().size();
  size_t indep_size = copasiModel->getNumIndependentReactionMetabs();
  size_t ode_size = copasiModel->getNumODEMetabs();
  size_t comps_size = copasiModel->getCompartments().size();
  size_t modvals_size = copasiModel->getModelValues().size();
  size_t reacs_size = copasiModel->getReactions().size();

  size_t i, j, num_params, count;
  const CCopasiVector< CReaction > & reacs = copasiModel->getReactions();
  const CReaction* reac;

  count = 0;

  for (i = 0; i < reacs_size; ++i)
    {

      reac = &reacs[i];
      num_params = reac->getParameters().size();

      for (j = 0; j < num_params; ++j)
        {
          if (reac->isLocalParameter(j))
            ++count;
        }
    }

  size_t numX = 0;
  size_t numY = 0;
  size_t numXC = 0;
  size_t numYC = 0;
  size_t numPC = 0;
  size_t numP = 0;
  size_t numDX = 0;
  size_t numCT = 0;

  std::ostringstream p_names;  p_names  << "const char* p_names[] = {";
  std::ostringstream x_names;  x_names  << "const char* x_names[] = {";
  std::ostringstream y_names;  y_names  << "const char* y_names[] = {";
  std::ostringstream xc_names; xc_names << "const char* xc_names[] = {";
  std::ostringstream pc_names; pc_names << "const char* pc_names[] = {";
  std::ostringstream yc_names; yc_names << "const char* yc_names[] = {";
  std::ostringstream dx_names; dx_names << "const char* dx_names[] = {";
  std::ostringstream ct_names; ct_names << "const char* ct_names[] = {";

  CKeyFactory* kf = CCopasiRootContainer::getKeyFactory();

  std::map< std::string, std::string >::const_iterator it = NameMap.begin();
  std::map< std::string, std::string > reverse_map;

  while (it != NameMap.end())
    {
      const std::string& abbrev = it->second;
      const std::string& key = it->first;

      if (startsWith(abbrev, "p["))
        {
          reverse_map[abbrev] = key;
          ++numP;
        }
      else if (startsWith(abbrev, "x["))
        {
          reverse_map[abbrev] = key;
          ++numX;
        }
      else if (startsWith(abbrev, "y["))
        {
          reverse_map[abbrev] = key;
          ++numY;
        }
      else if (startsWith(abbrev, "dx["))
        {
          reverse_map[abbrev] = key;
          ++numDX;
        }
      else if (startsWith(abbrev, "ct["))
        {
          reverse_map[abbrev] = key;
          ++numCT;
        }
      else if (startsWith(abbrev, "x_c["))
        {
          CCopasiObject* obj = kf->get(key);

          if (obj != NULL)
            {
              reverse_map[abbrev] = obj->getObjectName();
            }
          else
            {
              reverse_map[abbrev] = key;
            }

          ++numXC;
        }
      else if (startsWith(abbrev, "p_c["))
        {
          CCopasiObject* obj = kf->get(key);

          if (obj != NULL)
            {
              reverse_map[abbrev] = obj->getObjectName();
            }
          else
            {
              reverse_map[abbrev] = key;
            }

          ++numPC;
        }
      else if (startsWith(abbrev, "y_c["))
        {
          CCopasiObject* obj = kf->get(key);

          if (obj != NULL)
            {
              reverse_map[abbrev] = obj->getObjectName();
            }
          else
            {
              reverse_map[abbrev] = key;
            }

          ++numYC;
        }

      ++it;
    }

  for (size_t i = 0; i < numP; ++i)
    {
      std::stringstream str; str << "p[" << i << "]";
      printNameForKey(p_names, kf, reverse_map[str.str()]);
    }

  for (size_t i = 0; i < numX; ++i)
    {
      std::stringstream str; str << "x[" << i << "]";
      printNameForKey(x_names, kf, reverse_map[str.str()]);
    }

  for (size_t i = 0; i < numY; ++i)
    {
      std::stringstream str; str << "y[" << i << "]";
      printNameForKey(y_names, kf, reverse_map[str.str()]);
    }

  for (size_t i = 0; i < numDX; ++i)
    {
      std::stringstream str; str << "dx[" << i << "]";
      printNameForKey(dx_names, kf, reverse_map[str.str()]);
    }

  for (size_t i = 0; i < numCT; ++i)
    {
      std::stringstream str; str << "ct[" << i << "]";
      printNameForKey(ct_names, kf, reverse_map[str.str()]);
    }

  for (size_t i = 0; i < numXC; ++i)
    {
      std::stringstream str; str << "x_c[" << i << "]";
      xc_names << "\"" << reverse_map[str.str()] << "\", ";
    }

  for (size_t i = 0; i < numPC; ++i)
    {
      std::stringstream str; str << "p_c[" << i << "]";
      pc_names << "\"" << reverse_map[str.str()] << "\", ";
    }

  for (size_t i = 0; i < numYC; ++i)
    {
      std::stringstream str; str << "y_c[" << i << "]";
      yc_names << "\"" << reverse_map[str.str()] << "\", ";
    }

  os << "#ifdef SIZE_DEFINITIONS" << std::endl;
  os << "#define N_METABS " << metab_size << std::endl;
  os << "#define N_ODE_METABS " << ode_size << std::endl;
  os << "#define N_INDEP_METABS " << indep_size << std::endl;
  os << "#define N_COMPARTMENTS " << comps_size << std::endl;
  os << "#define N_GLOBAL_PARAMS " << modvals_size << std::endl;
  os << "#define N_KIN_PARAMS " << count << std::endl;
  os << "#define N_REACTIONS " << reacs_size << std::endl << std::endl;

  os << "#define N_ARRAY_SIZE_P  " << numP  << "\t// number of parameters" << std::endl;
  os << "#define N_ARRAY_SIZE_X  " << numX  << "\t// number of initials" << std::endl;
  os << "#define N_ARRAY_SIZE_Y  " << numY  << "\t// number of assigned elements" << std::endl;
  os << "#define N_ARRAY_SIZE_XC " << numXC << "\t// number of x concentration" << std::endl;
  os << "#define N_ARRAY_SIZE_PC " << numPC << "\t// number of p concentration" << std::endl;
  os << "#define N_ARRAY_SIZE_YC " << numYC << "\t// number of y concentration" << std::endl;
  os << "#define N_ARRAY_SIZE_DX " << numDX << "\t// number of ODEs " << std::endl;
  os << "#define N_ARRAY_SIZE_CT " << numCT << "\t// number of conserved totals" << std::endl << std::endl;

  os << "#endif // SIZE_DEFINITIONS" << std::endl;
  os << std::endl;

  os << "#ifdef TIME" << std::endl;
  os << "#define T  <set here a user name for the time variable> " << std::endl;
  os << "#endif // TIME" << std::endl;

  os << std::endl;
  os << "#ifdef NAME_ARRAYS" << std::endl;
  os << p_names.str()  << " \"\" };" << std::endl;
  os << x_names.str()  << " \"\" };" << std::endl;
  os << y_names.str()  << " \"\" };" << std::endl;
  os << xc_names.str() << " \"\" };" << std::endl;
  os << pc_names.str() << " \"\" };" << std::endl;
  os << yc_names.str() << " \"\" };" << std::endl;
  os << dx_names.str() << " \"\" };" << std::endl;
  os << ct_names.str() << " \"\" };" << std::endl;
  os << "#endif // NAME_ARRAYS" << std::endl;

  return true;
}
Example #22
0
std::string CODEExporterC::KineticFunction2ODEmember(const CReaction *reac)
{
  std::ostringstream equation;

  if (reac->getFunction()->getType() != CEvaluationTree::MassAction)
    {
      const CFunctionParameters & params = reac->getFunctionParameters();
      size_t k, params_size = params.size();
      const std::vector<std::vector<std::string> > & keyMap = reac->getParameterMappings();
      std::string name;
      equation << NameMap[reac->getFunction()->getKey()] << "(";

      for (k = 0; k < params_size; ++k)
        {

          CFunctionParameter::Role role = params[k]->getUsage();

          CCopasiObject * obj = CCopasiRootContainer::getKeyFactory()->get(keyMap[k][0]);

          if ((role == CFunctionParameter::SUBSTRATE)
              || (role == CFunctionParameter::PRODUCT)
              || (role == CFunctionParameter::MODIFIER))
            {
              if (obj)
                name = NameMap[obj->getKey()];
              else
                name = "unknown";
            }

          if (role == CFunctionParameter::PARAMETER)
            {
              if (!(reac->isLocalParameter(k)))
                {
                  CModelValue* modval;
                  modval = dynamic_cast< CModelValue * >(obj);
                  name = NameMap[modval->getKey()];
                }
              else
                {
                  CCopasiParameter* param;
                  param = dynamic_cast< CCopasiParameter * >(obj);
                  name = NameMap[param->getKey()];
                }
            }

          if (role == CFunctionParameter::VOLUME)
            {
              CCompartment* comp;
              comp = dynamic_cast< CCompartment * >(obj);
              name = NameMap[comp->getKey()];
            }

          if (role == CFunctionParameter::TIME)
            {
              name = "T";
            }

          if (name.empty())
            {
              std::string message = "Could not export C code, since one of the arguments could not be resolved. Please consider filing a bug with the COPASI tracker: http://www.copasi.org/tracker";
              CCopasiMessage(CCopasiMessage::EXCEPTION, message.c_str());
            }

          equation << name;

          if (k != params_size - 1)
            equation << ", ";
        }

      equation << ")";
    }
  else
    {
      const CCopasiVector<CChemEqElement> & substrs = reac->getChemEq().getSubstrates();
      const CCopasiVector<CChemEqElement> & prods = reac->getChemEq().getProducts();
      const std::vector<std::vector<std::string> > & keyMap = reac->getParameterMappings();
      CCopasiObject * obj;

      size_t substrs_size = substrs.size(), prods_size = prods.size();
      size_t k, m, mult;

      const CChemEqElement* substr;
      const CChemEqElement* prod;

      const CMassAction & cMassAction = *static_cast<const CMassAction*>(reac->getFunction());

      equation << "(";

      obj = CCopasiRootContainer::getKeyFactory()->get(keyMap[0][0]);

      if (!(reac->isLocalParameter(0)))
        {
          CModelValue* modval;
          modval = dynamic_cast< CModelValue * >(obj);

          equation << NameMap[modval->getKey()];
        }
      else
        {
          CCopasiParameter* param;
          param = dynamic_cast< CCopasiParameter * >(obj);

          equation << NameMap[param->getKey()];
        }

      for (k = 0; k < substrs_size; ++k)
        {
          substr = &substrs[k];
          mult = (size_t) substr->getMultiplicity();

          assert(substr->getMetabolite());
          equation << " * " << NameMap[substr->getMetabolite()->getKey()];

          if (mult > 1)
            for (m = 1; m < mult; ++m)
              equation << " * " << NameMap[substr->getMetabolite()->getKey()];
        }

      if (cMassAction.isReversible() == TriTrue)
        {
          equation << " - ";

          obj = CCopasiRootContainer::getKeyFactory()->get(keyMap[2][0]);

          if (!(reac->isLocalParameter(2)))
            {
              CModelValue* modval;
              modval = dynamic_cast< CModelValue * >(obj);

              equation << NameMap[modval->getKey()];
            }
          else
            {
              CCopasiParameter* param;
              param = dynamic_cast< CCopasiParameter * >(obj);

              equation << NameMap[param->getKey()];
            }

          for (k = 0; k < prods_size; ++k)
            {
              prod = &prods[k];
              mult = (size_t) prod->getMultiplicity();

              assert(prod->getMetabolite());
              equation << " * " << NameMap[prod->getMetabolite()->getKey()];

              if (mult > 1)
                for (m = 1; m < mult; ++m)
                  equation << " * " << NameMap[prod->getMetabolite()->getKey()];
            }
        }

      equation << ") ";
    }

  return equation.str();
}
Example #23
0
void CMMLOutput::createParameterMapping(const CReaction* pReac,
                                        std::vector<std::vector<std::string> > & params,
                                        bool numbers)
{
  assert(pReac);
  assert(pReac->getFunction());

  const CFunctionParameters & functionParams = pReac->getFunctionParameters();
  size_t j, jmax;
  size_t i, imax = functionParams.size();
  params.resize(imax);

  for (i = 0; i < imax; ++i)
    {
      params[i].resize(1);

      std::string name;

      //std::ostringstream number;
      switch (functionParams[i]->getUsage())
        {
          case CFunctionParameter::SUBSTRATE:
          case CFunctionParameter::PRODUCT:
          case CFunctionParameter::MODIFIER:

            if (functionParams[i]->getType() == CFunctionParameter::FLOAT64)
              {
                CCopasiObject * pObject = CCopasiRootContainer::getKeyFactory()->get(pReac->getParameterMappings()[i][0]);

                if (pObject != NULL)
                  {
                    name = pObject->getObjectDisplayName();
                  }
                else
                  {
                    name = "unknown";
                  }

                //params[i][0] = "<mi>"+ CMathMl::fixName(name)+"</mi>";
                params[i][0] = "<mi>[" + CMathMl::fixName(name) + "]</mi>";
              }
            else if (functionParams[i]->getType() == CFunctionParameter::VFLOAT64)
              {
                jmax = pReac->getParameterMappings()[i].size();
                params[i].resize(jmax);

                for (j = 0; j < jmax; ++j)
                  {
                    name = CCopasiRootContainer::getKeyFactory()->get(pReac->getParameterMappings()[i][j])->getObjectDisplayName();
                    //params[i][j] = "<mi>"+ CMathMl::fixName(name)+"</mi>";
                    params[i][j] = "<mi>[" + CMathMl::fixName(name) + "]</mi>";
                  }
              }
            else assert(false);

            break;

          case CFunctionParameter::PARAMETER:

            if (pReac->isLocalParameter(i))
              {
                if (numbers)
                  {
                    std::ostringstream number;
                    number << pReac->getParameterValue(functionParams[i]->getObjectName());
                    params[i][0] = "<mn>" + number.str() + "</mn>";
                  }
                else
                  {
                    name = CCopasiRootContainer::getKeyFactory()->get(pReac->getParameterMappings()[i][0])->getObjectName();
                    //params[i][0] = "<mi>" + CMathMl::fixName(name) + "</mi>";
                    params[i][0] = "<msub><mi>" + CMathMl::fixName(name) + "</mi><mi>("
                                   + CMathMl::fixName(pReac->getObjectName()) + ")</mi></msub>";
                  }
              }
            else
              {
                name = CCopasiRootContainer::getKeyFactory()->get(pReac->getParameterMappings()[i][0])->getObjectName();
                params[i][0] = "<mi>" + CMathMl::fixName(name) + "</mi>";
                //params[i][0] = "<mi>ggg</mi>";
              }

            break;

          case CFunctionParameter::VOLUME:
            name = CCopasiRootContainer::getKeyFactory()->get(pReac->getParameterMappings()[i][0])->getObjectName();
            params[i][0] = "<msub><mi>V</mi><mi>" + CMathMl::fixName(name)
                           + "</mi></msub>";
            break;

          case CFunctionParameter::TIME:
            params[i][0] = "<mi>time</mi>";
            break;

          default:
            break;
        }
    }
}
Example #24
0
void SliderDialog::createNewSlider()
{
  // allow the user to create more than one slider
  std::vector<const CCopasiObject*> objects = CCopasiSelectionDialog::getObjectVector(this,
      CQSimpleSelectionTree::InitialTime |
      CQSimpleSelectionTree::Parameters);
  std::vector<CSlider*>* pVector = getCSlidersForCurrentFolderId();
  std::vector<const CCopasiObject*>::const_iterator it = objects.begin(), endit = objects.end();
  bool yesToAll = false;
  bool noToAll = false;
  // create the sliders for all the selected objects

  // first we need the task object because we need it later to associate the
  // later with the correct task
  CCopasiObject* object = (CCopasiObject*)getTaskForFolderId(mCurrentFolderId);

  if (!object) return;

  CCopasiObject* pTmpObject = NULL;

  while (it != endit)
    {
      // create a new slider
      assert((*it) != NULL);
      pTmpObject = const_cast<CCopasiObject*>(determineCorrectObjectForSlider(*it));

      CSlider* pCSlider = new CSlider("slider", (*CCopasiRootContainer::getDatamodelList())[0]);

      if (pCSlider)
        {
          pCSlider->setSliderObject(pTmpObject);
          pCSlider->setAssociatedEntityKey(object->getKey());
          // check if a slider for that object already exists and if so, prompt
          // the user what to do
          CSlider* pEquivalentSlider = equivalentSliderExists(pCSlider);

          if (pEquivalentSlider != NULL)
            {
              CopasiSlider* pCopasiSlider = NULL;

              // if the user has specified yesToAll, we reset the ranges of all
              // duplicate sliders
              if (yesToAll)
                {
                  pEquivalentSlider->resetRange();
                  // update the slider widget
                  pCopasiSlider = findCopasiSliderForCSlider(pEquivalentSlider);
                  assert(pCopasiSlider != NULL);

                  if (pCopasiSlider != NULL)
                    {
                      pCopasiSlider->updateSliderData();
                    }
                }
              // if the user has not specified noToAll, we need to prompt
              else if (!noToAll)
                {
                  QMessageBox::StandardButton result = CQMessageBox::information(NULL, "Slider Exists",
                                                       "A slider for this object already exists.\n\nDo you want to reset the range of the slider?",
                                                       QMessageBox::Yes | QMessageBox::No | QMessageBox::YesToAll | QMessageBox::NoToAll, QMessageBox::No);

                  // check the answer and maybe set some flags
                  switch (result)
                    {
                      case QMessageBox::YesToAll:
                        // set the flag
                        yesToAll = true;

                      case QMessageBox::Yes:
                        // reset the range
                        pEquivalentSlider->resetRange();
                        // update the slider widget
                        pCopasiSlider = findCopasiSliderForCSlider(pEquivalentSlider);
                        assert(pCopasiSlider != NULL);

                        if (pCopasiSlider != NULL)
                          {
                            pCopasiSlider->updateSliderData();
                          }

                        break;

                      case QMessageBox::NoToAll:
                        // set the flag
                        noToAll = true;
                        break;

                      case QMessageBox::No:
                        // do nothing else
                        break;

                      default:
                        // do nothing
                        break;
                    }
                }

              delete pCSlider;
            }
          else
            {
              std::vector<CCopasiContainer*> listOfContainers;
              assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
              listOfContainers.push_back((*CCopasiRootContainer::getDatamodelList())[0]->getModel());
              pCSlider->compile(listOfContainers);
              pCSlider->resetRange();
              addSlider(pCSlider);
              mChanged = true;
            }
        }

      ++it;
    }

  delete pVector;
}
Example #25
0
void CQEventWidget1::addEvent(UndoEventData *pSData)
{
  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
  CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0];
  assert(pDataModel != NULL);

  CModel * pModel = pDataModel->getModel();
  assert(pModel != NULL);

  //reinsert the Event
  CEvent *pEvent =  pModel->createEvent(pSData->getName());

  //set the expressions
  pEvent->setTriggerExpression(pSData->getTriggerExpression());
  pEvent->setDelayExpression(pSData->getDelayExpression());
  pEvent->setPriorityExpression(pSData->getPriorityExpression());

  QList <UndoEventAssignmentData *> *assignmentData = pSData->getEventAssignmentData();
  QList <UndoEventAssignmentData *>::const_iterator i;

  for (i = assignmentData->begin(); i != assignmentData->end(); ++i)
    {
      UndoEventAssignmentData * assignData = *i;

      CCopasiObject * pObject = NULL;
      bool speciesExist = false;
      size_t ci;

      for (ci = 0; ci < pModel->getCompartments().size(); ci++)
        {
          CCompartment * pCompartment = pModel->getCompartments()[ci];

          if (pCompartment->getMetabolites().getIndex(assignData->getName()) != C_INVALID_INDEX)
            speciesExist = true;
        }

      if (speciesExist)
        {
          size_t index = pModel->findMetabByName(assignData->getName());
          pObject =  pModel->getMetabolites()[index];
        }
      else if (pModel->getModelValues().getIndex(assignData->getName()) != C_INVALID_INDEX)
        {
          pObject = pModel->getModelValues()[assignData->getName()];
        }
      else if (pModel->getReactions().getIndex(assignData->getName()) != C_INVALID_INDEX)
        {
          pObject = pModel->getReactions()[assignData->getName()];
        }

      const CModelEntity * pEntity = dynamic_cast< const CModelEntity * >(pObject);
      CEventAssignment *eventAssign = new CEventAssignment(pObject->getKey(), pEvent->getObjectParent());
      eventAssign->setExpression(assignData->getExpression());
      eventAssign->getExpressionPtr()->compile();
      pEvent->getAssignments().add(eventAssign);
    }

  std::string key = pEvent->getKey();
  protectedNotify(ListViews::EVENT, ListViews::ADD, key);

  mpListView->switchToOtherWidget(C_INVALID_INDEX, key);
}
Example #26
0
/**
 * Creates the data generators for SEDML.
 */
void CSEDMLExporter::createDataGenerators(CCopasiDataModel & dataModel,
    std::string & taskId,
    CCopasiTask* task)
{
  const CModel* pModel = dataModel.getModel();
  std::vector<std::string> stringsContainer; //split string container

  if (pModel == NULL)
    CCopasiMessage(CCopasiMessage::ERROR, "SED-ML: No model for this SED-ML document. An SBML model must exist for every SED-ML document.");

  SedPlot2D* pPSedPlot;
  SedCurve* pCurve; // = pPSedPlot->createCurve();

  //create generator for special varibale time
  const CCopasiObject* pTime = static_cast<const CCopasiObject *>(dataModel.getModel()->getObject(CCopasiObjectName("Reference=Time")));
  SedDataGenerator *pTimeDGenp = this->mpSEDMLDocument->createDataGenerator();
  pTimeDGenp->setId("time");
  pTimeDGenp->setName(pTime->getObjectName());
  SedVariable *pTimeVar = pTimeDGenp->createVariable();
  pTimeVar->setId("var_time");
  pTimeVar->setTaskReference(taskId);
  pTimeVar->setSymbol(SEDML_TIME_URN);
  pTimeDGenp->setMath(SBML_parseFormula(pTimeVar->getId().c_str()));

  size_t i, imax = dataModel.getPlotDefinitionList()->size();
  SedDataGenerator *pPDGen;

  if (imax == 0 && (task == NULL || task->getReport().getTarget().empty()))
    CCopasiMessage(CCopasiMessage::ERROR, "SED-ML: No plot/report definition for this SED-ML document.");

  // export report
  if (task != NULL && !task->getReport().getTarget().empty())
    {
      CReportDefinition* def = task->getReport().getReportDefinition();

      if (def != NULL)
        {
          SedReport* pReport = mpSEDMLDocument->createReport();
          std::string name = def->getObjectName();
          SEDMLUtils::removeCharactersFromString(name, "[]");
          //
          pReport->setId(SEDMLUtils::getNextId("report", mpSEDMLDocument->getNumOutputs()));
          pReport->setName(name);

          std::vector<CRegisteredObjectName> header = *def->getHeaderAddr();
          std::vector<CRegisteredObjectName> body =
            def->isTable() ? *def->getTableAddr() :
            *def->getBodyAddr();

          int dsCount = 0;

          for (size_t i = 0; i < body.size(); ++i)
            {
              CRegisteredObjectName& current = body[i];

              if (current == def->getSeparator().getCN()) continue;

              CCopasiObject *object = dataModel.getDataObject(current);

              if (object == NULL) continue;

              const std::string& typeX = object->getObjectName();
              std::string xAxis = object->getObjectDisplayName();

              std::string targetXPathStringX = SEDMLUtils::getXPathAndName(xAxis, typeX,
                                               pModel, dataModel);

              if (object->getCN() == pTime->getCN())
                pPDGen = pTimeDGenp;
              else
                pPDGen = createDataGenerator(
                           this->mpSEDMLDocument,
                           xAxis,
                           targetXPathStringX,
                           taskId,
                           i,
                           0
                         );

              SedDataSet* pDS = pReport->createDataSet();
              pDS->setId(SEDMLUtils::getNextId("ds", ++dsCount));

              if (def->isTable())
                {
                  CCopasiObject *headerObj = NULL;

                  if (header.size() > i)
                    headerObj = dataModel.getDataObject(header[i]);
                  else
                    headerObj = dataModel.getDataObject(body[i]);

                  if (headerObj != NULL)
                    pDS->setLabel(headerObj->getObjectDisplayName());
                  else
                    pDS->setLabel(xAxis);
                }
              else
                pDS->setLabel(xAxis);

              pDS->setDataReference(pPDGen->getId());
            }
        }
    }

  // export plots
  for (i = 0; i < imax; i++)
    {
      pPSedPlot = this->mpSEDMLDocument->createPlot2D();
      const CPlotSpecification* pPlot = (*dataModel.getPlotDefinitionList())[i];
      std::string plotName = pPlot->getObjectName();

      SEDMLUtils::removeCharactersFromString(plotName, "[]");

      pPSedPlot->setId(SEDMLUtils::getNextId("plot", mpSEDMLDocument->getNumOutputs()));
      pPSedPlot->setName(plotName);

      size_t j, jmax = pPlot->getItems().size();

      for (j = 0; j < jmax; j++)
        {
          const CPlotItem* pPlotItem = pPlot->getItems()[j];

          CCopasiObject *objectX, *objectY;

          if (pPlotItem->getChannels().size() >= 1)
            {
              objectX = dataModel.getDataObject(pPlotItem->getChannels()[0]);
            }
          else
            {
              CCopasiMessage(CCopasiMessage::WARNING, "SED-ML: Can't export plotItem '%s', as it has no data channel.", pPlotItem->getObjectName().c_str());
              continue;
            }

          if (objectX == NULL)
            {
              CCopasiMessage(CCopasiMessage::WARNING, "SED-ML: Can't export plotItem '%s' variable '%s', as it cannot be resolved.",  pPlotItem->getObjectName().c_str(), pPlotItem->getChannels()[0].c_str());
              continue;
            }

          bool xIsTime = objectX->getCN() == pTime->getCN();

          if (pPlotItem->getChannels().size() >= 2)
            {
              objectY = dataModel.getDataObject(pPlotItem->getChannels()[1]);
            }
          else
            {
              CCopasiMessage(CCopasiMessage::WARNING, "SED-ML: Can't export plotItem '%s', as it has only 1 data channel.", pPlotItem->getObjectName().c_str());
              continue;
            }

          if (objectY == NULL)
            {
              CCopasiMessage(CCopasiMessage::WARNING, "SED-ML: Can't export plotItem '%s' variable '%s', as it cannot be resolved.",  pPlotItem->getObjectName().c_str(), pPlotItem->getChannels()[1].c_str());
              continue;
            }

          const std::string& type = objectY->getObjectName();
          std::string yAxis = objectY->getObjectDisplayName();
          std::string sbmlId = yAxis;
          std::string targetXPathString = SEDMLUtils::getXPathAndName(sbmlId, type,
                                          pModel, dataModel);

          if (targetXPathString.empty())
            {
              CCopasiMessage(CCopasiMessage::WARNING, "SED-ML: Can't export plotItem '%s' variable '%s', as no xpath expression for it could be generated.",  pPlotItem->getObjectName().c_str(), pPlotItem->getChannels()[1].c_str());
              continue;
            }

          pPDGen = createDataGenerator(
                     this->mpSEDMLDocument,
                     sbmlId,
                     targetXPathString,
                     taskId,
                     i,
                     j
                   );

          pPDGen->setName(yAxis);

          pCurve = pPSedPlot->createCurve();
          std::ostringstream idCurveStrStream;
          idCurveStrStream << "p";
          idCurveStrStream << i + 1;
          idCurveStrStream << "_curve_";
          idCurveStrStream << j + 1;
          pCurve->setId(idCurveStrStream.str());
          pCurve->setLogX(pPlot->isLogX());
          pCurve->setLogY(pPlot->isLogY());
          pCurve->setName(yAxis);
          pCurve->setYDataReference(pPDGen->getId());

          if (xIsTime)
            {
              pCurve->setXDataReference(pTimeDGenp->getId());
            }
          else
            {
              const std::string& typeX = objectX->getObjectName();
              std::string xAxis = objectX->getObjectDisplayName();
              std::string targetXPathStringX = SEDMLUtils::getXPathAndName(xAxis, typeX,
                                               pModel, dataModel);

              pPDGen = createDataGenerator(
                         this->mpSEDMLDocument,
                         xAxis,
                         targetXPathStringX,
                         taskId,
                         i,
                         j
                       );
              pCurve->setXDataReference(pPDGen->getId());
            }
        }
    }
}