COPASI API  4.16.103
Public Slots | Signals | Public Member Functions | Public Attributes | Protected Attributes | Private Slots | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
CopasiPlot Class Reference

#include <CopasiPlot.h>

Inheritance diagram for CopasiPlot:
Inheritance graph
[legend]
Collaboration diagram for CopasiPlot:
Collaboration graph
[legend]

Public Slots

virtual void replot ()
 

Signals

void replotSignal ()
 

Public Member Functions

virtual bool compile (std::vector< CCopasiContainer * > listOfContainer, const CCopasiDataModel *pDataModel)
 
 CopasiPlot (const CPlotSpecification *plotspec, QWidget *parent=NULL)
 
virtual void finish ()
 
bool initFromSpec (const CPlotSpecification *plotspec)
 
virtual void output (const Activity &activity)
 
bool saveData (const std::string &filename)
 
virtual void separate (const Activity &activity)
 
void setCurvesVisibility (const bool &visibility)
 
virtual ~CopasiPlot ()
 
- Public Member Functions inherited from COutputInterface
virtual void close ()
 
 COutputInterface ()
 
 COutputInterface (const COutputInterface &src)
 
virtual const std::set< const
CCopasiObject * > & 
getObjects () const
 
virtual void output (const Activity &)
 
virtual void separate (const Activity &)
 
virtual ~COutputInterface ()
 

Public Attributes

QwtPlotZoomer * mpZoomer
 

Protected Attributes

bool mReplotFinished
 
- Protected Attributes inherited from COutputInterface
std::set< const CCopasiObject * > mObjects
 

Private Slots

void showCurve (QwtPlotItem *item, bool on)
 

Private Member Functions

void clearBuffers ()
 
 CopasiPlot (QWidget *parent=NULL)
 
void resizeCurveData (const size_t &activity)
 
void setAxisUnits (const C_INT32 &index, const CCopasiObject *pObject)
 
void updateCurves (const size_t &activity)
 
void updatePlot ()
 

Private Attributes

std::map< std::string,
C2DPlotCurve * > 
mCurveMap
 
CVector< C2DPlotCurve * > mCurves
 
std::vector< std::vector
< CVector< double > * > > 
mData
 
size_t mDataAfter
 
size_t mDataBefore
 
size_t mDataDuring
 
std::vector< std::vector
< std::pair< Activity, size_t > > > 
mDataIndex
 
std::vector< size_t > mDataSize
 
bool mHaveAfter
 
bool mHaveBefore
 
bool mHaveDuring
 
bool mIgnoreUpdate
 
QMutex mMutex
 
CCopasiTimeVariable mNextPlotTime
 
std::map< Activity, std::map
< const CCopasiObject
*, size_t > > 
mObjectIndex
 
std::vector< std::vector< bool > > mObjectInteger
 
std::vector< std::vector
< const C_FLOAT64 * > > 
mObjectValues
 
const CPlotSpecificationmpPlotSpecification
 
std::vector< std::vector
< const CCopasiObject * > > 
mSaveCurveObjects
 
std::vector< const
CCopasiObject * > 
mSaveHistogramObjects
 

Static Private Attributes

static C_FLOAT64 MissingValue = std::numeric_limits<C_FLOAT64>::quiet_NaN()
 

Additional Inherited Members

- Public Types inherited from COutputInterface
enum  Activity { BEFORE = 0x01, DURING = 0x02, AFTER = 0x04 }
 

Detailed Description

Definition at line 221 of file CopasiPlot.h.

Constructor & Destructor Documentation

CopasiPlot::CopasiPlot ( QWidget *  parent = NULL)
private

Default constructor which may never be called.

Parameters
QWidget*parent (default: NULL)

Definition at line 762 of file CopasiPlot.cpp.

762  :
763  QwtPlot(parent),
764  mCurves(0),
765  mCurveMap(),
766  mDataBefore(0),
767  mDataDuring(0),
768  mDataAfter(0),
769  mHaveBefore(false),
770  mHaveDuring(false),
771  mHaveAfter(false),
772  mpPlotSpecification(NULL),
773  mNextPlotTime(),
774  mIgnoreUpdate(false),
775  mpZoomer(NULL),
776  mReplotFinished(false)
777 {}
size_t mDataAfter
Definition: CopasiPlot.h:416
bool mHaveBefore
Definition: CopasiPlot.h:422
const CPlotSpecification * mpPlotSpecification
Definition: CopasiPlot.h:439
std::map< std::string, C2DPlotCurve * > mCurveMap
Definition: CopasiPlot.h:391
bool mIgnoreUpdate
Definition: CopasiPlot.h:449
size_t mDataBefore
Definition: CopasiPlot.h:406
bool mHaveDuring
Definition: CopasiPlot.h:428
QwtPlotZoomer * mpZoomer
Definition: CopasiPlot.h:455
CVector< C2DPlotCurve * > mCurves
Definition: CopasiPlot.h:386
bool mReplotFinished
Definition: CopasiPlot.h:458
size_t mDataDuring
Definition: CopasiPlot.h:411
bool mHaveAfter
Definition: CopasiPlot.h:434
CCopasiTimeVariable mNextPlotTime
Definition: CopasiPlot.h:444
CopasiPlot::CopasiPlot ( const CPlotSpecification plotspec,
QWidget *  parent = NULL 
)

Specific constructor

Parameters
constCPlotSpecification* plotspec
QWidget*parent (default: NULL)

Definition at line 779 of file CopasiPlot.cpp.

References ActivitySize, initFromSpec(), mData, mDataIndex, mDataSize, mObjectInteger, mObjectValues, mpZoomer, replot(), replotSignal(), and showCurve().

779  :
780  QwtPlot(parent),
781  mCurves(0),
782  mCurveMap(),
783  mDataBefore(0),
784  mDataDuring(0),
785  mDataAfter(0),
786  mHaveBefore(false),
787  mHaveDuring(false),
788  mHaveAfter(false),
789  mpPlotSpecification(NULL),
790  mNextPlotTime(),
791  mIgnoreUpdate(false),
792  mpZoomer(NULL),
793  mReplotFinished(false)
794 {
795  QwtLegend *legend = new QwtLegend;
796  legend->setItemMode(QwtLegend::CheckableItem);
797 
798  // whole legend can not be displayed at bottom on DARWIN
799  // maybe a Qwt bug ?!?
800 #ifdef Darwin
801  insertLegend(legend, QwtPlot::TopLegend);
802 #else
803  insertLegend(legend, QwtPlot::BottomLegend);
804 #endif
805 
806  // Set up the zoom facility
807  mpZoomer = new ScrollZoomer(canvas());
808  mpZoomer->setRubberBandPen(QColor(Qt::black));
809  mpZoomer->setTrackerPen(QColor(Qt::black));
810  mpZoomer->setTrackerMode(QwtPicker::AlwaysOn);
811  mpZoomer->setTrackerFont(this->font());
812 
813  // white background better for printing...
814  setCanvasBackground(Qt::white);
815 
816  // setTitle(FROM_UTF8(plotspec->getTitle()));
817  setCanvasLineWidth(0);
818 
819  canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, true);
820 
821  connect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)),
822  SLOT(showCurve(QwtPlotItem *, bool)));
823 
824  // Size the vectors to be able to store information for all activities.
825  mData.resize(ActivitySize);
826  mObjectValues.resize(ActivitySize);
828  mDataSize.resize(ActivitySize);
829  mDataIndex.clear();
830 
831  // Initialize from the plot specification
832  initFromSpec(plotspec);
833  connect(this, SIGNAL(replotSignal()), this, SLOT(replot()));
834 }
std::vector< size_t > mDataSize
Definition: CopasiPlot.h:370
size_t mDataAfter
Definition: CopasiPlot.h:416
bool mHaveBefore
Definition: CopasiPlot.h:422
const CPlotSpecification * mpPlotSpecification
Definition: CopasiPlot.h:439
std::map< std::string, C2DPlotCurve * > mCurveMap
Definition: CopasiPlot.h:391
bool mIgnoreUpdate
Definition: CopasiPlot.h:449
size_t mDataBefore
Definition: CopasiPlot.h:406
std::vector< std::vector< bool > > mObjectInteger
Definition: CopasiPlot.h:354
virtual void replot()
bool mHaveDuring
Definition: CopasiPlot.h:428
#define ActivitySize
Definition: CopasiPlot.cpp:40
std::vector< std::vector< std::pair< Activity, size_t > > > mDataIndex
Definition: CopasiPlot.h:375
QwtPlotZoomer * mpZoomer
Definition: CopasiPlot.h:455
std::vector< std::vector< const C_FLOAT64 * > > mObjectValues
Definition: CopasiPlot.h:349
CVector< C2DPlotCurve * > mCurves
Definition: CopasiPlot.h:386
std::vector< std::vector< CVector< double > * > > mData
Definition: CopasiPlot.h:344
void replotSignal()
void showCurve(QwtPlotItem *item, bool on)
bool mReplotFinished
Definition: CopasiPlot.h:458
size_t mDataDuring
Definition: CopasiPlot.h:411
bool initFromSpec(const CPlotSpecification *plotspec)
Definition: CopasiPlot.cpp:836
bool mHaveAfter
Definition: CopasiPlot.h:434
CCopasiTimeVariable mNextPlotTime
Definition: CopasiPlot.h:444
CopasiPlot::~CopasiPlot ( )
virtual

