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