1 // Copyright (C) 2007-2023 CEA, EDF, 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"
32 #include "OCCViewer_ViewWindow.h"
35 #include "SUIT_ViewModel.h"
37 #include <V3d_View.hxx>
38 #include <AIS_ColorScale.hxx>
39 #include <AIS_Trihedron.hxx>
40 #include <AIS_ViewCube.hxx>
41 #include <AIS_InteractiveContext.hxx>
42 #include <AIS_ListOfInteractive.hxx>
43 #include <Graphic3d_SequenceOfHClipPlane.hxx>
45 #include <Basics_OCCTVersion.hxx>
50 class SUIT_ViewWindow;
52 class OCCViewer_ClippingDlg;
53 class OCCViewer_ViewWindow;
54 class OCCViewer_ViewPort3d;
60 #pragma warning( disable:4251 )
64 An object wich provides alternative way to fit scene in a view
66 class OCCViewer_Fitter
69 /// A method which has top be reimplemented to provide alterantive implementation FitAll command
70 /// \param theView - a view which has to be fit
71 virtual void fitAll(Handle(V3d_View) theView) = 0;
76 class OCCVIEWER_EXPORT OCCViewer_Viewer: public SUIT_ViewModel
81 /*! supported gradient types */
83 HorizontalGradient, VerticalGradient,
84 Diagonal1Gradient, Diagonal2Gradient,
85 Corner1Gradient, Corner2Gradient,
86 Corner3Gradient, Corner4Gradient,
87 LastGradient = Corner4Gradient
89 /*! supported stereo types */
91 QuadBufferType, AnaglyphType,
92 RowInterlacedType, ColumnInterlacedType,
93 ChessBoardType, SideBySideType,
97 static QString Type() { return "OCCViewer"; }
98 static QString backgroundData( QStringList&, QIntList&, QIntList& );
99 static void stereoData( QStringList&, QIntList&);
101 OCCViewer_Viewer( bool DisplayTrihedron = true);
102 virtual ~OCCViewer_Viewer();
106 virtual SUIT_ViewWindow* createView(SUIT_Desktop* theDesktop);
108 virtual void setViewManager(SUIT_ViewManager* theViewManager);
109 virtual QString getType() const { return Type(); }
111 virtual void contextMenuPopup(QMenu*);
113 void getSelectedObjects(AIS_ListOfInteractive& theList);
114 void setObjectsSelected(const AIS_ListOfInteractive& theList);
115 void setSelected(const Handle(AIS_InteractiveObject)& theIO) { myAISContext->SetSelected(theIO,Standard_True);}
117 void performSelectionChanged();
118 // emit signal selectionChanged
120 void setDefaultLights();
122 QColor backgroundColor() const; // obsolete
123 void setBackgroundColor( const QColor& ); // obsolete
124 Qtx::BackgroundData background() const;
125 void setBackground( const Qtx::BackgroundData& );
127 QColor backgroundColor(int theViewId) const; // obsolete
128 void setBackgroundColor( int theViewId, const QColor& ); // obsolete
129 Qtx::BackgroundData background(int theViewId) const;
130 void setBackground( int theViewId, const Qtx::BackgroundData& );
132 bool isColorScaleVisible() const;
133 virtual void setColorScaleShown( const bool );
135 //! returns true if 3d Trihedron in viewer was created
136 bool trihedronActivated() const { return !myTrihedron.IsNull(); }
138 bool isTrihedronVisible() const;
139 virtual void setTrihedronShown( const bool );
141 double trihedronSize() const;
142 virtual void setTrihedronSize( const double , bool isRelative = true);
144 bool trihedronRelative() const {return myIsRelative; }
146 // a utility functions, used by SALOME_View_s methods
147 bool computeTrihedronSize( double& theNewSize, double& theSize );
148 virtual double computeSceneSize(const Handle(V3d_View)&) const;
150 void updateTrihedron();
153 bool viewCubeActivated() const { return !myViewCube.IsNull(); }
154 bool isViewCubeVisible() const;
155 virtual void setViewCubeShown( const bool );
156 void setViewCubeParamsFromPreferences();
158 virtual OCCViewer_ViewWindow* createSubWindow();
160 // Methods to access fitter
162 /// Returns currently installed fitter
163 OCCViewer_Fitter* fitter() const { return myFitter; }
165 /// Installs new fitter
166 /// \param theFitter a new fitter
167 void setFitter(OCCViewer_Fitter* theFitter) {
168 myFitter = theFitter;
173 Handle(V3d_Viewer) getViewer3d() const { return myV3dViewer;}
174 Handle(AIS_InteractiveContext) getAISContext() const { return myAISContext; }
175 Handle(AIS_ColorScale) getColorScale() const { return myColorScale; }
176 Handle(AIS_Trihedron) getTrihedron() const { return myTrihedron; }
177 Handle(AIS_ViewCube) getViewCube() const { return myViewCube; }
181 int interactionStyle() const;
182 void setInteractionStyle( const int );
184 int projectionType() const;
185 void setProjectionType( const int );
186 int stereoType() const;
187 void setStereoType( const int );
189 OCCViewer_ViewWindow::SelectionStyle selectionStyle() const;
190 void setSelectionStyle(OCCViewer_ViewWindow::SelectionStyle);
192 int anaglyphFilter() const;
193 void setAnaglyphFilter( const int );
195 void setStereographicFocus( const int, const double );
196 int stereographicFocusType() const;
197 double stereographicFocusValue() const;
199 void setInterocularDistance( const int, const double );
200 int interocularDistanceType() const;
201 double interocularDistanceValue() const;
203 bool isReverseStereo() const;
204 void setReverseStereo( const bool );
206 bool isVSync() const;
207 void setVSync( const bool );
209 bool isQuadBufferSupport() const;
210 void setQuadBufferSupport( const bool );
211 int zoomingStyle() const;
212 void setZoomingStyle( const int );
214 void enablePreselection(bool isEnabled);
215 bool isPreselectionEnabled() const;
217 void enableSelection(bool isEnabled);
218 bool isSelectionEnabled() const;
220 void setSelectionOptions( bool, bool );
222 void enableMultiselection(bool isEnable);
223 bool isMultiSelectionEnabled() const { return myMultiSelectionEnabled; }
225 bool enableDrawMode( bool on );
227 void setClippingColor( const QColor& );
228 QColor clippingColor() const;
230 void setClippingTextureParams( const bool, const QString&, const bool, const double );
231 bool isDefaultTextureUsed() const;
232 QString clippingTexture() const;
233 bool isTextureModulated() const;
234 double clippingTextureScale() const;
236 int getSelectionCount() const { return (!myAISContext.IsNull())? myAISContext->NbSelected():0; }
238 void setStaticTrihedronDisplayed(const bool on);
240 /* Clip planes management */
241 Handle(Graphic3d_ClipPlane) createClipPlane(const gp_Pln& thePlane, const Standard_Boolean theIsOn);
242 void setClipPlanes (ClipPlanesList theList);
243 ClipPlanesList getClipPlanes() const;
244 void applyExistingClipPlanesToObject (const Handle(AIS_InteractiveObject)& theObject);
246 OCCViewer_ClippingDlg* getClippingDlg() const;
247 void setClippingDlg(OCCViewer_ClippingDlg* theDlg);
250 /* Selection management */
251 bool highlight( const Handle(AIS_InteractiveObject)&, bool, bool=true );
252 bool unHighlightAll( bool=true, bool=true );
253 bool isInViewer( const Handle(AIS_InteractiveObject)&, bool=false );
254 bool isVisible( const Handle(AIS_InteractiveObject)& );
256 void setColor( const Handle(AIS_InteractiveObject)&, const QColor&, bool=true );
257 void switchRepresentation( const Handle(AIS_InteractiveObject)&, int, bool=true );
258 void setTransparency( const Handle(AIS_InteractiveObject)&, float, bool=true );
259 void setIsos( const int u, const int v ); // number of isolines
260 void isos( int& u, int& v ) const;
262 void initView( OCCViewer_ViewWindow* view );
265 void selectionChanged();
269 virtual void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
270 virtual void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
271 virtual void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*);
272 virtual void onKeyPress(SUIT_ViewWindow*, QKeyEvent*);
273 virtual void onViewClosed(OCCViewer_ViewPort3d*);
274 virtual void onViewMapped(OCCViewer_ViewPort3d*);
277 void onChangeBackground();
281 Handle(V3d_Viewer) myV3dViewer;
282 Handle(AIS_ColorScale) myColorScale;
283 Handle(AIS_Trihedron) myTrihedron;
284 Handle(AIS_ViewCube) myViewCube;
285 Handle(AIS_InteractiveContext) myAISContext;
287 int myInteractionStyle;
289 int myProjectionType;
291 int myAnaglyphFilter;
292 int myStereographicFocusType;
293 int myInterocularDistanceType;
294 OCCViewer_ViewWindow::SelectionStyle mySelectionStyle;
296 double myStereographicFocusValue;
297 double myInterocularDistanceValue;
299 bool myPreselectionEnabled;
300 bool mySelectionEnabled;
301 bool myMultiSelectionEnabled;
303 bool myToReverseStereo;
305 bool myQuadBufferSupport;
310 QPoint myStartPnt, myEndPnt, myCurPnt;
312 double myTrihedronSize;
314 QVector<Qtx::BackgroundData> myBackgrounds;
316 OCCViewer_ClippingDlg* myClippingDlg;
318 ClipPlanesList myClipPlanes;
319 Graphic3d_SequenceOfHClipPlane myInternalClipPlanes;
321 QColor myClippingColor;
322 bool myDefaultTextureUsed;
323 QString myClippingTexture;
324 bool myTextureModulated;
325 double myClippingTextureScale;
327 OCCViewer_Fitter* myFitter;
331 #pragma warning( default:4251 )