Salome HOME
Merge branch 'hydro/imps_2015' of https://git.salome-platform.org/gitpub/modules...
[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   QColor                          backgroundColor() const;                              // obsolete
104   void                            setBackgroundColor( const QColor& );                  // obsolete
105   Qtx::BackgroundData             background() const;
106   void                            setBackground( const Qtx::BackgroundData& );
107
108   QColor                          backgroundColor(int theViewId) const;                 // obsolete
109   void                            setBackgroundColor( int theViewId, const QColor& );   // obsolete
110   Qtx::BackgroundData             background(int theViewId) const;
111   void                            setBackground( int theViewId, const Qtx::BackgroundData& );
112
113   //! returns true if 3d Trihedron in viewer was created
114   bool                            trihedronActivated() const { return !myTrihedron.IsNull(); }
115
116   void                            toggleTrihedron();
117   bool                            isTrihedronVisible() const;
118   virtual void                    setTrihedronShown( const bool );
119
120   double                          trihedronSize() const;
121   virtual void                    setTrihedronSize( const double , bool isRelative = true);
122   
123   bool                            trihedronRelative() const {return myIsRelative; }
124
125   // a utility functions, used by SALOME_View_s methods
126   bool                            computeTrihedronSize( double& theNewSize, double& theSize );
127   virtual double                  computeSceneSize(const Handle(V3d_View)&) const;
128
129   void                            updateTrihedron();
130   
131
132   virtual OCCViewer_ViewWindow*   createSubWindow();
133
134 public:
135   Handle(V3d_Viewer)              getViewer3d()    const { return myV3dViewer;}
136   Handle(AIS_InteractiveContext)  getAISContext()  const { return myAISContext; }
137   Handle(AIS_Trihedron)           getTrihedron()   const { return myTrihedron; }
138
139   int                             getTopLayerId();
140
141   int                             interactionStyle() const;
142   void                            setInteractionStyle( const int );
143
144   int                             projectionType() const;
145   void                            setProjectionType( const int );
146   int                             stereoType() const;
147   void                            setStereoType( const int );
148
149   int                             anaglyphFilter() const;
150   void                            setAnaglyphFilter( const int );
151
152   void                            setStereographicFocus( const int, const double );
153   int                             stereographicFocusType() const;
154   double                          stereographicFocusValue() const;
155
156   void                            setInterocularDistance( const int, const double );
157   int                             interocularDistanceType() const;
158   double                          interocularDistanceValue() const;
159
160   bool                            isReverseStereo() const;
161   void                            setReverseStereo( const bool );
162
163   bool                            isVSync() const;
164   void                            setVSync( const bool );
165
166   bool                            isQuadBufferSupport() const;
167   void                            setQuadBufferSupport( const bool );
168   int                             zoomingStyle() const;
169   void                            setZoomingStyle( const int );
170
171   void                            enablePreselection(bool isEnabled);
172   bool                            isPreselectionEnabled() const;
173   
174   void                            enableSelection(bool isEnabled);
175   bool                            isSelectionEnabled() const;
176
177   void                            setSelectionOptions( bool, bool );
178
179   void                            enableMultiselection(bool isEnable);
180   bool                            isMultiSelectionEnabled() const { return myMultiSelectionEnabled; }
181
182   bool                            enableDrawMode( bool on );
183
184   void                            setClippingColor( const QColor& );
185   QColor                          clippingColor() const;
186
187   void                            setClippingTextureParams( const bool, const QString&, const bool, const double );
188   bool                            isDefaultTextureUsed() const;
189   QString                         clippingTexture() const;
190   bool                            isTextureModulated() const;
191   double                          clippingTextureScale() const;
192
193   int                             getSelectionCount() const { return (!myAISContext.IsNull())? myAISContext->NbSelected():0; }
194
195   void                            setStaticTrihedronDisplayed(const bool on);
196
197   /* Clip planes management */
198   Handle(Graphic3d_ClipPlane)     createClipPlane(const gp_Pln& thePlane, const Standard_Boolean theIsOn);
199   void                            setClipPlanes (ClipPlanesList theList);
200   ClipPlanesList                  getClipPlanes() const;
201   void                            applyExistingClipPlanesToObject (const Handle(AIS_InteractiveObject)& theObject);
202
203   OCCViewer_ClippingDlg*          getClippingDlg() const;
204   void                            setClippingDlg(OCCViewer_ClippingDlg* theDlg);
205   
206
207   /* Selection management */
208   bool    highlight( const Handle(AIS_InteractiveObject)&, bool, bool=true );
209   bool    unHighlightAll( bool=true, bool=true ); 
210   bool    isInViewer( const Handle(AIS_InteractiveObject)&, bool=false );
211   bool    isVisible( const Handle(AIS_InteractiveObject)& );
212
213   void    setColor( const Handle(AIS_InteractiveObject)&, const QColor&, bool=true );
214   void    switchRepresentation( const Handle(AIS_InteractiveObject)&, int, bool=true );
215   void    setTransparency( const Handle(AIS_InteractiveObject)&, float, bool=true );
216   void    setIsos( const int u, const int v ); // number of isolines
217   void    isos( int& u, int& v ) const;
218
219   void    initView( OCCViewer_ViewWindow* view );
220
221 signals:
222   void selectionChanged();
223   void deselection();
224
225 protected slots:
226   virtual void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
227   virtual void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
228   virtual void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*);
229   virtual void onKeyPress(SUIT_ViewWindow*, QKeyEvent*);
230   virtual void onViewClosed(OCCViewer_ViewPort3d*);
231   virtual void onViewMapped(OCCViewer_ViewPort3d*);
232
233   void onDumpView();
234   void onChangeBackground();
235
236 protected:
237
238   Handle(V3d_Viewer)              myV3dViewer;
239
240   Handle(AIS_Trihedron)           myTrihedron;
241   Handle(AIS_InteractiveContext)  myAISContext;
242
243   int                             myInteractionStyle;
244   int                             myZoomingStyle;
245   int                             myProjectionType;
246   int                             myStereoType;
247   int                             myAnaglyphFilter;
248   int                             myStereographicFocusType;
249   int                             myInterocularDistanceType;
250
251   double                          myStereographicFocusValue;
252   double                          myInterocularDistanceValue;
253
254   bool                            myPreselectionEnabled;
255   bool                            mySelectionEnabled;
256   bool                            myMultiSelectionEnabled;
257   bool                            myIsRelative;
258   bool                            myToReverseStereo;
259   bool                            myVSyncMode;
260   bool                            myQuadBufferSupport;
261
262   int                             myTopLayerId;
263
264   //QColor                          myBgColor;
265   QPoint                          myStartPnt, myEndPnt, myCurPnt;
266
267   double                          myTrihedronSize;
268
269   QVector<Qtx::BackgroundData>    myBackgrounds;
270
271   OCCViewer_ClippingDlg*          myClippingDlg;
272
273   ClipPlanesList                  myClipPlanes;
274   Graphic3d_SequenceOfHClipPlane  myInternalClipPlanes;
275
276   QColor                          myClippingColor;
277   bool                            myDefaultTextureUsed;
278   QString                         myClippingTexture;
279   bool                            myTextureModulated;
280   double                          myClippingTextureScale;
281
282 };
283
284 #ifdef WIN32
285 #pragma warning( default:4251 )
286 #endif
287
288 #endif