1 // Copyright (C) 2007-2008 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
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_ExtrusionDlg.cxx
24 // Author : Michael ZORIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_ExtrusionDlg.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_SpinBox.h"
34 #include "SMESHGUI_IdValidator.h"
35 #include "SMESHGUI_FilterDlg.h"
37 #include <SMESH_Actor.h>
38 #include <SMESH_TypeFilter.hxx>
39 #include <SMESH_LogicalFilter.hxx>
41 #include <SMDS_Mesh.hxx>
43 // SALOME GUI includes
44 #include <SUIT_ResourceMgr.h>
45 #include <SUIT_Desktop.h>
46 #include <SUIT_MessageBox.h>
47 #include <SUIT_Session.h>
48 #include <SUIT_OverrideCursor.h>
50 #include <LightApp_Application.h>
51 #include <LightApp_SelectionMgr.h>
53 #include <SVTK_ViewModel.h>
54 #include <SVTK_ViewWindow.h>
56 #include <SalomeApp_Notebook.h>
57 #include <SalomeApp_IntSpinBox.h>
60 #include <TColStd_MapOfInteger.hxx>
61 #include <TColStd_IndexedMapOfInteger.hxx>
65 #include <QApplication>
66 #include <QButtonGroup>
70 #include <QPushButton>
71 #include <QRadioButton>
73 #include <QHBoxLayout>
74 #include <QVBoxLayout>
75 #include <QGridLayout>
79 #include <SALOMEconfig.h>
80 #include CORBA_SERVER_HEADER(SMESH_Group)
81 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
86 //=================================================================================
87 // function : SMESHGUI_ExtrusionDlg()
88 // purpose : constructor
89 //=================================================================================
90 SMESHGUI_ExtrusionDlg::SMESHGUI_ExtrusionDlg (SMESHGUI* theModule)
91 : QDialog( SMESH::GetDesktop( theModule ) ),
92 SMESHGUI_Helper( theModule ),
93 mySMESHGUI( theModule ),
94 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
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")));
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 RadioButton1= new QRadioButton(ConstructorsBox);
119 RadioButton1->setIcon(image0);
120 RadioButton2= new QRadioButton(ConstructorsBox);
121 RadioButton2->setIcon(image1);
123 ConstructorsBoxLayout->addWidget(RadioButton1);
124 ConstructorsBoxLayout->addWidget(RadioButton2);
126 GroupConstructors->addButton(RadioButton1, 0);
127 GroupConstructors->addButton(RadioButton2, 1);
129 /***************************************************************/
130 GroupButtons = new QGroupBox(this);
131 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
132 GroupButtonsLayout->setSpacing(SPACING);
133 GroupButtonsLayout->setMargin(MARGIN);
135 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
136 buttonOk->setAutoDefault(true);
137 buttonOk->setDefault(true);
138 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
139 buttonApply->setAutoDefault(true);
140 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
141 buttonCancel->setAutoDefault(true);
142 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
143 buttonHelp->setAutoDefault(true);
145 GroupButtonsLayout->addWidget(buttonOk);
146 GroupButtonsLayout->addSpacing(10);
147 GroupButtonsLayout->addWidget(buttonApply);
148 GroupButtonsLayout->addSpacing(10);
149 GroupButtonsLayout->addStretch();
150 GroupButtonsLayout->addWidget(buttonCancel);
151 GroupButtonsLayout->addWidget(buttonHelp);
153 /***************************************************************/
154 GroupArguments = new QGroupBox(tr("EXTRUSION_1D"), this);
155 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
156 GroupArgumentsLayout->setSpacing(SPACING);
157 GroupArgumentsLayout->setMargin(MARGIN);
159 myIdValidator = new SMESHGUI_IdValidator(this);
161 // Controls for elements selection
162 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
164 SelectElementsButton = new QPushButton(GroupArguments);
165 SelectElementsButton->setIcon(image2);
167 LineEditElements = new QLineEdit(GroupArguments);
168 LineEditElements->setValidator(myIdValidator);
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);
218 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
219 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
220 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 5);
221 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 7);
222 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
223 GroupArgumentsLayout->addWidget(RadioButton3, 2, 1, 1, 3);
224 GroupArgumentsLayout->addWidget(RadioButton4, 2, 5, 1, 3);
225 GroupArgumentsLayout->addWidget(TextLabelDistance, 3, 0);
226 GroupArgumentsLayout->addWidget(TextLabelDx, 3, 2);
227 GroupArgumentsLayout->addWidget(SpinBox_Dx, 3, 3);
228 GroupArgumentsLayout->addWidget(TextLabelDy, 3, 4);
229 GroupArgumentsLayout->addWidget(SpinBox_Dy, 3, 5);
230 GroupArgumentsLayout->addWidget(TextLabelDz, 3, 6);
231 GroupArgumentsLayout->addWidget(SpinBox_Dz, 3, 7);
232 GroupArgumentsLayout->addWidget(TextLabelVector, 4, 0);
233 GroupArgumentsLayout->addWidget(SelectVectorButton, 4, 1);
234 GroupArgumentsLayout->addWidget(TextLabelVx, 4, 2);
235 GroupArgumentsLayout->addWidget(SpinBox_Vx, 4, 3);
236 GroupArgumentsLayout->addWidget(TextLabelVy, 4, 4);
237 GroupArgumentsLayout->addWidget(SpinBox_Vy, 4, 5);
238 GroupArgumentsLayout->addWidget(TextLabelVz, 4, 6);
239 GroupArgumentsLayout->addWidget(SpinBox_Vz, 4, 7);
240 GroupArgumentsLayout->addWidget(TextLabelDist, 5, 0);
241 GroupArgumentsLayout->addWidget(SpinBox_VDist, 5, 3);
242 GroupArgumentsLayout->addWidget(TextLabelNbSteps, 6, 0, 1, 3);
243 GroupArgumentsLayout->addWidget(SpinBox_NbSteps, 6, 3);
244 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 7, 0, 1, 8);
245 GroupArgumentsLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding), 8, 0);
248 /***************************************************************/
249 SMESHGUI_ExtrusionDlgLayout->addWidget(ConstructorsBox);
250 SMESHGUI_ExtrusionDlgLayout->addWidget(GroupArguments);
251 SMESHGUI_ExtrusionDlgLayout->addWidget(GroupButtons);
253 /* Initialisations */
254 SpinBox_Vx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, 3);
255 SpinBox_Vy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, 3);
256 SpinBox_Vz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, 3);
258 SpinBox_Dx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
259 SpinBox_Dy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
260 SpinBox_Dz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
262 SpinBox_NbSteps->setRange(1, 999999);
263 SpinBox_VDist->RangeStepAndValidator(0, COORD_MAX, 10.0, 3);
265 RadioButton1->setChecked(true);
266 RadioButton3->setChecked(true);
267 MakeGroupsCheck->setChecked(true);
269 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
271 mySMESHGUI->SetActiveDialogBox(this);
273 // Costruction of the logical filter for the elements: mesh/sub-mesh/group
274 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
275 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
277 QList<SUIT_SelectionFilter*> aListOfFilters;
278 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
279 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
281 myMeshOrSubMeshOrGroupFilter =
282 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
284 myHelpFileName = "extrusion_page.html";
288 /***************************************************************/
289 // signals and slots connections
290 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
291 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
292 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
293 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
295 connect(RadioButton3, SIGNAL(clicked()), this, SLOT(ClickOnRadio()));
296 connect(RadioButton4, SIGNAL(clicked()), this, SLOT(ClickOnRadio()));
298 // to update state of the Ok & Apply buttons
299 connect(SpinBox_Vx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
300 connect(SpinBox_Vy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
301 connect(SpinBox_Vz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
302 connect(SpinBox_Dx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
303 connect(SpinBox_Dy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
304 connect(SpinBox_Dz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
306 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
307 connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
308 connect(SelectVectorButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
309 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
310 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
311 /* to close dialog if study change */
312 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
313 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
314 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
316 /***************************************************************/
318 ConstructorsClicked(0);
320 SelectionIntoArgument();
323 //=================================================================================
324 // function : ~SMESHGUI_ExtrusionDlg()
325 // purpose : destructor
326 //=================================================================================
327 SMESHGUI_ExtrusionDlg::~SMESHGUI_ExtrusionDlg()
329 if ( myFilterDlg != 0 ) {
330 myFilterDlg->setParent( 0 );
335 //=================================================================================
337 // purpose : initialization
338 //=================================================================================
339 void SMESHGUI_ExtrusionDlg::Init (bool ResetControls)
344 LineEditElements->clear();
348 myMesh = SMESH::SMESH_Mesh::_nil();
351 SpinBox_NbSteps->setValue(1);
352 SpinBox_VDist->setValue(10);
353 SpinBox_Dx->SetValue(0);
354 SpinBox_Dy->SetValue(0);
355 SpinBox_Dz->SetValue(0);
356 SpinBox_Vx->SetValue(0);
357 SpinBox_Vy->SetValue(0);
358 SpinBox_Vz->SetValue(0);
360 CheckBoxMesh->setChecked(false);
367 //=================================================================================
368 // function : CheckIsEnable()
369 // purpose : Check whether the Ok and Apply buttons should be enabled or not
370 //=================================================================================
371 void SMESHGUI_ExtrusionDlg::CheckIsEnable()
373 double aX, aY, aZ, aModule;
374 if ( RadioButton3->isChecked() ) {
375 aX = SpinBox_Dx->GetValue();
376 aY = SpinBox_Dy->GetValue();
377 aZ = SpinBox_Dz->GetValue();
378 aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
379 } else if ( RadioButton4->isChecked() ) {
380 aX = SpinBox_Vx->GetValue();
381 aY = SpinBox_Vy->GetValue();
382 aZ = SpinBox_Vz->GetValue();
383 aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
386 bool anIsEnable = myNbOkElements > 0 && aModule > 1.0E-38;
388 buttonOk->setEnabled(anIsEnable);
389 buttonApply->setEnabled(anIsEnable);
392 //=================================================================================
393 // function : ConstructorsClicked()
394 // purpose : Radio button management
395 //=================================================================================
396 void SMESHGUI_ExtrusionDlg::ConstructorsClicked (int constructorId)
398 disconnect(mySelectionMgr, 0, this, 0);
400 switch (constructorId) {
403 GroupArguments->setTitle(tr("EXTRUSION_1D"));
404 if (!CheckBoxMesh->isChecked())
406 LineEditElements->clear();
408 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
409 aViewWindow->SetSelectionMode(EdgeSelection);
415 GroupArguments->setTitle(tr("EXTRUSION_2D"));
416 if (!CheckBoxMesh->isChecked())
418 LineEditElements->clear();
420 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
421 aViewWindow->SetSelectionMode(FaceSelection);
427 myEditCurrentArgument = (QWidget*)LineEditElements;
428 LineEditElements->setFocus();
430 if (CheckBoxMesh->isChecked())
433 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
436 //=================================================================================
437 // function : ConstructorsClicked()
438 // purpose : Radio button management
439 //=================================================================================
440 void SMESHGUI_ExtrusionDlg::ClickOnRadio()
442 if ( RadioButton3->isChecked() ) {
443 TextLabelDistance->show();
451 TextLabelVector->hide();
458 TextLabelDist->hide();
459 SpinBox_VDist->hide();
460 SelectVectorButton->hide();
461 } else if ( RadioButton4->isChecked() ) {
462 TextLabelDistance->hide();
470 TextLabelVector->show();
477 TextLabelDist->show();
478 SpinBox_VDist->show();
479 SelectVectorButton->show();
482 qApp->processEvents();
484 resize( minimumSizeHint() );
487 //=================================================================================
488 // function : ClickOnApply()
489 // purpose : Called when user presses <Apply> button
490 //=================================================================================
491 bool SMESHGUI_ExtrusionDlg::ClickOnApply()
493 if (mySMESHGUI->isActiveStudyLocked())
499 if (myNbOkElements) {
501 SMESH::DirStruct aVector;
502 QStringList aParameters;
504 if ( RadioButton3->isChecked() ) {
505 aVector.PS.x = SpinBox_Dx->GetValue();
506 aVector.PS.y = SpinBox_Dy->GetValue();
507 aVector.PS.z = SpinBox_Dz->GetValue();
509 aParameters << SpinBox_Dx->text();
510 aParameters << SpinBox_Dy->text();
511 aParameters << SpinBox_Dz->text();
512 } else if ( RadioButton4->isChecked() ) {
513 gp_XYZ aNormale(SpinBox_Vx->GetValue(),
514 SpinBox_Vy->GetValue(),
515 SpinBox_Vz->GetValue());
518 aNormale /= aNormale.Modulus();
519 long aVDist = (long)SpinBox_VDist->value();
521 aVector.PS.x = aNormale.X()*aVDist;
522 aVector.PS.y = aNormale.Y()*aVDist;
523 aVector.PS.z = aNormale.Z()*aVDist;
525 aParameters << SpinBox_Vx->text();
526 aParameters << SpinBox_Vy->text();
527 aParameters << SpinBox_Vz->text();
528 aParameters << SpinBox_VDist->text();
531 long aNbSteps = (long)SpinBox_NbSteps->value();
533 aParameters << SpinBox_NbSteps->text();
536 SUIT_OverrideCursor aWaitCursor;
537 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
539 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) {
540 if( CheckBoxMesh->isChecked() ) {
541 if( GetConstructorId() == 0 )
542 SMESH::ListOfGroups_var groups =
543 aMeshEditor->ExtrusionSweepObject1DMakeGroups(mySelectedObject, aVector, aNbSteps);
545 SMESH::ListOfGroups_var groups =
546 aMeshEditor->ExtrusionSweepObject2DMakeGroups(mySelectedObject, aVector, aNbSteps);
549 SMESH::ListOfGroups_var groups =
550 aMeshEditor->ExtrusionSweepMakeGroups(myElementsId.inout(), aVector, aNbSteps);
553 if( CheckBoxMesh->isChecked() ) {
554 if( GetConstructorId() == 0 )
555 aMeshEditor->ExtrusionSweepObject1D(mySelectedObject, aVector, aNbSteps);
557 aMeshEditor->ExtrusionSweepObject2D(mySelectedObject, aVector, aNbSteps);
560 aMeshEditor->ExtrusionSweep(myElementsId.inout(), aVector, aNbSteps);
563 getNotebook()->setParameters( myMesh, aParameters );
568 SMESH::Update(myIO, SMESH::eDisplay);
569 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() )
570 mySMESHGUI->updateObjBrowser(true); // new groups may appear
572 ConstructorsClicked(GetConstructorId());
573 mySelectionMgr->clearSelected();
574 mySelectedObject = SMESH::SMESH_IDSource::_nil();
575 SelectionIntoArgument();
580 //=================================================================================
581 // function : ClickOnOk()
582 // purpose : Called when user presses <OK> button
583 //=================================================================================
584 void SMESHGUI_ExtrusionDlg::ClickOnOk()
590 //=================================================================================
591 // function : ClickOnCancel()
592 // purpose : Called when dialog box is closed
593 //=================================================================================
594 void SMESHGUI_ExtrusionDlg::ClickOnCancel()
599 //=================================================================================
600 // function : ClickOnHelp()
602 //=================================================================================
603 void SMESHGUI_ExtrusionDlg::ClickOnHelp()
605 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
607 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
611 platform = "winapplication";
613 platform = "application";
615 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
616 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
617 arg(app->resourceMgr()->stringValue("ExternalBrowser",
619 arg(myHelpFileName));
623 //=================================================================================
624 // function : onTextChange()
626 //=================================================================================
627 void SMESHGUI_ExtrusionDlg::onTextChange (const QString& theNewText)
629 QLineEdit* send = (QLineEdit*)sender();
637 if (send == LineEditElements)
640 // hilight entered elements/nodes
642 if (!myIO.IsNull()) {
643 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
645 if (send == LineEditElements)
647 SMDS_Mesh* aMesh = myActor ? myActor->GetObject()->GetMesh() : 0;
648 SMESH::ElementType SMESHType = GetConstructorId() ? SMESH::FACE : SMESH::EDGE;
649 SMDSAbs_ElementType SMDSType = GetConstructorId() ? SMDSAbs_Face: SMDSAbs_Edge;
651 myElementsId = new SMESH::long_array;
652 myElementsId->length( aListId.count() );
653 TColStd_MapOfInteger newIndices;
654 for (int i = 0; i < aListId.count(); i++) {
655 int id = aListId[ i ].toInt();
656 bool validId = false;
659 const SMDS_MeshElement * e = aMesh->FindElement( id );
660 validId = ( e && e->GetType() == SMDSType );
662 validId = ( myMesh->GetElementType( id, true ) == SMESHType );
665 if ( validId && newIndices.Add( id ))
666 myElementsId[ newIndices.Extent()-1 ] = id;
668 myElementsId->length( myNbOkElements = newIndices.Extent() );
669 mySelector->AddOrRemoveIndex(myIO, newIndices, false);
670 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
671 aViewWindow->highlight( myIO, true, true );
680 //=================================================================================
681 // function : SelectionIntoArgument()
682 // purpose : Called when selection as changed or other case
683 //=================================================================================
684 void SMESHGUI_ExtrusionDlg::SelectionIntoArgument()
688 // return if dialog box is inactive
689 if (!GroupButtons->isEnabled())
693 if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
695 Handle(SALOME_InteractiveObject) resIO = myIO;
699 QString aString = "";
701 if(myEditCurrentArgument == (QWidget*)LineEditElements) {
703 LineEditElements->setText(aString);
709 mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
710 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
714 Handle(SALOME_InteractiveObject) IO = aList.First();
716 if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
717 myMesh = SMESH::GetMeshByIO(IO);
718 if (myMesh->_is_nil())
721 myActor = SMESH::FindActorByObject(myMesh);
724 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
727 // MakeGroups is available if there are groups
728 if ( myMesh->NbGroups() == 0 ) {
729 MakeGroupsCheck->setChecked(false);
730 MakeGroupsCheck->setEnabled(false);
732 MakeGroupsCheck->setEnabled(true);
735 if (CheckBoxMesh->isChecked()) {
736 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
738 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
739 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
743 // get indices of selcted elements
744 TColStd_IndexedMapOfInteger aMapIndex;
745 mySelector->GetIndex(IO,aMapIndex);
746 aNbElements = aMapIndex.Extent();
751 myElementsId = new SMESH::long_array;
752 myElementsId->length( aNbElements );
754 for ( int i = 0; i < aNbElements; ++i )
755 aString += QString(" %1").arg( myElementsId[ i ] = aMapIndex( i+1 ) );
758 myNbOkElements = true;
761 ((QLineEdit*)myEditCurrentArgument)->setText(aString);
764 else if(myEditCurrentArgument == (QWidget*)SpinBox_Vx){
765 TColStd_IndexedMapOfInteger aMapIndex;
766 mySelector->GetIndex(IO,aMapIndex);
767 int aNbElements = aMapIndex.Extent();
768 SMESH::SMESH_Mesh_var aMesh_var = SMESH::GetMeshByIO(IO);
769 SMESH_Actor* anActor = SMESH::FindActorByObject(aMesh_var);
770 SMDS_Mesh* aMesh = anActor ? anActor->GetObject()->GetMesh() : 0;
772 if(aNbElements != 1 || !aMesh)
775 const SMDS_MeshFace* face = dynamic_cast<const SMDS_MeshFace*>(aMesh->FindElement(aMapIndex(aNbElements)));
780 gp_XYZ aNormale = SMESH::getNormale(face);
781 SpinBox_Vx->SetValue(aNormale.X());
782 SpinBox_Vy->SetValue(aNormale.Y());
783 SpinBox_Vz->SetValue(aNormale.Z());
791 //=================================================================================
792 // function : SetEditCurrentArgument()
794 //=================================================================================
795 void SMESHGUI_ExtrusionDlg::SetEditCurrentArgument()
797 QPushButton* send = (QPushButton*)sender();
799 disconnect(mySelectionMgr, 0, this, 0);
800 mySelectionMgr->clearSelected();
801 mySelectionMgr->clearFilters();
803 if (send == SelectElementsButton) {
804 myEditCurrentArgument = (QWidget*)LineEditElements;
805 if (CheckBoxMesh->isChecked()) {
806 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
807 aViewWindow->SetSelectionMode(ActorSelection);
808 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
810 int aConstructorId = GetConstructorId();
811 if (aConstructorId == 0)
813 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
814 aViewWindow->SetSelectionMode(EdgeSelection);
816 else if (aConstructorId == 1)
818 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
819 aViewWindow->SetSelectionMode(FaceSelection);
823 else if (send == SelectVectorButton){
824 myEditCurrentArgument = (QWidget*)SpinBox_Vx;
825 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
826 aViewWindow->SetSelectionMode(FaceSelection);
829 myEditCurrentArgument->setFocus();
830 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
831 SelectionIntoArgument();
834 //=================================================================================
835 // function : DeactivateActiveDialog()
836 // purpose : Deactivates this dialog
837 //=================================================================================
838 void SMESHGUI_ExtrusionDlg::DeactivateActiveDialog()
840 if (ConstructorsBox->isEnabled()) {
841 ConstructorsBox->setEnabled(false);
842 GroupArguments->setEnabled(false);
843 GroupButtons->setEnabled(false);
844 mySMESHGUI->ResetState();
845 mySMESHGUI->SetActiveDialogBox(0);
849 //=================================================================================
850 // function : ActivateThisDialog()
851 // purpose : Activates this dialog
852 //=================================================================================
853 void SMESHGUI_ExtrusionDlg::ActivateThisDialog()
855 // Emit a signal to deactivate the active dialog
856 mySMESHGUI->EmitSignalDeactivateDialog();
857 ConstructorsBox->setEnabled(true);
858 GroupArguments->setEnabled(true);
859 GroupButtons->setEnabled(true);
861 mySMESHGUI->SetActiveDialogBox(this);
863 ConstructorsClicked(GetConstructorId());
864 SelectionIntoArgument();
867 //=================================================================================
868 // function : enterEvent()
869 // purpose : Mouse enter event
870 //=================================================================================
871 void SMESHGUI_ExtrusionDlg::enterEvent (QEvent*)
873 if (!ConstructorsBox->isEnabled())
874 ActivateThisDialog();
877 //=================================================================================
878 // function : closeEvent()
880 //=================================================================================
881 void SMESHGUI_ExtrusionDlg::closeEvent( QCloseEvent* )
883 /* same than click on cancel button */
884 disconnect(mySelectionMgr, 0, this, 0);
885 mySelectionMgr->clearFilters();
886 //mySelectionMgr->clearSelected();
887 if (SMESH::GetCurrentVtkView()) {
888 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
889 SMESH::SetPointRepresentation(false);
890 SMESH::SetPickable();
892 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
893 aViewWindow->SetSelectionMode(ActorSelection);
894 mySMESHGUI->ResetState();
897 void SMESHGUI_ExtrusionDlg::reject()
903 //=================================================================================
904 // function : onSelectMesh()
906 //=================================================================================
907 void SMESHGUI_ExtrusionDlg::onSelectMesh (bool toSelectMesh)
910 myIDs = LineEditElements->text();
911 TextLabelElements->setText(tr("SMESH_NAME"));
914 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
916 myFilterBtn->setEnabled(!toSelectMesh);
918 if (myEditCurrentArgument != LineEditElements) {
919 LineEditElements->clear();
923 mySelectionMgr->clearFilters();
926 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
927 aViewWindow->SetSelectionMode(ActorSelection);
928 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
929 LineEditElements->setReadOnly(true);
930 LineEditElements->setValidator(0);
932 int aConstructorId = GetConstructorId();
933 if (aConstructorId == 0)
935 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
936 aViewWindow->SetSelectionMode(EdgeSelection);
938 else if (aConstructorId == 1)
940 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
941 aViewWindow->SetSelectionMode(FaceSelection);
944 LineEditElements->setReadOnly(false);
945 LineEditElements->setValidator(myIdValidator);
946 onTextChange(LineEditElements->text());
949 SelectionIntoArgument();
952 LineEditElements->setText( myIDs );
955 //=================================================================================
956 // function : GetConstructorId()
958 //=================================================================================
959 int SMESHGUI_ExtrusionDlg::GetConstructorId()
961 return GroupConstructors->checkedId();
964 //=================================================================================
965 // function : keyPressEvent()
967 //=================================================================================
968 void SMESHGUI_ExtrusionDlg::keyPressEvent( QKeyEvent* e )
970 QDialog::keyPressEvent( e );
971 if ( e->isAccepted() )
974 if ( e->key() == Qt::Key_F1 ) {
980 //=================================================================================
981 // function : setFilters()
982 // purpose : SLOT. Called when "Filter" button pressed.
983 //=================================================================================
984 void SMESHGUI_ExtrusionDlg::setFilters()
986 if(myMesh->_is_nil()) {
987 SUIT_MessageBox::critical(this,
989 tr("NO_MESH_SELECTED"));
995 types.append( SMESH::EDGE );
996 types.append( SMESH::FACE );
997 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, types );
999 myFilterDlg->Init( GetConstructorId() ? SMESH::FACE : SMESH::EDGE );
1001 myFilterDlg->SetSelection();
1002 myFilterDlg->SetMesh( myMesh );
1003 myFilterDlg->SetSourceWg( LineEditElements );
1005 myFilterDlg->show();
1008 //=================================================================================
1009 // function : isValid
1011 //=================================================================================
1012 bool SMESHGUI_ExtrusionDlg::isValid()
1014 QList<QAbstractSpinBox*> aSpinBoxList;
1015 if ( RadioButton3->isChecked() )
1016 aSpinBoxList << SpinBox_Dx << SpinBox_Dy << SpinBox_Dz;
1017 else if ( RadioButton4->isChecked() )
1018 aSpinBoxList << SpinBox_Vx << SpinBox_Vy << SpinBox_Vz;
1019 aSpinBoxList << SpinBox_NbSteps;
1020 return checkParameters( true, aSpinBoxList );