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() ) );
139 disconnect( dlg(), SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
141 if( dlg()->testButtonFlags( QtxDialog::OK ) )
142 connect( dlg(), SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
144 if( dlg()->testButtonFlags( QtxDialog::Apply ) )
145 connect( dlg(), SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
147 if( dlg()->testButtonFlags( QtxDialog::Cancel ) )
148 connect( dlg(), SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
150 if( dlg()->testButtonFlags( QtxDialog::Close ) )
151 connect( dlg(), SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
156 SalomeApp_Operation::startOperation();
159 //=======================================================================
160 // name : isReadyToStart
161 // Purpose : Verify whether operation is ready to start
162 //=======================================================================
163 bool SMESHGUI_Operation::isReadyToStart()
165 if ( !SalomeApp_Operation::isReadyToStart() )
168 if ( getSMESHGUI() == 0 )
170 SUIT_MessageBox::warn1( SMESHGUI::desktop(), tr( "SMESH_WRN_WARNING" ),
171 tr( "NO_MODULE" ), tr( "SMESH_BUT_OK" ) );
178 //=======================================================================
180 // Purpose : Find type by id
181 //=======================================================================
182 int SMESHGUI_Operation::typeById( const QString& str, const SelectedObjectType objtype ) const
184 SalomeApp_Study* _study = dynamic_cast<SalomeApp_Study*>( study() );
188 _PTR( Study ) st = _study->studyDS();
191 if( objtype == Object )
193 SalomeApp_Study* _study = dynamic_cast<SalomeApp_Study*>( study() );
196 int t = SMESHGUI_Selection::type( str, _study->studyDS() );
199 //try to get GEOM type
200 _PTR( SObject ) sobj = st->FindObjectID( str.latin1() );
203 GEOM::GEOM_Object_var obj = GEOM::GEOM_Object::_narrow( dynamic_cast<SALOMEDS_SObject*>( sobj.get() )->GetObject() );
204 if( !CORBA::is_nil( obj ) )
205 res = prefix( "GEOM" ) + obj->GetType();
209 res = prefix( "SMESH" ) + t;
214 int pos = str.find( idChar() );
215 QString entry = str.left( pos ),
216 _id = str.mid( pos+1 );
218 int id = _id.toInt( &ok );
221 _PTR( SObject ) sobj = st->FindObjectID( entry.latin1() );
222 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( dynamic_cast<SALOMEDS_SObject*>( sobj.get() )->GetObject() );
223 SMESH::SMESH_subMesh_var submesh = SMESH::SMESH_subMesh::_narrow( dynamic_cast<SALOMEDS_SObject*>( sobj.get() )->GetObject() );
224 if( !CORBA::is_nil( mesh ) )
225 res = prefix( "SMESH element" ) + mesh->GetElementType( id, objtype==MeshElement );
227 else if( !CORBA::is_nil( submesh ) )
228 res = prefix( "SMESH element" ) + submesh->GetElementType( id, objtype==MeshElement );
235 //=======================================================================
237 // Purpose : Get prefix for module types
238 //=======================================================================
239 int SMESHGUI_Operation::prefix( const QString& name )
243 else if( name == "SMESH" )
245 else if( name == "SMESH element" )
251 //=======================================================================
253 // Purpose : Get names, types and ids of selected objects
254 //=======================================================================
255 void SMESHGUI_Operation::selected( QStringList& names, SalomeApp_Dialog::TypesList& types, QStringList& ids ) const
257 SUIT_DataOwnerPtrList list; selectionMgr()->selected( list );
258 SUIT_DataOwnerPtrList::const_iterator anIt = list.begin(),
260 for( ; anIt!=aLast; anIt++ )
262 SalomeApp_DataOwner* owner = dynamic_cast<SalomeApp_DataOwner*>( (*anIt).operator->() );
263 SalomeApp_SVTKDataOwner* vtkowner = dynamic_cast<SalomeApp_SVTKDataOwner*>( (*anIt).operator->() );
267 QString id_str = QString( "%1%2%3" ).arg( vtkowner->entry() ).arg( idChar() ), current_id_str;
268 Selection_Mode mode = vtkowner->GetMode();
269 SelectedObjectType objtype = mode == NodeSelection ? MeshNode : MeshElement;
270 const TColStd_IndexedMapOfInteger& ownerids = vtkowner->GetIds();
272 for( int i=1, n=ownerids.Extent(); i<=n; i++ )
274 int curid = ownerids( i );
275 current_id_str = id_str.arg( curid );
276 ids.append( current_id_str );
277 types.append( typeById( current_id_str, objtype ) );
278 names.append( QString( "%1" ).arg( curid ) );
284 QString id = owner->entry();
286 types.append( typeById( id, Object ) );
287 names.append( owner->IO()->getName() );
292 //=======================================================================
294 // Purpose : Char using to divide <entry> and <id> in string id representation. By default, '#'
295 //=======================================================================
296 QChar SMESHGUI_Operation::idChar() const
301 //=======================================================================
302 // name : setDialogActive
304 //=======================================================================
305 void SMESHGUI_Operation::setDialogActive( const bool active )
307 SalomeApp_Operation::setDialogActive( active );
309 SMESHGUI_Dialog* d = dynamic_cast<SMESHGUI_Dialog*>( dlg() );
311 d->setContentActive( active );
315 //=======================================================================
318 //=======================================================================
319 _PTR(Study) SMESHGUI_Operation::studyDS() const
321 SalomeApp_Study* s = dynamic_cast<SalomeApp_Study*>( study() );
325 //=======================================================================
328 //=======================================================================
329 void SMESHGUI_Operation::onOk()
337 //=======================================================================
340 //=======================================================================
341 bool SMESHGUI_Operation::onApply()
346 //=======================================================================
349 //=======================================================================
350 void SMESHGUI_Operation::onCancel()
355 //=======================================================================
358 //=======================================================================
359 void SMESHGUI_Operation::initDialog()