Destructor

Definition at line 1388 of file CopasiPlot.cpp.

References clearBuffers().

1389 {
1390  clearBuffers();
1391 }
void clearBuffers()

Member Function Documentation

void CopasiPlot::clearBuffers ( )
private

Clear all allocate buffers and set reset values

Definition at line 1675 of file CopasiPlot.cpp.

References ActivitySize, mData, mDataAfter, mDataBefore, mDataDuring, mDataIndex, mDataSize, mHaveAfter, mHaveBefore, mHaveDuring, mObjectIndex, mObjectInteger, COutputInterface::mObjects, mObjectValues, mSaveCurveObjects, and mSaveHistogramObjects.

Referenced by compile(), and ~CopasiPlot().

1676 {
1677  mObjects.clear();
1678 
1679  size_t Activity;
1680  size_t i, imax;
1681 
1682  for (Activity = 0; Activity < ActivitySize; Activity++)
1683  {
1684  std::vector< CVector< double > * > & data = mData[Activity];
1685 
1686  // Delete each QMemArray
1687  for (i = 0, imax = data.size(); i < imax; i++)
1688  if (data[i] != NULL) delete data[i];
1689 
1690  data.clear();
1691 
1692  mObjectValues[Activity].clear();
1693  mObjectInteger[Activity].clear();
1694  mDataSize[Activity] = 0;
1695  }
1696 
1697  mDataIndex.clear();
1698  mObjectIndex.clear();
1699 
1700  mSaveCurveObjects.clear();
1701  mSaveHistogramObjects.clear();
1702 
1703  mDataBefore = 0;
1704  mDataDuring = 0;
1705  mDataAfter = 0;
1706 
1707  mHaveBefore = false;
1708  mHaveDuring = false;
1709  mHaveAfter = false;
1710 }
std::vector< size_t > mDataSize
Definition: CopasiPlot.h:370
size_t mDataAfter
Definition: CopasiPlot.h:416
bool mHaveBefore
Definition: CopasiPlot.h:422
std::vector< std::vector< const CCopasiObject * > > mSaveCurveObjects
Definition: CopasiPlot.h:360
size_t mDataBefore
Definition: CopasiPlot.h:406
std::vector< std::vector< bool > > mObjectInteger
Definition: CopasiPlot.h:354
bool mHaveDuring
Definition: CopasiPlot.h:428
#define ActivitySize
Definition: CopasiPlot.cpp:40
std::vector< std::vector< std::pair< Activity, size_t > > > mDataIndex
Definition: CopasiPlot.h:375
std::map< Activity, std::map< const CCopasiObject *, size_t > > mObjectIndex
Definition: CopasiPlot.h:381
std::vector< std::vector< const C_FLOAT64 * > > mObjectValues
Definition: CopasiPlot.h:349
std::vector< std::vector< CVector< double > * > > mData
Definition: CopasiPlot.h:344
std::set< const CCopasiObject * > mObjects
std::vector< const CCopasiObject * > mSaveHistogramObjects
Definition: CopasiPlot.h:365
size_t mDataDuring
Definition: CopasiPlot.h:411
bool mHaveAfter
Definition: CopasiPlot.h:434
bool CopasiPlot::compile ( std::vector< CCopasiContainer * >  listOfContainer,
const CCopasiDataModel pDataModel 
)
virtual

compile the object list from name vector

Parameters
std::vector<CCopasiContainer * > listOfContainer
constCCopasiDataModel* pDataModel
Returns
bool success

Reimplemented from COutputInterface.

Definition at line 1035 of file CopasiPlot.cpp.

References ActivitySize, COutputInterface::AFTER, CVectorCore< CType >::array(), CPlotItem::bandedGraph, COutputInterface::BEFORE, C_FLOAT64, clearBuffers(), CPlotItem::curve2d, COutputInterface::DURING, fatalError, CPlotItem::getActivity(), CPlotItem::getChannels(), CCopasiTimeVariable::getCurrentWallTime(), CPlotSpecification::getItems(), CPlotItem::getNumChannels(), CPlotItem::getType(), CCopasiObject::getValuePointer(), CPlotItem::histoItem1d, CCopasiObject::isValueDbl(), CCopasiObject::isValueInt(), MCCopasiTask, mCurves, mData, mDataIndex, mHaveAfter, mHaveBefore, mHaveDuring, MissingValue, mNextPlotTime, mObjectIndex, mObjectInteger, COutputInterface::mObjects, mObjectValues, mpPlotSpecification, mReplotFinished, mSaveCurveObjects, mSaveHistogramObjects, CCopasiDataModel::ObjectFromName(), setAxisUnits(), CVectorCore< CType >::size(), CCopasiVector< T >::size(), and CCopasiMessage::WARNING.

Referenced by PlotWindow::compile().

