Salome HOME
bbb513c772d63b5b7fbe0974a9ae40f84b83be14
[modules/gui.git] / src / SVTK / SVTK_SelectorDef.h
1 //  Copyright (C) 2007-2008  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 //  SALOME SALOMEGUI : implementation of desktop and GUI kernel
23 //  File   : SALOME_Selection.h
24 //  Author : Nicolas REJNERI
25 //  Module : SALOME
26 //  $Header$
27 //
28 #ifndef SVTK_SELECTORDEF_H
29 #define SVTK_SELECTORDEF_H
30
31 #include <set>
32 #include <map>
33
34 #include <TColStd_IndexedMapOfInteger.hxx>
35 #include <TColStd_MapOfInteger.hxx>
36 #include <vtkSmartPointer.h>
37
38 #include "SALOME_InteractiveObject.hxx"
39
40 #include "SVTK_Selector.h"
41
42 class SALOME_Actor;
43
44 class SVTK_Viewer;
45 class SVTK_ViewWindow;
46 class vtkPicker;
47 class vtkCellPicker;
48
49 class SVTK_SelectorDef: public SVTK_Selector
50 {
51 public:
52   SVTK_SelectorDef();
53   virtual ~SVTK_SelectorDef();
54
55   virtual
56   void 
57   SetSelectionMode(Selection_Mode theMode);
58
59   virtual
60   Selection_Mode
61   SelectionMode() const { return mySelectionMode; }
62
63   virtual
64   void
65   ClearIObjects();
66
67   virtual
68   SALOME_Actor* 
69   GetActor(const Handle(SALOME_InteractiveObject)& theIO) const;
70
71   virtual
72   bool
73   IsSelected(const Handle(SALOME_InteractiveObject)& theIO) const;
74
75   virtual
76   bool
77   IsSelected(SALOME_Actor* theActor) const;
78
79   virtual
80   bool
81   AddIObject(const Handle(SALOME_InteractiveObject)& theIO);
82
83   virtual
84   bool
85   AddIObject(SALOME_Actor* theActor);
86
87   virtual
88   bool 
89   RemoveIObject(const Handle(SALOME_InteractiveObject)& theIO);
90
91   virtual
92   bool 
93   RemoveIObject(SALOME_Actor* theActor);
94
95   virtual
96   const SALOME_ListIO& 
97   StoredIObjects() const;
98
99   virtual
100   int 
101   IObjectCount() const;
102
103   virtual
104   bool 
105   HasIndex(const Handle(SALOME_InteractiveObject)& theIO ) const;
106
107   virtual
108   void 
109   GetIndex( const Handle(SALOME_InteractiveObject)& theIO, 
110             TColStd_IndexedMapOfInteger& theIndex );
111         
112   virtual
113   bool 
114   AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO, 
115                     const TColStd_IndexedMapOfInteger& theIndices, 
116                     bool theIsModeShift);
117   virtual
118   bool 
119   AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO, 
120                     const TColStd_MapOfInteger& theIndices, 
121                     bool theIsModeShift);
122   virtual
123   bool
124   AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO, 
125                     int theIndex, 
126                     bool theIsModeShift);
127   virtual
128   void 
129   RemoveIndex( const Handle(SALOME_InteractiveObject)& theIO, 
130                int theIndex);
131   virtual
132   bool 
133   IsIndexSelected(const Handle(SALOME_InteractiveObject)& theIO, 
134                   int theIndex) const;
135   virtual
136   void 
137   ClearIndex();
138
139   //----------------------------------------------------------------------------
140   virtual
141   void 
142   SetFilter(const Handle(VTKViewer_Filter)& theFilter);
143
144   virtual
145   Handle(VTKViewer_Filter) 
146   GetFilter(const TFilterID theId) const;
147
148   virtual
149   bool
150   IsFilterPresent(const TFilterID theId) const;
151
152   virtual
153   void
154   RemoveFilter(const int theId);
155
156   virtual
157   bool
158   IsValid(SALOME_Actor* theActor,
159           const TFilterID theId,
160           const bool theIsNode = false) const;
161   
162   //----------------------------------------------------------------------------
163   virtual
164   void 
165   StartPickCallback();
166
167   virtual
168   void 
169   EndPickCallback();
170
171   //----------------------------------------------------------------------------
172   virtual
173   SALOME_Actor*
174   Pick(const SVTK_SelectionEvent* theEvent, vtkRenderer* theRenderer) const;
175
176   virtual
177   void
178   SetTolerance(const double& theTolerance);
179
180 private:
181   int mySelectionMode;
182
183   struct TIOLessThan
184   {
185     bool 
186     operator()(const Handle(SALOME_InteractiveObject)& theRightIO,
187                const Handle(SALOME_InteractiveObject)& theLeftIO) const
188     {
189       return strcmp(theRightIO->getEntry(),theLeftIO->getEntry()) < 0;
190     }
191   };
192
193   struct TIndexedMapOfInteger
194   {
195     TColStd_IndexedMapOfInteger myMap;
196     TIndexedMapOfInteger()
197     {}
198     TIndexedMapOfInteger(const TIndexedMapOfInteger& theIndexedMapOfInteger)
199     {
200       myMap = theIndexedMapOfInteger.myMap;
201     }
202   };
203
204   mutable SALOME_ListIO myIObjectList;
205   typedef std::set<Handle(SALOME_InteractiveObject),
206                    TIOLessThan> TIObjects;
207   TIObjects myIObjects;
208
209   typedef std::map<Handle(SALOME_InteractiveObject),
210                    vtkSmartPointer<SALOME_Actor>,
211                    TIOLessThan> TIO2Actors;
212   TIO2Actors myIO2Actors;
213
214   typedef std::map<Handle(SALOME_InteractiveObject),
215                    TIndexedMapOfInteger,
216                    TIOLessThan> TMapIOSubIndex;
217   TMapIOSubIndex myMapIOSubIndex;
218
219   typedef std::map<TFilterID,Handle(VTKViewer_Filter)> TFilters;
220   TFilters myFilters;
221
222   vtkSmartPointer<vtkPicker> myPicker;
223   vtkSmartPointer<vtkCellPicker> myCellPicker;
224 };
225
226 #endif