Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[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 //
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 "SMESH_SMESHGUI.hxx"
31
32 #include <SMESHGUI_Operation.h>
33 #include <SMESHGUI_Dialog.h>
34 #include <SVTK_Selection.h>
35 #include <SALOME_InteractiveObject.hxx>
36
37 #include <SALOMEconfig.h>
38 #include CORBA_SERVER_HEADER(SMESH_Gen)
39
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 QValueList<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&, SMESHGUI_Dialog::TypesList&, QStringList& ) const;
116
117   //! Find type by id
118   virtual int       typeById( const QString&, const EntityType ) const;
119
120   //! Char using to divide <entry> and <id> in string id representation. By default, '#'
121   virtual QChar     idChar() const;
122
123   //! Try to find in certain object selection widget selected node or element ids and return it
124   void                   selectedIds( const int, IdList& ) const;
125
126   //! Find in QStringList correct node or element ids representation and append integer(id) to IdList
127   void                   extractIds( const QStringList&, IdList& ) const;
128
129   //! Return selected mesh if selection mode isn't ActorSelection and only one object is selected
130   SMESH::SMESH_Mesh_var  mesh() const;
131
132   //! Return actor according to selected mesh if selection mode isn't ActorSelection
133   SMESH_Actor*           actor() const;
134   
135 protected slots:
136   //! Installs filter corresponding to certain object selection widget
137   virtual void onActivateObject( int );
138
139   //! Removes filter corresponding to certain object selection widget
140   virtual void onDeactivateObject( int );
141
142   /*!
143     *  Empty default implementation. In successors it may be used for more advanced selection checking.
144     *  This slot is connected to signal when the selection changed in some object selection widget
145   */
146   virtual void onSelectionChanged( int );
147
148   /*! Default implementation allowing user to edit selected ids "by hands".
149       In order to run default mechanism, you must set for some
150       object selection widget the "name indication" to "ListOfNames",
151       "read only" state to false and connect the dialog's signal "objectChanged"
152       to this slot
153       Warning: this mechanism can process only integer ids, NOT MESH OR GROUP NAMES!!!
154   */
155   virtual void  onTextChanged( int, const QStringList& );
156   
157 private:
158   typedef QMap<int, SUIT_SelectionFilter*> Filters;
159   
160 private:
161   Filters         myFilters;
162   Selection_Mode  myDefSelectionMode, myOldSelectionMode;
163 };
164
165 #endif