Esempio n. 1
0
void Network::addCompartment(int index, float _xmin, float _xmax, float _ymin, float _ymax, string _name){
   //add in a compartment with all attributes specified.
   if(index>=compartments->size())compartments->resize(index+1);
   (*compartments)[index]=(Compartment(_xmin,_xmax,_ymin,_ymax,_name));
}
Esempio n. 2
0
bool CQSpecieDM::setData(const QModelIndex &index, const QVariant &value,
                         int role)
{
  if (index.isValid() && role == Qt::EditRole)
    {
      bool defaultRow = isDefaultRow(index);

      if (defaultRow)
        {
          if (index.column() == COL_TYPE_SPECIES)
            {
              if (index.data().toString() == QString(FROM_UTF8(CModelEntity::StatusName[mItemToType[value.toInt()]])))
                return false;
            }
          else if (index.column() == COL_COMPARTMENT && value == "")
            {
              return false;
            }
          else if (index.data() == value)
            {
              return false;
            }

          mNotify = false;
          insertRow();
          mNotify = true;
        }
      else
        {
          assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
          mpSpecies = (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getMetabolites()[index.row()];
        }

      const CCompartment * pCompartment = NULL;

      if (index.column() == COL_COMPARTMENT ||
          index.column() == COL_ICONCENTRATION ||
          index.column() == COL_INUMBER)
        {
          try
            {
              pCompartment = mpSpecies->getCompartment();
            }
          catch (...) {}
        }

      if (index.column() == COL_NAME_SPECIES)
        mpSpecies->setObjectName(TO_UTF8(value.toString()));
      else if (index.column() == COL_COMPARTMENT)
        {
          // This must be set first for setInitialConcentration and
          // setInitialNumber to work correctly.
          std::string Compartment(TO_UTF8(value.toString()));

          if (Compartment != pCompartment->getObjectName())
            {
              std::string CompartmentToRemove = mpSpecies->getCompartment()->getObjectName();
              assert(CCopasiRootContainer::getDatamodelList()->size() > 0);

              if (!(*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getCompartments()[Compartment]->addMetabolite(mpSpecies))
                {
                  QString msg;
                  msg = "Unable to move species '" + FROM_UTF8(mpSpecies->getObjectName()) + "'\n"
                        + "from compartment '" + FROM_UTF8(CompartmentToRemove) + "' to compartment '" + FROM_UTF8(Compartment) + "'\n"
                        + "since a species with that name already exist in the target compartment.";

                  CQMessageBox::information(NULL,
                                            "Unable to move Species",
                                            msg,
                                            QMessageBox::Ok, QMessageBox::Ok);
                  return false;
                }
              else
                {
                  (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getCompartments()[CompartmentToRemove]->getMetabolites().remove(mpSpecies->getObjectName());
                  (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->setCompileFlag();
                  (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->initializeMetabolites();

                  if (mpSpecies && pCompartment)
                    {
                      C_FLOAT64 Factor = 1.0 / pCompartment->getInitialValue();
                      Factor *= pCompartment->getInitialValue();

                      mpSpecies->setInitialValue(Factor * this->index(index.row(), COL_INUMBER).data().toDouble());
                      mpSpecies->setValue(Factor * this->index(index.row(), COL_NUMBER).data().toDouble());
                    }

                  emit notifyGUI(ListViews::METABOLITE, ListViews::CHANGE, mpSpecies->getKey());
                  emit notifyGUI(ListViews::COMPARTMENT, ListViews::CHANGE, pCompartment->getKey());
                }
            }
        }
      else if (index.column() == COL_TYPE_SPECIES)
        mpSpecies->setStatus((CModelEntity::Status) mItemToType[value.toInt()]);
      else if (index.column() == COL_ICONCENTRATION)
        {
          if (mFlagConc)
            mpSpecies->setInitialConcentration(value.toDouble());

          if (mpSpecies && pCompartment)
            {
              const C_FLOAT64 initialValue =
                CMetab::convertToNumber(this->index(index.row(), COL_ICONCENTRATION).data().toDouble(),
                                        *pCompartment,
                                        *(*CCopasiRootContainer::getDatamodelList())[0]->getModel());
              mpSpecies->setInitialValue(initialValue);
            }
        }
      else if (index.column() == COL_INUMBER)
        {
          if (!mFlagConc)
            mpSpecies->setInitialValue(value.toDouble());

          if (mpSpecies && pCompartment)
            {
              mpSpecies->setInitialConcentration(
                CMetab::convertToConcentration(this->index(index.row(), COL_INUMBER).data().toDouble(),
                                               *pCompartment,
                                               *(*CCopasiRootContainer::getDatamodelList())[0]->getModel())
              );
            }
        }

      if (defaultRow && this->index(index.row(), COL_NAME_SPECIES).data().toString() == "species")
        mpSpecies->setObjectName(TO_UTF8(createNewName("species", COL_NAME_SPECIES)));

      //Save Key
      std::string key = mpSpecies->getKey();
      emit dataChanged(index, index);

      if (defaultRow)
        {
          emit notifyGUI(ListViews::METABOLITE, ListViews::ADD, key);
        }
      else
        {
          emit notifyGUI(ListViews::METABOLITE, ListViews::CHANGE, key);
        }
    }

  return true;
}
Esempio n. 3
0
void Network::addCompartment(int index, string _name){
   //add in a compartment with _name specified (prefered in the algorithms).
   if(index>=compartments->size())compartments->resize(index+1);
   (*compartments)[index]=(Compartment(_name));
}
Esempio n. 4
0
bool CQSpecieDM::specieDataChange(
  UndoSpeciesData *pUndoSpeciesData,
  const QVariant &value,
  int column)
{
  switchToWidget(CCopasiUndoCommand::SPECIES);

  GET_MODEL_OR(pModel, return false);

  mpSpecies =
    dynamic_cast<CMetab*>(pUndoSpeciesData->getObject(pModel));

  if (mpSpecies == NULL)
    return false;

  const CCompartment * pCompartment = NULL;

  if (column == COL_COMPARTMENT ||
      column == COL_ICONCENTRATION ||
      column == COL_INUMBER)
    {
      try
        {
          pCompartment = mpSpecies->getCompartment();
        }
      catch (...) {}
    }

  if (column == COL_NAME_SPECIES)
    {
      mpSpecies->setObjectName(TO_UTF8(value.toString()));
      pUndoSpeciesData->setCN(mpSpecies->getCN());
    }
  else if (column == COL_COMPARTMENT)
    {
      // This must be set first for setInitialConcentration and
      // setInitialNumber to work correctly.
      std::string Compartment(TO_UTF8(value.toString()));

      if (Compartment != pCompartment->getObjectName())
        {
          std::string CompartmentToRemove = mpSpecies->getCompartment()->getObjectName();

          if (!(pModel->getCompartments()[Compartment].addMetabolite(mpSpecies)))
            {
              QString msg;
              msg = "Unable to move species '" + FROM_UTF8(mpSpecies->getObjectName()) + "'\n"
                    + "from compartment '" + FROM_UTF8(CompartmentToRemove) + "' to compartment '" + FROM_UTF8(Compartment) + "'\n"
                    + "since a species with that name already exist in the target compartment.";

              CQMessageBox::information(NULL,
                                        "Unable to move Species",
                                        msg,
                                        QMessageBox::Ok, QMessageBox::Ok);
              return false;
            }
          else
            {
              pModel->getCompartments()[CompartmentToRemove].getMetabolites().remove(mpSpecies->getObjectName());
              pModel->setCompileFlag();
              pModel->initializeMetabolites();

              if (mpSpecies && pCompartment)
                {
                  C_FLOAT64 Factor = 1.0 / pCompartment->getInitialValue();
                  Factor *= pCompartment->getInitialValue();

                  mpSpecies->setInitialValue(Factor * pUndoSpeciesData->getINumber());
                  mpSpecies->setValue(Factor * mpSpecies->getValue());
                }

              emit notifyGUI(ListViews::METABOLITE, ListViews::CHANGE, mpSpecies->getKey());
              emit notifyGUI(ListViews::COMPARTMENT, ListViews::CHANGE, pCompartment->getKey());
            }
        }
    }
  else if (column == COL_TYPE_SPECIES)
    mpSpecies->setStatus((CModelEntity::Status) mItemToType[value.toInt()]);
  else if (column == COL_ICONCENTRATION)
    {
      if (mFlagConc)
        mpSpecies->setInitialConcentration(value.toDouble());

      if (mpSpecies && pCompartment)
        {
          const C_FLOAT64 initialValue =
            CMetab::convertToNumber(pUndoSpeciesData->getIConc(),
                                    *pCompartment,
                                    *pModel);
          mpSpecies->setInitialValue(initialValue);
        }
    }
  else if (column == COL_INUMBER)
    {
      if (!mFlagConc)
        mpSpecies->setInitialValue(value.toDouble());

      if (mpSpecies && pCompartment)
        {
          mpSpecies->setInitialConcentration(
            CMetab::convertToConcentration(pUndoSpeciesData->getINumber(),
                                           *pCompartment,
                                           *pModel)
          );
        }
    }

  //Save Key
  std::string key = mpSpecies->getKey();

  // ask for refresh this may change the key!
  QModelIndex index = getIndexFor(mpSpecies, column);
  emit dataChanged(index, index);

  if (column == COL_NAME_SPECIES)
    {
      emit notifyGUI(ListViews::METABOLITE, ListViews::RENAME, key);
    }
  else
    {
      emit notifyGUI(ListViews::METABOLITE, ListViews::CHANGE, key);
    }

  return true;
}