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