Exemple #1
0
bool CQSpecieDM::insertRows(int position, int rows, const QModelIndex&)
{
  CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0];

  if (pDataModel->getModel()->getCompartments().size() == 0)
    {
      pDataModel->getModel()->createCompartment("compartment");
      emit notifyGUI(ListViews::COMPARTMENT, ListViews::ADD, pDataModel->getModel()->getCompartments()[0]->getKey());
    }

  beginInsertRows(QModelIndex(), position, position + rows - 1);

  for (int row = 0; row < rows; ++row)
    {
      mpSpecies =
        pDataModel->getModel()->createMetabolite(TO_UTF8(createNewName("species", COL_NAME_SPECIES)), "", 1.0, CModelEntity::REACTIONS);

      if (mNotify)
        {
          emit notifyGUI(ListViews::METABOLITE, ListViews::ADD, mpSpecies->getKey());
        }
    }

  endInsertRows();

  return true;
}
Exemple #2
0
void CQCompartment::deleteCompartment()
{

  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
  CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0];
  assert(pDataModel != NULL);
  CModel * pModel = pDataModel->getModel();

  if (pModel == NULL) return;

  if (mpCompartment == NULL) return;

  QMessageBox::StandardButton choice =
    CQMessageBox::confirmDelete(this, "compartment",
                                FROM_UTF8(mpCompartment->getObjectName()),
                                mpCompartment->getDeletedObjects());

  switch (choice)
    {
      case QMessageBox::Ok:
      {
        pDataModel->getModel()->removeCompartment(mKey);

        protectedNotify(ListViews::COMPARTMENT, ListViews::DELETE, mKey);
        protectedNotify(ListViews::COMPARTMENT, ListViews::DELETE, ""); //Refresh all as there may be dependencies.
        break;
      }

      default:
        break;
    }

  mpListView->switchToOtherWidget(111, "");
}
void CQCompartment::slotBtnDelete()
{
  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
  CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0];
  assert(pDataModel != NULL);
  CModel * pModel = pDataModel->getModel();

  if (pModel == NULL) return;

  if (mpCompartment == NULL) return;

  QMessageBox::StandardButton choice =
    CQMessageBox::confirmDelete(this, "compartment",
                                FROM_UTF8(mpCompartment->getObjectName()),
                                mpCompartment->getDeletedObjects());

  switch (choice)
    {
      case QMessageBox::Ok:
      {
        unsigned C_INT32 Index =
          pDataModel->getModel()->getCompartments().getIndex(mpCompartment->getObjectName());
        pDataModel->getModel()->removeCompartment(mKey);
        std::string deletedKey = mKey;
        //std::string moveToKey = "";

        unsigned C_INT32 Size =
          pDataModel->getModel()->getCompartments().size();

        QObject *pParent = parent();
        CTabWidget * pTabWidget = NULL;

        while (pParent != NULL &&
               (pTabWidget = dynamic_cast< CTabWidget *>(pParent)) == NULL)
          {
            pParent = pParent->parent();
          }

        if (pTabWidget != NULL)
          {
            if (Size > 0)
              pTabWidget->enter(pDataModel->getModel()->getCompartments()[std::min(Index, Size - 1)]->getKey());
            else
              pTabWidget->enter("");
          }

        protectedNotify(ListViews::COMPARTMENT, ListViews::DELETE, deletedKey);
        protectedNotify(ListViews::COMPARTMENT, ListViews::DELETE, ""); //Refresh all as there may be dependencies.
        break;
      }

      default:
        break;
    }
}
Exemple #4
0
void test000053::test4_bug1000()
{
  // load the CPS file
  // export to SBML
  // check the resulting SBML model
  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(test000053::MODEL_STRING_4));
  const CModel* pModel = pDataModel->getModel();
  CPPUNIT_ASSERT(pModel != NULL);
  CPPUNIT_ASSERT(pModel->getCompartments().size() == 1);
  CPPUNIT_ASSERT(pModel->getModelValues().size() == 0);
  CPPUNIT_ASSERT(pModel->getReactions().size() == 0);
  CPPUNIT_ASSERT(pModel->getMetabolites().size() == 1);
  const CMetab* pMetab = pModel->getMetabolites()[0];
  CPPUNIT_ASSERT(pMetab != NULL);
  CPPUNIT_ASSERT(pMetab->getObjectName() == "A");
  CPPUNIT_ASSERT(pMetab->getStatus() == CModelEntity::ASSIGNMENT);
  const CExpression* pExpr = pMetab->getExpressionPtr();
  CPPUNIT_ASSERT(pExpr != NULL);
  const CEvaluationNode* pRoot = pExpr->getRoot();
  CPPUNIT_ASSERT(pRoot != NULL);
  CPPUNIT_ASSERT(pRoot->mainType() == CEvaluationNode::T_NUMBER);
  CPPUNIT_ASSERT((pRoot->subType()) == CEvaluationNode::S_DOUBLE);
  const CEvaluationNodeNumber* pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pRoot);
  CPPUNIT_ASSERT(pNumberNode != NULL);
  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 1.5) / 1.5) < 1e-6);
}
Exemple #5
0
void SliderDialog::editSlider()
{
  SliderSettingsDialog* pSettingsDialog = new SliderSettingsDialog(this);
  // set the list of sliders that is already known
  CCopasiObject* object = (CCopasiObject*)getTaskForFolderId(mCurrentFolderId);

  if (!object) return;

  CCopasiDataModel * pDataModel = object->getObjectDataModel();
  assert(pDataModel != NULL);
  pSettingsDialog->setModel(pDataModel->getModel());

  std::vector<CSlider*>* pVector = getCSlidersForCurrentFolderId();
  pSettingsDialog->setDefinedSliders(*pVector);

  //pSettingsDialog->disableObjectChoosing(true);

  pSettingsDialog->setSlider(mpCurrSlider->getCSlider());

  if (pSettingsDialog->exec() == QDialog::Accepted)
    {
      addSlider(pSettingsDialog->getSlider());
      mpCurrSlider->updateSliderData();
      /*
      if ((!mpCurrSlider->isEnabled()) && mpCurrSlider->getCSlider()->compile())
        {
          mpCurrSlider->setEnabled(true);
        }
        */
    }

  delete pSettingsDialog;
  delete pVector;
}
Exemple #6
0
void test000080::test_mass_action_recognition_bug()
{
  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;

  try
    {
      CPPUNIT_ASSERT(pDataModel->importSBMLFromString(test000080::MODEL_STRING1));
    }
  catch (...)
    {
      // there should not be an exception
      CPPUNIT_ASSERT(false);
    }

  const CModel* pModel = pDataModel->getModel();

  CPPUNIT_ASSERT(pModel != NULL);

  CPPUNIT_ASSERT(pModel->getReactions().size() == 1);

  const CReaction* pReaction = pModel->getReactions()[0];

  CPPUNIT_ASSERT(pReaction != NULL);

  const CFunction* pFun = pReaction->getFunction();

  CPPUNIT_ASSERT(pFun != NULL);

  CPPUNIT_ASSERT(pFun->getType() == CEvaluationTree::UserDefined);
}
Exemple #7
0
RemoveGlobalQuantityRowsCommand::RemoveGlobalQuantityRowsCommand(
  QModelIndexList rows, CQGlobalQuantityDM * pGlobalQuantityDM, const QModelIndex&)
  : CCopasiUndoCommand("Global Quantity", GLOBALQUANTITY_REMOVE)
  , mpGlobalQuantityDM(pGlobalQuantityDM)
  , mRows(rows)
  , mpGlobalQuantityData()
  , mFirstTime(true)
{

  CCopasiDataModel * pDataModel = pGlobalQuantityDM->getDataModel();
  assert(pDataModel != NULL);
  CModel * pModel = pDataModel->getModel();
  assert(pModel != NULL);

  QModelIndexList::const_iterator i;

  for (i = rows.begin(); i != rows.end(); ++i)
    {
      CModelValue* pModelValue = &pModel->getModelValues()[i->row()];

      if (pGlobalQuantityDM->isDefaultRow(*i) || pModelValue == NULL)
        continue;

      UndoGlobalQuantityData *data = new UndoGlobalQuantityData(pModelValue);
      mpGlobalQuantityData.append(data);
    }

  setText(QObject::tr(": Removed Global Quantity"));
}
Exemple #8
0
void CCopasiTask::initObjects()
{
    addObjectReference("Output counter", mOutputCounter, CCopasiObject::ValueInt);
    new CCopasiTimer(CCopasiTimer::WALL, this);
    new CCopasiTimer(CCopasiTimer::PROCESS, this);

    CCopasiDataModel *pDataModel = getObjectDataModel();

    if (pDataModel != NULL)
    {
        if (pDataModel->getModel() != NULL)
        {
            setMathContainer(&pDataModel->getModel()->getMathContainer());
        }
    }
}
RemoveAllReactionRowsCommand::RemoveAllReactionRowsCommand(CQReactionDM * pReaDM, const QModelIndex&)
{
  mpReactionDM = pReaDM;

  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
  CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0];
  assert(pDataModel != NULL);
  CModel * pModel = pDataModel->getModel();

  assert(pModel != NULL);

  for (int i = 0; i != pReaDM->rowCount() - 1; ++i)
    {
      UndoReactionData *data = new UndoReactionData();
      CReactionInterface* ri = new CReactionInterface((*CCopasiRootContainer::getDatamodelList())[0]->getModel());

      if (pModel->getReactions()[i])
        {
          data->setName(pModel->getReactions()[i]->getObjectName());
          ri->initFromReaction(pModel->getReactions()[i]->getKey());
          data->setRi(ri);
          mpReaData.append(data);
        }
    }

  mType = REACTIONREMOVEALL;
  setEntityType("Reaction");
  this->setText(removeAllReactionRowsText());
}
Exemple #10
0
void CCopasiSelectionDialog::setFilter(const CQSimpleSelectionTree::ObjectClasses & classes)
{
  CCopasiDataModel * pDataModel = ListViews::dataModel(this);
  assert(pDataModel != NULL);

  this->mpSelectionWidget->populateTree(pDataModel->getModel(), classes);
}
void insertReactionRowsCommand::redo()
{
  mpReactionDM->insertNewReactionRow(mPosition, mRows, QModelIndex());
  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
  CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0];
  assert(pDataModel != NULL);
  CModel * pModel = pDataModel->getModel();
  assert(pModel != NULL);
  mpReaction = pModel->getReactions()[mPosition];
  std::string sName = mpReaction->getObjectName();

  if (mpReactionData != NULL)
    mpReactionData->setName(sName);

  CReactionInterface* ri = new CReactionInterface((*CCopasiRootContainer::getDatamodelList())[0]->getModel());
  ri->initFromReaction(mpReaction);

  if (mpReactionData != NULL)
    mpReactionData->setRi(ri);

  setUndoState(true);
  setAction("Add to list");

  if (mpReactionData != NULL)
    setName(mpReactionData->getName());
  else setName(sName);
}
void InsertCompartmentRowsCommand::redo()
{
  if (firstTime)
    {
      mpCompartmentDM->insertNewCompartmentRow(mPosition, mRows, QModelIndex());
      assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
      CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0];
      assert(pDataModel != NULL);
      CModel * pModel = pDataModel->getModel();
      assert(pModel != NULL);

      CCompartment *pCompartment = pModel->getCompartments()[mPosition];
      mpCompartmentData->setName(pCompartment->getObjectName());
      mpCompartmentData->setStatus(pCompartment->getStatus());
      mpCompartmentData->setInitialValue(pCompartment->getInitialValue());
      firstTime = false;
    }
  else
    {
      mpCompartmentDM->addCompartmentRow(mpCompartmentData);
    }

  setUndoState(true);
  setAction("Add to list");
  setName(mpCompartmentData->getName());
}
Exemple #13
0
void test000046::test_stoichiometricExpression()
{
  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING));
  CModel* pModel = pDataModel->getModel();
  CPPUNIT_ASSERT(pModel != NULL);
  CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CModel::mMol);
  CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CModel::ml);
  CPPUNIT_ASSERT(pModel->getTimeUnitEnum() == CModel::s);
  CPPUNIT_ASSERT(pModel->getCompartments().size() == 1);
  const CCompartment* pCompartment = pModel->getCompartments()[0];
  CPPUNIT_ASSERT(pCompartment != NULL);
  CPPUNIT_ASSERT(pCompartment->getStatus() == CModelEntity::FIXED);
  CPPUNIT_ASSERT(pModel->getMetabolites().size() == 2);
  CMetab* pA = pModel->getMetabolites()[0];
  CPPUNIT_ASSERT(pA != NULL);
  CPPUNIT_ASSERT(pA->getStatus() == CModelEntity::REACTIONS);
  const CMetab* pB = pModel->getMetabolites()[1];
  CPPUNIT_ASSERT(pB != NULL);
  CPPUNIT_ASSERT(pB->getStatus() == CModelEntity::REACTIONS);
  CPPUNIT_ASSERT(pModel->getModelValues().size() == 1);
  const CModelValue* pModelValue = pModel->getModelValues()[0];
  CPPUNIT_ASSERT(pModelValue != NULL);
  CPPUNIT_ASSERT(pModelValue->getStatus() == CModelEntity::FIXED);
  CPPUNIT_ASSERT(fabs((pModelValue->getInitialValue() - 3.7) / 3.7) < 1e-3);

  CPPUNIT_ASSERT(pModel->getReactions().size() == 1);
  const CReaction* pReaction1 = pModel->getReactions()[0];
  CPPUNIT_ASSERT(pReaction1 != NULL);
  CPPUNIT_ASSERT(pReaction1->isReversible() == true);
  // check the kinetic law
  const CFunction* pKineticFunction = pReaction1->getFunction();
  CPPUNIT_ASSERT(pKineticFunction != NULL);
  const CMassAction* pMassAction = dynamic_cast<const CMassAction*>(pKineticFunction);
  CPPUNIT_ASSERT(pMassAction != NULL);
  const CChemEq* pChemEq = &pReaction1->getChemEq();
  CPPUNIT_ASSERT(pChemEq != NULL);
  CPPUNIT_ASSERT(pChemEq->getCompartmentNumber() == 1);
  CPPUNIT_ASSERT(pChemEq->getSubstrates().size() == 1);
  const CChemEqElement* pElement = pChemEq->getSubstrates()[0];
  CPPUNIT_ASSERT(pElement != NULL);
  CPPUNIT_ASSERT(fabs((pElement->getMultiplicity() - 1.85) / 1.85) < 1e-3);
  CPPUNIT_ASSERT(pElement->getMetabolite() == pA);
  CPPUNIT_ASSERT(pChemEq->getProducts().size() == 1);
  pElement = pChemEq->getProducts()[0];
  CPPUNIT_ASSERT(pElement != NULL);
  CPPUNIT_ASSERT(fabs((pElement->getMultiplicity() - 3.35) / 3.35) / 3.35 < 1e-3);
  CPPUNIT_ASSERT(pElement->getMetabolite() == pB);
  CPPUNIT_ASSERT(pChemEq->getModifiers().size() == 0);
  //CPPUNIT_ASSERT(CCopasiMessage::size() == 5);
  CCopasiMessage message = CCopasiMessage::getLastMessage();
  CPPUNIT_ASSERT(message.getType() == CCopasiMessage::WARNING);
  std::string s = message.getText();
  CPPUNIT_ASSERT(!s.empty());
  CPPUNIT_ASSERT(s.find(std::string("One or more stoichiometric expressions were evaluated and converted to constants values.")) != std::string::npos);
  // the other four messages are libSBML unit warnings I don't care about right
  // now.
}
Exemple #14
0
void test000047::test_delay()
{
  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING));
  CModel* pModel = pDataModel->getModel();
  CPPUNIT_ASSERT(pModel != NULL);
  CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CUnit::mMol);
  CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CUnit::ml);
  CPPUNIT_ASSERT(pModel->getTimeUnitEnum() == CUnit::s);
  CPPUNIT_ASSERT(pModel->getCompartments().size() == 1);
  const CCompartment* pCompartment = pModel->getCompartments()[0];
  CPPUNIT_ASSERT(pCompartment != NULL);
  CPPUNIT_ASSERT(pCompartment->getStatus() == CModelEntity::FIXED);
  CPPUNIT_ASSERT(pModel->getMetabolites().size() == 2);
  const CMetab* pB = pModel->getMetabolites()[1];
  CPPUNIT_ASSERT(pB != NULL);
  CPPUNIT_ASSERT(pB->getStatus() == CModelEntity::FIXED);
  CMetab* pA = pModel->getMetabolites()[0];
  CPPUNIT_ASSERT(pA != NULL);
  CPPUNIT_ASSERT(pA->getStatus() == CModelEntity::ASSIGNMENT);
  const CExpression* pExpr = pA->getExpressionPtr();
  CPPUNIT_ASSERT(pExpr != NULL);
  const CEvaluationNode* pNode = pExpr->getRoot();
  CPPUNIT_ASSERT(pNode != NULL);
  const CEvaluationNodeDelay* pDelayNode = dynamic_cast<const CEvaluationNodeDelay*>(pNode);
  CPPUNIT_ASSERT(pDelayNode != NULL);
  const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pDelayNode->getChild());
  CPPUNIT_ASSERT(pObjectNode != NULL);
  CCopasiObjectName objectCN = pObjectNode->getObjectCN();
  CPPUNIT_ASSERT(!objectCN.empty());
  std::vector<CCopasiContainer*> listOfContainers;
  listOfContainers.push_back(pModel);
  const CCopasiObject* pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
  CPPUNIT_ASSERT(pObject != NULL);
  CPPUNIT_ASSERT(pObject->isReference() == true);
  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Concentration"));
  CPPUNIT_ASSERT(pObject->getObjectParent() == pB);
  const CEvaluationNodeNumber* pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pObjectNode->getSibling());
  CPPUNIT_ASSERT(pNumberNode != NULL);
  CPPUNIT_ASSERT(((CEvaluationNodeNumber::SubType)CEvaluationNode::subType(pNumberNode->getType())) == CEvaluationNodeNumber::DOUBLE);
  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 0.5) / 0.5) < 1e-3);

  CPPUNIT_ASSERT(pNumberNode->getSibling() == NULL);

  CPPUNIT_ASSERT(pModel->getModelValues().size() == 1);
  const CModelValue* pModelValue = pModel->getModelValues()[0];
  CPPUNIT_ASSERT(pModelValue != NULL);
  CPPUNIT_ASSERT(pModelValue->getStatus() == CModelEntity::FIXED);
  CPPUNIT_ASSERT(pModel->getReactions().size() == 0);
  //CPPUNIT_ASSERT(CCopasiMessage::size() == 2);
  CCopasiMessage message = CCopasiMessage::getLastMessage();
  CPPUNIT_ASSERT(message.getType() == CCopasiMessage::WARNING);
  std::string s = message.getText();
  CPPUNIT_ASSERT(!s.empty());
  CPPUNIT_ASSERT(s.find(std::string("COPASI does not support time delays. Calculations on this model will most likely lead to unusable results.")) != std::string::npos);
  // right now, we don't care about the last message since it is a units
  // warning from libSBML
}
Exemple #15
0
void CQEventWidget1::deleteEvent()
{

  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
  CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0];

  CModel * pModel = pDataModel->getModel();

  if (pModel == NULL)
    return;

  pDataModel->getModel()->removeEvent(mKey);

  mpEvent = NULL;

  protectedNotify(ListViews::EVENT, ListViews::DELETE, mKey);
  mpListView->switchToOtherWidget(116, "");
}
Exemple #16
0
void test000052::test_bug988()
{
    CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
    CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING));
    CModel* pModel = pDataModel->getModel();
    CPPUNIT_ASSERT(pModel != NULL);
    CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CModel::mMol);
    CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CModel::ml);
    CPPUNIT_ASSERT(pModel->getTimeUnitEnum() == CModel::s);
    CPPUNIT_ASSERT(pModel->getCompartments().size() == 1);
    const CCompartment* pCompartment = pModel->getCompartments()[0];
    CPPUNIT_ASSERT(pCompartment != NULL);
    CPPUNIT_ASSERT(pCompartment->getStatus() == CModelEntity::FIXED);
    CPPUNIT_ASSERT(pModel->getMetabolites().size() == 1);
    CMetab* pA = pModel->getMetabolites()[0];
    CPPUNIT_ASSERT(pA != NULL);
    CPPUNIT_ASSERT(pA->getStatus() == CModelEntity::ASSIGNMENT);
    const CExpression* pExpr = pA->getExpressionPtr();
    // check the expression
    const CEvaluationNode* pNode = pExpr->getRoot();
    CPPUNIT_ASSERT(pNode != NULL);
    const CEvaluationNodeChoice* pChoiceNode = dynamic_cast<const CEvaluationNodeChoice*>(pNode);
    CPPUNIT_ASSERT(pChoiceNode != NULL);
    pNode = dynamic_cast<const CEvaluationNode*>(pChoiceNode->getChild());
    CPPUNIT_ASSERT(pNode != NULL);
    const CEvaluationNodeLogical* pLogicalNode = dynamic_cast<const CEvaluationNodeLogical*>(pNode);
    CPPUNIT_ASSERT(pLogicalNode != NULL);
    CPPUNIT_ASSERT(((CEvaluationNodeLogical::SubType)CEvaluationNode::subType(pLogicalNode->getType())) == CEvaluationNodeLogical::LT);
    const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pLogicalNode->getChild());
    CPPUNIT_ASSERT(pObjectNode != NULL);
    CCopasiObjectName objectCN = pObjectNode->getObjectCN();
    CPPUNIT_ASSERT(!objectCN.empty());
    std::vector<CCopasiContainer*> listOfContainers;
    listOfContainers.push_back(pModel);
    const CCopasiObject* pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
    CPPUNIT_ASSERT(pObject != NULL);
    CPPUNIT_ASSERT(pObject->isReference() == true);
    CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Time"));
    CPPUNIT_ASSERT(pObject->getObjectParent() == pModel);
    const CEvaluationNodeNumber* pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pObjectNode->getSibling());
    CPPUNIT_ASSERT(pNumberNode != NULL);
    CPPUNIT_ASSERT(((CEvaluationNodeNumber::SubType)CEvaluationNode::subType(pNumberNode->getType())) == CEvaluationNodeNumber::DOUBLE);
    CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 5.0) / 5.0) < 1e-3);
    pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pLogicalNode->getSibling());
    CPPUNIT_ASSERT(pNumberNode != NULL);
    CPPUNIT_ASSERT(((CEvaluationNodeNumber::SubType)CEvaluationNode::subType(pNumberNode->getType())) == CEvaluationNodeNumber::DOUBLE);
    CPPUNIT_ASSERT(pNumberNode->getValue() < 1e-3);
    pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pNumberNode->getSibling());
    CPPUNIT_ASSERT(pNumberNode != NULL);
    CPPUNIT_ASSERT(((CEvaluationNodeNumber::SubType)CEvaluationNode::subType(pNumberNode->getType())) == CEvaluationNodeNumber::DOUBLE);
    CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 10.0) / 10.0) < 1e-3);

    CPPUNIT_ASSERT(pModel->getModelValues().size() == 0);
    CPPUNIT_ASSERT(pModel->getReactions().size() == 0);
}
// added 5/19/04
void ReactionsWidget1::slotBtnNew()
{
  std::string name = "reaction";
  size_t i = 0;
  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
  CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0];
  assert(pDataModel != NULL);

  while (!pDataModel->getModel()->createReaction(name))
    {
      i++;
      name = "reaction_";
      name += TO_UTF8(QString::number(i));
    }

  std::string key = pDataModel->getModel()->getReactions()[name]->getKey();
  protectedNotify(ListViews::REACTION, ListViews::ADD, key);
  enter(key);
  mpListView->switchToOtherWidget(C_INVALID_INDEX, key);
}
Exemple #18
0
/*! Slot to delete the active event widget */
void CQEventWidget1::slotBtnDelete()
{
#ifdef COPASI_UNDO
  mpUndoStack->push(new DeleteEventCommand(this));
#else
  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
  CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0];

  CModel * pModel = pDataModel->getModel();

  if (pModel == NULL)
    return;

  pDataModel->getModel()->removeEvent(mKey);

  mpEvent = NULL;

  protectedNotify(ListViews::EVENT, ListViews::DELETE, mKey);
