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