Tulip  5.3.1
Large graphs analysis and drawing
GlMainView.h
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 
20 #ifndef Tulip_GLMAINVIEW_H
21 #define Tulip_GLMAINVIEW_H
22 
23 #include <tulip/ViewWidget.h>
24 #include <tulip/GlMainWidget.h>
25 
26 class QGraphicsProxyWidget;
27 class QAction;
28 class QPushButton;
29 class QRectF;
30 
31 namespace tlp {
32 class GlOverviewGraphicsItem;
33 class SceneConfigWidget;
34 class SceneLayersConfigWidget;
35 class QuickAccessBar;
36 class ViewActionsManager;
37 
38 /**
39  * @ingroup Plugins
40  *
41  * @brief An abstract view that displays a GlMainWidget as its central widget.
42  *
43  * The GlMainView subclasses ViewWidget and always uses a GlMainWidget as the central widget of the
44  panel. It also adds the following features:
45  * @list
46  * @li An overview of the scene that can be toggled on or off.
47  * @li Some configuration widgets that modify the rendering parameters.
48  * @li A quick access bar widget that allows the user to quickly modify some of the most used
49  rendering parameters and graph properties (nodes color, edges display, etc)
50  * @li The possibility to make snapshots of the current scene
51  * @endlist
52  *
53  * Subclassing GlMainView means you will only want to display graphs in a single GlMainWidget.
54  Switching the central widget can only be achieved from the ViewWidget class.
55  *
56  * @warning It is strongly unadvised to re-implement methods already implemented into tlp::View or
57  tlp::ViewWidget. If you have to add custom behavior to those method, make sure to call the
58  upper-class methods first:
59  @code
60  void MyView::setupWidget() { // Where MyView is a subclass of tlp::GlMainView
61  GlMainView::setupWidget(); // call this first
62  // insert custom behavior here
63  }
64  @endcode
65 
66  * @see tlp::ViewWidget
67  */
68 class TLP_QT_SCOPE GlMainView : public tlp::ViewWidget {
69 
70  Q_OBJECT
71 
72  tlp::GlMainWidget *_glMainWidget;
73  tlp::GlOverviewGraphicsItem *_overviewItem;
74  tlp::ViewActionsManager *_viewActionsManager;
75 
76  QPushButton *_showOvButton, *_showQabButton;
77 
78 protected:
79  bool needQuickAccessBar, _needTooltipAndUrlManager;
80  QGraphicsProxyWidget *_quickAccessBarItem;
81  tlp::QuickAccessBar *_quickAccessBar;
82  tlp::SceneConfigWidget *_sceneConfigurationWidget;
83  tlp::SceneLayersConfigWidget *_sceneLayersConfigurationWidget;
84 
85 public:
86  enum OverviewPosition {
87  OVERVIEW_TOP_LEFT,
88  OVERVIEW_TOP_RIGHT,
89  OVERVIEW_BOTTOM_LEFT,
90  OVERVIEW_BOTTOM_RIGHT
91  };
92 
93  GlMainView(bool needTooltipAndUrlManager = false);
94  ~GlMainView() override;
95  tlp::GlMainWidget *getGlMainWidget() const;
96  QList<QWidget *> configurationWidgets() const override;
97  bool overviewVisible() const;
98  bool quickAccessBarVisible() const;
99  QPixmap snapshot(const QSize &outputSize = QSize()) const override;
100 
101  void setOverviewPosition(const OverviewPosition &position);
102  OverviewPosition overviewPosition() const;
103 
104  void setUpdateOverview(bool updateOverview);
105  bool updateOverview() const;
106 
107  void setState(const tlp::DataSet &) override;
108  tlp::DataSet state() const override;
109 
110  /** @brief Pick a node or an edge at a view position
111  * First take a look at a node located at (x,y); if none is found, take a look at an edge
112  * @param x the x coordinate of the position
113  * @param y the y coordinate of the position
114  * @param n on return holds the node found under the (x,y) position, n.isValid() return false if
115  * none has been found
116  * @param e on return holds the edge found under the (x,y) position, e.isValid() return false if
117  * none has been found
118  * @param pickNode enable or disable the node picking
119  * @param pickEdge enable or disable the edge picking
120  * @return true if something has been found, false otherwise
121  */
122  bool pickNodeEdge(const int x, const int y, tlp::node &n, tlp::edge &e, bool pickNode = true,
123  bool pickEdge = true);
124 
125  /**
126  * @brief Rotate the view camera by (x,y,z)
127  * @param x rotation around the X axis in degree
128  * @param y rotation around the Y axis in degree
129  * @param z rotation around Z axis in degree
130  */
131  inline void rotateCamera(int x, int y, int z) {
132  getGlMainWidget()->getScene()->rotateCamera(x, y, z);
133  }
134 
135  /**
136  * @brief Translate the view camera by (x,y,z)
137  * @param x offset along the X axis
138  * @param y offset along the Y axis
139  * @param z offset along the Z axis
140  */
141  inline void translateCamera(int x, int y, int z) {
142  getGlMainWidget()->getScene()->translateCamera(x, y, z);
143  }
144 
145  /**
146  * @brief Return the 3D world position for the given view position
147  */
148  inline Coord viewToWorld(const Coord &vpos) const {
149  return getGlMainWidget()->getScene()->getGraphCamera().viewportTo3DWorld(vpos);
150  }
151 
152  /**
153  * @brief Return the view position for the given 3D position
154  */
155  inline Coord worldToView(const Coord &wpos) const {
156  return getGlMainWidget()->getScene()->getGraphCamera().worldTo2DViewport(wpos);
157  }
158 
159  /**
160  * @brief Zoom by step to the given (x,y) view position
161  * @param step of zoom
162  */
163  inline void zoomXY(int step, const int x, const int y) {
164  getGlMainWidget()->getScene()->zoomXY(step, x, y);
165  }
166 
167  /**
168  * @brief Zoom by step
169  * @param step of zoom
170  */
171  inline void zoom(int step) {
172  getGlMainWidget()->getScene()->zoom(step);
173  }
174 
175  /**
176  * @brief Zoom by factor
177  * @param factor of zoom
178  */
179  inline void zoomFactor(float factor) {
180  getGlMainWidget()->getScene()->zoomFactor(factor);
181  }
182 
183  /**
184  * @brief Do a zoom and pan animation
185  * @param boundingBox the bounding box in scene coordinates on which the view
186  * has to be zoomed and panned. If it is not valid, the scene bounding box will be used.
187  * At the end of the animation, the view will be zoomed and centered on the content of that
188  * bounding box.
189  * @param duration the animation duration in msecs
190  */
191  void zoomAndPanAnimation(const tlp::BoundingBox &boundingBox, const double duration = 1000.);
192 
193 public slots:
194  /**
195  * @brief Calls GlMainWidget::draw();
196  */
197  void draw() override;
198 
199  /**
200  * @brief Calls GlMainWidget::redraw();
201  */
202  void redraw();
203 
204  /**
205  * @brief Calls GlMainWidget::redraw();
206  */
207  void refresh() override;
208 
209  /**
210  * @brief Force the overview to be redrawn. Since GlMainView already detects graph's
211  * modifications, this method should not be called manually to avoid extra rendering.
212  */
213  virtual void drawOverview(bool generatePixmap = true);
214 
215  /**
216  * @brief Centers the scene's camera
217  */
218  void centerView(bool graphChanged = false) override;
219 
220  /**
221  * @brief Toggles the overview on or off
222  */
223  void setOverviewVisible(bool);
224 
225  /**
226  * @brief allows to control the quick access bar visibility
227  */
228  void setQuickAccessBarVisible(bool);
229 
230  /**
231  * @brief Toggles the orthogonal projection on or off, then draws
232  */
233  void setViewOrtho(bool);
234 
235  /**
236  * @brief Force the settings set in the configuration widgets to be re-applied.
237  */
238  void applySettings() override;
239 
240  void undoCallback() override;
241 
242  static bool getNodeOrEdgeAtViewportPos(GlMainWidget *glw, int x, int y, node &n, edge &e);
243 
244  bool getNodeOrEdgeAtViewportPos(int x, int y, node &n, edge &e) const override {
245  return getNodeOrEdgeAtViewportPos(_glMainWidget, x, y, n, e);
246  }
247 
248  /**
249  * @brief Return the glMainWidget current display in the RGB888 format.
250  */
251  QImage getRGBImage() const;
252 
253 protected slots:
254  virtual void glMainViewDrawn(bool graphChanged);
255  virtual void sceneRectChanged(const QRectF &);
256  void fillContextMenu(QMenu *menu, const QPointF &) override;
257 
258 protected:
259  void setupWidget() override;
260  void assignNewGlMainWidget(GlMainWidget *glMainWidget, bool deleteOldGlMainWidget = true);
261  bool eventFilter(QObject *obj, QEvent *event) override;
262 
263  tlp::GlOverviewGraphicsItem *overviewItem() const;
264  void updateShowOverviewButton();
265  void updateShowQuickAccessBarButton();
266  virtual QuickAccessBar *getQuickAccessBarImpl();
267 
268  OverviewPosition _overviewPosition;
269 
270  bool _updateOverview;
271 };
272 } // namespace tlp
273 
274 #endif /* GLMAINVIEW_H_ */
An abstract view that displays a GlMainWidget as its central widget.
Definition: GlMainView.h:68
Coord viewToWorld(const Coord &vpos) const
Return the 3D world position for the given view position.
Definition: GlMainView.h:148
tlp::GlScene * getScene()
Get the GlScene of this GlMainWidget You have to add yours GlLayer and GlEntity to this GlScene At th...
Definition: GlMainWidget.h:100
void rotateCamera(int x, int y, int z)
Rotate the view camera by (x,y,z)
Definition: GlMainView.h:131
void translateCamera(const int x, const int y, const int z)
Translate camera by (x,y,z)
void rotateCamera(const int x, const int y, const int z)
Rotate camera by (x,y,z)
A container that can store data from any type.
Definition: DataSet.h:189
Camera & getGraphCamera()
By default the most important layer is the layer where the graph is visualized This function return t...
Definition: GlScene.h:505
void zoom(int step)
Zoom by step.
Definition: GlMainView.h:171
The edge struct represents an edge in a Graph object.
Definition: Edge.h:40
The node struct represents a node in a Graph object.
Definition: Node.h:40
Coord viewportTo3DWorld(const Coord &point) const
Return the 3D world coordinate for the given viewport point.
This class represents the 3D bounding box of an object. It is mostly used to determine whether or not...
Definition: BoundingBox.h:66
void zoomXY(int step, const int x, const int y)
Zoom by step to given x,y screen coordinates.
void zoomXY(int step, const int x, const int y)
Zoom by step to the given (x,y) view position.
Definition: GlMainView.h:163
void zoomFactor(float factor)
Zoom by factor.
Definition: GlMainView.h:179
void translateCamera(int x, int y, int z)
Translate the view camera by (x,y,z)
Definition: GlMainView.h:141
Coord worldToView(const Coord &wpos) const
Return the view position for the given 3D position.
Definition: GlMainView.h:155
ViewWidget provides convenience functions to allow the user to build a view plugin that displays a QW...
Definition: ViewWidget.h:49
Coord worldTo2DViewport(const Coord &obj) const
Return the viewport position for the given 3D coordinate.
void zoom(float factor, const Coord &dest)
Zoom to given world coordinate.
void zoomFactor(float factor)
Zoom by factor.
This widget provide a simple system to visualize data/graph with OpenGL 3D engine.
Definition: GlMainWidget.h:64