Salome HOME
Make branch compilable with newer version of SALOME
[modules/shaper.git] / src / SHAPERGUI / SHAPERGUI_SalomeViewer.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 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
41 /**
42 * \ingroup Salome
43 * A class for providing access of SHAPERGUI functionality to 
44 * SALOME view window functionality
45 */
46 class SHAPERGUI_SalomeView: public ModuleBase_IViewWindow
47 {
48 public:
49   /// Constructor
50   /// \param theViewer a reference to a viewer
51   SHAPERGUI_SalomeView(OCCViewer_Viewer* theViewer);
52
53   virtual Handle(V3d_View) v3dView() const;
54
55   /// Returns the view window view port
56   virtual QWidget* viewPort() const;
57
58   /// Set the current viewer
59   /// \param theViewer a viewer instance
60   void setViewer(OCCViewer_Viewer* theViewer) { myViewer = theViewer; }
61
62   /// Returns current viewer
63   OCCViewer_Viewer* viewer() const { return myViewer; }
64
65   /// Sets the current view
66   void setCurrentView(SUIT_ViewWindow* theView) { myCurrentView = theView; }
67
68 private:
69   /// A reference to a viewer
70   OCCViewer_Viewer* myViewer;
71   SUIT_ViewWindow* myCurrentView;
72 };
73
74
75 /**
76 * \ingroup Salome
77 * A class for providing access of SHAPERGUI functionality to 
78 * SALOME viewer functionality
79 */
80 class SHAPERGUI_SalomeViewer : public ModuleBase_IViewer
81 {
82 Q_OBJECT
83  public:
84    /// Constructor
85    /// \param theParent a parent object
86   SHAPERGUI_SalomeViewer(QObject* theParent);
87
88   ~SHAPERGUI_SalomeViewer();
89
90   //! Returns AIS_InteractiveContext from current OCCViewer
91   virtual Handle(AIS_InteractiveContext) AISContext() const;
92
93   //! Retrurns V3d_Vioewer from current viewer
94   virtual Handle(V3d_Viewer) v3dViewer() const;
95
96   //! Trihedron 3d object shown in the viewer
97   virtual Handle(AIS_Trihedron) trihedron() const;
98
99   //! Returns Vsd_View object from currently active view window
100   virtual Handle(V3d_View) activeView() const;
101
102   //! Returns viewer view port
103   virtual QWidget* activeViewPort() const;
104
105   //! Enable or disable selection in the viewer
106   virtual void enableSelection(bool isEnabled);
107
108   //! Returns true if selection is enabled
109   virtual bool isSelectionEnabled() const;
110
111   //! Enable or disable multiselection in the viewer
112   virtual void enableMultiselection(bool isEnable);
113
114   //! Returns true if multiselection is enabled
115   virtual bool isMultiSelectionEnabled() const;
116
117   //! Enable or disable draw mode in the viewer
118   virtual bool enableDrawMode(bool isEnabled);
119
120   //! For some signals it disconnects the window from usual signal and connect it to the module ones
121   void reconnectActions(SUIT_ViewWindow* theWindow, const bool theUseSHAPERSlot);
122
123   //! Perfroms the fit all for the active view
124   virtual void fitAll();
125
126   //! Erases all presentations from the viewer
127   virtual void eraseAll();
128
129   //! Sets the view projection
130   /// \param theX the X projection value
131   /// \param theY the Y projection value
132   /// \param theZ the Z projection value
133   /// \param theTwist the twist angle in radians
134   virtual void setViewProjection( double theX, double theY, double theZ,
135                                   double theTwist );
136
137   /// Set selector
138   /// \param theSel a selector instance
139   void setSelector(SHAPERGUI_OCCSelector* theSel);
140
141   /// Add selection filter to the viewer
142   virtual void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
143
144   /// Remove selection filter from the viewer
145   virtual void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
146
147   /// Returns true if the selection filter is set to the viewer
148   /// \param theFilter a selection filter
149   virtual bool hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
150
151   /// Remove all selection filters from the viewer
152   virtual void clearSelectionFilters();
153
154   /// Returns current selector
155   SHAPERGUI_OCCSelector* selector() const
156   {
157     return mySelector;
158   }
159
160   /// Update current viewer
161   virtual void update();
162
163   /// Method returns True if the viewer can process editing objects
164   /// by mouse drugging. If this is impossible thet it has to return False.
165   virtual bool canDragByMouse() const;
166
167   /// Activate or deactivate viewer
168   /// \param toActivate - activation flag
169   void activateViewer(bool toActivate);
170
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   virtual void setFitter(OCCViewer_Fitter* theFitter);
212   virtual OCCViewer_Fitter* fitter() const;
213
214   // Fit all along Z (perpendicular to display)
215   //virtual void Zfitall();
216
217  private slots:
218   void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
219   void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*);
220   void onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*);
221   void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
222   void onKeyPress(SUIT_ViewWindow*, QKeyEvent*);
223   void onKeyRelease(SUIT_ViewWindow*, QKeyEvent*);
224
225   void onTryCloseView(SUIT_ViewWindow*);
226   void onDeleteView(SUIT_ViewWindow*);
227   void onViewCreated(SUIT_ViewWindow*);
228   void onActivated(SUIT_ViewManager*);
229
230   void onSelectionChanged();
231   void onViewTransformed(OCCViewer_ViewWindow::OperationType);
232
233   /// Emit signal about trihedron visiblity change because SALOME sets
234   /// the trihedron visible by this signal.
235   /// It is necessary to activate the viewer trihedron in the current selection mode
236   void onViewPortMapped();
237
238  private:
239   SHAPERGUI_OCCSelector* mySelector;
240   SHAPERGUI_SalomeView* myView;
241   bool myIsSelectionChanged;
242 };
243
244
245 #endif