1037 {
1038  clearBuffers();
1039 
1040  size_t i, imax;
1041  size_t j, jmax;
1042 
1043  std::pair< std::set< const CCopasiObject * >::iterator, bool > Inserted;
1044  std::pair< Activity, size_t > DataIndex;
1045  std::vector< std::set < const CCopasiObject * > > ActivityObjects;
1046 
1047  ActivityObjects.resize(ActivitySize);
1048 
1049  // Loop over all curves.
1050  imax = mpPlotSpecification->getItems().size();
1051  mDataIndex.resize(imax);
1052 
1053  std::vector< std::vector < const CCopasiObject * > >::iterator itX;
1054  assert(pDataModel != NULL);
1055 
1056  for (i = 0; i < imax; ++i)
1057  {
1058  CPlotItem * pItem = mpPlotSpecification->getItems()[i];
1059  Activity ItemActivity = pItem->getActivity();
1060  DataIndex.first = ItemActivity;
1061 
1062  // Loop over all channels
1063  jmax = pItem->getNumChannels();
1064  mDataIndex[i].resize(jmax);
1065 
1066  for (j = 0; j < jmax; ++j)
1067  {
1068  const CCopasiObject* pObj =
1069  pDataModel->ObjectFromName(listOfContainer, pItem->getChannels()[j]);
1070 
1071  if (pObj)
1072  mObjects.insert(pObj);
1073  else
1075  pItem->getChannels()[j].c_str());
1076 
1077  // Remember the actual order for saving the data.
1078  // Note, we are currently only dealing with 2D curves and histograms.
1079  // In addition the data is not normalized. The same data column may appear
1080  // multiple times, e.g. as X value and as Y value for another curve.
1081  if (j == 0)
1082  {
1083  // We have an X value
1084  for (itX = mSaveCurveObjects.begin(); itX != mSaveCurveObjects.end(); ++itX)
1085  if (*itX->begin() == pObj) break;
1086 
1087  if (itX == mSaveCurveObjects.end())
1088  {
1089  std::vector < const CCopasiObject * > NewX;
1090  NewX.push_back(pObj);
1091 
1092  mSaveCurveObjects.push_back(NewX);
1093  itX = mSaveCurveObjects.end() - 1;
1094 
1095  setAxisUnits(xBottom, pObj);
1096  }
1097 
1098  if (pItem->getType() == CPlotItem::histoItem1d)
1099  mSaveHistogramObjects.push_back(pObj);
1100  }
1101  else
1102  {
1103  itX->push_back(pObj);
1104  setAxisUnits(yLeft, pObj);
1105  }
1106 
1107  Inserted = ActivityObjects[ItemActivity].insert(pObj);
1108 
1109  if (Inserted.second)
1110  {
1111  if (ItemActivity & COutputInterface::BEFORE) mHaveBefore = true;
1112 
1113  if (ItemActivity & COutputInterface::DURING) mHaveDuring = true;
1114 
1115  if (ItemActivity & COutputInterface::AFTER) mHaveAfter = true;
1116 
1117  // The insert was successful
1118  DataIndex.second = ActivityObjects[ItemActivity].size() - 1;
1119 
1120  // Allocate the data buffer
1121  mData[ItemActivity].push_back(new CVector<double>(1000));
1122 
1123  // Store the pointer to the current object value. (Only if it has a double or integer value
1124  // and the value pointer actually exists. If not, use a dummy value.)
1125  void * tmp;
1126 
1127  if ((pObj && (pObj->isValueInt() || pObj->isValueDbl())) && (tmp = pObj->getValuePointer()))
1128  {
1129  mObjectValues[ItemActivity].push_back((C_FLOAT64 *) tmp); //pObj->getValuePointer());
1130  mObjectInteger[ItemActivity].push_back(pObj->isValueInt());
1131  }
1132  else
1133  {
1134  mObjectValues[ItemActivity].push_back(&MissingValue);
1135  mObjectInteger[ItemActivity].push_back(false);
1136  }
1137 
1138  // Store [curve][channel] to data index
1139  mDataIndex[i][j] = DataIndex;
1140 
1141  // Store the [Activity][object] to data index.
1142  mObjectIndex[ItemActivity][pObj] = DataIndex.second;
1143  }
1144  else
1145  {
1146  // The object already existed we only need to
1147  // store [curve][channel] to data index.
1148  DataIndex.second = mObjectIndex[ItemActivity][pObj];
1149  mDataIndex[i][j] = DataIndex;
1150  }
1151  }
1152  }
1153 
1154  // We need to set the curve data here!
1155  size_t k = 0;
1156  C2DPlotCurve ** itCurves = mCurves.array();
1157  C2DPlotCurve ** endCurves = itCurves + mCurves.size();
1158 
1159  for (; itCurves != endCurves; ++itCurves, ++k)
1160  {
1161  std::vector< CVector< double > * > & data = mData[(*itCurves)->getActivity()];
1162 
1163  switch ((*itCurves)->getType())
1164  {
1165  case CPlotItem::curve2d:
1166  (*itCurves)->setData(C2DCurveData(*data[mDataIndex[k][0].second],
1167  *data[mDataIndex[k][1].second],
1168  0));
1169  break;
1170 
1172  (*itCurves)->setData(CBandedGraphData(*data[mDataIndex[k][0].second],
1173  *data[mDataIndex[k][1].second],
1174  *data[mDataIndex[k][2].second],
1175  0));
1176  break;
1177 
1179  (*itCurves)->setData(CHistoCurveData(*data[mDataIndex[k][0].second],
1180  0,
1181  mCurves[k]->getIncrement()));
1182 
1183  break;
1184 
1185  default:
1186  fatalError();
1187  break;
1188  }
1189  }
1190 
1192  mReplotFinished = true;
1193 
1194  return true;
1195 }
bool isValueInt() const
static C_FLOAT64 MissingValue
Definition: CopasiPlot.h:334
bool mHaveBefore
Definition: CopasiPlot.h:422
const CPlotSpecification * mpPlotSpecification
Definition: CopasiPlot.h:439
virtual size_t size() const
#define fatalError()
std::vector< CPlotDataChannelSpec > & getChannels()
Definition: CPlotItem.cpp:214
size_t getNumChannels() const
Definition: CPlotItem.cpp:220
std::vector< std::vector< const CCopasiObject * > > mSaveCurveObjects
Definition: CopasiPlot.h:360
std::vector< std::vector< bool > > mObjectInteger
Definition: CopasiPlot.h:354
bool mHaveDuring
Definition: CopasiPlot.h:428
#define MCCopasiTask
void setAxisUnits(const C_INT32 &index, const CCopasiObject *pObject)
#define ActivitySize
Definition: CopasiPlot.cpp:40
std::vector< std::vector< std::pair< Activity, size_t > > > mDataIndex
Definition: CopasiPlot.h:375
std::map< Activity, std::map< const CCopasiObject *, size_t > > mObjectIndex
Definition: CopasiPlot.h:381
std::vector< std::vector< const C_FLOAT64 * > > mObjectValues
Definition: CopasiPlot.h:349
const CPlotItem::Type & getType() const
Definition: CPlotItem.cpp:158
static CCopasiTimeVariable getCurrentWallTime()
Definition: CopasiTime.cpp:160
CVector< C2DPlotCurve * > mCurves
Definition: CopasiPlot.h:386
std::vector< std::vector< CVector< double > * > > mData
Definition: CopasiPlot.h:344
const COutputInterface::Activity & getActivity() const
Definition: CPlotItem.cpp:179
void clearBuffers()
std::set< const CCopasiObject * > mObjects
std::vector< const CCopasiObject * > mSaveHistogramObjects
Definition: CopasiPlot.h:365
size_t size() const
Definition: CVector.h:100
bool mReplotFinished
Definition: CopasiPlot.h:458
const CCopasiVector< CPlotItem > & getItems() const
#define C_FLOAT64
Definition: copasi.h:92
CType * array()
Definition: CVector.h:139
bool isValueDbl() const
virtual void * getValuePointer() const
bool mHaveAfter
Definition: CopasiPlot.h:434
CCopasiObject * ObjectFromName(const std::vector< CCopasiContainer * > &listOfContainer, const CCopasiObjectName &CN) const
CCopasiTimeVariable mNextPlotTime
Definition: CopasiPlot.h:444
void CopasiPlot::finish ( )
virtual

Finish the output

Reimplemented from COutputInterface.

Definition at line 1270 of file CopasiPlot.cpp.

References mNextPlotTime, mpZoomer, and replot().

Referenced by PlotWindow::finish().

1271 {
1272  // We need to force a replot, i.e., the next mNextPlotTime should be in the past.
1273  mNextPlotTime = 0;
1274  replot();
1275 
1276  if (mpZoomer)
1277  {
1278  mpZoomer->setEnabled(true);
1279  mpZoomer->setZoomBase();
1280  }
1281 }
virtual void replot()
QwtPlotZoomer * mpZoomer
Definition: CopasiPlot.h:455
CCopasiTimeVariable mNextPlotTime
Definition: CopasiPlot.h:444
bool CopasiPlot::initFromSpec ( const CPlotSpecification plotspec)

Initialize the the plot from the specification

Parameters
constCPlotSpecification* plotspec

Definition at line 836 of file CopasiPlot.cpp.

References CVectorCore< CType >::array(), CPlotItem::bandedGraph, CCopasiVector< T >::begin(), C_FLOAT64, C_INT32, CPlotItem::curve2d, CCopasiVector< T >::end(), FROM_UTF8, CQPlotColors::getColor(), CPlotSpecification::getItems(), CPlotItem::getTitle(), C2DPlotCurve::getType(), CPlotItem::histoItem1d, CPlotSpecification::isLogX(), CPlotSpecification::isLogY(), mCurveMap, mCurves, mIgnoreUpdate, mMutex, mpPlotSpecification, mpZoomer, pdelete, CVector< CType >::resize(), C2DPlotCurve::setIncrement(), showCurve(), and CCopasiVector< T >::size().

