1 // Copyright (C) 2007-2013 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.
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"
33 #include "SUIT_ViewModel.h"
35 #include <V3d_View.hxx>
36 #include <AIS_Trihedron.hxx>
37 #include <AIS_InteractiveContext.hxx>
38 #include <Basics_OCCTVersion.hxx>
43 class SUIT_ViewWindow;
45 class OCCViewer_ViewWindow;
47 class AIS_ListOfInteractive;
50 #pragma warning( disable:4251 )
53 class OCCVIEWER_EXPORT OCCViewer_Viewer: public SUIT_ViewModel
58 /*! supported gradient types */
60 HorizontalGradient, VerticalGradient,
61 Diagonal1Gradient, Diagonal2Gradient,
62 Corner1Gradient, Corner2Gradient,
63 Corner3Gradient, Corner4Gradient,
64 LastGradient = Corner4Gradient
67 static QString Type() { return "OCCViewer"; }
68 static QString backgroundData( QStringList&, QIntList&, QIntList& );
70 OCCViewer_Viewer( bool DisplayTrihedron = true);
71 virtual ~OCCViewer_Viewer();
75 virtual SUIT_ViewWindow* createView(SUIT_Desktop* theDesktop);
77 virtual void setViewManager(SUIT_ViewManager* theViewManager);
78 virtual QString getType() const { return Type(); }
80 virtual void contextMenuPopup(QMenu*);
82 void getSelectedObjects(AIS_ListOfInteractive& theList);
83 void setObjectsSelected(const AIS_ListOfInteractive& theList);
84 void setSelected(const Handle(AIS_InteractiveObject)& theIO) { myAISContext->SetSelected(theIO);}
86 void performSelectionChanged();
87 // emit signal selectionChanged
89 QColor backgroundColor() const; // obsolete
90 void setBackgroundColor( const QColor& ); // obsolete
91 Qtx::BackgroundData background() const;
92 void setBackground( const Qtx::BackgroundData& );
94 QColor backgroundColor(int theViewId) const; // obsolete
95 void setBackgroundColor( int theViewId, const QColor& ); // obsolete
96 Qtx::BackgroundData background(int theViewId) const;
97 void setBackground( int theViewId, const Qtx::BackgroundData& );
99 //! returns true if 3d Trihedron in viewer was created
100 bool trihedronActivated() const { return !myTrihedron.IsNull(); }
102 void toggleTrihedron();
103 bool isTrihedronVisible() const;
104 virtual void setTrihedronShown( const bool );
106 double trihedronSize() const;
107 virtual void setTrihedronSize( const double , bool isRelative = true);
109 bool trihedronRelative() const {return myIsRelative; }
111 // a utility function, used by SALOME_View_s methods
112 bool computeTrihedronSize( double& theNewSize, double& theSize );
114 void updateTrihedron();
117 virtual OCCViewer_ViewWindow* createSubWindow();
120 Handle(V3d_Viewer) getViewer3d() const { return myV3dViewer;}
121 #if OCC_VERSION_LARGE <= 0x06060000
122 Handle(V3d_Viewer) getCollector3d() const { return myV3dCollector; }
124 Handle(AIS_InteractiveContext) getAISContext() const { return myAISContext; }
125 Handle(AIS_Trihedron) getTrihedron() const { return myTrihedron; }
129 int interactionStyle() const;
130 void setInteractionStyle( const int );
132 int zoomingStyle() const;
133 void setZoomingStyle( const int );
135 void enablePreselection(bool isEnabled);
136 bool isPreselectionEnabled() const;
138 void enableSelection(bool isEnabled);
139 bool isSelectionEnabled() const;
141 void setSelectionOptions( bool, bool );
143 void enableMultiselection(bool isEnable);
144 bool isMultiSelectionEnabled() const { return myMultiSelectionEnabled; }
146 int getSelectionCount() const { return (!myAISContext.IsNull())? myAISContext->NbSelected():0; }
148 bool isStaticTrihedronDisplayed() { return myShowStaticTrihedron; }
149 void setStaticTrihedronDisplayed(const bool on);
151 /* Selection management */
152 bool highlight( const Handle(AIS_InteractiveObject)&, bool, bool=true );
153 bool unHighlightAll( bool=true, bool=true );
154 bool isInViewer( const Handle(AIS_InteractiveObject)&, bool=false );
155 bool isVisible( const Handle(AIS_InteractiveObject)& );
157 void setColor( const Handle(AIS_InteractiveObject)&, const QColor&, bool=true );
158 void switchRepresentation( const Handle(AIS_InteractiveObject)&, int, bool=true );
159 void setTransparency( const Handle(AIS_InteractiveObject)&, float, bool=true );
160 void setIsos( const int u, const int v ); // number of isolines
161 void isos( int& u, int& v ) const;
163 void initView( OCCViewer_ViewWindow* view );
166 void selectionChanged();
170 virtual void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
171 virtual void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
172 virtual void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*);
173 virtual void onKeyPress(SUIT_ViewWindow*, QKeyEvent*);
174 virtual void onViewClosed();
175 virtual void onViewMapped();
178 void onChangeBackground();
181 Handle(V3d_Viewer) myV3dViewer;
183 #if OCC_VERSION_LARGE <= 0x06060000
184 Handle(V3d_Viewer) myV3dCollector;
188 Handle(AIS_Trihedron) myTrihedron;
189 Handle(AIS_InteractiveContext) myAISContext;
191 int myInteractionStyle;
194 bool myPreselectionEnabled;
195 bool mySelectionEnabled;
196 bool myMultiSelectionEnabled;
202 QPoint myStartPnt, myEndPnt, myCurPnt;
204 bool myShowStaticTrihedron;
206 double myTrihedronSize;
208 QVector<Qtx::BackgroundData> myBackgrounds;
212 #pragma warning( default:4251 )