1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_ExtrusionDlg.cxx
25 // Author : Michael ZORIN, Open CASCADE S.A.S.
28 #include "SMESHGUI_ExtrusionDlg.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"
39 #include <SMESH_Actor.h>
40 #include <SMESH_TypeFilter.hxx>
41 #include <SMESH_LogicalFilter.hxx>
43 #include <SMDS_Mesh.hxx>
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>
52 #include <LightApp_Application.h>
53 #include <LightApp_SelectionMgr.h>
55 #include <SVTK_ViewModel.h>
56 #include <SVTK_ViewWindow.h>
58 #include <SalomeApp_IntSpinBox.h>
61 #include <TColStd_MapOfInteger.hxx>
62 #include <TColStd_IndexedMapOfInteger.hxx>
66 #include <QApplication>
67 #include <QButtonGroup>
71 #include <QPushButton>
72 #include <QRadioButton>
74 #include <QHBoxLayout>
75 #include <QVBoxLayout>
76 #include <QGridLayout>
80 #include <SALOMEconfig.h>
81 #include CORBA_SERVER_HEADER(SMESH_Group)
82 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
87 //=================================================================================
88 // function : SMESHGUI_ExtrusionDlg()
89 // purpose : constructor
90 //=================================================================================
91 SMESHGUI_ExtrusionDlg::SMESHGUI_ExtrusionDlg (SMESHGUI* theModule)
92 : SMESHGUI_PreviewDlg( theModule ),
93 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
95 mySelectedObject(SMESH::SMESH_IDSource::_nil())
97 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_EDGE")));
98 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_TRIANGLE")));
99 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
100 QPixmap image3 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_NODE")));
103 setAttribute( Qt::WA_DeleteOnClose, true );
104 setWindowTitle(tr("EXTRUSION_ALONG_LINE"));
105 setSizeGripEnabled(true);
107 QVBoxLayout* SMESHGUI_ExtrusionDlgLayout = new QVBoxLayout(this);
108 SMESHGUI_ExtrusionDlgLayout->setSpacing(SPACING);
109 SMESHGUI_ExtrusionDlgLayout->setMargin(MARGIN);
111 /***************************************************************/
112 ConstructorsBox = new QGroupBox(tr("SMESH_EXTRUSION"), this);
113 GroupConstructors = new QButtonGroup(this);
114 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
115 ConstructorsBoxLayout->setSpacing(SPACING);
116 ConstructorsBoxLayout->setMargin(MARGIN);
118 RadioButton0= new QRadioButton(ConstructorsBox);
119 RadioButton0->setIcon(image3);
120 RadioButton1= new QRadioButton(ConstructorsBox);
121 RadioButton1->setIcon(image0);
122 RadioButton2= new QRadioButton(ConstructorsBox);
123 RadioButton2->setIcon(image1);
125 ConstructorsBoxLayout->addWidget(RadioButton0);
126 ConstructorsBoxLayout->addWidget(RadioButton1);
127 ConstructorsBoxLayout->addWidget(RadioButton2);
129 GroupConstructors->addButton(RadioButton0, 0);
130 GroupConstructors->addButton(RadioButton1, 1);
131 GroupConstructors->addButton(RadioButton2, 2);
133 /***************************************************************/
134 GroupButtons = new QGroupBox(this);
135 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
136 GroupButtonsLayout->setSpacing(SPACING);
137 GroupButtonsLayout->setMargin(MARGIN);
139 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
140 buttonOk->setAutoDefault(true);
141 buttonOk->setDefault(true);
142 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
143 buttonApply->setAutoDefault(true);
144 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
145 buttonCancel->setAutoDefault(true);
146 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
147 buttonHelp->setAutoDefault(true);
149 GroupButtonsLayout->addWidget(buttonOk);
150 GroupButtonsLayout->addSpacing(10);
151 GroupButtonsLayout->addWidget(buttonApply);
152 GroupButtonsLayout->addSpacing(10);
153 GroupButtonsLayout->addStretch();
154 GroupButtonsLayout->addWidget(buttonCancel);
155 GroupButtonsLayout->addWidget(buttonHelp);
157 /***************************************************************/
158 GroupArguments = new QGroupBox(tr("EXTRUSION_0D"), this);
159 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
160 GroupArgumentsLayout->setSpacing(SPACING);
161 GroupArgumentsLayout->setMargin(MARGIN);
163 myIdValidator = new SMESHGUI_IdValidator(this);
165 // Controls for elements selection
166 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
168 SelectElementsButton = new QPushButton(GroupArguments);
169 SelectElementsButton->setIcon(image2);
171 LineEditElements = new QLineEdit(GroupArguments);
172 LineEditElements->setValidator(myIdValidator);
173 LineEditElements->setMaxLength(-1);
174 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
175 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
177 // Control for the whole mesh selection
178 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
180 RadioButton3 = new QRadioButton(GroupArguments);
181 RadioButton3->setText( tr("SMESH_EXTRUSION_TO_DISTANCE") );
182 RadioButton4 = new QRadioButton(GroupArguments);
183 RadioButton4->setText( tr("SMESH_EXTRUSION_ALONG_VECTOR") );
185 //Control for the Distance selection
186 TextLabelDistance = new QLabel(tr("SMESH_DISTANCE"), GroupArguments);
188 TextLabelDx = new QLabel(tr("SMESH_X"), GroupArguments);
189 SpinBox_Dx = new SMESHGUI_SpinBox(GroupArguments);
191 TextLabelDy = new QLabel(tr("SMESH_Y"), GroupArguments);
192 SpinBox_Dy = new SMESHGUI_SpinBox(GroupArguments);
194 TextLabelDz = new QLabel(tr("SMESH_Z"), GroupArguments);
195 SpinBox_Dz = new SMESHGUI_SpinBox(GroupArguments);
197 // Controls for vector selection
199 TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupArguments);
201 SelectVectorButton = new QPushButton(GroupArguments);
202 SelectVectorButton->setIcon(image2);
204 TextLabelVx = new QLabel(tr("SMESH_DX"), GroupArguments);
205 SpinBox_Vx = new SMESHGUI_SpinBox(GroupArguments);
207 TextLabelVy = new QLabel(tr("SMESH_DY"), GroupArguments);
208 SpinBox_Vy = new SMESHGUI_SpinBox(GroupArguments);
210 TextLabelVz = new QLabel(tr("SMESH_DZ"), GroupArguments);
211 SpinBox_Vz = new SMESHGUI_SpinBox(GroupArguments);
213 TextLabelDist = new QLabel(tr("SMESH_DISTANCE"), GroupArguments);
214 SpinBox_VDist = new SMESHGUI_SpinBox(GroupArguments);
216 // Controls for nb. steps defining
217 TextLabelNbSteps = new QLabel(tr("SMESH_NUMBEROFSTEPS"), GroupArguments);
218 SpinBox_NbSteps = new SalomeApp_IntSpinBox(GroupArguments);
220 // CheckBox for groups generation
221 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
224 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
226 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
227 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
228 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 5);
229 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 7);
230 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
231 GroupArgumentsLayout->addWidget(RadioButton3, 2, 1, 1, 3);
232 GroupArgumentsLayout->addWidget(RadioButton4, 2, 5, 1, 3);
233 GroupArgumentsLayout->addWidget(TextLabelDistance, 3, 0);
234 GroupArgumentsLayout->addWidget(TextLabelDx, 3, 2);
235 GroupArgumentsLayout->addWidget(SpinBox_Dx, 3, 3);
236 GroupArgumentsLayout->addWidget(TextLabelDy, 3, 4);
237 GroupArgumentsLayout->addWidget(SpinBox_Dy, 3, 5);
238 GroupArgumentsLayout->addWidget(TextLabelDz, 3, 6);
239 GroupArgumentsLayout->addWidget(SpinBox_Dz, 3, 7);
240 GroupArgumentsLayout->addWidget(TextLabelVector, 4, 0);
241 GroupArgumentsLayout->addWidget(SelectVectorButton, 4, 1);
242 GroupArgumentsLayout->addWidget(TextLabelVx, 4, 2);
243 GroupArgumentsLayout->addWidget(SpinBox_Vx, 4, 3);
244 GroupArgumentsLayout->addWidget(TextLabelVy, 4, 4);
245 GroupArgumentsLayout->addWidget(SpinBox_Vy, 4, 5);
246 GroupArgumentsLayout->addWidget(TextLabelVz, 4, 6);
247 GroupArgumentsLayout->addWidget(SpinBox_Vz, 4, 7);
248 GroupArgumentsLayout->addWidget(TextLabelDist, 5, 0);
249 GroupArgumentsLayout->addWidget(SpinBox_VDist, 5, 3);
250 GroupArgumentsLayout->addWidget(TextLabelNbSteps, 6, 0, 1, 3);
251 GroupArgumentsLayout->addWidget(SpinBox_NbSteps, 6, 3);
252 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 7, 0, 1, 8);
253 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 8, 0, 1, 8);
254 GroupArgumentsLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding), 8, 0);
257 /***************************************************************/
258 SMESHGUI_ExtrusionDlgLayout->addWidget(ConstructorsBox);
259 SMESHGUI_ExtrusionDlgLayout->addWidget(GroupArguments);
260 SMESHGUI_ExtrusionDlgLayout->addWidget(GroupButtons);
262 /* Initialisations */
263 SpinBox_Vx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, "length_precision");
264 SpinBox_Vy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, "length_precision");
265 SpinBox_Vz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, "length_precision");
267 SpinBox_Dx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
268 SpinBox_Dy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
269 SpinBox_Dz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
271 SpinBox_NbSteps->setRange(1, 999999);
272 SpinBox_VDist->RangeStepAndValidator(0, COORD_MAX, 10.0, "length_precision");
274 RadioButton0->setChecked(true);
275 RadioButton3->setChecked(true);
276 MakeGroupsCheck->setChecked(true);
278 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
280 mySMESHGUI->SetActiveDialogBox(this);
282 // Costruction of the logical filter for the elements: mesh/sub-mesh/group
283 QList<SUIT_SelectionFilter*> aListOfFilters;
284 aListOfFilters.append(new SMESH_TypeFilter (SMESH::MESH));
285 aListOfFilters.append(new SMESH_TypeFilter (SMESH::SUBMESH_VERTEX));
286 aListOfFilters.append(new SMESH_TypeFilter (SMESH::GROUP_NODE));
287 myMeshOrSubMeshOrGroupFilter0D =
288 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR, /*takeOwnership=*/true);
289 aListOfFilters[0] = new SMESH_TypeFilter (SMESH::MESH);
290 aListOfFilters[1] = new SMESH_TypeFilter (SMESH::SUBMESH_EDGE);
291 aListOfFilters[2] = new SMESH_TypeFilter (SMESH::GROUP_EDGE);
292 myMeshOrSubMeshOrGroupFilter1D =
293 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR, /*takeOwnership=*/true);
294 aListOfFilters[0] = new SMESH_TypeFilter (SMESH::MESH);
295 aListOfFilters[1] = new SMESH_TypeFilter (SMESH::SUBMESH_FACE);
296 aListOfFilters[2] = new SMESH_TypeFilter (SMESH::GROUP_FACE);
297 myMeshOrSubMeshOrGroupFilter2D =
298 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR, /*takeOwnership=*/true);
300 myHelpFileName = "extrusion_page.html";
304 /***************************************************************/
305 // signals and slots connections
306 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
307 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
308 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
309 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
311 connect(RadioButton3, SIGNAL(clicked()), this, SLOT(ClickOnRadio()));
312 connect(RadioButton4, SIGNAL(clicked()), this, SLOT(ClickOnRadio()));
314 // to update state of the Ok & Apply buttons
315 connect(SpinBox_Vx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
316 connect(SpinBox_Vy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
317 connect(SpinBox_Vz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
318 connect(SpinBox_Dx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
319 connect(SpinBox_Dy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
320 connect(SpinBox_Dz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
322 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
323 connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
324 connect(SelectVectorButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
325 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
326 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
327 /* to close dialog if study change */
328 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
329 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
330 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
332 connect(SpinBox_Dx, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
333 connect(SpinBox_Dy, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
334 connect(SpinBox_Dz, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
335 connect(SpinBox_Vx, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
336 connect(SpinBox_Vy, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
337 connect(SpinBox_Vz, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
338 connect(SpinBox_VDist, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
339 connect(SpinBox_NbSteps, SIGNAL(valueChanged(int)), this, SLOT(toDisplaySimulation()));
341 //To Connect preview check box
342 connectPreviewControl();
344 /***************************************************************/
346 ConstructorsClicked(0);
348 SelectionIntoArgument();
351 //=================================================================================
352 // function : ~SMESHGUI_ExtrusionDlg()
353 // purpose : destructor
354 //=================================================================================
355 SMESHGUI_ExtrusionDlg::~SMESHGUI_ExtrusionDlg()
357 if ( myFilterDlg != 0 ) {
358 myFilterDlg->setParent( 0 );
361 if ( myMeshOrSubMeshOrGroupFilter0D ) delete myMeshOrSubMeshOrGroupFilter0D;
362 if ( myMeshOrSubMeshOrGroupFilter1D ) delete myMeshOrSubMeshOrGroupFilter1D;
363 if ( myMeshOrSubMeshOrGroupFilter2D ) delete myMeshOrSubMeshOrGroupFilter2D;
366 //=================================================================================
368 // purpose : initialization
369 //=================================================================================
370 void SMESHGUI_ExtrusionDlg::Init (bool ResetControls)
375 LineEditElements->clear();
379 myMesh = SMESH::SMESH_Mesh::_nil();
382 SpinBox_NbSteps->setValue(1);
383 SpinBox_VDist->setValue(10);
384 SpinBox_Dx->SetValue(0);
385 SpinBox_Dy->SetValue(0);
386 SpinBox_Dz->SetValue(0);
387 SpinBox_Vx->SetValue(0);
388 SpinBox_Vy->SetValue(0);
389 SpinBox_Vz->SetValue(0);
391 CheckBoxMesh->setChecked(false);
393 myPreviewCheckBox->setChecked(false);
394 onDisplaySimulation(false);
400 //=================================================================================
401 // function : CheckIsEnable()
402 // purpose : Check whether the Ok and Apply buttons should be enabled or not
403 //=================================================================================
404 void SMESHGUI_ExtrusionDlg::CheckIsEnable()
406 bool anIsEnable = myNbOkElements > 0 && isValuesValid();
408 buttonOk->setEnabled(anIsEnable);
409 buttonApply->setEnabled(anIsEnable);
412 //=================================================================================
413 // function : isValuesValid()
414 // purpose : Return true in case if values entered into dialog are valid
415 //=================================================================================
416 bool SMESHGUI_ExtrusionDlg::isValuesValid() {
417 double aX, aY, aZ, aModule = 0;
418 if ( RadioButton3->isChecked() ) {
419 aX = SpinBox_Dx->GetValue();
420 aY = SpinBox_Dy->GetValue();
421 aZ = SpinBox_Dz->GetValue();
422 aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
423 } else if ( RadioButton4->isChecked() ) {
424 aX = SpinBox_Vx->GetValue();
425 aY = SpinBox_Vy->GetValue();
426 aZ = SpinBox_Vz->GetValue();
427 aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
429 return aModule > 1.0E-38;
432 //=================================================================================
433 // function : ConstructorsClicked()
434 // purpose : Radio button management
435 //=================================================================================
436 void SMESHGUI_ExtrusionDlg::ConstructorsClicked (int constructorId)
438 disconnect(mySelectionMgr, 0, this, 0);
442 TextLabelElements->setText(tr( constructorId ? "SMESH_ID_ELEMENTS" : "SMESH_ID_NODES"));
444 switch (constructorId) {
447 GroupArguments->setTitle(tr("EXTRUSION_0D"));
448 if (!CheckBoxMesh->isChecked())
450 LineEditElements->clear();
452 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
453 aViewWindow->SetSelectionMode(NodeSelection);
459 GroupArguments->setTitle(tr("EXTRUSION_1D"));
460 if (!CheckBoxMesh->isChecked())
462 LineEditElements->clear();
464 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
465 aViewWindow->SetSelectionMode(EdgeSelection);
471 GroupArguments->setTitle(tr("EXTRUSION_2D"));
472 if (!CheckBoxMesh->isChecked())
474 LineEditElements->clear();
476 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
477 aViewWindow->SetSelectionMode(FaceSelection);
483 myEditCurrentArgument = (QWidget*)LineEditElements;
484 LineEditElements->setFocus();
486 if (CheckBoxMesh->isChecked())
489 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
492 //=================================================================================
493 // function : ConstructorsClicked()
494 // purpose : Radio button management
495 //=================================================================================
496 void SMESHGUI_ExtrusionDlg::ClickOnRadio()
498 if ( RadioButton3->isChecked() ) {
499 TextLabelDistance->show();
507 TextLabelVector->hide();
514 TextLabelDist->hide();
515 SpinBox_VDist->hide();
516 SelectVectorButton->hide();
517 } else if ( RadioButton4->isChecked() ) {
518 TextLabelDistance->hide();
526 TextLabelVector->show();
533 TextLabelDist->show();
534 SpinBox_VDist->show();
535 SelectVectorButton->show();
537 onDisplaySimulation(true);
539 qApp->processEvents();
541 resize( minimumSizeHint() );
544 //=================================================================================
545 // function : ClickOnApply()
546 // purpose : Called when user presses <Apply> button
547 //=================================================================================
548 bool SMESHGUI_ExtrusionDlg::ClickOnApply()
550 if (mySMESHGUI->isActiveStudyLocked())
556 if (myNbOkElements) {
558 SMESH::DirStruct aVector;
559 getExtrusionVector(aVector);
561 QStringList aParameters;
562 if ( RadioButton3->isChecked() ) {
563 aParameters << SpinBox_Dx->text();
564 aParameters << SpinBox_Dy->text();
565 aParameters << SpinBox_Dz->text();
566 } else if ( RadioButton4->isChecked() ) {
567 // only 3 coords in a python dump command :(
568 // aParameters << SpinBox_Vx->text();
569 // aParameters << SpinBox_Vy->text();
570 // aParameters << SpinBox_Vz->text();
571 // aParameters << SpinBox_VDist->text();
574 long aNbSteps = (long)SpinBox_NbSteps->value();
576 aParameters << SpinBox_NbSteps->text();
579 SUIT_OverrideCursor aWaitCursor;
580 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
582 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
584 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) {
585 if( CheckBoxMesh->isChecked() )
586 switch (GetConstructorId() ) {
589 SMESH::ListOfGroups_var groups =
590 aMeshEditor->ExtrusionSweepObject0DMakeGroups(mySelectedObject, aVector, aNbSteps);
595 SMESH::ListOfGroups_var groups =
596 aMeshEditor->ExtrusionSweepObject1DMakeGroups(mySelectedObject, aVector, aNbSteps);
601 SMESH::ListOfGroups_var groups =
602 aMeshEditor->ExtrusionSweepObject2DMakeGroups(mySelectedObject, aVector, aNbSteps);
608 SMESH::ListOfGroups_var groups;
609 if (GetConstructorId() == 0)
610 groups = aMeshEditor->ExtrusionSweepMakeGroups0D(myElementsId.inout(), aVector, aNbSteps);
612 groups = aMeshEditor->ExtrusionSweepMakeGroups(myElementsId.inout(), aVector, aNbSteps);
617 if( CheckBoxMesh->isChecked() )
618 switch( GetConstructorId() ) {
621 aMeshEditor->ExtrusionSweepObject0D(mySelectedObject, aVector, aNbSteps);
626 aMeshEditor->ExtrusionSweepObject1D(mySelectedObject, aVector, aNbSteps);
631 aMeshEditor->ExtrusionSweepObject2D(mySelectedObject, aVector, aNbSteps);
636 if (GetConstructorId() == 0)
637 aMeshEditor->ExtrusionSweep0D(myElementsId.inout(), aVector, aNbSteps);
639 aMeshEditor->ExtrusionSweep(myElementsId.inout(), aVector, aNbSteps);
645 SMESH::Update(myIO, SMESH::eDisplay);
646 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() )
647 mySMESHGUI->updateObjBrowser(true); // new groups may appear
649 ConstructorsClicked(GetConstructorId());
650 mySelectionMgr->clearSelected();
651 mySelectedObject = SMESH::SMESH_IDSource::_nil();
652 SelectionIntoArgument();
654 SMESHGUI::Modified();
659 //=================================================================================
660 // function : ClickOnOk()
661 // purpose : Called when user presses <OK> button
662 //=================================================================================
663 void SMESHGUI_ExtrusionDlg::ClickOnOk()
669 //=================================================================================
670 // function : ClickOnCancel()
671 // purpose : Called when dialog box is closed
672 //=================================================================================
673 void SMESHGUI_ExtrusionDlg::ClickOnCancel()
678 //=================================================================================
679 // function : ClickOnHelp()
681 //=================================================================================
682 void SMESHGUI_ExtrusionDlg::ClickOnHelp()
684 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
686 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
690 platform = "winapplication";
692 platform = "application";
694 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
695 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
696 arg(app->resourceMgr()->stringValue("ExternalBrowser",
698 arg(myHelpFileName));
702 //=================================================================================
703 // function : onTextChange()
705 //=================================================================================
706 void SMESHGUI_ExtrusionDlg::onTextChange (const QString& theNewText)
708 QLineEdit* send = (QLineEdit*)sender();
716 if (send == LineEditElements)
719 // hilight entered elements/nodes
721 if (!myIO.IsNull()) {
722 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
724 if (send == LineEditElements)
726 SMDS_Mesh* aMesh = myActor ? myActor->GetObject()->GetMesh() : 0;
727 SMESH::ElementType SMESHType;
728 SMDSAbs_ElementType SMDSType;
729 switch (GetConstructorId()) {
732 SMESHType = SMESH::NODE;
733 SMDSType = SMDSAbs_Node;
738 SMESHType = SMESH::EDGE;
739 SMDSType = SMDSAbs_Edge;
744 SMESHType = SMESH::FACE;
745 SMDSType = SMDSAbs_Face;
749 myElementsId = new SMESH::long_array;
750 myElementsId->length( aListId.count() );
751 TColStd_MapOfInteger newIndices;
752 for (int i = 0; i < aListId.count(); i++) {
753 int id = aListId[ i ].toInt();
754 bool validId = false;
757 const SMDS_MeshElement * e;
758 if (SMDSType == SMDSAbs_Node)
759 e = aMesh->FindNode( id );
761 e = aMesh->FindElement( id );
762 validId = ( e && e->GetType() == SMDSType );
764 validId = ( myMesh->GetElementType( id, true ) == SMESHType );
767 if ( validId && newIndices.Add( id ))
768 myElementsId[ newIndices.Extent()-1 ] = id;
770 myElementsId->length( myNbOkElements = newIndices.Extent() );
771 mySelector->AddOrRemoveIndex(myIO, newIndices, false);
772 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
773 aViewWindow->highlight( myIO, true, true );
779 onDisplaySimulation(true);
784 //=================================================================================
785 // function : SelectionIntoArgument()
786 // purpose : Called when selection as changed or other case
787 //=================================================================================
788 void SMESHGUI_ExtrusionDlg::SelectionIntoArgument()
792 // return if dialog box is inactive
793 if (!GroupButtons->isEnabled())
797 if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
799 Handle(SALOME_InteractiveObject) resIO = myIO;
803 QString aString = "";
805 if(myEditCurrentArgument == (QWidget*)LineEditElements) {
807 LineEditElements->setText(aString);
813 mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
814 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
818 Handle(SALOME_InteractiveObject) IO = aList.First();
820 if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
821 myMesh = SMESH::GetMeshByIO(IO);
822 if (myMesh->_is_nil())
825 myActor = SMESH::FindActorByObject(myMesh);
828 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
831 // MakeGroups is available if there are groups
832 if ( myMesh->NbGroups() == 0 ) {
833 MakeGroupsCheck->setChecked(false);
834 MakeGroupsCheck->setEnabled(false);
836 MakeGroupsCheck->setEnabled(true);
839 if (CheckBoxMesh->isChecked()) {
840 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
842 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
843 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
847 // get indices of selcted elements
848 TColStd_IndexedMapOfInteger aMapIndex;
849 mySelector->GetIndex(IO,aMapIndex);
850 aNbElements = aMapIndex.Extent();
855 myElementsId = new SMESH::long_array;
856 myElementsId->length( aNbElements );
858 for ( int i = 0; i < aNbElements; ++i )
859 aString += QString(" %1").arg( myElementsId[ i ] = aMapIndex( i+1 ) );
862 myNbOkElements = true;
865 ((QLineEdit*)myEditCurrentArgument)->setText(aString);
868 else if(myEditCurrentArgument == (QWidget*)SpinBox_Vx){
869 TColStd_IndexedMapOfInteger aMapIndex;
870 mySelector->GetIndex(IO,aMapIndex);
871 int aNbElements = aMapIndex.Extent();
872 SMESH::SMESH_Mesh_var aMesh_var = SMESH::GetMeshByIO(IO);
873 SMESH_Actor* anActor = SMESH::FindActorByObject(aMesh_var);
874 SMDS_Mesh* aMesh = anActor ? anActor->GetObject()->GetMesh() : 0;
876 if(aNbElements != 1 || !aMesh)
879 const SMDS_MeshFace* face = dynamic_cast<const SMDS_MeshFace*>(aMesh->FindElement(aMapIndex(aNbElements)));
884 gp_XYZ aNormale = SMESH::getNormale(face);
885 SpinBox_Vx->SetValue(aNormale.X());
886 SpinBox_Vy->SetValue(aNormale.Y());
887 SpinBox_Vz->SetValue(aNormale.Z());
891 onDisplaySimulation(true);
897 //=================================================================================
898 // function : SetEditCurrentArgument()
900 //=================================================================================
901 void SMESHGUI_ExtrusionDlg::SetEditCurrentArgument()
903 QPushButton* send = (QPushButton*)sender();
905 disconnect(mySelectionMgr, 0, this, 0);
906 mySelectionMgr->clearSelected();
907 mySelectionMgr->clearFilters();
909 if (send == SelectElementsButton) {
910 myEditCurrentArgument = (QWidget*)LineEditElements;
911 if (CheckBoxMesh->isChecked())
913 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
914 aViewWindow->SetSelectionMode(ActorSelection);
915 switch( GetConstructorId() ) {
916 case 0: mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter0D); break;
917 case 1: mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter1D); break;
918 case 2: mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter2D); break;
923 int aConstructorId = GetConstructorId();
924 switch(aConstructorId) {
927 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
928 aViewWindow->SetSelectionMode(NodeSelection);
933 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
934 aViewWindow->SetSelectionMode(EdgeSelection);
939 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
940 aViewWindow->SetSelectionMode(FaceSelection);
946 else if (send == SelectVectorButton){
947 myEditCurrentArgument = (QWidget*)SpinBox_Vx;
948 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
949 aViewWindow->SetSelectionMode(FaceSelection);
952 myEditCurrentArgument->setFocus();
953 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
954 SelectionIntoArgument();
957 //=================================================================================
958 // function : DeactivateActiveDialog()
959 // purpose : Deactivates this dialog
960 //=================================================================================
961 void SMESHGUI_ExtrusionDlg::DeactivateActiveDialog()
963 if (ConstructorsBox->isEnabled()) {
964 ConstructorsBox->setEnabled(false);
965 GroupArguments->setEnabled(false);
966 GroupButtons->setEnabled(false);
967 mySMESHGUI->ResetState();
968 mySMESHGUI->SetActiveDialogBox(0);
972 //=================================================================================
973 // function : ActivateThisDialog()
974 // purpose : Activates this dialog
975 //=================================================================================
976 void SMESHGUI_ExtrusionDlg::ActivateThisDialog()
978 // Emit a signal to deactivate the active dialog
979 mySMESHGUI->EmitSignalDeactivateDialog();
980 ConstructorsBox->setEnabled(true);
981 GroupArguments->setEnabled(true);
982 GroupButtons->setEnabled(true);
984 mySMESHGUI->SetActiveDialogBox(this);
986 ConstructorsClicked(GetConstructorId());
987 SelectionIntoArgument();
990 //=================================================================================
991 // function : enterEvent()
992 // purpose : Mouse enter event
993 //=================================================================================
994 void SMESHGUI_ExtrusionDlg::enterEvent (QEvent*)
996 if (!ConstructorsBox->isEnabled())
997 ActivateThisDialog();
1000 //=================================================================================
1001 // function : closeEvent()
1003 //=================================================================================
1004 void SMESHGUI_ExtrusionDlg::closeEvent( QCloseEvent* )
1006 /* same than click on cancel button */
1007 disconnect(mySelectionMgr, 0, this, 0);
1008 mySelectionMgr->clearFilters();
1009 //mySelectionMgr->clearSelected();
1010 if (SMESH::GetCurrentVtkView()) {
1011 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1012 SMESH::SetPointRepresentation(false);
1013 SMESH::SetPickable();
1015 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1016 aViewWindow->SetSelectionMode(ActorSelection);
1017 mySMESHGUI->ResetState();
1020 void SMESHGUI_ExtrusionDlg::reject()
1026 //=================================================================================
1027 // function : onSelectMesh()
1029 //=================================================================================
1030 void SMESHGUI_ExtrusionDlg::onSelectMesh (bool toSelectMesh)
1033 myIDs = LineEditElements->text();
1034 TextLabelElements->setText(tr("SMESH_NAME"));
1037 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
1039 myFilterBtn->setEnabled(!toSelectMesh);
1041 if (myEditCurrentArgument != LineEditElements) {
1042 LineEditElements->clear();
1046 mySelectionMgr->clearFilters();
1050 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1051 aViewWindow->SetSelectionMode(ActorSelection);
1052 switch( GetConstructorId() ) {
1053 case 0: mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter0D); break;
1054 case 1: mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter1D); break;
1055 case 2: mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter2D); break;
1057 LineEditElements->setReadOnly(true);
1058 LineEditElements->setValidator(0);
1062 int aConstructorId = GetConstructorId();
1063 switch(aConstructorId) {
1066 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1067 aViewWindow->SetSelectionMode(NodeSelection);
1072 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1073 aViewWindow->SetSelectionMode(EdgeSelection);
1078 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1079 aViewWindow->SetSelectionMode(FaceSelection);
1083 LineEditElements->setReadOnly(false);
1084 LineEditElements->setValidator(myIdValidator);
1085 onTextChange(LineEditElements->text());
1088 SelectionIntoArgument();
1091 LineEditElements->setText( myIDs );
1094 //=================================================================================
1095 // function : GetConstructorId()
1097 //=================================================================================
1098 int SMESHGUI_ExtrusionDlg::GetConstructorId()
1100 return GroupConstructors->checkedId();
1103 //=================================================================================
1104 // function : keyPressEvent()
1106 //=================================================================================
1107 void SMESHGUI_ExtrusionDlg::keyPressEvent( QKeyEvent* e )
1109 QDialog::keyPressEvent( e );
1110 if ( e->isAccepted() )
1113 if ( e->key() == Qt::Key_F1 ) {
1119 //=================================================================================
1120 // function : setFilters()
1121 // purpose : SLOT. Called when "Filter" button pressed.
1122 //=================================================================================
1123 void SMESHGUI_ExtrusionDlg::setFilters()
1125 if(myMesh->_is_nil()) {
1126 SUIT_MessageBox::critical(this,
1128 tr("NO_MESH_SELECTED"));
1134 types.append( SMESH::NODE );
1135 types.append( SMESH::EDGE );
1136 types.append( SMESH::FACE );
1137 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, types );
1139 switch( GetConstructorId() ){
1142 myFilterDlg->Init( SMESH::NODE );
1147 myFilterDlg->Init( SMESH::EDGE );
1152 myFilterDlg->Init( SMESH::FACE );
1158 myFilterDlg->SetSelection();
1159 myFilterDlg->SetMesh( myMesh );
1160 myFilterDlg->SetSourceWg( LineEditElements );
1162 myFilterDlg->show();
1165 //=================================================================================
1166 // function : isValid
1168 //=================================================================================
1169 bool SMESHGUI_ExtrusionDlg::isValid()
1173 if ( RadioButton3->isChecked() ) {
1174 ok = SpinBox_Dx->isValid( msg, true ) && ok;
1175 ok = SpinBox_Dy->isValid( msg, true ) && ok;
1176 ok = SpinBox_Dz->isValid( msg, true ) && ok;
1177 } else if ( RadioButton4->isChecked() ) {
1178 ok = SpinBox_Vx->isValid( msg, true ) && ok;
1179 ok = SpinBox_Vy->isValid( msg, true ) && ok;
1180 ok = SpinBox_Vz->isValid( msg, true ) && ok;
1181 ok = SpinBox_VDist->isValid( msg, true ) && ok;
1183 ok = SpinBox_NbSteps->isValid( msg, true ) && ok;
1186 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1187 if ( !msg.isEmpty() )
1189 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1195 //=================================================================================
1196 // function : onDisplaySimulation
1197 // purpose : Show/Hide preview
1198 //=================================================================================
1199 void SMESHGUI_ExtrusionDlg::onDisplaySimulation( bool toDisplayPreview ) {
1200 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1201 if (myNbOkElements && isValid() && isValuesValid()) {
1203 SMESH::DirStruct aVector;
1204 getExtrusionVector(aVector);
1206 //Get Number of the steps
1207 long aNbSteps = (long)SpinBox_NbSteps->value();
1210 SUIT_OverrideCursor aWaitCursor;
1211 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
1212 if( CheckBoxMesh->isChecked() ) {
1213 switch (GetConstructorId()) {
1216 aMeshEditor->ExtrusionSweepObject0D(mySelectedObject, aVector, aNbSteps);
1221 aMeshEditor->ExtrusionSweepObject1D(mySelectedObject, aVector, aNbSteps);
1226 aMeshEditor->ExtrusionSweepObject2D(mySelectedObject, aVector, aNbSteps);
1232 if(GetConstructorId() == 0)
1233 aMeshEditor->ExtrusionSweep0D(myElementsId.inout(), aVector, aNbSteps);
1235 aMeshEditor->ExtrusionSweep(myElementsId.inout(), aVector, aNbSteps);
1237 SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
1238 mySimulation->SetData(aMeshPreviewStruct._retn());
1250 //=================================================================================
1251 // function : getExtrusionVector()
1252 // purpose : get direction of the extrusion
1253 //=================================================================================
1254 void SMESHGUI_ExtrusionDlg::getExtrusionVector(SMESH::DirStruct& aVector) {
1255 if ( RadioButton3->isChecked() ) {
1256 aVector.PS.x = SpinBox_Dx->GetValue();
1257 aVector.PS.y = SpinBox_Dy->GetValue();
1258 aVector.PS.z = SpinBox_Dz->GetValue();
1259 } else if ( RadioButton4->isChecked() ) {
1260 gp_XYZ aNormale(SpinBox_Vx->GetValue(),
1261 SpinBox_Vy->GetValue(),
1262 SpinBox_Vz->GetValue());
1265 aNormale /= aNormale.Modulus();
1266 double aVDist = (double)SpinBox_VDist->value();
1268 aVector.PS.x = aNormale.X()*aVDist;
1269 aVector.PS.y = aNormale.Y()*aVDist;
1270 aVector.PS.z = aNormale.Z()*aVDist;