Salome HOME
Copyright update 2020
[modules/shaper.git] / src / XGUI / XGUI_ViewerProxy.h
1 // Copyright (C) 2014-2020  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 XGUI_VIEWERPROXY_H
21 #define XGUI_VIEWERPROXY_H
22
23 #include "XGUI.h"
24 #include <ModuleBase_IViewer.h>
25 #include <ModelAPI_Feature.h>
26 #include <ModelAPI_Result.h>
27
28 #include <AIS_Trihedron.hxx>
29 #include <AIS_ListOfInteractive.hxx>
30
31 #ifdef HAVE_SALOME
32 #include <OCCViewer_ViewModel.h>
33 #else
34   #include <AppElements_Viewer.h>
35   #include <AppElements_ViewWindow.h>
36 #endif
37
38
39
40 class XGUI_Workshop;
41 /**
42  * \ingroup GUI
43  * Proxy class which repersents or AppElements_Viewer or Salome Viewer
44  * dependently on current launching environment.
45  * It is reccomennded to use this class in operation for accessing to viewer 
46  * functionality instead of direct access to a viewer
47  */
48 class XGUI_EXPORT XGUI_ViewerProxy : public ModuleBase_IViewer
49 {
50 Q_OBJECT
51  public:
52    /// Constructor
53    /// \param theParent a parent object
54   XGUI_ViewerProxy(XGUI_Workshop* theParent);
55
56   /// Connects some signals to the viewer from the module connector
57   void connectViewProxy();
58
59   //! Returns AIS_InteractiveContext from current OCCViewer
60   virtual Handle(AIS_InteractiveContext) AISContext() const;
61
62   //! Trihedron 3d object shown in the viewer
63   virtual Handle(AIS_Trihedron) trihedron() const;
64
65   //! Retrurns V3d_Vioewer from current viewer
66   virtual Handle(V3d_Viewer) v3dViewer() const;
67
68   //! Returns Vsd_View object from currently active view window
69   virtual Handle(V3d_View) activeView() const;
70
71   virtual QWidget* activeViewPort() const;
72
73   //! Enable or disable selection in the viewer
74   virtual void enableSelection(bool isEnabled);
75
76   //! Returns true if selection is enabled
77   virtual bool isSelectionEnabled() const;
78
79   //! Enable or disable multiselection in the viewer
80   virtual void enableMultiselection(bool isEnable);
81
82   //! Returns true if multiselection is enabled
83   virtual bool isMultiSelectionEnabled() const;
84
85   //! Enable or disable draw mode in the viewer
86   virtual bool enableDrawMode(bool isEnabled);
87
88   //! Sets the view projection
89   /// \param theX the X projection value
90   /// \param theY the Y projection value
91   /// \param theZ the Z projection value
92   /// \param theTwist the twist angle in radians
93   virtual void setViewProjection( double theX, double theY, double theZ,
94                                   double theTwist );
95
96   //! Sets the view fitted all
97   virtual void fitAll();
98
99   //! Erases all presentations from the viewer
100   virtual void eraseAll();
101
102   /// Connects to a viewer according to current environment
103   void connectToViewer();
104
105   /// Add selection filter to the viewer
106   virtual void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
107
108   /// Remove selection filter from the viewer
109   virtual void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
110
111   /// Returns true if the selection filter is set to the viewer
112   /// \param theFilter a selection filter
113   virtual bool hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
114
115   /// Remove all selection filters from the viewer
116   virtual void clearSelectionFilters();
117
118   /// Update current viewer
119   virtual void update();
120
121   /// Method returns True if the viewer can process editing objects
122   /// by mouse drugging. If this is impossible thet it has to return False.
123   virtual bool canDragByMouse() const;
124
125   virtual void updateHighlight();
126
127   // Methods for color scale management
128
129   //! Returns True if ColorScale is visible
130   virtual bool isColorScaleVisible() const;
131
132   //! Show/Hide ColorScale object
133   virtual void setColorScaleShown(bool on);
134
135   //! Set position of color scale
136   // \param theX is X position relative to current view width
137   // \param theY is Y position relative to current view heigth
138   virtual void setColorScalePosition(double theX, double theY);
139
140   //! Set size of color scale
141   // \param theW is width relative to current view width
142   // \param theh is height relative to current view heigth
143   virtual void setColorScaleSize(double theW, double theH);
144
145   //! Set range of color scale
146   // \param theMin is a minimal value
147   // \param theMax is a maximal value
148   virtual void setColorScaleRange(double theMin, double theMax);
149
150   //! Set number of intervals of color scale
151   // \param theNb is number of intervals
152   virtual void setColorScaleIntervals(int theNb);
153
154   //! Set text heigth of color scale
155   // \param theH is number of intervals
156   virtual void setColorScaleTextHeigth(int theH);
157
158   //! Set color of text of color scale
159   // \param theH is number of intervals
160   virtual void setColorScaleTextColor(const QColor& theColor);
161
162   //! Set title of color scale
163   // \param theText is a title
164   virtual void setColorScaleTitle(const QString& theText);
165
166   //! Set color scale parameters according to user preferences and window size
167   void setupColorScale();
168
169   // Fit all along Z (perpendicular to display)
170   //virtual void Zfitall();
171
172 #ifdef HAVE_SALOME
173   virtual void setFitter(OCCViewer_Fitter* theFitter);
174   virtual OCCViewer_Fitter* fitter() const;
175 #else
176   virtual void setFitter(AppElements_Fitter* theFitter);
177   virtual AppElements_Fitter* fitter() const;
178 #endif
179
180 signals:
181   /// Emits by mouse entering the view port
182   void enterViewPort();
183
184   /// Emits by mouse leaving of the view port
185   void leaveViewPort();
186
187 protected:
188   /// processes the application signals to catch the mouse leaving state of the main window
189   /// \param theObject
190   /// \param theEvent
191   bool eventFilter(QObject *theObject, QEvent *theEvent);
192
193 private slots:
194   void onViewCreated(ModuleBase_IViewWindow* theWnd);
195
196 #ifndef HAVE_SALOME
197   void onTryCloseView(AppElements_ViewWindow*);
198   void onDeleteView(AppElements_ViewWindow*);
199   void onViewCreated(AppElements_ViewWindow*);
200   void onActivated(AppElements_ViewWindow*);
201
202   void onMousePress(AppElements_ViewWindow*, QMouseEvent*);
203   void onMouseRelease(AppElements_ViewWindow*, QMouseEvent*);
204   void onMouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*);
205   void onMouseMove(AppElements_ViewWindow*, QMouseEvent*);
206
207   void onKeyPress(AppElements_ViewWindow*, QKeyEvent*);
208   void onKeyRelease(AppElements_ViewWindow*, QKeyEvent*);
209
210   void onViewTransformed(AppElements_ViewWindow::OperationType);
211 #else
212   void onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*);
213   void onKeyPress(ModuleBase_IViewWindow*, QKeyEvent*);
214   void onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*);
215 #endif
216
217  private:
218    void displayHighlight(FeaturePtr theFeature, const TopoDS_Shape& theIgnoreShape);
219    bool eraseHighlight();
220
221
222   XGUI_Workshop* myWorkshop;
223   ResultPtr myResult;
224   AIS_ListOfInteractive myHighlights;
225
226 };
227
228 #endif