1 // Copyright (C) 2007-2010 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")));
102 setAttribute( Qt::WA_DeleteOnClose, true );
103 setWindowTitle(tr("EXTRUSION_ALONG_LINE"));
104 setSizeGripEnabled(true);
106 QVBoxLayout* SMESHGUI_ExtrusionDlgLayout = new QVBoxLayout(this);
107 SMESHGUI_ExtrusionDlgLayout->setSpacing(SPACING);
108 SMESHGUI_ExtrusionDlgLayout->setMargin(MARGIN);
110 /***************************************************************/
111 ConstructorsBox = new QGroupBox(tr("SMESH_EXTRUSION"), this);
112 GroupConstructors = new QButtonGroup(this);
113 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
114 ConstructorsBoxLayout->setSpacing(SPACING);
115 ConstructorsBoxLayout->setMargin(MARGIN);
117 RadioButton1= new QRadioButton(ConstructorsBox);
118 RadioButton1->setIcon(image0);
119 RadioButton2= new QRadioButton(ConstructorsBox);
120 RadioButton2->setIcon(image1);
122 ConstructorsBoxLayout->addWidget(RadioButton1);
123 ConstructorsBoxLayout->addWidget(RadioButton2);
125 GroupConstructors->addButton(RadioButton1, 0);
126 GroupConstructors->addButton(RadioButton2, 1);
128 /***************************************************************/
129 GroupButtons = new QGroupBox(this);
130 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
131 GroupButtonsLayout->setSpacing(SPACING);
132 GroupButtonsLayout->setMargin(MARGIN);
134 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
135 buttonOk->setAutoDefault(true);
136 buttonOk->setDefault(true);
137 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
138 buttonApply->setAutoDefault(true);
139 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
140 buttonCancel->setAutoDefault(true);
141 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
142 buttonHelp->setAutoDefault(true);
144 GroupButtonsLayout->addWidget(buttonOk);
145 GroupButtonsLayout->addSpacing(10);
146 GroupButtonsLayout->addWidget(buttonApply);
147 GroupButtonsLayout->addSpacing(10);
148 GroupButtonsLayout->addStretch();
149 GroupButtonsLayout->addWidget(buttonCancel);
150 GroupButtonsLayout->addWidget(buttonHelp);
152 /***************************************************************/
153 GroupArguments = new QGroupBox(tr("EXTRUSION_1D"), this);
154 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
155 GroupArgumentsLayout->setSpacing(SPACING);
156 GroupArgumentsLayout->setMargin(MARGIN);
158 myIdValidator = new SMESHGUI_IdValidator(this);
160 // Controls for elements selection
161 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
163 SelectElementsButton = new QPushButton(GroupArguments);
164 SelectElementsButton->setIcon(image2);
166 LineEditElements = new QLineEdit(GroupArguments);
167 LineEditElements->setValidator(myIdValidator);
168 LineEditElements->setMaxLength(-1);
169 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
170 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
172 // Control for the whole mesh selection
173 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
175 RadioButton3 = new QRadioButton(GroupArguments);
176 RadioButton3->setText( tr("SMESH_EXTRUSION_TO_DISTANCE") );
177 RadioButton4 = new QRadioButton(GroupArguments);
178 RadioButton4->setText( tr("SMESH_EXTRUSION_ALONG_VECTOR") );
180 //Control for the Distance selection
181 TextLabelDistance = new QLabel(tr("SMESH_DISTANCE"), GroupArguments);
183 TextLabelDx = new QLabel(tr("SMESH_X"), GroupArguments);
184 SpinBox_Dx = new SMESHGUI_SpinBox(GroupArguments);
186 TextLabelDy = new QLabel(tr("SMESH_Y"), GroupArguments);
187 SpinBox_Dy = new SMESHGUI_SpinBox(GroupArguments);
189 TextLabelDz = new QLabel(tr("SMESH_Z"), GroupArguments);
190 SpinBox_Dz = new SMESHGUI_SpinBox(GroupArguments);
192 // Controls for vector selection
194 TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupArguments);
196 SelectVectorButton = new QPushButton(GroupArguments);
197 SelectVectorButton->setIcon(image2);
199 TextLabelVx = new QLabel(tr("SMESH_DX"), GroupArguments);
200 SpinBox_Vx = new SMESHGUI_SpinBox(GroupArguments);
202 TextLabelVy = new QLabel(tr("SMESH_DY"), GroupArguments);
203 SpinBox_Vy = new SMESHGUI_SpinBox(GroupArguments);
205 TextLabelVz = new QLabel(tr("SMESH_DZ"), GroupArguments);
206 SpinBox_Vz = new SMESHGUI_SpinBox(GroupArguments);
208 TextLabelDist = new QLabel(tr("SMESH_DISTANCE"), GroupArguments);
209 SpinBox_VDist = new SMESHGUI_SpinBox(GroupArguments);
211 // Controls for nb. steps defining
212 TextLabelNbSteps = new QLabel(tr("SMESH_NUMBEROFSTEPS"), GroupArguments);
213 SpinBox_NbSteps = new SalomeApp_IntSpinBox(GroupArguments);
215 // CheckBox for groups generation
216 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
219 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
221 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
222 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
223 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 5);
224 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 7);
225 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
226 GroupArgumentsLayout->addWidget(RadioButton3, 2, 1, 1, 3);
227 GroupArgumentsLayout->addWidget(RadioButton4, 2, 5, 1, 3);
228 GroupArgumentsLayout->addWidget(TextLabelDistance, 3, 0);
229 GroupArgumentsLayout->addWidget(TextLabelDx, 3, 2);
230 GroupArgumentsLayout->addWidget(SpinBox_Dx, 3, 3);
231 GroupArgumentsLayout->addWidget(TextLabelDy, 3, 4);
232 GroupArgumentsLayout->addWidget(SpinBox_Dy, 3, 5);
233 GroupArgumentsLayout->addWidget(TextLabelDz, 3, 6);
234 GroupArgumentsLayout->addWidget(SpinBox_Dz, 3, 7);
235 GroupArgumentsLayout->addWidget(TextLabelVector, 4, 0);
236 GroupArgumentsLayout->addWidget(SelectVectorButton, 4, 1);
237 GroupArgumentsLayout->addWidget(TextLabelVx, 4, 2);
238 GroupArgumentsLayout->addWidget(SpinBox_Vx, 4, 3);
239 GroupArgumentsLayout->addWidget(TextLabelVy, 4, 4);
240 GroupArgumentsLayout->addWidget(SpinBox_Vy, 4, 5);
241 GroupArgumentsLayout->addWidget(TextLabelVz, 4, 6);
242 GroupArgumentsLayout->addWidget(SpinBox_Vz, 4, 7);
243 GroupArgumentsLayout->addWidget(TextLabelDist, 5, 0);
244 GroupArgumentsLayout->addWidget(SpinBox_VDist, 5, 3);
245 GroupArgumentsLayout->addWidget(TextLabelNbSteps, 6, 0, 1, 3);
246 GroupArgumentsLayout->addWidget(SpinBox_NbSteps, 6, 3);
247 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 7, 0, 1, 8);
248 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 8, 0, 1, 8);
249 GroupArgumentsLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding), 8, 0);
252 /***************************************************************/
253 SMESHGUI_ExtrusionDlgLayout->addWidget(ConstructorsBox);
254 SMESHGUI_ExtrusionDlgLayout->addWidget(GroupArguments);
255 SMESHGUI_ExtrusionDlgLayout->addWidget(GroupButtons);
257 /* Initialisations */
258 SpinBox_Vx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, "length_precision");
259 SpinBox_Vy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, "length_precision");
260 SpinBox_Vz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, "length_precision");
262 SpinBox_Dx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
263 SpinBox_Dy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
264 SpinBox_Dz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
266 SpinBox_NbSteps->setRange(1, 999999);
267 SpinBox_VDist->RangeStepAndValidator(0, COORD_MAX, 10.0, "length_precision");
269 RadioButton1->setChecked(true);
270 RadioButton3->setChecked(true);
271 MakeGroupsCheck->setChecked(true);
273 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
275 mySMESHGUI->SetActiveDialogBox(this);
277 // Costruction of the logical filter for the elements: mesh/sub-mesh/group
278 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
279 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
281 QList<SUIT_SelectionFilter*> aListOfFilters;
282 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
283 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
285 myMeshOrSubMeshOrGroupFilter =
286 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
288 myHelpFileName = "extrusion_page.html";
292 /***************************************************************/
293 // signals and slots connections
294 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
295 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
296 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
297 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
299 connect(RadioButton3, SIGNAL(clicked()), this, SLOT(ClickOnRadio()));
300 connect(RadioButton4, SIGNAL(clicked()), this, SLOT(ClickOnRadio()));
302 // to update state of the Ok & Apply buttons
303 connect(SpinBox_Vx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
304 connect(SpinBox_Vy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
305 connect(SpinBox_Vz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
306 connect(SpinBox_Dx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
307 connect(SpinBox_Dy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
308 connect(SpinBox_Dz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
310 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
311 connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
312 connect(SelectVectorButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
313 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
314 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
315 /* to close dialog if study change */
316 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
317 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
318 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
320 connect(SpinBox_Dx, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
321 connect(SpinBox_Dy, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
322 connect(SpinBox_Dz, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
323 connect(SpinBox_Vx, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
324 connect(SpinBox_Vy, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
325 connect(SpinBox_Vz, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
326 connect(SpinBox_VDist, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
327 connect(SpinBox_NbSteps, SIGNAL(valueChanged(int)), this, SLOT(toDisplaySimulation()));
329 //To Connect preview check box
330 connectPreviewControl();
332 /***************************************************************/
334 ConstructorsClicked(0);
336 SelectionIntoArgument();
339 //=================================================================================
340 // function : ~SMESHGUI_ExtrusionDlg()
341 // purpose : destructor
342 //=================================================================================
343 SMESHGUI_ExtrusionDlg::~SMESHGUI_ExtrusionDlg()
345 if ( myFilterDlg != 0 ) {
346 myFilterDlg->setParent( 0 );
351 //=================================================================================
353 // purpose : initialization
354 //=================================================================================
355 void SMESHGUI_ExtrusionDlg::Init (bool ResetControls)
360 LineEditElements->clear();
364 myMesh = SMESH::SMESH_Mesh::_nil();
367 SpinBox_NbSteps->setValue(1);
368 SpinBox_VDist->setValue(10);
369 SpinBox_Dx->SetValue(0);
370 SpinBox_Dy->SetValue(0);
371 SpinBox_Dz->SetValue(0);
372 SpinBox_Vx->SetValue(0);
373 SpinBox_Vy->SetValue(0);
374 SpinBox_Vz->SetValue(0);
376 CheckBoxMesh->setChecked(false);
378 myPreviewCheckBox->setChecked(false);
379 onDisplaySimulation(false);
385 //=================================================================================
386 // function : CheckIsEnable()
387 // purpose : Check whether the Ok and Apply buttons should be enabled or not
388 //=================================================================================
389 void SMESHGUI_ExtrusionDlg::CheckIsEnable()
391 bool anIsEnable = myNbOkElements > 0 && isValuesValid();
393 buttonOk->setEnabled(anIsEnable);
394 buttonApply->setEnabled(anIsEnable);
397 //=================================================================================
398 // function : isValuesValid()
399 // purpose : Return true in case if values entered into dialog are valid
400 //=================================================================================
401 bool SMESHGUI_ExtrusionDlg::isValuesValid() {
402 double aX, aY, aZ, aModule = 0;
403 if ( RadioButton3->isChecked() ) {
404 aX = SpinBox_Dx->GetValue();
405 aY = SpinBox_Dy->GetValue();
406 aZ = SpinBox_Dz->GetValue();
407 aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
408 } else if ( RadioButton4->isChecked() ) {
409 aX = SpinBox_Vx->GetValue();
410 aY = SpinBox_Vy->GetValue();
411 aZ = SpinBox_Vz->GetValue();
412 aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
414 return aModule > 1.0E-38;
417 //=================================================================================
418 // function : ConstructorsClicked()
419 // purpose : Radio button management
420 //=================================================================================
421 void SMESHGUI_ExtrusionDlg::ConstructorsClicked (int constructorId)
423 disconnect(mySelectionMgr, 0, this, 0);
427 switch (constructorId) {
430 GroupArguments->setTitle(tr("EXTRUSION_1D"));
431 if (!CheckBoxMesh->isChecked())
433 LineEditElements->clear();
435 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
436 aViewWindow->SetSelectionMode(EdgeSelection);
442 GroupArguments->setTitle(tr("EXTRUSION_2D"));
443 if (!CheckBoxMesh->isChecked())
445 LineEditElements->clear();
447 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
448 aViewWindow->SetSelectionMode(FaceSelection);
454 myEditCurrentArgument = (QWidget*)LineEditElements;
455 LineEditElements->setFocus();
457 if (CheckBoxMesh->isChecked())
460 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
463 //=================================================================================
464 // function : ConstructorsClicked()
465 // purpose : Radio button management
466 //=================================================================================
467 void SMESHGUI_ExtrusionDlg::ClickOnRadio()
469 if ( RadioButton3->isChecked() ) {
470 TextLabelDistance->show();
478 TextLabelVector->hide();
485 TextLabelDist->hide();
486 SpinBox_VDist->hide();
487 SelectVectorButton->hide();
488 } else if ( RadioButton4->isChecked() ) {
489 TextLabelDistance->hide();
497 TextLabelVector->show();
504 TextLabelDist->show();
505 SpinBox_VDist->show();
506 SelectVectorButton->show();
508 onDisplaySimulation(true);
510 qApp->processEvents();
512 resize( minimumSizeHint() );
515 //=================================================================================
516 // function : ClickOnApply()
517 // purpose : Called when user presses <Apply> button
518 //=================================================================================
519 bool SMESHGUI_ExtrusionDlg::ClickOnApply()
521 if (mySMESHGUI->isActiveStudyLocked())
527 if (myNbOkElements) {
529 SMESH::DirStruct aVector;
530 getExtrusionVector(aVector);
532 QStringList aParameters;
533 if ( RadioButton3->isChecked() ) {
534 aParameters << SpinBox_Dx->text();
535 aParameters << SpinBox_Dy->text();
536 aParameters << SpinBox_Dz->text();
537 } else if ( RadioButton4->isChecked() ) {
538 aParameters << SpinBox_Vx->text();
539 aParameters << SpinBox_Vy->text();
540 aParameters << SpinBox_Vz->text();
541 aParameters << SpinBox_VDist->text();
544 long aNbSteps = (long)SpinBox_NbSteps->value();
546 aParameters << SpinBox_NbSteps->text();
549 SUIT_OverrideCursor aWaitCursor;
550 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
552 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) {
553 if( CheckBoxMesh->isChecked() ) {
554 if( GetConstructorId() == 0 )
555 SMESH::ListOfGroups_var groups =
556 aMeshEditor->ExtrusionSweepObject1DMakeGroups(mySelectedObject, aVector, aNbSteps);
558 SMESH::ListOfGroups_var groups =
559 aMeshEditor->ExtrusionSweepObject2DMakeGroups(mySelectedObject, aVector, aNbSteps);
562 SMESH::ListOfGroups_var groups =
563 aMeshEditor->ExtrusionSweepMakeGroups(myElementsId.inout(), aVector, aNbSteps);
566 if( CheckBoxMesh->isChecked() ) {
567 if( GetConstructorId() == 0 )
568 aMeshEditor->ExtrusionSweepObject1D(mySelectedObject, aVector, aNbSteps);
570 aMeshEditor->ExtrusionSweepObject2D(mySelectedObject, aVector, aNbSteps);
573 aMeshEditor->ExtrusionSweep(myElementsId.inout(), aVector, aNbSteps);
576 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
581 SMESH::Update(myIO, SMESH::eDisplay);
582 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() )
583 mySMESHGUI->updateObjBrowser(true); // new groups may appear
585 ConstructorsClicked(GetConstructorId());
586 mySelectionMgr->clearSelected();
587 mySelectedObject = SMESH::SMESH_IDSource::_nil();
588 SelectionIntoArgument();
590 SMESHGUI::Modified();
595 //=================================================================================
596 // function : ClickOnOk()
597 // purpose : Called when user presses <OK> button
598 //=================================================================================
599 void SMESHGUI_ExtrusionDlg::ClickOnOk()
605 //=================================================================================
606 // function : ClickOnCancel()
607 // purpose : Called when dialog box is closed
608 //=================================================================================
609 void SMESHGUI_ExtrusionDlg::ClickOnCancel()
614 //=================================================================================
615 // function : ClickOnHelp()
617 //=================================================================================
618 void SMESHGUI_ExtrusionDlg::ClickOnHelp()
620 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
622 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
626 platform = "winapplication";
628 platform = "application";
630 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
631 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
632 arg(app->resourceMgr()->stringValue("ExternalBrowser",
634 arg(myHelpFileName));
638 //=================================================================================
639 // function : onTextChange()
641 //=================================================================================
642 void SMESHGUI_ExtrusionDlg::onTextChange (const QString& theNewText)
644 QLineEdit* send = (QLineEdit*)sender();
652 if (send == LineEditElements)
655 // hilight entered elements/nodes
657 if (!myIO.IsNull()) {
658 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
660 if (send == LineEditElements)
662 SMDS_Mesh* aMesh = myActor ? myActor->GetObject()->GetMesh() : 0;
663 SMESH::ElementType SMESHType = GetConstructorId() ? SMESH::FACE : SMESH::EDGE;
664 SMDSAbs_ElementType SMDSType = GetConstructorId() ? SMDSAbs_Face: SMDSAbs_Edge;
666 myElementsId = new SMESH::long_array;
667 myElementsId->length( aListId.count() );
668 TColStd_MapOfInteger newIndices;
669 for (int i = 0; i < aListId.count(); i++) {
670 int id = aListId[ i ].toInt();
671 bool validId = false;
674 const SMDS_MeshElement * e = aMesh->FindElement( id );
675 validId = ( e && e->GetType() == SMDSType );
677 validId = ( myMesh->GetElementType( id, true ) == SMESHType );
680 if ( validId && newIndices.Add( id ))
681 myElementsId[ newIndices.Extent()-1 ] = id;
683 myElementsId->length( myNbOkElements = newIndices.Extent() );
684 mySelector->AddOrRemoveIndex(myIO, newIndices, false);
685 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
686 aViewWindow->highlight( myIO, true, true );
692 onDisplaySimulation(true);
697 //=================================================================================
698 // function : SelectionIntoArgument()
699 // purpose : Called when selection as changed or other case
700 //=================================================================================
701 void SMESHGUI_ExtrusionDlg::SelectionIntoArgument()
705 // return if dialog box is inactive
706 if (!GroupButtons->isEnabled())
710 if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
712 Handle(SALOME_InteractiveObject) resIO = myIO;
716 QString aString = "";
718 if(myEditCurrentArgument == (QWidget*)LineEditElements) {
720 LineEditElements->setText(aString);
726 mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
727 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
731 Handle(SALOME_InteractiveObject) IO = aList.First();
733 if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
734 myMesh = SMESH::GetMeshByIO(IO);
735 if (myMesh->_is_nil())
738 myActor = SMESH::FindActorByObject(myMesh);
741 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
744 // MakeGroups is available if there are groups
745 if ( myMesh->NbGroups() == 0 ) {
746 MakeGroupsCheck->setChecked(false);
747 MakeGroupsCheck->setEnabled(false);
749 MakeGroupsCheck->setEnabled(true);
752 if (CheckBoxMesh->isChecked()) {
753 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
755 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
756 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
760 // get indices of selcted elements
761 TColStd_IndexedMapOfInteger aMapIndex;
762 mySelector->GetIndex(IO,aMapIndex);
763 aNbElements = aMapIndex.Extent();
768 myElementsId = new SMESH::long_array;
769 myElementsId->length( aNbElements );
771 for ( int i = 0; i < aNbElements; ++i )
772 aString += QString(" %1").arg( myElementsId[ i ] = aMapIndex( i+1 ) );
775 myNbOkElements = true;
778 ((QLineEdit*)myEditCurrentArgument)->setText(aString);
781 else if(myEditCurrentArgument == (QWidget*)SpinBox_Vx){
782 TColStd_IndexedMapOfInteger aMapIndex;
783 mySelector->GetIndex(IO,aMapIndex);
784 int aNbElements = aMapIndex.Extent();
785 SMESH::SMESH_Mesh_var aMesh_var = SMESH::GetMeshByIO(IO);
786 SMESH_Actor* anActor = SMESH::FindActorByObject(aMesh_var);
787 SMDS_Mesh* aMesh = anActor ? anActor->GetObject()->GetMesh() : 0;
789 if(aNbElements != 1 || !aMesh)
792 const SMDS_MeshFace* face = dynamic_cast<const SMDS_MeshFace*>(aMesh->FindElement(aMapIndex(aNbElements)));
797 gp_XYZ aNormale = SMESH::getNormale(face);
798 SpinBox_Vx->SetValue(aNormale.X());
799 SpinBox_Vy->SetValue(aNormale.Y());
800 SpinBox_Vz->SetValue(aNormale.Z());
804 onDisplaySimulation(true);
810 //=================================================================================
811 // function : SetEditCurrentArgument()
813 //=================================================================================
814 void SMESHGUI_ExtrusionDlg::SetEditCurrentArgument()
816 QPushButton* send = (QPushButton*)sender();
818 disconnect(mySelectionMgr, 0, this, 0);
819 mySelectionMgr->clearSelected();
820 mySelectionMgr->clearFilters();
822 if (send == SelectElementsButton) {
823 myEditCurrentArgument = (QWidget*)LineEditElements;
824 if (CheckBoxMesh->isChecked()) {
825 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
826 aViewWindow->SetSelectionMode(ActorSelection);
827 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
829 int aConstructorId = GetConstructorId();
830 if (aConstructorId == 0)
832 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
833 aViewWindow->SetSelectionMode(EdgeSelection);
835 else if (aConstructorId == 1)
837 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
838 aViewWindow->SetSelectionMode(FaceSelection);
842 else if (send == SelectVectorButton){
843 myEditCurrentArgument = (QWidget*)SpinBox_Vx;
844 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
845 aViewWindow->SetSelectionMode(FaceSelection);
848 myEditCurrentArgument->setFocus();
849 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
850 SelectionIntoArgument();
853 //=================================================================================
854 // function : DeactivateActiveDialog()
855 // purpose : Deactivates this dialog
856 //=================================================================================
857 void SMESHGUI_ExtrusionDlg::DeactivateActiveDialog()
859 if (ConstructorsBox->isEnabled()) {
860 ConstructorsBox->setEnabled(false);
861 GroupArguments->setEnabled(false);
862 GroupButtons->setEnabled(false);
863 mySMESHGUI->ResetState();
864 mySMESHGUI->SetActiveDialogBox(0);
868 //=================================================================================
869 // function : ActivateThisDialog()
870 // purpose : Activates this dialog
871 //=================================================================================
872 void SMESHGUI_ExtrusionDlg::ActivateThisDialog()
874 // Emit a signal to deactivate the active dialog
875 mySMESHGUI->EmitSignalDeactivateDialog();
876 ConstructorsBox->setEnabled(true);
877 GroupArguments->setEnabled(true);
878 GroupButtons->setEnabled(true);
880 mySMESHGUI->SetActiveDialogBox(this);
882 ConstructorsClicked(GetConstructorId());
883 SelectionIntoArgument();
886 //=================================================================================
887 // function : enterEvent()
888 // purpose : Mouse enter event
889 //=================================================================================
890 void SMESHGUI_ExtrusionDlg::enterEvent (QEvent*)
892 if (!ConstructorsBox->isEnabled())
893 ActivateThisDialog();
896 //=================================================================================
897 // function : closeEvent()
899 //=================================================================================
900 void SMESHGUI_ExtrusionDlg::closeEvent( QCloseEvent* )
902 /* same than click on cancel button */
903 disconnect(mySelectionMgr, 0, this, 0);
904 mySelectionMgr->clearFilters();
905 //mySelectionMgr->clearSelected();
906 if (SMESH::GetCurrentVtkView()) {
907 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
908 SMESH::SetPointRepresentation(false);
909 SMESH::SetPickable();
911 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
912 aViewWindow->SetSelectionMode(ActorSelection);
913 mySMESHGUI->ResetState();
916 void SMESHGUI_ExtrusionDlg::reject()
922 //=================================================================================
923 // function : onSelectMesh()
925 //=================================================================================
926 void SMESHGUI_ExtrusionDlg::onSelectMesh (bool toSelectMesh)
929 myIDs = LineEditElements->text();
930 TextLabelElements->setText(tr("SMESH_NAME"));
933 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
935 myFilterBtn->setEnabled(!toSelectMesh);
937 if (myEditCurrentArgument != LineEditElements) {
938 LineEditElements->clear();
942 mySelectionMgr->clearFilters();
945 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
946 aViewWindow->SetSelectionMode(ActorSelection);
947 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
948 LineEditElements->setReadOnly(true);
949 LineEditElements->setValidator(0);
951 int aConstructorId = GetConstructorId();
952 if (aConstructorId == 0)
954 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
955 aViewWindow->SetSelectionMode(EdgeSelection);
957 else if (aConstructorId == 1)
959 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
960 aViewWindow->SetSelectionMode(FaceSelection);
963 LineEditElements->setReadOnly(false);
964 LineEditElements->setValidator(myIdValidator);
965 onTextChange(LineEditElements->text());
968 SelectionIntoArgument();
971 LineEditElements->setText( myIDs );
974 //=================================================================================
975 // function : GetConstructorId()
977 //=================================================================================
978 int SMESHGUI_ExtrusionDlg::GetConstructorId()
980 return GroupConstructors->checkedId();
983 //=================================================================================
984 // function : keyPressEvent()
986 //=================================================================================
987 void SMESHGUI_ExtrusionDlg::keyPressEvent( QKeyEvent* e )
989 QDialog::keyPressEvent( e );
990 if ( e->isAccepted() )
993 if ( e->key() == Qt::Key_F1 ) {
999 //=================================================================================
1000 // function : setFilters()
1001 // purpose : SLOT. Called when "Filter" button pressed.
1002 //=================================================================================
1003 void SMESHGUI_ExtrusionDlg::setFilters()
1005 if(myMesh->_is_nil()) {
1006 SUIT_MessageBox::critical(this,
1008 tr("NO_MESH_SELECTED"));
1014 types.append( SMESH::EDGE );
1015 types.append( SMESH::FACE );
1016 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, types );
1018 myFilterDlg->Init( GetConstructorId() ? SMESH::FACE : SMESH::EDGE );
1020 myFilterDlg->SetSelection();
1021 myFilterDlg->SetMesh( myMesh );
1022 myFilterDlg->SetSourceWg( LineEditElements );
1024 myFilterDlg->show();
1027 //=================================================================================
1028 // function : isValid
1030 //=================================================================================
1031 bool SMESHGUI_ExtrusionDlg::isValid()
1035 if ( RadioButton3->isChecked() ) {
1036 ok = SpinBox_Dx->isValid( msg, true ) && ok;
1037 ok = SpinBox_Dy->isValid( msg, true ) && ok;
1038 ok = SpinBox_Dz->isValid( msg, true ) && ok;
1039 } else if ( RadioButton4->isChecked() ) {
1040 ok = SpinBox_Vx->isValid( msg, true ) && ok;
1041 ok = SpinBox_Vy->isValid( msg, true ) && ok;
1042 ok = SpinBox_Vz->isValid( msg, true ) && ok;
1043 ok = SpinBox_VDist->isValid( msg, true ) && ok;
1045 ok = SpinBox_NbSteps->isValid( msg, true ) && ok;
1048 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1049 if ( !msg.isEmpty() )
1051 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1057 //=================================================================================
1058 // function : onDisplaySimulation
1059 // purpose : Show/Hide preview
1060 //=================================================================================
1061 void SMESHGUI_ExtrusionDlg::onDisplaySimulation( bool toDisplayPreview ) {
1062 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1063 if (myNbOkElements && isValid() && isValuesValid()) {
1065 SMESH::DirStruct aVector;
1066 getExtrusionVector(aVector);
1068 //Get Number of the steps
1069 long aNbSteps = (long)SpinBox_NbSteps->value();
1072 SUIT_OverrideCursor aWaitCursor;
1073 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
1074 if( CheckBoxMesh->isChecked() ) {
1075 if( GetConstructorId() == 0 )
1076 aMeshEditor->ExtrusionSweepObject1D(mySelectedObject, aVector, aNbSteps);
1078 aMeshEditor->ExtrusionSweepObject2D(mySelectedObject, aVector, aNbSteps);
1081 aMeshEditor->ExtrusionSweep(myElementsId.inout(), aVector, aNbSteps);
1083 SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
1084 mySimulation->SetData(aMeshPreviewStruct._retn());
1096 //=================================================================================
1097 // function : getExtrusionVector()
1098 // purpose : get direction of the extrusion
1099 //=================================================================================
1100 void SMESHGUI_ExtrusionDlg::getExtrusionVector(SMESH::DirStruct& aVector) {
1101 if ( RadioButton3->isChecked() ) {
1102 aVector.PS.x = SpinBox_Dx->GetValue();
1103 aVector.PS.y = SpinBox_Dy->GetValue();
1104 aVector.PS.z = SpinBox_Dz->GetValue();
1105 } else if ( RadioButton4->isChecked() ) {
1106 gp_XYZ aNormale(SpinBox_Vx->GetValue(),
1107 SpinBox_Vy->GetValue(),
1108 SpinBox_Vz->GetValue());
1111 aNormale /= aNormale.Modulus();
1112 long aVDist = (long)SpinBox_VDist->value();
1114 aVector.PS.x = aNormale.X()*aVDist;
1115 aVector.PS.y = aNormale.Y()*aVDist;
1116 aVector.PS.z = aNormale.Z()*aVDist;