1 // Copyright (C) 2007-2021 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"
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_InteractiveContext.hxx>
41 #include <AIS_ListOfInteractive.hxx>
42 #include <Graphic3d_SequenceOfHClipPlane.hxx>
44 #include <Basics_OCCTVersion.hxx>
49 class SUIT_ViewWindow;
51 class OCCViewer_ClippingDlg;
52 class OCCViewer_ViewWindow;
53 class OCCViewer_ViewPort3d;
59 #pragma warning( disable:4251 )
63 An object wich provides alternative way to fit scene in a view
65 class OCCViewer_Fitter
68 /// A method which has top be reimplemented to provide alterantive implementation FitAll command
69 /// \param theView - a view which has to be fit
70 virtual void fitAll(Handle(V3d_View) theView) = 0;
75 class OCCVIEWER_EXPORT OCCViewer_Viewer: public SUIT_ViewModel
80 /*! supported gradient types */
82 HorizontalGradient, VerticalGradient,
83 Diagonal1Gradient, Diagonal2Gradient,
84 Corner1Gradient, Corner2Gradient,
85 Corner3Gradient, Corner4Gradient,
86 LastGradient = Corner4Gradient
88 /*! supported stereo types */
90 QuadBufferType, AnaglyphType,
91 RowInterlacedType, ColumnInterlacedType,
92 ChessBoardType, SideBySideType,
96 static QString Type() { return "OCCViewer"; }
97 static QString backgroundData( QStringList&, QIntList&, QIntList& );
98 static void stereoData( QStringList&, QIntList&);
100 OCCViewer_Viewer( bool DisplayTrihedron = true);
101 virtual ~OCCViewer_Viewer();
105 virtual SUIT_ViewWindow* createView(SUIT_Desktop* theDesktop);
107 virtual void setViewManager(SUIT_ViewManager* theViewManager);
108 virtual QString getType() const { return Type(); }
110 virtual void contextMenuPopup(QMenu*);
112 void getSelectedObjects(AIS_ListOfInteractive& theList);
113 void setObjectsSelected(const AIS_ListOfInteractive& theList);
114 void setSelected(const Handle(AIS_InteractiveObject)& theIO) { myAISContext->SetSelected(theIO,Standard_True);}
116 void performSelectionChanged();
117 // emit signal selectionChanged
119 void setDefaultLights();
121 QColor backgroundColor() const; // obsolete
122 void setBackgroundColor( const QColor& ); // obsolete
123 Qtx::BackgroundData background() const;
124 void setBackground( const Qtx::BackgroundData& );
126 QColor backgroundColor(int theViewId) const; // obsolete
127 void setBackgroundColor( int theViewId, const QColor& ); // obsolete
128 Qtx::BackgroundData background(int theViewId) const;
129 void setBackground( int theViewId, const Qtx::BackgroundData& );
131 bool isColorScaleVisible() const;
132 virtual void setColorScaleShown( const bool );
134 //! returns true if 3d Trihedron in viewer was created
135 bool trihedronActivated() const { return !myTrihedron.IsNull(); }
137 void toggleTrihedron();
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 virtual OCCViewer_ViewWindow* createSubWindow();
155 // Methods to access fitter
157 /// Returns currently installed fitter
158 OCCViewer_Fitter* fitter() const { return myFitter; }
160 /// Installs new fitter
161 /// \param theFitter a new fitter
162 void setFitter(OCCViewer_Fitter* theFitter) {
163 myFitter = theFitter;
168 Handle(V3d_Viewer) getViewer3d() const { return myV3dViewer;}
169 Handle(AIS_InteractiveContext) getAISContext() const { return myAISContext; }
170 Handle(AIS_ColorScale) getColorScale() const { return myColorScale; }
171 Handle(AIS_Trihedron) getTrihedron() const { return myTrihedron; }
175 int interactionStyle() const;
176 void setInteractionStyle( const int );
178 int projectionType() const;
179 void setProjectionType( const int );
180 int stereoType() const;
181 void setStereoType( const int );
183 OCCViewer_ViewWindow::SelectionStyle selectionStyle() const;
184 void setSelectionStyle(OCCViewer_ViewWindow::SelectionStyle);
186 int anaglyphFilter() const;
187 void setAnaglyphFilter( const int );
189 void setStereographicFocus( const int, const double );
190 int stereographicFocusType() const;
191 double stereographicFocusValue() const;
193 void setInterocularDistance( const int, const double );
194 int interocularDistanceType() const;
195 double interocularDistanceValue() const;
197 bool isReverseStereo() const;
198 void setReverseStereo( const bool );
200 bool isVSync() const;
201 void setVSync( const bool );
203 bool isQuadBufferSupport() const;
204 void setQuadBufferSupport( const bool );
205 int zoomingStyle() const;
206 void setZoomingStyle( const int );
208 void enablePreselection(bool isEnabled);
209 bool isPreselectionEnabled() const;
211 void enableSelection(bool isEnabled);
212 bool isSelectionEnabled() const;
214 void setSelectionOptions( bool, bool );
216 void enableMultiselection(bool isEnable);
217 bool isMultiSelectionEnabled() const { return myMultiSelectionEnabled; }
219 bool enableDrawMode( bool on );
221 void setClippingColor( const QColor& );
222 QColor clippingColor() const;
224 void setClippingTextureParams( const bool, const QString&, const bool, const double );
225 bool isDefaultTextureUsed() const;
226 QString clippingTexture() const;
227 bool isTextureModulated() const;
228 double clippingTextureScale() const;
230 int getSelectionCount() const { return (!myAISContext.IsNull())? myAISContext->NbSelected():0; }
232 void setStaticTrihedronDisplayed(const bool on);
234 /* Clip planes management */
235 Handle(Graphic3d_ClipPlane) createClipPlane(const gp_Pln& thePlane, const Standard_Boolean theIsOn);
236 void setClipPlanes (ClipPlanesList theList);
237 ClipPlanesList getClipPlanes() const;
238 void applyExistingClipPlanesToObject (const Handle(AIS_InteractiveObject)& theObject);
240 OCCViewer_ClippingDlg* getClippingDlg() const;
241 void setClippingDlg(OCCViewer_ClippingDlg* theDlg);
244 /* Selection management */
245 bool highlight( const Handle(AIS_InteractiveObject)&, bool, bool=true );
246 bool unHighlightAll( bool=true, bool=true );
247 bool isInViewer( const Handle(AIS_InteractiveObject)&, bool=false );
248 bool isVisible( const Handle(AIS_InteractiveObject)& );
250 void setColor( const Handle(AIS_InteractiveObject)&, const QColor&, bool=true );
251 void switchRepresentation( const Handle(AIS_InteractiveObject)&, int, bool=true );
252 void setTransparency( const Handle(AIS_InteractiveObject)&, float, bool=true );
253 void setIsos( const int u, const int v ); // number of isolines
254 void isos( int& u, int& v ) const;
256 void initView( OCCViewer_ViewWindow* view );
259 void selectionChanged();
263 virtual void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
264 virtual void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
265 virtual void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*);
266 virtual void onKeyPress(SUIT_ViewWindow*, QKeyEvent*);
267 virtual void onViewClosed(OCCViewer_ViewPort3d*);
268 virtual void onViewMapped(OCCViewer_ViewPort3d*);
271 void onChangeBackground();
275 Handle(V3d_Viewer) myV3dViewer;
276 Handle(AIS_ColorScale) myColorScale;
277 Handle(AIS_Trihedron) myTrihedron;
278 Handle(AIS_InteractiveContext) myAISContext;
280 int myInteractionStyle;
282 int myProjectionType;
284 int myAnaglyphFilter;
285 int myStereographicFocusType;
286 int myInterocularDistanceType;
287 OCCViewer_ViewWindow::SelectionStyle mySelectionStyle;
289 double myStereographicFocusValue;
290 double myInterocularDistanceValue;
292 bool myPreselectionEnabled;
293 bool mySelectionEnabled;
294 bool myMultiSelectionEnabled;
296 bool myToReverseStereo;
298 bool myQuadBufferSupport;
303 QPoint myStartPnt, myEndPnt, myCurPnt;
305 double myTrihedronSize;
307 QVector<Qtx::BackgroundData> myBackgrounds;
309 OCCViewer_ClippingDlg* myClippingDlg;
311 ClipPlanesList myClipPlanes;
312 Graphic3d_SequenceOfHClipPlane myInternalClipPlanes;
314 QColor myClippingColor;
315 bool myDefaultTextureUsed;
316 QString myClippingTexture;
317 bool myTextureModulated;
318 double myClippingTextureScale;
320 OCCViewer_Fitter* myFitter;
324 #pragma warning( default:4251 )