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 ) ),
94 myEditCurrentArgument(0),
96 mySelectedObject(SMESH::SMESH_IDSource::_nil())
98 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_EDGE")));
99 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_TRIANGLE")));
100 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
101 QPixmap image3 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_NODE")));
104 setAttribute( Qt::WA_DeleteOnClose, true );
105 setWindowTitle(tr("EXTRUSION_ALONG_LINE"));
106 setSizeGripEnabled(true);
108 QVBoxLayout* SMESHGUI_ExtrusionDlgLayout = new QVBoxLayout(this);
109 SMESHGUI_ExtrusionDlgLayout->setSpacing(SPACING);
110 SMESHGUI_ExtrusionDlgLayout->setMargin(MARGIN);
112 /***************************************************************/
113 ConstructorsBox = new QGroupBox(tr("SMESH_EXTRUSION"), this);
114 GroupConstructors = new QButtonGroup(this);
115 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
116 ConstructorsBoxLayout->setSpacing(SPACING);
117 ConstructorsBoxLayout->setMargin(MARGIN);
119 RadioButton0= new QRadioButton(ConstructorsBox);
120 RadioButton0->setIcon(image3);
121 RadioButton1= new QRadioButton(ConstructorsBox);
122 RadioButton1->setIcon(image0);
123 RadioButton2= new QRadioButton(ConstructorsBox);
124 RadioButton2->setIcon(image1);
126 ConstructorsBoxLayout->addWidget(RadioButton0);
127 ConstructorsBoxLayout->addWidget(RadioButton1);
128 ConstructorsBoxLayout->addWidget(RadioButton2);
130 GroupConstructors->addButton(RadioButton0, 0);
131 GroupConstructors->addButton(RadioButton1, 1);
132 GroupConstructors->addButton(RadioButton2, 2);
134 /***************************************************************/
135 GroupButtons = new QGroupBox(this);
136 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
137 GroupButtonsLayout->setSpacing(SPACING);
138 GroupButtonsLayout->setMargin(MARGIN);
140 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
141 buttonOk->setAutoDefault(true);
142 buttonOk->setDefault(true);
143 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
144 buttonApply->setAutoDefault(true);
145 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
146 buttonCancel->setAutoDefault(true);
147 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
148 buttonHelp->setAutoDefault(true);
150 GroupButtonsLayout->addWidget(buttonOk);
151 GroupButtonsLayout->addSpacing(10);
152 GroupButtonsLayout->addWidget(buttonApply);
153 GroupButtonsLayout->addSpacing(10);
154 GroupButtonsLayout->addStretch();
155 GroupButtonsLayout->addWidget(buttonCancel);
156 GroupButtonsLayout->addWidget(buttonHelp);
158 /***************************************************************/
159 GroupArguments = new QGroupBox(tr("EXTRUSION_0D"), this);
160 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
161 GroupArgumentsLayout->setSpacing(SPACING);
162 GroupArgumentsLayout->setMargin(MARGIN);
164 myIdValidator = new SMESHGUI_IdValidator(this);
166 // Controls for elements selection
167 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
169 SelectElementsButton = new QPushButton(GroupArguments);
170 SelectElementsButton->setIcon(image2);
172 LineEditElements = new QLineEdit(GroupArguments);
173 LineEditElements->setValidator(myIdValidator);
174 LineEditElements->setMaxLength(-1);
175 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
176 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
178 // Control for the whole mesh selection
179 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
181 RadioButton3 = new QRadioButton(GroupArguments);
182 RadioButton3->setText( tr("SMESH_EXTRUSION_TO_DISTANCE") );
183 RadioButton4 = new QRadioButton(GroupArguments);
184 RadioButton4->setText( tr("SMESH_EXTRUSION_ALONG_VECTOR") );
186 //Control for the Distance selection
187 TextLabelDistance = new QLabel(tr("SMESH_DISTANCE"), GroupArguments);
189 TextLabelDx = new QLabel(tr("SMESH_X"), GroupArguments);
190 SpinBox_Dx = new SMESHGUI_SpinBox(GroupArguments);
192 TextLabelDy = new QLabel(tr("SMESH_Y"), GroupArguments);
193 SpinBox_Dy = new SMESHGUI_SpinBox(GroupArguments);
195 TextLabelDz = new QLabel(tr("SMESH_Z"), GroupArguments);
196 SpinBox_Dz = new SMESHGUI_SpinBox(GroupArguments);
198 // Controls for vector selection
200 TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupArguments);
202 SelectVectorButton = new QPushButton(GroupArguments);
203 SelectVectorButton->setIcon(image2);
205 TextLabelVx = new QLabel(tr("SMESH_DX"), GroupArguments);
206 SpinBox_Vx = new SMESHGUI_SpinBox(GroupArguments);
208 TextLabelVy = new QLabel(tr("SMESH_DY"), GroupArguments);
209 SpinBox_Vy = new SMESHGUI_SpinBox(GroupArguments);
211 TextLabelVz = new QLabel(tr("SMESH_DZ"), GroupArguments);
212 SpinBox_Vz = new SMESHGUI_SpinBox(GroupArguments);
214 TextLabelDist = new QLabel(tr("SMESH_DISTANCE"), GroupArguments);
215 SpinBox_VDist = new SMESHGUI_SpinBox(GroupArguments);
217 // Controls for nb. steps defining
218 TextLabelNbSteps = new QLabel(tr("SMESH_NUMBEROFSTEPS"), GroupArguments);
219 SpinBox_NbSteps = new SalomeApp_IntSpinBox(GroupArguments);
221 // CheckBox for groups generation
222 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
225 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
227 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
228 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
229 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 5);
230 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 7);
231 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
232 GroupArgumentsLayout->addWidget(RadioButton3, 2, 1, 1, 3);
233 GroupArgumentsLayout->addWidget(RadioButton4, 2, 5, 1, 3);
234 GroupArgumentsLayout->addWidget(TextLabelDistance, 3, 0);
235 GroupArgumentsLayout->addWidget(TextLabelDx, 3, 2);
236 GroupArgumentsLayout->addWidget(SpinBox_Dx, 3, 3);
237 GroupArgumentsLayout->addWidget(TextLabelDy, 3, 4);
238 GroupArgumentsLayout->addWidget(SpinBox_Dy, 3, 5);
239 GroupArgumentsLayout->addWidget(TextLabelDz, 3, 6);
240 GroupArgumentsLayout->addWidget(SpinBox_Dz, 3, 7);
241 GroupArgumentsLayout->addWidget(TextLabelVector, 4, 0);
242 GroupArgumentsLayout->addWidget(SelectVectorButton, 4, 1);
243 GroupArgumentsLayout->addWidget(TextLabelVx, 4, 2);
244 GroupArgumentsLayout->addWidget(SpinBox_Vx, 4, 3);
245 GroupArgumentsLayout->addWidget(TextLabelVy, 4, 4);
246 GroupArgumentsLayout->addWidget(SpinBox_Vy, 4, 5);
247 GroupArgumentsLayout->addWidget(TextLabelVz, 4, 6);
248 GroupArgumentsLayout->addWidget(SpinBox_Vz, 4, 7);
249 GroupArgumentsLayout->addWidget(TextLabelDist, 5, 0);
250 GroupArgumentsLayout->addWidget(SpinBox_VDist, 5, 3);
251 GroupArgumentsLayout->addWidget(TextLabelNbSteps, 6, 0, 1, 3);
252 GroupArgumentsLayout->addWidget(SpinBox_NbSteps, 6, 3);
253 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 7, 0, 1, 8);
254 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 8, 0, 1, 8);
255 GroupArgumentsLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding), 8, 0);
258 /***************************************************************/
259 SMESHGUI_ExtrusionDlgLayout->addWidget(ConstructorsBox);
260 SMESHGUI_ExtrusionDlgLayout->addWidget(GroupArguments);
261 SMESHGUI_ExtrusionDlgLayout->addWidget(GroupButtons);
263 /* Initialisations */
264 SpinBox_Vx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, "length_precision");
265 SpinBox_Vy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, "length_precision");
266 SpinBox_Vz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, "length_precision");
268 SpinBox_Dx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
269 SpinBox_Dy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
270 SpinBox_Dz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
272 SpinBox_NbSteps->setRange(1, 999999);
273 SpinBox_VDist->RangeStepAndValidator(0, COORD_MAX, 10.0, "length_precision");
275 RadioButton0->setChecked(true);
276 RadioButton3->setChecked(true);
277 MakeGroupsCheck->setChecked(true);
279 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
281 mySMESHGUI->SetActiveDialogBox(this);
283 // Costruction of the logical filter for the elements: mesh/sub-mesh/group
284 QList<SUIT_SelectionFilter*> aListOfFilters;
285 aListOfFilters.append(new SMESH_TypeFilter (SMESH::MESH));
286 aListOfFilters.append(new SMESH_TypeFilter (SMESH::SUBMESH_VERTEX));
287 aListOfFilters.append(new SMESH_TypeFilter (SMESH::GROUP_NODE));
288 myMeshOrSubMeshOrGroupFilter0D =
289 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR, /*takeOwnership=*/true);
290 aListOfFilters[0] = new SMESH_TypeFilter (SMESH::MESH);
291 aListOfFilters[1] = new SMESH_TypeFilter (SMESH::SUBMESH_EDGE);
292 aListOfFilters[2] = new SMESH_TypeFilter (SMESH::GROUP_EDGE);
293 myMeshOrSubMeshOrGroupFilter1D =
294 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR, /*takeOwnership=*/true);
295 aListOfFilters[0] = new SMESH_TypeFilter (SMESH::MESH);
296 aListOfFilters[1] = new SMESH_TypeFilter (SMESH::SUBMESH_FACE);
297 aListOfFilters[2] = new SMESH_TypeFilter (SMESH::GROUP_FACE);
298 myMeshOrSubMeshOrGroupFilter2D =
299 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR, /*takeOwnership=*/true);
301 myHelpFileName = "extrusion_page.html";
305 /***************************************************************/
306 // signals and slots connections
307 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
308 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
309 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
310 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
312 connect(RadioButton3, SIGNAL(clicked()), this, SLOT(ClickOnRadio()));
313 connect(RadioButton4, SIGNAL(clicked()), this, SLOT(ClickOnRadio()));
315 // to update state of the Ok & Apply buttons
316 connect(SpinBox_Vx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
317 connect(SpinBox_Vy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
318 connect(SpinBox_Vz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
319 connect(SpinBox_Dx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
320 connect(SpinBox_Dy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
321 connect(SpinBox_Dz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
323 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
324 connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
325 connect(SelectVectorButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
326 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
327 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
328 /* to close dialog if study change */
329 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
330 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
331 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
333 connect(SpinBox_Dx, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
334 connect(SpinBox_Dy, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
335 connect(SpinBox_Dz, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
336 connect(SpinBox_Vx, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
337 connect(SpinBox_Vy, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
338 connect(SpinBox_Vz, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
339 connect(SpinBox_VDist, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
340 connect(SpinBox_NbSteps, SIGNAL(valueChanged(int)), this, SLOT(toDisplaySimulation()));
342 //To Connect preview check box
343 connectPreviewControl();
345 /***************************************************************/
347 ConstructorsClicked(0);
349 SelectionIntoArgument();
352 //=================================================================================
353 // function : ~SMESHGUI_ExtrusionDlg()
354 // purpose : destructor
355 //=================================================================================
356 SMESHGUI_ExtrusionDlg::~SMESHGUI_ExtrusionDlg()
358 if ( myFilterDlg != 0 ) {
359 myFilterDlg->setParent( 0 );
362 if ( myMeshOrSubMeshOrGroupFilter0D ) delete myMeshOrSubMeshOrGroupFilter0D;
363 if ( myMeshOrSubMeshOrGroupFilter1D ) delete myMeshOrSubMeshOrGroupFilter1D;
364 if ( myMeshOrSubMeshOrGroupFilter2D ) delete myMeshOrSubMeshOrGroupFilter2D;
367 //=================================================================================
369 // purpose : initialization
370 //=================================================================================
371 void SMESHGUI_ExtrusionDlg::Init (bool ResetControls)
376 LineEditElements->clear();
380 myMesh = SMESH::SMESH_Mesh::_nil();
383 SpinBox_NbSteps->setValue(1);
384 SpinBox_VDist->setValue(10);
385 SpinBox_Dx->SetValue(0);
386 SpinBox_Dy->SetValue(0);
387 SpinBox_Dz->SetValue(0);
388 SpinBox_Vx->SetValue(0);
389 SpinBox_Vy->SetValue(0);
390 SpinBox_Vz->SetValue(0);
392 CheckBoxMesh->setChecked(false);
394 myPreviewCheckBox->setChecked(false);
395 onDisplaySimulation(false);
401 //=================================================================================
402 // function : CheckIsEnable()
403 // purpose : Check whether the Ok and Apply buttons should be enabled or not
404 //=================================================================================
405 void SMESHGUI_ExtrusionDlg::CheckIsEnable()
407 bool anIsEnable = myNbOkElements > 0 && isValuesValid();
409 buttonOk->setEnabled(anIsEnable);
410 buttonApply->setEnabled(anIsEnable);
413 //=================================================================================
414 // function : isValuesValid()
415 // purpose : Return true in case if values entered into dialog are valid
416 //=================================================================================
417 bool SMESHGUI_ExtrusionDlg::isValuesValid() {
418 double aX, aY, aZ, aModule = 0;
419 if ( RadioButton3->isChecked() ) {
420 aX = SpinBox_Dx->GetValue();
421 aY = SpinBox_Dy->GetValue();
422 aZ = SpinBox_Dz->GetValue();
423 aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
424 } else if ( RadioButton4->isChecked() ) {
425 aX = SpinBox_Vx->GetValue();
426 aY = SpinBox_Vy->GetValue();
427 aZ = SpinBox_Vz->GetValue();
428 aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
430 return aModule > 1.0E-38;
433 //=================================================================================
434 // function : ConstructorsClicked()
435 // purpose : Radio button management
436 //=================================================================================
437 void SMESHGUI_ExtrusionDlg::ConstructorsClicked (int constructorId)
439 disconnect(mySelectionMgr, 0, this, 0);
443 TextLabelElements->setText(tr( constructorId ? "SMESH_ID_ELEMENTS" : "SMESH_ID_NODES"));
445 switch (constructorId) {
448 GroupArguments->setTitle(tr("EXTRUSION_0D"));
449 if (!CheckBoxMesh->isChecked())
451 LineEditElements->clear();
453 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
454 aViewWindow->SetSelectionMode(NodeSelection);
460 GroupArguments->setTitle(tr("EXTRUSION_1D"));
461 if (!CheckBoxMesh->isChecked())
463 LineEditElements->clear();
465 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
466 aViewWindow->SetSelectionMode(EdgeSelection);
472 GroupArguments->setTitle(tr("EXTRUSION_2D"));
473 if (!CheckBoxMesh->isChecked())
475 LineEditElements->clear();
477 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
478 aViewWindow->SetSelectionMode(FaceSelection);
484 myEditCurrentArgument = (QWidget*)LineEditElements;
485 LineEditElements->setFocus();
487 if (CheckBoxMesh->isChecked())
490 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
493 //=================================================================================
494 // function : ConstructorsClicked()
495 // purpose : Radio button management
496 //=================================================================================
497 void SMESHGUI_ExtrusionDlg::ClickOnRadio()
499 if ( RadioButton3->isChecked() ) {
500 TextLabelDistance->show();
508 TextLabelVector->hide();
515 TextLabelDist->hide();
516 SpinBox_VDist->hide();
517 SelectVectorButton->hide();
518 } else if ( RadioButton4->isChecked() ) {
519 TextLabelDistance->hide();
527 TextLabelVector->show();
534 TextLabelDist->show();
535 SpinBox_VDist->show();
536 SelectVectorButton->show();
538 onDisplaySimulation(true);
540 qApp->processEvents();
542 resize( minimumSizeHint() );
545 //=================================================================================
546 // function : ClickOnApply()
547 // purpose : Called when user presses <Apply> button
548 //=================================================================================
549 bool SMESHGUI_ExtrusionDlg::ClickOnApply()
551 if (mySMESHGUI->isActiveStudyLocked())
557 if (myNbOkElements) {
559 SMESH::DirStruct aVector;
560 getExtrusionVector(aVector);
562 QStringList aParameters;
563 if ( RadioButton3->isChecked() ) {
564 aParameters << SpinBox_Dx->text();
565 aParameters << SpinBox_Dy->text();
566 aParameters << SpinBox_Dz->text();
567 } else if ( RadioButton4->isChecked() ) {
568 // only 3 coords in a python dump command :(
569 // aParameters << SpinBox_Vx->text();
570 // aParameters << SpinBox_Vy->text();
571 // aParameters << SpinBox_Vz->text();
572 // aParameters << SpinBox_VDist->text();
575 long aNbSteps = (long)SpinBox_NbSteps->value();
577 aParameters << SpinBox_NbSteps->text();
580 SUIT_OverrideCursor aWaitCursor;
581 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
583 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
585 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) {
586 if( CheckBoxMesh->isChecked() )
587 switch (GetConstructorId() ) {
590 SMESH::ListOfGroups_var groups =
591 aMeshEditor->ExtrusionSweepObject0DMakeGroups(mySelectedObject, aVector, aNbSteps);
596 SMESH::ListOfGroups_var groups =
597 aMeshEditor->ExtrusionSweepObject1DMakeGroups(mySelectedObject, aVector, aNbSteps);
602 SMESH::ListOfGroups_var groups =
603 aMeshEditor->ExtrusionSweepObject2DMakeGroups(mySelectedObject, aVector, aNbSteps);
609 SMESH::ListOfGroups_var groups;
610 if (GetConstructorId() == 0)
611 groups = aMeshEditor->ExtrusionSweepMakeGroups0D(myElementsId.inout(), aVector, aNbSteps);
613 groups = aMeshEditor->ExtrusionSweepMakeGroups(myElementsId.inout(), aVector, aNbSteps);
618 if( CheckBoxMesh->isChecked() )
619 switch( GetConstructorId() ) {
622 aMeshEditor->ExtrusionSweepObject0D(mySelectedObject, aVector, aNbSteps);
627 aMeshEditor->ExtrusionSweepObject1D(mySelectedObject, aVector, aNbSteps);
632 aMeshEditor->ExtrusionSweepObject2D(mySelectedObject, aVector, aNbSteps);
637 if (GetConstructorId() == 0)
638 aMeshEditor->ExtrusionSweep0D(myElementsId.inout(), aVector, aNbSteps);
640 aMeshEditor->ExtrusionSweep(myElementsId.inout(), aVector, aNbSteps);
646 SMESH::Update(myIO, SMESH::eDisplay);
647 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() )
648 mySMESHGUI->updateObjBrowser(true); // new groups may appear
650 ConstructorsClicked(GetConstructorId());
651 mySelectionMgr->clearSelected();
652 mySelectedObject = SMESH::SMESH_IDSource::_nil();
653 SelectionIntoArgument();
655 SMESHGUI::Modified();
660 //=================================================================================
661 // function : ClickOnOk()
662 // purpose : Called when user presses <OK> button
663 //=================================================================================
664 void SMESHGUI_ExtrusionDlg::ClickOnOk()
670 //=================================================================================
671 // function : ClickOnCancel()
672 // purpose : Called when dialog box is closed
673 //=================================================================================
674 void SMESHGUI_ExtrusionDlg::ClickOnCancel()
679 //=================================================================================
680 // function : ClickOnHelp()
682 //=================================================================================
683 void SMESHGUI_ExtrusionDlg::ClickOnHelp()
685 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
687 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
691 platform = "winapplication";
693 platform = "application";
695 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
696 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
697 arg(app->resourceMgr()->stringValue("ExternalBrowser",
699 arg(myHelpFileName));
703 //=================================================================================
704 // function : onTextChange()
706 //=================================================================================
707 void SMESHGUI_ExtrusionDlg::onTextChange (const QString& theNewText)
709 QLineEdit* send = (QLineEdit*)sender();
717 if (send == LineEditElements)
720 // hilight entered elements/nodes
722 if (!myIO.IsNull()) {
723 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
725 if (send == LineEditElements)
727 SMDS_Mesh* aMesh = myActor ? myActor->GetObject()->GetMesh() : 0;
728 SMESH::ElementType SMESHType;
729 SMDSAbs_ElementType SMDSType;
730 switch (GetConstructorId()) {
733 SMESHType = SMESH::NODE;
734 SMDSType = SMDSAbs_Node;
739 SMESHType = SMESH::EDGE;
740 SMDSType = SMDSAbs_Edge;
745 SMESHType = SMESH::FACE;
746 SMDSType = SMDSAbs_Face;
750 myElementsId = new SMESH::long_array;
751 myElementsId->length( aListId.count() );
752 TColStd_MapOfInteger newIndices;
753 for (int i = 0; i < aListId.count(); i++) {
754 int id = aListId[ i ].toInt();
755 bool validId = false;
758 const SMDS_MeshElement * e;
759 if (SMDSType == SMDSAbs_Node)
760 e = aMesh->FindNode( id );
762 e = aMesh->FindElement( id );
763 validId = ( e && e->GetType() == SMDSType );
765 validId = ( myMesh->GetElementType( id, true ) == SMESHType );
768 if ( validId && newIndices.Add( id ))
769 myElementsId[ newIndices.Extent()-1 ] = id;
771 myElementsId->length( myNbOkElements = newIndices.Extent() );
772 mySelector->AddOrRemoveIndex(myIO, newIndices, false);
773 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
774 aViewWindow->highlight( myIO, true, true );
780 onDisplaySimulation(true);
785 //=================================================================================
786 // function : SelectionIntoArgument()
787 // purpose : Called when selection as changed or other case
788 //=================================================================================
789 void SMESHGUI_ExtrusionDlg::SelectionIntoArgument()
793 // return if dialog box is inactive
794 if (!GroupButtons->isEnabled())
798 if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
800 Handle(SALOME_InteractiveObject) resIO = myIO;
804 QString aString = "";
806 if(myEditCurrentArgument == (QWidget*)LineEditElements) {
808 LineEditElements->setText(aString);
814 mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
815 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
819 Handle(SALOME_InteractiveObject) IO = aList.First();
821 if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
822 myMesh = SMESH::GetMeshByIO(IO);
823 if (myMesh->_is_nil())
826 myActor = SMESH::FindActorByObject(myMesh);
829 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
832 // MakeGroups is available if there are groups
833 if ( myMesh->NbGroups() == 0 ) {
834 MakeGroupsCheck->setChecked(false);
835 MakeGroupsCheck->setEnabled(false);
837 MakeGroupsCheck->setEnabled(true);
840 if (CheckBoxMesh->isChecked()) {
841 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
843 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
844 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
848 // get indices of selcted elements
849 TColStd_IndexedMapOfInteger aMapIndex;
850 mySelector->GetIndex(IO,aMapIndex);
851 aNbElements = aMapIndex.Extent();
856 myElementsId = new SMESH::long_array;
857 myElementsId->length( aNbElements );
859 for ( int i = 0; i < aNbElements; ++i )
860 aString += QString(" %1").arg( myElementsId[ i ] = aMapIndex( i+1 ) );
863 myNbOkElements = true;
866 ((QLineEdit*)myEditCurrentArgument)->setText(aString);
869 else if(myEditCurrentArgument == (QWidget*)SpinBox_Vx){
870 TColStd_IndexedMapOfInteger aMapIndex;
871 mySelector->GetIndex(IO,aMapIndex);
872 int aNbElements = aMapIndex.Extent();
873 SMESH::SMESH_Mesh_var aMesh_var = SMESH::GetMeshByIO(IO);
874 SMESH_Actor* anActor = SMESH::FindActorByObject(aMesh_var);
875 SMDS_Mesh* aMesh = anActor ? anActor->GetObject()->GetMesh() : 0;
877 if(aNbElements != 1 || !aMesh)
880 const SMDS_MeshFace* face = dynamic_cast<const SMDS_MeshFace*>(aMesh->FindElement(aMapIndex(aNbElements)));
885 gp_XYZ aNormale = SMESH::getNormale(face);
886 SpinBox_Vx->SetValue(aNormale.X());
887 SpinBox_Vy->SetValue(aNormale.Y());
888 SpinBox_Vz->SetValue(aNormale.Z());
892 onDisplaySimulation(true);
898 //=================================================================================
899 // function : SetEditCurrentArgument()
901 //=================================================================================
902 void SMESHGUI_ExtrusionDlg::SetEditCurrentArgument()
904 QPushButton* send = (QPushButton*)sender();
906 disconnect(mySelectionMgr, 0, this, 0);
907 mySelectionMgr->clearSelected();
908 mySelectionMgr->clearFilters();
910 if (send == SelectElementsButton) {
911 myEditCurrentArgument = (QWidget*)LineEditElements;
912 if (CheckBoxMesh->isChecked())
914 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
915 aViewWindow->SetSelectionMode(ActorSelection);
916 switch( GetConstructorId() ) {
917 case 0: mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter0D); break;
918 case 1: mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter1D); break;
919 case 2: mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter2D); break;
924 int aConstructorId = GetConstructorId();
925 switch(aConstructorId) {
928 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
929 aViewWindow->SetSelectionMode(NodeSelection);
934 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
935 aViewWindow->SetSelectionMode(EdgeSelection);
940 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
941 aViewWindow->SetSelectionMode(FaceSelection);
947 else if (send == SelectVectorButton){
948 myEditCurrentArgument = (QWidget*)SpinBox_Vx;
949 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
950 aViewWindow->SetSelectionMode(FaceSelection);
953 myEditCurrentArgument->setFocus();
954 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
955 SelectionIntoArgument();
958 //=================================================================================
959 // function : DeactivateActiveDialog()
960 // purpose : Deactivates this dialog
961 //=================================================================================
962 void SMESHGUI_ExtrusionDlg::DeactivateActiveDialog()
964 if (ConstructorsBox->isEnabled()) {
965 ConstructorsBox->setEnabled(false);
966 GroupArguments->setEnabled(false);
967 GroupButtons->setEnabled(false);
968 mySMESHGUI->ResetState();
969 mySMESHGUI->SetActiveDialogBox(0);
973 //=================================================================================
974 // function : ActivateThisDialog()
975 // purpose : Activates this dialog
976 //=================================================================================
977 void SMESHGUI_ExtrusionDlg::ActivateThisDialog()
979 // Emit a signal to deactivate the active dialog
980 mySMESHGUI->EmitSignalDeactivateDialog();
981 ConstructorsBox->setEnabled(true);
982 GroupArguments->setEnabled(true);
983 GroupButtons->setEnabled(true);
985 mySMESHGUI->SetActiveDialogBox(this);
987 ConstructorsClicked(GetConstructorId());
988 SelectionIntoArgument();
991 //=================================================================================
992 // function : enterEvent()
993 // purpose : Mouse enter event
994 //=================================================================================
995 void SMESHGUI_ExtrusionDlg::enterEvent (QEvent*)
997 if (!ConstructorsBox->isEnabled())
998 ActivateThisDialog();
1001 //=================================================================================
1002 // function : closeEvent()
1004 //=================================================================================
1005 void SMESHGUI_ExtrusionDlg::closeEvent( QCloseEvent* )
1007 /* same than click on cancel button */
1008 disconnect(mySelectionMgr, 0, this, 0);
1009 mySelectionMgr->clearFilters();
1010 //mySelectionMgr->clearSelected();
1011 if (SMESH::GetCurrentVtkView()) {
1012 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1013 SMESH::SetPointRepresentation(false);
1014 SMESH::SetPickable();
1016 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1017 aViewWindow->SetSelectionMode(ActorSelection);
1018 mySMESHGUI->ResetState();
1021 void SMESHGUI_ExtrusionDlg::reject()
1027 //=================================================================================
1028 // function : onSelectMesh()
1030 //=================================================================================
1031 void SMESHGUI_ExtrusionDlg::onSelectMesh (bool toSelectMesh)
1034 myIDs = LineEditElements->text();
1035 TextLabelElements->setText(tr("SMESH_NAME"));
1038 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
1040 myFilterBtn->setEnabled(!toSelectMesh);
1042 if (myEditCurrentArgument != LineEditElements) {
1043 LineEditElements->clear();
1047 mySelectionMgr->clearFilters();
1051 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1052 aViewWindow->SetSelectionMode(ActorSelection);
1053 switch( GetConstructorId() ) {
1054 case 0: mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter0D); break;
1055 case 1: mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter1D); break;
1056 case 2: mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter2D); break;
1058 LineEditElements->setReadOnly(true);
1059 LineEditElements->setValidator(0);
1063 int aConstructorId = GetConstructorId();
1064 switch(aConstructorId) {
1067 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1068 aViewWindow->SetSelectionMode(NodeSelection);
1073 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1074 aViewWindow->SetSelectionMode(EdgeSelection);
1079 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1080 aViewWindow->SetSelectionMode(FaceSelection);
1084 LineEditElements->setReadOnly(false);
1085 LineEditElements->setValidator(myIdValidator);
1086 onTextChange(LineEditElements->text());
1089 SelectionIntoArgument();
1092 LineEditElements->setText( myIDs );
1095 //=================================================================================
1096 // function : GetConstructorId()
1098 //=================================================================================
1099 int SMESHGUI_ExtrusionDlg::GetConstructorId()
1101 return GroupConstructors->checkedId();
1104 //=================================================================================
1105 // function : keyPressEvent()
1107 //=================================================================================
1108 void SMESHGUI_ExtrusionDlg::keyPressEvent( QKeyEvent* e )
1110 QDialog::keyPressEvent( e );
1111 if ( e->isAccepted() )
1114 if ( e->key() == Qt::Key_F1 ) {
1120 //=================================================================================
1121 // function : setFilters()
1122 // purpose : SLOT. Called when "Filter" button pressed.
1123 //=================================================================================
1124 void SMESHGUI_ExtrusionDlg::setFilters()
1126 if(myMesh->_is_nil()) {
1127 SUIT_MessageBox::critical(this,
1129 tr("NO_MESH_SELECTED"));
1135 types.append( SMESH::NODE );
1136 types.append( SMESH::EDGE );
1137 types.append( SMESH::FACE );
1138 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, types );
1140 switch( GetConstructorId() ){
1143 myFilterDlg->Init( SMESH::NODE );
1148 myFilterDlg->Init( SMESH::EDGE );
1153 myFilterDlg->Init( SMESH::FACE );
1159 myFilterDlg->SetSelection();
1160 myFilterDlg->SetMesh( myMesh );
1161 myFilterDlg->SetSourceWg( LineEditElements );
1163 myFilterDlg->show();
1166 //=================================================================================
1167 // function : isValid
1169 //=================================================================================
1170 bool SMESHGUI_ExtrusionDlg::isValid()
1174 if ( RadioButton3->isChecked() ) {
1175 ok = SpinBox_Dx->isValid( msg, true ) && ok;
1176 ok = SpinBox_Dy->isValid( msg, true ) && ok;
1177 ok = SpinBox_Dz->isValid( msg, true ) && ok;
1178 } else if ( RadioButton4->isChecked() ) {
1179 ok = SpinBox_Vx->isValid( msg, true ) && ok;
1180 ok = SpinBox_Vy->isValid( msg, true ) && ok;
1181 ok = SpinBox_Vz->isValid( msg, true ) && ok;
1182 ok = SpinBox_VDist->isValid( msg, true ) && ok;
1184 ok = SpinBox_NbSteps->isValid( msg, true ) && ok;
1187 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1188 if ( !msg.isEmpty() )
1190 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1196 //=================================================================================
1197 // function : onDisplaySimulation
1198 // purpose : Show/Hide preview
1199 //=================================================================================
1200 void SMESHGUI_ExtrusionDlg::onDisplaySimulation( bool toDisplayPreview ) {
1201 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1202 if (myNbOkElements && isValid() && isValuesValid()) {
1204 SMESH::DirStruct aVector;
1205 getExtrusionVector(aVector);
1207 //Get Number of the steps
1208 long aNbSteps = (long)SpinBox_NbSteps->value();
1211 SUIT_OverrideCursor aWaitCursor;
1212 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
1213 if( CheckBoxMesh->isChecked() ) {
1214 switch (GetConstructorId()) {
1217 aMeshEditor->ExtrusionSweepObject0D(mySelectedObject, aVector, aNbSteps);
1222 aMeshEditor->ExtrusionSweepObject1D(mySelectedObject, aVector, aNbSteps);
1227 aMeshEditor->ExtrusionSweepObject2D(mySelectedObject, aVector, aNbSteps);
1233 if(GetConstructorId() == 0)
1234 aMeshEditor->ExtrusionSweep0D(myElementsId.inout(), aVector, aNbSteps);
1236 aMeshEditor->ExtrusionSweep(myElementsId.inout(), aVector, aNbSteps);
1238 SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
1239 mySimulation->SetData(aMeshPreviewStruct._retn());
1251 //=================================================================================
1252 // function : getExtrusionVector()
1253 // purpose : get direction of the extrusion
1254 //=================================================================================
1255 void SMESHGUI_ExtrusionDlg::getExtrusionVector(SMESH::DirStruct& aVector) {
1256 if ( RadioButton3->isChecked() ) {
1257 aVector.PS.x = SpinBox_Dx->GetValue();
1258 aVector.PS.y = SpinBox_Dy->GetValue();
1259 aVector.PS.z = SpinBox_Dz->GetValue();
1260 } else if ( RadioButton4->isChecked() ) {
1261 gp_XYZ aNormale(SpinBox_Vx->GetValue(),
1262 SpinBox_Vy->GetValue(),
1263 SpinBox_Vz->GetValue());
1266 aNormale /= aNormale.Modulus();
1267 double aVDist = (double)SpinBox_VDist->value();
1269 aVector.PS.x = aNormale.X()*aVDist;
1270 aVector.PS.y = aNormale.Y()*aVDist;
1271 aVector.PS.z = aNormale.Z()*aVDist;