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_SelectionIdsOp.cxx
23 // Author : Alexander SOLOVYOV
26 #include <SMESHGUI_SelectionIdsOp.h>
27 #include <SMESHGUI_Utils.h>
28 #include <SMESHGUI_VTKUtils.h>
29 #include <SMESHGUI_MeshUtils.h>
31 #include <SalomeApp_SelectionMgr.h>
33 #include <SALOME_ListIO.hxx>
34 #include <SVTK_ViewModel.h>
35 #include <SVTK_Selector.h>
37 #include <SMDS_Mesh.hxx>
38 #include <SMESH_Actor.h>
40 #include <TColStd_MapOfInteger.hxx>
43 Class : SMESHGUI_SelectionIdsOp
47 //=================================================================================
48 // name : SMESHGUI_SelectionIdsOp
50 //=================================================================================
51 SMESHGUI_SelectionIdsOp::SMESHGUI_SelectionIdsOp( const Selection_Mode mode )
52 : SMESHGUI_SelectionOp( mode )
56 //=================================================================================
57 // name : ~SMESHGUI_SelectionIdsOp
59 //=================================================================================
60 SMESHGUI_SelectionIdsOp::~SMESHGUI_SelectionIdsOp()
64 //=================================================================================
65 // name : startOperation
67 //=================================================================================
68 void SMESHGUI_SelectionIdsOp::startOperation()
70 SMESHGUI_SelectionOp::startOperation();
73 disconnect( dlg(), SIGNAL( objectChanged( int, const QStringList& ) ),
74 this, SLOT( onTextChanged( int, const QStringList& ) ) );
75 connect( dlg(), SIGNAL( objectChanged( int, const QStringList& ) ),
76 this, SLOT( onTextChanged( int, const QStringList& ) ) );
80 //=================================================================================
81 // name : commitOperation
83 //=================================================================================
84 void SMESHGUI_SelectionIdsOp::commitOperation()
86 SMESHGUI_SelectionOp::commitOperation();
87 myMesh = SMESH::SMESH_Mesh::_nil();
90 //=================================================================================
91 // name : abortOperation
93 //=================================================================================
94 void SMESHGUI_SelectionIdsOp::abortOperation()
96 SMESHGUI_SelectionOp::abortOperation();
97 myMesh = SMESH::SMESH_Mesh::_nil();
100 //=================================================================================
101 // name : selectionDone
103 //=================================================================================
104 void SMESHGUI_SelectionIdsOp::selectionDone()
111 selectionMgr()->selectedObjects(aList,SVTK_Viewer::Type());
113 if( aList.Extent() != 1)
115 myMesh = SMESH::SMESH_Mesh::_nil();
116 dlg()->clearSelection();
120 Handle(SALOME_InteractiveObject) anIO = aList.First();
121 myMesh = SMESH::GetMeshByIO(anIO);
123 QStringList names, ids; SalomeApp_Dialog::TypesList types;
124 selected( names, types, ids );
125 dlg()->selectObject( names, types, ids );
128 //=================================================================================
131 //=================================================================================
132 SMESH::SMESH_Mesh_var SMESHGUI_SelectionIdsOp::mesh() const
137 //=================================================================================
140 //=================================================================================
141 SMESH_Actor* SMESHGUI_SelectionIdsOp::actor() const
143 return SMESH::FindActorByObject( myMesh.in() );
146 //=================================================================================
147 // name : onTextChanged
149 //=================================================================================
150 void SMESHGUI_SelectionIdsOp::onTextChanged( int, const QStringList& list )
155 TColStd_MapOfInteger newIndices;
157 SALOME_ListIO sel; selectionMgr()->selectedObjects( sel );
158 SMESH_Actor* anActor = actor();
159 if( sel.Extent()==0 || !anActor )
162 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
164 IdList ids; extractIds( list, ids, '\0' );
165 IdList::const_iterator anIt = ids.begin(),
167 for( ; anIt!=aLast; anIt++ )
168 if( const SMDS_MeshNode * n = aMesh->FindNode( *anIt ) )
169 newIndices.Add( n->GetID() );
171 selector()->AddOrRemoveIndex( sel.First(), newIndices, false );
172 highlight( sel.First(), true, true );
174 QStringList names, _ids; SalomeApp_Dialog::TypesList types;
175 selected( names, types, _ids );
176 dlg()->selectObject( names, types, _ids, false );
179 //=================================================================================
180 // name : selectedIds
182 //=================================================================================
183 void SMESHGUI_SelectionIdsOp::selectedIds( const int id, IdList& list ) const
188 QStringList ids; dlg()->selectedObject( id, ids );
189 extractIds( ids, list );
192 //=================================================================================
195 //=================================================================================
196 void SMESHGUI_SelectionIdsOp::extractIds( const QStringList& ids, IdList& list, const QChar idchar )
198 QStringList::const_iterator anIt = ids.begin(),
201 for( ; anIt!=aLast; anIt++ )
204 int pos = idchar=='\0' ? -1 : id_str.find( idchar );
206 if( idchar=='\0' || pos>=0 )
208 id = id_str.mid( pos+1 ).toInt();
214 //=================================================================================
217 //=================================================================================
218 void SMESHGUI_SelectionIdsOp::extractIds( const QStringList& ids, IdList& list ) const
220 extractIds( ids, list, idChar() );