Referenced by CopasiPlot(), and PlotWindow::initFromSpec().

837 {
838  mIgnoreUpdate = true;
839  mpPlotSpecification = plotspec;
840 
841  if (mpZoomer) mpZoomer->setEnabled(false);
842 
843  // size_t k, kmax = mpPlotSpecification->getItems().size();
844 
845  setTitle(FROM_UTF8(mpPlotSpecification->getTitle()));
846 
848  mCurves = NULL;
849 
850  std::map< std::string, C2DPlotCurve * >::iterator found;
851 
854 
856  Visible = true;
857  bool * pVisible = Visible.array();
858 
859  for (; itPlotItem != endPlotItem; ++itPlotItem, ++pVisible)
860  {
861  // Qwt does not like it to reuse the curve as this may lead to access
862  // violation. We therefore delete the curves but remember their visibility.
863  if ((found = mCurveMap.find((*itPlotItem)->CCopasiParameter::getKey())) != mCurveMap.end())
864  {
865  *pVisible = found->second->isVisible();
866  }
867  }
868 
869  // Remove unused curves if definition has changed
870  std::map< std::string, C2DPlotCurve * >::iterator it = mCurveMap.begin();
871  std::map< std::string, C2DPlotCurve * >::iterator end = mCurveMap.end();
872 
873  for (; it != end; ++it)
874  pdelete(it->second);
875 
876  mCurveMap.clear();
877 
878  itPlotItem = mpPlotSpecification->getItems().begin();
879  pVisible = Visible.array();
880  C2DPlotCurve ** ppCurve = mCurves.array();
881  unsigned long int k = 0;
882  bool needLeft = false;
883  bool needRight = false;
884 
885  for (; itPlotItem != endPlotItem; ++itPlotItem, ++pVisible, ++ppCurve, ++k)
886  {
887  // set up the curve
888  C2DPlotCurve * pCurve = new C2DPlotCurve(&mMutex,
889  (*itPlotItem)->getType(),
890  (*itPlotItem)->getActivity(),
891  FROM_UTF8((*itPlotItem)->getTitle()));
892  *ppCurve = pCurve;
893 
894  mCurveMap[(*itPlotItem)->CCopasiParameter::getKey()] = pCurve;
895 
896  //color handling should be similar for different curve types
897  QColor color;
898 
899  if (pCurve->getType() == CPlotItem::curve2d
900  || pCurve->getType() == CPlotItem::histoItem1d
901  || pCurve->getType() == CPlotItem::bandedGraph)
902  {
903  std::string colorstr = *(*itPlotItem)->getValue("Color").pSTRING;
904  color = CQPlotColors::getColor(colorstr, k);
905  }
906 
907  pCurve->setPen(color);
908  pCurve->attach(this);
909 
910  showCurve(pCurve, *pVisible);
911 
912  if (pCurve->getType() == CPlotItem::curve2d
913  || pCurve->getType() == CPlotItem::bandedGraph)
914  {
915  needLeft = true;
916  pCurve->setRenderHint(QwtPlotItem::RenderAntialiased);
917 
918  unsigned C_INT32 linetype = *(*itPlotItem)->getValue("Line type").pUINT;
919 
920  if (linetype == 0 //line
921  || linetype == 3) //line+symbols
922  {
923  pCurve->setStyle(QwtPlotCurve::Lines);
924  unsigned C_INT32 linesubtype = *(*itPlotItem)->getValue("Line subtype").pUINT;
925  C_FLOAT64 width = *(*itPlotItem)->getValue("Line width").pUDOUBLE;
926 
927  switch (linesubtype) //symbol type
928  {
929  case 1:
930  pCurve->setPen(QPen(QBrush(color), width, Qt::DotLine, Qt::FlatCap));
931  break;
932 
933  case 2:
934  pCurve->setPen(QPen(QBrush(color), width, Qt::DashLine));
935  break;
936 
937  case 3:
938  pCurve->setPen(QPen(QBrush(color), width, Qt::DashDotLine));
939  break;
940 
941  case 4:
942  pCurve->setPen(QPen(QBrush(color), width, Qt::DashDotDotLine));
943  break;
944 
945  case 0:
946  default:
947  pCurve->setPen(QPen(QBrush(color), width, Qt::SolidLine));
948  break;
949  }
950  }
951 
952  if (linetype == 1) //points
953  {
954  C_FLOAT64 width = *(*itPlotItem)->getValue("Line width").pUDOUBLE;
955  pCurve->setPen(QPen(color, width, Qt::SolidLine, Qt::RoundCap));
956  pCurve->setStyle(QwtPlotCurve::Dots);
957  }
958 
959  if (linetype == 2) //only symbols
960  {
961  pCurve->setStyle(QwtPlotCurve::NoCurve);
962  }
963 
964  if (linetype == 2 //symbols
965  || linetype == 3) //line+symbols
966  {
967  unsigned C_INT32 symbolsubtype = *(*itPlotItem)->getValue("Symbol subtype").pUINT;
968 
969  switch (symbolsubtype) //symbol type
970  {
971  case 1:
972  pCurve->setSymbol(QwtSymbol(QwtSymbol::Cross, QBrush(), QPen(QBrush(color), 2), QSize(7, 7)));
973  break;
974 
975  case 2:
976  pCurve->setSymbol(QwtSymbol(QwtSymbol::Ellipse, QBrush(), QPen(QBrush(color), 1), QSize(8, 8)));
977  break;
978 
979  case 0:
980  default:
981  pCurve->setSymbol(QwtSymbol(QwtSymbol::Cross, QBrush(color), QPen(QBrush(color), 1), QSize(5, 5)));
982  break;
983  }
984  }
985  } //2d curves and banded graphs
986 
987  if (pCurve->getType() == CPlotItem::bandedGraph)
988  {
989  //set fill color
990  QColor c = color;
991  c.setAlpha(64);
992  pCurve->setBrush(c);
993  }
994 
995  if (pCurve->getType() == CPlotItem::histoItem1d)
996  {
997  pCurve->setIncrement(*(*itPlotItem)->getValue("increment").pDOUBLE);
998 
999  pCurve->setStyle(QwtPlotCurve::Steps);
1000  pCurve->setYAxis(QwtPlot::yRight);
1001  pCurve->setCurveAttribute(QwtPlotCurve::Inverted);
1002 
1003  needRight = true;
1004  }
1005  }
1006 
1007  if (plotspec->isLogX())
1008  setAxisScaleEngine(xBottom, new QwtLog10ScaleEngine());
1009  else
1010  setAxisScaleEngine(xBottom, new QwtLinearScaleEngine());
1011 
1012  setAxisAutoScale(xBottom);
1013 
1014  if (plotspec->isLogY())
1015  setAxisScaleEngine(yLeft, new QwtLog10ScaleEngine());
1016  else
1017  setAxisScaleEngine(yLeft, new QwtLinearScaleEngine());
1018 
1019  setAxisAutoScale(yLeft);
1020 
1021  enableAxis(yLeft, needLeft);
1022 
1023  if (needRight)
1024  {
1025  setAxisScaleEngine(yRight, new QwtLinearScaleEngine());
1026  setAxisTitle(yRight, "Percent %");
1027  enableAxis(yRight);
1028  }
1029 
1030  mIgnoreUpdate = false;
1031 
1032  return true; //TODO really check!
1033 }
static QColor getColor(std::string colorstr, size_t colorindex)
#define pdelete(p)
Definition: copasi.h:215
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
void setIncrement(const C_FLOAT64 &increment)
Definition: CopasiPlot.cpp:647
const CPlotSpecification * mpPlotSpecification
Definition: CopasiPlot.h:439
virtual size_t size() const
std::map< std::string, C2DPlotCurve * > mCurveMap
Definition: CopasiPlot.h:391
iterator begin()
bool mIgnoreUpdate
Definition: CopasiPlot.h:449
void resize(size_t size, const bool &copy=false)
Definition: CVector.h:301
#define C_INT32
Definition: copasi.h:90
const CPlotItem::Type & getType() const
Definition: CopasiPlot.cpp:657
iterator end()
QMutex mMutex
Definition: CopasiPlot.h:339
QwtPlotZoomer * mpZoomer
Definition: CopasiPlot.h:455
CVector< C2DPlotCurve * > mCurves
Definition: CopasiPlot.h:386
void showCurve(QwtPlotItem *item, bool on)
const CCopasiVector< CPlotItem > & getItems() const
#define C_FLOAT64
Definition: copasi.h:92
CType * array()
Definition: CVector.h:139
const std::string & getTitle() const
Definition: CPlotItem.cpp:228
void CopasiPlot::output ( const Activity activity)
virtual

