COPASI API  4.16.103
CQGLLayoutPainter.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 #ifndef CQGLLAYOUTPAINTER_H__
7 #define CQGLLAYOUTPAINTER_H__
8 
9 #include <QtOpenGL/QGLWidget>
10 #include <QtCore/QRectF>
11 #include <set>
12 
13 class CCopasiDataModel;
14 class CCopasiObject;
15 class CLGraphicalObject;
16 class CLayout;
17 class CLLayoutRenderer;
18 class CLPoint;
20 class CQFontRenderer;
21 class QMouseEvent;
22 class QShowEvent;
23 
24 class CQGLLayoutPainter : public QGLWidget
25 {
26 
27  Q_OBJECT // must include this if you use Qt signals/slots
28 
29 public:
30  enum STATE
31  {
35  };
36 
37 public:
38  CQGLLayoutPainter(const QGLFormat& format, QWidget *parent = 0);
40 
41  /**
42  * sets the the x and y offset of the viewport.
43  */
44  void setCurrentPosition(double x, double y);
45 
46  /**
47  * sets the the x offset of the viewport.
48  */
49  void setCurrentPositionX(double x);
50 
51  /**
52  * sets the the y offset of the viewport.
53  */
54  void setCurrentPositionY(double y);
55 
56  /**
57  * Returns the current x offset of the viewport.
58  */
59  double getCurrentPositionX() const;
60 
61  /**
62  * Returns the current y offset of the viewport.
63  */
64  double getCurrentPositionY() const;
65 
66  /**
67  * Sets the zoom factor.
68  */
69  void setZoomFactor(double);
70 
71  /**
72  * Returns the zoom factor.
73  */
74  double getZoomFactor() const;
75 
76  /**
77  * Updates the viewport.
78  */
79  void update();
80 
81  void resetView();
82 
83  /**
84  * Calculates the ratio that is needed to fit the diagram on the current viewport
85  * and sets this as the zoom factor.
86  * The method returns the new zoom factor.
87  */
88  double fitToScreen();
89 
90  double minX() const;
91 
92  void setMinX(double x);
93 
94  double minY() const;
95 
96  void setMinY(double y);
97 
98  double maxX() const;
99 
100  void setMaxX(double x);
101 
102  double maxY() const;
103 
104  void setMaxY(double y);
105 
106  void setBounds(double minX, double minY, double maxX, double maxY);
107 
108  void setBounds(const QRectF& rect);
109 
110  void calculateAndAssignBounds(CLayout* pLayout);
111 
112  void update(const CCopasiDataModel* pDocument, CLayout* pLayout, const CLRenderInformationBase* pRenderInfo, const QString& baseDir);
113 
114  void change_style(const CLRenderInformationBase* pRenderInfo, bool defaultStyle = false);
115 
116  /**
117  * Reverts the currently selected curve if there is one.
118  * If nothing is selected or the single selected item is not a curve,
119  * nothing is done.
120  */
121  void revertCurve();
122 
123  /**
124  * Returns the width of the current drawing area.
125  */
126  unsigned int getViewportWidth() const;
127 
128  /**
129  * Returns the height of the current viewport area.
130  */
131  unsigned int getViewportHeight() const;
132 
133  /**
134  * Returns the width of the layout part that is currently displayed.
135  */
136  double getCurrentWidth() const;
137 
138  /**
139  * Returns the width of the layout part that is currently displayed.
140  */
141  double getCurrentHeight() const;
142 
143  /**
144  * Returns the currently selected items.
145  */
146  std::set<CLGraphicalObject*> getSelection();
147 
148  /**
149  * Sets the selection to the items in the given set.
150  */
151  void setSelection(const std::set<CLGraphicalObject*>& selection);
152 
153  // the following methods are used to highlight elements in the diagram
154  // based on their association to model elements
155 
156  /**
157  * Sets the list of model objects that are to be highlighted in the diagram.
158  */
159  void setHighlightedObjects(const std::set<const CLGraphicalObject*>& highlightedObjects);
160 
161  /**
162  * Returns a const reference to the set of highlighted model objects.
163  */
164  const std::set<const CLGraphicalObject*>& getHighlightedObjects() const;
165 
166  /**
167  * Returns a reference to the set of highlighted model objects.
168  */
169  std::set<const CLGraphicalObject*>& getHighlightedObjects();
170 
171  /**
172  * Sets the highlight color.
173  */
174  void setHighlightColor(const GLfloat c[4]);
175 
176  /**
177  * Returns a const pointer to the highlight color.
178  * The array has a size of 4 elements.
179  */
180  const GLfloat* getHighlightColor() const;
181 
182  /**
183  * Returns the currently set fog density.
184  */
185  GLfloat getFogDensity() const;
186 
187  /**
188  * Sets the new fog density value.
189  */
190  void setFogDensity(GLfloat dens);
191 
192  /**
193  * Sets the fog color.
194  */
195  void setFogColor(const GLfloat c[4]);
196 
197  /**
198  * Returns a const pointer to the fog color.
199  * The array has a size of 4 elements.
200  */
201  const GLfloat* getFogColor() const;
202 
203  /**
204  * Toggles the flag that determines if highlighted objects
205  * are actually highlighted or if the rest is fogged out.
206  */
207  void toggleHighlightFlag();
208 
209  /**
210  * Toggles the flag that determines if highlighted objects
211  * are actually highlighted or if the rest is fogged out.
212  */
213  void setHighlightFlag(bool flag);
214 
215  /**
216  * Returns the highlight flag.
217  */
218  bool getHighlightFlag() const;
219 
220  /**
221  * Sets the aspect for the renderer.
222  */
223  void setAspect(double aspect);
224 
225  /**
226  * Returns the aspect from the renderer.
227  */
228  double getAspect() const;
229 
230  GLubyte* export_bitmap(double x, double y, double width, double height, unsigned int imageWidth, unsigned int imageHeight, bool drawSelection);
231 
232 protected:
233  bool mInitialized; // whether the gl context has been initialized
234  double mMinX; // minimal x value of the layout
235  double mMinY; // minimal y value of the layout
236  double mMaxX; // maximal x value of the layout
237  double mMaxY; // maximal y value of the layout
238  double mCurrentZoom ; // current zoom factor
239  double mCurrentPositionX; // x offset of the current viewport
240  double mCurrentPositionY; // y offset of the current viewport
241  unsigned int mViewportWidth; // the width of the current drawing area
242  unsigned int mViewportHeight; // the height of the current drawing area
244 
245  // stores the position where the mouse was pressed
247 
248  // stores the position where the mouse currently is
250 
251  // stores the position where the mouse was at the last move event
252  // this is important to determine how far objects have to be moved.
254 
255  /**
256  * is set to the button(s) that is (are) pressed and to Qt::NoButton once it is
257  * released.
258  */
259  Qt::MouseButton mMouseButton;
260 
261  /**
262  * flag that determines if a drag timeout has occured.
263  */
265 
266  /**
267  * stores the current state of the scene.
268  */
270 
271  /**
272  * Stores a pointer to the basepoint if we are currently
273  * dragging one.
274  */
276 
277  static const int MARGIN;
278 
279  // for windows and unix/linux we need to define some function pointers
280  // for OpenGL extension functions
281 #ifdef _WIN32
282 // framebuffer object functions
283  typedef GLenum(APIENTRY* PFNGLCHECKFRAMEBUFFERSTATUSEXT)(GLenum target);
284  typedef void (APIENTRY* PFNGLGENFRAMEBUFFERSEXT)(GLsizei n, GLuint* framebuffers);
285  typedef void (APIENTRY* PFNGLGENRENDERBUFFERSEXT)(GLsizei n, GLuint* renderbuffers);
286  typedef void (APIENTRY* PFNGLDELETEFRAMEBUFFERSEXT)(GLsizei n, GLuint* framebuffers);
287  typedef void (APIENTRY* PFNGLDELETERENDERBUFFERSEXT)(GLsizei n, GLuint* renderbuffers);
288  typedef void (APIENTRY* PFNGLBINDFRAMEBUFFEREXT)(GLenum target, GLuint framebuffer);
289  typedef void (APIENTRY* PFNGLBINDRENDERBUFFEREXT)(GLenum target, GLuint renderbuffer);
290  typedef void (APIENTRY* PFNGLRENDERBUFFERSTORAGEEXT)(GLenum target, GLenum internalFormat, GLsizei width, GLsizei height);
291  typedef void (APIENTRY* PFNGLFRAMEBUFFERRENDERBUFFEREXT)(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
292 // multisample functions
293  typedef void (APIENTRY* PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXT)(GLenum target, GLsizei samples, GLenum internalFormat, GLsizei width, GLsizei height);
294  typedef void (APIENTRY* PFNGLBLITFRAMEBUFFEREXT)(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
295  GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
296  GLbitfield mask, GLenum filter);
297 #else
298 //#ifndef __APPLE__ // if it is not an apple, we assume it is an X11 system
299  typedef GLenum(*PFNGLCHECKFRAMEBUFFERSTATUSEXT)(GLenum target);
300  typedef void (*PFNGLGENFRAMEBUFFERSEXT)(GLsizei n, GLuint* framebuffers);
301  typedef void (*PFNGLGENRENDERBUFFERSEXT)(GLsizei n, GLuint* renderbuffers);
302  typedef void (*PFNGLDELETEFRAMEBUFFERSEXT)(GLsizei n, GLuint* framebuffers);
303  typedef void (*PFNGLDELETERENDERBUFFERSEXT)(GLsizei n, GLuint* renderbuffers);
304  typedef void (*PFNGLBINDFRAMEBUFFEREXT)(GLenum target, GLuint framebuffer);
305  typedef void (*PFNGLBINDRENDERBUFFEREXT)(GLenum target, GLuint renderbuffer);
306  typedef void (*PFNGLRENDERBUFFERSTORAGEEXT)(GLenum target, GLenum internalFormat, GLsizei width, GLsizei height);
307  typedef void (*PFNGLFRAMEBUFFERRENDERBUFFEREXT)(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
308 // multisample functions
309  typedef void (*PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXT)(GLenum target, GLsizei samples, GLenum internalFormat, GLsizei width, GLsizei height);
310  typedef void (*PFNGLBLITFRAMEBUFFEREXT)(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
311  GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
312  GLbitfield mask, GLenum filter);
313 //#endif // __APPLE__
314 #endif // WIN32
315 //#ifndef __APPLE__
327 //#endif // __APPLE__
328 
329 protected:
330 
331  void draw();
332 
333  virtual void initializeGL();
334 
335  virtual void resizeGL(int w, int h);
336 
337  virtual void paintGL();
338 
339  virtual void mousePressEvent(QMouseEvent* pMouseEvent);
340 
341  virtual void mouseReleaseEvent(QMouseEvent* pMouseEvent);
342 
343  virtual void mouseMoveEvent(QMouseEvent* pMouseEvent);
344 
345  /**
346  * This method sets the correct cursor and updates the status message for the
347  * status bar.
348  */
350 
351  /**
352  * Destroys the passed in render and framebuffers.
353  */
354  void destroy_buffers(GLuint& fbo, GLuint* rbuffers, GLuint& multiFBO, GLuint* multiRBuffers);
355 
356  /**
357  * Checks the state of the currently bound framebuffer.
358  * If the framebuffer is valid, true is returned, if it is invalid,
359  * the return value is false and messageHeader and message contain a message
360  * header and a message to display to the user.
361  */
362  bool check_fbo_status(QString& messageHeader, QString& message);
363 
364  /**
365  * Renders the specified part of the model into a bitmap.
366  * The bitmap is returned as RGBA data in pImageData.
367  * If pImageData is pointing to a null pointer, memory is alocated and the caller has to release it.
368  * If drawing the bitmap is successfull, true is returned, else false is
369  * returned.
370  */
371  bool draw_bitmap(double x, double y, double width, double height,
372  unsigned int imageWidth, unsigned int imageHeight,
373  GLuint& fbo, GLuint& multiFBO,
374  GLuint** rbuffers, GLuint** multiRBuffers,
375  GLubyte** pImageData, GLuint samples = 0);
376 
377 //#ifndef __APPLE__
378  /**
379  * On non apple systems, we need to get the pointers to extension functions.
380  */
382 
383  /**
384  * Set all pointer to extension function to NULL.
385  */
387 
388 //#endif // __APPLE__
389 //
390 #ifdef __APPLE__
391  // This routine comes straight from Apples OpenGL programming guide
392  // It basically does the same as the glxGetProcAddr from glx
393  void * MyNSGLGetProcAddress(const char *name);
394 #endif // __APPLE__
395 
396 protected slots:
397  /**
398  * This slot is called if a timer runs down that is started on a left mouse press
399  */
400  void timeout();
401 
402 signals:
403  /**
404  * signal is emitted when the status bar is supposed to show a certain
405  * message.
406  * The message text and the timeout in milliseconds are the arguments
407  * to the signal.
408  */
409  void status_message(const QString& message, int timeout);
410 
411  /**
412  * This signal is emitted when the painter changes
413  * the document / layout.
414  */
415  void documentChanged();
416 
417  /**
418  * This signal is emitted whenever the selection changes.
419  * If after the change exactly one curve object is selected, the
420  * argument to the signal is true, otherwise it is false
421  */
422  void singleCurveSelected(bool);
423 };
424 
425 #endif /* CQGLLAYOUTPAINTER_H__ */
unsigned int getViewportHeight() const
PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXT glRenderbufferStorageMultisampleEXTPtr
double minX() const
void setSelection(const std::set< CLGraphicalObject * > &selection)
bool check_fbo_status(QString &messageHeader, QString &message)
double getCurrentHeight() const
void setCurrentPosition(double x, double y)
double getCurrentPositionY() const
void setBounds(double minX, double minY, double maxX, double maxY)
const GLfloat * getHighlightColor() const
void(* PFNGLBLITFRAMEBUFFEREXT)(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
PFNGLGENRENDERBUFFERSEXT glGenRenderbuffersEXTPtr
void status_message(const QString &message, int timeout)
void(* PFNGLGENRENDERBUFFERSEXT)(GLsizei n, GLuint *renderbuffers)
virtual void initializeGL()
PFNGLGENFRAMEBUFFERSEXT glGenFramebuffersEXTPtr
GLfloat getFogDensity() const
virtual void mousePressEvent(QMouseEvent *pMouseEvent)
void(* PFNGLDELETEFRAMEBUFFERSEXT)(GLsizei n, GLuint *framebuffers)
void(* PFNGLFRAMEBUFFERRENDERBUFFEREXT)(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
double maxY() const
const std::set< const CLGraphicalObject * > & getHighlightedObjects() const
void setMinX(double x)
void setHighlightColor(const GLfloat c[4])
PFNGLBLITFRAMEBUFFEREXT glBlitFramebufferEXTPtr
unsigned int mViewportHeight
void calculateAndAssignBounds(CLayout *pLayout)
double getCurrentPositionX() const
virtual void mouseMoveEvent(QMouseEvent *pMouseEvent)
static const int MARGIN
void setCurrentPositionX(double x)
CQGLLayoutPainter(const QGLFormat &format, QWidget *parent=0)
PFNGLRENDERBUFFERSTORAGEEXT glRenderbufferStorageEXTPtr
#define APIENTRY
Definition: glext.h:57
void destroy_buffers(GLuint &fbo, GLuint *rbuffers, GLuint &multiFBO, GLuint *multiRBuffers)
bool getHighlightFlag() const
void setCurrentPositionY(double y)
void setFogDensity(GLfloat dens)
double getCurrentWidth() const
void setMinY(double y)
PFNGLFRAMEBUFFERRENDERBUFFEREXT glFramebufferRenderbufferEXTPtr
Definition: CLBase.h:54
void setHighlightedObjects(const std::set< const CLGraphicalObject * > &highlightedObjects)
void setZoomFactor(double)
void change_style(const CLRenderInformationBase *pRenderInfo, bool defaultStyle=false)
void(* PFNGLGENFRAMEBUFFERSEXT)(GLsizei n, GLuint *framebuffers)
virtual void resizeGL(int w, int h)
void setFogColor(const GLfloat c[4])
GLubyte * export_bitmap(double x, double y, double width, double height, unsigned int imageWidth, unsigned int imageHeight, bool drawSelection)
void(* PFNGLBINDFRAMEBUFFEREXT)(GLenum target, GLuint framebuffer)
void setMaxX(double x)
PFNGLCHECKFRAMEBUFFERSTATUSEXT glCheckFramebufferStatusEXTPtr
virtual void paintGL()
PFNGLDELETERENDERBUFFERSEXT glDeleteRenderbuffersEXTPtr
Qt::MouseButton mMouseButton
long int flag
Definition: f2c.h:52
unsigned int getViewportWidth() const
PFNGLDELETEFRAMEBUFFERSEXT glDeleteFramebuffersEXTPtr
double maxX() const
const GLfloat * getFogColor() const
void singleCurveSelected(bool)
double getZoomFactor() const
void(* PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXT)(GLenum target, GLsizei samples, GLenum internalFormat, GLsizei width, GLsizei height)
PFNGLBINDFRAMEBUFFEREXT glBindFramebufferEXTPtr
virtual void mouseReleaseEvent(QMouseEvent *pMouseEvent)
void setAspect(double aspect)
void setHighlightFlag(bool flag)
PFNGLBINDRENDERBUFFEREXT glBindRenderbufferEXTPtr
GLenum(* PFNGLCHECKFRAMEBUFFERSTATUSEXT)(GLenum target)
double minY() const
() void(yyvaluep))
void(* PFNGLRENDERBUFFERSTORAGEEXT)(GLenum target, GLenum internalFormat, GLsizei width, GLsizei height)
void setMaxY(double y)
std::set< CLGraphicalObject * > getSelection()
void(* PFNGLDELETERENDERBUFFERSEXT)(GLsizei n, GLuint *renderbuffers)
double getAspect() const
bool draw_bitmap(double x, double y, double width, double height, unsigned int imageWidth, unsigned int imageHeight, GLuint &fbo, GLuint &multiFBO, GLuint **rbuffers, GLuint **multiRBuffers, GLubyte **pImageData, GLuint samples=0)
unsigned int mViewportWidth
CLLayoutRenderer * mpRenderer
void(* PFNGLBINDRENDERBUFFEREXT)(GLenum target, GLuint renderbuffer)