Exemple #1
0
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);
}
Exemple #2
0
// virtual
bool CModelParameter::refreshFromModel(const bool & modifyExistence)
{
    bool success = true;

    if (modifyExistence)
    {
        if (mCompareResult == CModelParameter::Obsolete)
        {
            delete this;

            return true;
        }

        if (mCompareResult == CModelParameter::Missing)
        {
            mCompareResult = CModelParameter::Identical;
        }

        if (mType != ReactionParameter &&
                mpObject != NULL)
        {
            mSimulationType = static_cast< CModelEntity * >(mpObject)->getStatus();
        }
    }

    if (mpObject != NULL)
    {
        switch (mType)
        {
        case Model:
        {
            CModel * pModel = static_cast< CModel * >(mpObject);

            if (!pModel->isAutonomous())
            {
                mValue = pModel->getInitialValue();
            }
            else
            {
                mValue = 0.0;
            }
        }
        break;

        case Compartment:
        case Species:
        case ModelValue:
        {
            CModelEntity * pEntity = static_cast< CModelEntity * >(mpObject);

            mValue = pEntity->getInitialValue();
        }
        break;

        case ReactionParameter:
        {
            CCopasiParameter * pParameter = static_cast< CCopasiParameter * >(mpObject);
            mValue = * pParameter->getValue().pDOUBLE;

            // We need to update the mapping
            // Check whether this refers to a global quantity.
            const CReaction * pReaction = static_cast< CModelParameterReactionParameter * >(this)->getReaction();

            if (pReaction != NULL)
            {
                if (pReaction->isLocalParameter(getName()))
                {
                    mSimulationType = CModelEntity::FIXED;
                    static_cast< CModelParameterReactionParameter * >(this)->setGlobalQuantityCN("");
                }
                else
                {
                    mSimulationType = CModelEntity::ASSIGNMENT;
                    const std::vector<std::string> ModelValue = pReaction->getParameterMapping(getName());

                    assert(ModelValue.size() == 1);

                    CModelValue * pModelValue = static_cast< CModelValue * >(CCopasiRootContainer::getKeyFactory()->get(ModelValue[0]));
                    static_cast< CModelParameterReactionParameter * >(this)->setGlobalQuantityCN(pModelValue->getInitialValueReference()->getCN());
                }
            }

            CCopasiObjectName GlobalQuantityCN = static_cast< CModelParameterReactionParameter * >(this)->getGlobalQuantityCN();

            if (GlobalQuantityCN != "")
            {
                CModelParameter * pGlobalQuantity = getSet()->getModelParameter(GlobalQuantityCN);

                if (pGlobalQuantity != NULL)
                {
                    mValue = pGlobalQuantity->getValue(ParticleNumbers);
                }
            }
        }
        break;

        default:
            success = false;
            break;
        }
    }

    return success;
}