Salome HOME
2fe9e92bcc5b7ec3b7e9138c963bf8cf47dcae42
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ExtrusionDlg.cxx
1 // Copyright (C) 2007-2019  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File   : SMESHGUI_ExtrusionDlg.cxx
25 // Author : Michael ZORIN, Open CASCADE S.A.S.
26 // SMESH includes
27 //
28 #include "SMESHGUI_ExtrusionDlg.h"
29
30 #include "SMESHGUI.h"
31 #include "SMESHGUI_FilterDlg.h"
32 #include "SMESHGUI_IdValidator.h"
33 #include "SMESHGUI_MeshEditPreview.h"
34 #include "SMESHGUI_MeshUtils.h"
35 #include "SMESHGUI_SpinBox.h"
36 #include "SMESHGUI_Utils.h"
37 #include "SMESHGUI_VTKUtils.h"
38 #include <GEOMBase.h>
39 #include <SMDS_Mesh.hxx>
40 #include <SMESH_Actor.h>
41 #include <SMESH_LogicalFilter.hxx>
42 #include <SMESH_TypeFilter.hxx>
43
44 // SALOME GUI includes
45 #include <LightApp_Application.h>
46 #include <LightApp_SelectionMgr.h>
47 #include <SUIT_Desktop.h>
48 #include <SUIT_MessageBox.h>
49 #include <SUIT_OverrideCursor.h>
50 #include <SUIT_ResourceMgr.h>
51 #include <SUIT_Session.h>
52 #include <SVTK_ViewModel.h>
53 #include <SVTK_ViewWindow.h>
54 #include <SalomeApp_IntSpinBox.h>
55
56 // OCCT includes
57 #include <BRep_Tool.hxx>
58 #include <TColStd_IndexedMapOfInteger.hxx>
59 #include <TColStd_MapOfInteger.hxx>
60 #include <TopoDS_Vertex.hxx>
61 #include <gp_XYZ.hxx>
62
63 // Qt includes
64 #include <QApplication>
65 #include <QButtonGroup>
66 #include <QCheckBox>
67 #include <QGridLayout>
68 #include <QGroupBox>
69 #include <QHBoxLayout>
70 #include <QKeyEvent>
71 #include <QLabel>
72 #include <QLineEdit>
73 #include <QListWidget>
74 #include <QPushButton>
75 #include <QRadioButton>
76 #include <QToolButton>
77 #include <QVBoxLayout>
78
79 // IDL includes
80 #include <SALOMEconfig.h>
81 #include CORBA_SERVER_HEADER(SMESH_Group)
82 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
83 #include <SMESH_NumberFilter.hxx>
84
85 #define SPACING 6
86 #define MARGIN  11
87
88 namespace
89 {
90   const char* getLabelText( int typeIndex, bool objSelection )
91   {
92     const char* typeLbl[3] = { "SMESH_ID_NODES", "SMESH_ID_EDGES", "SMESH_ID_FACES" };
93     const char* obj = "SMESH_OBJECTS";
94     return objSelection ? obj : typeLbl[ typeIndex ];
95   }
96 }
97
98 //================================================================================
99 /*!
100  * \brief Constructor
101  */
102 //================================================================================
103
104 SMESHGUI_3TypesSelector::SMESHGUI_3TypesSelector( QWidget * parent ):
105   QWidget( parent )
106 {
107   SMESHGUI*  gui = SMESHGUI::GetSMESHGUI();
108   mySelectionMgr = SMESH::GetSelectionMgr( gui );
109   mySelector     = SMESH::GetViewWindow( gui )->GetSelector();
110   myFilterDlg    = 0;
111   myIdValidator  = new SMESHGUI_IdValidator(this);
112
113   QPixmap image( SMESH::GetResourceMgr( gui )->loadPixmap("SMESH", tr("ICON_SELECT")));
114
115   mySelectBtnGrp = new QButtonGroup( this );
116   mySelectBtnGrp->setExclusive( true );
117
118   QVBoxLayout* mainLayout = new QVBoxLayout( this );
119   mainLayout->setSpacing( SPACING );
120   mainLayout->setMargin( 0 );
121
122   const char* groupLbl[3] = { "SMESH_NODES", "SMESH_EDGES", "SMESH_FACES" };
123
124   for ( int i = 0; i < 3; ++i )
125   {
126     myGroups[i] = new QGroupBox( tr( groupLbl[i] ), this );
127     mainLayout->addWidget( myGroups[i] );
128     QGridLayout* layout = new QGridLayout( myGroups[i] );
129     layout->setSpacing( SPACING );
130     layout->setMargin( MARGIN );
131
132     QPushButton* selBtn = new QPushButton( myGroups[i] );
133     selBtn->setIcon( image );
134     selBtn->setCheckable( true );
135     mySelectBtnGrp->addButton( selBtn, i );
136     myLabel    [i] = new QLabel( myGroups[i] );
137     myLineEdit [i] = new QLineEdit( myGroups[i] );
138     myMeshChk  [i] = new QCheckBox( tr("SMESH_SELECT_WHOLE_MESH"), myGroups[i] );
139     myFilterBtn[i] = new QPushButton( tr( "SMESH_BUT_FILTER" ), myGroups[i] );
140
141     myLineEdit[i]->setMaxLength(-1);
142     myLabel   [i]->setText( tr( getLabelText( i, true )));
143
144     layout->addWidget(myLabel    [i], 0, 0);
145     layout->addWidget(selBtn,         0, 1);
146     layout->addWidget(myLineEdit [i], 0, 2, 1, 2);
147     layout->addWidget(myFilterBtn[i], 0, 4);
148     layout->addWidget(myMeshChk  [i], 1, 0, 1, 5);
149     layout->setColumnStretch( 2, 10 );
150
151     connect( myMeshChk  [i], SIGNAL(toggled(bool)),               SLOT(onSelectMesh(bool)));
152     connect( myFilterBtn[i], SIGNAL(clicked()),                   SLOT(setFilters()));
153     connect( myLineEdit [i], SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
154     myIDSource[i] = new SMESH::ListOfIDSources;
155   }
156   connect( mySelectBtnGrp, SIGNAL(buttonClicked (int)),           SLOT(onSelectType(int)));
157   connect(mySelectionMgr, SIGNAL( currentSelectionChanged()),     SLOT(selectionIntoArgument()));
158
159   // Costruction of the logical filter for the elements: mesh/sub-mesh/group
160   QList<SUIT_SelectionFilter*> aListOfFilters;
161   aListOfFilters.append(new SMESH_TypeFilter (SMESH::MESH));
162   aListOfFilters.append(new SMESH_TypeFilter (SMESH::SUBMESH_VERTEX));
163   aListOfFilters.append(new SMESH_TypeFilter (SMESH::GROUP_NODE));
164   myFilter[0] = 
165     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR, /*takeOwnership=*/true);
166   aListOfFilters.append(0);
167   aListOfFilters[0] = new SMESH_TypeFilter (SMESH::MESH);
168   aListOfFilters[1] = new SMESH_TypeFilter (SMESH::SUBMESH_EDGE);
169   aListOfFilters[2] = new SMESH_TypeFilter (SMESH::GROUP_EDGE);
170   aListOfFilters[3] = new SMESH_TypeFilter (SMESH::IDSOURCE_EDGE); // for sub-mesh on group of EDGEs
171   myFilter[1] = 
172     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR, /*takeOwnership=*/true);
173   aListOfFilters[0] = new SMESH_TypeFilter (SMESH::MESH);
174   aListOfFilters[1] = new SMESH_TypeFilter (SMESH::SUBMESH_FACE);
175   aListOfFilters[2] = new SMESH_TypeFilter (SMESH::GROUP_FACE);
176   aListOfFilters[3] = new SMESH_TypeFilter (SMESH::IDSOURCE_FACE); // for sub-mesh on group of FACEs
177   myFilter[2] = 
178     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR, /*takeOwnership=*/true);
179
180   myBusy = false;
181
182   myMeshChk[0]->setChecked( true );
183   myMeshChk[1]->setChecked( true );
184   myMeshChk[2]->setChecked( true );
185   mySelectBtnGrp->button(0)->click();
186 }
187
188 //================================================================================
189 /*!
190  * \brief Destructor
191  */
192 //================================================================================
193
194 SMESHGUI_3TypesSelector::~SMESHGUI_3TypesSelector()
195 {
196   myIDSource[0].out();
197   myIDSource[1].out();
198   myIDSource[2].out();
199
200   delete myFilter[0];
201   delete myFilter[1];
202   delete myFilter[2];
203
204   if ( myFilterDlg )
205   {
206     myFilterDlg->setParent( 0 );
207     delete myFilterDlg;
208     myFilterDlg = 0;
209   }
210   disconnect(mySelectionMgr, 0, this, 0);
211 }
212
213 //================================================================================
214 /*!
215  * \brief Slot called when selection changes
216  */
217 //================================================================================
218
219 void SMESHGUI_3TypesSelector::selectionIntoArgument()
220 {
221   if (myBusy) return;
222
223   // return if dialog box is inactive
224   if ( !isEnabled() )
225     return;
226
227   // get a current element type
228   int iType = mySelectBtnGrp->checkedId();
229   if ( iType < 0 || iType > 2 )
230     return;
231
232   QString aString = "";
233   int nbObjects = 0;
234
235   // clear
236   myBusy = true;
237   myLineEdit[ iType ]->setText(aString);
238   myIDSource[ iType ]->length (nbObjects);
239   myBusy = false;
240   if ( !myGroups[ iType ]->isEnabled() )
241     return;
242
243   SMESH::SetPointRepresentation(false);
244
245   SALOME_ListIO selected;
246   mySelectionMgr->selectedObjects( selected );
247
248   if ( myMeshChk[ iType ]->isChecked() ) // objects selection
249     myIDSource[ iType ]->length( selected.Extent() ); // reserve
250   myIDSource[ iType ]->length(0);
251
252   SALOME_ListIteratorOfListIO It( selected );
253   for ( ; It.More(); It.Next() )
254   {
255     Handle(SALOME_InteractiveObject) IO = It.Value();
256
257     // get selected mesh
258     SMESH::SMESH_Mesh_var mesh = SMESH::GetMeshByIO(IO);
259     if ( mesh->_is_nil() )
260       continue;
261     if ( !myMesh->_is_nil() &&
262          IsAnythingSelected() &&
263          myMesh->GetId() != mesh->GetId() )
264       continue; // other mesh
265     myMesh  = mesh;
266     myIO    = IO;
267     myActor = SMESH::FindActorByEntry( IO->getEntry() );
268
269     if ( myMeshChk[ iType ]->isChecked() ) // objects selection
270     {
271       SMESH::SMESH_IDSource_var idSrc = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
272       if ( idSrc->_is_nil() )
273         continue;
274       mesh = SMESH::SMESH_Mesh::_narrow( idSrc );
275       if ( !mesh->_is_nil() ) // if a mesh is selected, stop iteration
276       {
277         nbObjects = 1;
278         myIDSource[ iType ]->length( nbObjects );
279         myIDSource[ iType ][ 0 ] = idSrc;
280         aString = IO->getName();
281         break;
282       }
283       else // several groups can be selected
284       {
285         myIDSource[ iType ]->length( nbObjects + 1 );
286         myIDSource[ iType ][ nbObjects++ ] = idSrc;
287         aString += " " + QString( IO->getName() ) + " ";
288       }
289     }
290     else // get indices of selected elements
291     {
292       TColStd_IndexedMapOfInteger aMapIndex;
293       mySelector->GetIndex(IO,aMapIndex);
294       int nbElements = aMapIndex.Extent();
295       if ( nbElements > 0 )
296       {
297         SMESH::long_array_var ids = new SMESH::long_array;
298         ids->length( nbElements );
299         for ( int i = 0; i < nbElements; ++i )
300           aString += QString(" %1").arg( ids[ i ] = aMapIndex( i+1 ));
301         addTmpIdSource( ids, iType, nbObjects++ );
302       }
303       break;
304     }
305   }
306
307   myIDSource[ iType ]->length( nbObjects );
308
309   myBusy = true;
310   myLineEdit[ iType ]->setText(aString);
311   myBusy = false;
312
313   emit selectionChanged();
314 }
315
316 //================================================================================
317 /*!
318  * \brief Slot called when text changes in myLineEdit
319  */
320 //================================================================================
321
322 void SMESHGUI_3TypesSelector::onTextChange( const QString& theNewText )
323 {
324   // return if busy
325   if (myBusy) return;
326
327   // get a current element type
328   int iType = 0;
329   QLineEdit* le = (QLineEdit*) sender();
330   for ( ; iType < 3; ++iType )
331     if ( myLineEdit[ iType ] == le )
332       break;
333   if ( iType < 0 || iType > 2 )
334     return;
335   if ( !myGroups[ iType ]->isEnabled() )
336     return;
337
338   myBusy = true;
339
340   // highlight entered elements/nodes
341
342   myIDSource[ iType ]->length( 0 );
343
344   if ( !myMesh->_is_nil() )
345   {
346     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
347     if ( aListId.count() > 0 )
348     {
349       SMDS_Mesh* aMesh = myActor ? myActor->GetObject()->GetMesh() : 0;
350
351       SMESH::ElementType SMESHType = SMESH::ElementType ( iType+1 );
352       SMDSAbs_ElementType SMDSType = SMDSAbs_ElementType( iType+1 );
353       const bool isNode = ( SMDSType == SMDSAbs_Node );
354
355       SMESH::long_array_var ids = new SMESH::long_array;
356       ids->length( aListId.count() );
357       TColStd_MapOfInteger newIndices;
358       for (int i = 0; i < aListId.count(); i++) {
359         int id = aListId[ i ].toInt();
360         bool validId = false;
361         if ( id > 0 ) {
362           if ( aMesh ) {
363             const SMDS_MeshElement * e;
364             if ( isNode ) e = aMesh->FindNode( id );
365             else          e = aMesh->FindElement( id );
366             validId = ( e && e->GetType() == SMDSType );
367           } else {
368             validId = ( myMesh->GetElementType( id, !isNode ) == SMESHType );
369           }
370         }
371         if ( validId && newIndices.Add( id ))
372           ids[ newIndices.Extent()-1 ] = id;
373       }
374       if ( !newIndices.IsEmpty() ) {
375         ids->length( newIndices.Extent() );
376         addTmpIdSource( ids, iType, 0 );
377       }
378       mySelector->AddOrRemoveIndex(myIO, newIndices, false);
379       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView() )
380         aViewWindow->highlight( myIO, true, true );
381     }
382   }
383
384   emit selectionChanged();
385
386   myBusy = false;
387 }
388
389 //================================================================================
390 /*!
391  * \brief Creates from ids and stores a temporary IDSource
392  */
393 //================================================================================
394
395 void SMESHGUI_3TypesSelector::addTmpIdSource( SMESH::long_array_var& ids, int iType, int index )
396 {
397   SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
398   SMESH::SMESH_IDSource_var idSrc =
399     aMeshEditor->MakeIDSource( ids, SMESH::ElementType( iType+1 ));
400
401   if ( (int) myIDSource[ iType ]->length() <= index )
402     myIDSource[ iType ]->length( index + 1 );
403   myIDSource[ iType ][ index ] = idSrc;
404
405   myTmpIDSourceList.push_back( idSrc );
406 }
407
408 //================================================================================
409 /*!
410  * \brief Slot called when myMeshChk is checked
411  */
412 //================================================================================
413
414 void SMESHGUI_3TypesSelector::onSelectMesh( bool on )
415 {
416   QCheckBox* send = (QCheckBox*)sender();
417   for ( int iType = 0; iType < 3; ++iType )
418     if ( send == myMeshChk[ iType ])
419     {
420       myLabel[ iType ]->setText( tr( getLabelText( iType, on )));
421       myFilterBtn[ iType ]->setEnabled( !on );
422       myIDSource [ iType ]->length(0);
423       myBusy = true; 
424       myLineEdit [ iType ]->setText("");
425       myBusy = false; 
426       myLineEdit [ iType ]->setReadOnly( on );
427       myLineEdit [ iType ]->setValidator( on ? 0 : myIdValidator );
428       mySelectBtnGrp->button(iType)->click();
429       break;
430     }
431     else
432     {
433       
434     }
435 }
436
437 //================================================================================
438 /*!
439  * \brief Slot called when a selection button is clicked
440  */
441 //================================================================================
442
443 void SMESHGUI_3TypesSelector::onSelectType(int iType)
444 {
445   if ( iType < 0 || iType > 2 )
446     return;
447
448   myIDSource[ iType ]->length(0);
449   myLineEdit[ iType ]->setText("");
450
451   disconnect(mySelectionMgr, 0, this, 0);
452   mySelectionMgr->clearFilters();
453
454   SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
455   if ( myMeshChk[ iType ]->isChecked() )
456   {
457     if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
458     mySelectionMgr->installFilter( myFilter[ iType ]);
459   }
460   else if ( aViewWindow )
461   {
462     switch ( iType+1 ) {
463     case SMESH::NODE: aViewWindow->SetSelectionMode(NodeSelection); break;
464     case SMESH::EDGE: aViewWindow->SetSelectionMode(EdgeSelection); break;
465     case SMESH::FACE: aViewWindow->SetSelectionMode(FaceSelection); break;
466     }
467   }
468
469   myLineEdit[ iType ]->setFocus();
470
471   connect(mySelectionMgr, SIGNAL( currentSelectionChanged()), SLOT( selectionIntoArgument()));
472   selectionIntoArgument();
473 }
474
475 //================================================================================
476 /*!
477  * \brief Slot called when "Set filter" is clicked
478  */
479 //================================================================================
480
481 void SMESHGUI_3TypesSelector::setFilters()
482 {
483   if ( myMesh->_is_nil() ) {
484     SUIT_MessageBox::critical(this,
485                               tr("SMESH_ERROR"),
486                               tr("NO_MESH_SELECTED"));
487     return;
488   }
489   if ( !myFilterDlg )
490   {
491     QList<int> types;
492     types.append( SMESH::NODE );
493     types.append( SMESH::EDGE );
494     types.append( SMESH::FACE );
495     myFilterDlg = new SMESHGUI_FilterDlg( SMESHGUI::GetSMESHGUI(), types );
496   }
497
498   QPushButton* send = (QPushButton*)sender();
499   for ( int iType = 0; iType < 3; ++iType )
500     if ( send == myFilterBtn[ iType ])
501     {
502       mySelectBtnGrp->button(iType)->click();
503
504       myFilterDlg->Init( SMESH::ElementType( iType+1 ) );
505       myFilterDlg->SetSelection();
506       myFilterDlg->SetMesh( myMesh );
507       myFilterDlg->SetSourceWg( myLineEdit[ iType ]);
508       myFilterDlg->show();
509       break;
510     }
511 }
512
513 //================================================================================
514 /*!
515  * \brief Clear selection
516  */
517 //================================================================================
518
519 void SMESHGUI_3TypesSelector::Clear()
520 {
521   myBusy = true;
522   for ( int iType = 0; iType < 3; ++iType )
523   {
524     myIDSource[ iType ]->length(0);
525     myLineEdit[ iType ]->setText("");
526   }
527   myBusy = false;
528   selectionIntoArgument();
529 }
530
531 //================================================================================
532 /*!
533  * \brief Enable/disable controls of a type
534  */
535 //================================================================================
536
537 void SMESHGUI_3TypesSelector::SetEnabled( bool enable, SMESH::ElementType type )
538 {
539   myBusy = true; 
540   for ( int iType = 0; iType < 3; ++iType )
541     if ( iType+1 == type || type == SMESH::ALL )
542     {
543       myGroups[ iType ]->setEnabled( enable );
544       if ( !enable ) {
545         myIDSource[ iType ]->length(0);
546         myLineEdit[ iType ]->setText("");
547       }
548     }
549   myBusy = false;
550   selectionIntoArgument();
551 }
552
553 //================================================================================
554 /*!
555  * \brief Checks if anything is selected
556  */
557 //================================================================================
558
559 bool SMESHGUI_3TypesSelector::IsAnythingSelected( SMESH::ElementType type )
560 {
561   int nbSel = 0;
562
563   for ( int iType = 0; iType < 3; ++iType )
564     if ( iType+1 == type || type == SMESH::ALL )
565       nbSel += myIDSource[ iType ]->length();
566
567   return nbSel;
568 }
569
570 //================================================================================
571 /*!
572  * \brief Returns selected elements and most complex type of selected elements
573  */
574 //================================================================================
575
576 SMESH::ElementType SMESHGUI_3TypesSelector::GetSelected( SMESH::ListOfIDSources & nodes,
577                                                          SMESH::ListOfIDSources & edges,
578                                                          SMESH::ListOfIDSources & faces )
579 {
580   nodes = myIDSource[0];
581   edges = myIDSource[1];
582   faces = myIDSource[2];
583
584   if ( myIDSource[2]->length() > 0 ) return SMESH::FACE;
585   if ( myIDSource[1]->length() > 0 ) return SMESH::EDGE;
586   if ( myIDSource[0]->length() > 0 ) return SMESH::NODE;
587   return SMESH::ALL;
588 }
589
590 //=================================================================================
591 // function : SMESHGUI_ExtrusionDlg()
592 // purpose  : constructor
593 //=================================================================================
594
595 SMESHGUI_ExtrusionDlg::SMESHGUI_ExtrusionDlg (SMESHGUI* theModule)
596   : SMESHGUI_PreviewDlg( theModule ),
597     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
598 {
599   SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
600   QPixmap selectImage ( mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
601   QPixmap addImage    ( mgr->loadPixmap("SMESH", tr("ICON_APPEND")));
602   QPixmap removeImage ( mgr->loadPixmap("SMESH", tr("ICON_REMOVE")));
603
604   setModal( false );
605   setAttribute( Qt::WA_DeleteOnClose, true );
606   setWindowTitle(tr("EXTRUSION_ALONG_LINE"));
607   setSizeGripEnabled(true);
608
609   QVBoxLayout* SMESHGUI_ExtrusionDlgLayout = new QVBoxLayout(this);
610   SMESHGUI_ExtrusionDlgLayout->setSpacing(SPACING);
611   SMESHGUI_ExtrusionDlgLayout->setMargin(MARGIN);
612
613   /***************************************************************/
614   GroupArguments = new QGroupBox(tr("SMESH_EXTRUSION"), this);
615   QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
616   GroupArgumentsLayout->setSpacing(SPACING);
617   GroupArgumentsLayout->setMargin(MARGIN);
618
619   // Controls for elements selection
620   SelectorWdg = new SMESHGUI_3TypesSelector( GroupArguments );
621
622   ExtrMethod_RBut0 = new QRadioButton(GroupArguments);
623   ExtrMethod_RBut0->setText( tr("SMESH_EXTRUSION_TO_DISTANCE") );
624   ExtrMethod_RBut1 = new QRadioButton(GroupArguments);
625   ExtrMethod_RBut1->setText( tr("SMESH_EXTRUSION_ALONG_VECTOR") );
626   ExtrMethod_RBut2 = new QRadioButton(GroupArguments);
627   ExtrMethod_RBut2->setText( tr("SMESH_EXTRUSION_BY_NORMAL") );
628
629   //Control for the Distance selection
630   TextLabelDistance = new QLabel(tr("SMESH_DISTANCE"), GroupArguments);
631   
632   TextLabelDx = new QLabel(tr("SMESH_X"), GroupArguments);
633   SpinBox_Dx = new SMESHGUI_SpinBox(GroupArguments);
634   
635   TextLabelDy = new QLabel(tr("SMESH_Y"), GroupArguments);
636   SpinBox_Dy = new SMESHGUI_SpinBox(GroupArguments);
637
638   TextLabelDz = new QLabel(tr("SMESH_Z"), GroupArguments);
639   SpinBox_Dz = new SMESHGUI_SpinBox(GroupArguments);
640
641   // Controls for vector selection
642
643   TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupArguments);
644
645   SelectVectorButton = new QPushButton( GroupArguments );
646   SelectVectorButton->setIcon( selectImage );
647   SelectVectorButton->setCheckable( true );
648   SelectorWdg->GetButtonGroup()->addButton( SelectVectorButton );
649
650   TextLabelVx = new QLabel(tr("SMESH_DX"), GroupArguments);
651   SpinBox_Vx = new SMESHGUI_SpinBox(GroupArguments);
652
653   TextLabelVy = new QLabel(tr("SMESH_DY"), GroupArguments);
654   SpinBox_Vy = new SMESHGUI_SpinBox(GroupArguments);
655
656   TextLabelVz = new QLabel(tr("SMESH_DZ"), GroupArguments);
657   SpinBox_Vz = new SMESHGUI_SpinBox(GroupArguments);
658
659   TextLabelDist = new QLabel(tr("SMESH_DISTANCE"), GroupArguments);
660   SpinBox_VDist = new SMESHGUI_SpinBox(GroupArguments);
661
662   // Controls for nb. steps defining
663   TextLabelNbSteps = new QLabel(tr("SMESH_NUMBEROFSTEPS"), GroupArguments);
664   SpinBox_NbSteps = new SalomeApp_IntSpinBox(GroupArguments);
665
666   // CheckBox for groups generation
667   MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
668
669   // CheckBox for ByAverageNormal arg of ExtrusionByNormal()
670   ByAverageNormalCheck = new QCheckBox(tr("BY_AVERAGE_NORMAL"), GroupArguments);
671
672   // CheckBox for UseInputElemsOnly arg of ExtrusionByNormal()
673   UseInputElemsOnlyCheck = new QCheckBox(tr("USE_INPUT_ELEMS_ONLY"), GroupArguments);
674
675   //Preview check box
676   myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
677
678   // Base point
679
680   BasePointGrp = new QGroupBox(tr("BASE_POINT"), GroupArguments);
681   BasePointGrp->setCheckable(true);
682   BasePointGrp->setChecked(false);
683   QHBoxLayout* BasePointGrpLayout = new QHBoxLayout(BasePointGrp);
684   BasePointGrpLayout->setSpacing(SPACING); BasePointGrpLayout->setMargin(MARGIN);
685
686   SelectBasePointButton = new QPushButton(BasePointGrp);
687   SelectBasePointButton->setIcon(selectImage);
688   SelectBasePointButton->setCheckable(true);
689   SelectorWdg->GetButtonGroup()->addButton( SelectBasePointButton );
690
691   QLabel* XLab  = new QLabel(tr("SMESH_X"), BasePointGrp);
692   BasePoint_XSpin = new SMESHGUI_SpinBox(BasePointGrp);
693   BasePoint_XSpin->SetValue(0.);
694   QLabel* YLab  = new QLabel(tr("SMESH_Y"), BasePointGrp);
695   BasePoint_YSpin = new SMESHGUI_SpinBox(BasePointGrp);
696   BasePoint_YSpin->SetValue(0.);
697   QLabel* ZLab  = new QLabel(tr("SMESH_Z"), BasePointGrp);
698   BasePoint_ZSpin = new SMESHGUI_SpinBox(BasePointGrp);
699   BasePoint_ZSpin->SetValue(0.);
700
701   BasePointGrpLayout->addWidget(SelectBasePointButton);
702   BasePointGrpLayout->addWidget(XLab);
703   BasePointGrpLayout->addWidget(BasePoint_XSpin, 1);
704   BasePointGrpLayout->addWidget(YLab);
705   BasePointGrpLayout->addWidget(BasePoint_YSpin, 1);
706   BasePointGrpLayout->addWidget(ZLab);
707   BasePointGrpLayout->addWidget(BasePoint_ZSpin, 1);
708
709   // Scales
710
711   ScalesGrp = new QGroupBox(tr("SMESH_SCALES"), GroupArguments);
712   ScalesGrp->setCheckable(true);
713   ScalesGrp->setChecked(false);
714   QGridLayout* ScalesGrpLayout = new QGridLayout( ScalesGrp );
715   ScalesGrpLayout->setSpacing(SPACING); ScalesGrpLayout->setMargin(MARGIN);
716
717   ScalesList = new QListWidget( ScalesGrp );
718   ScalesList->setSelectionMode(QListWidget::ExtendedSelection);
719
720   AddScaleButton = new QToolButton( ScalesGrp );
721   AddScaleButton->setIcon( addImage );
722
723   RemoveScaleButton = new QToolButton( ScalesGrp );
724   RemoveScaleButton->setIcon( removeImage );
725
726   ScaleSpin = new SMESHGUI_SpinBox( ScalesGrp );
727   ScaleSpin->SetValue(2);
728
729   LinearScalesCheck = new QCheckBox(tr("LINEAR_SCALES"), ScalesGrp );
730
731   ScalesGrpLayout->addWidget(ScalesList,        0, 0, 4, 1);
732   ScalesGrpLayout->addWidget(AddScaleButton,    0, 1);
733   ScalesGrpLayout->addWidget(RemoveScaleButton, 2, 1);
734   ScalesGrpLayout->addWidget(ScaleSpin,         0, 2);
735   ScalesGrpLayout->addWidget(LinearScalesCheck, 4, 0, 1, 3);
736   ScalesGrpLayout->setRowMinimumHeight(1, 10);
737   ScalesGrpLayout->setRowStretch(3, 10);
738
739   // Angles
740
741   AnglesGrp = new QGroupBox(tr("SMESH_ANGLES"), GroupArguments);
742   AnglesGrp->setCheckable(true);
743   AnglesGrp->setChecked(false);
744   QGridLayout* AnglesGrpLayout = new QGridLayout( AnglesGrp );
745   AnglesGrpLayout->setSpacing(SPACING); AnglesGrpLayout->setMargin(MARGIN);
746
747   AnglesList = new QListWidget( AnglesGrp );
748   AnglesList->setSelectionMode(QListWidget::ExtendedSelection);
749
750   AddAngleButton = new QToolButton( AnglesGrp );
751   AddAngleButton->setIcon( addImage );
752
753   RemoveAngleButton = new QToolButton( AnglesGrp );
754   RemoveAngleButton->setIcon( removeImage );
755
756   AngleSpin = new SMESHGUI_SpinBox( AnglesGrp );
757   AngleSpin->SetValue(10);
758
759   LinearAnglesCheck = new QCheckBox(tr("LINEAR_ANGLES"), AnglesGrp );
760
761   AnglesGrpLayout->addWidget(AnglesList,        0, 0, 4, 1);
762   AnglesGrpLayout->addWidget(AddAngleButton,    0, 1);
763   AnglesGrpLayout->addWidget(RemoveAngleButton, 2, 1);
764   AnglesGrpLayout->addWidget(AngleSpin,         0, 2);
765   AnglesGrpLayout->addWidget(LinearAnglesCheck, 4, 0, 1, 3);
766   AnglesGrpLayout->setRowMinimumHeight(1, 10);
767   AnglesGrpLayout->setRowStretch(3, 10);
768
769   // layouting
770   GroupArgumentsLayout->addWidget(SelectorWdg,            0, 0, 1, 9);
771   GroupArgumentsLayout->addWidget(ExtrMethod_RBut0,       1, 0, 1, 3);
772   GroupArgumentsLayout->addWidget(ExtrMethod_RBut1,       1, 3, 1, 3);
773   GroupArgumentsLayout->addWidget(ExtrMethod_RBut2,       1, 6, 1, 3);
774   GroupArgumentsLayout->addWidget(TextLabelDistance,      2, 0);
775   GroupArgumentsLayout->addWidget(TextLabelDx,            2, 2);
776   GroupArgumentsLayout->addWidget(SpinBox_Dx,             2, 3);
777   GroupArgumentsLayout->addWidget(TextLabelDy,            2, 4);
778   GroupArgumentsLayout->addWidget(SpinBox_Dy,             2, 5);
779   GroupArgumentsLayout->addWidget(TextLabelDz,            2, 6);
780   GroupArgumentsLayout->addWidget(SpinBox_Dz,             2, 7);
781   GroupArgumentsLayout->addWidget(TextLabelVector,        3, 0);
782   GroupArgumentsLayout->addWidget(SelectVectorButton,     3, 1);
783   GroupArgumentsLayout->addWidget(TextLabelVx,            3, 2);
784   GroupArgumentsLayout->addWidget(SpinBox_Vx,             3, 3);
785   GroupArgumentsLayout->addWidget(TextLabelVy,            3, 4);
786   GroupArgumentsLayout->addWidget(SpinBox_Vy,             3, 5);
787   GroupArgumentsLayout->addWidget(TextLabelVz,            3, 6);
788   GroupArgumentsLayout->addWidget(SpinBox_Vz,             3, 7);
789   GroupArgumentsLayout->addWidget(TextLabelDist,          4, 0);
790   GroupArgumentsLayout->addWidget(SpinBox_VDist,          4, 3);
791   GroupArgumentsLayout->addWidget(TextLabelNbSteps,       5, 0, 1, 3);
792   GroupArgumentsLayout->addWidget(SpinBox_NbSteps,        5, 3);
793   GroupArgumentsLayout->addWidget(ByAverageNormalCheck,   6, 0, 1, 4);
794   GroupArgumentsLayout->addWidget(UseInputElemsOnlyCheck, 6, 4, 1, 4);
795   GroupArgumentsLayout->addWidget(BasePointGrp,           7, 0, 1, 9);
796   GroupArgumentsLayout->addWidget(ScalesGrp,              8, 0, 1, 4);
797   GroupArgumentsLayout->addWidget(AnglesGrp,              8, 5, 1, 4);
798   GroupArgumentsLayout->addWidget(myPreviewCheckBox,      9, 0, 1, 8);
799   GroupArgumentsLayout->addWidget(MakeGroupsCheck,        10,0, 1, 8);
800   GroupArgumentsLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding), 10, 0);
801
802   /***************************************************************/
803   GroupButtons = new QGroupBox(this);
804   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
805   GroupButtonsLayout->setSpacing(SPACING);
806   GroupButtonsLayout->setMargin(MARGIN);
807
808   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
809   buttonOk->setAutoDefault(true);
810   buttonOk->setDefault(true);
811   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
812   buttonApply->setAutoDefault(true);
813   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
814   buttonCancel->setAutoDefault(true);
815   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
816   buttonHelp->setAutoDefault(true);
817
818   GroupButtonsLayout->addWidget(buttonOk);
819   GroupButtonsLayout->addSpacing(10);
820   GroupButtonsLayout->addWidget(buttonApply);
821   GroupButtonsLayout->addSpacing(10);
822   GroupButtonsLayout->addStretch();
823   GroupButtonsLayout->addWidget(buttonCancel);
824   GroupButtonsLayout->addWidget(buttonHelp);
825
826   /***************************************************************/
827   SMESHGUI_ExtrusionDlgLayout->addWidget(GroupArguments);
828   SMESHGUI_ExtrusionDlgLayout->addWidget(GroupButtons);
829
830   /* Initialisations */
831   SpinBox_Vx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.1, "length_precision");
832   SpinBox_Vy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.1, "length_precision");
833   SpinBox_Vz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.1, "length_precision");
834
835   SpinBox_Dx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
836   SpinBox_Dy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
837   SpinBox_Dz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
838   
839   SpinBox_NbSteps->setRange(1, 999999);
840   SpinBox_VDist->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
841
842   BasePoint_XSpin->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
843   BasePoint_YSpin->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
844   BasePoint_ZSpin->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
845   ScaleSpin->RangeStepAndValidator      (COORD_MIN, COORD_MAX, 1.0, "length_precision");
846   AngleSpin->RangeStepAndValidator      (-180.0, 180.0, 5.0, "angle_precision");
847
848   ExtrMethod_RBut0->setChecked(true);
849   UseInputElemsOnlyCheck->setChecked(true);
850   MakeGroupsCheck->setChecked(true);
851
852   mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
853
854   mySMESHGUI->SetActiveDialogBox(this);
855
856   myHelpFileName = "extrusion.html";
857
858   Init();
859
860   /***************************************************************/
861   // signals and slots connections
862   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
863   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
864   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
865   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
866
867   connect(ExtrMethod_RBut0, SIGNAL(clicked()), this, SLOT(ClickOnRadio()));
868   connect(ExtrMethod_RBut1, SIGNAL(clicked()), this, SLOT(ClickOnRadio()));
869   connect(ExtrMethod_RBut2, SIGNAL(clicked()), this, SLOT(ClickOnRadio()));
870
871   // to update state of the Ok & Apply buttons
872   connect(SpinBox_Vx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
873   connect(SpinBox_Vy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
874   connect(SpinBox_Vz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
875   connect(SpinBox_Dx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
876   connect(SpinBox_Dy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
877   connect(SpinBox_Dz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
878
879   connect(AddScaleButton,    SIGNAL(clicked()), this, SLOT(OnScaleAdded()));
880   connect(RemoveScaleButton, SIGNAL(clicked()), this, SLOT(OnScaleRemoved()));
881   connect(AddAngleButton,    SIGNAL(clicked()), this, SLOT(OnScaleAdded()));
882   connect(RemoveAngleButton, SIGNAL(clicked()), this, SLOT(OnScaleRemoved()));
883
884   connect(SelectVectorButton,   SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
885   connect(SelectBasePointButton,SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
886   connect(BasePointGrp,         SIGNAL(toggled(bool)), this, SLOT(SetEditCurrentArgument()));
887   connect(BasePointGrp,         SIGNAL(toggled(bool)), SelectBasePointButton, SLOT(click()));
888   connect(mySMESHGUI,           SIGNAL(SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
889   connect(mySelectionMgr,       SIGNAL(currentSelectionChanged()), SLOT(toDisplaySimulation()));
890   connect(SelectorWdg,          SIGNAL(selectionChanged()), this, SLOT(toDisplaySimulation()));
891   connect(SelectorWdg,          SIGNAL(selectionChanged()), this, SLOT(CheckIsEnable()));
892   /* to close dialog if study change */
893   connect(mySMESHGUI,           SIGNAL(SignalCloseAllDialogs()),      this, SLOT(reject()));
894   connect(mySMESHGUI,           SIGNAL(SignalActivatedViewManager()), this, SLOT(onOpenView()));
895   connect(mySMESHGUI,           SIGNAL(SignalCloseView()),            this, SLOT(onCloseView()));
896
897   connect(SpinBox_Dx,      SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
898   connect(SpinBox_Dy,      SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
899   connect(SpinBox_Dz,      SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
900   connect(SpinBox_Vx,      SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
901   connect(SpinBox_Vy,      SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
902   connect(SpinBox_Vz,      SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
903   connect(SpinBox_VDist,   SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
904   connect(SpinBox_NbSteps, SIGNAL(valueChanged(int)),    this, SLOT(toDisplaySimulation()));
905   connect(ByAverageNormalCheck,   SIGNAL(toggled(bool)), this, SLOT(toDisplaySimulation()));
906   connect(UseInputElemsOnlyCheck, SIGNAL(toggled(bool)), this, SLOT(toDisplaySimulation()));
907   connect(AddScaleButton,         SIGNAL(clicked()),     this, SLOT(toDisplaySimulation()));
908   connect(RemoveScaleButton,      SIGNAL(clicked()),     this, SLOT(toDisplaySimulation()));
909   connect(LinearScalesCheck,      SIGNAL(toggled(bool)), this, SLOT(toDisplaySimulation()));
910   connect(AddAngleButton,         SIGNAL(clicked()),     this, SLOT(toDisplaySimulation()));
911   connect(RemoveAngleButton,      SIGNAL(clicked()),     this, SLOT(toDisplaySimulation()));
912   connect(LinearAnglesCheck,      SIGNAL(toggled(bool)), this, SLOT(toDisplaySimulation()));
913   connect(BasePointGrp,           SIGNAL(toggled(bool)), this, SLOT(toDisplaySimulation()));
914   connect(BasePoint_XSpin, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
915   connect(BasePoint_YSpin, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
916   connect(BasePoint_ZSpin, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
917   connect(ScalesGrp,       SIGNAL(toggled(bool)), this, SLOT(toDisplaySimulation()));
918   connect(AnglesGrp,       SIGNAL(toggled(bool)), this, SLOT(toDisplaySimulation()));
919
920   //To Connect preview check box
921   connectPreviewControl();
922
923   /***************************************************************/
924   
925   ClickOnRadio();
926 }
927
928 //=================================================================================
929 // function : ~SMESHGUI_ExtrusionDlg()
930 // purpose  : destructor
931 //=================================================================================
932 SMESHGUI_ExtrusionDlg::~SMESHGUI_ExtrusionDlg()
933 {
934 }
935
936 //=================================================================================
937 // function : Init()
938 // purpose  : initialization
939 //=================================================================================
940 void SMESHGUI_ExtrusionDlg::Init (bool ResetControls)
941 {
942   if (ResetControls)
943   {
944     SpinBox_NbSteps->setValue(1);
945     SpinBox_VDist->setValue(10);
946     SpinBox_Dx->SetValue(0);
947     SpinBox_Dy->SetValue(0);
948     SpinBox_Dz->SetValue(0);
949     SpinBox_Vx->SetValue(0);
950     SpinBox_Vy->SetValue(0);
951     SpinBox_Vz->SetValue(0);
952
953     myPreviewCheckBox->setChecked(false);
954     onDisplaySimulation(false);
955   }
956   SelectorWdg->Clear();
957   CheckIsEnable();
958 }
959
960 //=================================================================================
961 // function : CheckIsEnable()
962 // purpose  : Check whether the Ok and Apply buttons should be enabled or not
963 //=================================================================================
964 void SMESHGUI_ExtrusionDlg::CheckIsEnable()
965 {  
966   bool anIsEnable = SelectorWdg->IsAnythingSelected() && isValuesValid();
967
968   buttonOk->setEnabled(anIsEnable);
969   buttonApply->setEnabled(anIsEnable);
970 }
971
972 //=================================================================================
973 // function : isValuesValid()
974 // purpose  : Return true in case if values entered into dialog are valid
975 //=================================================================================
976 bool SMESHGUI_ExtrusionDlg::isValuesValid()
977 {
978   double aX, aY, aZ, aModule = 0;
979   if ( ExtrMethod_RBut0->isChecked() )
980   {
981     aX = SpinBox_Dx->GetValue();
982     aY = SpinBox_Dy->GetValue();
983     aZ = SpinBox_Dz->GetValue();
984     aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
985   }
986   else if ( ExtrMethod_RBut1->isChecked() )
987   {
988     aX = SpinBox_Vx->GetValue();
989     aY = SpinBox_Vy->GetValue();
990     aZ = SpinBox_Vz->GetValue();
991     aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
992     double aVDist = (double)SpinBox_VDist->value();
993     aModule *= aVDist;
994   }
995   else if ( ExtrMethod_RBut2->isChecked() )
996   {
997     aModule = Abs((double)SpinBox_VDist->value());
998   }
999   
1000   return aModule > 1.0E-38;
1001 }
1002
1003 //=======================================================================
1004 //function : getScaleParams
1005 //purpose  : return 3 scaling parameters
1006 //=======================================================================
1007
1008 void SMESHGUI_ExtrusionDlg::getScaleParams( SMESH::double_array*& scales,
1009                                             SMESH::double_array*& basePoint,
1010                                             bool &                scalesVariation,
1011                                             SMESH::double_array*& angles,
1012                                             bool &                anglesVariation )
1013 {
1014   scales = new SMESH::double_array;
1015   if ( ScalesGrp->isChecked() )
1016   {
1017     scales->length( myScalesList.count() );
1018     for ( int i = 0; i < myScalesList.count(); ++i )
1019       (*scales)[i] = myScalesList[i];
1020   }
1021   angles = new SMESH::double_array;
1022   if ( AnglesGrp->isChecked() )
1023   {
1024     angles->length( myAnglesList.count() );
1025     for ( int i = 0; i < myAnglesList.count(); ++i )
1026       (*angles)[i] = myAnglesList[i]*M_PI/180.;
1027   }
1028   basePoint = new SMESH::double_array;
1029   if ( BasePointGrp->isChecked() )
1030   {
1031     basePoint->length( 3 );
1032     (*basePoint)[0] = BasePoint_XSpin->GetValue();
1033     (*basePoint)[1] = BasePoint_YSpin->GetValue();
1034     (*basePoint)[2] = BasePoint_ZSpin->GetValue();
1035   }
1036
1037   scalesVariation = ( scales->length() > 0 && LinearScalesCheck->isChecked() );
1038   anglesVariation = ( angles->length() > 0 && LinearAnglesCheck->isChecked() );
1039 }
1040
1041 //=================================================================================
1042 // function : ClickOnRadio()
1043 // purpose  : Radio button management
1044 //=================================================================================
1045
1046 void SMESHGUI_ExtrusionDlg::ClickOnRadio()
1047 {
1048   if ( ExtrMethod_RBut0->isChecked() )
1049   {
1050     TextLabelDistance->show();
1051     TextLabelDx->show();
1052     SpinBox_Dx->show();
1053     TextLabelDy->show();
1054     SpinBox_Dy->show();
1055     TextLabelDz->show();
1056     SpinBox_Dz->show();
1057
1058     TextLabelVector->hide();
1059     TextLabelVx->hide();
1060     SpinBox_Vx->hide();
1061     TextLabelVy->hide();
1062     SpinBox_Vy->hide();
1063     TextLabelVz->hide();
1064     SpinBox_Vz->hide();
1065     TextLabelDist->hide();
1066     SpinBox_VDist->hide();
1067     SelectVectorButton->hide();
1068
1069     ByAverageNormalCheck->hide();
1070     UseInputElemsOnlyCheck->hide();
1071
1072     SelectorWdg->SetEnabled( true, SMESH::ALL );
1073   }
1074   else if ( ExtrMethod_RBut1->isChecked() )
1075   {
1076     TextLabelDistance->hide();
1077     TextLabelDx->hide();
1078     SpinBox_Dx->hide();
1079     TextLabelDy->hide();
1080     SpinBox_Dy->hide();
1081     TextLabelDz->hide();
1082     SpinBox_Dz->hide();
1083
1084     TextLabelVector->show();
1085     TextLabelVx->show();
1086     SpinBox_Vx->show();
1087     TextLabelVy->show();
1088     SpinBox_Vy->show();
1089     TextLabelVz->show();
1090     SpinBox_Vz->show();
1091     TextLabelDist->show();
1092     SpinBox_VDist->show();
1093     SelectVectorButton->show();
1094
1095     ByAverageNormalCheck->hide();
1096     UseInputElemsOnlyCheck->hide();
1097
1098     SelectorWdg->SetEnabled( true, SMESH::ALL );
1099   }
1100   else if ( ExtrMethod_RBut2->isChecked() )
1101   {
1102     TextLabelDistance->hide();
1103     TextLabelDx->hide();
1104     SpinBox_Dx->hide();
1105     TextLabelDy->hide();
1106     SpinBox_Dy->hide();
1107     TextLabelDz->hide();
1108     SpinBox_Dz->hide();
1109
1110     TextLabelVector->hide();
1111     TextLabelVx->hide();
1112     SpinBox_Vx->hide();
1113     TextLabelVy->hide();
1114     SpinBox_Vy->hide();
1115     TextLabelVz->hide();
1116     SpinBox_Vz->hide();
1117
1118     TextLabelDist->show();
1119     SpinBox_VDist->show();
1120     SelectVectorButton->hide();
1121
1122     ByAverageNormalCheck->show();
1123     UseInputElemsOnlyCheck->show();
1124
1125     SelectorWdg->SetEnabled( false, SMESH::NODE );
1126     SelectorWdg->SetEnabled( false, SMESH::EDGE );
1127   }
1128
1129   BasePointGrp->setEnabled( !ExtrMethod_RBut2->isChecked() );
1130   ScalesGrp   ->setEnabled( !ExtrMethod_RBut2->isChecked() );
1131   AnglesGrp   ->setEnabled( !ExtrMethod_RBut2->isChecked() );
1132
1133
1134   CheckIsEnable();
1135
1136   onDisplaySimulation(true);
1137   // AdjustSize
1138   qApp->processEvents();
1139   updateGeometry();
1140   resize( minimumSizeHint() );
1141 }
1142
1143 //=================================================================================
1144 // function : ClickOnApply()
1145 // purpose  : Called when user presses <Apply> button
1146 //=================================================================================
1147
1148 bool SMESHGUI_ExtrusionDlg::ClickOnApply()
1149 {
1150   if (SMESHGUI::isStudyLocked())
1151     return false;
1152
1153   if (!isValid())
1154     return false;
1155
1156   if ( SelectorWdg->IsAnythingSelected() )
1157   {
1158     SMESH::DirStruct aVector;
1159     getExtrusionVector(aVector);
1160
1161     QStringList aParameters;
1162     if ( ExtrMethod_RBut0->isChecked() )
1163     {
1164       aParameters << SpinBox_Dx->text();
1165       aParameters << SpinBox_Dy->text();
1166       aParameters << SpinBox_Dz->text();
1167     }
1168     else if ( ExtrMethod_RBut1->isChecked() )
1169     {
1170       // only 3 coords in a python dump command :(
1171       // aParameters << SpinBox_Vx->text();
1172       // aParameters << SpinBox_Vy->text();
1173       // aParameters << SpinBox_Vz->text();
1174       // aParameters << SpinBox_VDist->text();
1175     }
1176     else if ( ExtrMethod_RBut2->isChecked() )
1177     {
1178       aParameters << SpinBox_VDist->text();
1179     }
1180
1181     long aNbSteps = (long)SpinBox_NbSteps->value();
1182     aParameters << SpinBox_NbSteps->text();
1183
1184     for (int i = 0; i < myScalesList.count(); i++)
1185       aParameters << ScalesList->item(i)->text();
1186
1187     for (int i = 0; i < myAnglesList.count(); i++)
1188       aParameters << AnglesList->item(i)->text();
1189
1190     bool meshHadNewTypeBefore = true;
1191     int  maxSelType = 0;
1192     const bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
1193
1194     try
1195     {
1196       SUIT_OverrideCursor aWaitCursor;
1197
1198       SMESH::SMESH_Mesh_var mesh = SelectorWdg->GetMesh();
1199
1200       SMESH::ListOfIDSources_var nodes = new SMESH::ListOfIDSources();
1201       SMESH::ListOfIDSources_var edges = new SMESH::ListOfIDSources();
1202       SMESH::ListOfIDSources_var faces = new SMESH::ListOfIDSources();
1203       maxSelType = SelectorWdg->GetSelected( nodes, edges, faces );
1204
1205       // is it necessary to switch on the next Display Mode?
1206       SMESH::ElementType newType = (SMESH::ElementType)( maxSelType + 1 );
1207       SMESH::array_of_ElementType_var oldTypes = mesh->GetTypes();
1208       meshHadNewTypeBefore = false;
1209       for ( size_t i = 0; i < oldTypes->length() && !meshHadNewTypeBefore; ++i )
1210         meshHadNewTypeBefore = ( oldTypes[i] >= newType );
1211
1212       SMESH::SMESH_MeshEditor_var meshEditor = mesh->GetMeshEditor();
1213       SMESH::ListOfGroups_var groups;
1214
1215       mesh->SetParameters( aParameters.join(":").toUtf8().constData() );
1216
1217       if ( ExtrMethod_RBut2->isVisible() &&
1218            ExtrMethod_RBut2->isChecked() ) // Extrusion by normal
1219       {
1220         double stepSize          = (double) SpinBox_VDist->value();
1221         long   nbSteps           = (long) SpinBox_NbSteps->value();
1222         bool   useInputElemsOnly = UseInputElemsOnlyCheck->isChecked();
1223         bool   byAverageNormal   = ByAverageNormalCheck->isChecked();
1224         int    dim               = (maxSelType == SMESH::FACE) ? 2 : 1;
1225
1226         groups = meshEditor->ExtrusionByNormal( faces, stepSize, nbSteps, byAverageNormal,
1227                                                 useInputElemsOnly, makeGroups, dim );
1228       }
1229       else
1230       {
1231         SMESH::double_array_var scales, basePoint, angles;
1232         bool scalesVariation, anglesVariation;
1233         getScaleParams( scales.out(), basePoint.out(), scalesVariation,
1234                         angles.out(), anglesVariation );
1235         groups = meshEditor->ExtrusionSweepObjects( nodes, edges, faces,
1236                                                     aVector, aNbSteps, makeGroups,
1237                                                     scales, scalesVariation, basePoint,
1238                                                     angles, anglesVariation );
1239       }
1240
1241     } catch (...) {
1242     }
1243
1244     SMESH_Actor* actor = SelectorWdg->GetActor();
1245     if ( actor && !meshHadNewTypeBefore )
1246     {
1247       unsigned int aMode = actor->GetEntityMode();
1248       switch ( maxSelType ) {
1249       case SMESH::NODE: // extrude node -> edges
1250         actor->SetRepresentation(SMESH_Actor::eEdge);
1251         actor->SetEntityMode( aMode |= SMESH_Actor::eEdges ); break;
1252       case SMESH::EDGE: // edge -> faces
1253         actor->SetRepresentation(SMESH_Actor::eSurface);
1254         actor->SetEntityMode( aMode |= SMESH_Actor::eFaces ); break;
1255       case SMESH::FACE: // faces -> volumes
1256         actor->SetRepresentation(SMESH_Actor::eSurface);
1257         actor->SetEntityMode( aMode |= SMESH_Actor::eVolumes ); break;
1258       }
1259     }
1260     if ( actor )
1261       SMESH::Update( actor->getIO(), actor->GetVisibility() );
1262     if ( makeGroups )
1263       mySMESHGUI->updateObjBrowser(true); // new groups may appear
1264
1265     mySelectionMgr->clearSelected();
1266     Init(false);
1267
1268     SMESHGUI::Modified();
1269   }
1270   return true;
1271 }
1272
1273 //=================================================================================
1274 // function : ClickOnOk()
1275 // purpose  : Called when user presses <OK> button
1276 //=================================================================================
1277 void SMESHGUI_ExtrusionDlg::ClickOnOk()
1278 {
1279   if (ClickOnApply())
1280     reject();
1281 }
1282
1283 //=================================================================================
1284 // function : reject()
1285 // purpose  : Called when dialog box is closed
1286 //=================================================================================
1287 void SMESHGUI_ExtrusionDlg::reject()
1288 {
1289   disconnect(mySelectionMgr, 0, this, 0);
1290   mySelectionMgr->clearFilters();
1291   //mySelectionMgr->clearSelected();
1292   if (SMESH::GetCurrentVtkView()) {
1293     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1294     SMESH::SetPointRepresentation(false);
1295     SMESH::SetPickable();
1296   }
1297   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1298     aViewWindow->SetSelectionMode(ActorSelection);
1299   mySMESHGUI->ResetState();
1300
1301   QDialog::reject();
1302 }
1303
1304 //=================================================================================
1305 // function : onOpenView()
1306 // purpose  :
1307 //=================================================================================
1308 void SMESHGUI_ExtrusionDlg::onOpenView()
1309 {
1310   if ( mySelector ) {
1311     SMESH::SetPointRepresentation(false);
1312   }
1313   else {
1314     mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
1315     ActivateThisDialog();
1316   }
1317 }
1318
1319 //=================================================================================
1320 // function : onCloseView()
1321 // purpose  :
1322 //=================================================================================
1323 void SMESHGUI_ExtrusionDlg::onCloseView()
1324 {
1325   DeactivateActiveDialog();
1326   mySelector = 0;
1327 }
1328
1329 //=================================================================================
1330 // function : ClickOnHelp()
1331 // purpose  :
1332 //=================================================================================
1333 void SMESHGUI_ExtrusionDlg::ClickOnHelp()
1334 {
1335   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1336   if (app) 
1337     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
1338   else {
1339     QString platform;
1340 #ifdef WIN32
1341     platform = "winapplication";
1342 #else
1343     platform = "application";
1344 #endif
1345     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
1346                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1347                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
1348                                                                  platform)).
1349                              arg(myHelpFileName));
1350   }
1351 }
1352
1353 //=================================================================================
1354 // function : SelectionIntoArgument()
1355 // purpose  : Called when selection has changed or other case
1356 //=================================================================================
1357 void SMESHGUI_ExtrusionDlg::SelectionIntoArgument()
1358 {
1359   // return if dialog box is inactive
1360   if (!GroupButtons->isEnabled())
1361     return;
1362
1363   SALOME_ListIO aList;
1364   mySelectionMgr->selectedObjects(aList);
1365   if ( aList.IsEmpty() || aList.Extent() > 1 )
1366     return;
1367
1368   if ( SelectVectorButton->isChecked() )
1369   {
1370     Handle(SALOME_InteractiveObject) IO = aList.First();
1371     TColStd_IndexedMapOfInteger aMapIndex;
1372     mySelector->GetIndex(IO,aMapIndex);
1373     if ( aMapIndex.Extent() != 1 )
1374       return;
1375     SMESH_Actor* anActor = SMESH::FindActorByEntry( IO->getEntry() );
1376     SMDS_Mesh*     aMesh = anActor ? anActor->GetObject()->GetMesh() : 0;
1377     if ( !aMesh )
1378       return;
1379
1380     const SMDS_MeshFace* face =
1381       aMesh->DownCast< SMDS_MeshFace >(aMesh->FindElement(aMapIndex(1)));
1382     if (!face)
1383       return;
1384
1385     gp_XYZ aNormale = SMESH::getNormale(face);
1386     SpinBox_Vx->SetValue(aNormale.X());
1387     SpinBox_Vy->SetValue(aNormale.Y());
1388     SpinBox_Vz->SetValue(aNormale.Z());
1389   }
1390   else if ( SelectBasePointButton->isChecked() )
1391   {
1392     if (!BasePointGrp->isChecked())
1393       return;
1394
1395     // try to get shape from selection
1396     Handle(SALOME_InteractiveObject) IO = aList.First();
1397
1398     // check if geom vertex is selected
1399     GEOM::GEOM_Object_var aGeomObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(IO);
1400     TopoDS_Vertex aVertex;
1401     if (!aGeomObj->_is_nil()) {
1402       if (aGeomObj->IsShape() && GEOMBase::GetShape(aGeomObj, aVertex) && !aVertex.IsNull()) {
1403         gp_Pnt aPnt = BRep_Tool::Pnt(aVertex);
1404         BasePoint_XSpin->SetValue(aPnt.X());
1405         BasePoint_YSpin->SetValue(aPnt.Y());
1406         BasePoint_ZSpin->SetValue(aPnt.Z());
1407       }
1408     }
1409
1410     if ( aVertex.IsNull() )
1411     {
1412       // check if smesh node is selected
1413       SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(IO);
1414       if (aMesh->_is_nil())
1415         return;
1416
1417       QString aString;
1418       int aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
1419       // return if more than one node is selected
1420       if (aNbUnits != 1)
1421         return;
1422
1423       SMESH_Actor* aMeshActor = SMESH::FindActorByObject(aMesh);
1424       if (!aMeshActor)
1425         return;
1426
1427       SMDS_Mesh* mesh = aMeshActor->GetObject()->GetMesh();
1428       if (!mesh)
1429         return;
1430
1431       const SMDS_MeshNode* n = mesh->FindNode(aString.toLong());
1432       if (!n)
1433         return;
1434
1435       BasePoint_XSpin->SetValue(n->X());
1436       BasePoint_YSpin->SetValue(n->Y());
1437       BasePoint_ZSpin->SetValue(n->Z());
1438     }
1439   }
1440
1441   onDisplaySimulation(true);
1442   CheckIsEnable();
1443 }
1444
1445 //=================================================================================
1446 // function : SetEditCurrentArgument()
1447 // purpose  :
1448 //=================================================================================
1449 void SMESHGUI_ExtrusionDlg::SetEditCurrentArgument()
1450 {
1451   QPushButton* send = (QPushButton*)sender();
1452
1453   disconnect(mySelectionMgr, 0, this, 0);
1454   mySelectionMgr->clearSelected();
1455   mySelectionMgr->clearFilters();
1456
1457   if (send == SelectVectorButton)
1458   {
1459     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1460       aViewWindow->SetSelectionMode(FaceSelection);
1461   }
1462   else if ( send == SelectBasePointButton )
1463   {
1464     SMESH::SetPointRepresentation(true);
1465     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1466       aViewWindow->SetSelectionMode(NodeSelection);
1467
1468     SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter(SMESH::IDSOURCE);
1469     SMESH_NumberFilter* aVertexFilter      = new SMESH_NumberFilter ("GEOM", TopAbs_VERTEX,
1470                                                                      1, TopAbs_VERTEX);
1471     QList<SUIT_SelectionFilter*> aListOfFilters;
1472     aListOfFilters << aMeshOrSubMeshFilter << aVertexFilter;
1473
1474     mySelectionMgr->installFilter(new SMESH_LogicalFilter
1475                                   (aListOfFilters, SMESH_LogicalFilter::LO_OR, true));
1476   }
1477   
1478   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
1479   SelectionIntoArgument();
1480 }
1481
1482 //=================================================================================
1483 // function : DeactivateActiveDialog()
1484 // purpose  : Deactivates this dialog
1485 //=================================================================================
1486 void SMESHGUI_ExtrusionDlg::DeactivateActiveDialog()
1487 {
1488   if (GroupButtons->isEnabled())
1489   {
1490     GroupArguments->setEnabled(false);
1491     GroupButtons->setEnabled(false);
1492     SelectorWdg->setEnabled(false);
1493     mySMESHGUI->ResetState();
1494     mySMESHGUI->SetActiveDialogBox(0);
1495   }
1496 }
1497
1498 //=================================================================================
1499 // function : ActivateThisDialog()
1500 // purpose  : Activates this dialog
1501 //=================================================================================
1502 void SMESHGUI_ExtrusionDlg::ActivateThisDialog()
1503 {
1504   // Emit a signal to deactivate the active dialog
1505   mySMESHGUI->EmitSignalDeactivateDialog();
1506   GroupArguments->setEnabled(true);
1507   GroupButtons->setEnabled(true);
1508   SelectorWdg->setEnabled(true);
1509
1510   mySMESHGUI->SetActiveDialogBox(this);
1511 }
1512
1513 //=================================================================================
1514 // function : enterEvent()
1515 // purpose  :
1516 //=================================================================================
1517 void SMESHGUI_ExtrusionDlg::enterEvent (QEvent*)
1518 {
1519   if ( !GroupButtons->isEnabled() ) {
1520     SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
1521     if ( aViewWindow && !mySelector) {
1522       mySelector = aViewWindow->GetSelector();
1523     }
1524     ActivateThisDialog();
1525   }
1526 }
1527
1528 //=================================================================================
1529 // function : keyPressEvent()
1530 // purpose  :
1531 //=================================================================================
1532 void SMESHGUI_ExtrusionDlg::keyPressEvent( QKeyEvent* e )
1533 {
1534   QDialog::keyPressEvent( e );
1535   if ( e->isAccepted() )
1536     return;
1537
1538   if ( e->key() == Qt::Key_F1 ) {
1539     e->accept();
1540     ClickOnHelp();
1541   }
1542 }
1543
1544 //=================================================================================
1545 // function : isValid
1546 // purpose  :
1547 //=================================================================================
1548 bool SMESHGUI_ExtrusionDlg::isValid()
1549 {
1550   QString msg;
1551   bool ok = true;
1552   if ( ExtrMethod_RBut0->isChecked() ) {
1553     ok = SpinBox_Dx->isValid( msg, true ) && ok;
1554     ok = SpinBox_Dy->isValid( msg, true ) && ok;
1555     ok = SpinBox_Dz->isValid( msg, true ) && ok;
1556   } else if ( ExtrMethod_RBut1->isChecked() ) {
1557     ok = SpinBox_Vx->isValid( msg, true ) && ok;
1558     ok = SpinBox_Vy->isValid( msg, true ) && ok;
1559     ok = SpinBox_Vz->isValid( msg, true ) && ok;
1560     ok = SpinBox_VDist->isValid( msg, true ) && ok;
1561   }
1562   ok = SpinBox_NbSteps->isValid( msg, true ) && ok;
1563
1564   if ( BasePointGrp->isChecked()) {
1565     ok = BasePoint_XSpin->isValid( msg, true ) && ok;
1566     ok = BasePoint_YSpin->isValid( msg, true ) && ok;
1567     ok = BasePoint_ZSpin->isValid( msg, true ) && ok;
1568   }
1569
1570   if( !ok ) {
1571     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1572     if ( !msg.isEmpty() )
1573       str += "\n" + msg;
1574     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1575     return false;
1576   }
1577   return true;
1578 }
1579
1580 //=================================================================================
1581 // function : onDisplaySimulation
1582 // purpose  : Show/Hide preview
1583 //=================================================================================
1584 void SMESHGUI_ExtrusionDlg::onDisplaySimulation( bool toDisplayPreview )
1585 {
1586   if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1587     if ( SelectorWdg->IsAnythingSelected() && isValid() && isValuesValid())
1588     {
1589       //Get input vector
1590       SMESH::DirStruct aVector;
1591       getExtrusionVector(aVector);
1592
1593       //Get Number of the steps
1594       long aNbSteps = (long)SpinBox_NbSteps->value();
1595       try
1596       {
1597         SUIT_OverrideCursor aWaitCursor;
1598
1599         SMESH::SMESH_Mesh_var             mesh = SelectorWdg->GetMesh();
1600         SMESH::SMESH_MeshEditor_var meshEditor = mesh->GetMeshEditPreviewer();
1601         SMESH::ListOfGroups_var         groups;
1602
1603         SMESH::ListOfIDSources_var nodes = new SMESH::ListOfIDSources();
1604         SMESH::ListOfIDSources_var edges = new SMESH::ListOfIDSources();
1605         SMESH::ListOfIDSources_var faces = new SMESH::ListOfIDSources();
1606         const int  maxSelType = SelectorWdg->GetSelected( nodes, edges, faces );
1607         const bool makeGroups = false;
1608
1609         if ( ExtrMethod_RBut2->isVisible() &&
1610              ExtrMethod_RBut2->isChecked() ) // Extrusion by normal
1611         {
1612           double stepSize          = (double) SpinBox_VDist->value();
1613           long   nbSteps           = (long) SpinBox_NbSteps->value();
1614           bool   useInputElemsOnly = UseInputElemsOnlyCheck->isChecked();
1615           bool   byAverageNormal   = ByAverageNormalCheck->isChecked();
1616           int    dim               = (maxSelType == SMESH::FACE) ? 2 : 1;
1617
1618           groups = meshEditor->ExtrusionByNormal( faces, stepSize, nbSteps, byAverageNormal,
1619                                                   useInputElemsOnly, makeGroups, dim );
1620         }
1621         else
1622         {
1623           SMESH::double_array_var scales, basePoint, angles;
1624           bool scalesVariation, anglesVariation;
1625           getScaleParams( scales.out(), basePoint.out(), scalesVariation,
1626                           angles.out(), anglesVariation );
1627           groups = meshEditor->ExtrusionSweepObjects( nodes, edges, faces,
1628                                                       aVector, aNbSteps, makeGroups,
1629                                                       scales, scalesVariation, basePoint,
1630                                                       angles, anglesVariation );
1631         }
1632         SMESH::MeshPreviewStruct_var aMeshPreviewStruct = meshEditor->GetPreviewData();
1633         mySimulation->SetData(aMeshPreviewStruct);
1634
1635       } catch (...) {
1636         hidePreview();
1637       }
1638     } else {
1639       hidePreview();
1640     }
1641   } else {
1642     hidePreview();
1643   }
1644 }
1645
1646 //=================================================================================
1647 // function : getExtrusionVector()
1648 // purpose  : get direction of the extrusion
1649 //=================================================================================
1650 void SMESHGUI_ExtrusionDlg::getExtrusionVector(SMESH::DirStruct& aVector)
1651 {
1652   if ( ExtrMethod_RBut0->isChecked() )
1653   {
1654     aVector.PS.x = SpinBox_Dx->GetValue();
1655     aVector.PS.y = SpinBox_Dy->GetValue();
1656     aVector.PS.z = SpinBox_Dz->GetValue();
1657   }
1658   else if ( ExtrMethod_RBut1->isChecked() )
1659   {
1660     gp_XYZ aNormale(SpinBox_Vx->GetValue(),
1661                     SpinBox_Vy->GetValue(),
1662                     SpinBox_Vz->GetValue());
1663     aNormale /= aNormale.Modulus();
1664     double aVDist = (double)SpinBox_VDist->value();
1665
1666     aVector.PS.x = aNormale.X()*aVDist;
1667     aVector.PS.y = aNormale.Y()*aVDist;
1668     aVector.PS.z = aNormale.Z()*aVDist;
1669   }
1670 }
1671
1672 //=======================================================================
1673 // function : OnScaleAdded()
1674 // purpose  : Called when user adds Scale or Angle to the list
1675 //=======================================================================
1676 void SMESHGUI_ExtrusionDlg::OnScaleAdded()
1677 {
1678   if ( sender() == AddScaleButton )
1679   {
1680     QString msg;
1681     if( !ScaleSpin->isValid( msg, true ) ) {
1682       QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1683       if ( !msg.isEmpty() )
1684         str += "\n" + msg;
1685       SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1686       return;
1687     }
1688     ScalesList->addItem(ScaleSpin->text());
1689     myScalesList.append(ScaleSpin->GetValue());
1690   }
1691
1692   if ( sender() == AddAngleButton )
1693   {
1694     QString msg;
1695     if( !AngleSpin->isValid( msg, true ) ) {
1696       QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1697       if ( !msg.isEmpty() )
1698         str += "\n" + msg;
1699       SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1700       return;
1701     }
1702     AnglesList->addItem(AngleSpin->text());
1703     myAnglesList.append(AngleSpin->GetValue());
1704   }
1705 }
1706
1707 //=======================================================================
1708 // function : OnScaleRemoved()
1709 // purpose  : Called when user removes Scales or Angles from the list
1710 //=======================================================================
1711 void SMESHGUI_ExtrusionDlg::OnScaleRemoved()
1712 {
1713   QListWidget* widget;
1714   QList<double>* list;
1715   if ( sender() == RemoveScaleButton )
1716   {
1717     widget = ScalesList;
1718     list   = & myScalesList;
1719   }
1720   else
1721   {
1722     widget = AnglesList;
1723     list   = & myAnglesList;
1724   }
1725
1726   QList<QListWidgetItem*> aList = widget->selectedItems();
1727   QListWidgetItem* anItem;
1728   int row = 0;
1729   foreach(anItem, aList) {
1730     row = widget->row(anItem);
1731     list->removeAt(row);
1732     delete anItem;
1733   }
1734   widget->setCurrentRow( row, QItemSelectionModel::Select );
1735 }