Perform an output event for the current activity

Parameters
constActivity & activity

Definition at line 1197 of file CopasiPlot.cpp.

References ActivitySize, COutputInterface::AFTER, COutputInterface::BEFORE, C_INT32, COutputInterface::DURING, mData, mDataAfter, mDataBefore, mDataDuring, mDataSize, mHaveAfter, mHaveBefore, mHaveDuring, mObjectInteger, mObjectValues, resizeCurveData(), and updatePlot().

Referenced by PlotWindow::output().

1198 {
1199  size_t i, imax;
1200  C_INT32 ItemActivity;
1201 
1202  if (mHaveBefore && (activity == COutputInterface::BEFORE)) mDataBefore++;
1203  else if (mHaveDuring && (activity == COutputInterface::DURING)) mDataDuring++;
1204  else if (mHaveAfter && (activity == COutputInterface::AFTER)) mDataAfter++;
1205 
1206  for (ItemActivity = 0; ItemActivity < ActivitySize; ItemActivity++)
1207  if ((ItemActivity & activity) && mData[ItemActivity].size())
1208  {
1209  std::vector< CVector< double > * > & data = mData[ItemActivity];
1210  size_t & ndata = mDataSize[ItemActivity];
1211 
1212  if ((imax = data.size()) != 0)
1213  {
1214  if (ndata >= data[0]->size())
1215  {
1216  resizeCurveData(ItemActivity);
1217  }
1218 
1219  //the data that needs to be stored internally:
1220  for (i = 0; i < imax; ++i)
1221  if (mObjectInteger[ItemActivity][i])
1222  (*data[i])[ndata] = *(C_INT32 *)mObjectValues[ItemActivity][i];
1223  else
1224  (*data[i])[ndata] = *mObjectValues[ItemActivity][i];
1225 
1226  ++ndata;
1227  }
1228  }
1229 
1230  updatePlot();
1231 }
std::vector< size_t > mDataSize
Definition: CopasiPlot.h:370
void resizeCurveData(const size_t &activity)
size_t mDataAfter
Definition: CopasiPlot.h:416
bool mHaveBefore
Definition: CopasiPlot.h:422
size_t mDataBefore
Definition: CopasiPlot.h:406
#define C_INT32
Definition: copasi.h:90
std::vector< std::vector< bool > > mObjectInteger
Definition: CopasiPlot.h:354
void updatePlot()
bool mHaveDuring
Definition: CopasiPlot.h:428
#define ActivitySize
Definition: CopasiPlot.cpp:40
std::vector< std::vector< const C_FLOAT64 * > > mObjectValues
Definition: CopasiPlot.h:349
std::vector< std::vector< CVector< double > * > > mData
Definition: CopasiPlot.h:344
size_t mDataDuring
Definition: CopasiPlot.h:411
bool mHaveAfter
Definition: CopasiPlot.h:434
void CopasiPlot::replot ( )
virtualslot

Definition at line 1726 of file CopasiPlot.cpp.

References C_INVALID_INDEX, CCopasiTimeVariable::getCurrentWallTime(), CCopasiTimeVariable::getMicroSeconds(), mMutex, mNextPlotTime, mReplotFinished, and updateCurves().

Referenced by CopasiPlot(), finish(), setCurvesVisibility(), showCurve(), PlotWindow::toggleLogX(), and PlotWindow::toggleLogY().

1727 {
1729  {
1731 
1732  {
1733  QMutexLocker Locker(&mMutex);
1735  }
1736 
1737  QwtPlot::replot();
1738 
1739  Delta = CCopasiTimeVariable::getCurrentWallTime() - Delta;
1741  }
1742 
1743  mReplotFinished = true;
1744 }
#define C_INVALID_INDEX
Definition: copasi.h:222
void updateCurves(const size_t &activity)
QMutex mMutex
Definition: CopasiPlot.h:339
static CCopasiTimeVariable getCurrentWallTime()
Definition: CopasiTime.cpp:160
bool mReplotFinished
Definition: CopasiPlot.h:458
C_INT64 getMicroSeconds(const bool &bounded=false) const
Definition: CopasiTime.cpp:112
CCopasiTimeVariable mNextPlotTime
Definition: CopasiPlot.h:444
void CopasiPlot::replotSignal ( )
signal

Referenced by CopasiPlot(), and updatePlot().

void CopasiPlot::resizeCurveData ( const size_t &  activity)
private

Resize the curve data

Definition at line 1306 of file CopasiPlot.cpp.

References CVectorCore< CType >::array(), CPlotItem::bandedGraph, CPlotItem::curve2d, fatalError, CPlotItem::histoItem1d, mCurves, mData, mDataIndex, pdelete, and CVectorCore< CType >::size().

Referenced by output(), and separate().

1307 {
1308  std::vector< CVector< double > * > & data = mData[activity];
1309  std::vector< CVector< double > * >::iterator it = data.begin();
1310 
1311  std::vector< CVector< double > * > OldData = data;
1312  std::vector< CVector< double > * >::iterator itOld = OldData.begin();
1313  std::vector< CVector< double > * >::iterator endOld = OldData.end();
1314 
1315  size_t oldSize = (*it)->size();
1316  size_t newSize = 2 * (*it)->size();
1317 
1318  // We must not deallocate the old data since this will create a window of time
1319  // were the GUI thread may access the old location before it is notified.
1320  for (; itOld != endOld; ++itOld, ++it)
1321  {
1322  *it = new CVector< double >(newSize);
1323  memcpy((*it)->array(), (*itOld)->array(), oldSize * sizeof(double));
1324  }
1325 
1326  // Tell the curves that the location of the data has changed
1327  // otherwise repaint events could crash
1328  size_t k = 0;
1329  C2DPlotCurve ** itCurves = mCurves.array();
1330  C2DPlotCurve ** endCurves = itCurves + mCurves.size();
1331 
1332  for (; itCurves != endCurves; ++itCurves, ++k)
1333  {
1334  if ((size_t)(*itCurves)->getActivity() == activity)
1335  {
1336  std::vector< CVector< double > * > & data = mData[activity];
1337 
1338  switch ((*itCurves)->getType())
1339  {
1340  case CPlotItem::curve2d:
1341  (*itCurves)->reallocatedData(data[mDataIndex[k][0].second],
1342  data[mDataIndex[k][1].second]);
1343  break;
1344 
1346  (*itCurves)->reallocatedData(data[mDataIndex[k][0].second],
1347  data[mDataIndex[k][1].second],
1348  data[mDataIndex[k][2].second]);
1349  break;
1350 
1352  (*itCurves)->reallocatedData(data[mDataIndex[k][0].second],
1353  NULL);
1354  break;
1355 
1356  default:
1357  fatalError();
1358  break;
1359  }
1360  }
1361  }
1362 
1363  // It is now save to delete the old data since the GUI thread has been notified.
1364  for (itOld = OldData.begin(); itOld != endOld; ++itOld)
1365  {
1366  pdelete(*itOld);
1367  }
1368 }
#define pdelete(p)
Definition: copasi.h:215
#define fatalError()
std::vector< std::vector< std::pair< Activity, size_t > > > mDataIndex
Definition: CopasiPlot.h:375
CVector< C2DPlotCurve * > mCurves
Definition: CopasiPlot.h:386
std::vector< std::vector< CVector< double > * > > mData
Definition: CopasiPlot.h:344
size_t size() const
Definition: CVector.h:100
CType * array()
Definition: CVector.h:139
bool CopasiPlot::saveData ( const std::string &  filename)

