]> SALOME platform Git repositories - modules/gui.git/blob - src/OCCViewer/OCCViewer_ViewModel.h
Salome HOME
e8693b78317b187bb8739379d182a3572dd19798
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewModel.h
1 // Copyright (C) 2007-2021  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   // Methods to access fitter
156
157   /// Returns currently installed fitter
158   OCCViewer_Fitter* fitter() const { return myFitter; }
159
160   /// Installs new fitter
161   /// \param theFitter a new fitter
162   void setFitter(OCCViewer_Fitter* theFitter) {
163     myFitter = theFitter;
164   }
165
166
167 public:
168   Handle(V3d_Viewer)              getViewer3d()    const { return myV3dViewer;}
169   Handle(AIS_InteractiveContext)  getAISContext()  const { return myAISContext; }
170   Handle(AIS_ColorScale)          getColorScale()  const { return myColorScale; }
171   Handle(AIS_Trihedron)           getTrihedron()   const { return myTrihedron; }
172
173   int                             getTopLayerId();
174
175   int                             interactionStyle() const;
176   void                            setInteractionStyle( const int );
177
178   int                             projectionType() const;
179   void                            setProjectionType( const int );
180   int                             stereoType() const;
181   void                            setStereoType( const int );
182
183   OCCViewer_ViewWindow::SelectionStyle selectionStyle() const;
184   void                            setSelectionStyle(OCCViewer_ViewWindow::SelectionStyle);
185
186   int                             anaglyphFilter() const;
187   void                            setAnaglyphFilter( const int );
188
189   void                            setStereographicFocus( const int, const double );
190   int                             stereographicFocusType() const;
191   double                          stereographicFocusValue() const;
192
193   void                            setInterocularDistance( const int, const double );
194   int                             interocularDistanceType() const;
195   double                          interocularDistanceValue() const;
196
197   bool                            isReverseStereo() const;
198   void                            setReverseStereo( const bool );
199
200   bool                            isVSync() const;
201   void                            setVSync( const bool );
202
203   bool                            isQuadBufferSupport() const;
204   void                            setQuadBufferSupport( const bool );
205   int                             zoomingStyle() const;
206   void                            setZoomingStyle( const int );
207
208   void                            enablePreselection(bool isEnabled);
209   bool                            isPreselectionEnabled() const;
210   
211   void                            enableSelection(bool isEnabled);
212   bool                            isSelectionEnabled() const;
213
214   void                            setSelectionOptions( bool, bool );
215
216   void                            enableMultiselection(bool isEnable);
217   bool                            isMultiSelectionEnabled() const { return myMultiSelectionEnabled; }
218
219   bool                            enableDrawMode( bool on );
220
221   void                            setClippingColor( const QColor& );
222   QColor                          clippingColor() const;
223
224   void                            setClippingTextureParams( const bool, const QString&, const bool, const double );
225   bool                            isDefaultTextureUsed() const;
226   QString                         clippingTexture() const;
227   bool                            isTextureModulated() const;
228   double                          clippingTextureScale() const;
229
230   int                             getSelectionCount() const { return (!myAISContext.IsNull())? myAISContext->NbSelected():0; }
231
232   void                            setStaticTrihedronDisplayed(const bool on);
233
234   /* Clip planes management */
235   Handle(Graphic3d_ClipPlane)     createClipPlane(const gp_Pln& thePlane, const Standard_Boolean theIsOn);
236   void                            setClipPlanes (ClipPlanesList theList);
237   ClipPlanesList                  getClipPlanes() const;
238   void                            applyExistingClipPlanesToObject (const Handle(AIS_InteractiveObject)& theObject);
239
240   OCCViewer_ClippingDlg*          getClippingDlg() const;
241   void                            setClippingDlg(OCCViewer_ClippingDlg* theDlg);
242   
243
244   /* Selection management */
245   bool    highlight( const Handle(AIS_InteractiveObject)&, bool, bool=true );
246   bool    unHighlightAll( bool=true, bool=true ); 
247   bool    isInViewer( const Handle(AIS_InteractiveObject)&, bool=false );
248   bool    isVisible( const Handle(AIS_InteractiveObject)& );
249
250   void    setColor( const Handle(AIS_InteractiveObject)&, const QColor&, bool=true );
251   void    switchRepresentation( const Handle(AIS_InteractiveObject)&, int, bool=true );
252   void    setTransparency( const Handle(AIS_InteractiveObject)&, float, bool=true );
253   void    setIsos( const int u, const int v ); // number of isolines
254   void    isos( int& u, int& v ) const;
255
256   void    initView( OCCViewer_ViewWindow* view );
257
258 signals:
259   void selectionChanged();
260   void deselection();
261
262 protected slots:
263   virtual void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
264   virtual void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
265   virtual void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*);
266   virtual void onKeyPress(SUIT_ViewWindow*, QKeyEvent*);
267   virtual void onViewClosed(OCCViewer_ViewPort3d*);
268   virtual void onViewMapped(OCCViewer_ViewPort3d*);
269
270   void onDumpView();
271   void onChangeBackground();
272
273 protected:
274
275   Handle(V3d_Viewer)              myV3dViewer;
276   Handle(AIS_ColorScale)          myColorScale;
277   Handle(AIS_Trihedron)           myTrihedron;
278   Handle(AIS_InteractiveContext)  myAISContext;
279
280   int                             myInteractionStyle;
281   int                             myZoomingStyle;
282   int                             myProjectionType;
283   int                             myStereoType;
284   int                             myAnaglyphFilter;
285   int                             myStereographicFocusType;
286   int                             myInterocularDistanceType;
287   OCCViewer_ViewWindow::SelectionStyle mySelectionStyle;
288
289   double                          myStereographicFocusValue;
290   double                          myInterocularDistanceValue;
291
292   bool                            myPreselectionEnabled;
293   bool                            mySelectionEnabled;
294   bool                            myMultiSelectionEnabled;
295   bool                            myIsRelative;
296   bool                            myToReverseStereo;
297   bool                            myVSyncMode;
298   bool                            myQuadBufferSupport;
299
300   int                             myTopLayerId;
301
302   //QColor                          myBgColor;
303   QPoint                          myStartPnt, myEndPnt, myCurPnt;
304
305   double                          myTrihedronSize;
306
307   QVector<Qtx::BackgroundData>    myBackgrounds;
308
309   OCCViewer_ClippingDlg*          myClippingDlg;
310
311   ClipPlanesList                  myClipPlanes;
312   Graphic3d_SequenceOfHClipPlane  myInternalClipPlanes;
313
314   QColor                          myClippingColor;
315   bool                            myDefaultTextureUsed;
316   QString                         myClippingTexture;
317   bool                            myTextureModulated;
318   double                          myClippingTextureScale;
319
320   OCCViewer_Fitter* myFitter;
321 };
322
323 #ifdef WIN32
324 #pragma warning( default:4251 )
325 #endif
326
327 #endif