Salome HOME
0a7901267b630e6cb8e1900e3a7fbda257f10be7
[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
782   connect(SpinBox_Dx,      SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
783   connect(SpinBox_Dy,      SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
784   connect(SpinBox_Dz,      SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
785   connect(SpinBox_Vx,      SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
786   connect(SpinBox_Vy,      SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
787   connect(SpinBox_Vz,      SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
788   connect(SpinBox_VDist,   SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
789   connect(SpinBox_NbSteps, SIGNAL(valueChanged(int)),    this, SLOT(toDisplaySimulation()));
790   connect(ByAverageNormalCheck,   SIGNAL(toggled(bool)), this, SLOT(toDisplaySimulation()));
791   connect(UseInputElemsOnlyCheck, SIGNAL(toggled(bool)), this, SLOT(toDisplaySimulation()));
792
793   //To Connect preview check box
794   connectPreviewControl();
795
796   /***************************************************************/
797   
798   ClickOnRadio();
799 }
800
801 //=================================================================================
802 // function : ~SMESHGUI_ExtrusionDlg()
803 // purpose  : destructor
804 //=================================================================================
805 SMESHGUI_ExtrusionDlg::~SMESHGUI_ExtrusionDlg()
806 {
807 }
808
809 //=================================================================================
810 // function : Init()
811 // purpose  : initialization
812 //=================================================================================
813 void SMESHGUI_ExtrusionDlg::Init (bool ResetControls)
814 {
815   if (ResetControls)
816   {
817     SpinBox_NbSteps->setValue(1);
818     SpinBox_VDist->setValue(10);
819     SpinBox_Dx->SetValue(0);
820     SpinBox_Dy->SetValue(0);
821     SpinBox_Dz->SetValue(0);
822     SpinBox_Vx->SetValue(0);
823     SpinBox_Vy->SetValue(0);
824     SpinBox_Vz->SetValue(0);
825
826     myPreviewCheckBox->setChecked(false);
827     onDisplaySimulation(false);
828   }
829   SelectorWdg->Clear();
830   CheckIsEnable();
831 }
832
833 //=================================================================================
834 // function : CheckIsEnable()
835 // purpose  : Check whether the Ok and Apply buttons should be enabled or not
836 //=================================================================================
837 void SMESHGUI_ExtrusionDlg::CheckIsEnable()
838 {  
839   bool anIsEnable = SelectorWdg->IsAnythingSelected() && isValuesValid();
840
841   buttonOk->setEnabled(anIsEnable);
842   buttonApply->setEnabled(anIsEnable);
843 }
844
845 //=================================================================================
846 // function : isValuesValid()
847 // purpose  : Return true in case if values entered into dialog are valid
848 //=================================================================================
849 bool SMESHGUI_ExtrusionDlg::isValuesValid()
850 {
851   double aX, aY, aZ, aModule = 0;
852   if ( ExtrMethod_RBut0->isChecked() )
853   {
854     aX = SpinBox_Dx->GetValue();
855     aY = SpinBox_Dy->GetValue();
856     aZ = SpinBox_Dz->GetValue();
857     aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
858   }
859   else if ( ExtrMethod_RBut1->isChecked() )
860   {
861     aX = SpinBox_Vx->GetValue();
862     aY = SpinBox_Vy->GetValue();
863     aZ = SpinBox_Vz->GetValue();
864     aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
865     double aVDist = (double)SpinBox_VDist->value();
866     aModule *= aVDist;
867   }
868   else if ( ExtrMethod_RBut2->isChecked() )
869   {
870     aModule = Abs((double)SpinBox_VDist->value());
871   }
872   
873   return aModule > 1.0E-38;
874 }
875
876 //=================================================================================
877 // function : ClickOnRadio()
878 // purpose  : Radio button management
879 //=================================================================================
880
881 void SMESHGUI_ExtrusionDlg::ClickOnRadio()
882 {
883   if ( ExtrMethod_RBut0->isChecked() )
884   {
885     TextLabelDistance->show();
886     TextLabelDx->show();
887     SpinBox_Dx->show();
888     TextLabelDy->show();
889     SpinBox_Dy->show();
890     TextLabelDz->show();
891     SpinBox_Dz->show();
892
893     TextLabelVector->hide();
894     TextLabelVx->hide();
895     SpinBox_Vx->hide();
896     TextLabelVy->hide();
897     SpinBox_Vy->hide();
898     TextLabelVz->hide();
899     SpinBox_Vz->hide();
900     TextLabelDist->hide();
901     SpinBox_VDist->hide();
902     SelectVectorButton->hide();
903
904     ByAverageNormalCheck->hide();
905     UseInputElemsOnlyCheck->hide();
906
907     SelectorWdg->SetEnabled( true, SMESH::ALL );
908   }
909   else if ( ExtrMethod_RBut1->isChecked() )
910   {
911     TextLabelDistance->hide();
912     TextLabelDx->hide();
913     SpinBox_Dx->hide();
914     TextLabelDy->hide();
915     SpinBox_Dy->hide();
916     TextLabelDz->hide();
917     SpinBox_Dz->hide();
918
919     TextLabelVector->show();
920     TextLabelVx->show();
921     SpinBox_Vx->show();
922     TextLabelVy->show();
923     SpinBox_Vy->show();
924     TextLabelVz->show();
925     SpinBox_Vz->show();
926     TextLabelDist->show();
927     SpinBox_VDist->show();
928     SelectVectorButton->show();
929
930     ByAverageNormalCheck->hide();
931     UseInputElemsOnlyCheck->hide();
932
933     SelectorWdg->SetEnabled( true, SMESH::ALL );
934   }
935   else if ( ExtrMethod_RBut2->isChecked() )
936   {
937     TextLabelDistance->hide();
938     TextLabelDx->hide();
939     SpinBox_Dx->hide();
940     TextLabelDy->hide();
941     SpinBox_Dy->hide();
942     TextLabelDz->hide();
943     SpinBox_Dz->hide();
944
945     TextLabelVector->hide();
946     TextLabelVx->hide();
947     SpinBox_Vx->hide();
948     TextLabelVy->hide();
949     SpinBox_Vy->hide();
950     TextLabelVz->hide();
951     SpinBox_Vz->hide();
952
953     TextLabelDist->show();
954     SpinBox_VDist->show();
955     SelectVectorButton->hide();
956
957     ByAverageNormalCheck->show();
958     UseInputElemsOnlyCheck->show();
959
960     SelectorWdg->SetEnabled( false, SMESH::NODE );
961     SelectorWdg->SetEnabled( false, SMESH::EDGE );
962   }
963
964   CheckIsEnable();
965
966   onDisplaySimulation(true);
967   // AdjustSize
968   qApp->processEvents();
969   updateGeometry();
970   resize( minimumSizeHint() );
971 }
972
973 //=================================================================================
974 // function : ClickOnApply()
975 // purpose  : Called when user presses <Apply> button
976 //=================================================================================
977
978 bool SMESHGUI_ExtrusionDlg::ClickOnApply()
979 {
980   if (mySMESHGUI->isActiveStudyLocked())
981     return false;
982
983   if (!isValid())
984     return false;
985
986   if ( SelectorWdg->IsAnythingSelected() )
987   {
988     SMESH::DirStruct aVector;
989     getExtrusionVector(aVector);
990     
991     QStringList aParameters;
992     if ( ExtrMethod_RBut0->isChecked() )
993     {
994       aParameters << SpinBox_Dx->text();
995       aParameters << SpinBox_Dy->text();
996       aParameters << SpinBox_Dz->text();
997     }
998     else if ( ExtrMethod_RBut1->isChecked() )
999     {
1000       // only 3 coords in a python dump command :(
1001       // aParameters << SpinBox_Vx->text();
1002       // aParameters << SpinBox_Vy->text();
1003       // aParameters << SpinBox_Vz->text();
1004       // aParameters << SpinBox_VDist->text();
1005     }
1006     else if ( ExtrMethod_RBut2->isChecked() )
1007     {
1008       aParameters << SpinBox_VDist->text();
1009     }
1010
1011     long aNbSteps = (long)SpinBox_NbSteps->value();
1012
1013     aParameters << SpinBox_NbSteps->text();
1014
1015     bool meshHadNewTypeBefore = true;
1016     int  maxSelType = 0;
1017     const bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
1018
1019     try {
1020       SUIT_OverrideCursor aWaitCursor;
1021
1022       SMESH::SMESH_Mesh_var mesh = SelectorWdg->GetMesh();
1023
1024       SMESH::ListOfIDSources_var nodes = new SMESH::ListOfIDSources();
1025       SMESH::ListOfIDSources_var edges = new SMESH::ListOfIDSources();
1026       SMESH::ListOfIDSources_var faces = new SMESH::ListOfIDSources();
1027       maxSelType = SelectorWdg->GetSelected( nodes, edges, faces );
1028
1029       // is it necessary to switch on the next Display Mode?
1030       SMESH::ElementType newType = (SMESH::ElementType)( maxSelType + 1 );
1031       SMESH::array_of_ElementType_var oldTypes = mesh->GetTypes();
1032       meshHadNewTypeBefore = false;
1033       for ( size_t i = 0; i < oldTypes->length() && !meshHadNewTypeBefore; ++i )
1034         meshHadNewTypeBefore = ( oldTypes[i] >= newType );
1035
1036       SMESH::SMESH_MeshEditor_var meshEditor = mesh->GetMeshEditor();
1037       SMESH::ListOfGroups_var groups;
1038
1039       mesh->SetParameters( aParameters.join(":").toLatin1().constData() );
1040
1041       if ( ExtrMethod_RBut2->isVisible() &&
1042            ExtrMethod_RBut2->isChecked() ) // Extrusion by normal
1043       {
1044         double stepSize          = (double) SpinBox_VDist->value();
1045         long   nbSteps           = (long) SpinBox_NbSteps->value();
1046         bool   useInputElemsOnly = UseInputElemsOnlyCheck->isChecked();
1047         bool   byAverageNormal   = ByAverageNormalCheck->isChecked();
1048         int    dim               = (maxSelType == SMESH::FACE) ? 2 : 1;
1049
1050         groups = meshEditor->ExtrusionByNormal( faces, stepSize, nbSteps, useInputElemsOnly,
1051                                                 byAverageNormal, makeGroups, dim );
1052       }
1053       else
1054       {
1055         groups = meshEditor->ExtrusionSweepObjects( nodes, edges, faces,
1056                                                     aVector, aNbSteps, makeGroups );
1057       }
1058
1059     } catch (...) {
1060     }
1061
1062     SMESH_Actor* actor = SelectorWdg->GetActor();
1063     if ( actor && !meshHadNewTypeBefore )
1064     {
1065       unsigned int aMode = actor->GetEntityMode();
1066       switch ( maxSelType ) {
1067       case SMESH::NODE: // extrude node -> edges
1068         actor->SetRepresentation(SMESH_Actor::eEdge);
1069         actor->SetEntityMode( aMode |= SMESH_Actor::eEdges ); break;
1070       case SMESH::EDGE: // edge -> faces
1071         actor->SetRepresentation(SMESH_Actor::eSurface);
1072         actor->SetEntityMode( aMode |= SMESH_Actor::eFaces ); break;
1073       case SMESH::FACE: // faces -> volumes
1074         actor->SetRepresentation(SMESH_Actor::eSurface);
1075         actor->SetEntityMode( aMode |= SMESH_Actor::eVolumes ); break;
1076       }
1077     }
1078     if ( actor )
1079       SMESH::Update( actor->getIO(), actor->GetVisibility() );
1080     if ( makeGroups )
1081       mySMESHGUI->updateObjBrowser(true); // new groups may appear
1082     Init(false);
1083     mySelectionMgr->clearSelected();
1084     SelectorWdg->Clear();
1085
1086     SMESHGUI::Modified();
1087   }
1088   return true;
1089 }
1090
1091 //=================================================================================
1092 // function : ClickOnOk()
1093 // purpose  : Called when user presses <OK> button
1094 //=================================================================================
1095 void SMESHGUI_ExtrusionDlg::ClickOnOk()
1096 {
1097   if (ClickOnApply())
1098     reject();
1099 }
1100
1101 //=================================================================================
1102 // function : reject()
1103 // purpose  : Called when dialog box is closed
1104 //=================================================================================
1105 void SMESHGUI_ExtrusionDlg::reject()
1106 {
1107   disconnect(mySelectionMgr, 0, this, 0);
1108   mySelectionMgr->clearFilters();
1109   //mySelectionMgr->clearSelected();
1110   if (SMESH::GetCurrentVtkView()) {
1111     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1112     SMESH::SetPointRepresentation(false);
1113     SMESH::SetPickable();
1114   }
1115   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1116     aViewWindow->SetSelectionMode(ActorSelection);
1117   mySMESHGUI->ResetState();
1118
1119   QDialog::reject();
1120 }
1121
1122 //=================================================================================
1123 // function : ClickOnHelp()
1124 // purpose  :
1125 //=================================================================================
1126 void SMESHGUI_ExtrusionDlg::ClickOnHelp()
1127 {
1128   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1129   if (app) 
1130     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
1131   else {
1132     QString platform;
1133 #ifdef WIN32
1134     platform = "winapplication";
1135 #else
1136     platform = "application";
1137 #endif
1138     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
1139                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1140                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
1141                                                                  platform)).
1142                              arg(myHelpFileName));
1143   }
1144 }
1145
1146 //=================================================================================
1147 // function : SelectionIntoArgument()
1148 // purpose  : Called when selection has changed or other case
1149 //=================================================================================
1150 void SMESHGUI_ExtrusionDlg::SelectionIntoArgument()
1151 {
1152   // return if dialog box is inactive
1153   if (!GroupButtons->isEnabled())
1154     return;
1155
1156   if ( SelectVectorButton->isChecked() )
1157   {
1158     SALOME_ListIO aList;
1159     mySelectionMgr->selectedObjects(aList);
1160     if ( aList.IsEmpty() || aList.Extent() > 1 )
1161       return;
1162
1163     Handle(SALOME_InteractiveObject) IO = aList.First();
1164     TColStd_IndexedMapOfInteger aMapIndex;
1165     mySelector->GetIndex(IO,aMapIndex);
1166     if ( aMapIndex.Extent() != 1 )
1167       return;
1168     SMESH_Actor* anActor = SMESH::FindActorByEntry( IO->getEntry() );
1169     SMDS_Mesh*     aMesh = anActor ? anActor->GetObject()->GetMesh() : 0;
1170     if ( !aMesh )
1171       return;
1172
1173     const SMDS_MeshFace* face =
1174       dynamic_cast<const SMDS_MeshFace*>(aMesh->FindElement(aMapIndex(1)));
1175     if (!face)
1176       return;
1177
1178     gp_XYZ aNormale = SMESH::getNormale(face);
1179     SpinBox_Vx->SetValue(aNormale.X());
1180     SpinBox_Vy->SetValue(aNormale.Y());
1181     SpinBox_Vz->SetValue(aNormale.Z());
1182   }
1183
1184   onDisplaySimulation(true);
1185   CheckIsEnable();
1186 }
1187
1188 //=================================================================================
1189 // function : SetEditCurrentArgument()
1190 // purpose  :
1191 //=================================================================================
1192 void SMESHGUI_ExtrusionDlg::SetEditCurrentArgument()
1193 {
1194   QPushButton* send = (QPushButton*)sender();
1195
1196   disconnect(mySelectionMgr, 0, this, 0);
1197   mySelectionMgr->clearSelected();
1198   mySelectionMgr->clearFilters();
1199
1200   if (send == SelectVectorButton)
1201   {
1202     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1203       aViewWindow->SetSelectionMode(FaceSelection);
1204   }
1205   
1206   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
1207   SelectionIntoArgument();
1208 }
1209
1210 //=================================================================================
1211 // function : DeactivateActiveDialog()
1212 // purpose  : Deactivates this dialog
1213 //=================================================================================
1214 void SMESHGUI_ExtrusionDlg::DeactivateActiveDialog()
1215 {
1216   if (GroupButtons->isEnabled())
1217   {
1218     GroupArguments->setEnabled(false);
1219     GroupButtons->setEnabled(false);
1220     SelectorWdg->setEnabled(false);
1221     mySMESHGUI->ResetState();
1222     mySMESHGUI->SetActiveDialogBox(0);
1223   }
1224 }
1225
1226 //=================================================================================
1227 // function : ActivateThisDialog()
1228 // purpose  : Activates this dialog
1229 //=================================================================================
1230 void SMESHGUI_ExtrusionDlg::ActivateThisDialog()
1231 {
1232   // Emit a signal to deactivate the active dialog
1233   mySMESHGUI->EmitSignalDeactivateDialog();
1234   GroupArguments->setEnabled(true);
1235   GroupButtons->setEnabled(true);
1236   SelectorWdg->setEnabled(true);
1237
1238   mySMESHGUI->SetActiveDialogBox(this);
1239 }
1240
1241 //=================================================================================
1242 // function : enterEvent()
1243 // purpose  : Mouse enter event
1244 //=================================================================================
1245 void SMESHGUI_ExtrusionDlg::enterEvent (QEvent*)
1246 {
1247   if (!GroupButtons->isEnabled())
1248     ActivateThisDialog();
1249 }
1250
1251 //=================================================================================
1252 // function : keyPressEvent()
1253 // purpose  :
1254 //=================================================================================
1255 void SMESHGUI_ExtrusionDlg::keyPressEvent( QKeyEvent* e )
1256 {
1257   QDialog::keyPressEvent( e );
1258   if ( e->isAccepted() )
1259     return;
1260
1261   if ( e->key() == Qt::Key_F1 ) {
1262     e->accept();
1263     ClickOnHelp();
1264   }
1265 }
1266
1267 //=================================================================================
1268 // function : isValid
1269 // purpose  :
1270 //=================================================================================
1271 bool SMESHGUI_ExtrusionDlg::isValid()
1272 {
1273   QString msg;
1274   bool ok = true;
1275   if ( ExtrMethod_RBut0->isChecked() ) {
1276     ok = SpinBox_Dx->isValid( msg, true ) && ok;
1277     ok = SpinBox_Dy->isValid( msg, true ) && ok;
1278     ok = SpinBox_Dz->isValid( msg, true ) && ok;
1279   } else if ( ExtrMethod_RBut1->isChecked() ) {
1280     ok = SpinBox_Vx->isValid( msg, true ) && ok;
1281     ok = SpinBox_Vy->isValid( msg, true ) && ok;
1282     ok = SpinBox_Vz->isValid( msg, true ) && ok;
1283     ok = SpinBox_VDist->isValid( msg, true ) && ok;
1284   }
1285   ok = SpinBox_NbSteps->isValid( msg, true ) && ok;
1286
1287   if( !ok ) {
1288     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1289     if ( !msg.isEmpty() )
1290       str += "\n" + msg;
1291     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1292     return false;
1293   }
1294   return true;
1295 }
1296
1297 //=================================================================================
1298 // function : onDisplaySimulation
1299 // purpose  : Show/Hide preview
1300 //=================================================================================
1301 void SMESHGUI_ExtrusionDlg::onDisplaySimulation( bool toDisplayPreview )
1302 {
1303   if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1304     if ( SelectorWdg->IsAnythingSelected() && isValid() && isValuesValid())
1305     {
1306       //Get input vector
1307       SMESH::DirStruct aVector;
1308       getExtrusionVector(aVector);
1309
1310       //Get Number of the steps
1311       long aNbSteps = (long)SpinBox_NbSteps->value();
1312       try
1313       {
1314         SUIT_OverrideCursor aWaitCursor;
1315
1316         SMESH::SMESH_Mesh_var             mesh = SelectorWdg->GetMesh();
1317         SMESH::SMESH_MeshEditor_var meshEditor = mesh->GetMeshEditPreviewer();
1318         SMESH::ListOfGroups_var         groups;
1319
1320         SMESH::ListOfIDSources_var nodes = new SMESH::ListOfIDSources();
1321         SMESH::ListOfIDSources_var edges = new SMESH::ListOfIDSources();
1322         SMESH::ListOfIDSources_var faces = new SMESH::ListOfIDSources();
1323         const int  maxSelType = SelectorWdg->GetSelected( nodes, edges, faces );
1324         const bool makeGroups = false;
1325
1326         if ( ExtrMethod_RBut2->isVisible() &&
1327              ExtrMethod_RBut2->isChecked() ) // Extrusion by normal
1328         {
1329           double stepSize          = (double) SpinBox_VDist->value();
1330           long   nbSteps           = (long) SpinBox_NbSteps->value();
1331           bool   useInputElemsOnly = UseInputElemsOnlyCheck->isChecked();
1332           bool   byAverageNormal   = ByAverageNormalCheck->isChecked();
1333           int    dim               = (maxSelType == SMESH::FACE) ? 2 : 1;
1334
1335           groups = meshEditor->ExtrusionByNormal( faces, stepSize, nbSteps, useInputElemsOnly,
1336                                                   byAverageNormal, makeGroups, dim );
1337         }
1338         else
1339         {
1340           groups = meshEditor->ExtrusionSweepObjects( nodes, edges, faces,
1341                                                       aVector, aNbSteps, makeGroups );
1342         }
1343         SMESH::MeshPreviewStruct_var aMeshPreviewStruct = meshEditor->GetPreviewData();
1344         mySimulation->SetData(aMeshPreviewStruct._retn());
1345
1346       } catch (...) {
1347         hidePreview();
1348       }
1349     } else {
1350       hidePreview();
1351     }
1352   } else {
1353     hidePreview();
1354   }
1355 }
1356
1357 //=================================================================================
1358 // function : getExtrusionVector()
1359 // purpose  : get direction of the extrusion
1360 //=================================================================================
1361 void SMESHGUI_ExtrusionDlg::getExtrusionVector(SMESH::DirStruct& aVector)
1362 {
1363   if ( ExtrMethod_RBut0->isChecked() )
1364   {
1365     aVector.PS.x = SpinBox_Dx->GetValue();
1366     aVector.PS.y = SpinBox_Dy->GetValue();
1367     aVector.PS.z = SpinBox_Dz->GetValue();
1368   }
1369   else if ( ExtrMethod_RBut1->isChecked() )
1370   {
1371     gp_XYZ aNormale(SpinBox_Vx->GetValue(),
1372                     SpinBox_Vy->GetValue(),
1373                     SpinBox_Vz->GetValue());
1374     aNormale /= aNormale.Modulus();
1375     double aVDist = (double)SpinBox_VDist->value();
1376
1377     aVector.PS.x = aNormale.X()*aVDist;
1378     aVector.PS.y = aNormale.Y()*aVDist;
1379     aVector.PS.z = aNormale.Z()*aVDist;
1380   }
1381 }