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