1 // Copyright (C) 2007-2020 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 #if OCC_VERSION_LARGE <= 0x07030000
156 void setUseLocalSelection(bool theIsUseLocalSelection);
157 bool useLocalSelection() const;
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; }
180 int interactionStyle() const;
181 void setInteractionStyle( const int );
183 int projectionType() const;
184 void setProjectionType( const int );
185 int stereoType() const;
186 void setStereoType( const int );
188 OCCViewer_ViewWindow::SelectionStyle selectionStyle() const;
189 void setSelectionStyle(OCCViewer_ViewWindow::SelectionStyle);
191 int anaglyphFilter() const;
192 void setAnaglyphFilter( const int );
194 void setStereographicFocus( const int, const double );
195 int stereographicFocusType() const;
196 double stereographicFocusValue() const;
198 void setInterocularDistance( const int, const double );
199 int interocularDistanceType() const;
200 double interocularDistanceValue() const;
202 bool isReverseStereo() const;
203 void setReverseStereo( const bool );
205 bool isVSync() const;
206 void setVSync( const bool );
208 bool isQuadBufferSupport() const;
209 void setQuadBufferSupport( const bool );
210 int zoomingStyle() const;
211 void setZoomingStyle( const int );
213 void enablePreselection(bool isEnabled);
214 bool isPreselectionEnabled() const;
216 void enableSelection(bool isEnabled);
217 bool isSelectionEnabled() const;
219 void setSelectionOptions( bool, bool );
221 void enableMultiselection(bool isEnable);
222 bool isMultiSelectionEnabled() const { return myMultiSelectionEnabled; }
224 bool enableDrawMode( bool on );
226 void setClippingColor( const QColor& );
227 QColor clippingColor() const;
229 void setClippingTextureParams( const bool, const QString&, const bool, const double );
230 bool isDefaultTextureUsed() const;
231 QString clippingTexture() const;
232 bool isTextureModulated() const;
233 double clippingTextureScale() const;
235 int getSelectionCount() const { return (!myAISContext.IsNull())? myAISContext->NbSelected():0; }
237 void setStaticTrihedronDisplayed(const bool on);
239 /* Clip planes management */
240 Handle(Graphic3d_ClipPlane) createClipPlane(const gp_Pln& thePlane, const Standard_Boolean theIsOn);
241 void setClipPlanes (ClipPlanesList theList);
242 ClipPlanesList getClipPlanes() const;
243 void applyExistingClipPlanesToObject (const Handle(AIS_InteractiveObject)& theObject);
245 OCCViewer_ClippingDlg* getClippingDlg() const;
246 void setClippingDlg(OCCViewer_ClippingDlg* theDlg);
249 /* Selection management */
250 bool highlight( const Handle(AIS_InteractiveObject)&, bool, bool=true );
251 bool unHighlightAll( bool=true, bool=true );
252 bool isInViewer( const Handle(AIS_InteractiveObject)&, bool=false );
253 bool isVisible( const Handle(AIS_InteractiveObject)& );
255 void setColor( const Handle(AIS_InteractiveObject)&, const QColor&, bool=true );
256 void switchRepresentation( const Handle(AIS_InteractiveObject)&, int, bool=true );
257 void setTransparency( const Handle(AIS_InteractiveObject)&, float, bool=true );
258 void setIsos( const int u, const int v ); // number of isolines
259 void isos( int& u, int& v ) const;
261 void initView( OCCViewer_ViewWindow* view );
263 /// Sets a flag to ignore mouse release for selection. Used for Rectangle/Polygon selection
264 void doNotSelect() { mySelectionDone = true; }
267 void selectionChanged();
271 virtual void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
272 virtual void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
273 virtual void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*);
274 virtual void onKeyPress(SUIT_ViewWindow*, QKeyEvent*);
275 virtual void onViewClosed(OCCViewer_ViewPort3d*);
276 virtual void onViewMapped(OCCViewer_ViewPort3d*);
279 void onChangeBackground();
283 Handle(V3d_Viewer) myV3dViewer;
284 Handle(AIS_ColorScale) myColorScale;
285 Handle(AIS_Trihedron) myTrihedron;
286 Handle(AIS_InteractiveContext) myAISContext;
288 int myInteractionStyle;
290 int myProjectionType;
292 int myAnaglyphFilter;
293 int myStereographicFocusType;
294 int myInterocularDistanceType;
295 OCCViewer_ViewWindow::SelectionStyle mySelectionStyle;
297 double myStereographicFocusValue;
298 double myInterocularDistanceValue;
300 bool myPreselectionEnabled;
301 bool mySelectionEnabled;
302 bool myMultiSelectionEnabled;
304 bool myToReverseStereo;
306 bool myQuadBufferSupport;
311 QPoint myStartPnt, myEndPnt, myCurPnt;
313 double myTrihedronSize;
315 QVector<Qtx::BackgroundData> myBackgrounds;
317 OCCViewer_ClippingDlg* myClippingDlg;
319 ClipPlanesList myClipPlanes;
320 Graphic3d_SequenceOfHClipPlane myInternalClipPlanes;
322 QColor myClippingColor;
323 bool myDefaultTextureUsed;
324 QString myClippingTexture;
325 bool myTextureModulated;
326 double myClippingTextureScale;
327 #if OCC_VERSION_LARGE <= 0x07030000
328 bool myIsUseLocalSelection;
331 OCCViewer_Fitter* myFitter;
332 bool mySelectionDone;
336 #pragma warning( default:4251 )