Salome HOME
Provide color scale for SALOME SHAPER module
[modules/shaper.git] / src / ModuleBase / ModuleBase_IViewer.h
1 // Copyright (C) 2014-2019  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 #include <QObject>
25 #include <QMap>
26 #include <AIS_InteractiveContext.hxx>
27 #include <V3d_View.hxx>
28 #include <AIS_Trihedron.hxx>
29
30 class QMouseEvent;
31 class QKeyEvent;
32 class QContextMenuEvent;
33 class ModuleBase_IViewWindow;
34
35 /**
36  * \ingroup GUI
37  * A Base object for definition of connector object to
38  * Salome Viewer. Reimplemented in SHAPERGUI_SalomeViewer class
39  */
40 class MODULEBASE_EXPORT ModuleBase_IViewer : public QObject
41 {
42 Q_OBJECT
43  public:
44    /// Constructor
45    /// \param theParent a parent object
46   ModuleBase_IViewer(QObject* theParent);
47
48   //! Returns AIS_InteractiveContext from current OCCViewer
49   virtual Handle(AIS_InteractiveContext) AISContext() const = 0;
50
51   //! Trihedron 3d object shown in the viewer
52   virtual Handle(AIS_Trihedron) trihedron() const = 0;
53
54   //! Retrurns V3d_Vioewer from current viewer
55   virtual Handle(V3d_Viewer) v3dViewer() const = 0;
56
57   //! Returns Vsd_View object from currently active view window
58   virtual Handle(V3d_View) activeView() const = 0;
59
60   //! Returns currently active view port widget
61   virtual QWidget* activeViewPort() const = 0;
62
63   //! Enable or disable selection in the viewer
64   //! \param isEnabled is enable or disable flag
65   virtual void enableSelection(bool isEnabled) = 0;
66
67   //! Returns true if selection is enabled
68   virtual bool isSelectionEnabled() const = 0;
69
70   //! Enable or disable multiselection in the viewer
71   //! \param isEnable is enable or disable flag
72   virtual void enableMultiselection(bool isEnable) = 0;
73
74   //! Returns true if multiselection is enabled
75   virtual bool isMultiSelectionEnabled() const = 0;
76
77   //! Enable or disable draw mode in the viewer
78   virtual bool enableDrawMode(bool isEnabled) = 0;
79
80   //! Perfroms the fit all for the active view
81   virtual void fitAll() = 0;
82
83   //! Erases all presentations from the viewer
84   virtual void eraseAll() = 0;
85
86   //! Sets the view projection
87   /// \param theX the X projection value
88   /// \param theY the Y projection value
89   /// \param theZ the Z projection value
90   /// \param theTwist the twist angle in radians
91   virtual void setViewProjection( double theX, double theY, double theZ,
92                                   double theTwist ) = 0;
93
94   /// Add selection filter to the viewer
95   /// \param theFilter a selection filter
96   virtual void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) = 0;
97
98   /// Remove selection filter from the viewer
99   /// \param theFilter a selection filter
100   virtual void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) = 0;
101
102   /// Returns true if the selection filter is set to the viewer
103   /// \param theFilter a selection filter
104   virtual bool hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) = 0;
105
106   /// Update current viewer
107   virtual void update() = 0;
108
109   /// Returns a scale factor of the given view
110   /// \param theView a view object
111   const double Scale(const Handle(V3d_View)& theView)
112   {
113     if (!myWindowScale.contains(theView))
114       myWindowScale.insert(theView, theView->Camera()->Scale());
115     return myWindowScale[theView];
116   }
117
118   /// Remember a scale factor for the view object
119   /// \param theView a view object
120   /// \param theVal a scale factor
121   void SetScale(const Handle(V3d_View)& theView, const double theVal)
122   { myWindowScale[theView] = theVal; }
123
124   /// Method returns True if the viewer can process editing objects
125   /// by mouse drugging. If this is impossible thet it has to return False.
126   virtual bool canDragByMouse() const { return true; }
127
128   /// Fit all along Z (perpendicular to display)
129   //virtual void Zfitall() = 0;
130
131   /// Show highlight for pre-highlighted sub-shape
132   virtual void updateHighlight() {}
133
134   /// Set flag which indicates that viewer is used for 2d operations
135   /// \param is2d a new 2d mode state
136   void set2dMode(bool is2d) {
137     myIs2dMode = is2d;
138   }
139
140   /// Returns current state of 2d mode flag
141   bool is2dMode() const {
142     return myIs2dMode;
143   }
144
145   // Methods for color scale management
146
147   //! Returns True if ColorScale is visible
148   virtual bool isColorScaleVisible() const = 0;
149
150   //! Show/Hide ColorScale object
151   virtual void setColorScaleShown(bool on) = 0;
152
153   //! Set position of color scale
154   // \param theX is X position relative to current view width
155   // \param theY is Y position relative to current view heigth
156   virtual void setColorScalePosition(double theX, double theY) = 0;
157
158   //! Set size of color scale
159   // \param theW is width relative to current view width
160   // \param theh is height relative to current view heigth
161   virtual void setColorScaleSize(double theW, double theH) = 0;
162
163   //! Set range of color scale
164   // \param theMin is a minimal value
165   // \param theMax is a maximal value
166   virtual void setColorScaleRange(double theMin, double theMax) = 0;
167
168   //! Set number of intervals of color scale
169   // \param theNb is number of intervals
170   virtual void setColorScaleIntervals(int theNb) = 0;
171
172   //! Set text heigth of color scale
173   // \param theH is number of intervals
174   virtual void setColorScaleTextHeigth(int theH) = 0;
175
176   //! Set title of color scale
177   // \param theText is a title
178   virtual void setColorScaleTitle(const QString& theText) = 0;
179
180   static Handle(Prs3d_Drawer) DefaultHighlightDrawer;
181
182 signals:
183   /// Signal emited when last view window is closed
184   void lastViewClosed();
185
186   /// Signal emited before view window is closed
187   void tryCloseView(ModuleBase_IViewWindow* theWnd);
188
189   /// Signal emited on delete view window
190   void deleteView(ModuleBase_IViewWindow* theWnd);
191
192   /// Signal emited on creation of view window
193   void viewCreated(ModuleBase_IViewWindow* theWnd);
194
195   /// Signal emited on key release
196   void activated(ModuleBase_IViewWindow* theWnd);
197
198   /// Signal emited on mouse press
199   void mousePress(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
200
201   /// Signal emited on mouse release
202   void mouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
203
204   /// Signal emited on mouse double click
205   void mouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
206
207   /// Signal emited on mouse move
208   void mouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
209
210   /// Signal emited on key press
211   void keyPress(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
212
213   /// Signal emited on key release
214   void keyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
215
216   /// Signal emited on selection changed
217   void selectionChanged();
218
219   /// Signal emited on selection changed
220   void contextMenuRequested(QContextMenuEvent*);
221
222   /// Signal emitted on transformation of view point in view window
223   /// \param theTransformation type of transformation (see AppElements_ViewWindow::OperationType)
224   void viewTransformed(int theTransformation);
225
226   /// Signal emited on selection changed
227   void trihedronVisibilityChanged(bool theState);
228
229   protected:
230     /// A map for storing a scale factors dependent on view object
231     QMap<Handle(V3d_View), double> myWindowScale;
232
233     bool myIs2dMode;
234 };
235
236 #endif