#endif
}
Exemple #19
0
bool CQUnitDM::removeRows(QModelIndexList rows, const QModelIndex&)
{
  if (rows.isEmpty())
    return false;

  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
  CCopasiDataModel* pDataModel = &CCopasiRootContainer::getDatamodelList()->operator[](0);
  assert(pDataModel != NULL);
  CModel * pModel = pDataModel->getModel();

  if (pModel == NULL)
    return false;

  // Build the list of pointers to items to be deleted
  // before actually deleting any item.

  QList <CUnitDefinition *> pUnitDefQList;
  QModelIndexList::const_iterator i;
  CUnitDefinition * pUnitDef;

  for (i = rows.begin(); i != rows.end(); ++i)
    {
      if (!isDefaultRow(*i) &&
          (pUnitDef = &CCopasiRootContainer::getUnitList()->operator[](i->row())) != NULL &&
          pModel->getUnitSymbolUsage(pUnitDef->getSymbol()).empty() &&
          !pUnitDef->isReadOnly())//Don't delete built-ins or used units
        pUnitDefQList.append(&CCopasiRootContainer::getUnitList()->operator[](i->row()));
    }

  for (QList <CUnitDefinition *>::const_iterator j = pUnitDefQList.begin(); j != pUnitDefQList.end(); ++j)
    {
      size_t delRow =
        CCopasiRootContainer::getUnitList()->CCopasiVector< CUnitDefinition >::getIndex(*j);

      if (delRow != C_INVALID_INDEX)
        {
          CCopasiObject::DataObjectSet DeletedObjects;
          DeletedObjects.insert(*j);

          QMessageBox::StandardButton choice =
            CQMessageBox::confirmDelete(NULL, "unit",
                                        FROM_UTF8((*j)->getObjectName()),
                                        DeletedObjects);

          if (choice == QMessageBox::Ok)
            removeRow((int) delRow);
        }
    }

  return true;
}
RemoveAllGlobalQuantityRowsCommand::RemoveAllGlobalQuantityRowsCommand(CQGlobalQuantityDM * pGlobalQuantityDM, const QModelIndex&)
{
  mpGlobalQuantityDM = pGlobalQuantityDM;

  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
  CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0];
  assert(pDataModel != NULL);
  CModel * pModel = pDataModel->getModel();

  assert(pModel != NULL);

  for (int i = 0; i != pGlobalQuantityDM->rowCount() - 1; ++i)
    {

      UndoGlobalQuantityData *data = new UndoGlobalQuantityData();

      if (pModel->getModelValues()[i])
        {
          data->setName(pModel->getModelValues()[i]->getObjectName());
          data->setStatus(pModel->getModelValues()[i]->getStatus());

          if (pModel->getModelValues()[i]->getStatus() != CModelEntity::ASSIGNMENT)
            {
              data->setInitialValue(pModel->getModelValues()[i]->getInitialValue());
            }

          // set expression
          if (pModel->getModelValues()[i]->getStatus() != CModelEntity::FIXED)
            {
              data->setExpression(pModel->getModelValues()[i]->getExpression());
            }

          // set initial expression
          if (pModel->getModelValues()[i]->getStatus() != CModelEntity::ASSIGNMENT)
            {
              data->setInitialExpression(pModel->getModelValues()[i]->getInitialExpression());
            }

          setDependentObjects(pModel->getModelValues()[i]->getDeletedObjects());
          data->setReactionDependencyObjects(getReactionData());
          data->setSpecieDependencyObjects(getSpecieData());
          data->setEventDependencyObjects(getEventData());
          mpGlobalQuantityData.append(data);
        }
    }

  mType = GLOBALQUANTITYREMOVEALL;
  setEntityType("Global Quantity");
  this->setText(removeAllGlobalQuantityRowsText());
}
// Just added 5/18/04
void ReactionsWidget1::slotBtnDelete()
{
  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
  CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0];
  assert(pDataModel != NULL);
  CModel * pModel = pDataModel->getModel();

  if (pModel == NULL)
    return;

  CReaction * pReaction =
    dynamic_cast< CReaction * >(CCopasiRootContainer::getKeyFactory()->get(mKey));

  if (pReaction == NULL) return;

  QMessageBox::StandardButton choice =
    CQMessageBox::confirmDelete(NULL, "reaction",
                                FROM_UTF8(pReaction->getObjectName()),
                                pReaction->getDeletedObjects());

  switch (choice)
    {
      case QMessageBox::Ok:                                                     // Yes or Enter
      {
        pDataModel->getModel()->removeReaction(mKey);

        mpRi->setFunctionWithEmptyMapping("");

        protectedNotify(ListViews::REACTION, ListViews::DELETE, mKey);
        protectedNotify(ListViews::REACTION, ListViews::DELETE, "");//Refresh all as there may be dependencies.
        break;
      }

      default:                                                     // No or Escape
        break;
    }
}
Exemple #22
0
bool CSlider::setSliderObject(CCopasiObject * pObject)
{
  mpSliderObject = pObject;

  if (!pObject)
    {
      mInitialRefreshes.clear();
      return false;
    }

  mCN = pObject->getCN();

  std::set< const CCopasiObject * > ChangedObjects;
  ChangedObjects.insert(pObject);

  CCopasiDataModel* pDataModel = getObjectDataModel();
  assert(pDataModel != NULL);
  mInitialRefreshes = pDataModel->getModel()->buildInitialRefreshSequence(ChangedObjects);

  if (mpSliderObject->isValueInt())
    {
      this->setSliderType(Integer);
    }
  else if (mpSliderObject->isValueDbl())
    {
      this->setSliderType(Float);
    }
  else
    {
      this->setSliderType(Undefined);
    }

  if (this->mSync) this->sync();

  C_FLOAT64 value = this->getSliderValue();
  this->mOriginalValue = value;

  if (this->mMinValue > value)
    {
      this->mMinValue = value;
    }

  if (this->mMaxValue < value)
    {
      this->mMaxValue = value;
    }

  return true;
}
Exemple #23
0
void CQCompartment::slotBtnDelete()
{
#ifdef COPASI_UNDO
  mpUndoStack->push(new DeleteCompartmentCommand(this));
#else
  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
  CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0];
  assert(pDataModel != NULL);
  CModel * pModel = pDataModel->getModel();

  if (pModel == NULL) return;

  if (mpCompartment == NULL) return;

  QMessageBox::StandardButton choice =
    CQMessageBox::confirmDelete(this, "compartment",
                                FROM_UTF8(mpCompartment->getObjectName()),
                                mpCompartment->getDeletedObjects());

  switch (choice)
    {
      case QMessageBox::Ok:
      {
        pDataModel->getModel()->removeCompartment(mKey);

        protectedNotify(ListViews::COMPARTMENT, ListViews::DELETE, mKey);
        protectedNotify(ListViews::COMPARTMENT, ListViews::DELETE, ""); //Refresh all as there may be dependencies.
        break;
      }

      default:
        break;
    }

