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