1 // Copyright (C) 2007-2012 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>
42 class SUIT_ViewWindow;
44 class OCCViewer_ViewWindow;
46 class AIS_ListOfInteractive;
49 #pragma warning( disable:4251 )
52 class OCCVIEWER_EXPORT OCCViewer_Viewer: public SUIT_ViewModel
57 /*! supported gradient types */
59 HorizontalGradient, VerticalGradient,
60 Diagonal1Gradient, Diagonal2Gradient,
61 Corner1Gradient, Corner2Gradient,
62 Corner3Gradient, Corner4Gradient,
63 LastGradient = Corner4Gradient
66 static QString Type() { return "OCCViewer"; }
67 static QString backgroundData( QStringList&, QIntList&, QIntList& );
69 OCCViewer_Viewer( bool DisplayTrihedron = true);
70 virtual ~OCCViewer_Viewer();
74 virtual SUIT_ViewWindow* createView(SUIT_Desktop* theDesktop);
76 virtual void setViewManager(SUIT_ViewManager* theViewManager);
77 virtual QString getType() const { return Type(); }
79 virtual void contextMenuPopup(QMenu*);
81 void getSelectedObjects(AIS_ListOfInteractive& theList);
82 void setObjectsSelected(const AIS_ListOfInteractive& theList);
83 void setSelected(const Handle(AIS_InteractiveObject)& theIO) { myAISContext->SetSelected(theIO);}
85 void performSelectionChanged();
86 // emit signal selectionChanged
88 QColor backgroundColor() const; // obsolete
89 void setBackgroundColor( const QColor& ); // obsolete
90 Qtx::BackgroundData background() const;
91 void setBackground( const Qtx::BackgroundData& );
93 QColor backgroundColor(int theViewId) const; // obsolete
94 void setBackgroundColor( int theViewId, const QColor& ); // obsolete
95 Qtx::BackgroundData background(int theViewId) const;
96 void setBackground( int theViewId, const Qtx::BackgroundData& );
98 //! returns true if 3d Trihedron in viewer was created
99 bool trihedronActivated() const { return !myTrihedron.IsNull(); }
101 void toggleTrihedron();
102 bool isTrihedronVisible() const;
103 virtual void setTrihedronShown( const bool );
105 double trihedronSize() const;
106 virtual void setTrihedronSize( const double , bool isRelative = true);
108 bool trihedronRelative() const {return myIsRelative; }
110 // a utility function, used by SALOME_View_s methods
111 bool computeTrihedronSize( double& theNewSize, double& theSize );
113 void updateTrihedron();
116 virtual OCCViewer_ViewWindow* createSubWindow();
119 Handle(V3d_Viewer) getViewer3d() const { return myV3dViewer;}
120 Handle(V3d_Viewer) getCollector3d() const { return myV3dCollector; }
121 Handle(AIS_InteractiveContext) getAISContext() const { return myAISContext; }
122 Handle(AIS_Trihedron) getTrihedron() const { return myTrihedron; }
126 int interactionStyle() const;
127 void setInteractionStyle( const int );
129 int zoomingStyle() const;
130 void setZoomingStyle( const int );
132 void enableSelection(bool isEnabled);
133 bool isSelectionEnabled() const { return mySelectionEnabled; }
135 void enableMultiselection(bool isEnable);
136 bool isMultiSelectionEnabled() const { return myMultiSelectionEnabled; }
138 int getSelectionCount() const { return (!myAISContext.IsNull())? myAISContext->NbSelected():0; }
140 bool isStaticTrihedronDisplayed() { return myShowStaticTrihedron; }
141 void setStaticTrihedronDisplayed(const bool on);
143 /* Selection management */
144 bool highlight( const Handle(AIS_InteractiveObject)&, bool, bool=true );
145 bool unHighlightAll( bool=true );
146 bool isInViewer( const Handle(AIS_InteractiveObject)&, bool=false );
147 bool isVisible( const Handle(AIS_InteractiveObject)& );
149 void setColor( const Handle(AIS_InteractiveObject)&, const QColor&, bool=true );
150 void switchRepresentation( const Handle(AIS_InteractiveObject)&, int, bool=true );
151 void setTransparency( const Handle(AIS_InteractiveObject)&, float, bool=true );
152 void setIsos( const int u, const int v ); // number of isolines
153 void isos( int& u, int& v ) const;
155 void initView( OCCViewer_ViewWindow* view );
158 void selectionChanged();
162 virtual void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
163 virtual void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
164 virtual void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*);
165 virtual void onKeyPress(SUIT_ViewWindow*, QKeyEvent*);
166 virtual void onViewClosed();
169 void onChangeBackground();
172 Handle(V3d_Viewer) myV3dViewer;
173 Handle(V3d_Viewer) myV3dCollector;
175 Handle(AIS_Trihedron) myTrihedron;
176 Handle(AIS_InteractiveContext) myAISContext;
178 int myInteractionStyle;
181 bool mySelectionEnabled;
182 bool myMultiSelectionEnabled;
188 QPoint myStartPnt, myEndPnt;
190 bool myShowStaticTrihedron;
192 double myTrihedronSize;
194 QVector<Qtx::BackgroundData> myBackgrounds;
198 #pragma warning( default:4251 )