#endif
}
Exemple #24
0
void CQPlotsWidget::slotBtnDeactivateAllClicked()
{
  CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0];
  assert(pDataModel != NULL);

  if (!pDataModel->getModel())
    return;

  for (size_t i = 0; i < pDataModel->getPlotDefinitionList()->size(); i++)
    {
      CPlotSpecification *pPS = static_cast<CPlotSpecification *>(pDataModel->getPlotDefinitionList()->operator[](i));
      pPS->setActive(false);
    }

  mpTblPlots->doItemsLayout();
}
Exemple #25
0
bool CQSpecieDM::removeRows(QModelIndexList rows, const QModelIndex&)
{
  if (rows.isEmpty())
    return false;

  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
  CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0];
  assert(pDataModel != NULL);
  CModel * pModel = pDataModel->getModel();

  if (pModel == NULL)
    return false;

//Build the list of pointers to items to be deleted
//before actually deleting any item.
  QList <CMetab *> pSpecies;
  QModelIndexList::const_iterator i;

  for (i = rows.begin(); i != rows.end(); ++i)
    {
      if (!isDefaultRow(*i) && pModel->getMetabolites()[(*i).row()])
        pSpecies.append(pModel->getMetabolites()[(*i).row()]);
    }

  QList <CMetab *>::const_iterator j;

  for (j = pSpecies.begin(); j != pSpecies.end(); ++j)
    {
      CMetab * pSpecie = *j;

      size_t delRow =
        pModel->getMetabolites().CCopasiVector< CMetab >::getIndex(pSpecie);

      if (delRow != C_INVALID_INDEX)
        {
          QMessageBox::StandardButton choice =
            CQMessageBox::confirmDelete(NULL, "species",
                                        FROM_UTF8(pSpecie->getObjectName()),
                                        pSpecie->getDeletedObjects());

          if (choice == QMessageBox::Ok)
            removeRow((int) delRow);
        }
    }

  return true;
}
RemoveEventRowsCommand::RemoveEventRowsCommand(QModelIndexList rows, CQEventDM * pEventDM, const QModelIndex&)
{
  mpEventDM = pEventDM;
  mRows = rows;
  mFirstTime = true;

  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
  CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0];
  assert(pDataModel != NULL);
  CModel * pModel = pDataModel->getModel();

  assert(pModel != NULL);

  QModelIndexList::const_iterator i;

  for (i = rows.begin(); i != rows.end(); ++i)
    {
      UndoEventData *data = new UndoEventData();

      if (!pEventDM->isDefaultRow(*i) && pModel->getEvents()[(*i).row()])
        {
          data->setName(pModel->getEvents()[(*i).row()]->getObjectName());
          data->setPriorityExpression(pModel->getEvents()[(*i).row()]->getPriorityExpression());
          data->setDelayExpression(pModel->getEvents()[(*i).row()]->getDelayExpression());
          data->setTriggerExpression(pModel->getEvents()[(*i).row()]->getTriggerExpression());

          CCopasiVector< CEventAssignment >::const_iterator it = pModel->getEvents()[(*i).row()]->getAssignments().begin();
          CCopasiVector< CEventAssignment >::const_iterator end = pModel->getEvents()[(*i).row()]->getAssignments().end();

          for (; it != end; ++it)
            {
              const CModelEntity * pEntity = dynamic_cast< CModelEntity * >(CCopasiRootContainer::getKeyFactory()->get((*it)->getTargetKey()));
              UndoEventAssignmentData *eventAssignData = new UndoEventAssignmentData();
              eventAssignData->setName(pEntity->getObjectName());
              eventAssignData->setExpression((*it)->getExpression());
              data->getEventAssignmentData()->append(eventAssignData);
            }

          mpEventData.append(data);
        }
    }

  this->setText(removeEventRowsText());
  mType = EVENTREMOVE;
  setEntityType("Event");
}
Exemple #27
0
/**
 * Load a trajectory problem
 * @param "CReadConfig &" configBuffer
 */
