Salome HOME
3657b04747ef9510f409348fc3e686e939e1d2bc
[modules/shaper.git] / src / SHAPERGUI / SHAPERGUI_SalomeViewer.h
1 // Copyright (C) 2014-2024  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 SHAPERGUI_SalomeViewer_H
21 #define SHAPERGUI_SalomeViewer_H
22
23 #include "SHAPER_SHAPERGUI.h"
24
25 #include <ModuleBase_IViewer.h>
26 #include <ModuleBase_IViewWindow.h>
27
28 #include <OCCViewer_ViewWindow.h>
29
30 #include <V3d_View.hxx>
31 #include <AIS_Trihedron.hxx>
32
33 class SUIT_ViewWindow;
34 class QMouseEvent;
35 class QKeyEvent;
36
37 class SHAPERGUI_OCCSelector;
38 class OCCViewer_Viewer;
39 class SUIT_ViewManager;
40 class AIS_TextLabel;
41
42 /**
43 * \ingroup Salome
44 * A class for providing access of SHAPERGUI functionality to 
45 * SALOME view window functionality
46 */
47 class SHAPERGUI_SalomeView: public ModuleBase_IViewWindow
48 {
49 public:
50   /// Constructor
51   /// \param theViewer a reference to a viewer
52   SHAPERGUI_SalomeView(OCCViewer_Viewer* theViewer);
53
54   virtual Handle(V3d_View) v3dView() const;
55
56   /// Returns the view window view port
57   virtual QWidget* viewPort() const;
58
59   /// Set the current viewer
60   /// \param theViewer a viewer instance
61   void setViewer(OCCViewer_Viewer* theViewer) { myViewer = theViewer; }
62
63   /// Returns current viewer
64   OCCViewer_Viewer* viewer() const { return myViewer; }
65
66   /// Sets the current view
67   void setCurrentView(SUIT_ViewWindow* theView) { myCurrentView = theView; }
68
69 private:
70   /// A reference to a viewer
71   OCCViewer_Viewer* myViewer;
72   SUIT_ViewWindow* myCurrentView;
73 };
74
75
76 /**
77 * \ingroup Salome
78 * A class for providing access of SHAPERGUI functionality to 
79 * SALOME viewer functionality
80 */
81 class SHAPERGUI_SalomeViewer : public ModuleBase_IViewer
82 {
83 Q_OBJECT
84  public:
85    /// Constructor
86    /// \param theParent a parent object
87   SHAPERGUI_SalomeViewer(QObject* theParent);
88
89   ~SHAPERGUI_SalomeViewer();
90
91   //! Returns AIS_InteractiveContext from current OCCViewer
92   virtual Handle(AIS_InteractiveContext) AISContext() const;
93
94   //! Retrurns V3d_Vioewer from current viewer
95   virtual Handle(V3d_Viewer) v3dViewer() const;
96
97   //! Trihedron 3d object shown in the viewer
98   virtual Handle(AIS_Trihedron) trihedron() const;
99
100   //! Returns Vsd_View object from currently active view window
101   virtual Handle(V3d_View) activeView() const;
102
103   //! Returns viewer view port
104   virtual QWidget* activeViewPort() const;
105
106   //! Enable or disable selection in the viewer
107   virtual void enableSelection(bool isEnabled);
108
109   //! Returns true if selection is enabled
110   virtual bool isSelectionEnabled() const;
111
112   //! Enable or disable multiselection in the viewer
113   virtual void enableMultiselection(bool isEnable);
114
115   //! Returns true if multiselection is enabled
116   virtual bool isMultiSelectionEnabled() const;
117
118   //! Enable or disable draw mode in the viewer
119   virtual bool enableDrawMode(bool isEnabled);
120
121   //! For some signals it disconnects the window from usual signal and connect it to the module ones
122   void reconnectActions(SUIT_ViewWindow* theWindow, const bool theUseSHAPERSlot);
123
124   //! Perfroms the fit all for the active view
125   virtual void fitAll();
126
127   //! Erases all presentations from the viewer
128   virtual void eraseAll();
129
130   //! Sets the view projection
131   /// \param theX the X projection value
132   /// \param theY the Y projection value
133   /// \param theZ the Z projection value
134   /// \param theTwist the twist angle in radians
135   virtual void setViewProjection( double theX, double theY, double theZ,
136                                   double theTwist );
137
138   /// Set selector
139   /// \param theSel a selector instance
140   void setSelector(SHAPERGUI_OCCSelector* theSel);
141
142   /// Add selection filter to the viewer
143   virtual void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
144
145   /// Remove selection filter from the viewer
146   virtual void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
147
148   /// Returns true if the selection filter is set to the viewer
149   /// \param theFilter a selection filter
150   virtual bool hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
151
152   /// Remove all selection filters from the viewer
153   virtual void clearSelectionFilters();
154
155   /// Returns current selector
156   SHAPERGUI_OCCSelector* selector() const
157   {
158     return mySelector;
159   }
160
161   /// Update current viewer
162   virtual void update();
163
164   /// Method returns True if the viewer can process editing objects
165   /// by mouse drugging. If this is impossible thet it has to return False.
166   virtual bool canDragByMouse() const;
167
168   /// Activate or deactivate viewer
169   /// \param toActivate - activation flag
170   void activateViewer(bool toActivate);
171
172   // Methods for color scale management
173
174   //! Returns True if ColorScale is visible
175   virtual bool isColorScaleVisible() const;
176
177   //! Show/Hide ColorScale object
178   virtual void setColorScaleShown(bool on);
179
180   //! Set position of color scale
181   // \param theX is X position relative to current view width
182   // \param theY is Y position relative to current view heigth
183   virtual void setColorScalePosition(double theX, double theY);
184
185   //! Set size of color scale
186   // \param theW is width relative to current view width
187   // \param theh is height relative to current view heigth
188   virtual void setColorScaleSize(double theW, double theH);
189
190   //! Set range of color scale
191   // \param theMin is a minimal value
192   // \param theMax is a maximal value
193   virtual void setColorScaleRange(double theMin, double theMax);
194
195   //! Set number of intervals of color scale
196   // \param theNb is number of intervals
197   virtual void setColorScaleIntervals(int theNb);
198
199   //! Set text heigth of color scale
200   // \param theH is number of intervals
201   virtual void setColorScaleTextHeigth(int theH);
202
203   //! Set color of text of color scale
204   // \param theH is number of intervals
205   virtual void setColorScaleTextColor(const QColor& theColor);
206
207   //! Set title of color scale
208   // \param theText is a title
209   virtual void setColorScaleTitle(const QString& theText);
210
211   //! Sets the text displayed in right-top corner of the 3D view
212   //! \param theText the text to display, or empty string to erase presentation;
213   //!        the first item is the font name and text color
214   //! \param theSize size of the text font
215   virtual void setText(const ModuleBase_IViewer::TextColor& theText, const int theSize);
216
217   virtual void setFitter(OCCViewer_Fitter* theFitter);
218   virtual OCCViewer_Fitter* fitter() const;
219
220  private slots:
221   void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
222   void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*);
223   void onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*);
224   void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
225   void onKeyPress(SUIT_ViewWindow*, QKeyEvent*);
226   void onKeyRelease(SUIT_ViewWindow*, QKeyEvent*);
227
228   void onTryCloseView(SUIT_ViewWindow*);
229   void onDeleteView(SUIT_ViewWindow*);
230   void onViewCreated(SUIT_ViewWindow*);
231   void onActivated(SUIT_ViewManager*);
232
233   void onSelectionChanged();
234   void onViewTransformed(OCCViewer_ViewWindow::OperationType);
235
236   /// Emit signal about trihedron visiblity change because SALOME sets
237   /// the trihedron visible by this signal.
238   /// It is necessary to activate the viewer trihedron in the current selection mode
239   void onViewPortMapped();
240
241   /// Signal called in order to apdate viewer transformed objects
242   void onAfterViewCreated();
243
244  private:
245   SHAPERGUI_OCCSelector* mySelector;
246   SHAPERGUI_SalomeView* myView;
247   bool myIsSelectionChanged;
248   /// Presentation of names of all displayed SHAPER group results in 3D view,
249   /// a text in right-top corner of the view.
250   NCollection_List<Handle(AIS_TextLabel)> myText;
251 };
252
253
254 #endif