Salome HOME
updated copyright message
[modules/shaper.git] / src / XGUI / XGUI_ViewerProxy.h
1 // Copyright (C) 2014-2023  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   //! Sets the text displayed in right-top corner of the 3D view
170   //! \param theText the text to display, or empty string to erase presentation;
171   //!        the first item is the font name and text color
172   //! \param theSize size of the text font
173   virtual void setText(const ModuleBase_IViewer::TextColor& theText, const int theSize);
174
175   // Fit all along Z (perpendicular to display)
176   //virtual void Zfitall();
177
178 #ifdef HAVE_SALOME
179   virtual void setFitter(OCCViewer_Fitter* theFitter);
180   virtual OCCViewer_Fitter* fitter() const;
181 #else
182   virtual void setFitter(AppElements_Fitter* theFitter);
183   virtual AppElements_Fitter* fitter() const;
184 #endif
185
186 signals:
187   /// Emits by mouse entering the view port
188   void enterViewPort();
189
190   /// Emits by mouse leaving of the view port
191   void leaveViewPort();
192
193 protected:
194   /// processes the application signals to catch the mouse leaving state of the main window
195   /// \param theObject
196   /// \param theEvent
197   bool eventFilter(QObject *theObject, QEvent *theEvent);
198
199 private slots:
200   void onViewCreated(ModuleBase_IViewWindow* theWnd);
201
202 #ifndef HAVE_SALOME
203   void onTryCloseView(AppElements_ViewWindow*);
204   void onDeleteView(AppElements_ViewWindow*);
205   void onViewCreated(AppElements_ViewWindow*);
206   void onActivated(AppElements_ViewWindow*);
207
208   void onMousePress(AppElements_ViewWindow*, QMouseEvent*);
209   void onMouseRelease(AppElements_ViewWindow*, QMouseEvent*);
210   void onMouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*);
211   void onMouseMove(AppElements_ViewWindow*, QMouseEvent*);
212
213   void onKeyPress(AppElements_ViewWindow*, QKeyEvent*);
214   void onKeyRelease(AppElements_ViewWindow*, QKeyEvent*);
215
216   void onViewTransformed(AppElements_ViewWindow::OperationType);
217 #else
218   void onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*);
219   void onKeyPress(ModuleBase_IViewWindow*, QKeyEvent*);
220   void onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*);
221 #endif
222
223  private:
224    void displayHighlight(FeaturePtr theFeature, const TopoDS_Shape& theIgnoreShape);
225    bool eraseHighlight();
226    void createPresentations(const ResultPtr& theRes, const TopoDS_Shape& theIgnoreShape);
227
228
229   XGUI_Workshop* myWorkshop;
230   ResultPtr myResult;
231   AIS_ListOfInteractive myHighlights;
232
233 };
234
235 #endif