Salome HOME
0023124: EDF 11219 GEOM: Ray tracing in the OCC viewer
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewModel.h
1 // Copyright (C) 2007-2015  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
33 #include "Qtx.h"
34 #include "SUIT_ViewModel.h"
35
36 #include <V3d_View.hxx>
37 #include <AIS_Trihedron.hxx>
38 #include <AIS_InteractiveContext.hxx>
39 #include <Graphic3d_SequenceOfHClipPlane.hxx>
40
41 class QKeyEvent;
42 class QMouseEvent;
43
44 class SUIT_ViewWindow;
45 class SUIT_Desktop;
46 class OCCViewer_ClippingDlg;
47 class OCCViewer_ViewWindow;
48 class OCCViewer_ViewPort3d;
49
50 class AIS_ListOfInteractive;
51
52 class QtxAction;
53
54
55 #ifdef WIN32
56 #pragma warning( disable:4251 )
57 #endif
58
59 class OCCVIEWER_EXPORT OCCViewer_Viewer: public SUIT_ViewModel
60 {
61   Q_OBJECT
62
63 public:
64   /*! supported gradient types */
65   enum { 
66     HorizontalGradient, VerticalGradient,
67     Diagonal1Gradient,  Diagonal2Gradient,
68     Corner1Gradient,    Corner2Gradient,
69     Corner3Gradient,    Corner4Gradient,
70     LastGradient = Corner4Gradient
71   };
72   /*! supported stereo types */
73   enum {
74     QuadBufferType,    AnaglyphType,
75     RowInterlacedType, ColumnInterlacedType,
76     ChessBoardType,    SideBySideType,
77     OverUnderType
78   };
79   
80   static QString           Type() { return "OCCViewer"; }
81   static QString           backgroundData( QStringList&, QIntList&, QIntList& );
82   static void              stereoData( QStringList&, QIntList&);
83
84   OCCViewer_Viewer( bool DisplayTrihedron = true);
85   virtual ~OCCViewer_Viewer();
86
87   void update();
88
89   virtual SUIT_ViewWindow*        createView(SUIT_Desktop* theDesktop);
90   
91   virtual void                    setViewManager(SUIT_ViewManager* theViewManager);
92   virtual QString                 getType() const { return Type(); }
93
94   virtual void                    contextMenuPopup(QMenu*);
95   
96   void                            getSelectedObjects(AIS_ListOfInteractive& theList);
97   void                            setObjectsSelected(const AIS_ListOfInteractive& theList);
98   void                            setSelected(const Handle(AIS_InteractiveObject)& theIO) { myAISContext->SetSelected(theIO);}
99
100   void                            performSelectionChanged();
101   // emit signal selectionChanged
102
103   void                            setDefaultLights();
104
105   QColor                          backgroundColor() const;                              // obsolete
106   void                            setBackgroundColor( const QColor& );                  // obsolete
107   Qtx::BackgroundData             background() const;
108   void                            setBackground( const Qtx::BackgroundData& );
109
110   QColor                          backgroundColor(int theViewId) const;                 // obsolete
111   void                            setBackgroundColor( int theViewId, const QColor& );   // obsolete
112   Qtx::BackgroundData             background(int theViewId) const;
113   void                            setBackground( int theViewId, const Qtx::BackgroundData& );
114
115   //! returns true if 3d Trihedron in viewer was created
116   bool                            trihedronActivated() const { return !myTrihedron.IsNull(); }
117
118   void                            toggleTrihedron();
119   bool                            isTrihedronVisible() const;
120   virtual void                    setTrihedronShown( const bool );
121
122   double                          trihedronSize() const;
123   virtual void                    setTrihedronSize( const double , bool isRelative = true);
124   
125   bool                            trihedronRelative() const {return myIsRelative; }
126
127   // a utility functions, used by SALOME_View_s methods
128   bool                            computeTrihedronSize( double& theNewSize, double& theSize );
129   virtual double                  computeSceneSize(const Handle(V3d_View)&) const;
130
131   void                            updateTrihedron();
132   
133
134   virtual OCCViewer_ViewWindow*   createSubWindow();
135
136 public:
137   Handle(V3d_Viewer)              getViewer3d()    const { return myV3dViewer;}
138   Handle(AIS_InteractiveContext)  getAISContext()  const { return myAISContext; }
139   Handle(AIS_Trihedron)           getTrihedron()   const { return myTrihedron; }
140
141   int                             getTopLayerId();
142
143   int                             interactionStyle() const;
144   void                            setInteractionStyle( const int );
145
146   int                             projectionType() const;
147   void                            setProjectionType( const int );
148   int                             stereoType() const;
149   void                            setStereoType( const int );
150
151   int                             anaglyphFilter() const;
152   void                            setAnaglyphFilter( const int );
153
154   void                            setStereographicFocus( const int, const double );
155   int                             stereographicFocusType() const;
156   double                          stereographicFocusValue() const;
157
158   void                            setInterocularDistance( const int, const double );
159   int                             interocularDistanceType() const;
160   double                          interocularDistanceValue() const;
161
162   bool                            isReverseStereo() const;
163   void                            setReverseStereo( const bool );
164
165   bool                            isVSync() const;
166   void                            setVSync( const bool );
167
168   bool                            isQuadBufferSupport() const;
169   void                            setQuadBufferSupport( const bool );
170   int                             zoomingStyle() const;
171   void                            setZoomingStyle( const int );
172
173   void                            enablePreselection(bool isEnabled);
174   bool                            isPreselectionEnabled() const;
175   
176   void                            enableSelection(bool isEnabled);
177   bool                            isSelectionEnabled() const;
178
179   void                            setSelectionOptions( bool, bool );
180
181   void                            enableMultiselection(bool isEnable);
182   bool                            isMultiSelectionEnabled() const { return myMultiSelectionEnabled; }
183
184   bool                            enableDrawMode( bool on );
185
186   void                            setClippingColor( const QColor& );
187   QColor                          clippingColor() const;
188
189   void                            setClippingTextureParams( const bool, const QString&, const bool, const double );
190   bool                            isDefaultTextureUsed() const;
191   QString                         clippingTexture() const;
192   bool                            isTextureModulated() const;
193   double                          clippingTextureScale() const;
194
195   int                             getSelectionCount() const { return (!myAISContext.IsNull())? myAISContext->NbSelected():0; }
196
197   void                            setStaticTrihedronDisplayed(const bool on);
198
199   /* Clip planes management */
200   Handle(Graphic3d_ClipPlane)     createClipPlane(const gp_Pln& thePlane, const Standard_Boolean theIsOn);
201   void                            setClipPlanes (ClipPlanesList theList);
202   ClipPlanesList                  getClipPlanes() const;
203   void                            applyExistingClipPlanesToObject (const Handle(AIS_InteractiveObject)& theObject);
204
205   OCCViewer_ClippingDlg*          getClippingDlg() const;
206   void                            setClippingDlg(OCCViewer_ClippingDlg* theDlg);
207   
208
209   /* Selection management */
210   bool    highlight( const Handle(AIS_InteractiveObject)&, bool, bool=true );
211   bool    unHighlightAll( bool=true, bool=true ); 
212   bool    isInViewer( const Handle(AIS_InteractiveObject)&, bool=false );
213   bool    isVisible( const Handle(AIS_InteractiveObject)& );
214
215   void    setColor( const Handle(AIS_InteractiveObject)&, const QColor&, bool=true );
216   void    switchRepresentation( const Handle(AIS_InteractiveObject)&, int, bool=true );
217   void    setTransparency( const Handle(AIS_InteractiveObject)&, float, bool=true );
218   void    setIsos( const int u, const int v ); // number of isolines
219   void    isos( int& u, int& v ) const;
220
221   void    initView( OCCViewer_ViewWindow* view );
222
223 signals:
224   void selectionChanged();
225   void deselection();
226
227 protected slots:
228   virtual void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
229   virtual void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
230   virtual void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*);
231   virtual void onKeyPress(SUIT_ViewWindow*, QKeyEvent*);
232   virtual void onViewClosed(OCCViewer_ViewPort3d*);
233   virtual void onViewMapped(OCCViewer_ViewPort3d*);
234
235   void onDumpView();
236   void onChangeBackground();
237
238 protected:
239
240   Handle(V3d_Viewer)              myV3dViewer;
241
242   Handle(AIS_Trihedron)           myTrihedron;
243   Handle(AIS_InteractiveContext)  myAISContext;
244
245   int                             myInteractionStyle;
246   int                             myZoomingStyle;
247   int                             myProjectionType;
248   int                             myStereoType;
249   int                             myAnaglyphFilter;
250   int                             myStereographicFocusType;
251   int                             myInterocularDistanceType;
252
253   double                          myStereographicFocusValue;
254   double                          myInterocularDistanceValue;
255
256   bool                            myPreselectionEnabled;
257   bool                            mySelectionEnabled;
258   bool                            myMultiSelectionEnabled;
259   bool                            myIsRelative;
260   bool                            myToReverseStereo;
261   bool                            myVSyncMode;
262   bool                            myQuadBufferSupport;
263
264   int                             myTopLayerId;
265
266   //QColor                          myBgColor;
267   QPoint                          myStartPnt, myEndPnt, myCurPnt;
268
269   double                          myTrihedronSize;
270
271   QVector<Qtx::BackgroundData>    myBackgrounds;
272
273   OCCViewer_ClippingDlg*          myClippingDlg;
274
275   ClipPlanesList                  myClipPlanes;
276   Graphic3d_SequenceOfHClipPlane  myInternalClipPlanes;
277
278   QColor                          myClippingColor;
279   bool                            myDefaultTextureUsed;
280   QString                         myClippingTexture;
281   bool                            myTextureModulated;
282   double                          myClippingTextureScale;
283
284 };
285
286 #ifdef WIN32
287 #pragma warning( default:4251 )
288 #endif
289
290 #endif