Salome HOME
114ae093e7d8bef2598dddfed6ea01e2acc0b502
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewModel.h
1 // Copyright (C) 2007-2020  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef OCCVIEWER_VIEWMODEL_H
24 #define OCCVIEWER_VIEWMODEL_H
25
26 #include <QColor>
27 #include <QPoint>
28 #include <QVector>
29
30 #include "OCCViewer.h"
31 #include "OCCViewer_ClipPlane.h"
32 #include "OCCViewer_ViewWindow.h"
33
34 #include "Qtx.h"
35 #include "SUIT_ViewModel.h"
36
37 #include <V3d_View.hxx>
38 #include <AIS_ColorScale.hxx>
39 #include <AIS_Trihedron.hxx>
40 #include <AIS_InteractiveContext.hxx>
41 #include <AIS_ListOfInteractive.hxx>
42 #include <Graphic3d_SequenceOfHClipPlane.hxx>
43
44 #include <Basics_OCCTVersion.hxx>
45
46 class QKeyEvent;
47 class QMouseEvent;
48
49 class SUIT_ViewWindow;
50 class SUIT_Desktop;
51 class OCCViewer_ClippingDlg;
52 class OCCViewer_ViewWindow;
53 class OCCViewer_ViewPort3d;
54
55 class QtxAction;
56
57
58 #ifdef WIN32
59 #pragma warning( disable:4251 )
60 #endif
61
62 /**
63 An object wich provides alternative way to fit scene in a view
64 */
65 class OCCViewer_Fitter
66 {
67 public:
68   /// A method which has top be reimplemented to provide alterantive implementation FitAll command
69   /// \param theView - a view which has to be fit
70   virtual void fitAll(Handle(V3d_View) theView) = 0;
71 };
72
73
74
75 class OCCVIEWER_EXPORT OCCViewer_Viewer: public SUIT_ViewModel
76 {
77   Q_OBJECT
78
79 public:
80   /*! supported gradient types */
81   enum { 
82     HorizontalGradient, VerticalGradient,
83     Diagonal1Gradient,  Diagonal2Gradient,
84     Corner1Gradient,    Corner2Gradient,
85     Corner3Gradient,    Corner4Gradient,
86     LastGradient = Corner4Gradient
87   };
88   /*! supported stereo types */
89   enum {
90     QuadBufferType,    AnaglyphType,
91     RowInterlacedType, ColumnInterlacedType,
92     ChessBoardType,    SideBySideType,
93     OverUnderType
94   };
95   
96   static QString           Type() { return "OCCViewer"; }
97   static QString           backgroundData( QStringList&, QIntList&, QIntList& );
98   static void              stereoData( QStringList&, QIntList&);
99
100   OCCViewer_Viewer( bool DisplayTrihedron = true);
101   virtual ~OCCViewer_Viewer();
102
103   void update();
104
105   virtual SUIT_ViewWindow*        createView(SUIT_Desktop* theDesktop);
106   
107   virtual void                    setViewManager(SUIT_ViewManager* theViewManager);
108   virtual QString                 getType() const { return Type(); }
109
110   virtual void                    contextMenuPopup(QMenu*);
111   
112   void                            getSelectedObjects(AIS_ListOfInteractive& theList);
113   void                            setObjectsSelected(const AIS_ListOfInteractive& theList);
114   void                            setSelected(const Handle(AIS_InteractiveObject)& theIO) { myAISContext->SetSelected(theIO,Standard_True);}
115
116   void                            performSelectionChanged();
117   // emit signal selectionChanged
118
119   void                            setDefaultLights();
120
121   QColor                          backgroundColor() const;                              // obsolete
122   void                            setBackgroundColor( const QColor& );                  // obsolete
123   Qtx::BackgroundData             background() const;
124   void                            setBackground( const Qtx::BackgroundData& );
125
126   QColor                          backgroundColor(int theViewId) const;                 // obsolete
127   void                            setBackgroundColor( int theViewId, const QColor& );   // obsolete
128   Qtx::BackgroundData             background(int theViewId) const;
129   void                            setBackground( int theViewId, const Qtx::BackgroundData& );
130
131   bool                            isColorScaleVisible() const;
132   virtual void                    setColorScaleShown( const bool );
133
134   //! returns true if 3d Trihedron in viewer was created
135   bool                            trihedronActivated() const { return !myTrihedron.IsNull(); }
136
137   void                            toggleTrihedron();
138   bool                            isTrihedronVisible() const;
139   virtual void                    setTrihedronShown( const bool );
140
141   double                          trihedronSize() const;
142   virtual void                    setTrihedronSize( const double , bool isRelative = true);
143   
144   bool                            trihedronRelative() const {return myIsRelative; }
145
146   // a utility functions, used by SALOME_View_s methods
147   bool                            computeTrihedronSize( double& theNewSize, double& theSize );
148   virtual double                  computeSceneSize(const Handle(V3d_View)&) const;
149
150   void                            updateTrihedron();
151   
152
153   virtual OCCViewer_ViewWindow*   createSubWindow();
154
155 #if OCC_VERSION_LARGE <= 0x07030000
156   void                            setUseLocalSelection(bool theIsUseLocalSelection);
157   bool                            useLocalSelection() const;
158 #endif
159
160   // Methods to access fitter
161
162   /// Returns currently installed fitter
163   OCCViewer_Fitter* fitter() const { return myFitter; }
164
165   /// Installs new fitter
166   /// \param theFitter a new fitter
167   void setFitter(OCCViewer_Fitter* theFitter) {
168     myFitter = theFitter;
169   }
170
171
172 public:
173   Handle(V3d_Viewer)              getViewer3d()    const { return myV3dViewer;}
174   Handle(AIS_InteractiveContext)  getAISContext()  const { return myAISContext; }
175   Handle(AIS_ColorScale)          getColorScale()  const { return myColorScale; }
176   Handle(AIS_Trihedron)           getTrihedron()   const { return myTrihedron; }
177
178   int                             getTopLayerId();
179
180   int                             interactionStyle() const;
181   void                            setInteractionStyle( const int );
182
183   int                             projectionType() const;
184   void                            setProjectionType( const int );
185   int                             stereoType() const;
186   void                            setStereoType( const int );
187
188   OCCViewer_ViewWindow::SelectionStyle selectionStyle() const;
189   void                            setSelectionStyle(OCCViewer_ViewWindow::SelectionStyle);
190
191   int                             anaglyphFilter() const;
192   void                            setAnaglyphFilter( const int );
193
194   void                            setStereographicFocus( const int, const double );
195   int                             stereographicFocusType() const;
196   double                          stereographicFocusValue() const;
197
198   void                            setInterocularDistance( const int, const double );
199   int                             interocularDistanceType() const;
200   double                          interocularDistanceValue() const;
201
202   bool                            isReverseStereo() const;
203   void                            setReverseStereo( const bool );
204
205   bool                            isVSync() const;
206   void                            setVSync( const bool );
207
208   bool                            isQuadBufferSupport() const;
209   void                            setQuadBufferSupport( const bool );
210   int                             zoomingStyle() const;
211   void                            setZoomingStyle( const int );
212
213   void                            enablePreselection(bool isEnabled);
214   bool                            isPreselectionEnabled() const;
215   
216   void                            enableSelection(bool isEnabled);
217   bool                            isSelectionEnabled() const;
218
219   void                            setSelectionOptions( bool, bool );
220
221   void                            enableMultiselection(bool isEnable);
222   bool                            isMultiSelectionEnabled() const { return myMultiSelectionEnabled; }
223
224   bool                            enableDrawMode( bool on );
225
226   void                            setClippingColor( const QColor& );
227   QColor                          clippingColor() const;
228
229   void                            setClippingTextureParams( const bool, const QString&, const bool, const double );
230   bool                            isDefaultTextureUsed() const;
231   QString                         clippingTexture() const;
232   bool                            isTextureModulated() const;
233   double                          clippingTextureScale() const;
234
235   int                             getSelectionCount() const { return (!myAISContext.IsNull())? myAISContext->NbSelected():0; }
236
237   void                            setStaticTrihedronDisplayed(const bool on);
238
239   /* Clip planes management */
240   Handle(Graphic3d_ClipPlane)     createClipPlane(const gp_Pln& thePlane, const Standard_Boolean theIsOn);
241   void                            setClipPlanes (ClipPlanesList theList);
242   ClipPlanesList                  getClipPlanes() const;
243   void                            applyExistingClipPlanesToObject (const Handle(AIS_InteractiveObject)& theObject);
244
245   OCCViewer_ClippingDlg*          getClippingDlg() const;
246   void                            setClippingDlg(OCCViewer_ClippingDlg* theDlg);
247   
248
249   /* Selection management */
250   bool    highlight( const Handle(AIS_InteractiveObject)&, bool, bool=true );
251   bool    unHighlightAll( bool=true, bool=true ); 
252   bool    isInViewer( const Handle(AIS_InteractiveObject)&, bool=false );
253   bool    isVisible( const Handle(AIS_InteractiveObject)& );
254
255   void    setColor( const Handle(AIS_InteractiveObject)&, const QColor&, bool=true );
256   void    switchRepresentation( const Handle(AIS_InteractiveObject)&, int, bool=true );
257   void    setTransparency( const Handle(AIS_InteractiveObject)&, float, bool=true );
258   void    setIsos( const int u, const int v ); // number of isolines
259   void    isos( int& u, int& v ) const;
260
261   void    initView( OCCViewer_ViewWindow* view );
262
263   /// Sets a flag to ignore mouse release for selection. Used for Rectangle/Polygon selection
264   void    doNotSelect() { mySelectionDone = true; }
265
266 signals:
267   void selectionChanged();
268   void deselection();
269
270 protected slots:
271   virtual void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
272   virtual void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
273   virtual void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*);
274   virtual void onKeyPress(SUIT_ViewWindow*, QKeyEvent*);
275   virtual void onViewClosed(OCCViewer_ViewPort3d*);
276   virtual void onViewMapped(OCCViewer_ViewPort3d*);
277
278   void onDumpView();
279   void onChangeBackground();
280
281 protected:
282
283   Handle(V3d_Viewer)              myV3dViewer;
284   Handle(AIS_ColorScale)          myColorScale;
285   Handle(AIS_Trihedron)           myTrihedron;
286   Handle(AIS_InteractiveContext)  myAISContext;
287
288   int                             myInteractionStyle;
289   int                             myZoomingStyle;
290   int                             myProjectionType;
291   int                             myStereoType;
292   int                             myAnaglyphFilter;
293   int                             myStereographicFocusType;
294   int                             myInterocularDistanceType;
295   OCCViewer_ViewWindow::SelectionStyle mySelectionStyle;
296
297   double                          myStereographicFocusValue;
298   double                          myInterocularDistanceValue;
299
300   bool                            myPreselectionEnabled;
301   bool                            mySelectionEnabled;
302   bool                            myMultiSelectionEnabled;
303   bool                            myIsRelative;
304   bool                            myToReverseStereo;
305   bool                            myVSyncMode;
306   bool                            myQuadBufferSupport;
307
308   int                             myTopLayerId;
309
310   //QColor                          myBgColor;
311   QPoint                          myStartPnt, myEndPnt, myCurPnt;
312
313   double                          myTrihedronSize;
314
315   QVector<Qtx::BackgroundData>    myBackgrounds;
316
317   OCCViewer_ClippingDlg*          myClippingDlg;
318
319   ClipPlanesList                  myClipPlanes;
320   Graphic3d_SequenceOfHClipPlane  myInternalClipPlanes;
321
322   QColor                          myClippingColor;
323   bool                            myDefaultTextureUsed;
324   QString                         myClippingTexture;
325   bool                            myTextureModulated;
326   double                          myClippingTextureScale;
327 #if OCC_VERSION_LARGE <= 0x07030000
328   bool                            myIsUseLocalSelection;
329 #endif
330
331   OCCViewer_Fitter* myFitter;
332   bool mySelectionDone;
333 };
334
335 #ifdef WIN32
336 #pragma warning( default:4251 )
337 #endif
338
339 #endif