示例#1
0
void CQCompartmentDM::insertNewRows(int position, int rows, int column, const QVariant & value)
{
  beginInsertRows(QModelIndex(), position, position + rows - 1);

  for (int row = 0; row < rows; ++row)
    {
      QString name = createNewName(column == COL_NAME_COMPARTMENTS ? value.toString() : "compartment", COL_NAME_COMPARTMENTS);

      CCompartment * pComp = mpDataModel->getModel()->createCompartment(TO_UTF8(name));

      if (pComp == NULL)
        continue;

      if (column == COL_TYPE_COMPARTMENTS)
        {
          pComp->setStatus(CModelEntity::StatusName.toEnum(TO_UTF8(value.toString())));
        }

      if (column == COL_IVOLUME)
        {
          pComp->setInitialValue(value.toDouble());
        }

      CUndoData UndoData(CUndoData::Type::INSERT, pComp);
      ListViews::addUndoMetaData(this, UndoData);
      emit signalNotifyChanges(mpDataModel->recordData(UndoData));
    }

  endInsertRows();
}
示例#2
0
void CQCompartment::addCompartment(UndoCompartmentData *pSData)
{
  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
  CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0];
  assert(pDataModel != NULL);

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

  //reinsert all the Compartments
  CCompartment *pCompartment =  pModel->createCompartment(pSData->getName());
  pCompartment->setInitialValue(pSData->getInitialValue());
  pCompartment->setStatus(pSData->getStatus());
  std::string key = pCompartment->getKey();
  protectedNotify(ListViews::COMPARTMENT, ListViews::ADD, key);

  //restore all the dependencies
  //reinsert all the species
  QList <UndoSpecieData *> *pSpecieData = pSData->getSpecieDependencyObjects();
  QList <UndoSpecieData *>::const_iterator i;

  for (i = pSpecieData->begin(); i != pSpecieData->end(); ++i)
    {
      UndoSpecieData * data = *i;
      //  beginInsertRows(QModelIndex(), 1, 1);
      CMetab *pSpecie =  pModel->createMetabolite(data->getName(), data->getCompartment(), data->getIConc(), data->getStatus());
      protectedNotify(ListViews::METABOLITE, ListViews::ADD, pSpecie->getKey());
      //endInsertRows();
    }

  //reinsert the dependency reaction
  QList <UndoReactionData *> *pReactionData = pSData->getReactionDependencyObjects();
  QList <UndoReactionData *>::const_iterator j;

  for (j = pReactionData->begin(); j != pReactionData->end(); ++j)
    {

      //UndoReactionData * rData = dynamic_cast<UndoReactionData*>(*j);
      UndoReactionData * rData = *j;

      //TODO check if reaction already exist in the model, better idea may be implemented in the future
      bool exist = false;

      for (int ii = 0; ii < (int)pModel->getReactions().size(); ++ii)
        {
          if (pModel->getReactions()[ii]->getObjectName() == rData->getName())
            {
              exist = true;
              ii = ii + pModel->getReactions().size() + 1; //jump out of the loop reaction exist already
            }
          else
            {
              exist = false;
            }
        }

      if (!exist)
        {
          protectedNotify(ListViews::METABOLITE, ListViews::ADD, ""); //Refresh all dependency species.
          CReaction *pRea =  pModel->createReaction(rData->getName());
          rData->getRi()->writeBackToReaction(pRea);
          protectedNotify(ListViews::REACTION, ListViews::ADD, pRea->getKey());
        }
    }

  mpListView->switchToOtherWidget(C_INVALID_INDEX, key);
}