X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESHGUI%2FSMESHGUI_SelectionOp.cxx;h=ce349a055b67c6833ce83d28e6694e2c6e38d076;hp=6992319581dfa5c7bfbf82eb7c29229d10160c5e;hb=bd8f1aee7c78f7d2eb82bd4fec5e08c9e3d280ce;hpb=b0105f0f9d05ef09ad770cf0d343901589cba620 diff --git a/src/SMESHGUI/SMESHGUI_SelectionOp.cxx b/src/SMESHGUI/SMESHGUI_SelectionOp.cxx index 699231958..ce349a055 100644 --- a/src/SMESHGUI/SMESHGUI_SelectionOp.cxx +++ b/src/SMESHGUI/SMESHGUI_SelectionOp.cxx @@ -1,54 +1,57 @@ -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE // +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. // -// File : SMESHGUI_SelectionOp.cxx -// Author : Alexander SOLOVYOV -// Module : SMESH - -#include -#include -#include -#include -#include +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : SMESHGUI_SelectionOp.cxx +// Author : Alexander SOLOVYOV, Open CASCADE S.A.S. +// SMESH includes +// +#include "SMESHGUI_SelectionOp.h" + +#include "SMESHGUI.h" +#include "SMESHGUI_VTKUtils.h" +#include "SMESHGUI_MeshUtils.h" +#include "SMESHGUI_Selection.h" + +#include +#include +#include + +// SALOME GUI includes #include -#include +#include #include -#include #include #include -#include -#include -#include -#include +#include +#include -#include CORBA_SERVER_HEADER(GEOM_Gen) +// SALOME KERNEL includes #include -#include - /* Class : SMESHGUI_SelectionOp Description : Base operation for all operations using object selection in viewer or objectbrowser - through common widgets created by SalomeApp_Dialog::createObject + through common widgets created by LightApp_Dialog::createObject */ //================================================================================= @@ -67,11 +70,7 @@ SMESHGUI_SelectionOp::SMESHGUI_SelectionOp( const Selection_Mode mode ) //================================================================================= SMESHGUI_SelectionOp::~SMESHGUI_SelectionOp() { - Filters::const_iterator anIt = myFilters.begin(), - aLast = myFilters.end(); - for( ; anIt!=aLast; anIt++ ) - if( anIt.data() ) - delete anIt.data(); + removeCustomFilters(); } //================================================================================= @@ -80,6 +79,9 @@ SMESHGUI_SelectionOp::~SMESHGUI_SelectionOp() //================================================================================= void SMESHGUI_SelectionOp::startOperation() { + myOldSelectionMode = selectionMode(); + setSelectionMode( myDefSelectionMode ); + SMESHGUI_Operation::startOperation(); if( dlg() ) { @@ -90,26 +92,27 @@ void SMESHGUI_SelectionOp::startOperation() connect( dlg(), SIGNAL( objectDeactivated( int ) ), this, SLOT( onDeactivateObject( int ) ) ); connect( dlg(), SIGNAL( selectionChanged( int ) ), this, SLOT( onSelectionChanged( int ) ) ); } - - myOldSelectionMode = selectionMode(); - setSelectionMode( myDefSelectionMode ); } //================================================================================= // name : removeCustomFilters // purpose : //================================================================================= -void SMESHGUI_SelectionOp::removeCustomFilters() const +void SMESHGUI_SelectionOp::removeCustomFilters() { - SalomeApp_SelectionMgr* mgr = selectionMgr(); - if( !mgr ) - return; - - Filters::const_iterator anIt = myFilters.begin(), - aLast = myFilters.end(); - for( ; anIt!=aLast; anIt++ ) - if( anIt.data() ) - mgr->removeFilter( anIt.data() ); + if (myFilters.count() > 0) { + LightApp_SelectionMgr* mgr = selectionMgr(); + Filters::const_iterator anIt = myFilters.begin(), + aLast = myFilters.end(); + for ( ; anIt != aLast; anIt++) { + if (anIt.value()) { + if (mgr) mgr->removeFilter(anIt.value()); + delete anIt.value(); + } + } + + myFilters.clear(); + } } //================================================================================= @@ -118,9 +121,9 @@ void SMESHGUI_SelectionOp::removeCustomFilters() const //================================================================================= void SMESHGUI_SelectionOp::commitOperation() { + SMESHGUI_Operation::commitOperation(); removeCustomFilters(); setSelectionMode( myOldSelectionMode ); - SMESHGUI_Operation::commitOperation(); } //================================================================================= @@ -129,9 +132,9 @@ void SMESHGUI_SelectionOp::commitOperation() //================================================================================= void SMESHGUI_SelectionOp::abortOperation() { + SMESHGUI_Operation::abortOperation(); removeCustomFilters(); setSelectionMode( myOldSelectionMode ); - SMESHGUI_Operation::abortOperation(); } //================================================================================= @@ -156,7 +159,7 @@ void SMESHGUI_SelectionOp::selectionDone() } QStringList names, ids; - SalomeApp_Dialog::TypesList types; + LightApp_Dialog::TypesList types; selected( names, types, ids ); dlg()->selectObject( names, types, ids ); } @@ -176,7 +179,7 @@ SUIT_SelectionFilter* SMESHGUI_SelectionOp::createFilter( const int ) const //================================================================================= void SMESHGUI_SelectionOp::onActivateObject( int id ) { - SalomeApp_SelectionMgr* mgr = selectionMgr(); + LightApp_SelectionMgr* mgr = selectionMgr(); if( !mgr ) return; @@ -195,9 +198,7 @@ void SMESHGUI_SelectionOp::onActivateObject( int id ) //================================================================================= void SMESHGUI_SelectionOp::onDeactivateObject( int id ) { - SalomeApp_SelectionMgr* mgr = selectionMgr(); - if( mgr && myFilters.contains( id ) && myFilters[ id ] ) - mgr->removeFilter( myFilters[ id ] ); + removeCustomFilters(); } //================================================================================= @@ -311,7 +312,7 @@ int SMESHGUI_SelectionOp::typeById( const QString& str, const EntityType objtype if( t<0 ) { //try to get GEOM type - _PTR( SObject ) sobj = st->FindObjectID( str.latin1() ); + _PTR( SObject ) sobj = st->FindObjectID( str.toLatin1().data() ); if( sobj ) { GEOM::GEOM_Object_var obj = GEOM::GEOM_Object::_narrow( @@ -326,14 +327,14 @@ int SMESHGUI_SelectionOp::typeById( const QString& str, const EntityType objtype } else { - int pos = str.find( idChar() ); + int pos = str.indexOf( idChar() ); QString entry = str.left( pos ), _id = str.mid( pos+1 ); bool ok; int id = _id.toInt( &ok ); if( ok ) { - _PTR( SObject ) sobj = st->FindObjectID( entry.latin1() ); + _PTR( SObject ) sobj = st->FindObjectID( entry.toLatin1().data() ); SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( dynamic_cast( sobj.get() )->GetObject() ); SMESH::SMESH_subMesh_var submesh = SMESH::SMESH_subMesh::_narrow( @@ -356,7 +357,7 @@ int SMESHGUI_SelectionOp::typeById( const QString& str, const EntityType objtype // Purpose : Get names, types and ids of selected objects //======================================================================= void SMESHGUI_SelectionOp::selected( QStringList& names, - SalomeApp_Dialog::TypesList& types, + LightApp_Dialog::TypesList& types, QStringList& ids ) const { /* SUIT_DataOwnerPtrList list; selectionMgr()->selected( list ); @@ -364,8 +365,8 @@ void SMESHGUI_SelectionOp::selected( QStringList& names, aLast = list.end(); for( ; anIt!=aLast; anIt++ ) { - SalomeApp_DataOwner* owner = dynamic_cast( (*anIt).operator->() ); - SalomeApp_SVTKDataOwner* vtkowner = dynamic_cast( (*anIt).operator->() ); + LightApp_DataOwner* owner = dynamic_cast( (*anIt).operator->() ); + LightApp_SVTKDataOwner* vtkowner = dynamic_cast( (*anIt).operator->() ); if( vtkowner ) { @@ -403,7 +404,7 @@ void SMESHGUI_SelectionOp::selected( QStringList& names, { selIndices.Clear(); selectionMgr()->GetIndexes( anIt.Value(), selIndices ); - if( selIndices.Extent()==0 ) + if( selIndices.Extent() > 0 ) { QString id_str = QString( "%1%2%3" ).arg( anIt.Value()->getEntry() ).arg( idChar() ), current_id_str; for( int i=1, n=selIndices.Extent(); i<=n; i++ ) @@ -420,7 +421,13 @@ void SMESHGUI_SelectionOp::selected( QStringList& names, QString id = anIt.Value()->getEntry(); ids.append( id ); types.append( typeById( id, Object ) ); - names.append( anIt.Value()->getName() ); + SalomeApp_Study* _study = dynamic_cast( study() ); + if( _study ) + { + _PTR(SObject) obj = _study->studyDS()->FindObjectID( anIt.Value()->getEntry() ); + if( obj ) + names.append( obj->GetName().c_str() ); + } } } } @@ -484,14 +491,21 @@ void SMESHGUI_SelectionOp::onTextChanged( int, const QStringList& list ) IdList ids; extractIds( list, ids, '\0' ); IdList::const_iterator anIt = ids.begin(), aLast = ids.end(); - for( ; anIt!=aLast; anIt++ ) - if( const SMDS_MeshNode * n = aMesh->FindNode( *anIt ) ) - newIndices.Add( n->GetID() ); + if ( selectionMode() == NodeSelection ) + for( ; anIt!=aLast; anIt++ ) { + if( const SMDS_MeshNode * n = aMesh->FindNode( *anIt ) ) + newIndices.Add( n->GetID() ); + } + else + for( ; anIt!=aLast; anIt++ ) { + if( const SMDS_MeshElement* e = aMesh->FindElement( *anIt ) ) + newIndices.Add( e->GetID() ); + } selector()->AddOrRemoveIndex( sel.First(), newIndices, false ); highlight( sel.First(), true, true ); - QStringList names, _ids; SalomeApp_Dialog::TypesList types; + QStringList names, _ids; LightApp_Dialog::TypesList types; selected( names, types, _ids ); dlg()->selectObject( names, types, _ids, false ); } @@ -521,7 +535,7 @@ void SMESHGUI_SelectionOp::extractIds( const QStringList& ids, IdList& list, con for( ; anIt!=aLast; anIt++ ) { id_str = *anIt; - int pos = idchar=='\0' ? -1 : id_str.find( idchar ); + int pos = idchar=='\0' ? -1 : id_str.indexOf( idchar ); int id = -1; if( idchar=='\0' || pos>=0 ) {