]> SALOME platform Git repositories - modules/smesh.git/blob - src/SMESHGUI/SMESHGUI_ExtrusionOp.cxx
Salome HOME
Portation on new based dialog
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ExtrusionOp.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //
23 //
24 //  File   : SMESHGUI_ExtrusionOp.cxx
25 //  Author : Alexander SOLOVYOV
26 //  Module : SMESH
27 //  $Header:
28
29 #include "SMESHGUI_ExtrusionOp.h"
30 #include <SMESHGUI_ExtrusionDlg.h>
31 #include <SMESHGUI_VTKUtils.h>
32
33 #include <SMESH_TypeFilter.hxx>
34 #include <SMESH_LogicalFilter.hxx>
35
36 #include <SUIT_OverrideCursor.h>
37
38 #include <SALOMEDS_SObject.hxx>
39
40 #include CORBA_SERVER_HEADER(SMESH_Group)
41
42 //=================================================================================
43 // name     : SMESHGUI_ExtrusionOp
44 // purpose  : constructor
45 //=================================================================================
46 SMESHGUI_ExtrusionOp::SMESHGUI_ExtrusionOp()
47 : SMESHGUI_SelectionOp( EdgeSelection ),
48   myDlg( 0 )
49 {
50 }
51
52 //=================================================================================
53 // name     : ~SMESHGUI_ExtrusionOp
54 // purpose  : destructor
55 //=================================================================================
56 SMESHGUI_ExtrusionOp::~SMESHGUI_ExtrusionOp()
57 {
58   if( myDlg )
59     delete myDlg;
60 }
61
62 //=================================================================================
63 // name     : dlg
64 // purpose  : 
65 //=================================================================================
66 SalomeApp_Dialog* SMESHGUI_ExtrusionOp::dlg() const
67 {
68   return myDlg;
69 }
70
71 //=================================================================================
72 // name     : initDialog
73 // purpose  : 
74 //=================================================================================
75 void SMESHGUI_ExtrusionOp::initDialog()
76 {
77   if( myDlg )
78   {
79     myDlg->init();
80     updateDialog();
81   }
82 }
83
84 //=================================================================================
85 // name     : startOperation
86 // purpose  : 
87 //=================================================================================
88 void SMESHGUI_ExtrusionOp::startOperation()
89 {
90   if( !myDlg )
91   {
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& ) ) );
96   }
97
98   SMESHGUI_SelectionOp::startOperation();
99
100   myDlg->show();
101 }
102
103 //=================================================================================
104 // name     : onSelectionChanged
105 // purpose  :
106 //=================================================================================
107 void SMESHGUI_ExtrusionOp::onSelectionChanged( int )
108 {
109   updateDialog();
110 }
111
112 //=================================================================================
113 // name     : createFilter
114 // purpose  :
115 //=================================================================================
116 SUIT_SelectionFilter* SMESHGUI_ExtrusionOp::createFilter( const int id ) const
117 {
118   if( id==1 )
119   {
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);
123
124     QPtrList<SUIT_SelectionFilter> list;
125     list.append( aMeshOrSubMesh );
126     list.append( aGroup );
127
128     return new SMESH_LogicalFilter( list, SMESH_LogicalFilter::LO_OR );
129   }
130   else
131     return 0;
132 }
133
134 //=================================================================================
135 // name     : updateDialog
136 // purpose  :
137 //=================================================================================
138 void SMESHGUI_ExtrusionOp::updateDialog()
139 {
140   if( !myDlg )
141     return;
142
143   bool en = myDlg->hasSelection( myDlg->isSelectMesh() ? 1 : 0 );
144   myDlg->setButtonEnabled( en, QtxDialog::OK | QtxDialog::Apply );
145
146
147 //=================================================================================
148 // name     : onApply
149 // purpose  :
150 //=================================================================================
151 bool SMESHGUI_ExtrusionOp::onApply()
152 {
153   if( isStudyLocked() )
154     return false;
155
156   IdList ids;
157   SMESH::SMESH_Mesh_var m = extractIds( ids );
158   if( ids.count() && !m->_is_nil() )
159   {
160     SMESH::long_array_var anElementsId = new SMESH::long_array;
161     anElementsId->length( ids.count() );
162     
163     for( int i=0, n=ids.count(); i<n; i++)
164       anElementsId[i] = ids[i];
165
166     SMESH::DirStruct aVector;
167     double x, y, z;
168     myDlg->coords( x, y, z );
169     aVector.PS.x = x;
170     aVector.PS.y = y;
171     aVector.PS.z = z;
172     long aNbSteps = (long)myDlg->nbStep();
173
174     try
175     {
176       SMESH::SMESH_MeshEditor_var aMeshEditor = m->GetMeshEditor();
177       SUIT_OverrideCursor c;
178       aMeshEditor->ExtrusionSweep( anElementsId.inout(), aVector, aNbSteps );
179     }
180     catch (...)
181     {
182     }
183
184     initDialog();
185     SMESH::UpdateView();
186     return true;
187   }
188   return false;
189 }
190
191 //=================================================================================
192 // name     : onChangeType
193 // purpose  :
194 //=================================================================================
195 void SMESHGUI_ExtrusionOp::onChangeType( int t )
196 {
197   if( !myDlg->isSelectMesh() )
198     setSelectionMode( t==0 ? EdgeSelection : FaceSelection );
199 }
200
201 //=================================================================================
202 // name     : onActivateObject
203 // purpose  :
204 //=================================================================================
205 void SMESHGUI_ExtrusionOp::onActivateObject( int id )
206 {
207   if( id==0 && myDlg )
208     onChangeType( myDlg->constructorId() );
209   else if( id==1 )
210     setSelectionMode( ActorSelection );
211 }
212
213 //=================================================================================
214 // name     : extractIds
215 // purpose  :
216 //=================================================================================
217 SMESH::SMESH_Mesh_var SMESHGUI_ExtrusionOp::extractIds( IdList& list ) const
218 {
219   if( selectionMode()==ActorSelection )
220   {
221     SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
222     QStringList sel; myDlg->selectedObject( 1, sel );
223     if( sel.isEmpty() )
224       return aMesh;
225       
226     _PTR( SObject ) SO = studyDS()->FindObjectID( sel.first() );
227     if( !SO )
228       return aMesh;
229
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 );
234
235     SMESH::long_array_var anElementsIds = new SMESH::long_array;    
236     if( !selMesh->_is_nil() )
237     {
238       //MESH
239       aMesh = selMesh;
240
241       // get IDs from submesh
242       anElementsIds = selMesh->GetElementsByType( myDlg->constructorId()==0 ? SMESH::EDGE : SMESH::FACE );    
243     }
244     else if( !selSubMesh->_is_nil() )
245     {
246       //SUBMESH
247       aMesh = selSubMesh->GetFather();
248
249       // get IDs from submesh
250       anElementsIds = selSubMesh->GetElementsByType( myDlg->constructorId()==0 ? SMESH::EDGE : SMESH::FACE );
251     }
252     else if( !selGroup->_is_nil() )
253     {
254       //GROUP
255       aMesh = selGroup->GetMesh();
256
257       if( selGroup->GetType()==( myDlg->constructorId()==0 ? SMESH::EDGE : SMESH::FACE ) )
258         // get IDs from group
259         anElementsIds = selGroup->GetListOfID();
260     }
261
262     for (int i=0, n=anElementsIds->length(); i<n; i++)
263       list.append( anElementsIds[ i ] );
264    
265     return aMesh;
266   }
267   else
268   {
269     SMESHGUI_SelectionOp::selectedIds( 0, list );
270     return mesh();
271   }
272 }