Salome HOME
correct previous integration (Porting to Python 2.6)
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_SelectionOp.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 // File   : SMESHGUI_SelectionOp.h
23 // Author : Alexander SOLOVYOV, Open CASCADE S.A.S.
24 //
25 #ifndef SMESHGUI_SELECTIONOP_H
26 #define SMESHGUI_SELECTIONOP_H
27
28 // SMESH includes
29 #include "SMESH_SMESHGUI.hxx"
30
31 #include "SMESHGUI_Operation.h"
32 #include "SMESHGUI_Dialog.h"
33
34 // SALOME GUI includes
35 #include <SVTK_Selection.h>
36 #include <SALOME_InteractiveObject.hxx>
37
38 // IDL includes
39 #include <SALOMEconfig.h>
40 #include CORBA_SERVER_HEADER(SMESH_Mesh)
41
42 class SUIT_SelectionFilter;
43 class TColStd_MapOfInteger;
44 class SVTK_ViewWindow;
45 class SVTK_Selector;
46 class SMESH_Actor;
47
48 /*
49   Class       : SMESHGUI_SelectionOp
50   Description : Base operation for all operations using object selection in viewer or objectbrowser
51                 through common widgets created by LightApp_Dialog::createObject
52 */
53 class SMESHGUI_EXPORT SMESHGUI_SelectionOp : public SMESHGUI_Operation
54
55   Q_OBJECT
56
57 public:
58   typedef QList<int> IdList; //! List of node or element ids
59   
60 public:
61   SMESHGUI_SelectionOp( const Selection_Mode = ActorSelection );
62   virtual ~SMESHGUI_SelectionOp();
63
64   static void                   extractIds( const QStringList&, IdList&, const QChar );  
65
66 protected:
67   typedef enum
68   {
69     Object,
70     MeshNode,
71     MeshElement
72
73   } EntityType;
74   /*!
75       This enumeration is used in typeById method to distinguish objects, mesh nodes and mesh elements,
76       because node end element ids may overlap
77   */
78   
79 protected:
80   virtual void                  startOperation();
81   virtual void                  commitOperation();
82   virtual void                  abortOperation();
83   virtual void                  selectionDone();
84
85   //! sets the dialog widgets to state just after operation start
86   virtual void                  initDialog();
87
88   /*!
89    *  Creates filter being used when certain object selection widget is active
90    *  If no filter must be used, then function must return 0
91    *  if id is negative, then function must return filter for common using independently of active widget
92    */
93   virtual SUIT_SelectionFilter* createFilter( const int ) const;
94
95   //! Remove only filters set by this operation (they are in map myFilters )
96   void                          removeCustomFilters();
97
98   //! Return what selection mode is set in VTK viewer
99   Selection_Mode                selectionMode() const;
100
101   //! Set selection mode in VTK viewer
102   void                          setSelectionMode( const Selection_Mode );
103
104   //! Hilight object in VTK viewer
105   void                          highlight( const Handle( SALOME_InteractiveObject )&,
106                                            const bool, const bool = true );
107                                
108   //! Select some nodes or elements in VTK
109   void                          addOrRemoveIndex( const Handle( SALOME_InteractiveObject )&,
110                                                   const TColStd_MapOfInteger&, const bool isModeShift);
111
112   SVTK_ViewWindow*              viewWindow() const;
113   SVTK_Selector*                selector() const;
114
115   //! Get names, types and ids of selected objects
116   virtual void                  selected( QStringList&, 
117                                           SMESHGUI_Dialog::TypesList&, QStringList& ) const;
118
119   //! Find type by id
120   virtual int                   typeById( const QString&, const EntityType ) const;
121
122   //! Char using to divide <entry> and <id> in string id representation. By default, '#'
123   virtual QChar                 idChar() const;
124
125   //! Try to find in certain object selection widget selected node or element ids and return it
126   void                          selectedIds( const int, IdList& ) const;
127
128   //! Find in QStringList correct node or element ids representation and append integer(id) to IdList
129   void                          extractIds( const QStringList&, IdList& ) const;
130
131   //! Return selected mesh if selection mode isn't ActorSelection and only one object is selected
132   SMESH::SMESH_Mesh_var         mesh() const;
133
134   //! Return actor according to selected mesh if selection mode isn't ActorSelection
135   SMESH_Actor*                  actor() const;
136   
137 protected slots:
138   //! Installs filter corresponding to certain object selection widget
139   virtual void                  onActivateObject( int );
140
141   //! Removes filter corresponding to certain object selection widget
142   virtual void                  onDeactivateObject( int );
143
144   /*!
145     *  Empty default implementation. In successors it may be used for more advanced selection checking.
146     *  This slot is connected to signal when the selection changed in some object selection widget
147   */
148   virtual void                  onSelectionChanged( int );
149
150   /*! Default implementation allowing user to edit selected ids "by hands".
151       In order to run default mechanism, you must set for some
152       object selection widget the "name indication" to "ListOfNames",
153       "read only" state to false and connect the dialog's signal "objectChanged"
154       to this slot
155       Warning: this mechanism can process only integer ids, NOT MESH OR GROUP NAMES!!!
156   */
157   virtual void                  onTextChanged( int, const QStringList& );
158   
159 private:
160   typedef QMap<int, SUIT_SelectionFilter*> Filters;
161   
162 private:
163   Filters         myFilters;
164   Selection_Mode  myDefSelectionMode, myOldSelectionMode;
165 };
166
167 #endif // SMESHGUI_SELECTIONOP_H