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 //=======================================================================
44 // name : ~SMESHGUI_Operation
45 // Purpose : Destructor
46 //=======================================================================
47 SMESHGUI_Operation::~SMESHGUI_Operation()
51 //=======================================================================
52 // name : selectionMode
53 // Purpose : Returns selection mode
54 //=======================================================================
55 Selection_Mode SMESHGUI_Operation::selectionMode() const
57 SVTK_ViewWindow* wnd = viewWindow();
59 return wnd->SelectionMode();
61 return ActorSelection;
64 //=======================================================================
65 // name : setSelectionMode
66 // Purpose : Set selection mode
67 //=======================================================================
68 void SMESHGUI_Operation::setSelectionMode( const Selection_Mode mode )
70 SVTK_ViewWindow* wnd = viewWindow();
72 wnd->SetSelectionMode( mode );
75 //=======================================================================
77 // Purpose : Highlight object in 3d viewer
78 //=======================================================================
79 void SMESHGUI_Operation::highlight( const Handle( SALOME_InteractiveObject )& obj,
80 const bool hilight, const bool immediately )
82 SVTK_ViewWindow* wnd = viewWindow();
84 wnd->highlight( obj, hilight, immediately );
87 //=======================================================================
88 // name : addOrRemoveIndex
89 // Purpose : Select/deselect cells of mesh
90 //=======================================================================
91 void SMESHGUI_Operation::addOrRemoveIndex( const Handle( SALOME_InteractiveObject )& obj,
92 const TColStd_MapOfInteger& indices,
93 const bool isModeShift )
95 SVTK_Selector* sel = selector();
97 sel->AddOrRemoveIndex( obj, indices, isModeShift );
100 //=======================================================================
101 // name : getSMESHGUI
102 // Purpose : Get SMESH module
103 //=======================================================================
104 SMESHGUI* SMESHGUI_Operation::getSMESHGUI() const
106 return dynamic_cast<SMESHGUI*>( module() );
109 //=======================================================================
111 // Purpose : Get active view window
112 //=======================================================================
113 SVTK_ViewWindow* SMESHGUI_Operation::viewWindow() const
115 return SMESH::GetViewWindow( getSMESHGUI() );
118 //=======================================================================
120 // Purpose : Get selector
121 //=======================================================================
122 SVTK_Selector* SMESHGUI_Operation::selector() const
124 SVTK_ViewWindow* wnd = viewWindow();
125 return wnd ? wnd->GetSelector() : 0;
128 //=======================================================================
129 // name : startOperation
130 // Purpose : Start opeartion
131 //=======================================================================
132 void SMESHGUI_Operation::startOperation()
136 disconnect( dlg(), SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
137 disconnect( dlg(), SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
138 disconnect( dlg(), SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
140 if( dlg()->testButtonFlags( QtxDialog::OK ) )
141 connect( dlg(), SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
143 if( dlg()->testButtonFlags( QtxDialog::Apply ) )
144 connect( dlg(), SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
146 if( dlg()->testButtonFlags( QtxDialog::Cancel ) )
147 connect( dlg(), SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
152 SalomeApp_Operation::startOperation();
155 //=======================================================================
156 // name : isReadyToStart
157 // Purpose : Verify whether operation is ready to start
158 //=======================================================================
159 bool SMESHGUI_Operation::isReadyToStart()
161 if ( !SalomeApp_Operation::isReadyToStart() )
164 if ( getSMESHGUI() == 0 )
166 SUIT_MessageBox::warn1( SMESHGUI::desktop(), tr( "SMESH_WRN_WARNING" ),
167 tr( "NO_MODULE" ), tr( "SMESH_BUT_OK" ) );
174 //=======================================================================
176 // Purpose : Find type by id
177 //=======================================================================
178 int SMESHGUI_Operation::typeById( const QString& str, const SelectedObjectType objtype ) const
180 SalomeApp_Study* _study = dynamic_cast<SalomeApp_Study*>( study() );
184 _PTR( Study ) st = _study->studyDS();
187 if( objtype == Object )
189 SalomeApp_Study* _study = dynamic_cast<SalomeApp_Study*>( study() );
192 int t = SMESHGUI_Selection::type( str, _study->studyDS() );
195 //try to get GEOM type
196 _PTR( SObject ) sobj = st->FindObjectID( str.latin1() );
199 GEOM::GEOM_Object_var obj = GEOM::GEOM_Object::_narrow( dynamic_cast<SALOMEDS_SObject*>( sobj.get() )->GetObject() );
200 if( !CORBA::is_nil( obj ) )
201 res = prefix( "GEOM" ) + obj->GetType();
205 res = prefix( "SMESH" ) + t;
210 int pos = str.find( idChar() );
211 QString entry = str.left( pos ),
212 _id = str.mid( pos+1 );
214 int id = _id.toInt( &ok );
217 _PTR( SObject ) sobj = st->FindObjectID( entry.latin1() );
218 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( dynamic_cast<SALOMEDS_SObject*>( sobj.get() )->GetObject() );
219 SMESH::SMESH_subMesh_var submesh = SMESH::SMESH_subMesh::_narrow( dynamic_cast<SALOMEDS_SObject*>( sobj.get() )->GetObject() );
220 if( !CORBA::is_nil( mesh ) )
221 res = prefix( "SMESH element" ) + mesh->GetElementType( id, objtype==MeshElement );
223 else if( !CORBA::is_nil( submesh ) )
224 res = prefix( "SMESH element" ) + submesh->GetElementType( id, objtype==MeshElement );
231 //=======================================================================
233 // Purpose : Get prefix for module types
234 //=======================================================================
235 int SMESHGUI_Operation::prefix( const QString& name )
239 else if( name == "SMESH" )
241 else if( name == "SMESH element" )
247 //=======================================================================
249 // Purpose : Get names, types and ids of selected objects
250 //=======================================================================
251 void SMESHGUI_Operation::selected( QStringList& names, SalomeApp_Dialog::TypesList& types, QStringList& ids ) const
253 SUIT_DataOwnerPtrList list; selectionMgr()->selected( list );
254 SUIT_DataOwnerPtrList::const_iterator anIt = list.begin(),
256 for( ; anIt!=aLast; anIt++ )
258 SalomeApp_DataOwner* owner = dynamic_cast<SalomeApp_DataOwner*>( (*anIt).operator->() );
259 SalomeApp_SVTKDataOwner* vtkowner = dynamic_cast<SalomeApp_SVTKDataOwner*>( (*anIt).operator->() );
263 QString id_str = QString( "%1%2%3" ).arg( vtkowner->entry() ).arg( idChar() ), current_id_str;
264 Selection_Mode mode = vtkowner->GetMode();
265 SelectedObjectType objtype = mode == NodeSelection ? MeshNode : MeshElement;
266 const TColStd_IndexedMapOfInteger& ownerids = vtkowner->GetIds();
268 for( int i=1, n=ownerids.Extent(); i<=n; i++ )
270 int curid = ownerids( i );
271 current_id_str = id_str.arg( curid );
272 ids.append( current_id_str );
273 types.append( typeById( current_id_str, objtype ) );
274 names.append( QString( "%1" ).arg( curid ) );
280 QString id = owner->entry();
282 types.append( typeById( id, Object ) );
283 names.append( owner->IO()->getName() );
288 //=======================================================================
290 // Purpose : Char using to divide <entry> and <id> in string id representation. By default, '#'
291 //=======================================================================
292 QChar SMESHGUI_Operation::idChar() const
297 //=======================================================================
298 // name : setDialogActive
300 //=======================================================================
301 void SMESHGUI_Operation::setDialogActive( const bool active )
303 SalomeApp_Operation::setDialogActive( active );
305 SMESHGUI_Dialog* d = dynamic_cast<SMESHGUI_Dialog*>( dlg() );
307 d->setContentActive( active );
311 //=======================================================================
314 //=======================================================================
315 _PTR(Study) SMESHGUI_Operation::studyDS() const
317 SalomeApp_Study* s = dynamic_cast<SalomeApp_Study*>( study() );
322 //=======================================================================
325 //=======================================================================
326 void SMESHGUI_Operation::onOk()
334 //=======================================================================
337 //=======================================================================
338 bool SMESHGUI_Operation::onApply()
343 //=======================================================================
346 //=======================================================================
347 void SMESHGUI_Operation::onCancel()
352 //=======================================================================
355 //=======================================================================
356 void SMESHGUI_Operation::initDialog()