1 // Copyright (C) 2007-2011 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 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
284 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
286 QList<SUIT_SelectionFilter*> aListOfFilters;
287 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
288 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
290 myMeshOrSubMeshOrGroupFilter =
291 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
293 myHelpFileName = "extrusion_page.html";
297 /***************************************************************/
298 // signals and slots connections
299 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
300 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
301 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
302 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
304 connect(RadioButton3, SIGNAL(clicked()), this, SLOT(ClickOnRadio()));
305 connect(RadioButton4, SIGNAL(clicked()), this, SLOT(ClickOnRadio()));
307 // to update state of the Ok & Apply buttons
308 connect(SpinBox_Vx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
309 connect(SpinBox_Vy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
310 connect(SpinBox_Vz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
311 connect(SpinBox_Dx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
312 connect(SpinBox_Dy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
313 connect(SpinBox_Dz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
315 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
316 connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
317 connect(SelectVectorButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
318 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
319 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
320 /* to close dialog if study change */
321 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
322 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
323 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
325 connect(SpinBox_Dx, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
326 connect(SpinBox_Dy, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
327 connect(SpinBox_Dz, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
328 connect(SpinBox_Vx, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
329 connect(SpinBox_Vy, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
330 connect(SpinBox_Vz, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
331 connect(SpinBox_VDist, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
332 connect(SpinBox_NbSteps, SIGNAL(valueChanged(int)), this, SLOT(toDisplaySimulation()));
334 //To Connect preview check box
335 connectPreviewControl();
337 /***************************************************************/
339 ConstructorsClicked(0);
341 SelectionIntoArgument();
344 //=================================================================================
345 // function : ~SMESHGUI_ExtrusionDlg()
346 // purpose : destructor
347 //=================================================================================
348 SMESHGUI_ExtrusionDlg::~SMESHGUI_ExtrusionDlg()
350 if ( myFilterDlg != 0 ) {
351 myFilterDlg->setParent( 0 );
356 //=================================================================================
358 // purpose : initialization
359 //=================================================================================
360 void SMESHGUI_ExtrusionDlg::Init (bool ResetControls)
365 LineEditElements->clear();
369 myMesh = SMESH::SMESH_Mesh::_nil();
372 SpinBox_NbSteps->setValue(1);
373 SpinBox_VDist->setValue(10);
374 SpinBox_Dx->SetValue(0);
375 SpinBox_Dy->SetValue(0);
376 SpinBox_Dz->SetValue(0);
377 SpinBox_Vx->SetValue(0);
378 SpinBox_Vy->SetValue(0);
379 SpinBox_Vz->SetValue(0);
381 CheckBoxMesh->setChecked(false);
383 myPreviewCheckBox->setChecked(false);
384 onDisplaySimulation(false);
390 //=================================================================================
391 // function : CheckIsEnable()
392 // purpose : Check whether the Ok and Apply buttons should be enabled or not
393 //=================================================================================
394 void SMESHGUI_ExtrusionDlg::CheckIsEnable()
396 bool anIsEnable = myNbOkElements > 0 && isValuesValid();
398 buttonOk->setEnabled(anIsEnable);
399 buttonApply->setEnabled(anIsEnable);
402 //=================================================================================
403 // function : isValuesValid()
404 // purpose : Return true in case if values entered into dialog are valid
405 //=================================================================================
406 bool SMESHGUI_ExtrusionDlg::isValuesValid() {
407 double aX, aY, aZ, aModule = 0;
408 if ( RadioButton3->isChecked() ) {
409 aX = SpinBox_Dx->GetValue();
410 aY = SpinBox_Dy->GetValue();
411 aZ = SpinBox_Dz->GetValue();
412 aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
413 } else if ( RadioButton4->isChecked() ) {
414 aX = SpinBox_Vx->GetValue();
415 aY = SpinBox_Vy->GetValue();
416 aZ = SpinBox_Vz->GetValue();
417 aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
419 return aModule > 1.0E-38;
422 //=================================================================================
423 // function : ConstructorsClicked()
424 // purpose : Radio button management
425 //=================================================================================
426 void SMESHGUI_ExtrusionDlg::ConstructorsClicked (int constructorId)
428 disconnect(mySelectionMgr, 0, this, 0);
432 switch (constructorId) {
435 GroupArguments->setTitle(tr("EXTRUSION_0D"));
436 if (!CheckBoxMesh->isChecked())
438 LineEditElements->clear();
440 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
441 aViewWindow->SetSelectionMode(NodeSelection);
447 GroupArguments->setTitle(tr("EXTRUSION_1D"));
448 if (!CheckBoxMesh->isChecked())
450 LineEditElements->clear();
452 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
453 aViewWindow->SetSelectionMode(EdgeSelection);
459 GroupArguments->setTitle(tr("EXTRUSION_2D"));
460 if (!CheckBoxMesh->isChecked())
462 LineEditElements->clear();
464 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
465 aViewWindow->SetSelectionMode(FaceSelection);
471 myEditCurrentArgument = (QWidget*)LineEditElements;
472 LineEditElements->setFocus();
474 if (CheckBoxMesh->isChecked())
477 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
480 //=================================================================================
481 // function : ConstructorsClicked()
482 // purpose : Radio button management
483 //=================================================================================
484 void SMESHGUI_ExtrusionDlg::ClickOnRadio()
486 if ( RadioButton3->isChecked() ) {
487 TextLabelDistance->show();
495 TextLabelVector->hide();
502 TextLabelDist->hide();
503 SpinBox_VDist->hide();
504 SelectVectorButton->hide();
505 } else if ( RadioButton4->isChecked() ) {
506 TextLabelDistance->hide();
514 TextLabelVector->show();
521 TextLabelDist->show();
522 SpinBox_VDist->show();
523 SelectVectorButton->show();
525 onDisplaySimulation(true);
527 qApp->processEvents();
529 resize( minimumSizeHint() );
532 //=================================================================================
533 // function : ClickOnApply()
534 // purpose : Called when user presses <Apply> button
535 //=================================================================================
536 bool SMESHGUI_ExtrusionDlg::ClickOnApply()
538 if (mySMESHGUI->isActiveStudyLocked())
544 if (myNbOkElements) {
546 SMESH::DirStruct aVector;
547 getExtrusionVector(aVector);
549 QStringList aParameters;
550 if ( RadioButton3->isChecked() ) {
551 aParameters << SpinBox_Dx->text();
552 aParameters << SpinBox_Dy->text();
553 aParameters << SpinBox_Dz->text();
554 } else if ( RadioButton4->isChecked() ) {
555 // only 3 coords in a python dump command :(
556 // aParameters << SpinBox_Vx->text();
557 // aParameters << SpinBox_Vy->text();
558 // aParameters << SpinBox_Vz->text();
559 // aParameters << SpinBox_VDist->text();
562 long aNbSteps = (long)SpinBox_NbSteps->value();
564 aParameters << SpinBox_NbSteps->text();
567 SUIT_OverrideCursor aWaitCursor;
568 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
570 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
572 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) {
573 if( CheckBoxMesh->isChecked() )
574 switch (GetConstructorId() ) {
577 SMESH::ListOfGroups_var groups =
578 aMeshEditor->ExtrusionSweepObject0DMakeGroups(mySelectedObject, aVector, aNbSteps);
583 SMESH::ListOfGroups_var groups =
584 aMeshEditor->ExtrusionSweepObject1DMakeGroups(mySelectedObject, aVector, aNbSteps);
589 SMESH::ListOfGroups_var groups =
590 aMeshEditor->ExtrusionSweepObject2DMakeGroups(mySelectedObject, aVector, aNbSteps);
596 SMESH::ListOfGroups_var groups;
597 if (GetConstructorId() == 0)
598 groups = aMeshEditor->ExtrusionSweepMakeGroups0D(myElementsId.inout(), aVector, aNbSteps);
600 groups = aMeshEditor->ExtrusionSweepMakeGroups(myElementsId.inout(), aVector, aNbSteps);
605 if( CheckBoxMesh->isChecked() )
606 switch( GetConstructorId() ) {
609 aMeshEditor->ExtrusionSweepObject0D(mySelectedObject, aVector, aNbSteps);
614 aMeshEditor->ExtrusionSweepObject1D(mySelectedObject, aVector, aNbSteps);
619 aMeshEditor->ExtrusionSweepObject2D(mySelectedObject, aVector, aNbSteps);
624 if (GetConstructorId() == 0)
625 aMeshEditor->ExtrusionSweep0D(myElementsId.inout(), aVector, aNbSteps);
627 aMeshEditor->ExtrusionSweep(myElementsId.inout(), aVector, aNbSteps);
633 SMESH::Update(myIO, SMESH::eDisplay);
634 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() )
635 mySMESHGUI->updateObjBrowser(true); // new groups may appear
637 ConstructorsClicked(GetConstructorId());
638 mySelectionMgr->clearSelected();
639 mySelectedObject = SMESH::SMESH_IDSource::_nil();
640 SelectionIntoArgument();
642 SMESHGUI::Modified();
647 //=================================================================================
648 // function : ClickOnOk()
649 // purpose : Called when user presses <OK> button
650 //=================================================================================
651 void SMESHGUI_ExtrusionDlg::ClickOnOk()
657 //=================================================================================
658 // function : ClickOnCancel()
659 // purpose : Called when dialog box is closed
660 //=================================================================================
661 void SMESHGUI_ExtrusionDlg::ClickOnCancel()
666 //=================================================================================
667 // function : ClickOnHelp()
669 //=================================================================================
670 void SMESHGUI_ExtrusionDlg::ClickOnHelp()
672 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
674 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
678 platform = "winapplication";
680 platform = "application";
682 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
683 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
684 arg(app->resourceMgr()->stringValue("ExternalBrowser",
686 arg(myHelpFileName));
690 //=================================================================================
691 // function : onTextChange()
693 //=================================================================================
694 void SMESHGUI_ExtrusionDlg::onTextChange (const QString& theNewText)
696 QLineEdit* send = (QLineEdit*)sender();
704 if (send == LineEditElements)
707 // hilight entered elements/nodes
709 if (!myIO.IsNull()) {
710 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
712 if (send == LineEditElements)
714 SMDS_Mesh* aMesh = myActor ? myActor->GetObject()->GetMesh() : 0;
715 SMESH::ElementType SMESHType;
716 SMDSAbs_ElementType SMDSType;
717 switch (GetConstructorId()) {
720 SMESHType = SMESH::NODE;
721 SMDSType = SMDSAbs_Node;
726 SMESHType = SMESH::EDGE;
727 SMDSType = SMDSAbs_Edge;
732 SMESHType = SMESH::FACE;
733 SMDSType = SMDSAbs_Face;
737 myElementsId = new SMESH::long_array;
738 myElementsId->length( aListId.count() );
739 TColStd_MapOfInteger newIndices;
740 for (int i = 0; i < aListId.count(); i++) {
741 int id = aListId[ i ].toInt();
742 bool validId = false;
745 const SMDS_MeshElement * e;
746 if (SMDSType == SMDSAbs_Node)
747 e = aMesh->FindNode( id );
749 e = aMesh->FindElement( id );
750 validId = ( e && e->GetType() == SMDSType );
752 validId = ( myMesh->GetElementType( id, true ) == SMESHType );
755 if ( validId && newIndices.Add( id ))
756 myElementsId[ newIndices.Extent()-1 ] = id;
758 myElementsId->length( myNbOkElements = newIndices.Extent() );
759 mySelector->AddOrRemoveIndex(myIO, newIndices, false);
760 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
761 aViewWindow->highlight( myIO, true, true );
767 onDisplaySimulation(true);
772 //=================================================================================
773 // function : SelectionIntoArgument()
774 // purpose : Called when selection as changed or other case
775 //=================================================================================
776 void SMESHGUI_ExtrusionDlg::SelectionIntoArgument()
780 // return if dialog box is inactive
781 if (!GroupButtons->isEnabled())
785 if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
787 Handle(SALOME_InteractiveObject) resIO = myIO;
791 QString aString = "";
793 if(myEditCurrentArgument == (QWidget*)LineEditElements) {
795 LineEditElements->setText(aString);
801 mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
802 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
806 Handle(SALOME_InteractiveObject) IO = aList.First();
808 if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
809 myMesh = SMESH::GetMeshByIO(IO);
810 if (myMesh->_is_nil())
813 myActor = SMESH::FindActorByObject(myMesh);
816 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
819 // MakeGroups is available if there are groups
820 if ( myMesh->NbGroups() == 0 ) {
821 MakeGroupsCheck->setChecked(false);
822 MakeGroupsCheck->setEnabled(false);
824 MakeGroupsCheck->setEnabled(true);
827 if (CheckBoxMesh->isChecked()) {
828 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
830 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
831 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
835 // get indices of selcted elements
836 TColStd_IndexedMapOfInteger aMapIndex;
837 mySelector->GetIndex(IO,aMapIndex);
838 aNbElements = aMapIndex.Extent();
843 myElementsId = new SMESH::long_array;
844 myElementsId->length( aNbElements );
846 for ( int i = 0; i < aNbElements; ++i )
847 aString += QString(" %1").arg( myElementsId[ i ] = aMapIndex( i+1 ) );
850 myNbOkElements = true;
853 ((QLineEdit*)myEditCurrentArgument)->setText(aString);
856 else if(myEditCurrentArgument == (QWidget*)SpinBox_Vx){
857 TColStd_IndexedMapOfInteger aMapIndex;
858 mySelector->GetIndex(IO,aMapIndex);
859 int aNbElements = aMapIndex.Extent();
860 SMESH::SMESH_Mesh_var aMesh_var = SMESH::GetMeshByIO(IO);
861 SMESH_Actor* anActor = SMESH::FindActorByObject(aMesh_var);
862 SMDS_Mesh* aMesh = anActor ? anActor->GetObject()->GetMesh() : 0;
864 if(aNbElements != 1 || !aMesh)
867 const SMDS_MeshFace* face = dynamic_cast<const SMDS_MeshFace*>(aMesh->FindElement(aMapIndex(aNbElements)));
872 gp_XYZ aNormale = SMESH::getNormale(face);
873 SpinBox_Vx->SetValue(aNormale.X());
874 SpinBox_Vy->SetValue(aNormale.Y());
875 SpinBox_Vz->SetValue(aNormale.Z());
879 onDisplaySimulation(true);
885 //=================================================================================
886 // function : SetEditCurrentArgument()
888 //=================================================================================
889 void SMESHGUI_ExtrusionDlg::SetEditCurrentArgument()
891 QPushButton* send = (QPushButton*)sender();
893 disconnect(mySelectionMgr, 0, this, 0);
894 mySelectionMgr->clearSelected();
895 mySelectionMgr->clearFilters();
897 if (send == SelectElementsButton) {
898 myEditCurrentArgument = (QWidget*)LineEditElements;
899 if (CheckBoxMesh->isChecked()) {
900 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
901 aViewWindow->SetSelectionMode(ActorSelection);
902 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
904 int aConstructorId = GetConstructorId();
905 switch(aConstructorId) {
908 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
909 aViewWindow->SetSelectionMode(NodeSelection);
914 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
915 aViewWindow->SetSelectionMode(EdgeSelection);
920 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
921 aViewWindow->SetSelectionMode(FaceSelection);
927 else if (send == SelectVectorButton){
928 myEditCurrentArgument = (QWidget*)SpinBox_Vx;
929 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
930 aViewWindow->SetSelectionMode(FaceSelection);
933 myEditCurrentArgument->setFocus();
934 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
935 SelectionIntoArgument();
938 //=================================================================================
939 // function : DeactivateActiveDialog()
940 // purpose : Deactivates this dialog
941 //=================================================================================
942 void SMESHGUI_ExtrusionDlg::DeactivateActiveDialog()
944 if (ConstructorsBox->isEnabled()) {
945 ConstructorsBox->setEnabled(false);
946 GroupArguments->setEnabled(false);
947 GroupButtons->setEnabled(false);
948 mySMESHGUI->ResetState();
949 mySMESHGUI->SetActiveDialogBox(0);
953 //=================================================================================
954 // function : ActivateThisDialog()
955 // purpose : Activates this dialog
956 //=================================================================================
957 void SMESHGUI_ExtrusionDlg::ActivateThisDialog()
959 // Emit a signal to deactivate the active dialog
960 mySMESHGUI->EmitSignalDeactivateDialog();
961 ConstructorsBox->setEnabled(true);
962 GroupArguments->setEnabled(true);
963 GroupButtons->setEnabled(true);
965 mySMESHGUI->SetActiveDialogBox(this);
967 ConstructorsClicked(GetConstructorId());
968 SelectionIntoArgument();
971 //=================================================================================
972 // function : enterEvent()
973 // purpose : Mouse enter event
974 //=================================================================================
975 void SMESHGUI_ExtrusionDlg::enterEvent (QEvent*)
977 if (!ConstructorsBox->isEnabled())
978 ActivateThisDialog();
981 //=================================================================================
982 // function : closeEvent()
984 //=================================================================================
985 void SMESHGUI_ExtrusionDlg::closeEvent( QCloseEvent* )
987 /* same than click on cancel button */
988 disconnect(mySelectionMgr, 0, this, 0);
989 mySelectionMgr->clearFilters();
990 //mySelectionMgr->clearSelected();
991 if (SMESH::GetCurrentVtkView()) {
992 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
993 SMESH::SetPointRepresentation(false);
994 SMESH::SetPickable();
996 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
997 aViewWindow->SetSelectionMode(ActorSelection);
998 mySMESHGUI->ResetState();
1001 void SMESHGUI_ExtrusionDlg::reject()
1007 //=================================================================================
1008 // function : onSelectMesh()
1010 //=================================================================================
1011 void SMESHGUI_ExtrusionDlg::onSelectMesh (bool toSelectMesh)
1014 myIDs = LineEditElements->text();
1015 TextLabelElements->setText(tr("SMESH_NAME"));
1018 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
1020 myFilterBtn->setEnabled(!toSelectMesh);
1022 if (myEditCurrentArgument != LineEditElements) {
1023 LineEditElements->clear();
1027 mySelectionMgr->clearFilters();
1030 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1031 aViewWindow->SetSelectionMode(ActorSelection);
1032 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
1033 LineEditElements->setReadOnly(true);
1034 LineEditElements->setValidator(0);
1036 int aConstructorId = GetConstructorId();
1037 switch(aConstructorId) {
1040 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1041 aViewWindow->SetSelectionMode(NodeSelection);
1046 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1047 aViewWindow->SetSelectionMode(EdgeSelection);
1052 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1053 aViewWindow->SetSelectionMode(FaceSelection);
1057 LineEditElements->setReadOnly(false);
1058 LineEditElements->setValidator(myIdValidator);
1059 onTextChange(LineEditElements->text());
1062 SelectionIntoArgument();
1065 LineEditElements->setText( myIDs );
1068 //=================================================================================
1069 // function : GetConstructorId()
1071 //=================================================================================
1072 int SMESHGUI_ExtrusionDlg::GetConstructorId()
1074 return GroupConstructors->checkedId();
1077 //=================================================================================
1078 // function : keyPressEvent()
1080 //=================================================================================
1081 void SMESHGUI_ExtrusionDlg::keyPressEvent( QKeyEvent* e )
1083 QDialog::keyPressEvent( e );
1084 if ( e->isAccepted() )
1087 if ( e->key() == Qt::Key_F1 ) {
1093 //=================================================================================
1094 // function : setFilters()
1095 // purpose : SLOT. Called when "Filter" button pressed.
1096 //=================================================================================
1097 void SMESHGUI_ExtrusionDlg::setFilters()
1099 if(myMesh->_is_nil()) {
1100 SUIT_MessageBox::critical(this,
1102 tr("NO_MESH_SELECTED"));
1108 types.append( SMESH::NODE );
1109 types.append( SMESH::EDGE );
1110 types.append( SMESH::FACE );
1111 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, types );
1113 switch( GetConstructorId() ){
1116 myFilterDlg->Init( SMESH::NODE );
1121 myFilterDlg->Init( SMESH::EDGE );
1126 myFilterDlg->Init( SMESH::FACE );
1132 myFilterDlg->SetSelection();
1133 myFilterDlg->SetMesh( myMesh );
1134 myFilterDlg->SetSourceWg( LineEditElements );
1136 myFilterDlg->show();
1139 //=================================================================================
1140 // function : isValid
1142 //=================================================================================
1143 bool SMESHGUI_ExtrusionDlg::isValid()
1147 if ( RadioButton3->isChecked() ) {
1148 ok = SpinBox_Dx->isValid( msg, true ) && ok;
1149 ok = SpinBox_Dy->isValid( msg, true ) && ok;
1150 ok = SpinBox_Dz->isValid( msg, true ) && ok;
1151 } else if ( RadioButton4->isChecked() ) {
1152 ok = SpinBox_Vx->isValid( msg, true ) && ok;
1153 ok = SpinBox_Vy->isValid( msg, true ) && ok;
1154 ok = SpinBox_Vz->isValid( msg, true ) && ok;
1155 ok = SpinBox_VDist->isValid( msg, true ) && ok;
1157 ok = SpinBox_NbSteps->isValid( msg, true ) && ok;
1160 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1161 if ( !msg.isEmpty() )
1163 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1169 //=================================================================================
1170 // function : onDisplaySimulation
1171 // purpose : Show/Hide preview
1172 //=================================================================================
1173 void SMESHGUI_ExtrusionDlg::onDisplaySimulation( bool toDisplayPreview ) {
1174 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1175 if (myNbOkElements && isValid() && isValuesValid()) {
1177 SMESH::DirStruct aVector;
1178 getExtrusionVector(aVector);
1180 //Get Number of the steps
1181 long aNbSteps = (long)SpinBox_NbSteps->value();
1184 SUIT_OverrideCursor aWaitCursor;
1185 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
1186 if( CheckBoxMesh->isChecked() ) {
1187 switch (GetConstructorId()) {
1190 aMeshEditor->ExtrusionSweepObject0D(mySelectedObject, aVector, aNbSteps);
1195 aMeshEditor->ExtrusionSweepObject1D(mySelectedObject, aVector, aNbSteps);
1200 aMeshEditor->ExtrusionSweepObject2D(mySelectedObject, aVector, aNbSteps);
1206 if(GetConstructorId() == 0)
1207 aMeshEditor->ExtrusionSweep0D(myElementsId.inout(), aVector, aNbSteps);
1209 aMeshEditor->ExtrusionSweep(myElementsId.inout(), aVector, aNbSteps);
1211 SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
1212 mySimulation->SetData(aMeshPreviewStruct._retn());
1224 //=================================================================================
1225 // function : getExtrusionVector()
1226 // purpose : get direction of the extrusion
1227 //=================================================================================
1228 void SMESHGUI_ExtrusionDlg::getExtrusionVector(SMESH::DirStruct& aVector) {
1229 if ( RadioButton3->isChecked() ) {
1230 aVector.PS.x = SpinBox_Dx->GetValue();
1231 aVector.PS.y = SpinBox_Dy->GetValue();
1232 aVector.PS.z = SpinBox_Dz->GetValue();
1233 } else if ( RadioButton4->isChecked() ) {
1234 gp_XYZ aNormale(SpinBox_Vx->GetValue(),
1235 SpinBox_Vy->GetValue(),
1236 SpinBox_Vz->GetValue());
1239 aNormale /= aNormale.Modulus();
1240 double aVDist = (double)SpinBox_VDist->value();
1242 aVector.PS.x = aNormale.X()*aVDist;
1243 aVector.PS.y = aNormale.Y()*aVDist;
1244 aVector.PS.z = aNormale.Z()*aVDist;