1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
22 // File : SMESHGUI_SelectionOp.cxx
23 // Author : Alexander SOLOVYOV
26 #include <SMESHGUI_SelectionOp.h>
27 #include <SUIT_SelectionFilter.h>
28 #include <SalomeApp_SelectionMgr.h>
31 Class : SMESHGUI_SelectionOp
32 Description : Base operation for all operations using object selection in viewer or objectbrowser
33 through common widgets created by SalomeApp_Dialog::createObject
36 //=================================================================================
37 // name : SMESHGUI_SelectionOp
39 //=================================================================================
40 SMESHGUI_SelectionOp::SMESHGUI_SelectionOp( const Selection_Mode mode )
41 : SMESHGUI_Operation(),
42 myDefSelectionMode( mode )
46 //=================================================================================
47 // name : ~SMESHGUI_SelectionOp
49 //=================================================================================
50 SMESHGUI_SelectionOp::~SMESHGUI_SelectionOp()
52 Filters::const_iterator anIt = myFilters.begin(),
53 aLast = myFilters.end();
54 for( ; anIt!=aLast; anIt++ )
59 //=================================================================================
60 // name : startOperation
62 //=================================================================================
63 void SMESHGUI_SelectionOp::startOperation()
65 SMESHGUI_Operation::startOperation();
68 disconnect( dlg(), SIGNAL( objectActivated( int ) ), this, SLOT( onActivateObject( int ) ) );
69 disconnect( dlg(), SIGNAL( objectDeactivated( int ) ), this, SLOT( onDeactivateObject( int ) ) );
70 disconnect( dlg(), SIGNAL( selectionChanged( int ) ), this, SLOT( onSelectionChanged( int ) ) );
71 connect( dlg(), SIGNAL( objectActivated( int ) ), this, SLOT( onActivateObject( int ) ) );
72 connect( dlg(), SIGNAL( objectDeactivated( int ) ), this, SLOT( onDeactivateObject( int ) ) );
73 connect( dlg(), SIGNAL( selectionChanged( int ) ), this, SLOT( onSelectionChanged( int ) ) );
76 myOldSelectionMode = selectionMode();
77 setSelectionMode( myDefSelectionMode );
80 //=================================================================================
81 // name : removeCustomFilters
83 //=================================================================================
84 void SMESHGUI_SelectionOp::removeCustomFilters() const
86 SalomeApp_SelectionMgr* mgr = selectionMgr();
90 Filters::const_iterator anIt = myFilters.begin(),
91 aLast = myFilters.end();
92 for( ; anIt!=aLast; anIt++ )
94 mgr->removeFilter( anIt.data() );
97 //=================================================================================
98 // name : commitOperation
100 //=================================================================================
101 void SMESHGUI_SelectionOp::commitOperation()
103 removeCustomFilters();
104 setSelectionMode( myOldSelectionMode );
105 SMESHGUI_Operation::commitOperation();
108 //=================================================================================
109 // name : abortOperation
111 //=================================================================================
112 void SMESHGUI_SelectionOp::abortOperation()
114 removeCustomFilters();
115 setSelectionMode( myOldSelectionMode );
116 SMESHGUI_Operation::abortOperation();
119 //=================================================================================
120 // name : selectionDone
122 //=================================================================================
123 void SMESHGUI_SelectionOp::selectionDone()
128 QStringList names, ids;
129 SalomeApp_Dialog::TypesList types;
130 selected( names, types, ids );
131 dlg()->selectObject( names, types, ids );
134 //=================================================================================
135 // name : createFilter
137 //=================================================================================
138 SUIT_SelectionFilter* SMESHGUI_SelectionOp::createFilter( const int ) const
143 //=================================================================================
144 // name : onActivateObject
146 //=================================================================================
147 void SMESHGUI_SelectionOp::onActivateObject( int id )
149 SalomeApp_SelectionMgr* mgr = selectionMgr();
153 if( !myFilters.contains( id ) )
154 myFilters[ id ] = createFilter( id );
156 if( myFilters[ id ] )
157 mgr->installFilter( myFilters[ id ] );
162 //=================================================================================
163 // name : onDeactivateObject
165 //=================================================================================
166 void SMESHGUI_SelectionOp::onDeactivateObject( int id )
168 SalomeApp_SelectionMgr* mgr = selectionMgr();
169 if( mgr && myFilters.contains( id ) && myFilters[ id ] )
170 mgr->removeFilter( myFilters[ id ] );
173 //=================================================================================
176 //=================================================================================
177 void SMESHGUI_SelectionOp::initDialog()
181 dlg()->clearSelection();
182 dlg()->deactivateAll();
186 //=================================================================================
189 //=================================================================================
190 void SMESHGUI_SelectionOp::onSelectionChanged( int )