Salome HOME
7b2e438d3af5505503d7514f762da532c510a034
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_SelectionOp.h
1 // Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3 //
4 // This library is free software; you can redistribute it and/or 
5 // modify it under the terms of the GNU Lesser General Public 
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License. 
8 //
9 // This library is distributed in the hope that it will be useful, 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details. 
13 //
14 // You should have received a copy of the GNU Lesser General Public 
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 // File   : SMESHGUI_SelectionOp.h
21 // Author : Alexander SOLOVYOV, Open CASCADE S.A.S.
22 //
23
24 #ifndef SMESHGUI_SELECTIONOP_H
25 #define SMESHGUI_SELECTIONOP_H
26
27 // SMESH includes
28 #include "SMESH_SMESHGUI.hxx"
29
30 #include "SMESHGUI_Operation.h"
31 #include "SMESHGUI_Dialog.h"
32
33 // SALOME GUI includes
34 #include <SVTK_Selection.h>
35 #include <SALOME_InteractiveObject.hxx>
36
37 // IDL includes
38 #include <SALOMEconfig.h>
39 #include CORBA_SERVER_HEADER(SMESH_Mesh)
40
41 class SUIT_SelectionFilter;
42 class TColStd_MapOfInteger;
43 class SVTK_ViewWindow;
44 class SVTK_Selector;
45 class SMESH_Actor;
46
47 /*
48   Class       : SMESHGUI_SelectionOp
49   Description : Base operation for all operations using object selection in viewer or objectbrowser
50                 through common widgets created by LightApp_Dialog::createObject
51 */
52 class SMESHGUI_EXPORT SMESHGUI_SelectionOp : public SMESHGUI_Operation
53
54   Q_OBJECT
55
56 public:
57   typedef QList<int> IdList; //! List of node or element ids
58   
59 public:
60   SMESHGUI_SelectionOp( const Selection_Mode = ActorSelection );
61   virtual ~SMESHGUI_SelectionOp();
62
63   static void                   extractIds( const QStringList&, IdList&, const QChar );  
64
65 protected:
66   typedef enum
67   {
68     Object,
69     MeshNode,
70     MeshElement
71
72   } EntityType;
73   /*!
74       This enumeration is used in typeById method to distinguish objects, mesh nodes and mesh elements,
75       because node end element ids may overlap
76   */
77   
78 protected:
79   virtual void                  startOperation();
80   virtual void                  commitOperation();
81   virtual void                  abortOperation();
82   virtual void                  selectionDone();
83
84   //! sets the dialog widgets to state just after operation start
85   virtual void                  initDialog();
86
87   /*!
88    *  Creates filter being used when certain object selection widget is active
89    *  If no filter must be used, then function must return 0
90    *  if id is negative, then function must return filter for common using independently of active widget
91    */
92   virtual SUIT_SelectionFilter* createFilter( const int ) const;
93
94   //! Remove only filters set by this operation (they are in map myFilters )
95   void                          removeCustomFilters();
96
97   //! Return what selection mode is set in VTK viewer
98   Selection_Mode                selectionMode() const;
99
100   //! Set selection mode in VTK viewer
101   void                          setSelectionMode( const Selection_Mode );
102
103   //! Hilight object in VTK viewer
104   void                          highlight( const Handle( SALOME_InteractiveObject )&,
105                                            const bool, const bool = true );
106                                
107   //! Select some nodes or elements in VTK
108   void                          addOrRemoveIndex( const Handle( SALOME_InteractiveObject )&,
109                                                   const TColStd_MapOfInteger&, const bool );
110
111   SVTK_ViewWindow*              viewWindow() const;
112   SVTK_Selector*                selector() const;
113
114   //! Get names, types and ids of selected objects
115   virtual void                  selected( QStringList&, 
116                                           SMESHGUI_Dialog::TypesList&, QStringList& ) const;
117
118   //! Find type by id
119   virtual int                   typeById( const QString&, const EntityType ) const;
120
121   //! Char using to divide <entry> and <id> in string id representation. By default, '#'
122   virtual QChar                 idChar() const;
123
124   //! Try to find in certain object selection widget selected node or element ids and return it
125   void                          selectedIds( const int, IdList& ) const;
126
127   //! Find in QStringList correct node or element ids representation and append integer(id) to IdList
128   void                          extractIds( const QStringList&, IdList& ) const;
129
130   //! Return selected mesh if selection mode isn't ActorSelection and only one object is selected
131   SMESH::SMESH_Mesh_var         mesh() const;
132
133   //! Return actor according to selected mesh if selection mode isn't ActorSelection
134   SMESH_Actor*                  actor() const;
135   
136 protected slots:
137   //! Installs filter corresponding to certain object selection widget
138   virtual void                  onActivateObject( int );
139
140   //! Removes filter corresponding to certain object selection widget
141   virtual void                  onDeactivateObject( int );
142
143   /*!
144     *  Empty default implementation. In successors it may be used for more advanced selection checking.
145     *  This slot is connected to signal when the selection changed in some object selection widget
146   */
147   virtual void                  onSelectionChanged( int );
148
149   /*! Default implementation allowing user to edit selected ids "by hands".
150       In order to run default mechanism, you must set for some
151       object selection widget the "name indication" to "ListOfNames",
152       "read only" state to false and connect the dialog's signal "objectChanged"
153       to this slot
154       Warning: this mechanism can process only integer ids, NOT MESH OR GROUP NAMES!!!
155   */
156   virtual void                  onTextChanged( int, const QStringList& );
157   
158 private:
159   typedef QMap<int, SUIT_SelectionFilter*> Filters;
160   
161 private:
162   Filters         myFilters;
163   Selection_Mode  myDefSelectionMode, myOldSelectionMode;
164 };
165
166 #endif // SMESHGUI_SELECTIONOP_H