Salome HOME
updated copyright message
[modules/shaper.git] / src / ModuleBase / ModuleBase_IViewer.h
1 // Copyright (C) 2014-2023  CEA, EDF
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   //! Type for mapping from text to color to display the names lines in different colors
191   typedef std::list<std::pair<std::wstring, std::vector<int> > > TextColor;
192
193   //! Sets the text displayed in right-top corner of the 3D view
194   //! \param theText the text to display, or empty string to erase presentation;
195   //!        the first item is the font name and text color
196   //! \param theSize size of the text font
197   virtual void setText(const TextColor& theText, const int theSize) = 0;
198
199
200   /// Switches On additional highlight for objects preselection
201   void showSelectionHighlight() {
202     myShowHighlight = true;
203   }
204
205   /// Switches Off additional highlight for objects preselection
206   void hideSelectionHighlight() {
207     myShowHighlight = false;
208   }
209
210 #ifdef HAVE_SALOME
211   virtual void setFitter(OCCViewer_Fitter* theFitter) = 0;
212   virtual OCCViewer_Fitter* fitter() const = 0;
213 #else
214   virtual void setFitter(AppElements_Fitter* theFitter) = 0;
215   virtual AppElements_Fitter* fitter() const = 0;
216 #endif
217
218   static Handle(Prs3d_Drawer) DefaultHighlightDrawer;
219
220
221 signals:
222   /// Signal emited when last view window is closed
223   void lastViewClosed();
224
225   /// Signal emited before view window is closed
226   void tryCloseView(ModuleBase_IViewWindow* theWnd);
227
228   /// Signal emited on delete view window
229   void deleteView(ModuleBase_IViewWindow* theWnd);
230
231   /// Signal emited on creation of view window
232   void viewCreated(ModuleBase_IViewWindow* theWnd);
233
234   /// Signal emited on key release
235   void activated(ModuleBase_IViewWindow* theWnd);
236
237   /// Signal emited on mouse press
238   void mousePress(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
239
240   /// Signal emited on mouse release
241   void mouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
242
243   /// Signal emited on mouse double click
244   void mouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
245
246   /// Signal emited on mouse move
247   void mouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
248
249   /// Signal emited on key press
250   void keyPress(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
251
252   /// Signal emited on key release
253   void keyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
254
255   /// Signal emited on selection changed
256   void selectionChanged();
257
258   /// Signal emited on selection changed
259   void contextMenuRequested(QContextMenuEvent*);
260
261   /// Signal emitted on transformation of view point in view window
262   /// \param theTransformation type of transformation (see AppElements_ViewWindow::OperationType)
263   void viewTransformed(int theTransformation);
264
265   /// Signal emited on selection changed
266   void trihedronVisibilityChanged(bool theState);
267
268   protected:
269     /// A map for storing a scale factors dependent on view object
270     QMap<Handle(V3d_View), double> myWindowScale;
271
272     bool myIs2dMode;
273
274     bool myShowHighlight;
275 };
276
277 #endif