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()
39 : SalomeApp_Operation()
43 SMESHGUI_Operation::~SMESHGUI_Operation()
48 //=======================================================================
49 // name : setSelectionMode
50 // Purpose : Set selection mode
51 //=======================================================================
52 void SMESHGUI_Operation::setSelectionMode( const Selection_Mode mode )
54 SVTK_ViewWindow* wnd = viewWindow();
56 wnd->SetSelectionMode( mode );
59 //=======================================================================
61 // Purpose : Highlight object in 3d viewer
62 //=======================================================================
63 void SMESHGUI_Operation::highlight( const Handle( SALOME_InteractiveObject )& obj,
64 const bool hilight, const bool immediately )
66 SVTK_ViewWindow* wnd = viewWindow();
68 wnd->highlight( obj, hilight, immediately );
71 //=======================================================================
72 // name : addOrRemoveIndex
73 // Purpose : Select/deselect cells of mesh
74 //=======================================================================
75 void SMESHGUI_Operation::addOrRemoveIndex( const Handle( SALOME_InteractiveObject )& obj,
76 const TColStd_MapOfInteger& indices,
77 const bool isModeShift )
79 SVTK_Selector* sel = selector();
81 sel->AddOrRemoveIndex( obj, indices, isModeShift );
84 //=======================================================================
86 // Purpose : Get SMESH module
87 //=======================================================================
88 SMESHGUI* SMESHGUI_Operation::getSMESHGUI() const
90 return dynamic_cast<SMESHGUI*>( module() );
93 //=======================================================================
95 // Purpose : Get active view window
96 //=======================================================================
97 SVTK_ViewWindow* SMESHGUI_Operation::viewWindow() const
99 return SMESH::GetViewWindow( getSMESHGUI() );
102 //=======================================================================
104 // Purpose : Get selector
105 //=======================================================================
106 SVTK_Selector* SMESHGUI_Operation::selector() const
108 SVTK_ViewWindow* wnd = viewWindow();
109 return wnd ? wnd->GetSelector() : 0;
112 //=======================================================================
113 // name : startOperation
114 // Purpose : Start opeartion
115 //=======================================================================
116 void SMESHGUI_Operation::startOperation()
120 disconnect( dlg(), SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
121 disconnect( dlg(), SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
122 disconnect( dlg(), SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
124 if( dlg()->testButtonFlags( QtxDialog::OK ) )
125 connect( dlg(), SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
127 if( dlg()->testButtonFlags( QtxDialog::Apply ) )
128 connect( dlg(), SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
130 if( dlg()->testButtonFlags( QtxDialog::Cancel ) )
131 connect( dlg(), SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
134 SalomeApp_Operation::startOperation();
137 //=======================================================================
138 // name : isReadyToStart
139 // Purpose : Verify whether operation is ready to start
140 //=======================================================================
141 bool SMESHGUI_Operation::isReadyToStart()
143 if ( !SalomeApp_Operation::isReadyToStart() )
146 if ( getSMESHGUI() == 0 )
148 SUIT_MessageBox::warn1( SMESHGUI::desktop(), tr( "SMESH_WRN_WARNING" ),
149 tr( "NO_MODULE" ), tr( "SMESH_BUT_OK" ) );
156 //=======================================================================
158 // Purpose : Find type by id
159 //=======================================================================
160 int SMESHGUI_Operation::typeById( const QString& str, const SelectedObjectType objtype ) const
162 SalomeApp_Study* _study = dynamic_cast<SalomeApp_Study*>( study() );
166 _PTR( Study ) st = _study->studyDS();
169 if( objtype == Object )
171 SalomeApp_Study* _study = dynamic_cast<SalomeApp_Study*>( study() );
174 int t = SMESHGUI_Selection::type( str, _study->studyDS() );
177 //try to get GEOM type
178 _PTR( SObject ) sobj = st->FindObjectID( str.latin1() );
181 GEOM::GEOM_Object_var obj = GEOM::GEOM_Object::_narrow( dynamic_cast<SALOMEDS_SObject*>( sobj.get() )->GetObject() );
182 if( !CORBA::is_nil( obj ) )
183 res = prefix( "GEOM" ) + obj->GetType();
187 res = prefix( "SMESH" ) + t;
192 int pos = str.find( idChar() );
193 QString entry = str.left( pos ),
194 _id = str.mid( pos+1 );
196 int id = _id.toInt( &ok );
199 _PTR( SObject ) sobj = st->FindObjectID( entry.latin1() );
200 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( dynamic_cast<SALOMEDS_SObject*>( sobj.get() )->GetObject() );
201 SMESH::SMESH_subMesh_var submesh = SMESH::SMESH_subMesh::_narrow( dynamic_cast<SALOMEDS_SObject*>( sobj.get() )->GetObject() );
202 if( !CORBA::is_nil( mesh ) )
203 res = prefix( "SMESH element" ) + mesh->GetElementType( id, objtype==MeshElement );
205 else if( !CORBA::is_nil( submesh ) )
206 res = prefix( "SMESH element" ) + submesh->GetElementType( id, objtype==MeshElement );
213 //=======================================================================
215 // Purpose : Get prefix for module types
216 //=======================================================================
217 int SMESHGUI_Operation::prefix( const QString& name )
221 else if( name == "SMESH" )
223 else if( name == "SMESH element" )
229 //=======================================================================
231 // Purpose : Get names, types and ids of selected objects
232 //=======================================================================
233 void SMESHGUI_Operation::selected( QStringList& names, SalomeApp_Dialog::TypesList& types, QStringList& ids ) const
235 SUIT_DataOwnerPtrList list; selectionMgr()->selected( list );
236 SUIT_DataOwnerPtrList::const_iterator anIt = list.begin(),
238 for( ; anIt!=aLast; anIt++ )
240 SalomeApp_DataOwner* owner = dynamic_cast<SalomeApp_DataOwner*>( (*anIt).operator->() );
241 SalomeApp_SVTKDataOwner* vtkowner = dynamic_cast<SalomeApp_SVTKDataOwner*>( (*anIt).operator->() );
245 QString id_str = QString( "%1%2%3" ).arg( vtkowner->entry() ).arg( idChar() ), current_id_str;
246 Selection_Mode mode = vtkowner->GetMode();
247 SelectedObjectType objtype = mode == NodeSelection ? MeshNode : MeshElement;
248 const TColStd_IndexedMapOfInteger& ownerids = vtkowner->GetIds();
250 for( int i=1, n=ownerids.Extent(); i<=n; i++ )
252 int curid = ownerids( i );
253 current_id_str = id_str.arg( curid );
254 ids.append( current_id_str );
255 types.append( typeById( current_id_str, objtype ) );
256 names.append( QString( "%1" ).arg( curid ) );
262 QString id = owner->entry();
264 types.append( typeById( id, Object ) );
265 names.append( owner->IO()->getName() );
270 //=======================================================================
272 // Purpose : Char using to divide <entry> and <id> in string id representation. By default, '#'
273 //=======================================================================
274 QChar SMESHGUI_Operation::idChar() const
279 //=======================================================================
280 // name : setDialogActive
282 //=======================================================================
283 void SMESHGUI_Operation::setDialogActive( const bool active )
285 SalomeApp_Operation::setDialogActive( active );
287 SMESHGUI_Dialog* d = dynamic_cast<SMESHGUI_Dialog*>( dlg() );
289 d->setContentActive( active );
293 //=======================================================================
296 //=======================================================================
297 _PTR(Study) SMESHGUI_Operation::studyDS() const
299 SalomeApp_Study* s = dynamic_cast<SalomeApp_Study*>( study() );
304 //=======================================================================
307 //=======================================================================
308 void SMESHGUI_Operation::onOk()
316 //=======================================================================
319 //=======================================================================
320 bool SMESHGUI_Operation::onApply()
325 //=======================================================================
328 //=======================================================================
329 void SMESHGUI_Operation::onCancel()
334 //=======================================================================
335 // name : commitOperation
337 //=======================================================================
338 void SMESHGUI_Operation::commitOperation()
340 selectionMgr()->clearFilters();
341 SalomeApp_Operation::commitOperation();
344 //=======================================================================
345 // name : abortOperation
347 //=======================================================================
348 void SMESHGUI_Operation::abortOperation()
350 selectionMgr()->clearFilters();
351 SalomeApp_Operation::abortOperation();