1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_ExtrusionOp.cxx
25 // Author : Alexander SOLOVYOV
29 #include "SMESHGUI_ExtrusionOp.h"
30 #include <SMESHGUI_ExtrusionDlg.h>
31 #include <SMESHGUI_VTKUtils.h>
33 #include <SMESH_TypeFilter.hxx>
34 #include <SMESH_LogicalFilter.hxx>
36 #include <SUIT_OverrideCursor.h>
38 #include <SALOMEDS_SObject.hxx>
40 #include CORBA_SERVER_HEADER(SMESH_Group)
42 //=================================================================================
43 // name : SMESHGUI_ExtrusionOp
44 // purpose : constructor
45 //=================================================================================
46 SMESHGUI_ExtrusionOp::SMESHGUI_ExtrusionOp()
47 : SMESHGUI_SelectionOp( EdgeSelection ),
52 //=================================================================================
53 // name : ~SMESHGUI_ExtrusionOp
54 // purpose : destructor
55 //=================================================================================
56 SMESHGUI_ExtrusionOp::~SMESHGUI_ExtrusionOp()
62 //=================================================================================
65 //=================================================================================
66 SalomeApp_Dialog* SMESHGUI_ExtrusionOp::dlg() const
71 //=================================================================================
74 //=================================================================================
75 void SMESHGUI_ExtrusionOp::initDialog()
84 //=================================================================================
85 // name : startOperation
87 //=================================================================================
88 void SMESHGUI_ExtrusionOp::startOperation()
92 myDlg = new SMESHGUI_ExtrusionDlg();
93 connect( myDlg, SIGNAL( constructorClicked( int ) ), this, SLOT( onChangeType( int ) ) );
94 connect( myDlg, SIGNAL( objectChanged( int, const QStringList& ) ),
95 this, SLOT( onTextChanged( int, const QStringList& ) ) );
98 SMESHGUI_SelectionOp::startOperation();
103 //=================================================================================
104 // name : onSelectionChanged
106 //=================================================================================
107 void SMESHGUI_ExtrusionOp::onSelectionChanged( int )
112 //=================================================================================
113 // name : createFilter
115 //=================================================================================
116 SUIT_SelectionFilter* SMESHGUI_ExtrusionOp::createFilter( const int id ) const
120 // Costruction of the logical filter for the elements: mesh/sub-mesh/group
121 SMESH_TypeFilter* aMeshOrSubMesh = new SMESH_TypeFilter (MESHorSUBMESH);
122 SMESH_TypeFilter* aGroup = new SMESH_TypeFilter (GROUP);
124 QPtrList<SUIT_SelectionFilter> list;
125 list.append( aMeshOrSubMesh );
126 list.append( aGroup );
128 return new SMESH_LogicalFilter( list, SMESH_LogicalFilter::LO_OR );
134 //=================================================================================
135 // name : updateDialog
137 //=================================================================================
138 void SMESHGUI_ExtrusionOp::updateDialog()
143 bool en = myDlg->hasSelection( myDlg->isSelectMesh() ? 1 : 0 );
144 myDlg->setButtonEnabled( en, QtxDialog::OK | QtxDialog::Apply );
147 //=================================================================================
150 //=================================================================================
151 bool SMESHGUI_ExtrusionOp::onApply()
153 if( isStudyLocked() )
157 SMESH::SMESH_Mesh_var m = extractIds( ids );
158 if( ids.count() && !m->_is_nil() )
160 SMESH::long_array_var anElementsId = new SMESH::long_array;
161 anElementsId->length( ids.count() );
163 for( int i=0, n=ids.count(); i<n; i++)
164 anElementsId[i] = ids[i];
166 SMESH::DirStruct aVector;
168 myDlg->coords( x, y, z );
172 long aNbSteps = (long)myDlg->nbStep();
176 SMESH::SMESH_MeshEditor_var aMeshEditor = m->GetMeshEditor();
177 SUIT_OverrideCursor c;
178 aMeshEditor->ExtrusionSweep( anElementsId.inout(), aVector, aNbSteps );
191 //=================================================================================
192 // name : onChangeType
194 //=================================================================================
195 void SMESHGUI_ExtrusionOp::onChangeType( int t )
197 if( !myDlg->isSelectMesh() )
198 setSelectionMode( t==0 ? EdgeSelection : FaceSelection );
201 //=================================================================================
202 // name : onActivateObject
204 //=================================================================================
205 void SMESHGUI_ExtrusionOp::onActivateObject( int id )
208 onChangeType( myDlg->constructorId() );
210 setSelectionMode( ActorSelection );
213 //=================================================================================
216 //=================================================================================
217 SMESH::SMESH_Mesh_var SMESHGUI_ExtrusionOp::extractIds( IdList& list ) const
219 if( selectionMode()==ActorSelection )
221 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
222 QStringList sel; myDlg->selectedObject( 1, sel );
226 _PTR( SObject ) SO = studyDS()->FindObjectID( sel.first() );
230 CORBA::Object* obj = _CAST(SObject, SO)->GetObject();
231 SMESH::SMESH_Mesh_var selMesh = SMESH::SMESH_Mesh::_narrow( obj );
232 SMESH::SMESH_subMesh_var selSubMesh = SMESH::SMESH_subMesh::_narrow( obj );
233 SMESH::SMESH_Group_var selGroup = SMESH::SMESH_Group::_narrow( obj );
235 SMESH::long_array_var anElementsIds = new SMESH::long_array;
236 if( !selMesh->_is_nil() )
241 // get IDs from submesh
242 anElementsIds = selMesh->GetElementsByType( myDlg->constructorId()==0 ? SMESH::EDGE : SMESH::FACE );
244 else if( !selSubMesh->_is_nil() )
247 aMesh = selSubMesh->GetFather();
249 // get IDs from submesh
250 anElementsIds = selSubMesh->GetElementsByType( myDlg->constructorId()==0 ? SMESH::EDGE : SMESH::FACE );
252 else if( !selGroup->_is_nil() )
255 aMesh = selGroup->GetMesh();
257 if( selGroup->GetType()==( myDlg->constructorId()==0 ? SMESH::EDGE : SMESH::FACE ) )
258 // get IDs from group
259 anElementsIds = selGroup->GetListOfID();
262 for (int i=0, n=anElementsIds->length(); i<n; i++)
263 list.append( anElementsIds[ i ] );
269 SMESHGUI_SelectionOp::selectedIds( 0, list );