void CTrajectoryProblem::load(CReadConfig & configBuffer,
                              CReadConfig::Mode C_UNUSED(mode))
{
  if (configBuffer.getVersion() < "4.0")
    {
      CCopasiDataModel* pDataModel = getObjectDataModel();
      assert(pDataModel != NULL);
      mpModel = pDataModel->getModel();
      configBuffer.getVariable("EndTime", "C_FLOAT64",
                               mpDuration,
                               CReadConfig::LOOP);
      configBuffer.getVariable("Points", "C_INT32",
                               mpStepNumber);
      mStepNumberSetLast = true;

      sync();
    }
}
RemoveCompartmentRowsCommand::RemoveCompartmentRowsCommand(QModelIndexList rows, CQCompartmentDM * pCompartmentDM, const QModelIndex&)
{
  mpCompartmentDM = pCompartmentDM;
  mRows = rows;
  mFirstTime = true;

  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
  CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0];
  assert(pDataModel != NULL);
  CModel * pModel = pDataModel->getModel();

  assert(pModel != NULL);

  QModelIndexList::const_iterator i;

  for (i = rows.begin(); i != rows.end(); ++i)
    {
      UndoCompartmentData *data = new UndoCompartmentData();

      if (!pCompartmentDM->isDefaultRow(*i) && pModel->getCompartments()[(*i).row()])
        {
          mpSpecieData = new QList <UndoSpecieData*>();
          mpReactionData = new  QList <UndoReactionData*>();
          mpGlobalQuantityData = new  QList <UndoGlobalQuantityData*>();
          mpEventData = new  QList <UndoEventData*>();
          data->setName(pModel->getCompartments()[(*i).row()]->getObjectName());
          data->setStatus(pModel->getCompartments()[(*i).row()]->getStatus());
          data->setInitialValue(pModel->getCompartments()[(*i).row()]->getInitialValue());
          setDependentObjects(pModel->getCompartments()[(*i).row()]->getDeletedObjects());
          data->setReactionDependencyObjects(getReactionData());
          data->setSpecieDependencyObjects(getSpecieData());
          data->setGlobalQuantityDependencyObjects(getGlobalQuantityData());
          data->setEventDependencyObjects(getEventData());

          mpCompartmentData.append(data);
        }
    }

  this->setText(removeCompartmentRowsText());

  mType = COMPARTMENTREMOVE;
  setEntityType("Compartment");
}
Exemple #29
0
void SliderDialog::addSlider(CSlider* pSlider)
{
  if (mpParentWindow == NULL)
    return;

  // check if there already is a slider for this  object
  CCopasiDataModel * pDataModel = pSlider->getObjectDataModel();
  assert(pDataModel != NULL);
  SCopasiXMLGUI* pGUI = pDataModel->getGUI();
  assert(pGUI);

  if (!equivalentSliderExists(pSlider))
    {
      CObjectInterface::ContainerList listOfContainers;
      assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
      listOfContainers.push_back(pDataModel->getModel());
      pSlider->compile(listOfContainers);
      pGUI->getSliderList()->add(pSlider, true);
    }

  CopasiSlider* tmp = findCopasiSliderForCSlider(pSlider);

  if (!tmp)
    {
      setCurrentSlider(new CopasiSlider(pSlider, mpParentWindow->getDataModel(), mpSliderBox));
      mpCurrSlider->installEventFilter(this);
      mpCurrSlider->setHidden(true);
      mpCurrSlider->updateSliderData();
      // make sure the slider points to the correct object
      // for the currently set framework
      this->setCorrectSliderObject(this->mpCurrSlider);
      mSliderMap[mCurrentFolderId].push_back(mpCurrSlider);
      QBoxLayout* layout = static_cast<QBoxLayout*>(mpSliderBox->layout());
      int childCount = layout->count() - 1;
      layout->insertWidget(childCount, mpCurrSlider);
      connect(mpCurrSlider, SIGNAL(valueChanged(double)), this , SLOT(sliderValueChanged()));
      connect(mpCurrSlider, SIGNAL(sliderReleased()), this, SLOT(sliderReleased()));
      connect(mpCurrSlider, SIGNAL(sliderPressed()), this, SLOT(sliderPressed()));
      connect(mpCurrSlider, SIGNAL(closeClicked(CopasiSlider*)), this, SLOT(removeSlider(CopasiSlider*)));
      connect(mpCurrSlider, SIGNAL(editClicked(CopasiSlider*)), this, SLOT(editSlider(CopasiSlider*)));
      mpCurrSlider->setHidden(false);
      mChanged = true;
    }
void CQSpeciesDetail::slotBtnNew()
{
  save();

  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
  CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0];
  assert(pDataModel != NULL);

  CModel * pModel = pDataModel->getModel();

  if (pModel == NULL)
    return;

  if (pModel->getCompartments().size() == 0)
    pModel->createCompartment("compartment");

  std::string name = "species";
  int i = 0;

  while (!(mpMetab = pModel->createMetabolite(name, "", 1.0, CModelEntity::REACTIONS)))
    {
      i++;
      name = "species_";
      name += TO_UTF8(QString::number(i));
    }

  switch (mFramework)
    {
      case 0:
        mpMetab->setInitialConcentration(1.0);
        break;

      case 1:
        mpMetab->setInitialValue(100.0);
        break;
    }

  std::string key = mpMetab->getKey();
  enter(key);
  protectedNotify(ListViews::METABOLITE, ListViews::ADD, key);
  mpListView->switchToOtherWidget(-1, key);
}