Save tab delimited data to file

Parameters
conststd::string & filename
Returns
bool success

Definition at line 1393 of file CopasiPlot.cpp.

References ActivitySize, COutputInterface::AFTER, CVectorCore< CType >::array(), COutputInterface::BEFORE, C_INT32, COutputInterface::DURING, CLocaleString::fromUtf8(), CPlotItem::histoItem1d, mCurves, mData, mDataAfter, mDataBefore, mDataDuring, mDataSize, MissingValue, mObjectIndex, COutputInterface::mObjects, mSaveCurveObjects, mSaveHistogramObjects, CVectorCore< CType >::size(), CHistoCurveData::size(), CHistoCurveData::x(), and CHistoCurveData::y().

Referenced by PlotWindow::slotSaveData().

1394 {
1395  // No objects.
1396  if (!mObjects.size()) return true;
1397 
1398  // Find out whether we have any data.
1399  C_INT32 ItemActivity;
1400 
1401  for (ItemActivity = 0; ItemActivity < ActivitySize; ItemActivity++)
1402  if (mDataSize[ItemActivity] != 0) break;
1403 
1404  // No data
1405  if (ItemActivity == ActivitySize) return true;
1406 
1407  std::ofstream fs(CLocaleString::fromUtf8(filename).c_str());
1408 
1409  if (!fs.good()) return false;
1410 
1411  // Write the table header
1412  fs << "# ";
1413 
1414  std::vector< std::vector < const CCopasiObject * > >::const_iterator itX;
1415  std::vector< std::vector < const CCopasiObject * > >::const_iterator endX =
1416  mSaveCurveObjects.end();
1417 
1418  std::vector < const CCopasiObject * >::const_iterator it;
1419  std::vector < const CCopasiObject * >::const_iterator end;
1420 
1421  for (itX = mSaveCurveObjects.begin(); itX != endX; ++itX)
1422  for (it = itX->begin(), end = itX->end(); it != end; ++it)
1423  if (*it != NULL)
1424  fs << (*it)->getObjectDisplayName() << "\t";
1425  else
1426  fs << "Not found\t";
1427 
1428  fs << "\n";
1429 
1430  size_t i, imax = mObjects.size();
1431  std::vector< CVector< double > * > Data;
1432  Data.resize(imax);
1433 
1434  std::vector< CVector< double > * >::const_iterator itData;
1435  std::vector< CVector< double > * >::const_iterator endData = Data.end();
1436 
1437  std::vector< size_t > Offset;
1438  std::vector< size_t >::const_iterator itOffset;
1439 
1440  Offset.resize(imax);
1441 
1442  std::map< Activity, std::map< const CCopasiObject *, size_t > >::iterator itActivity;
1443  std::map< const CCopasiObject *, size_t >::iterator itObject;
1444 
1445  if (mDataBefore)
1446  {
1447  for (itX = mSaveCurveObjects.begin(), i = 0; itX != endX; ++itX)
1448  for (it = itX->begin(), end = itX->end(); it != end; ++it, ++i)
1449  {
1450  if ((itActivity = mObjectIndex.find(COutputInterface::BEFORE)) != mObjectIndex.end() &&
1451  (itObject = itActivity->second.find(*it)) != itActivity->second.end())
1452  {
1453  Data[i] = mData[COutputInterface::BEFORE][itObject->second];
1454  continue;
1455  }
1456 
1458  (itObject = itActivity->second.find(*it)) != itActivity->second.end())
1459  {
1460  Data[i] = mData[COutputInterface::BEFORE | COutputInterface::DURING][itObject->second];
1461  continue;
1462  }
1463 
1465  (itObject = itActivity->second.find(*it)) != itActivity->second.end())
1466  {
1467  Data[i] = mData[COutputInterface::BEFORE | COutputInterface::AFTER][itObject->second];
1468  continue;
1469  }
1470 
1472  (itObject = itActivity->second.find(*it)) != itActivity->second.end())
1473  {
1475  continue;
1476  }
1477 
1478  Data[i] = NULL;
1479  }
1480 
1481  for (i = 0; i < mDataBefore; i++)
1482  {
1483  for (itData = Data.begin(); itData != endData; ++itData)
1484  {
1485  if (*itData) fs << (**itData)[i];
1486  else fs << MissingValue;
1487 
1488  fs << "\t";
1489  }
1490 
1491  fs << std::endl;
1492  }
1493  }
1494 
1495  if (mDataDuring)
1496  {
1497  for (itX = mSaveCurveObjects.begin(), i = 0; itX != endX; ++itX)
1498  for (it = itX->begin(), end = itX->end(); it != end; ++it, ++i)
1499  {
1500  if ((itActivity = mObjectIndex.find(COutputInterface::DURING)) != mObjectIndex.end() &&
1501  (itObject = itActivity->second.find(*it)) != itActivity->second.end())
1502  {
1503  Data[i] = mData[COutputInterface::DURING][itObject->second];
1504  Offset[i] = 0;
1505  continue;
1506  }
1507 
1509  (itObject = itActivity->second.find(*it)) != itActivity->second.end())
1510  {
1511  Data[i] = mData[COutputInterface::BEFORE | COutputInterface::DURING][itObject->second];
1512  Offset[i] = mDataBefore;
1513  continue;
1514  }
1515 
1517  (itObject = itActivity->second.find(*it)) != itActivity->second.end())
1518  {
1519  Data[i] = mData[COutputInterface::DURING | COutputInterface::AFTER][itObject->second];
1520  Offset[i] = 0;
1521  continue;
1522  }
1523 
1525  (itObject = itActivity->second.find(*it)) != itActivity->second.end())
1526  {
1528  Offset[i] = mDataBefore;
1529  continue;
1530  }
1531 
1532  Data[i] = NULL;
1533  }
1534 
1535  for (i = 0; i < mDataDuring; i++)
1536  {
1537  for (itData = Data.begin(), itOffset = Offset.begin(); itData != endData; ++itData)
1538  {
1539  if (*itData) fs << (**itData)[i + *itOffset];
1540  else fs << MissingValue;
1541 
1542  fs << "\t";
1543  }
1544 
1545  fs << std::endl;
1546  }
1547  }
1548 
1549  if (mDataAfter)
1550  {
1551  for (itX = mSaveCurveObjects.begin(), i = 0; itX != endX; ++itX)
1552  for (it = itX->begin(), end = itX->end(); it != end; ++it, ++i)
1553  {
1554  if ((itActivity = mObjectIndex.find(COutputInterface::AFTER)) != mObjectIndex.end() &&
1555  (itObject = itActivity->second.find(*it)) != itActivity->second.end())
1556  {
1557  Data[i] = mData[COutputInterface::AFTER][itObject->second];
1558  Offset[i] = 0;
1559  continue;
1560  }
1561 
1563  (itObject = itActivity->second.find(*it)) != itActivity->second.end())
1564  {
1565  Data[i] = mData[COutputInterface::BEFORE | COutputInterface::AFTER][itObject->second];
1566  Offset[i] = mDataBefore;
1567  continue;
1568  }
1569 
1571  (itObject = itActivity->second.find(*it)) != itActivity->second.end())
1572  {
1573  Data[i] = mData[COutputInterface::DURING | COutputInterface::AFTER][itObject->second];
1574  Offset[i] = mDataDuring;
1575  continue;
1576  }
1577 
1579  (itObject = itActivity->second.find(*it)) != itActivity->second.end())
1580  {
1582  Offset[i] = mDataBefore + mDataDuring;
1583  continue;
1584  }
1585 
1586  Data[i] = NULL;
1587  }
1588 
1589  for (i = 0; i < mDataAfter; i++)
1590  {
1591  for (itData = Data.begin(), itOffset = Offset.begin(); itData != endData; ++itData)
1592  {
1593  if (*itData) fs << (**itData)[i + *itOffset];
1594  else fs << MissingValue;
1595 
1596  fs << "\t";
1597  }
1598 
1599  fs << std::endl;
1600  }
1601  }
1602 
1603  bool FirstHistogram = true;
1604  size_t HistogramIndex = 0;
1605 
1606  C2DPlotCurve ** itCurves = mCurves.array();
1607  C2DPlotCurve ** endCurves = itCurves + mCurves.size();
1608 
1609  for (; itCurves != endCurves; ++itCurves)
1610  {
1611  if ((*itCurves)->getType() == CPlotItem::histoItem1d)
1612  {
1613  if (FirstHistogram)
1614  {
1615  fs << "\n# The histograms: \n";
1616  FirstHistogram = false;
1617  }
1618 
1619  if (mSaveHistogramObjects[HistogramIndex] != NULL)
1620  fs << mSaveHistogramObjects[HistogramIndex]->getObjectDisplayName();
1621  else
1622  fs << "Not found";
1623 
1624  fs << std::endl;
1625 
1626  CHistoCurveData * pData = static_cast< CHistoCurveData * >(&(*itCurves)->data());
1627  size_t i, imax = pData->size();
1628 
1629  for (i = 0; i < imax; ++i)
1630  {
1631  fs << pData->x(i) << "\t" << pData->y(i) << "\n";
1632  }
1633  }
1634  }
1635 
1636  fs.close();
1637 
1638  if (!fs.good()) return false;
1639 
1640  return true;
1641 }
std::vector< size_t > mDataSize
Definition: CopasiPlot.h:370
virtual size_t size() const
Definition: CopasiPlot.cpp:474
static C_FLOAT64 MissingValue
Definition: CopasiPlot.h:334
size_t mDataAfter
Definition: CopasiPlot.h:416
virtual double x(size_t i) const
Definition: CopasiPlot.cpp:479
std::vector< std::vector< const CCopasiObject * > > mSaveCurveObjects
Definition: CopasiPlot.h:360
size_t mDataBefore
Definition: CopasiPlot.h:406
#define C_INT32
Definition: copasi.h:90
#define ActivitySize
Definition: CopasiPlot.cpp:40
std::map< Activity, std::map< const CCopasiObject *, size_t > > mObjectIndex
Definition: CopasiPlot.h:381
virtual double y(size_t i) const
Definition: CopasiPlot.cpp:484
CVector< C2DPlotCurve * > mCurves
Definition: CopasiPlot.h:386
std::vector< std::vector< CVector< double > * > > mData
Definition: CopasiPlot.h:344
std::set< const CCopasiObject * > mObjects
std::vector< const CCopasiObject * > mSaveHistogramObjects
Definition: CopasiPlot.h:365
size_t size() const
Definition: CVector.h:100
CType * array()
Definition: CVector.h:139
size_t mDataDuring
Definition: CopasiPlot.h:411
static CLocaleString fromUtf8(const std::string &utf8)
void CopasiPlot::separate ( const Activity activity)
virtual

