Version: 8.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OCCViewer_ViewModel.h
Go to the documentation of this file.
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;
50 
51 class QtxAction;
52 
53 
54 #ifdef WIN32
55 #pragma warning( disable:4251 )
56 #endif
57 
59 {
60  Q_OBJECT
61 
62 public:
64  enum {
65  HorizontalGradient, VerticalGradient,
66  Diagonal1Gradient, Diagonal2Gradient,
67  Corner1Gradient, Corner2Gradient,
68  Corner3Gradient, Corner4Gradient,
69  LastGradient = Corner4Gradient
70  };
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 
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 public:
136  Handle(V3d_Viewer) getViewer3d() const { return myV3dViewer;}
137  Handle(AIS_InteractiveContext) getAISContext() const { return myAISContext; }
138  Handle(AIS_Trihedron) getTrihedron() const { return myTrihedron; }
139 
140  int getTopLayerId();
141 
142  int interactionStyle() const;
143  void setInteractionStyle( const int );
144 
145  int projectionType() const;
146  void setProjectionType( const int );
147  int stereoType() const;
148  void setStereoType( const int );
149 
150  int anaglyphFilter() const;
151  void setAnaglyphFilter( const int );
152 
153  void setStereographicFocus( const int, const double );
154  int stereographicFocusType() const;
155  double stereographicFocusValue() const;
156 
157  void setInterocularDistance( const int, const double );
158  int interocularDistanceType() const;
159  double interocularDistanceValue() const;
160 
161  bool isReverseStereo() const;
162  void setReverseStereo( const bool );
163 
164  bool isVSync() const;
165  void setVSync( const bool );
166 
167  bool isQuadBufferSupport() const;
168  void setQuadBufferSupport( const bool );
169  int zoomingStyle() const;
170  void setZoomingStyle( const int );
171 
172  void enablePreselection(bool isEnabled);
173  bool isPreselectionEnabled() const;
174 
175  void enableSelection(bool isEnabled);
176  bool isSelectionEnabled() const;
177 
178  void setSelectionOptions( bool, bool );
179 
180  void enableMultiselection(bool isEnable);
181  bool isMultiSelectionEnabled() const { return myMultiSelectionEnabled; }
182 
183  bool enableDrawMode( bool on );
184 
185  void setClippingColor( const QColor& );
186  QColor clippingColor() const;
187 
188  void setClippingTextureParams( const bool, const QString&, const bool, const double );
189  bool isDefaultTextureUsed() const;
190  QString clippingTexture() const;
191  bool isTextureModulated() const;
192  double clippingTextureScale() const;
193 
194  int getSelectionCount() const { return (!myAISContext.IsNull())? myAISContext->NbSelected():0; }
195 
196  void setStaticTrihedronDisplayed(const bool on);
197 
198  /* Clip planes management */
199  Handle(Graphic3d_ClipPlane) createClipPlane(const gp_Pln& thePlane, const Standard_Boolean theIsOn);
200  void setClipPlanes (ClipPlanesList theList);
201  ClipPlanesList getClipPlanes() const;
202  void applyExistingClipPlanesToObject (const Handle(AIS_InteractiveObject)& theObject);
203 
204  OCCViewer_ClippingDlg* getClippingDlg() const;
205  void setClippingDlg(OCCViewer_ClippingDlg* theDlg);
206 
207 
208  /* Selection management */
209  bool highlight( const Handle(AIS_InteractiveObject)&, bool, bool=true );
210  bool unHighlightAll( bool=true, bool=true );
211  bool isInViewer( const Handle(AIS_InteractiveObject)&, bool=false );
212  bool isVisible( const Handle(AIS_InteractiveObject)& );
213 
214  void setColor( const Handle(AIS_InteractiveObject)&, const QColor&, bool=true );
215  void switchRepresentation( const Handle(AIS_InteractiveObject)&, int, bool=true );
216  void setTransparency( const Handle(AIS_InteractiveObject)&, float, bool=true );
217  void setIsos( const int u, const int v ); // number of isolines
218  void isos( int& u, int& v ) const;
219 
220  void initView( OCCViewer_ViewWindow* view );
221 
222 signals:
223  void selectionChanged();
224  void deselection();
225 
226 protected slots:
227  virtual void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
228  virtual void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
229  virtual void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*);
230  virtual void onKeyPress(SUIT_ViewWindow*, QKeyEvent*);
231  virtual void onViewClosed(OCCViewer_ViewPort3d*);
232  virtual void onViewMapped(OCCViewer_ViewPort3d*);
233 
234  void onDumpView();
235  void onChangeBackground();
236 
237 protected:
238 
239  Handle(V3d_Viewer) myV3dViewer;
240 
241  Handle(AIS_Trihedron) myTrihedron;
242  Handle(AIS_InteractiveContext) myAISContext;
243 
244  int myInteractionStyle;
245  int myZoomingStyle;
246  int myProjectionType;
247  int myStereoType;
248  int myAnaglyphFilter;
249  int myStereographicFocusType;
250  int myInterocularDistanceType;
251 
252  double myStereographicFocusValue;
253  double myInterocularDistanceValue;
254 
255  bool myPreselectionEnabled;
256  bool mySelectionEnabled;
257  bool myMultiSelectionEnabled;
258  bool myIsRelative;
259  bool myToReverseStereo;
260  bool myVSyncMode;
261  bool myQuadBufferSupport;
262 
263  int myTopLayerId;
264 
265  //QColor myBgColor;
266  QPoint myStartPnt, myEndPnt, myCurPnt;
267 
268  double myTrihedronSize;
269 
270  QVector<Qtx::BackgroundData> myBackgrounds;
271 
272  OCCViewer_ClippingDlg* myClippingDlg;
273 
274  ClipPlanesList myClipPlanes;
275  Graphic3d_SequenceOfHClipPlane myInternalClipPlanes;
276 
277  QColor myClippingColor;
278  bool myDefaultTextureUsed;
279  QString myClippingTexture;
280  bool myTextureModulated;
281  double myClippingTextureScale;
282 
283 };
284 
285 #ifdef WIN32
286 #pragma warning( default:4251 )
287 #endif
288 
289 #endif