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++;
    }
}
示例#2
0
std::string CLGraphicalObject::getModelObjectName() const
{
  CCopasiObject * tmp = getModelObject();

  if (tmp)
    return tmp->getObjectName();
  else
    return "";
}
示例#3
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;
}
示例#4
0
std::string CLGraphicalObject::getModelObjectDisplayName(bool /* regular */, bool /* richtext */) const
{
  CCopasiObject * tmp = getModelObject();

  if (tmp)
    {
      return tmp->getObjectName();
    }
  else
    {
      return "";
    }
}
示例#5
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";
        }
    }
}
示例#6
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 << "\", ";
    }
}
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);
}
示例#8
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;
}
示例#9
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());
            }
        }
    }
}