1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #ifndef OCCVIEWER_VIEWMODEL_H
24 #define OCCVIEWER_VIEWMODEL_H
30 #include "OCCViewer.h"
31 #include "OCCViewer_ClipPlane.h"
34 #include "SUIT_ViewModel.h"
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>
45 class SUIT_ViewWindow;
47 class OCCViewer_ClippingDlg;
48 class OCCViewer_ViewWindow;
49 class OCCViewer_ViewPort3d;
55 #pragma warning( disable:4251 )
58 class OCCVIEWER_EXPORT OCCViewer_Viewer: public SUIT_ViewModel
63 /*! supported gradient types */
65 HorizontalGradient, VerticalGradient,
66 Diagonal1Gradient, Diagonal2Gradient,
67 Corner1Gradient, Corner2Gradient,
68 Corner3Gradient, Corner4Gradient,
69 LastGradient = Corner4Gradient
71 /*! supported stereo types */
73 QuadBufferType, AnaglyphType,
74 RowInterlacedType, ColumnInterlacedType,
75 ChessBoardType, SideBySideType,
79 static QString Type() { return "OCCViewer"; }
80 static QString backgroundData( QStringList&, QIntList&, QIntList& );
81 static void stereoData( QStringList&, QIntList&);
83 OCCViewer_Viewer( bool DisplayTrihedron = true);
84 virtual ~OCCViewer_Viewer();
88 virtual SUIT_ViewWindow* createView(SUIT_Desktop* theDesktop);
90 virtual void setViewManager(SUIT_ViewManager* theViewManager);
91 virtual QString getType() const { return Type(); }
93 virtual void contextMenuPopup(QMenu*);
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);}
99 void performSelectionChanged();
100 // emit signal selectionChanged
102 void setDefaultLights();
104 QColor backgroundColor() const; // obsolete
105 void setBackgroundColor( const QColor& ); // obsolete
106 Qtx::BackgroundData background() const;
107 void setBackground( const Qtx::BackgroundData& );
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& );
114 //! returns true if 3d Trihedron in viewer was created
115 bool trihedronActivated() const { return !myTrihedron.IsNull(); }
117 void toggleTrihedron();
118 bool isTrihedronVisible() const;
119 virtual void setTrihedronShown( const bool );
121 double trihedronSize() const;
122 virtual void setTrihedronSize( const double , bool isRelative = true);
124 bool trihedronRelative() const {return myIsRelative; }
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;
130 void updateTrihedron();
133 virtual OCCViewer_ViewWindow* createSubWindow();
136 Handle(V3d_Viewer) getViewer3d() const { return myV3dViewer;}
137 Handle(AIS_InteractiveContext) getAISContext() const { return myAISContext; }
138 Handle(AIS_Trihedron) getTrihedron() const { return myTrihedron; }
142 int interactionStyle() const;
143 void setInteractionStyle( const int );
145 int projectionType() const;
146 void setProjectionType( const int );
147 int stereoType() const;
148 void setStereoType( const int );
150 int anaglyphFilter() const;
151 void setAnaglyphFilter( const int );
153 void setStereographicFocus( const int, const double );
154 int stereographicFocusType() const;
155 double stereographicFocusValue() const;
157 void setInterocularDistance( const int, const double );
158 int interocularDistanceType() const;
159 double interocularDistanceValue() const;
161 bool isReverseStereo() const;
162 void setReverseStereo( const bool );
164 bool isVSync() const;
165 void setVSync( const bool );
167 bool isQuadBufferSupport() const;
168 void setQuadBufferSupport( const bool );
169 int zoomingStyle() const;
170 void setZoomingStyle( const int );
172 void enablePreselection(bool isEnabled);
173 bool isPreselectionEnabled() const;
175 void enableSelection(bool isEnabled);
176 bool isSelectionEnabled() const;
178 void setSelectionOptions( bool, bool );
180 void enableMultiselection(bool isEnable);
181 bool isMultiSelectionEnabled() const { return myMultiSelectionEnabled; }
183 bool enableDrawMode( bool on );
185 void setClippingColor( const QColor& );
186 QColor clippingColor() const;
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;
194 int getSelectionCount() const { return (!myAISContext.IsNull())? myAISContext->NbSelected():0; }
196 void setStaticTrihedronDisplayed(const bool on);
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);
204 OCCViewer_ClippingDlg* getClippingDlg() const;
205 void setClippingDlg(OCCViewer_ClippingDlg* theDlg);
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)& );
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;
220 void initView( OCCViewer_ViewWindow* view );
223 void selectionChanged();
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*);
235 void onChangeBackground();
239 Handle(V3d_Viewer) myV3dViewer;
241 Handle(AIS_Trihedron) myTrihedron;
242 Handle(AIS_InteractiveContext) myAISContext;
244 int myInteractionStyle;
246 int myProjectionType;
248 int myAnaglyphFilter;
249 int myStereographicFocusType;
250 int myInterocularDistanceType;
252 double myStereographicFocusValue;
253 double myInterocularDistanceValue;
255 bool myPreselectionEnabled;
256 bool mySelectionEnabled;
257 bool myMultiSelectionEnabled;
259 bool myToReverseStereo;
261 bool myQuadBufferSupport;
266 QPoint myStartPnt, myEndPnt, myCurPnt;
268 double myTrihedronSize;
270 QVector<Qtx::BackgroundData> myBackgrounds;
272 OCCViewer_ClippingDlg* myClippingDlg;
274 ClipPlanesList myClipPlanes;
275 Graphic3d_SequenceOfHClipPlane myInternalClipPlanes;
277 QColor myClippingColor;
278 bool myDefaultTextureUsed;
279 QString myClippingTexture;
280 bool myTextureModulated;
281 double myClippingTextureScale;
286 #pragma warning( default:4251 )