3 // Copyright (C) 2005 CEA/DEN, EDF R&D
7 // File : SMESHGUI_Operation.h
8 // Author : Sergey LITONIN
11 #include "SMESHGUI_Operation.h"
13 #include "SMESHGUI_VTKUtils.h"
14 #include "SMESHGUI_Selection.h"
16 #include <SVTK_ViewWindow.h>
17 #include <SVTK_Selector.h>
18 #include <SUIT_MessageBox.h>
19 #include <SUIT_Desktop.h>
21 #include <SalomeApp_Study.h>
22 #include <SalomeApp_VTKSelector.h>
23 #include <SalomeApp_SelectionMgr.h>
25 #include <SALOMEDS_SObject.hxx>
27 #include <SMESHDS_Mesh.hxx>
30 Class : SMESHGUI_Operation
31 Description : Base class for all SMESH operations
34 //=======================================================================
35 // name : SMESHGUI_Operation
36 // Purpose : Constructor
37 //=======================================================================
38 SMESHGUI_Operation::SMESHGUI_Operation( SalomeApp_Application* app )
39 : SalomeApp_Operation( app )
44 SMESHGUI_Operation::~SMESHGUI_Operation()
49 //=======================================================================
50 // name : setSelectionMode
51 // Purpose : Set selection mode
52 //=======================================================================
53 void SMESHGUI_Operation::setSelectionMode( const Selection_Mode mode )
55 SVTK_ViewWindow* wnd = viewWindow();
57 wnd->SetSelectionMode( mode );
60 //=======================================================================
62 // Purpose : Highlight object in 3d viewer
63 //=======================================================================
64 void SMESHGUI_Operation::highlight( const Handle( SALOME_InteractiveObject )& obj,
65 const bool hilight, const bool immediately )
67 SVTK_ViewWindow* wnd = viewWindow();
69 wnd->highlight( obj, hilight, immediately );
72 //=======================================================================
73 // name : addOrRemoveIndex
74 // Purpose : Select/deselect cells of mesh
75 //=======================================================================
76 void SMESHGUI_Operation::addOrRemoveIndex( const Handle( SALOME_InteractiveObject )& obj,
77 const TColStd_MapOfInteger& indices,
78 const bool isModeShift )
80 SVTK_Selector* sel = selector();
82 sel->AddOrRemoveIndex( obj, indices, isModeShift );
85 //=======================================================================
87 // Purpose : Get SMESH module
88 //=======================================================================
89 SMESHGUI* SMESHGUI_Operation::getSMESHGUI() const
91 return dynamic_cast<SMESHGUI*>( module() );
94 //=======================================================================
96 // Purpose : Get active view window
97 //=======================================================================
98 SVTK_ViewWindow* SMESHGUI_Operation::viewWindow() const
100 return SMESH::GetViewWindow( getSMESHGUI() );
103 //=======================================================================
105 // Purpose : Get selector
106 //=======================================================================
107 SVTK_Selector* SMESHGUI_Operation::selector() const
109 SVTK_ViewWindow* wnd = viewWindow();
110 return wnd ? wnd->GetSelector() : 0;
113 //=======================================================================
114 // name : startOperation
115 // Purpose : Start opeartion
116 //=======================================================================
117 void SMESHGUI_Operation::startOperation()
119 SalomeApp_Operation::startOperation();
122 //=======================================================================
123 // name : isReadyToStart
124 // Purpose : Verify whether operation is ready to start
125 //=======================================================================
126 bool SMESHGUI_Operation::isReadyToStart()
128 if ( !SalomeApp_Operation::isReadyToStart() )
131 if ( getSMESHGUI() == 0 )
133 SUIT_MessageBox::warn1( SMESHGUI::desktop(), tr( "SMESH_WRN_WARNING" ),
134 tr( "NO_MODULE" ), tr( "SMESH_BUT_OK" ) );
141 //=======================================================================
143 // Purpose : Find type by id
144 //=======================================================================
145 int SMESHGUI_Operation::typeById( const QString& str, const SelectedObjectType objtype ) const
147 SalomeApp_Study* _study = dynamic_cast<SalomeApp_Study*>( study() );
151 _PTR( Study ) st = _study->studyDS();
154 if( objtype == Object )
156 SalomeApp_Study* _study = dynamic_cast<SalomeApp_Study*>( study() );
159 int t = SMESHGUI_Selection::type( str, _study->studyDS() );
162 //try to get GEOM type
163 _PTR( SObject ) sobj = st->FindObjectID( str.latin1() );
166 GEOM::GEOM_Object_var obj = GEOM::GEOM_Object::_narrow( dynamic_cast<SALOMEDS_SObject*>( sobj.get() )->GetObject() );
167 if( !CORBA::is_nil( obj ) )
168 res = prefix( "GEOM" ) + obj->GetType();
172 res = prefix( "SMESH" ) + t;
177 int pos = str.find( idChar() );
178 QString entry = str.left( pos-1 ),
179 _id = str.mid( pos+1 );
181 int id = _id.toInt( &ok );
184 _PTR( SObject ) sobj = st->FindObjectID( entry.latin1() );
185 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( dynamic_cast<SALOMEDS_SObject*>( sobj.get() )->GetObject() );
186 SMESH::SMESH_subMesh_var submesh = SMESH::SMESH_subMesh::_narrow( dynamic_cast<SALOMEDS_SObject*>( sobj.get() )->GetObject() );
187 if( !CORBA::is_nil( mesh ) )
188 res = prefix( "SMESH element" ) + mesh->GetElementType( id, objtype==MeshElement );
190 else if( !CORBA::is_nil( submesh ) )
191 res = prefix( "SMESH element" ) + submesh->GetElementType( id, objtype==MeshElement );
198 //=======================================================================
200 // Purpose : Get prefix for module types
201 //=======================================================================
202 int SMESHGUI_Operation::prefix( const QString& name ) const
206 else if( name == "SMESH" )
208 else if( name == "SMESH element" )
214 //=======================================================================
216 // Purpose : Get names, types and ids of selected objects
217 //=======================================================================
218 void SMESHGUI_Operation::selected( QStringList& names, SalomeApp_Dialog::TypesList& types, QStringList& ids ) const
220 SUIT_DataOwnerPtrList list; selectionMgr()->selected( list );
221 SUIT_DataOwnerPtrList::const_iterator anIt = list.begin(),
223 for( ; anIt!=aLast; anIt++ )
225 SalomeApp_DataOwner* owner = dynamic_cast<SalomeApp_DataOwner*>( (*anIt).operator->() );
226 SalomeApp_SVTKDataOwner* vtkowner = dynamic_cast<SalomeApp_SVTKDataOwner*>( (*anIt).operator->() );
230 QString id_str = QString( "%1%2%3" ).arg( vtkowner->entry() ).arg( idChar() ), current_id_str;
231 Selection_Mode mode = vtkowner->GetMode();
232 SelectedObjectType objtype = mode == NodeSelection ? MeshNode : MeshElement;
233 const TColStd_IndexedMapOfInteger& ownerids = vtkowner->GetIds();
235 for( int i=1, n=ownerids.Extent(); i<=n; i++ )
237 int curid = ownerids( i );
238 current_id_str = id_str.arg( curid );
239 ids.append( current_id_str );
240 types.append( typeById( current_id_str, objtype ) );
241 names.append( QString( "%1" ).arg( curid ) );
247 QString id = owner->entry();
249 types.append( typeById( id, Object ) );
250 names.append( owner->IO()->getName() );
255 //=======================================================================
257 // Purpose : Char using to divide <entry> and <id> in string id representation. By default, '#'
258 //=======================================================================
259 QChar SMESHGUI_Operation::idChar() const