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(); }
bool CModelAdd::addCompartments(std::string name) { size_t i, imax = mmModel->getCompartments().size(); for (i = 0; i < imax; ++i) { const CCompartment* sourceComp = &mmModel->getCompartments()[i]; if (!sourceComp) return false; //create new compartment std::string newName = sourceComp->getObjectName() + "_" + name; CCompartment* newComp = mpModel->createCompartment(newName, sourceComp->getInitialValue()); if (!newComp) return false; newComp->setStatus(sourceComp->getStatus()); newComp->setDimensionality(sourceComp->getDimensionality()); keyMap[sourceComp->getKey()] = newComp->getKey(); nameMap[sourceComp->getObjectName()] = newName; } return true; }
void CModelExpansion::duplicateCompartment(const CCompartment* source, const std::string & index, const SetOfModelElements & sourceSet, ElementsMap & emap) { //if the source object has already been duplicated: do nothing if (emap.exists(source)) return; //try creating the object until we find a name that is not yet used CCompartment* newObj; std::ostringstream infix; do { std::ostringstream name; name << source->getObjectName() << infix.str() << index; newObj = mpModel->createCompartment(name.str(), source->getInitialValue()); infix << "_"; } while (!newObj); //add duplicated object to the map emap.add(source, newObj); //now copy the contents of the object newObj->setDimensionality(source->getDimensionality()); //status newObj->setStatus(source->getStatus()); //expression (for assignment or ODE) newObj->setExpression(source->getExpression()); updateExpression(newObj->getExpressionPtr(), index, sourceSet, emap); //initial expression newObj->setInitialExpression(source->getInitialExpression()); updateExpression(newObj->getInitialExpressionPtr(), index, sourceSet, emap); newObj->setNotes(source->getNotes()); newObj->setMiriamAnnotation(source->getMiriamAnnotation(), newObj->getKey(), source->getKey()); }
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); }