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