Salome HOME
17c3723afa8b602ffca77c6e3d23dc42e482dfb1
[modules/shaper.git] / src / ModuleBase / ModuleBase_IViewer.h
1 // Copyright (C) 2014-2021  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef ModuleBase_IViewer_H
21 #define ModuleBase_IViewer_H
22
23 #include "ModuleBase.h"
24
25 #include <QObject>
26 #include <QMap>
27 #include <AIS_InteractiveContext.hxx>
28 #include <V3d_View.hxx>
29 #include <AIS_Trihedron.hxx>
30
31 class QMouseEvent;
32 class QKeyEvent;
33 class QContextMenuEvent;
34 class ModuleBase_IViewWindow;
35 #ifdef HAVE_SALOME
36 class OCCViewer_Fitter;
37 #else
38 class AppElements_Fitter;
39 #endif
40
41 /**
42  * \ingroup GUI
43  * A Base object for definition of connector object to
44  * Salome Viewer. Reimplemented in SHAPERGUI_SalomeViewer class
45  */
46 class MODULEBASE_EXPORT ModuleBase_IViewer : public QObject
47 {
48 Q_OBJECT
49  public:
50    /// Constructor
51    /// \param theParent a parent object
52   ModuleBase_IViewer(QObject* theParent);
53
54   //! Returns AIS_InteractiveContext from current OCCViewer
55   virtual Handle(AIS_InteractiveContext) AISContext() const = 0;
56
57   //! Trihedron 3d object shown in the viewer
58   virtual Handle(AIS_Trihedron) trihedron() const = 0;
59
60   //! Retrurns V3d_Vioewer from current viewer
61   virtual Handle(V3d_Viewer) v3dViewer() const = 0;
62
63   //! Returns Vsd_View object from currently active view window
64   virtual Handle(V3d_View) activeView() const = 0;
65
66   //! Returns currently active view port widget
67   virtual QWidget* activeViewPort() const = 0;
68
69   //! Enable or disable selection in the viewer
70   //! \param isEnabled is enable or disable flag
71   virtual void enableSelection(bool isEnabled) = 0;
72
73   //! Returns true if selection is enabled
74   virtual bool isSelectionEnabled() const = 0;
75
76   //! Enable or disable multiselection in the viewer
77   //! \param isEnable is enable or disable flag
78   virtual void enableMultiselection(bool isEnable) = 0;
79
80   //! Returns true if multiselection is enabled
81   virtual bool isMultiSelectionEnabled() const = 0;
82
83   //! Enable or disable draw mode in the viewer
84   virtual bool enableDrawMode(bool isEnabled) = 0;
85
86   //! Perfroms the fit all for the active view
87   virtual void fitAll() = 0;
88
89   //! Erases all presentations from the viewer
90   virtual void eraseAll() = 0;
91
92   //! Sets the view projection
93   /// \param theX the X projection value
94   /// \param theY the Y projection value
95   /// \param theZ the Z projection value
96   /// \param theTwist the twist angle in radians
97   virtual void setViewProjection( double theX, double theY, double theZ,
98                                   double theTwist ) = 0;
99
100   /// Add selection filter to the viewer
101   /// \param theFilter a selection filter
102   virtual void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) = 0;
103
104   /// Remove selection filter from the viewer
105   /// \param theFilter a selection filter
106   virtual void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) = 0;
107
108   /// Returns true if the selection filter is set to the viewer
109   /// \param theFilter a selection filter
110   virtual bool hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) = 0;
111
112   /// Update current viewer
113   virtual void update() = 0;
114
115   /// Returns a scale factor of the given view
116   /// \param theView a view object
117   const double Scale(const Handle(V3d_View)& theView)
118   {
119     if (!myWindowScale.contains(theView))
120       myWindowScale.insert(theView, theView->Camera()->Scale());
121     return myWindowScale[theView];
122   }
123
124   /// Remember a scale factor for the view object
125   /// \param theView a view object
126   /// \param theVal a scale factor
127   void SetScale(const Handle(V3d_View)& theView, const double theVal)
128   { myWindowScale[theView] = theVal; }
129
130   /// Method returns True if the viewer can process editing objects
131   /// by mouse drugging. If this is impossible thet it has to return False.
132   virtual bool canDragByMouse() const { return true; }
133
134   /// Fit all along Z (perpendicular to display)
135   //virtual void Zfitall() = 0;
136
137   /// Show highlight for pre-highlighted sub-shape
138   virtual void updateHighlight() {}
139
140   /// Set flag which indicates that viewer is used for 2d operations
141   /// \param is2d a new 2d mode state
142   void set2dMode(bool is2d) {
143     myIs2dMode = is2d;
144   }
145
146   /// Returns current state of 2d mode flag
147   bool is2dMode() const {
148     return myIs2dMode;
149   }
150
151   // Methods for color scale management
152
153   //! Returns True if ColorScale is visible
154   virtual bool isColorScaleVisible() const = 0;
155
156   //! Show/Hide ColorScale object
157   virtual void setColorScaleShown(bool on) = 0;
158
159   //! Set position of color scale
160   // \param theX is X position relative to current view width
161   // \param theY is Y position relative to current view heigth
162   virtual void setColorScalePosition(double theX, double theY) = 0;
163
164   //! Set size of color scale
165   // \param theW is width relative to current view width
166   // \param theh is height relative to current view heigth
167   virtual void setColorScaleSize(double theW, double theH) = 0;
168
169   //! Set range of color scale
170   // \param theMin is a minimal value
171   // \param theMax is a maximal value
172   virtual void setColorScaleRange(double theMin, double theMax) = 0;
173
174   //! Set number of intervals of color scale
175   // \param theNb is number of intervals
176   virtual void setColorScaleIntervals(int theNb) = 0;
177
178   //! Set text heigth of color scale
179   // \param theH is number of intervals
180   virtual void setColorScaleTextHeigth(int theH) = 0;
181
182   //! Set color of text of color scale
183   // \param theH is number of intervals
184   virtual void setColorScaleTextColor(const QColor& theColor) = 0;
185
186   //! Set title of color scale
187   // \param theText is a title
188   virtual void setColorScaleTitle(const QString& theText) = 0;
189
190   /// Switches On additional highlight for objects preselection
191   void showSelectionHighlight() {
192     myShowHighlight = true;
193   }
194
195   /// Switches Off additional highlight for objects preselection
196   void hideSelectionHighlight() {
197     myShowHighlight = false;
198   }
199
200 #ifdef HAVE_SALOME
201   virtual void setFitter(OCCViewer_Fitter* theFitter) = 0;
202   virtual OCCViewer_Fitter* fitter() const = 0;
203 #else
204   virtual void setFitter(AppElements_Fitter* theFitter) = 0;
205   virtual AppElements_Fitter* fitter() const = 0;
206 #endif
207
208   static Handle(Prs3d_Drawer) DefaultHighlightDrawer;
209
210
211 signals:
212   /// Signal emited when last view window is closed
213   void lastViewClosed();
214
215   /// Signal emited before view window is closed
216   void tryCloseView(ModuleBase_IViewWindow* theWnd);
217
218   /// Signal emited on delete view window
219   void deleteView(ModuleBase_IViewWindow* theWnd);
220
221   /// Signal emited on creation of view window
222   void viewCreated(ModuleBase_IViewWindow* theWnd);
223
224   /// Signal emited on key release
225   void activated(ModuleBase_IViewWindow* theWnd);
226
227   /// Signal emited on mouse press
228   void mousePress(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
229
230   /// Signal emited on mouse release
231   void mouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
232
233   /// Signal emited on mouse double click
234   void mouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
235
236   /// Signal emited on mouse move
237   void mouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
238
239   /// Signal emited on key press
240   void keyPress(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
241
242   /// Signal emited on key release
243   void keyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
244
245   /// Signal emited on selection changed
246   void selectionChanged();
247
248   /// Signal emited on selection changed
249   void contextMenuRequested(QContextMenuEvent*);
250
251   /// Signal emitted on transformation of view point in view window
252   /// \param theTransformation type of transformation (see AppElements_ViewWindow::OperationType)
253   void viewTransformed(int theTransformation);
254
255   /// Signal emited on selection changed
256   void trihedronVisibilityChanged(bool theState);
257
258   protected:
259     /// A map for storing a scale factors dependent on view object
260     QMap<Handle(V3d_View), double> myWindowScale;
261
262     bool myIs2dMode;
263
264     bool myShowHighlight;
265 };
266
267 #endif