bool CQGlobalQuantityDM::removeGlobalQuantityRows(QModelIndexList rows, const QModelIndex&) { if (rows.isEmpty()) return false; switchToWidget(CCopasiUndoCommand::GLOBALQUANTITYIES); //Build the list of pointers to items to be deleted //before actually deleting any item. QList <CModelValue *> pGlobalQuantities; QModelIndexList::const_iterator i; for (i = rows.begin(); i != rows.end(); ++i) { if (!isDefaultRow(*i) && &mpGlobalQuantities->operator [](i->row())) pGlobalQuantities.append(&mpGlobalQuantities->operator [](i->row())); } QList <CModelValue *>::const_iterator j; for (j = pGlobalQuantities.begin(); j != pGlobalQuantities.end(); ++j) { CModelValue * pGQ = *j; size_t delRow = mpGlobalQuantities->CCopasiVector< CModelValue >::getIndex(pGQ); if (delRow == C_INVALID_INDEX) continue; QMessageBox::StandardButton choice = CQMessageBox::confirmDelete(NULL, "quantity", FROM_UTF8(pGQ->getObjectName()), pGQ->getDeletedObjects()); if (choice == QMessageBox::Ok) removeRow((int) delRow); } return true; }
void CFixLocalReactionParameters::changeModel() { CCopasiParameter * pParameter = NULL; CModelValue * pModelValue = NULL; CReaction * pReaction = NULL; std::stringstream NameStream; std::stringstream Message; std::string OldCN; std::string NewCNBase; std::string NewCN; std::string Infix; std::string::size_type Start; // Loop through all changes. std::multimap< CCopasiParameter *, const CExpression * >::const_iterator itChanges = mChanges.begin(); std::multimap< CCopasiParameter *, const CExpression * >::const_iterator endChanges = mChanges.end(); for (; itChanges != endChanges; ++itChanges) { if (pParameter != itChanges->first) { // We have a new parameter pParameter = itChanges->first; OldCN = "<" + pParameter->getCN() + ",Reference="; // Create a global quantity of type FIXED. std::string Name = pParameter->getObjectName(); pReaction = static_cast< CReaction * >(pParameter->getObjectAncestor("Reaction")); Name += "{" + pReaction->getObjectName() + "}"; pModelValue = mpModel->createModelValue(Name, pParameter->getValue< C_FLOAT64 >()); // In case the created name is not unique we append _n with increasing n // until we succeed; C_INT32 index = 0; while (pModelValue == NULL) { NameStream.str(""); NameStream << Name << "_" << index++; pModelValue = mpModel->createModelValue(NameStream.str(), pParameter->getValue< C_FLOAT64 >()); } NewCNBase = "<" + pModelValue->getCN() + ",Reference="; // If the parameter is actually used in the reaction // it is changed to the global quantity. if (pReaction->isLocalParameter(pParameter->getObjectName())) pReaction->setParameterMapping(pParameter->getObjectName(), pModelValue->getKey()); Message << " " << pParameter->getObjectName() << " in " << pReaction->getObjectName() << " is replaced by " << pModelValue->getObjectName() << std::endl; } // We need to distinguish between initial and other expressions. if (itChanges->second->getObjectName().compare(0, 7, "Initial") == 0) NewCN = NewCNBase + "Initial"; else NewCN = NewCNBase; // Replace the OldCN of the parameter with the NewCN of global quantity in all expressions. Infix = itChanges->second->getInfix(); // There may be more than one occurrence. Start = 0; while ((Start = Infix.find(OldCN), Start) != std::string::npos) Infix.replace(Start, OldCN.length(), NewCN); const_cast< CExpression * >(itChanges->second)->setInfix(Infix); } CCopasiMessage(CCopasiMessage::WARNING, MCXML + 14, Message.str().c_str()); }