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();
135 void setUseLocalSelection(bool theIsUseLocalSelection);
136 bool useLocalSelection() const;
139 Handle(V3d_Viewer) getViewer3d() const { return myV3dViewer;}
140 Handle(AIS_InteractiveContext) getAISContext() const { return myAISContext; }
141 Handle(AIS_Trihedron) getTrihedron() const { return myTrihedron; }
145 int interactionStyle() const;
146 void setInteractionStyle( const int );
148 int projectionType() const;
149 void setProjectionType( const int );
150 int stereoType() const;
151 void setStereoType( const int );
153 int anaglyphFilter() const;
154 void setAnaglyphFilter( const int );
156 void setStereographicFocus( const int, const double );
157 int stereographicFocusType() const;
158 double stereographicFocusValue() const;
160 void setInterocularDistance( const int, const double );
161 int interocularDistanceType() const;
162 double interocularDistanceValue() const;
164 bool isReverseStereo() const;
165 void setReverseStereo( const bool );
167 bool isVSync() const;
168 void setVSync( const bool );
170 bool isQuadBufferSupport() const;
171 void setQuadBufferSupport( const bool );
172 int zoomingStyle() const;
173 void setZoomingStyle( const int );
175 void enablePreselection(bool isEnabled);
176 bool isPreselectionEnabled() const;
178 void enableSelection(bool isEnabled);
179 bool isSelectionEnabled() const;
181 void setSelectionOptions( bool, bool );
183 void enableMultiselection(bool isEnable);
184 bool isMultiSelectionEnabled() const { return myMultiSelectionEnabled; }
186 bool enableDrawMode( bool on );
188 void setClippingColor( const QColor& );
189 QColor clippingColor() const;
191 void setClippingTextureParams( const bool, const QString&, const bool, const double );
192 bool isDefaultTextureUsed() const;
193 QString clippingTexture() const;
194 bool isTextureModulated() const;
195 double clippingTextureScale() const;
197 int getSelectionCount() const { return (!myAISContext.IsNull())? myAISContext->NbSelected():0; }
199 void setStaticTrihedronDisplayed(const bool on);
201 /* Clip planes management */
202 Handle(Graphic3d_ClipPlane) createClipPlane(const gp_Pln& thePlane, const Standard_Boolean theIsOn);
203 void setClipPlanes (ClipPlanesList theList);
204 ClipPlanesList getClipPlanes() const;
205 void applyExistingClipPlanesToObject (const Handle(AIS_InteractiveObject)& theObject);
207 OCCViewer_ClippingDlg* getClippingDlg() const;
208 void setClippingDlg(OCCViewer_ClippingDlg* theDlg);
211 /* Selection management */
212 bool highlight( const Handle(AIS_InteractiveObject)&, bool, bool=true );
213 bool unHighlightAll( bool=true, bool=true );
214 bool isInViewer( const Handle(AIS_InteractiveObject)&, bool=false );
215 bool isVisible( const Handle(AIS_InteractiveObject)& );
217 void setColor( const Handle(AIS_InteractiveObject)&, const QColor&, bool=true );
218 void switchRepresentation( const Handle(AIS_InteractiveObject)&, int, bool=true );
219 void setTransparency( const Handle(AIS_InteractiveObject)&, float, bool=true );
220 void setIsos( const int u, const int v ); // number of isolines
221 void isos( int& u, int& v ) const;
223 void initView( OCCViewer_ViewWindow* view );
226 void selectionChanged();
230 virtual void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
231 virtual void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
232 virtual void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*);
233 virtual void onKeyPress(SUIT_ViewWindow*, QKeyEvent*);
234 virtual void onViewClosed(OCCViewer_ViewPort3d*);
235 virtual void onViewMapped(OCCViewer_ViewPort3d*);
238 void onChangeBackground();
242 Handle(V3d_Viewer) myV3dViewer;
244 Handle(AIS_Trihedron) myTrihedron;
245 Handle(AIS_InteractiveContext) myAISContext;
247 int myInteractionStyle;
249 int myProjectionType;
251 int myAnaglyphFilter;
252 int myStereographicFocusType;
253 int myInterocularDistanceType;
255 double myStereographicFocusValue;
256 double myInterocularDistanceValue;
258 bool myPreselectionEnabled;
259 bool mySelectionEnabled;
260 bool myMultiSelectionEnabled;
262 bool myToReverseStereo;
264 bool myQuadBufferSupport;
269 QPoint myStartPnt, myEndPnt, myCurPnt;
271 double myTrihedronSize;
273 QVector<Qtx::BackgroundData> myBackgrounds;
275 OCCViewer_ClippingDlg* myClippingDlg;
277 ClipPlanesList myClipPlanes;
278 Graphic3d_SequenceOfHClipPlane myInternalClipPlanes;
280 QColor myClippingColor;
281 bool myDefaultTextureUsed;
282 QString myClippingTexture;
283 bool myTextureModulated;
284 double myClippingTextureScale;
285 bool myIsUseLocalSelection;
289 #pragma warning( default:4251 )