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