COPASI API  4.16.103
CQGLNetworkPainter.h
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #ifndef CQGLNETWORKPAINTER_H_
16 #define CQGLNETWORKPAINTER_H_
17 
18 #include <QtOpenGL/qgl.h>
19 
20 #ifdef __APPLE__
21 #include "OpenGL/glu.h"
22 #else
23 #include "GL/glu.h"
24 #endif // __APPLE__
25 
26 #include <QtGui/QColor>
27 #include <QtGui/QDialog> // for CQSimpleProgressDialog
28 #include <QtGui/QFont>
29 #include <QtGui/QImage>
30 
31 #include <vector>
32 #include <string>
33 #include <map>
34 #include <set>
35 
36 #include "copasi/layout/CLBase.h"
37 #include "copasi/layout/CLGlyphs.h"
38 #include "copasi/layout/CLCurve.h"
39 
40 #include "copasi/layoutUI/CLabel.h"
41 #include "copasi/layoutUI/CArrow.h"
51 
54 
55 class CLayout;
56 class CQLayoutMainWindow;
57 class QResizeEvent;
58 class QContextMenuEvent;
59 class QAction;
60 class QProgressBar;
61 
62 class CQGLNetworkPainter : public QGLWidget
63 {
64 
65  Q_OBJECT // must include this if you use Qt signals/slots
66 
67 public:
68  CQGLNetworkPainter(const QGLFormat& format, QWidget *parent = 0);
70 
72 
74  C_FLOAT64 getZoomFactor() const;
75 
81 
82  void setGraphSize(const CLPoint & min, const CLPoint & max);
83  const CLPoint& getGraphMin();
84  const CLPoint& getGraphMax();
85  void createGraph(CLayout *lP); // create local data structures
86  void drawGraph(); // create OpenGL display list with graph objects
87  void drawNode(CCompartmentGraphNode &n); // draw comaprtment node as a green rectangle
88  void drawNode(CGraphNode &n);
89  void drawEdge(CGraphCurve &c);
91 
92  bool createDataSets();
93  bool mDataPresentP; // shows, whether time series data has been load before
94  size_t getNumberOfSteps() const;
95  size_t getCurrentStep() const;
96  bool isCircleMode();
97 
98  void setNodeSize(std::string key, C_FLOAT64 val);
99  void setNodeSizeWithoutChangingCurves(std::string key, C_FLOAT64 val);
100 
101  std::string getNodeNameEntry(int i);
102  std::string getNameForNodeKey(std::string key);
103 
104  size_t getNumberOfNodeEntries() {return viewerNodes.size();}
105  CDataEntity* getDataSetAt(size_t stepNumber);
106 
107  void mapLabelsToRectangles();
108  void mapLabelsToCircles();
109 
110  void runAnimation();
111  void showStep(size_t i);
112 
115  void rescaleNode(std::string key, C_FLOAT64 newMin, C_FLOAT64 newMax, CVisParameters::SCALING_MODE scaleMode);
116  void setConstantNodeSizeForAllSteps(std::string key, C_FLOAT64 midValue);
117 
118  void setConstantNodeSize(std::string key, C_FLOAT64 val);
119 
120  void zoomGraph(C_FLOAT64 zoomFactor);
121  QImage getImage();
122 
123  void setItemAnimated(std::string key, bool animatedP);
124 
125  void setFontSizeForLabels(unsigned int fs);
127 
128  void update();
129 
130  void resetView();
131 
132  /**
133  * Calculates the ratio that is needed to fit the diagram on the current viewport
134  * and sets this as the zoom factor.
135  * The new zoom factor is returned.
136  */
137  double fitToScreen();
138 
139  void pauseAnimation();
140 
141  /**
142  * Sets the scaling mode to either global or individual scaling.
143  */
145 
146  /**
147  * New method for creating a bitmap from the animation window.
148  * This method uses QPainter, QImage and QGLFrameBufferObject to draw
149  * into a multisample buffer if availabel and if not, it will be single sample.
150  * This way the implementation should work on more computers.
151  * The image is rendered in tiles of size 128x128 which should be OK for even small
152  * frame buffers and it is a multiple of 2 which is compliant with older versions of OpenGL.
153  *
154  * The methods get the region to be drawn and the size of the final image as parameters.
155  * In addition to that, the user can specify a vectir of frame numbers to be rendered.
156  * If no frame number is given, nothing is rendered.
157  * If a frame number is outside the range of valid frame numbers, the last frame is rendered.
158  * If the rendering was successfull, true is returned, otherwise false is returned.
159  */
160  bool export_bitmap(double x, double y, double width, double height, unsigned int imageWidth, unsigned int imageHeight, const QString& filename, const std::vector<size_t> frames);
161 
162 private slots:
163  void zoomIn();
164  void zoomOut();
165  void setFontSize();
166 
167 public slots:
168  void triggerAnimationStep();
169 
170 signals:
171  void stepChanged(int);
172  void endOfAnimationReached();
173  void signalZoomIn();
174  void signalZoomOut();
175 
176 private:
178  static const float COMPARTMENT_DEPTH;
179  static const float COMPARTMENT_SHADOW_DEPTH;
180  static const float COMPARTMENT_FRAME_DEPTH;
181 
182  static const float SPECIES_DEPTH;
183  static const float SPECIES_SHADOW_DEPTH;
184  static const float SPECIES_FRAME_DEPTH;
185 
186  static const float SPECIESREFERENCE_DEPTH;
187 
188  static const GLfloat MIRROR_X[16];
189  static const GLfloat MIRROR_Y[16];
190 
191  GLfloat mSpeciesColor[4];
192  GLfloat mCompartmentColor[4];
193  GLfloat mShadowColor[4];
195  GLfloat mTextColor[4];
196  GLfloat mFrameColor[4];
200  GLclampf mBackgroundColor[4];
201 
202  // offset values for the shadows
207 
208  // determines if shadows are drawn or not
210 
211  unsigned int mNumCirclePoints;
212  std::vector<std::pair<float, float> > mCirclePoints;
213 
216 
217  C_FLOAT64 mCurrentZoom ; // current zoom factor
221  static const C_INT32 MIN_HEIGHT; // min height for bounding boxes of labels (-> min font pt size)
222 
223  std::vector<std::string> viewerNodes; // contains node keys
224  std::vector<std::string> viewerCompartmentNodes; // contains node keys
225  std::vector<CGraphCurve> viewerCurves; // contains curves defining a reaction (not directly associated with a node)
226  std::vector<CLabel> viewerLabels;
227  std::vector<CGraphCurve> curvesWithArrow;
228 
229  GLuint graphObjList;
231  std::string mFontname;
232  unsigned int mFontsize;
234  QFont mf;
235 
236  std::vector<CDataEntity> mDataSets;
237 
238  std::map<std::string, std::string> keyMap; // maps Copasi SBML object keys to layout node keys
239  std::map<std::string, CGraphNode>nodeMap;
240  std::map<std::string, CCompartmentGraphNode> compartmentNodeMap;
241  std::map<std::string, std::string>labelNodeMap; // maps label keys to node keys
242 
243  std::map<std::string, RGTextureSpec*>labelTextureMap; // maps label texts to texture info
244  std::multimap<std::string, CGraphCurve> nodeCurveMap; // maps mKey of viewer node (CGraphNode, originally from CLMetabGlyph) to curves (stored in viewerCurves) that point to this node)
245  std::multimap<std::string, CArrow> nodeArrowMap; // maps mKey of viewer node (CGraphNode, originally from CLMetabGlyph, to arrows (stored in viewerArrows) that point to thid node)
246 
247  std::set<std::string> setOfConstantMetabolites;
248  std::set<std::string> setOfDisabledMetabolites;
249 
250  void addMetaboliteForAnimation(std::string key);
251  void removeMetaboliteForAnimation(std::string key);
252 
253  void drawColorLegend();
254 
255  size_t stepShown;
256  QTimer *regularTimer;
258 
259  void adaptCurveForRectangles(std::multimap<std::string, CGraphCurve>::iterator it, CLBoundingBox box);
260  void adaptCurveForCircle(std::multimap<std::string, CGraphCurve>::iterator it, CLBoundingBox box);
264  QAction *zoomInAction;
265  QAction *zoomOutAction;
267  void createActions();
268  void zoom(double zoomFactor);
269  void drawStringAt(std::string s, C_FLOAT64 x, C_FLOAT64 y, C_FLOAT64 w, C_FLOAT64 h, QColor bgCol);
270  int round2powN(double d);
271 
272  void RG_drawStringAt(std::string s, C_INT32 x, C_INT32 y, C_INT32 w, C_INT32 h);
273  RGTextureSpec* RG_createTextureForText(const std::string& text, const std::string& fontName, unsigned int fontSize);
274  RGTextureSpec* getTextureForText(const std::string& text, const std::string& fontName, unsigned int fontSize);
275 
277 
278  int getTextWidth(const std::string& text, const std::string& fontName, unsigned int fontSize);
279  int getLabelWindowWidth(int width);
280 
282  void updateEdge(CLLineSegment line);
283  bool checkCurve(CGraphCurve *curve, CGraphCurve curveR, CLBoundingBox box);
284 
287 
288  void printNodeMap();
289  void printAvailableFonts();
290  GLuint textureNames[1];
292 
293  ///flag that indicates whether OpenGL was initialized
295 
296 protected:
297  /**
298  * Calculates a circle with n points.
299  * The points are returned as pairs of x,y values in a vector.
300  * The points are calculated for a circle with diameter 1.
301  */
302  static std::vector<std::pair<float, float> > calculateCirclePoints(unsigned int n);
303 
304  /**
305  * Calculates the angle of the given line and the positive x axis.
306  * The returned value is in degrees.
307  */
308  static double calculateAngle(const CLPoint& endPoint, const CLPoint& startPoint);
309 
310  /**
311  * This method creates all display lists and sets the clear color.
312  * This should be called whenever a color is changed.
313  */
314  void initializeDisplayLists();
315  void initializeGraphPainter(QWidget *viewportWidget);
316  void draw();
317  void contextMenuEvent(QContextMenuEvent *event);
318  void testOpenGL();
319 
320  void initializeGL();
321 
322  void resizeGL(int w, int h);
323 
324  void paintGL();
325 
326  void printNodeInfoForKey(std::string key); // just for debugging
327 };
328 
329 #endif /*GLGRAPHPAINTER_H_*/
void stepChanged(int)
bool mIsInitialized
flag that indicates whether OpenGL was initialized
void drawNode(CCompartmentGraphNode &n)
CLPoint getPointOnRectangle(CLBoundingBox r, CLPoint p)
static const GLfloat MIRROR_X[16]
int getLabelWindowWidth(int width)
static const float SPECIES_SHADOW_DEPTH
static const GLfloat MIRROR_Y[16]
std::vector< CDataEntity > mDataSets
std::multimap< std::string, CArrow > nodeArrowMap
GLfloat mInanimatedSpeciesColor[4]
std::map< std::string, RGTextureSpec * > labelTextureMap
std::vector< CGraphCurve > curvesWithArrow
void setCurrentPosition(C_FLOAT64 x, C_FLOAT64 y)
unsigned int mNumCirclePoints
std::vector< CGraphCurve > viewerCurves
CVisParameters::SCALING_MODE mScaleMode
std::vector< std::pair< float, float > > mCirclePoints
void setCurrentPositionY(C_FLOAT64 y)
std::set< std::string > setOfConstantMetabolites
CSimSummaryInfo * pSummaryInfo
void setNodeSizeWithoutChangingCurves(std::string key, C_FLOAT64 val)
CQLayoutMainWindow * pParentLayoutWindow
CDataEntity * getDataSetAt(size_t stepNumber)
static const C_INT32 MIN_HEIGHT
#define C_INT32
Definition: copasi.h:90
void rescaleNode(std::string key, C_FLOAT64 newMin, C_FLOAT64 newMax, CVisParameters::SCALING_MODE scaleMode)
std::multimap< std::string, CGraphCurve > nodeCurveMap
void updateGraphWithNodeSizes()
size_t getCurrentStep() const
static const float COMPARTMENT_FRAME_DEPTH
void setConstantNodeSize(std::string key, C_FLOAT64 val)
void printNodeInfoForKey(std::string key)
static const float COMPARTMENT_SHADOW_DEPTH
void createGraph(CLayout *lP)
void setGraphSize(const CLPoint &min, const CLPoint &max)
bool checkCurve(CGraphCurve *curve, CGraphCurve curveR, CLBoundingBox box)
void rescaleDataSets(CVisParameters::SCALING_MODE scaleMode)
int getTextWidth(const std::string &text, const std::string &fontName, unsigned int fontSize)
std::map< std::string, std::string > labelNodeMap
std::map< std::string, CCompartmentGraphNode > compartmentNodeMap
void setCurrentPositionX(C_FLOAT64 x)
std::map< std::string, std::string > keyMap
Definition: CLBase.h:54
static const C_FLOAT64 DEFAULT_NODE_SIZE
size_t getNumberOfSteps() const
static double calculateAngle(const CLPoint &endPoint, const CLPoint &startPoint)
static const float SPECIES_FRAME_DEPTH
GLfloat mConstantSpeciesColor[4]
Definition: CArrow.h:29
#define C_INT16
Definition: copasi.h:91
RGTextureSpec * getTextureForText(const std::string &text, const std::string &fontName, unsigned int fontSize)
Header file of class CArrow.
void setScaleMode(CVisParameters::SCALING_MODE scaleMode)
shapeOfLabels mLabelShape
static const float SPECIES_DEPTH
GLfloat mAnimatedSpeciesColor[4]
std::string getNameForNodeKey(std::string key)
GLclampf mBackgroundColor[4]
void updateEdge(CLLineSegment line)
RGTextureSpec * RG_createTextureForText(const std::string &text, const std::string &fontName, unsigned int fontSize)
CLPoint getPointOnCircle(CLBoundingBox r, CLPoint p)
C_FLOAT64 getCurrentPositionY() const
void endOfAnimationReached()
void setFontSizeForLabels(unsigned int fs)
void RG_drawStringAt(std::string s, C_INT32 x, C_INT32 y, C_INT32 w, C_INT32 h)
void addMetaboliteForAnimation(std::string key)
void setNodeSize(std::string key, C_FLOAT64 val)
#define C_FLOAT64
Definition: copasi.h:92
static const float SPECIESREFERENCE_DEPTH
void adaptCurveForRectangles(std::multimap< std::string, CGraphCurve >::iterator it, CLBoundingBox box)
bool export_bitmap(double x, double y, double width, double height, unsigned int imageWidth, unsigned int imageHeight, const QString &filename, const std::vector< size_t > frames)
void rescaleDataSetsWithNewMinMax(C_FLOAT64 oldMin, C_FLOAT64 oldMax, C_FLOAT64 newMin, C_FLOAT64 newMax, CVisParameters::SCALING_MODE scaleMode)
const CLPoint & getGraphMax()
void zoomGraph(C_FLOAT64 zoomFactor)
void removeMetaboliteForAnimation(std::string key)
std::vector< std::string > viewerNodes
std::vector< std::string > viewerCompartmentNodes
void drawEdge(CGraphCurve &c)
CQGLNetworkPainter(const QGLFormat &format, QWidget *parent=0)
std::string getNodeNameEntry(int i)
GLfloat mSpeciesReferenceColor[4]
C_FLOAT64 getCurrentPositionX() const
static const float COMPARTMENT_DEPTH
C_FLOAT64 getZoomFactor() const
void zoom(double zoomFactor)
void resizeGL(int w, int h)
void contextMenuEvent(QContextMenuEvent *event)
void initializeGraphPainter(QWidget *viewportWidget)
void setZoomFactor(C_FLOAT64)
static std::vector< std::pair< float, float > > calculateCirclePoints(unsigned int n)
void setItemAnimated(std::string key, bool animatedP)
void drawArrow(CArrow a, CLMetabReferenceGlyph::Role role)
void drawStringAt(std::string s, C_FLOAT64 x, C_FLOAT64 y, C_FLOAT64 w, C_FLOAT64 h, QColor bgCol)
std::vector< CLabel > viewerLabels
#define min(a, b)
Definition: f2c.h:175
const CLPoint & getGraphMin()
std::set< std::string > setOfDisabledMetabolites
void setConstantNodeSizeForAllSteps(std::string key, C_FLOAT64 midValue)
std::map< std::string, CGraphNode > nodeMap
CLPoint getPointNearCircle(CLBoundingBox r, CLPoint p, C_INT16 d)
void adaptCurveForCircle(std::multimap< std::string, CGraphCurve >::iterator it, CLBoundingBox box)
#define max(a, b)
Definition: f2c.h:176