Tulip  6.0.0
Large graphs analysis and drawing
GlMainView.h
1 /*
2  *
3  * This file is part of Tulip (https://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  std::list<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  /**
111  * @brief Rotate the view camera by (x,y,z)
112  * @param x rotation around the X axis in degree
113  * @param y rotation around the Y axis in degree
114  * @param z rotation around Z axis in degree
115  */
116  inline void rotateCamera(int x, int y, int z) {
117  getGlMainWidget()->getScene()->rotateCamera(x, y, z);
118  }
119 
120  /**
121  * @brief Translate the view camera by (x,y,z)
122  * @param x offset along the X axis
123  * @param y offset along the Y axis
124  * @param z offset along the Z axis
125  */
126  inline void translateCamera(int x, int y, int z) {
127  getGlMainWidget()->getScene()->translateCamera(x, y, z);
128  }
129 
130  /**
131  * @brief Return the 3D world position for the given view position
132  */
133  inline Coord viewToWorld(const Coord &vpos) const {
134  return getGlMainWidget()->getScene()->getGraphCamera().viewportTo3DWorld(vpos);
135  }
136 
137  /**
138  * @brief Return the view position for the given 3D position
139  */
140  inline Coord worldToView(const Coord &wpos) const {
141  return getGlMainWidget()->getScene()->getGraphCamera().worldTo2DViewport(wpos);
142  }
143 
144  /**
145  * @brief Zoom by step to the given (x,y) view position
146  * @param step of zoom
147  */
148  inline void zoomXY(int step, const int x, const int y) {
149  getGlMainWidget()->getScene()->zoomXY(step, x, y);
150  }
151 
152  /**
153  * @brief Zoom by step
154  * @param step of zoom
155  */
156  inline void zoom(int step) {
157  getGlMainWidget()->getScene()->zoom(step);
158  }
159 
160  /**
161  * @brief Zoom by factor
162  * @param factor of zoom
163  */
164  inline void zoomFactor(float factor) {
165  getGlMainWidget()->getScene()->zoomFactor(factor);
166  }
167 
168  /**
169  * @brief Do a zoom and pan animation
170  * @param boundingBox the bounding box in scene coordinates on which the view
171  * has to be zoomed and panned. If it is not valid, the scene bounding box will be used.
172  * At the end of the animation, the view will be zoomed and centered on the content of that
173  * bounding box.
174  * @param duration the animation duration in msecs
175  */
176  void zoomAndPanAnimation(const tlp::BoundingBox &boundingBox, const double duration = 1000.);
177 
178 public slots:
179  /**
180  * @brief Calls GlMainWidget::draw();
181  */
182  void draw() override;
183 
184  /**
185  * @brief Calls GlMainWidget::redraw();
186  */
187  void redraw();
188 
189  /**
190  * @brief Calls GlMainWidget::redraw();
191  */
192  void refresh() override;
193 
194  /**
195  * @brief Force the overview to be redrawn. Since GlMainView already detects graph's
196  * modifications, this method should not be called manually to avoid extra rendering.
197  */
198  virtual void drawOverview(bool generatePixmap = true);
199 
200  /**
201  * @brief Centers the scene's camera
202  */
203  void centerView(bool graphChanged = false) override;
204 
205  /**
206  * @brief Toggles the overview on or off
207  */
208  void setOverviewVisible(bool);
209 
210  /**
211  * @brief allows to control the quick access bar visibility
212  */
214 
215  /**
216  * @brief Toggles the orthogonal projection on or off, then draws
217  */
218  void setViewOrtho(bool);
219 
220  /**
221  * @brief Force the settings set in the configuration widgets to be re-applied.
222  */
223  void applySettings() override;
224 
225  void undoCallback() override;
226 
227  static bool getNodeOrEdgeAtViewportPos(GlMainWidget *glw, int x, int y, node &n, edge &e);
228 
229  bool getNodeOrEdgeAtViewportPos(int x, int y, node &n, edge &e) const override {
230  return getNodeOrEdgeAtViewportPos(_glMainWidget, x, y, n, e);
231  }
232 
233  /**
234  * @brief Return the glMainWidget current display in the RGB888 format.
235  */
236  QImage getRGBImage() const;
237 
238 protected slots:
239  virtual void glMainViewDrawn(bool graphChanged);
240  virtual void sceneRectChanged(const QRectF &);
241  void fillContextMenu(QMenu *menu, const QPointF &) override;
242 
243 protected:
244  void setupWidget() override;
245  void assignNewGlMainWidget(GlMainWidget *glMainWidget, bool deleteOldGlMainWidget = true);
246  bool eventFilter(QObject *obj, QEvent *event) override;
247 
248  tlp::GlOverviewGraphicsItem *overviewItem() const;
249  void updateShowOverviewButton();
250  void updateShowQuickAccessBarButton();
251  virtual QuickAccessBar *getQuickAccessBarImpl();
252 
253  OverviewPosition _overviewPosition;
254 
255  bool _updateOverview;
256 };
257 } // namespace tlp
258 
259 #endif /* GLMAINVIEW_H_ */
Coord viewportTo3DWorld(const Coord &point) const
Return the 3D world coordinate for the given viewport point.
Coord worldTo2DViewport(const Coord &obj) const
Return the viewport position for the given 3D coordinate.
A container that can store data from any type.
Definition: DataSet.h:195
An abstract view that displays a GlMainWidget as its central widget.
Definition: GlMainView.h:68
tlp::DataSet state() const override
Backup the state of the view. This method is used to restore the View's parameters when it's re-opene...
void setupWidget() override
Sets up the central widget. This is similar to View::setupUi in the sense that the purpose of setupWi...
void refresh() override
Calls GlMainWidget::redraw();.
QPixmap snapshot(const QSize &outputSize=QSize()) const override
Takes a snapshot of the view's screen and saves it into the given pixmap. The snapshot is scaled to o...
void setOverviewVisible(bool)
Toggles the overview on or off.
Coord viewToWorld(const Coord &vpos) const
Return the 3D world position for the given view position.
Definition: GlMainView.h:133
void setQuickAccessBarVisible(bool)
allows to control the quick access bar visibility
void redraw()
Calls GlMainWidget::redraw();.
virtual void drawOverview(bool generatePixmap=true)
Force the overview to be redrawn. Since GlMainView already detects graph's modifications,...
void setViewOrtho(bool)
Toggles the orthogonal projection on or off, then draws.
void zoomFactor(float factor)
Zoom by factor.
Definition: GlMainView.h:164
void rotateCamera(int x, int y, int z)
Rotate the view camera by (x,y,z)
Definition: GlMainView.h:116
Coord worldToView(const Coord &wpos) const
Return the view position for the given 3D position.
Definition: GlMainView.h:140
void zoomXY(int step, const int x, const int y)
Zoom by step to the given (x,y) view position.
Definition: GlMainView.h:148
std::list< QWidget * > configurationWidgets() const override
void draw() override
Calls GlMainWidget::draw();.
void centerView(bool graphChanged=false) override
Centers the scene's camera.
void zoom(int step)
Zoom by step.
Definition: GlMainView.h:156
void zoomAndPanAnimation(const tlp::BoundingBox &boundingBox, const double duration=1000.)
Do a zoom and pan animation.
void translateCamera(int x, int y, int z)
Translate the view camera by (x,y,z)
Definition: GlMainView.h:126
QImage getRGBImage() const
Return the glMainWidget current display in the RGB888 format.
void applySettings() override
Force the settings set in the configuration widgets to be re-applied.
void setState(const tlp::DataSet &) override
Restores the state of the view. DataSet passed down to this method can come from a previous backup or...
This widget provide a simple system to visualize data/graph with OpenGL 3D engine.
Definition: GlMainWidget.h:63
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:99
void zoomFactor(float factor)
Zoom by factor.
Camera & getGraphCamera()
By default the most important layer is the layer where the graph is visualized This function return t...
Definition: GlScene.h:459
void zoomXY(int step, const int x, const int y)
Zoom by step to given x,y screen coordinates.
void rotateCamera(const int x, const int y, const int z)
Rotate camera by (x,y,z)
void zoom(float factor, const Coord &dest)
Zoom to given world coordinate.
void translateCamera(const int x, const int y, const int z)
Translate camera by (x,y,z)
ViewWidget provides convenience functions to allow the user to build a view plugin that displays a QW...
Definition: ViewWidget.h:51
This class represents the 3D bounding box of an object. It is mostly used to determine whether or not...
Definition: BoundingBox.h:67
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