From: asl Date: Mon, 4 Jul 2005 10:45:26 +0000 (+0000) Subject: The default method of selection management is added: X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c7d2780341a6a3df9dfe6ff711338e6d1d11d817;p=modules%2Fsmesh.git The default method of selection management is added: selected( ... ) the lists filled by this method can be passed to dialog::selectObject method in selectionDone() to implement default selection management --- diff --git a/src/SMESHGUI/SMESHGUI_Operation.cxx b/src/SMESHGUI/SMESHGUI_Operation.cxx index 6ebf2d2b7..b2af6a075 100755 --- a/src/SMESHGUI/SMESHGUI_Operation.cxx +++ b/src/SMESHGUI/SMESHGUI_Operation.cxx @@ -11,12 +11,20 @@ #include "SMESHGUI_Operation.h" #include "SMESHGUI.h" #include "SMESHGUI_VTKUtils.h" +#include "SMESHGUI_Selection.h" #include #include #include #include +#include +#include +#include + +#include + +#include /* Class : SMESHGUI_Operation @@ -126,9 +134,129 @@ bool SMESHGUI_Operation::isReadyToStart() tr( "NO_MODULE" ), tr( "SMESH_BUT_OK" ) ); return false; } + + return true; +} + +//======================================================================= +// name : typeById +// Purpose : Find type by id +//======================================================================= +int SMESHGUI_Operation::typeById( const QString& str, const SelectedObjectType objtype ) const +{ + SalomeApp_Study* _study = dynamic_cast( study() ); + if( !_study ) + return -1; + + _PTR( Study ) st = _study->studyDS(); + + int res = -1; + if( objtype == Object ) + { + SalomeApp_Study* _study = dynamic_cast( study() ); + if( _study ) + { + int t = SMESHGUI_Selection::type( str, _study->studyDS() ); + if( t<0 ) + { + //try to get GEOM type + _PTR( SObject ) sobj = st->FindObjectID( str.latin1() ); + if( sobj ) + { + GEOM::GEOM_Object_var obj = GEOM::GEOM_Object::_narrow( dynamic_cast( sobj.get() )->GetObject() ); + if( !CORBA::is_nil( obj ) ) + res = prefix( "GEOM" ) + obj->GetType(); + } + } + else + res = prefix( "SMESH" ) + t; + } + } + else + { + int pos = str.find( idChar() ); + QString entry = str.left( pos-1 ), + _id = str.mid( pos+1 ); + bool ok; + int id = _id.toInt( &ok ); + if( ok ) + { + _PTR( SObject ) sobj = st->FindObjectID( entry.latin1() ); + SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( dynamic_cast( sobj.get() )->GetObject() ); + SMESH::SMESH_subMesh_var submesh = SMESH::SMESH_subMesh::_narrow( dynamic_cast( sobj.get() )->GetObject() ); + if( !CORBA::is_nil( mesh ) ) + res = prefix( "SMESH element" ) + mesh->GetElementType( id, objtype==MeshElement ); + + else if( !CORBA::is_nil( submesh ) ) + res = prefix( "SMESH element" ) + submesh->GetElementType( id, objtype==MeshElement ); + } + } + + return res; } +//======================================================================= +// name : prefix +// Purpose : Get prefix for module types +//======================================================================= +int SMESHGUI_Operation::prefix( const QString& name ) const +{ + if( name == "GEOM" ) + return 100; + else if( name == "SMESH" ) + return 200; + else if( name == "SMESH element" ) + return 300; + else + return 0; +} +//======================================================================= +// name : selected +// Purpose : Get names, types and ids of selected objects +//======================================================================= +void SMESHGUI_Operation::selected( QStringList& names, SalomeApp_Dialog::TypesList& types, QStringList& ids ) const +{ + SUIT_DataOwnerPtrList list; selectionMgr()->selected( list ); + SUIT_DataOwnerPtrList::const_iterator anIt = list.begin(), + aLast = list.end(); + for( ; anIt!=aLast; anIt++ ) + { + SalomeApp_DataOwner* owner = dynamic_cast( (*anIt).operator->() ); + SalomeApp_SVTKDataOwner* vtkowner = dynamic_cast( (*anIt).operator->() ); + if( vtkowner ) + { + QString id_str = QString( "%1%2%3" ).arg( vtkowner->entry() ).arg( idChar() ), current_id_str; + Selection_Mode mode = vtkowner->GetMode(); + SelectedObjectType objtype = mode == NodeSelection ? MeshNode : MeshElement; + const TColStd_IndexedMapOfInteger& ownerids = vtkowner->GetIds(); + for( int i=1, n=ownerids.Extent(); i<=n; i++ ) + { + int curid = ownerids( i ); + current_id_str = id_str.arg( curid ); + ids.append( current_id_str ); + types.append( typeById( current_id_str, objtype ) ); + names.append( QString( "%1" ).arg( curid ) ); + } + } + else if( owner ) + { + QString id = owner->entry(); + ids.append( id ); + types.append( typeById( id, Object ) ); + names.append( owner->IO()->getName() ); + } + } +} + +//======================================================================= +// name : idChar +// Purpose : Char using to divide and in string id representation. By default, '#' +//======================================================================= +QChar SMESHGUI_Operation::idChar() const +{ + return '#'; +} diff --git a/src/SMESHGUI/SMESHGUI_Operation.h b/src/SMESHGUI/SMESHGUI_Operation.h index cbda5f6d0..a0af7f0b2 100755 --- a/src/SMESHGUI/SMESHGUI_Operation.h +++ b/src/SMESHGUI/SMESHGUI_Operation.h @@ -36,7 +36,15 @@ public: virtual ~SMESHGUI_Operation(); protected: + typedef enum + { + Object, + MeshNode, + MeshElement + } SelectedObjectType; + +protected: void setSelectionMode( const Selection_Mode ); void highlight( const Handle( SALOME_InteractiveObject )&, const bool, const bool = true ); @@ -45,10 +53,25 @@ protected: virtual void startOperation(); virtual bool isReadyToStart(); - + SMESHGUI* getSMESHGUI() const; SVTK_ViewWindow* viewWindow() const; SVTK_Selector* selector() const; + + + + virtual int prefix( const QString& ) const; + // Return hard-coded prefix using to differ intersecting types + + virtual void selected( QStringList&, SalomeApp_Dialog::TypesList&, QStringList& ) const; + // Get names, types and ids of selected objects + + virtual int typeById( const QString&, const SelectedObjectType ) const; + // Find type by id + + virtual QChar idChar() const; + // Char using to divide and in string id representation + // By default, '#' };