1 // Copyright (C) 2007-2015 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 <Graphic3d_SequenceOfHClipPlane.hxx>
44 class SUIT_ViewWindow;
46 class OCCViewer_ClippingDlg;
47 class OCCViewer_ViewWindow;
48 class OCCViewer_ViewPort3d;
50 class AIS_ListOfInteractive;
56 #pragma warning( disable:4251 )
59 class OCCVIEWER_EXPORT OCCViewer_Viewer: public SUIT_ViewModel
64 /*! supported gradient types */
66 HorizontalGradient, VerticalGradient,
67 Diagonal1Gradient, Diagonal2Gradient,
68 Corner1Gradient, Corner2Gradient,
69 Corner3Gradient, Corner4Gradient,
70 LastGradient = Corner4Gradient
72 /*! supported stereo types */
74 QuadBufferType, AnaglyphType,
75 RowInterlacedType, ColumnInterlacedType,
76 ChessBoardType, SideBySideType,
80 static QString Type() { return "OCCViewer"; }
81 static QString backgroundData( QStringList&, QIntList&, QIntList& );
82 static void stereoData( QStringList&, QIntList&);
84 OCCViewer_Viewer( bool DisplayTrihedron = true);
85 virtual ~OCCViewer_Viewer();
89 virtual SUIT_ViewWindow* createView(SUIT_Desktop* theDesktop);
91 virtual void setViewManager(SUIT_ViewManager* theViewManager);
92 virtual QString getType() const { return Type(); }
94 virtual void contextMenuPopup(QMenu*);
96 void getSelectedObjects(AIS_ListOfInteractive& theList);
97 void setObjectsSelected(const AIS_ListOfInteractive& theList);
98 void setSelected(const Handle(AIS_InteractiveObject)& theIO) { myAISContext->SetSelected(theIO);}
100 void performSelectionChanged();
101 // emit signal selectionChanged
103 QColor backgroundColor() const; // obsolete
104 void setBackgroundColor( const QColor& ); // obsolete
105 Qtx::BackgroundData background() const;
106 void setBackground( const Qtx::BackgroundData& );
108 QColor backgroundColor(int theViewId) const; // obsolete
109 void setBackgroundColor( int theViewId, const QColor& ); // obsolete
110 Qtx::BackgroundData background(int theViewId) const;
111 void setBackground( int theViewId, const Qtx::BackgroundData& );
113 //! returns true if 3d Trihedron in viewer was created
114 bool trihedronActivated() const { return !myTrihedron.IsNull(); }
116 void toggleTrihedron();
117 bool isTrihedronVisible() const;
118 virtual void setTrihedronShown( const bool );
120 double trihedronSize() const;
121 virtual void setTrihedronSize( const double , bool isRelative = true);
123 bool trihedronRelative() const {return myIsRelative; }
125 // a utility functions, used by SALOME_View_s methods
126 bool computeTrihedronSize( double& theNewSize, double& theSize );
127 virtual double computeSceneSize(const Handle(V3d_View)&) const;
129 void updateTrihedron();
132 virtual OCCViewer_ViewWindow* createSubWindow();
135 Handle(V3d_Viewer) getViewer3d() const { return myV3dViewer;}
136 Handle(AIS_InteractiveContext) getAISContext() const { return myAISContext; }
137 Handle(AIS_Trihedron) getTrihedron() const { return myTrihedron; }
141 int interactionStyle() const;
142 void setInteractionStyle( const int );
144 int projectionType() const;
145 void setProjectionType( const int );
146 int stereoType() const;
147 void setStereoType( const int );
149 int anaglyphFilter() const;
150 void setAnaglyphFilter( const int );
152 void setStereographicFocus( const int, const double );
153 int stereographicFocusType() const;
154 double stereographicFocusValue() const;
156 void setInterocularDistance( const int, const double );
157 int interocularDistanceType() const;
158 double interocularDistanceValue() const;
160 bool isReverseStereo() const;
161 void setReverseStereo( const bool );
163 bool isVSync() const;
164 void setVSync( const bool );
166 bool isQuadBufferSupport() const;
167 void setQuadBufferSupport( const bool );
168 int zoomingStyle() const;
169 void setZoomingStyle( const int );
171 void enablePreselection(bool isEnabled);
172 bool isPreselectionEnabled() const;
174 void enableSelection(bool isEnabled);
175 bool isSelectionEnabled() const;
177 void setSelectionOptions( bool, bool );
179 void enableMultiselection(bool isEnable);
180 bool isMultiSelectionEnabled() const { return myMultiSelectionEnabled; }
182 void setClippingColor( const QColor& );
183 QColor clippingColor() const;
185 void setClippingTextureParams( const bool, const QString&, const bool, const double );
186 bool isDefaultTextureUsed() const;
187 QString clippingTexture() const;
188 bool isTextureModulated() const;
189 double clippingTextureScale() const;
191 int getSelectionCount() const { return (!myAISContext.IsNull())? myAISContext->NbSelected():0; }
193 void setStaticTrihedronDisplayed(const bool on);
195 /* Clip planes management */
196 Handle(Graphic3d_ClipPlane) createClipPlane(const gp_Pln& thePlane, const Standard_Boolean theIsOn);
197 void setClipPlanes (ClipPlanesList theList);
198 ClipPlanesList getClipPlanes() const;
199 void applyExistingClipPlanesToObject (const Handle(AIS_InteractiveObject)& theObject);
201 OCCViewer_ClippingDlg* getClippingDlg() const;
202 void setClippingDlg(OCCViewer_ClippingDlg* theDlg);
205 /* Selection management */
206 bool highlight( const Handle(AIS_InteractiveObject)&, bool, bool=true );
207 bool unHighlightAll( bool=true, bool=true );
208 bool isInViewer( const Handle(AIS_InteractiveObject)&, bool=false );
209 bool isVisible( const Handle(AIS_InteractiveObject)& );
211 void setColor( const Handle(AIS_InteractiveObject)&, const QColor&, bool=true );
212 void switchRepresentation( const Handle(AIS_InteractiveObject)&, int, bool=true );
213 void setTransparency( const Handle(AIS_InteractiveObject)&, float, bool=true );
214 void setIsos( const int u, const int v ); // number of isolines
215 void isos( int& u, int& v ) const;
217 void initView( OCCViewer_ViewWindow* view );
220 void selectionChanged();
224 virtual void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
225 virtual void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
226 virtual void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*);
227 virtual void onKeyPress(SUIT_ViewWindow*, QKeyEvent*);
228 virtual void onViewClosed(OCCViewer_ViewPort3d*);
229 virtual void onViewMapped(OCCViewer_ViewPort3d*);
232 void onChangeBackground();
236 Handle(V3d_Viewer) myV3dViewer;
238 Handle(AIS_Trihedron) myTrihedron;
239 Handle(AIS_InteractiveContext) myAISContext;
241 int myInteractionStyle;
243 int myProjectionType;
245 int myAnaglyphFilter;
246 int myStereographicFocusType;
247 int myInterocularDistanceType;
249 double myStereographicFocusValue;
250 double myInterocularDistanceValue;
252 bool myPreselectionEnabled;
253 bool mySelectionEnabled;
254 bool myMultiSelectionEnabled;
256 bool myToReverseStereo;
258 bool myQuadBufferSupport;
263 QPoint myStartPnt, myEndPnt, myCurPnt;
265 double myTrihedronSize;
267 QVector<Qtx::BackgroundData> myBackgrounds;
269 OCCViewer_ClippingDlg* myClippingDlg;
271 ClipPlanesList myClipPlanes;
272 Graphic3d_SequenceOfHClipPlane myInternalClipPlanes;
274 QColor myClippingColor;
275 bool myDefaultTextureUsed;
276 QString myClippingTexture;
277 bool myTextureModulated;
278 double myClippingTextureScale;
283 #pragma warning( default:4251 )