Introduce an additional separator into the output

Parameters
constActivity & activity

Definition at line 1233 of file CopasiPlot.cpp.

References ActivitySize, COutputInterface::AFTER, COutputInterface::BEFORE, C_INT32, COutputInterface::DURING, mData, mDataAfter, mDataBefore, mDataDuring, mDataSize, mHaveAfter, mHaveBefore, mHaveDuring, MissingValue, resizeCurveData(), and updatePlot().

Referenced by PlotWindow::separate().

1234 {
1235  size_t i, imax;
1236  C_INT32 ItemActivity;
1237 
1238  if (mHaveBefore && (activity == COutputInterface::BEFORE)) mDataBefore++;
1239 
1240  if (mHaveDuring && (activity == COutputInterface::DURING)) mDataDuring++;
1241 
1242  if (mHaveAfter && (activity == COutputInterface::AFTER)) mDataAfter++;
1243 
1244  for (ItemActivity = 0; ItemActivity < ActivitySize; ItemActivity++)
1245  if ((ItemActivity & activity) && mData[ItemActivity].size())
1246  {
1247  std::vector< CVector< double > * > & data = mData[ItemActivity];
1248  size_t & ndata = mDataSize[ItemActivity];
1249 
1250  if ((imax = data.size()) != 0)
1251  {
1252  if (ndata >= data[0]->size())
1253  {
1254  resizeCurveData(ItemActivity);
1255  }
1256 
1257  //the data that needs to be stored internally:
1258  for (i = 0; i < imax; ++i)
1259  (*data[i])[ndata] = MissingValue;
1260 
1261  ++ndata;
1262  }
1263  }
1264 
1265  updatePlot();
1266 
1267  return;
1268 }
std::vector< size_t > mDataSize
Definition: CopasiPlot.h:370
void resizeCurveData(const size_t &activity)
static C_FLOAT64 MissingValue
Definition: CopasiPlot.h:334
size_t mDataAfter
Definition: CopasiPlot.h:416
bool mHaveBefore
Definition: CopasiPlot.h:422
size_t mDataBefore
Definition: CopasiPlot.h:406
#define C_INT32
Definition: copasi.h:90
void updatePlot()
bool mHaveDuring
Definition: CopasiPlot.h:428
#define ActivitySize
Definition: CopasiPlot.cpp:40
std::vector< std::vector< CVector< double > * > > mData
Definition: CopasiPlot.h:344
size_t mDataDuring
Definition: CopasiPlot.h:411
bool mHaveAfter
Definition: CopasiPlot.h:434
void CopasiPlot::setAxisUnits ( const C_INT32 index,
const CCopasiObject pObject 
)
private

Set the units of the indexed axis based on the type of the object.

Parameters
constC_INT32 & index
constCCopasiObject * pObject

Definition at line 1712 of file CopasiPlot.cpp.

References FROM_UTF8, and CCopasiObject::getUnits().

Referenced by compile().

