bool CEventAssignment::compile(CObjectInterface::ContainerList listOfContainer) { clearDirectDependencies(); bool success = true; mpTarget = NULL; CModelEntity * pEntity = dynamic_cast< CModelEntity * >(CCopasiRootContainer::getKeyFactory()->get(getObjectName())); // The entity type must not be an ASSIGNMENT if (pEntity != NULL && pEntity->getStatus() != CModelEntity::ASSIGNMENT) { // We need use the virtual method getValueObject to retrieve the // target value from the model entity mpTarget = pEntity->getValueObject(); } else if (pEntity != NULL && pEntity->getStatus() == CModelEntity::ASSIGNMENT) { CCopasiMessage(CCopasiMessage::WARNING, "Invalid EventAssignment for '%s': an Assignment Rule already exists", pEntity->getObjectName().c_str()); } else if (pEntity == NULL) { CCopasiMessage(CCopasiMessage::WARNING, "Invalid EventAssignment for '%s': object does not exist.", getObjectName().c_str()); } if (mpTarget == NULL) { success = false; } if (mpExpression != NULL) { success &= mpExpression->compile(listOfContainer); setDirectDependencies(mpExpression->getDirectDependencies()); } else { success = false; } return success; }
void CQUpdatesWidget::loadObjectsTable(CModel* pModel) { if (!pModel) return; mpTableObj->setColumnCount(5); mpTableObj->setRowCount(0); mpTableObj->setHorizontalHeaderItem(0, new QTableWidgetItem("User order")); mpTableObj->setHorizontalHeaderItem(1, new QTableWidgetItem("status")); mpTableObj->setHorizontalHeaderItem(2, new QTableWidgetItem("")); mpTableObj->setHorizontalHeaderItem(3, new QTableWidgetItem("Reduced system")); mpTableObj->setHorizontalHeaderItem(4, new QTableWidgetItem("status")); size_t i, imax; //metabolites imax = pModel->getMetabolites().size(); if ((int) imax > mpTableObj->rowCount()) mpTableObj->setRowCount((int) imax); for (i = 0; i < imax; ++i) { mpTableObj->setVerticalHeaderItem((int) i, new QTableWidgetItem(QString::number(i))); CMetab* pM = pModel->getMetabolites()[i]; QColor c(100, 100, 100); if (pM->getStatus() == CModelEntity::FIXED) c = QColor(150, 150, 150); if (pM->getStatus() == CModelEntity::ASSIGNMENT) c = QColor(250, 150, 250); if (pM->getStatus() == CModelEntity::REACTIONS) c = QColor(250, 250, 200); if (pM->getStatus() == CModelEntity::ODE) c = QColor(150, 250, 250); if (pM->getStatus() == CModelEntity::TIME) c = QColor(250, 150, 150); mpTableObj->setItem((int) i, 0, new QTableWidgetItem(FROM_UTF8(pM->getObjectName()))); //mpTableObj->setText(i, 0, FROM_UTF8(pM->getObjectName())); std::string tmpString = CModelEntity::StatusName[pM->getStatus()]; if (pM->isUsed()) tmpString += " (Used = true, "; else tmpString += " (Used = false, "; mpTableObj->setItem((int) i, 1, new QTableWidgetItem(FROM_UTF8(tmpString))); //mpTableObj->setText(i, 1, FROM_UTF8(tmpString)); } mpTableObj->resizeColumnToContents(0); mpTableObj->resizeColumnToContents(1); mpTableObj->setColumnWidth(2, 10); //metabolitesX imax = pModel->getMetabolitesX().size(); if ((int) imax > mpTableObj->rowCount()) mpTableObj->setRowCount((int) imax); for (i = 0; i < imax; ++i) { CMetab* pM = pModel->getMetabolitesX()[i]; QColor c(100, 100, 100); if (pM->getStatus() == CModelEntity::FIXED) c = QColor(150, 150, 150); if (pM->getStatus() == CModelEntity::ASSIGNMENT) c = QColor(250, 150, 250); if (pM->getStatus() == CModelEntity::REACTIONS) c = QColor(250, 250, 200); if (pM->getStatus() == CModelEntity::ODE) c = QColor(150, 250, 250); if (pM->getStatus() == CModelEntity::TIME) c = QColor(250, 150, 150); mpTableObj->setItem((int) i, 3, new QTableWidgetItem(FROM_UTF8(pM->getObjectName()))); //mpTableObj->setText(i, 3, FROM_UTF8(pM->getObjectName())); std::string tmpString = CModelEntity::StatusName[pM->getStatus()]; if (pM->isUsed()) tmpString += " (Used = true, "; else tmpString += " (Used = false, "; mpTableObj->setItem((int) i, 4, new QTableWidgetItem(FROM_UTF8(tmpString))); } mpTableObj->resizeColumnToContents(3); mpTableObj->resizeColumnToContents(4); //state const CStateTemplate & st = pModel->getStateTemplate(); imax = st.size(); mpTableState->setRowCount(0); mpTableState->setRowCount((int)(imax + 1)); mpTableState->setColumnCount(5); mpTableState->setHorizontalHeaderItem(0, new QTableWidgetItem("Name")); mpTableState->setHorizontalHeaderItem(1, new QTableWidgetItem("status")); mpTableState->setHorizontalHeaderItem(2, new QTableWidgetItem("")); mpTableState->setHorizontalHeaderItem(3, new QTableWidgetItem("ATol(1)")); mpTableState->setHorizontalHeaderItem(4, new QTableWidgetItem("SS criterion(1)")); for (i = 0; i < imax; ++i) { mpTableState->setVerticalHeaderItem((int) i, new QTableWidgetItem(QString::number(i))); CModelEntity* pME = *(st.getEntities() + i); //first column QColor c(100, 100, 100); if (dynamic_cast<CModel*>(pME)) c = QColor(250, 100, 100); if (dynamic_cast<CMetab*>(pME)) c = QColor(250, 250, 150); if (dynamic_cast<CCompartment*>(pME)) c = QColor(100, 250, 100); if (dynamic_cast<CModelValue*>(pME)) c = QColor(100, 100, 250); mpTableState->setItem((int) i, 0, new QTableWidgetItem(FROM_UTF8(pME->getObjectDisplayName()))); // mpTableState->setText(i, 0,FROM_UTF8(pME->getObjectDisplayName())); //second column std::string tmpString = CModelEntity::StatusName[pME->getStatus()]; if (pME->isUsed()) tmpString += " (Used = true, "; else tmpString += " (Used = false, "; c = QColor(100, 100, 100); if (pME->getStatus() == CModelEntity::FIXED) c = QColor(150, 150, 150); if (pME->getStatus() == CModelEntity::ASSIGNMENT) c = QColor(250, 150, 250); if (pME->getStatus() == CModelEntity::REACTIONS) c = QColor(250, 250, 200); if (pME->getStatus() == CModelEntity::ODE) c = QColor(150, 250, 250); if (pME->getStatus() == CModelEntity::TIME) c = QColor(250, 150, 150); mpTableState->setItem((int) i, 1, new QTableWidgetItem(FROM_UTF8(tmpString))); //mpTableState->setText(i, 1, FROM_UTF8(tmpString)); } QColor c(200, 250, 250); for (i = st.beginIndependent() - st.getEntities(); i < (size_t)(st.endIndependent() - st.getEntities()); ++i) mpTableState->setItem((int) i, 2, new QTableWidgetItem("")); c = QColor(250, 200, 250); for (i = st.beginDependent() - st.getEntities(); i < (size_t)(st.endDependent() - st.getEntities()); ++i) mpTableState->setItem((int) i, 2, new QTableWidgetItem("")); c = QColor(200, 200, 200); for (i = st.beginFixed() - st.getEntities(); i < (size_t)(st.endFixed() - st.getEntities()); ++i) mpTableState->setItem((int) i, 2, new QTableWidgetItem("")); int tmpint = st.beginIndependent() - st.getEntities(); mpTableState->setItem(tmpint, 2, new QTableWidgetItem("beginIndependent ")); tmpint = st.endIndependent() - st.getEntities(); mpTableState->setItem(tmpint, 2, new QTableWidgetItem(mpTableState->item(tmpint, 2)->text() + "endIndependent ")); tmpint = st.beginDependent() - st.getEntities(); mpTableState->setItem(tmpint, 2, new QTableWidgetItem(mpTableState->item(tmpint, 2)->text() + "beginDependent ")); tmpint = st.endDependent() - st.getEntities(); mpTableState->setItem(tmpint, 2, new QTableWidgetItem(mpTableState->item(tmpint, 2)->text() + "endDependent ")); tmpint = st.beginFixed() - st.getEntities(); mpTableState->setItem(tmpint, 2, new QTableWidgetItem(mpTableState->item(tmpint, 2)->text() + "beginFixed ")); tmpint = st.endFixed() - st.getEntities(); mpTableState->setItem(tmpint, 2, new QTableWidgetItem("endFixed ")); //add absolute Tolerances to table CVector< C_FLOAT64 > atolv = pModel->initializeAtolVector(1, false); tmpint = st.beginIndependent() - st.getEntities(); for (i = 0; i < atolv.size(); ++i) { mpTableState->setItem((int) i + tmpint, 3, new QTableWidgetItem(QString::number(atolv[i]))); CModelEntity* pME = *(st.getEntities() + i + 1); C_FLOAT64 tmp = std::min(atolv[i], std::max(100.0 * std::numeric_limits< C_FLOAT64 >::min(), fabs(pME->getInitialValue()))); mpTableState->setItem((int) i + tmpint, 4, new QTableWidgetItem(QString::number(tmp))); } mpTableState->resizeColumnToContents(0); mpTableState->resizeColumnToContents(1); mpTableState->resizeColumnToContents(2); mpTableState->resizeColumnToContents(3); mpTableState->resizeColumnToContents(4); }
// virtual bool CModelParameter::updateModel() { bool success = true; if (mpObject != NULL) { switch (mType) { case Model: { CModel * pModel = static_cast< CModel * >(mpObject); if (!pModel->isAutonomous()) { pModel->setInitialValue(mValue); } else { pModel->setInitialValue(0.0); } } break; case Compartment: case Species: case ModelValue: { CModelEntity * pEntity = static_cast< CModelEntity * >(mpObject); if (pEntity->getStatus() != CModelEntity::ASSIGNMENT) { pEntity->setInitialValue(mValue); if (mIsInitialExpressionValid) { pEntity->setInitialExpression(getInitialExpression()); } } } break; case ReactionParameter: { CCopasiParameter * pParameter = static_cast< CCopasiParameter * >(mpObject); CReaction * pReaction = static_cast< CReaction * >(mpObject->getObjectAncestor("Reaction")); if (mIsInitialExpressionValid && getInitialExpression() != "") { CModel * pModel = mpParent->getModel(); assert(pModel != NULL); std::vector< CCopasiContainer * > ListOfContainer; ListOfContainer.push_back(pModel); CCopasiObjectName CN = static_cast< CEvaluationNodeObject * >(mpInitialExpression->getRoot())->getObjectCN(); CCopasiObject * pObject = pModel->getObjectDataModel()->ObjectFromName(ListOfContainer, CN); assert(pObject != NULL); // We assign the object value pParameter->setValue(* (C_FLOAT64 *) pObject->getValuePointer()); // We map the parameter to the global quantity pReaction->setParameterMapping(pParameter->getObjectName(), pObject->getObjectParent()->getKey()); } else { pParameter->setValue(mValue); // We need to remove the existing mapping to a global quantity1. pReaction->setParameterMapping(pParameter->getObjectName(), pParameter->getKey()); } } break; default: success = false; break; } } return success; }