Salome HOME
Merge from BR_PORTING_VTK6 01/03/2013
[modules/gui.git] / src / SVTK / SVTK_ViewModel.h
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef SVTK_VIEWMODEL_H
24 #define SVTK_VIEWMODEL_H
25
26 #include "SVTK.h"
27 #include "SVTK_ViewModelBase.h"
28
29 #include "Qtx.h"
30
31 #include <SALOME_Prs.h>
32 #include <SALOME_InteractiveObject.hxx>
33 #include <SALOME_ListIO.hxx>
34
35 #include <QColor>
36 #include <QMap>
37
38 class QMouseEvent;
39
40 class SVTK_ViewWindow;
41 class VTKViewer_Actor;
42
43 //! Extends two interfaces #SVTK_ViewModelBase and #SALOME_View 
44 class SVTK_EXPORT SVTK_Viewer : public SVTK_ViewModelBase, public SALOME_View 
45 {
46   Q_OBJECT;
47
48 public:
49   /*! supported gradient types */
50   enum { 
51     HorizontalGradient,
52     VerticalGradient,
53     FirstDiagonalGradient,
54     SecondDiagonalGradient,
55     FirstCornerGradient,
56     SecondCornerGradient,
57     ThirdCornerGradient,
58     FourthCornerGradient,
59     LastGradient = FourthCornerGradient,
60   };
61
62   typedef SVTK_ViewWindow TViewWindow;
63   
64   //! Define string representation of the viewer type
65   static QString           Type() { return "VTKViewer"; }
66   static QString           backgroundData( QStringList&, QIntList&, QIntList& );
67
68   SVTK_Viewer();
69   virtual ~SVTK_Viewer();
70
71   //! See #SUIT_ViewModel::createView
72   virtual SUIT_ViewWindow* createView(SUIT_Desktop*);
73
74   //! See #SUIT_ViewModel::createView
75   virtual void setViewManager(SUIT_ViewManager* theViewManager);
76
77   //! See #SUIT_ViewModel::contextMenuPopup
78   virtual void contextMenuPopup( QMenu* );
79
80   //! See #SUIT_ViewModel::getType
81   virtual QString getType() const { return Type(); }
82
83   //! Get background color of the viewer [obsolete]
84   QColor backgroundColor() const;
85
86   //! Set background color to the viewer [obsolete]
87   void setBackgroundColor( const QColor& );
88
89   //! Get background color of the viewer
90   Qtx::BackgroundData background() const;
91
92   //! Set background color to the viewer
93   void setBackground( const Qtx::BackgroundData& );
94
95   //! Get size of trihedron of the viewer (see #SVTK_Renderer::SetTrihedronSize)
96   double trihedronSize() const;
97
98   //! Shows if the size of trihedron relative (see #SVTK_Renderer::SetTrihedronSize)
99   bool trihedronRelative() const;
100
101   //! Set size of trihedron of the viewer (see #SVTK_Renderer::SetTrihedronSize)
102   void setTrihedronSize( const double, const bool = true );
103
104   //! Get visibility status of the static trihedron
105   bool isStaticTrihedronVisible() const;
106
107   //! Set visibility status of the static trihedron
108   void setStaticTrihedronVisible( const bool );
109
110   //! Gets projection mode
111   int projectionMode() const;
112
113   //! Sets projection mode
114   void setProjectionMode( const int );
115
116   //! Gets interaction style
117   int interactionStyle() const;
118
119   //! Sets interaction style
120   void setInteractionStyle( const int );
121
122   //! Gets zooming style
123   int zoomingStyle() const;
124
125   //! Sets zooming style
126   void setZoomingStyle( const int );
127
128   //! Gets dynamic preselection
129   bool dynamicPreSelection() const;
130
131   //! Sets dynamic preselection
132   void setDynamicPreSelection( const bool );
133
134   //! Get incremental speed (see #SVTK_InteractorStyle::ControllerIncrement)
135   int incrementalSpeed() const;
136
137   //! Returns modification mode of incremental speed (see #SVTK_InteractorStyle::ControllerIncrement)
138   int incrementalSpeedMode() const;
139
140   //! Set the incremental speed for view operation (see #SVTK_InteractorStyle::ControllerIncrement)
141   void setIncrementalSpeed( const int, const int = 0 );
142
143   //! Gets spacemouse button for specified function
144   int spacemouseBtn( const int ) const;
145
146   //! Sets spacemouse buttons
147   void setSpacemouseButtons( const int, const int, const int );
148
149 public:
150   void enableSelection(bool isEnabled);
151   bool isSelectionEnabled() const { return mySelectionEnabled; }
152
153   void enableMultiselection(bool isEnable);
154   bool isMultiSelectionEnabled() const { return myMultiSelectionEnabled; }
155
156   int  getSelectionCount() const;
157
158   /* Reimplemented from SALOME_View */
159
160   //! See #SALOME_View::Display( const SALOME_Prs* )
161   void Display( const SALOME_VTKPrs* ); 
162
163   //! See #SALOME_View::Erase( const SALOME_VTKPrs*, const bool = false )
164   void Erase( const SALOME_VTKPrs*, const bool = false );
165
166   //! See #SALOME_View::EraseAll( const bool = false )
167   void EraseAll( const bool = false );
168
169   //! See #SALOME_View::getVisible( SALOME_ListIO& )
170   virtual void GetVisible( SALOME_ListIO& );
171
172   //! See #SALOME_View::CreatePrs( const char* entry = 0 )
173   SALOME_Prs* CreatePrs( const char* entry = 0 );
174
175   //! See #SALOME_View::isVisible( const Handle(SALOME_InteractiveObject)& )
176   virtual bool isVisible( const Handle(SALOME_InteractiveObject)& );
177
178   //! See #SALOME_View::Repaint()
179   virtual void Repaint();
180
181  signals:
182   void actorAdded(SVTK_ViewWindow*, VTKViewer_Actor*);
183   void actorRemoved(SVTK_ViewWindow*, VTKViewer_Actor*);
184
185 protected slots:
186   void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
187   void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
188   void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*);
189
190   void onDumpView();
191   void onChangeBackground();
192
193   void onActorAdded(VTKViewer_Actor*);
194   void onActorRemoved(VTKViewer_Actor*);
195
196 private:
197   void updateToolBars();
198
199   Qtx::BackgroundData  myDefaultBackground;
200   double myTrihedronSize;
201   bool                 myTrihedronRelative;
202   bool                 myIsStaticTrihedronVisible;
203   bool                 mySelectionEnabled;
204   bool                 myMultiSelectionEnabled;
205   int                  myIncrementSpeed;
206   int                  myIncrementMode;
207   int                  myProjMode;
208   int                  myStyle;
209   int                  myZoomingStyle;
210   bool                 myDynamicPreSelection;
211   int                  mySpaceBtn[3];
212 };
213
214 #endif