+
+//=======================================================================
+// name : selectionMode
+// Purpose : Returns selection mode
+//=======================================================================
+Selection_Mode SMESHGUI_SelectionOp::selectionMode() const
+{
+ SVTK_ViewWindow* wnd = viewWindow();
+ if( wnd )
+ return wnd->SelectionMode();
+ else
+ return ActorSelection;
+}
+
+//=======================================================================
+// name : setSelectionMode
+// Purpose : Set selection mode
+//=======================================================================
+void SMESHGUI_SelectionOp::setSelectionMode( const Selection_Mode mode )
+{
+ SVTK_ViewWindow* wnd = viewWindow();
+ if( wnd )
+ wnd->SetSelectionMode( mode );
+}
+
+//=======================================================================
+// name : highlight
+// Purpose : Highlight object in 3d viewer
+//=======================================================================
+void SMESHGUI_SelectionOp::highlight( const Handle( SALOME_InteractiveObject )& obj,
+ const bool hilight, const bool immediately )
+{
+ SVTK_ViewWindow* wnd = viewWindow();
+ if( wnd )
+ wnd->highlight( obj, hilight, immediately );
+}
+
+//=======================================================================
+// name : addOrRemoveIndex
+// Purpose : Select/deselect cells of mesh
+//=======================================================================
+void SMESHGUI_SelectionOp::addOrRemoveIndex( const Handle( SALOME_InteractiveObject )& obj,
+ const TColStd_MapOfInteger& indices,
+ const bool isModeShift )
+{
+ SVTK_Selector* sel = selector();
+ if( sel )
+ sel->AddOrRemoveIndex( obj, indices, isModeShift );
+}
+
+//=======================================================================
+// name : viewWindow
+// Purpose : Get active view window
+//=======================================================================
+SVTK_ViewWindow* SMESHGUI_SelectionOp::viewWindow() const
+{
+ return SMESH::GetViewWindow( getSMESHGUI() );
+}
+
+//=======================================================================
+// name : selector
+// Purpose : Get selector
+//=======================================================================
+SVTK_Selector* SMESHGUI_SelectionOp::selector() const
+{
+ SVTK_ViewWindow* wnd = viewWindow();
+ return wnd ? wnd->GetSelector() : 0;
+}
+
+//=======================================================================
+// name : typeById
+// Purpose : Find type by id
+//=======================================================================
+int SMESHGUI_SelectionOp::typeById( const QString& str, const EntityType objtype ) const
+{
+ SalomeApp_Study* _study = dynamic_cast<SalomeApp_Study*>( study() );
+ if( !_study )
+ return -1;
+
+ _PTR( Study ) st = _study->studyDS();
+
+ int res = -1;
+ if( objtype == Object )
+ {
+ SalomeApp_Study* _study = dynamic_cast<SalomeApp_Study*>( 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<SALOMEDS_SObject*>( sobj.get() )->GetObject() );
+ if( !CORBA::is_nil( obj ) )
+ res = SMESHGUI_Dialog::prefix( "GEOM" ) + obj->GetType();
+ }
+ }
+ else
+ res = SMESHGUI_Dialog::prefix( "SMESH" ) + t;
+ }
+ }
+ else
+ {
+ int pos = str.find( 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() );
+ SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( dynamic_cast<SALOMEDS_SObject*>( sobj.get() )->GetObject() );
+ SMESH::SMESH_subMesh_var submesh = SMESH::SMESH_subMesh::_narrow( dynamic_cast<SALOMEDS_SObject*>( sobj.get() )->GetObject() );
+ if( !CORBA::is_nil( mesh ) )
+ res = SMESHGUI_Dialog::prefix( "SMESH element" ) + mesh->GetElementType( id, objtype==MeshElement );
+
+ else if( !CORBA::is_nil( submesh ) )
+ res = SMESHGUI_Dialog::prefix( "SMESH element" ) + submesh->GetElementType( id, objtype==MeshElement );
+ }
+ }
+
+ return res;
+}
+
+//=======================================================================
+// name : selected
+// Purpose : Get names, types and ids of selected objects
+//=======================================================================
+void SMESHGUI_SelectionOp::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<SalomeApp_DataOwner*>( (*anIt).operator->() );
+ SalomeApp_SVTKDataOwner* vtkowner = dynamic_cast<SalomeApp_SVTKDataOwner*>( (*anIt).operator->() );
+
+ if( vtkowner )
+ {
+ QString id_str = QString( "%1%2%3" ).arg( vtkowner->entry() ).arg( idChar() ), current_id_str;
+ Selection_Mode mode = vtkowner->GetMode();
+ EntityType 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 <entry> and <id> in string id representation. By default, '#'
+//=======================================================================
+QChar SMESHGUI_SelectionOp::idChar() const
+{
+ return '#';
+}
+
+//=================================================================================
+// name : mesh
+// purpose :
+//=================================================================================
+SMESH::SMESH_Mesh_var SMESHGUI_SelectionOp::mesh() const
+{
+ if( selectionMode()==ActorSelection )
+ return SMESH::SMESH_Mesh::_nil();
+
+ SALOME_ListIO sel; selectionMgr()->selectedObjects( sel, SVTK_Viewer::Type() );
+ if( sel.Extent()==1 )
+ return SMESH::GetMeshByIO( sel.First() );
+ else
+ return SMESH::SMESH_Mesh::_nil();
+}
+
+//=================================================================================
+// name : actor
+// purpose :
+//=================================================================================
+SMESH_Actor* SMESHGUI_SelectionOp::actor() const
+{
+ SMESH::SMESH_Mesh_var m = mesh();
+ if( !m->_is_nil() )
+ return SMESH::FindActorByObject( m.in() );
+ else
+ return 0;
+}
+
+//=================================================================================
+// name : onTextChanged
+// purpose :
+//=================================================================================
+void SMESHGUI_SelectionOp::onTextChanged( int, const QStringList& list )
+{
+ if( !dlg() )
+ return;
+
+ TColStd_MapOfInteger newIndices;
+
+ SALOME_ListIO sel; selectionMgr()->selectedObjects( sel );
+ SMESH_Actor* anActor = actor();
+ if( sel.Extent()==0 || !anActor )
+ return;
+
+ SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
+
+ 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() );
+
+ selector()->AddOrRemoveIndex( sel.First(), newIndices, false );
+ highlight( sel.First(), true, true );
+
+ QStringList names, _ids; SalomeApp_Dialog::TypesList types;
+ selected( names, types, _ids );
+ dlg()->selectObject( names, types, _ids, false );
+}
+
+//=================================================================================
+// name : selectedIds
+// purpose :
+//=================================================================================
+void SMESHGUI_SelectionOp::selectedIds( const int id, IdList& list ) const
+{
+ if( !dlg() )
+ return;
+
+ QStringList ids; dlg()->selectedObject( id, ids );
+ extractIds( ids, list );
+}
+
+//=================================================================================
+// name : extractIds
+// purpose :
+//=================================================================================
+void SMESHGUI_SelectionOp::extractIds( const QStringList& ids, IdList& list, const QChar idchar )
+{
+ QStringList::const_iterator anIt = ids.begin(),
+ aLast = ids.end();
+ QString id_str;
+ for( ; anIt!=aLast; anIt++ )
+ {
+ id_str = *anIt;
+ int pos = idchar=='\0' ? -1 : id_str.find( idchar );
+ int id = -1;
+ if( idchar=='\0' || pos>=0 )
+ {
+ id = id_str.mid( pos+1 ).toInt();
+ list.append( id );
+ }
+ }
+}
+
+//=================================================================================
+// name : extractIds
+// purpose :
+//=================================================================================
+void SMESHGUI_SelectionOp::extractIds( const QStringList& ids, IdList& list ) const
+{
+ extractIds( ids, list, idChar() );
+}