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