void InsertCompartmentRowsCommand::redo()
{
  if (firstTime)
    {
      mpCompartmentDM->insertNewCompartmentRow(mPosition, mRows, QModelIndex());
      assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
      CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0];
      assert(pDataModel != NULL);
      CModel * pModel = pDataModel->getModel();
      assert(pModel != NULL);

      CCompartment *pCompartment = pModel->getCompartments()[mPosition];
      mpCompartmentData->setName(pCompartment->getObjectName());
      mpCompartmentData->setStatus(pCompartment->getStatus());
      mpCompartmentData->setInitialValue(pCompartment->getInitialValue());
      firstTime = false;
    }
  else
    {
      mpCompartmentDM->addCompartmentRow(mpCompartmentData);
    }

  setUndoState(true);
  setAction("Add to list");
  setName(mpCompartmentData->getName());
}
示例#2
0
bool CODEExporterC::preprocess(const CModel* copasiModel)

{
  size_t n[3] = {0, 0, 0};
  size_t n_c[3] = {0, 0, 0};
  size_t i, j;
  size_t dependent;

  setReservedNames();

  NameMap[timeKey] = translateTimeVariableName();

  const CCopasiVector< CMetab > & metabs = copasiModel->getMetabolitesX();
  size_t metabs_size = metabs.size();

  for (i = 0; i < metabs_size; i++)
    {
      CMetab * metab = metabs[i];

      //if (metab->isUsed())
      {
        std::string smname;
        std::string name;
        dependent = metab->isDependent();

        smname = setExportName(metab->getStatus(), n, dependent);
        name = setConcentrationName(metab->getStatus(), n_c, dependent);

        NameMap[metab->getKey()] = name;

        std::ostringstream smKey;
        smKey << "sm_" << metab->getKey();

        NameMap[smKey.str()] = smname;

        if ((metab->getStatus() == CModelEntity::REACTIONS && !metab->isDependent()) || metab->getStatus() == CModelEntity::ODE)
          {
            std::ostringstream odeKey;
            odeKey << "ode_" << metab->getKey();

            NameMap[odeKey.str()] = setODEName(smname);
          }
      }
    }

  size_t comps_size = copasiModel->getCompartments().size();
  const CCopasiVector< CCompartment > & comps = copasiModel->getCompartments();

  for (i = 0; i < comps_size; i++)
    {
      CCompartment * comp = comps[i];

      std::string name;
      dependent = 0;

      name = setExportName(comp->getStatus(), n, dependent);
      NameMap[comp->getKey()] = name;

      if (comp->getStatus() == CModelEntity::ODE)
        {
          std::ostringstream odeKey;
          odeKey << "ode_" << comp->getKey();

          NameMap[odeKey.str()] = setODEName(name);
        }
    }

  size_t modvals_size = copasiModel->getModelValues().size();
  const CCopasiVector< CModelValue > & modvals = copasiModel->getModelValues();

  for (i = 0; i < modvals_size; i++)
    {
      CModelValue* modval = modvals[i];
      std::string name = setExportName(modval->getStatus(), n, 0);
      NameMap[modval->getKey()] = name;

      if (modval->getStatus() == CModelEntity::ODE)
        {
          std::ostringstream odeKey;
          odeKey << "ode_" << modval->getKey();
          NameMap[odeKey.str()] = setODEName(name);
        }
    }

  size_t reacs_size = copasiModel->getReactions().size();

  const CCopasiVector< CReaction > & reacs = copasiModel->getReactions();

  std::set<std::string> tmpset;

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

      params_size = reacs[i]->getParameters().size();

      for (j = 0; j < params_size; ++j)
        {
          if (!reacs[i]->isLocalParameter(reacs[i]->getParameters().getParameter(j)->getObjectName()))
            continue;

          std::ostringstream name;

          name << "p[" << n[0] << "]";
          n[0] ++;

          NameMap[reacs[i]->getParameters().getParameter(j)->getKey()] = name.str();
        }

      const CFunction* func = reacs[i]->getFunction();

      std::string name = func->getObjectName();

      if (func->getRoot())
        setExportNameOfFunction(func->getRoot(), tmpset);

      if (func->getType() != CEvaluationTree::MassAction)
        if (tmpset.find(name) == tmpset.end())
          {
            NameMap[func->getKey()] = translateObjectName(name);
            tmpset.insert(name);
          }
    }

  return true;
}