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