Salome HOME
0061db7bae7929184b9218545af31444354c5106
[modules/gui.git] / src / SVTK / SVTK_SelectorDef.h
1 // Copyright (C) 2007-2023  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, or (at your option) any later version.
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 //  SALOME SALOMEGUI : implementation of desktop and GUI kernel
24 //  File   : SALOME_Selection.h
25 //  Author : Nicolas REJNERI
26
27 #ifndef SVTK_SELECTORDEF_H
28 #define SVTK_SELECTORDEF_H
29
30 #include "SVTK_Selector.h"
31
32 #include <set>
33 #include <map>
34
35 #include <TColStd_IndexedMapOfInteger.hxx>
36 #include <TColStd_MapOfInteger.hxx>
37 #include <vtkSmartPointer.h>
38
39 #include "SALOME_InteractiveObject.hxx"
40
41 class SALOME_Actor;
42
43 class SVTK_Viewer;
44 class SVTK_ViewWindow;
45 class vtkPicker;
46 class vtkCellPicker;
47
48 class SVTK_SelectorDef: public SVTK_Selector
49 {
50 public:
51   SVTK_SelectorDef();
52   virtual ~SVTK_SelectorDef();
53
54   virtual
55   void 
56   SetSelectionMode(Selection_Mode theMode);
57
58   virtual
59   Selection_Mode
60   SelectionMode() const { return mySelectionMode; }
61
62   virtual
63   void
64   ClearIObjects();
65
66   virtual
67   SALOME_Actor* 
68   GetActor(const Handle(SALOME_InteractiveObject)& theIO) const;
69
70   virtual
71   bool
72   IsSelected(const Handle(SALOME_InteractiveObject)& theIO) const;
73
74   virtual
75   bool
76   IsSelected(SALOME_Actor* theActor) const;
77
78   virtual
79   bool
80   AddIObject(const Handle(SALOME_InteractiveObject)& theIO);
81
82   virtual
83   bool
84   AddIObject(SALOME_Actor* theActor);
85
86   virtual
87   bool 
88   RemoveIObject(const Handle(SALOME_InteractiveObject)& theIO);
89
90   virtual
91   bool 
92   RemoveIObject(SALOME_Actor* theActor);
93
94   virtual
95   const SALOME_ListIO& 
96   StoredIObjects() const;
97
98   virtual
99   int 
100   IObjectCount() const;
101
102   virtual
103   bool 
104   HasIndex(const Handle(SALOME_InteractiveObject)& theIO ) const;
105
106   virtual
107   void 
108   GetIndex( const Handle(SALOME_InteractiveObject)& theIO, 
109             SVTK_TIndexedMapOfVtkId& theIndex );
110         
111   virtual
112   bool 
113   AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO, 
114                     const SVTK_TIndexedMapOfVtkId& theIndices, 
115                     bool theIsModeShift);
116   virtual
117   bool 
118   AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO, 
119                     const SVTK_TVtkIDsMap& theIndices, 
120                     bool theIsModeShift);
121   virtual
122   bool
123   AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO, 
124                     int theIndex, 
125                     bool theIsModeShift);
126   virtual
127   void 
128   RemoveIndex( const Handle(SALOME_InteractiveObject)& theIO, 
129                int theIndex);
130   virtual
131   bool 
132   IsIndexSelected(const Handle(SALOME_InteractiveObject)& theIO, 
133                   int theIndex) const;
134   virtual
135   void 
136   ClearIndex();
137
138   //----------------------------------------------------------------------------
139   /// ! Composite indexes 
140   virtual
141   bool 
142   HasCompositeIndex(const Handle(SALOME_InteractiveObject)& theIO ) const;
143
144   virtual
145   void 
146   GetCompositeIndex( const Handle(SALOME_InteractiveObject)& theIO, 
147                      SVTK_IndexedMapOfVtkIds& theIds );        
148   virtual
149   bool 
150   AddOrRemoveCompositeIndex( const Handle(SALOME_InteractiveObject)& theIO, 
151                              const SVTK_IndexedMapOfVtkIds& theIds,
152                              bool theIsModeShift);
153
154   virtual
155   bool
156   AddOrRemoveCompositeIndex( const Handle(SALOME_InteractiveObject)& theIO, 
157                              SVTK_ListOfVtk theIds,
158                              bool theIsModeShift);
159
160   virtual
161   void 
162   RemoveCompositeIndex( const Handle(SALOME_InteractiveObject)& theIO, 
163                         SVTK_ListOfVtk theIds );
164
165   virtual
166   bool 
167   IsCompositeIndexSelected(const Handle(SALOME_InteractiveObject)& theIO, 
168                            SVTK_ListOfVtk theIds ) const;
169
170   virtual
171   void 
172   ClearCompositeIndex();
173
174   //----------------------------------------------------------------------------
175   virtual
176   void 
177   SetFilter(const Handle(VTKViewer_Filter)& theFilter);
178
179   virtual
180   Handle(VTKViewer_Filter) 
181   GetFilter(const TFilterID theId) const;
182
183   virtual
184   bool
185   IsFilterPresent(const TFilterID theId) const;
186
187   virtual
188   void
189   RemoveFilter(const int theId);
190
191   virtual
192   bool
193   IsValid(SALOME_Actor* theActor,
194           const TFilterID theId,
195           const bool theIsNode = false) const;
196   
197   //----------------------------------------------------------------------------
198   virtual
199   void 
200   StartPickCallback();
201
202   virtual
203   void 
204   EndPickCallback();
205
206   //----------------------------------------------------------------------------
207   virtual
208   vtkActorCollection*
209   Pick(const SVTK_SelectionEvent* theEvent, vtkRenderer* theRenderer) const;
210
211   virtual
212   void
213   SetTolerance(const double& theTolerance);
214
215   virtual
216   void
217   SetDynamicPreSelection( bool theIsDynPreselect );
218
219   virtual
220   bool
221   GetDynamicPreSelection() const;
222
223   virtual
224   void
225   SetPreSelectionEnabled( bool theEnabled );
226
227   virtual
228   bool
229   IsPreSelectionEnabled() const;
230
231   virtual
232   void
233   SetSelectionEnabled( bool theEnabled );
234
235   virtual
236   bool
237   IsSelectionEnabled() const;
238
239 private:
240   int mySelectionMode;
241
242   bool myDynamicPreselection;
243   bool myPreselectionEnabled;
244   bool mySelectionEnabled;
245
246   struct TIOLessThan
247   {
248     bool 
249     operator()(const Handle(SALOME_InteractiveObject)& theRightIO,
250                const Handle(SALOME_InteractiveObject)& theLeftIO) const
251     {
252       return strcmp(theRightIO->getEntry(),theLeftIO->getEntry()) < 0;
253     }
254   };
255
256   struct TIndexedMapOfInteger
257   {
258     SVTK_TIndexedMapOfVtkId myMap;
259     TIndexedMapOfInteger()
260     {}
261     TIndexedMapOfInteger(const TIndexedMapOfInteger& theIndexedMapOfInteger)
262     {
263       myMap = theIndexedMapOfInteger.myMap;
264     }
265   };
266
267   mutable SALOME_ListIO myIObjectList;
268   typedef std::set<Handle(SALOME_InteractiveObject),
269                    TIOLessThan> TIObjects;
270   TIObjects myIObjects;
271
272   typedef std::map<Handle(SALOME_InteractiveObject),
273                    vtkSmartPointer<SALOME_Actor>,
274                    TIOLessThan> TIO2Actors;
275   TIO2Actors myIO2Actors;
276
277   typedef std::map<Handle(SALOME_InteractiveObject),
278                    TIndexedMapOfInteger,
279                    TIOLessThan> TMapIOSubIndex;
280   TMapIOSubIndex myMapIOSubIndex;
281
282   typedef std::map<Handle(SALOME_InteractiveObject),
283                    SVTK_IndexedMapOfVtkIds,
284                    TIOLessThan> TMapIOSubCompositeIndex;
285   TMapIOSubCompositeIndex myMapIOSubCompositeIndex;
286
287
288   typedef std::map<TFilterID,Handle(VTKViewer_Filter)> TFilters;
289   TFilters myFilters;
290
291   vtkSmartPointer<vtkPicker> myPicker;
292   vtkSmartPointer<vtkCellPicker> myCellPicker;
293 };
294
295 #endif