Пример #1
0
bool CPlotSpecification::createDefaultPlot(const CModel* model)
{
  mActive = true;

  //TODO cleanup before?
  //title = "Default Data Plot 2D";

  CPlotItem * plItem;
  std::string itemTitle;
  CPlotDataChannelSpec name2;
  const CCopasiObject * tmp;

  CPlotDataChannelSpec name1 = model->getValueReference()->getCN();

  size_t i, imax = model->getMetabolites().size();

  for (i = 0; i < imax; ++i)
    {
      tmp = model->getMetabolites()[i]->getConcentrationReference();
      name2 = tmp->getCN();
      itemTitle = tmp->getObjectDisplayName();

      plItem = this->createItem(itemTitle, CPlotItem::curve2d);
      plItem->addChannel(name1);
      plItem->addChannel(name2);
    }

  return true; //TODO: really check;
}
Пример #2
0
void CQPlotSubwidget::addHisto1DTab(const std::string &title,
                                    const CPlotDataChannelSpec &x, const C_FLOAT64 &incr)
{
  CPlotItem *item = new CPlotItem(title, NULL, CPlotItem::histoItem1d);
  item->addChannel(x);
  item->setValue("increment", incr);
  addPlotItem(item);
}
Пример #3
0
void CQPlotSubwidget::addCurveTab(const std::string &title,
                                  const CPlotDataChannelSpec &x,
                                  const CPlotDataChannelSpec &y)
{
  CPlotItem *item = new CPlotItem(title, NULL, CPlotItem::curve2d);
  item->addChannel(x);
  item->addChannel(y);
  addPlotItem(item);
}
Пример #4
0
void CQPlotSubwidget::addSpectrumTab(const std::string &title,
                                     const CPlotDataChannelSpec &x,
                                     const CPlotDataChannelSpec &yone,
                                     const CPlotDataChannelSpec &ytwo)
{
  CPlotItem *item = new CPlotItem(title, NULL, CPlotItem::spectogram);
  item->addChannel(x);
  item->addChannel(yone);
  item->addChannel(ytwo);
  addPlotItem(item);
}
Пример #5
0
bool CQPlotSubwidget::areOfSameType(QList<QListWidgetItem *> &items)
{
  if (items.size() <= 1) return true;

  QList<CPlotItem::Type> listOfUniqueTypes;
  QList<QListWidgetItem *>::const_iterator it = items.begin();

  while (it != items.end())
    {
      QString currentText = (*it)->text();
      CPlotItem *item = mList[currentText];

      if (!listOfUniqueTypes.contains(item->getType()))
        listOfUniqueTypes.append(item->getType());

      ++it;
    }

  return listOfUniqueTypes.size() == 1;
}
Пример #6
0
void CQPlotSubwidget::storeChanges()
{
  if (mLastSelection.size() == 0)
    return;

  if (mLastSelection.size() == 1)
    {
      QString oldName = mLastSelection[0]->text();
      CPlotItem *item = mList[oldName];
      updateItem(item);

      if (item == NULL) return;

      QString newName = FROM_UTF8(item->getTitle());

      if (oldName != newName)
        {
          mList.remove(oldName);
          mLastSelection[0]->setText(newName);
          mList.insert(newName, item);
        }

      // assign current
    }
  else
    {
      if (!areOfSameType(mLastSelection) || !mpStack->isEnabled())
        return;

      CPlotItem *common = new CPlotItem("nope");

      if (mpStack->currentWidget() == mpHistoWidget)
        {
          common->setType(CPlotItem::histoItem1d);
        }

#if COPASI_BANDED_GRAPH
      else if (mpStack->currentWidget() == mpBandedGraphWidget)
        {
          common->setType(CPlotItem::bandedGraph);
        }

#endif
      else if (mpStack->currentWidget() == mpSpectogramWidget)
        {
          common->setType(CPlotItem::spectogram);
        }
      else
        {
          common->setType(CPlotItem::curve2d);
        }

      common = updateItem(common);

      if (common == NULL)
        return;

      QList<QListWidgetItem *>::const_iterator it;

      for (it = mLastSelection.begin(); it != mLastSelection.end(); ++it)
        {
          CPlotItem *current = mList[(*it)->text()];

          if (current == NULL)
            continue;

          std::vector<CPlotDataChannelSpec> channels = current->getChannels();
          CPlotItem *newItem = new CPlotItem(*common, NO_PARENT);
          newItem->setType(current->getType());
          newItem->setTitle(current->getTitle());
          newItem->getChannels() = channels;
          newItem->setActivity(common->getActivity());
          mList[(*it)->text()] = newItem;
          delete current;
        }

      pdelete(common);
      // assign multiple
    }
}
Пример #7
0
bool
CQSpectogramWidget::LoadFromCurveSpec(const CPlotItem * pCurve)
{
  if (!pCurve)
    {
      // We need to reset the widget to defaults
      mpEditTitle->setText("");

      mpObjectX = mpObjectY = mpObjectZ = NULL;

      mpEditX->setText("");
      mpEditY->setText("");
      mpEditZ->setText("");

      mpCheckBefore->setChecked(false);
      mpCheckDuring->setChecked(true);
      mpCheckAfter->setChecked(false);

      return true;
    }

  if (pCurve->getType() != CPlotItem::spectogram) return false;

  //if (pCurve->getChannels().getSize != 3) return false;

  mpEditTitle->setText(FROM_UTF8(pCurve->getTitle()));

  //TODO: check if objects exist....
  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
  CCopasiDataModel* pDataModel = &CCopasiRootContainer::getDatamodelList()->operator[](0);
  assert(pDataModel != NULL);
  mpObjectX = mpObjectY = mpObjectZ = NULL;

  if (pCurve->getChannels().size() >= 1)
    mpObjectX = dynamic_cast<const CCopasiObject*>(pDataModel->getObject(pCurve->getChannels()[0]));

  if (pCurve->getChannels().size() >= 2)
    mpObjectY = dynamic_cast<const CCopasiObject*>(pDataModel->getObject(pCurve->getChannels()[1]));

  if (pCurve->getChannels().size() >= 3)
    {
      mpObjectZ = dynamic_cast<const CCopasiObject*>(pDataModel->getObject(pCurve->getChannels()[2]));

      if ((mpObjectZ->getObjectDisplayName() == "(CN)Root") && mpObjectY)
        mpObjectZ = mpObjectY;  // as long as we haven't a second Y-axis chooser, this has to suffice.
    }

  if (mpObjectX)
    mpEditX->setText(FROM_UTF8(mpObjectX->getObjectDisplayName()));
  else
    mpEditX->clear();

  if (mpObjectY)
    mpEditY->setText(FROM_UTF8(mpObjectY->getObjectDisplayName()));
  else
    mpEditY->clear();

  if (mpObjectZ)
    mpEditZ->setText(FROM_UTF8(mpObjectZ->getObjectDisplayName()));
  else
    mpEditZ->clear();

  CPlotItem* pItem = const_cast<CPlotItem*>(pCurve);

  mpLogZ->setChecked(*pItem->assertParameter("logZ", CCopasiParameter::BOOL, false));
  mpBilinear->setChecked(*pItem->assertParameter("bilinear", CCopasiParameter::BOOL, true));
  std::string *contours = pItem->assertParameter("contours", CCopasiParameter::STRING, std::string(""));
  mpContours->setText(FROM_UTF8(*contours));
  std::string *maxZ = pItem->assertParameter("maxZ", CCopasiParameter::STRING, std::string(""));
  mpMaxZ->setText(FROM_UTF8(*maxZ));
  std::string *colorMap = pItem->assertParameter("colorMap", CCopasiParameter::STRING, std::string("Default"));
  mpColorMap->setCurrentIndex(mpColorMap->findText(FROM_UTF8(*colorMap)));

  mpCheckBefore->setChecked(pCurve->getActivity() & COutputInterface::BEFORE);
  mpCheckDuring->setChecked(pCurve->getActivity() & COutputInterface::DURING);
  mpCheckAfter->setChecked(pCurve->getActivity() & COutputInterface::AFTER);

  return true;
}
Пример #8
0
bool CopasiPlot::compile(std::vector< CCopasiContainer * > listOfContainer,
                         const CCopasiDataModel* pDataModel)
{
  clearBuffers();

  size_t i, imax;
  size_t j, jmax;

  std::pair< std::set< const CCopasiObject * >::iterator, bool > Inserted;
  std::pair< Activity, size_t > DataIndex;
  std::vector< std::set < const CCopasiObject * > > ActivityObjects;

  ActivityObjects.resize(ActivitySize);

  // Loop over all curves.
  imax = mpPlotSpecification->getItems().size();
  mDataIndex.resize(imax);

  std::vector< std::vector < const CCopasiObject * > >::iterator itX;
  assert(pDataModel != NULL);

  for (i = 0; i < imax; ++i)
    {
      CPlotItem * pItem = mpPlotSpecification->getItems()[i];
      Activity ItemActivity = pItem->getActivity();
      DataIndex.first = ItemActivity;

      // Loop over all channels
      jmax = pItem->getNumChannels();
      mDataIndex[i].resize(jmax);

      for (j = 0; j < jmax; ++j)
        {
          const CCopasiObject* pObj =
            pDataModel->ObjectFromName(listOfContainer, pItem->getChannels()[j]);

          if (pObj)
            mObjects.insert(pObj);
          else
            CCopasiMessage(CCopasiMessage::WARNING, MCCopasiTask + 6,
                           pItem->getChannels()[j].c_str());

          // Remember the actual order for saving the data.
          // Note, we are currently only dealing with 2D curves and histograms.
          // In addition the data is not normalized. The same data column may appear
          // multiple times, e.g. as X value and as Y value for another curve.
          if (j == 0)
            {
              // We have an X value
              for (itX = mSaveCurveObjects.begin(); itX != mSaveCurveObjects.end(); ++itX)
                if (*itX->begin() == pObj) break;

              if (itX == mSaveCurveObjects.end())
                {
                  std::vector < const CCopasiObject * > NewX;
                  NewX.push_back(pObj);

                  mSaveCurveObjects.push_back(NewX);
                  itX = mSaveCurveObjects.end() - 1;

                  setAxisUnits(xBottom, pObj);
                }

              if (pItem->getType() == CPlotItem::histoItem1d)
                mSaveHistogramObjects.push_back(pObj);
            }
          else
            {
              itX->push_back(pObj);
              setAxisUnits(yLeft, pObj);
            }

          Inserted = ActivityObjects[ItemActivity].insert(pObj);

          if (Inserted.second)
            {
              if (ItemActivity & COutputInterface::BEFORE) mHaveBefore = true;

              if (ItemActivity & COutputInterface::DURING) mHaveDuring = true;

              if (ItemActivity & COutputInterface::AFTER) mHaveAfter = true;

              // The insert was successful
              DataIndex.second = ActivityObjects[ItemActivity].size() - 1;

              // Allocate the data buffer
              mData[ItemActivity].push_back(new CVector<double>(1000));

              // Store the pointer to the current object value. (Only if it has a double or integer value
              // and the value pointer actually exists. If not, use a dummy value.)
              void * tmp;

              if ((pObj && (pObj->isValueInt() || pObj->isValueDbl())) && (tmp = pObj->getValuePointer()))
                {
                  mObjectValues[ItemActivity].push_back((C_FLOAT64 *) tmp); //pObj->getValuePointer());
                  mObjectInteger[ItemActivity].push_back(pObj->isValueInt());
                }
              else
                {
                  mObjectValues[ItemActivity].push_back(&MissingValue);
                  mObjectInteger[ItemActivity].push_back(false);
                }

              // Store [curve][channel] to data index
              mDataIndex[i][j] = DataIndex;

              // Store the [Activity][object] to data index.
              mObjectIndex[ItemActivity][pObj] = DataIndex.second;
            }
          else
            {
              // The object already existed we only need to
              // store [curve][channel] to data index.
              DataIndex.second = mObjectIndex[ItemActivity][pObj];
              mDataIndex[i][j] = DataIndex;
            }
        }
    }

  // We need to set the curve data here!
  size_t k = 0;
  C2DPlotCurve ** itCurves = mCurves.array();
  C2DPlotCurve ** endCurves = itCurves + mCurves.size();

  for (; itCurves != endCurves; ++itCurves, ++k)
    {
      std::vector< CVector< double > * > & data = mData[(*itCurves)->getActivity()];

      switch ((*itCurves)->getType())
        {
          case CPlotItem::curve2d:
            (*itCurves)->setData(C2DCurveData(*data[mDataIndex[k][0].second],
                                              *data[mDataIndex[k][1].second],
                                              0));
            break;

          case CPlotItem::bandedGraph:
            (*itCurves)->setData(CBandedGraphData(*data[mDataIndex[k][0].second],
                                                  *data[mDataIndex[k][1].second],
                                                  *data[mDataIndex[k][2].second],
                                                  0));
            break;

          case CPlotItem::histoItem1d:
            (*itCurves)->setData(CHistoCurveData(*data[mDataIndex[k][0].second],
                                                 0,
                                                 mCurves[k]->getIncrement()));

            break;

          default:
            fatalError();
            break;
        }
    }

  mNextPlotTime = CCopasiTimeVariable::getCurrentWallTime();
  mReplotFinished = true;

  return true;
}