Salome HOME
1623bdc2d113e23904158b470d3623d9efcdba35
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewModel.h
1 // Copyright (C) 2007-2023  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_ViewCube.hxx>
41 #include <AIS_InteractiveContext.hxx>
42 #include <AIS_ListOfInteractive.hxx>
43 #include <Graphic3d_SequenceOfHClipPlane.hxx>
44
45 #include <Basics_OCCTVersion.hxx>
46
47 class QKeyEvent;
48 class QMouseEvent;
49
50 class SUIT_ViewWindow;
51 class SUIT_Desktop;
52 class OCCViewer_ClippingDlg;
53 class OCCViewer_ViewWindow;
54 class OCCViewer_ViewPort3d;
55
56 class QtxAction;
57
58
59 #ifdef WIN32
60 #pragma warning( disable:4251 )
61 #endif
62
63 /**
64 An object wich provides alternative way to fit scene in a view
65 */
66 class OCCViewer_Fitter
67 {
68 public:
69   /// A method which has top be reimplemented to provide alterantive implementation FitAll command
70   /// \param theView - a view which has to be fit
71   virtual void fitAll(Handle(V3d_View) theView) = 0;
72 };
73
74
75
76 class OCCVIEWER_EXPORT OCCViewer_Viewer: public SUIT_ViewModel
77 {
78   Q_OBJECT
79
80 public:
81   /*! supported gradient types */
82   enum { 
83     HorizontalGradient, VerticalGradient,
84     Diagonal1Gradient,  Diagonal2Gradient,
85     Corner1Gradient,    Corner2Gradient,
86     Corner3Gradient,    Corner4Gradient,
87     LastGradient = Corner4Gradient
88   };
89   /*! supported stereo types */
90   enum {
91     QuadBufferType,    AnaglyphType,
92     RowInterlacedType, ColumnInterlacedType,
93     ChessBoardType,    SideBySideType,
94     OverUnderType
95   };
96   
97   static QString           Type() { return "OCCViewer"; }
98   static QString           backgroundData( QStringList&, QIntList&, QIntList& );
99   static void              stereoData( QStringList&, QIntList&);
100
101   OCCViewer_Viewer( bool DisplayTrihedron = true);
102   virtual ~OCCViewer_Viewer();
103
104   void update();
105
106   virtual SUIT_ViewWindow*        createView(SUIT_Desktop* theDesktop);
107   
108   virtual void                    setViewManager(SUIT_ViewManager* theViewManager);
109   virtual QString                 getType() const { return Type(); }
110
111   virtual void                    contextMenuPopup(QMenu*);
112   
113   void                            getSelectedObjects(AIS_ListOfInteractive& theList);
114   void                            setObjectsSelected(const AIS_ListOfInteractive& theList);
115   void                            setSelected(const Handle(AIS_InteractiveObject)& theIO) { myAISContext->SetSelected(theIO,Standard_True);}
116
117   void                            performSelectionChanged();
118   // emit signal selectionChanged
119
120   void                            setDefaultLights();
121
122   QColor                          backgroundColor() const;                              // obsolete
123   void                            setBackgroundColor( const QColor& );                  // obsolete
124   Qtx::BackgroundData             background() const;
125   void                            setBackground( const Qtx::BackgroundData& );
126
127   QColor                          backgroundColor(int theViewId) const;                 // obsolete
128   void                            setBackgroundColor( int theViewId, const QColor& );   // obsolete
129   Qtx::BackgroundData             background(int theViewId) const;
130   void                            setBackground( int theViewId, const Qtx::BackgroundData& );
131
132   bool                            isColorScaleVisible() const;
133   virtual void                    setColorScaleShown( const bool );
134
135   //! returns true if 3d Trihedron in viewer was created
136   bool                            trihedronActivated() const { return !myTrihedron.IsNull(); }
137
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   // View Cube methods
153   bool                            viewCubeActivated() const { return !myViewCube.IsNull(); }
154   bool                            isViewCubeVisible() const;
155   virtual void                    setViewCubeShown( const bool );
156   void                            setViewCubeParamsFromPreferences();
157
158   virtual OCCViewer_ViewWindow*   createSubWindow();
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   Handle(AIS_ViewCube)            getViewCube()    const { return myViewCube; }
178
179   int                             getTopLayerId();
180
181   int                             interactionStyle() const;
182   void                            setInteractionStyle( const int );
183
184   int                             projectionType() const;
185   void                            setProjectionType( const int );
186   int                             stereoType() const;
187   void                            setStereoType( const int );
188
189   OCCViewer_ViewWindow::SelectionStyle selectionStyle() const;
190   void                            setSelectionStyle(OCCViewer_ViewWindow::SelectionStyle);
191
192   int                             anaglyphFilter() const;
193   void                            setAnaglyphFilter( const int );
194
195   void                            setStereographicFocus( const int, const double );
196   int                             stereographicFocusType() const;
197   double                          stereographicFocusValue() const;
198
199   void                            setInterocularDistance( const int, const double );
200   int                             interocularDistanceType() const;
201   double                          interocularDistanceValue() const;
202
203   bool                            isReverseStereo() const;
204   void                            setReverseStereo( const bool );
205
206   bool                            isVSync() const;
207   void                            setVSync( const bool );
208
209   bool                            isQuadBufferSupport() const;
210   void                            setQuadBufferSupport( const bool );
211   int                             zoomingStyle() const;
212   void                            setZoomingStyle( const int );
213
214   void                            enablePreselection(bool isEnabled);
215   bool                            isPreselectionEnabled() const;
216   
217   void                            enableSelection(bool isEnabled);
218   bool                            isSelectionEnabled() const;
219
220   void                            setSelectionOptions( bool, bool );
221
222   void                            enableMultiselection(bool isEnable);
223   bool                            isMultiSelectionEnabled() const { return myMultiSelectionEnabled; }
224
225   bool                            enableDrawMode( bool on );
226
227   void                            setClippingColor( const QColor& );
228   QColor                          clippingColor() const;
229
230   void                            setClippingTextureParams( const bool, const QString&, const bool, const double );
231   bool                            isDefaultTextureUsed() const;
232   QString                         clippingTexture() const;
233   bool                            isTextureModulated() const;
234   double                          clippingTextureScale() const;
235
236   int                             getSelectionCount() const { return (!myAISContext.IsNull())? myAISContext->NbSelected():0; }
237
238   void                            setStaticTrihedronDisplayed(const bool on);
239
240   /* Clip planes management */
241   Handle(Graphic3d_ClipPlane)     createClipPlane(const gp_Pln& thePlane, const Standard_Boolean theIsOn);
242   void                            setClipPlanes (ClipPlanesList theList);
243   ClipPlanesList                  getClipPlanes() const;
244   void                            applyExistingClipPlanesToObject (const Handle(AIS_InteractiveObject)& theObject);
245
246   OCCViewer_ClippingDlg*          getClippingDlg() const;
247   void                            setClippingDlg(OCCViewer_ClippingDlg* theDlg);
248   
249
250   /* Selection management */
251   bool    highlight( const Handle(AIS_InteractiveObject)&, bool, bool=true );
252   bool    unHighlightAll( bool=true, bool=true ); 
253   bool    isInViewer( const Handle(AIS_InteractiveObject)&, bool=false );
254   bool    isVisible( const Handle(AIS_InteractiveObject)& );
255
256   void    setColor( const Handle(AIS_InteractiveObject)&, const QColor&, bool=true );
257   void    switchRepresentation( const Handle(AIS_InteractiveObject)&, int, bool=true );
258   void    setTransparency( const Handle(AIS_InteractiveObject)&, float, bool=true );
259   void    setIsos( const int u, const int v ); // number of isolines
260   void    isos( int& u, int& v ) const;
261
262   void    initView( OCCViewer_ViewWindow* view );
263
264 signals:
265   void selectionChanged();
266   void deselection();
267
268 protected slots:
269   virtual void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
270   virtual void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
271   virtual void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*);
272   virtual void onKeyPress(SUIT_ViewWindow*, QKeyEvent*);
273   virtual void onViewClosed(OCCViewer_ViewPort3d*);
274   virtual void onViewMapped(OCCViewer_ViewPort3d*);
275
276   void onDumpView();
277   void onChangeBackground();
278
279 protected:
280
281   Handle(V3d_Viewer)              myV3dViewer;
282   Handle(AIS_ColorScale)          myColorScale;
283   Handle(AIS_Trihedron)           myTrihedron;
284   Handle(AIS_ViewCube)            myViewCube;
285   Handle(AIS_InteractiveContext)  myAISContext;
286
287   int                             myInteractionStyle;
288   int                             myZoomingStyle;
289   int                             myProjectionType;
290   int                             myStereoType;
291   int                             myAnaglyphFilter;
292   int                             myStereographicFocusType;
293   int                             myInterocularDistanceType;
294   OCCViewer_ViewWindow::SelectionStyle mySelectionStyle;
295
296   double                          myStereographicFocusValue;
297   double                          myInterocularDistanceValue;
298
299   bool                            myPreselectionEnabled;
300   bool                            mySelectionEnabled;
301   bool                            myMultiSelectionEnabled;
302   bool                            myIsRelative;
303   bool                            myToReverseStereo;
304   bool                            myVSyncMode;
305   bool                            myQuadBufferSupport;
306
307   int                             myTopLayerId;
308
309   //QColor                          myBgColor;
310   QPoint                          myStartPnt, myEndPnt, myCurPnt;
311
312   double                          myTrihedronSize;
313
314   QVector<Qtx::BackgroundData>    myBackgrounds;
315
316   OCCViewer_ClippingDlg*          myClippingDlg;
317
318   ClipPlanesList                  myClipPlanes;
319   Graphic3d_SequenceOfHClipPlane  myInternalClipPlanes;
320
321   QColor                          myClippingColor;
322   bool                            myDefaultTextureUsed;
323   QString                         myClippingTexture;
324   bool                            myTextureModulated;
325   double                          myClippingTextureScale;
326
327   OCCViewer_Fitter* myFitter;
328 };
329
330 #ifdef WIN32
331 #pragma warning( default:4251 )
332 #endif
333
334 #endif