void CMIRIAMInfo::load(const std::string& key) { pdelete(mpRDFGraph); mKey = key; CCopasiObject * pCopasiObject = dynamic_cast< CCopasiObject * >(CCopasiRootContainer::getKeyFactory()->get(mKey)); if (pCopasiObject != NULL) { const std::string * pMiriamAnnotation = NULL; CAnnotation * pAnnotation = CAnnotation::castObject(pCopasiObject); if (pAnnotation != NULL) { pMiriamAnnotation = &pAnnotation->getMiriamAnnotation(); } if (pMiriamAnnotation && *pMiriamAnnotation != "") mpRDFGraph = CRDFParser::graphFromXml(*pMiriamAnnotation); } if (mpRDFGraph == NULL) mpRDFGraph = new CRDFGraph; // We make sure that we always have an about node. if (pCopasiObject != NULL) mTriplet.pObject = mpRDFGraph->createAboutNode(pCopasiObject->getKey()); else mTriplet.pObject = mpRDFGraph->createAboutNode(""); // Load the created date if set; CRDFPredicate::Path Path = mTriplet.pObject->getPath(); std::set< CRDFTriplet > Triples = mTriplet.pObject->getDescendantsWithPredicate(CRDFPredicate::dcterms_created); if (Triples.size() > 0) mCreated = *Triples.begin(); else mCreated = CRDFTriplet(); // This is an invalid triplet, i.e., !mCreated is true. loadCreators(); loadReferences(); loadModifications(); loadBiologicalDescriptions(); return; }
void SliderDialog::createNewSlider() { // allow the user to create more than one slider std::vector<const CCopasiObject*> objects = CCopasiSelectionDialog::getObjectVector(this, CQSimpleSelectionTree::InitialTime | CQSimpleSelectionTree::Parameters); std::vector<CSlider*>* pVector = getCSlidersForCurrentFolderId(); std::vector<const CCopasiObject*>::const_iterator it = objects.begin(), endit = objects.end(); bool yesToAll = false; bool noToAll = false; // create the sliders for all the selected objects // first we need the task object because we need it later to associate the // later with the correct task CCopasiObject* object = (CCopasiObject*)getTaskForFolderId(mCurrentFolderId); if (!object) return; CCopasiObject* pTmpObject = NULL; while (it != endit) { // create a new slider assert((*it) != NULL); pTmpObject = const_cast<CCopasiObject*>(determineCorrectObjectForSlider(*it)); CSlider* pCSlider = new CSlider("slider", (*CCopasiRootContainer::getDatamodelList())[0]); if (pCSlider) { pCSlider->setSliderObject(pTmpObject); pCSlider->setAssociatedEntityKey(object->getKey()); // check if a slider for that object already exists and if so, prompt // the user what to do CSlider* pEquivalentSlider = equivalentSliderExists(pCSlider); if (pEquivalentSlider != NULL) { CopasiSlider* pCopasiSlider = NULL; // if the user has specified yesToAll, we reset the ranges of all // duplicate sliders if (yesToAll) { pEquivalentSlider->resetRange(); // update the slider widget pCopasiSlider = findCopasiSliderForCSlider(pEquivalentSlider); assert(pCopasiSlider != NULL); if (pCopasiSlider != NULL) { pCopasiSlider->updateSliderData(); } } // if the user has not specified noToAll, we need to prompt else if (!noToAll) { QMessageBox::StandardButton result = CQMessageBox::information(NULL, "Slider Exists", "A slider for this object already exists.\n\nDo you want to reset the range of the slider?", QMessageBox::Yes | QMessageBox::No | QMessageBox::YesToAll | QMessageBox::NoToAll, QMessageBox::No); // check the answer and maybe set some flags switch (result) { case QMessageBox::YesToAll: // set the flag yesToAll = true; case QMessageBox::Yes: // reset the range pEquivalentSlider->resetRange(); // update the slider widget pCopasiSlider = findCopasiSliderForCSlider(pEquivalentSlider); assert(pCopasiSlider != NULL); if (pCopasiSlider != NULL) { pCopasiSlider->updateSliderData(); } break; case QMessageBox::NoToAll: // set the flag noToAll = true; break; case QMessageBox::No: // do nothing else break; default: // do nothing break; } } delete pCSlider; } else { std::vector<CCopasiContainer*> listOfContainers; assert(CCopasiRootContainer::getDatamodelList()->size() > 0); listOfContainers.push_back((*CCopasiRootContainer::getDatamodelList())[0]->getModel()); pCSlider->compile(listOfContainers); pCSlider->resetRange(); addSlider(pCSlider); mChanged = true; } } ++it; } delete pVector; }
// virtual bool COPASIHandler::processEnd(const XML_Char * pszName) { bool finished = false; switch (mCurrentElement.first) { case COPASI: { // We need to handle the unmapped parameters of type key. std::vector< std::string >::iterator it = mpData->UnmappedKeyParameters.begin(); std::vector< std::string >::iterator end = mpData->UnmappedKeyParameters.end(); for (; it != end; ++it) { CCopasiParameter * pParameter = dynamic_cast< CCopasiParameter * >(CCopasiRootContainer::getKeyFactory()->get(*it)); if (pParameter != NULL && pParameter->getType() == CCopasiParameter::KEY) { CCopasiObject * pObject = mpData->mKeyMap.get(pParameter->getValue< std::string >()); if (pObject != NULL) pParameter->setValue(pObject->getKey()); else pParameter->setValue(std::string("")); } } // We need to remove the no longer needed expression "Objective Function" from the function list. if (mpData->pFunctionList != NULL && mpData->pFunctionList->getIndex("Objective Function") != C_INVALID_INDEX) { mpData->pFunctionList->remove("Objective Function"); } } finished = true; break; case ParameterGroup: finished = true; break; case ListOfFunctions: case Model: case ListOfTasks: case ListOfReports: case ListOfPlots: case ListOfLayouts: case SBMLReference: case ListOfUnitDefinitions: break; case GUI: if (mpData->pGUI == NULL) { CCopasiMessage::getLastMessage(); } break; default: CCopasiMessage(CCopasiMessage::EXCEPTION, MCXML + 2, mpParser->getCurrentLineNumber(), mpParser->getCurrentColumnNumber(), pszName); break; } return finished; }
std::string CODEExporterC::KineticFunction2ODEmember(const CReaction *reac) { std::ostringstream equation; if (reac->getFunction()->getType() != CEvaluationTree::MassAction) { const CFunctionParameters & params = reac->getFunctionParameters(); size_t k, params_size = params.size(); const std::vector<std::vector<std::string> > & keyMap = reac->getParameterMappings(); std::string name; equation << NameMap[reac->getFunction()->getKey()] << "("; for (k = 0; k < params_size; ++k) { CFunctionParameter::Role role = params[k]->getUsage(); CCopasiObject * obj = CCopasiRootContainer::getKeyFactory()->get(keyMap[k][0]); if ((role == CFunctionParameter::SUBSTRATE) || (role == CFunctionParameter::PRODUCT) || (role == CFunctionParameter::MODIFIER)) { if (obj) name = NameMap[obj->getKey()]; else name = "unknown"; } if (role == CFunctionParameter::PARAMETER) { if (!(reac->isLocalParameter(k))) { CModelValue* modval; modval = dynamic_cast< CModelValue * >(obj); name = NameMap[modval->getKey()]; } else { CCopasiParameter* param; param = dynamic_cast< CCopasiParameter * >(obj); name = NameMap[param->getKey()]; } } if (role == CFunctionParameter::VOLUME) { CCompartment* comp; comp = dynamic_cast< CCompartment * >(obj); name = NameMap[comp->getKey()]; } if (role == CFunctionParameter::TIME) { name = "T"; } if (name.empty()) { std::string message = "Could not export C code, since one of the arguments could not be resolved. Please consider filing a bug with the COPASI tracker: http://www.copasi.org/tracker"; CCopasiMessage(CCopasiMessage::EXCEPTION, message.c_str()); } equation << name; if (k != params_size - 1) equation << ", "; } equation << ")"; } else { const CCopasiVector<CChemEqElement> & substrs = reac->getChemEq().getSubstrates(); const CCopasiVector<CChemEqElement> & prods = reac->getChemEq().getProducts(); const std::vector<std::vector<std::string> > & keyMap = reac->getParameterMappings(); CCopasiObject * obj; size_t substrs_size = substrs.size(), prods_size = prods.size(); size_t k, m, mult; const CChemEqElement* substr; const CChemEqElement* prod; const CMassAction & cMassAction = *static_cast<const CMassAction*>(reac->getFunction()); equation << "("; obj = CCopasiRootContainer::getKeyFactory()->get(keyMap[0][0]); if (!(reac->isLocalParameter(0))) { CModelValue* modval; modval = dynamic_cast< CModelValue * >(obj); equation << NameMap[modval->getKey()]; } else { CCopasiParameter* param; param = dynamic_cast< CCopasiParameter * >(obj); equation << NameMap[param->getKey()]; } for (k = 0; k < substrs_size; ++k) { substr = &substrs[k]; mult = (size_t) substr->getMultiplicity(); assert(substr->getMetabolite()); equation << " * " << NameMap[substr->getMetabolite()->getKey()]; if (mult > 1) for (m = 1; m < mult; ++m) equation << " * " << NameMap[substr->getMetabolite()->getKey()]; } if (cMassAction.isReversible() == TriTrue) { equation << " - "; obj = CCopasiRootContainer::getKeyFactory()->get(keyMap[2][0]); if (!(reac->isLocalParameter(2))) { CModelValue* modval; modval = dynamic_cast< CModelValue * >(obj); equation << NameMap[modval->getKey()]; } else { CCopasiParameter* param; param = dynamic_cast< CCopasiParameter * >(obj); equation << NameMap[param->getKey()]; } for (k = 0; k < prods_size; ++k) { prod = &prods[k]; mult = (size_t) prod->getMultiplicity(); assert(prod->getMetabolite()); equation << " * " << NameMap[prod->getMetabolite()->getKey()]; if (mult > 1) for (m = 1; m < mult; ++m) equation << " * " << NameMap[prod->getMetabolite()->getKey()]; } } equation << ") "; } return equation.str(); }
void CQEventWidget1::addEvent(UndoEventData *pSData) { assert(CCopasiRootContainer::getDatamodelList()->size() > 0); CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0]; assert(pDataModel != NULL); CModel * pModel = pDataModel->getModel(); assert(pModel != NULL); //reinsert the Event CEvent *pEvent = pModel->createEvent(pSData->getName()); //set the expressions pEvent->setTriggerExpression(pSData->getTriggerExpression()); pEvent->setDelayExpression(pSData->getDelayExpression()); pEvent->setPriorityExpression(pSData->getPriorityExpression()); QList <UndoEventAssignmentData *> *assignmentData = pSData->getEventAssignmentData(); QList <UndoEventAssignmentData *>::const_iterator i; for (i = assignmentData->begin(); i != assignmentData->end(); ++i) { UndoEventAssignmentData * assignData = *i; CCopasiObject * pObject = NULL; bool speciesExist = false; size_t ci; for (ci = 0; ci < pModel->getCompartments().size(); ci++) { CCompartment * pCompartment = pModel->getCompartments()[ci]; if (pCompartment->getMetabolites().getIndex(assignData->getName()) != C_INVALID_INDEX) speciesExist = true; } if (speciesExist) { size_t index = pModel->findMetabByName(assignData->getName()); pObject = pModel->getMetabolites()[index]; } else if (pModel->getModelValues().getIndex(assignData->getName()) != C_INVALID_INDEX) { pObject = pModel->getModelValues()[assignData->getName()]; } else if (pModel->getReactions().getIndex(assignData->getName()) != C_INVALID_INDEX) { pObject = pModel->getReactions()[assignData->getName()]; } const CModelEntity * pEntity = dynamic_cast< const CModelEntity * >(pObject); CEventAssignment *eventAssign = new CEventAssignment(pObject->getKey(), pEvent->getObjectParent()); eventAssign->setExpression(assignData->getExpression()); eventAssign->getExpressionPtr()->compile(); pEvent->getAssignments().add(eventAssign); } std::string key = pEvent->getKey(); protectedNotify(ListViews::EVENT, ListViews::ADD, key); mpListView->switchToOtherWidget(C_INVALID_INDEX, key); }
// virtual CXMLHandler * ParameterHandler::processStart(const XML_Char * pszName, const XML_Char ** papszAttrs) { CXMLHandler * pHandlerToCall = NULL; const char * cValue = NULL; const char * cType = NULL; std::string name; std::string sValue(""); bool UnmappedKey = false; void * pValue = NULL; CCopasiParameter::Type type; C_FLOAT64 d; C_INT32 i; size_t ui; bool b; switch (mCurrentElement.first) { case Parameter: // Parameter has attributes name, type and value name = mpParser->getAttributeValue("name", papszAttrs); cType = mpParser->getAttributeValue("type", papszAttrs); type = toEnum(cType, CCopasiParameter::XMLType, CCopasiParameter::INVALID); cValue = mpParser->getAttributeValue("value", papszAttrs); if (cValue != NULL) { sValue = cValue; } switch (type) { case CCopasiParameter::DOUBLE: d = CCopasiXMLInterface::DBL(sValue.c_str()); pValue = &d; break; case CCopasiParameter::UDOUBLE: d = CCopasiXMLInterface::DBL(sValue.c_str()); pValue = &d; break; case CCopasiParameter::INT: i = strToInt(sValue.c_str()); pValue = &i; break; case CCopasiParameter::UINT: ui = strToUnsignedInt(sValue.c_str()); pValue = &ui; break; case CCopasiParameter::BOOL: if (sValue == "0" || sValue == "false") { b = false; } else { b = true; } pValue = &b; break; case CCopasiParameter::STRING: case CCopasiParameter::FILE: case CCopasiParameter::CN: pValue = &sValue; break; case CCopasiParameter::KEY: { if (sValue != "" && CKeyFactory::isValidKey(sValue)) { CCopasiObject * pObject = mpData->mKeyMap.get(sValue); if (pObject) { sValue = pObject->getKey(); } else { UnmappedKey = true; } } pValue = &sValue; } break; default: CCopasiMessage(CCopasiMessage::ERROR, MCXML + 16, name.c_str(), cType, mpParser->getCurrentLineNumber()); pValue = NULL; break; } mpData->pCurrentParameter = new CCopasiParameter(name, type, pValue); if (UnmappedKey) { mpData->UnmappedKeyParameters.push_back(mpData->pCurrentParameter->getKey()); } break; default: CCopasiMessage(CCopasiMessage::EXCEPTION, MCXML + 2, mpParser->getCurrentLineNumber(), mpParser->getCurrentColumnNumber(), pszName); break; } return pHandlerToCall; }