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