1714 {
1715  if (pObject == NULL) return;
1716 
1717  std::string Units = pObject->getUnits();
1718 
1719  if (Units != "")
1720  setAxisTitle(index, FROM_UTF8(Units));
1721 
1722  return;
1723 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
virtual std::string getUnits() const
void CopasiPlot::setCurvesVisibility ( const bool &  visibility)

Shows or hide all curves depending on whether visibility is false or true

Parameters
constbool & visibility

Definition at line 1656 of file CopasiPlot.cpp.

References mCurveMap, mIgnoreUpdate, and replot().

Referenced by PlotWindow::slotDeselectAll(), and PlotWindow::slotSelectAll().

1657 {
1658  std::map< std::string, C2DPlotCurve * >::iterator it = mCurveMap.begin();
1659  std::map< std::string, C2DPlotCurve * >::iterator end = mCurveMap.end();
1660 
1661  for (; it != end; ++it)
1662  {
1663  it->second->setVisible(visibility);
1664  it->second->setItemAttribute(QwtPlotItem::AutoScale, visibility);
1665  QWidget *w = legend()->find(it->second);
1666 
1667  if (w && w->inherits("QwtLegendItem"))
1668  static_cast< QwtLegendItem * >(w)->setChecked(visibility);
1669  }
1670 
1671  if (!mIgnoreUpdate)
1672  replot();
1673 }
std::map< std::string, C2DPlotCurve * > mCurveMap
Definition: CopasiPlot.h:391
bool mIgnoreUpdate
Definition: CopasiPlot.h:449
virtual void replot()
void CopasiPlot::showCurve ( QwtPlotItem *  item,
bool  on 
)
privateslot

Slot used to turn curves on and of through the legend buttons.

Parameters
QwtPlotItem*item
boolon

Definition at line 1643 of file CopasiPlot.cpp.

References mIgnoreUpdate, and replot().

Referenced by CopasiPlot(), and initFromSpec().

1644 {
1645  item->setVisible(on);
1646  item->setItemAttribute(QwtPlotItem::AutoScale, on);
1647  QWidget *w = legend()->find(item);
1648 
1649  if (w && w->inherits("QwtLegendItem"))
1650  static_cast< QwtLegendItem * >(w)->setChecked(on);
1651 
1652  if (!mIgnoreUpdate)
1653  replot();
1654 }
bool mIgnoreUpdate
Definition: CopasiPlot.h:449
virtual void replot()
void CopasiPlot::updateCurves ( const size_t &  activity)
private

Tell the curves where the data is located. It must be called after reallocating the memory for the curve data.

Definition at line 1283 of file CopasiPlot.cpp.

References ActivitySize, CVectorCore< CType >::array(), C_INT32, C_INVALID_INDEX, mCurves, mDataSize, and CVectorCore< CType >::size().

Referenced by replot().

1284 {
1285  if (activity == C_INVALID_INDEX)
1286  {
1287  C_INT32 ItemActivity;
1288 
1289  for (ItemActivity = 0; ItemActivity < ActivitySize; ItemActivity++)
1290  updateCurves(ItemActivity);
1291 
1292  return;
1293  }
1294 
1295  size_t k = 0;
1296  C2DPlotCurve ** itCurves = mCurves.array();
1297  C2DPlotCurve ** endCurves = itCurves + mCurves.size();
1298 
1299  for (; itCurves != endCurves; ++itCurves, ++k)
1300  if ((size_t)(*itCurves)->getActivity() == activity)
1301  {
1302  (*itCurves)->setDataSize(mDataSize[activity]);
1303  }
1304 }
std::vector< size_t > mDataSize
Definition: CopasiPlot.h:370
#define C_INVALID_INDEX
Definition: copasi.h:222
#define C_INT32
Definition: copasi.h:90
void updateCurves(const size_t &activity)
#define ActivitySize
Definition: CopasiPlot.cpp:40
CVector< C2DPlotCurve * > mCurves
Definition: CopasiPlot.h:386
size_t size() const
Definition: CVector.h:100
CType * array()
Definition: CVector.h:139
void CopasiPlot::updatePlot ( )
private

Redraw the plot

Definition at line 1370 of file CopasiPlot.cpp.

References mReplotFinished, and replotSignal().

Referenced by output(), and separate().

1371 {
1372  if (mReplotFinished)
1373  {
1374  mReplotFinished = false;
1375  emit replotSignal();
1376  }
1377 }
void replotSignal()
bool mReplotFinished
Definition: CopasiPlot.h:458

Member Data Documentation

std::map< std::string, C2DPlotCurve * > CopasiPlot::mCurveMap
private

A map between a specification identified by its key and a curve

Definition at line 391 of file CopasiPlot.h.

Referenced by initFromSpec(), and setCurvesVisibility().

CVector< C2DPlotCurve * > CopasiPlot::mCurves
private

The list of curves

Definition at line 386 of file CopasiPlot.h.

Referenced by compile(), initFromSpec(), resizeCurveData(), saveData(), and updateCurves().

std::vector< std::vector< CVector< double > * > > CopasiPlot::mData
private

Vector that contains pointers to vectors of data in the selected columns.

Definition at line 344 of file CopasiPlot.h.

Referenced by clearBuffers(), compile(), CopasiPlot(), output(), resizeCurveData(), saveData(), and separate().

size_t CopasiPlot::mDataAfter
private

Count of data lines recorded during activity AFTER.

Definition at line 416 of file CopasiPlot.h.

Referenced by clearBuffers(), output(), saveData(), and separate().

size_t CopasiPlot::mDataBefore
private

Vector of the activity of each item (curve) Map of curve to the index to the corresponding histogram. Count of data lines recorded during activity BEFORE.

Definition at line 406 of file CopasiPlot.h.

Referenced by clearBuffers(), output(), saveData(), and separate().

size_t CopasiPlot::mDataDuring
private

Count of data lines recorded during activity DURING.

Definition at line 411 of file CopasiPlot.h.

Referenced by clearBuffers(), output(), saveData(), and separate().

std::vector< std::vector< std::pair < Activity, size_t > > > CopasiPlot::mDataIndex
private

Map curve and channel to index pair indicating where the data is stored.

Definition at line 375 of file CopasiPlot.h.

Referenced by clearBuffers(), compile(), CopasiPlot(), and resizeCurveData().

std::vector< size_t > CopasiPlot::mDataSize
private

Vector of actual data lines in the local buffers

Definition at line 370 of file CopasiPlot.h.

Referenced by clearBuffers(), CopasiPlot(), output(), saveData(), separate(), and updateCurves().

bool CopasiPlot::mHaveAfter
private

Flag indicating whether there are any curves recording data during activity AFTER.

Definition at line 434 of file CopasiPlot.h.

Referenced by clearBuffers(), compile(), output(), and separate().

bool CopasiPlot::mHaveBefore
private

Flag indicating whether there are any curves recording data during activity BEFORE.

Definition at line 422 of file CopasiPlot.h.

Referenced by clearBuffers(), compile(), output(), and separate().

bool CopasiPlot::mHaveDuring
private

Flag indicating whether there are any curves recording data during activity DURING.

Definition at line 428 of file CopasiPlot.h.

Referenced by clearBuffers(), compile(), output(), and separate().

bool CopasiPlot::mIgnoreUpdate
private

Indicates whether redrawing/updating shall be suppressed during initialization.

Definition at line 449 of file CopasiPlot.h.

Referenced by initFromSpec(), setCurvesVisibility(), and showCurve().

C_FLOAT64 CopasiPlot::MissingValue = std::numeric_limits<C_FLOAT64>::quiet_NaN()
staticprivate

The value for missing objects

Definition at line 334 of file CopasiPlot.h.

Referenced by compile(), saveData(), and separate().

QMutex CopasiPlot::mMutex
private

Mutex preventing access to data during reallocation.

Definition at line 339 of file CopasiPlot.h.

Referenced by initFromSpec(), and replot().

CCopasiTimeVariable CopasiPlot::mNextPlotTime
private

The next time a plot update is performed

Definition at line 444 of file CopasiPlot.h.

Referenced by compile(), finish(), and replot().

std::map< Activity, std::map< const CCopasiObject *, size_t > > CopasiPlot::mObjectIndex
private

Map activity and object to index indicating where data is stored within the current activity.

Definition at line 381 of file CopasiPlot.h.

Referenced by clearBuffers(), compile(), and saveData().

std::vector< std::vector< bool > > CopasiPlot::mObjectInteger
private

Vector of bool indicating whether the current object value is integer

Definition at line 354 of file CopasiPlot.h.

Referenced by clearBuffers(), compile(), CopasiPlot(), and output().

std::vector< std::vector< const C_FLOAT64 * > > CopasiPlot::mObjectValues
private

Vector of pointers to the current object values

Definition at line 349 of file CopasiPlot.h.

Referenced by clearBuffers(), compile(), CopasiPlot(), and output().

const CPlotSpecification* CopasiPlot::mpPlotSpecification
private

Pointer to the specification for the plot.

Definition at line 439 of file CopasiPlot.h.

Referenced by compile(), and initFromSpec().

QwtPlotZoomer* CopasiPlot::mpZoomer

Pointer to the zooming engine for the plot.

Definition at line 455 of file CopasiPlot.h.

Referenced by CopasiPlot(), finish(), initFromSpec(), and PlotWindow::slotZoomOut().

bool CopasiPlot::mReplotFinished
protected

Definition at line 458 of file CopasiPlot.h.

Referenced by compile(), replot(), and updatePlot().

std::vector< std::vector < const CCopasiObject * > > CopasiPlot::mSaveCurveObjects
private

The order of 2d curve objects used when the data is saved. The first object in each vector is the object for the X axis.

Definition at line 360 of file CopasiPlot.h.

Referenced by clearBuffers(), compile(), and saveData().

std::vector< const CCopasiObject * > CopasiPlot::mSaveHistogramObjects
private

The order of histogram objects used when the data is saved.

Definition at line 365 of file CopasiPlot.h.

Referenced by clearBuffers(), compile(), and saveData().


The documentation for this class was generated from the following files: