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"
38 #include <SMESH_Actor.h>
39 #include <SMESH_TypeFilter.hxx>
40 #include <SMESH_LogicalFilter.hxx>
42 #include <SMDS_Mesh.hxx>
44 // SALOME GUI includes
45 #include <SUIT_ResourceMgr.h>
46 #include <SUIT_Desktop.h>
47 #include <SUIT_MessageBox.h>
48 #include <SUIT_Session.h>
49 #include <SUIT_OverrideCursor.h>
51 #include <LightApp_Application.h>
52 #include <LightApp_SelectionMgr.h>
54 #include <SVTK_ViewModel.h>
55 #include <SVTK_ViewWindow.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 mySMESHGUI( 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);
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, "length_precision");
255 SpinBox_Vy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, "length_precision");
256 SpinBox_Vz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, "length_precision");
258 SpinBox_Dx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
259 SpinBox_Dy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
260 SpinBox_Dz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
262 SpinBox_NbSteps->setRange(1, 999999);
263 SpinBox_VDist->RangeStepAndValidator(0, COORD_MAX, 10.0, "length_precision");
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 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
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();
577 SMESHGUI::Modified();
582 //=================================================================================
583 // function : ClickOnOk()
584 // purpose : Called when user presses <OK> button
585 //=================================================================================
586 void SMESHGUI_ExtrusionDlg::ClickOnOk()
592 //=================================================================================
593 // function : ClickOnCancel()
594 // purpose : Called when dialog box is closed
595 //=================================================================================
596 void SMESHGUI_ExtrusionDlg::ClickOnCancel()
601 //=================================================================================
602 // function : ClickOnHelp()
604 //=================================================================================
605 void SMESHGUI_ExtrusionDlg::ClickOnHelp()
607 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
609 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
613 platform = "winapplication";
615 platform = "application";
617 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
618 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
619 arg(app->resourceMgr()->stringValue("ExternalBrowser",
621 arg(myHelpFileName));
625 //=================================================================================
626 // function : onTextChange()
628 //=================================================================================
629 void SMESHGUI_ExtrusionDlg::onTextChange (const QString& theNewText)
631 QLineEdit* send = (QLineEdit*)sender();
639 if (send == LineEditElements)
642 // hilight entered elements/nodes
644 if (!myIO.IsNull()) {
645 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
647 if (send == LineEditElements)
649 SMDS_Mesh* aMesh = myActor ? myActor->GetObject()->GetMesh() : 0;
650 SMESH::ElementType SMESHType = GetConstructorId() ? SMESH::FACE : SMESH::EDGE;
651 SMDSAbs_ElementType SMDSType = GetConstructorId() ? SMDSAbs_Face: SMDSAbs_Edge;
653 myElementsId = new SMESH::long_array;
654 myElementsId->length( aListId.count() );
655 TColStd_MapOfInteger newIndices;
656 for (int i = 0; i < aListId.count(); i++) {
657 int id = aListId[ i ].toInt();
658 bool validId = false;
661 const SMDS_MeshElement * e = aMesh->FindElement( id );
662 validId = ( e && e->GetType() == SMDSType );
664 validId = ( myMesh->GetElementType( id, true ) == SMESHType );
667 if ( validId && newIndices.Add( id ))
668 myElementsId[ newIndices.Extent()-1 ] = id;
670 myElementsId->length( myNbOkElements = newIndices.Extent() );
671 mySelector->AddOrRemoveIndex(myIO, newIndices, false);
672 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
673 aViewWindow->highlight( myIO, true, true );
682 //=================================================================================
683 // function : SelectionIntoArgument()
684 // purpose : Called when selection as changed or other case
685 //=================================================================================
686 void SMESHGUI_ExtrusionDlg::SelectionIntoArgument()
690 // return if dialog box is inactive
691 if (!GroupButtons->isEnabled())
695 if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
697 Handle(SALOME_InteractiveObject) resIO = myIO;
701 QString aString = "";
703 if(myEditCurrentArgument == (QWidget*)LineEditElements) {
705 LineEditElements->setText(aString);
711 mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
712 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
716 Handle(SALOME_InteractiveObject) IO = aList.First();
718 if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
719 myMesh = SMESH::GetMeshByIO(IO);
720 if (myMesh->_is_nil())
723 myActor = SMESH::FindActorByObject(myMesh);
726 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
729 // MakeGroups is available if there are groups
730 if ( myMesh->NbGroups() == 0 ) {
731 MakeGroupsCheck->setChecked(false);
732 MakeGroupsCheck->setEnabled(false);
734 MakeGroupsCheck->setEnabled(true);
737 if (CheckBoxMesh->isChecked()) {
738 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
740 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
741 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
745 // get indices of selcted elements
746 TColStd_IndexedMapOfInteger aMapIndex;
747 mySelector->GetIndex(IO,aMapIndex);
748 aNbElements = aMapIndex.Extent();
753 myElementsId = new SMESH::long_array;
754 myElementsId->length( aNbElements );
756 for ( int i = 0; i < aNbElements; ++i )
757 aString += QString(" %1").arg( myElementsId[ i ] = aMapIndex( i+1 ) );
760 myNbOkElements = true;
763 ((QLineEdit*)myEditCurrentArgument)->setText(aString);
766 else if(myEditCurrentArgument == (QWidget*)SpinBox_Vx){
767 TColStd_IndexedMapOfInteger aMapIndex;
768 mySelector->GetIndex(IO,aMapIndex);
769 int aNbElements = aMapIndex.Extent();
770 SMESH::SMESH_Mesh_var aMesh_var = SMESH::GetMeshByIO(IO);
771 SMESH_Actor* anActor = SMESH::FindActorByObject(aMesh_var);
772 SMDS_Mesh* aMesh = anActor ? anActor->GetObject()->GetMesh() : 0;
774 if(aNbElements != 1 || !aMesh)
777 const SMDS_MeshFace* face = dynamic_cast<const SMDS_MeshFace*>(aMesh->FindElement(aMapIndex(aNbElements)));
782 gp_XYZ aNormale = SMESH::getNormale(face);
783 SpinBox_Vx->SetValue(aNormale.X());
784 SpinBox_Vy->SetValue(aNormale.Y());
785 SpinBox_Vz->SetValue(aNormale.Z());
793 //=================================================================================
794 // function : SetEditCurrentArgument()
796 //=================================================================================
797 void SMESHGUI_ExtrusionDlg::SetEditCurrentArgument()
799 QPushButton* send = (QPushButton*)sender();
801 disconnect(mySelectionMgr, 0, this, 0);
802 mySelectionMgr->clearSelected();
803 mySelectionMgr->clearFilters();
805 if (send == SelectElementsButton) {
806 myEditCurrentArgument = (QWidget*)LineEditElements;
807 if (CheckBoxMesh->isChecked()) {
808 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
809 aViewWindow->SetSelectionMode(ActorSelection);
810 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
812 int aConstructorId = GetConstructorId();
813 if (aConstructorId == 0)
815 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
816 aViewWindow->SetSelectionMode(EdgeSelection);
818 else if (aConstructorId == 1)
820 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
821 aViewWindow->SetSelectionMode(FaceSelection);
825 else if (send == SelectVectorButton){
826 myEditCurrentArgument = (QWidget*)SpinBox_Vx;
827 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
828 aViewWindow->SetSelectionMode(FaceSelection);
831 myEditCurrentArgument->setFocus();
832 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
833 SelectionIntoArgument();
836 //=================================================================================
837 // function : DeactivateActiveDialog()
838 // purpose : Deactivates this dialog
839 //=================================================================================
840 void SMESHGUI_ExtrusionDlg::DeactivateActiveDialog()
842 if (ConstructorsBox->isEnabled()) {
843 ConstructorsBox->setEnabled(false);
844 GroupArguments->setEnabled(false);
845 GroupButtons->setEnabled(false);
846 mySMESHGUI->ResetState();
847 mySMESHGUI->SetActiveDialogBox(0);
851 //=================================================================================
852 // function : ActivateThisDialog()
853 // purpose : Activates this dialog
854 //=================================================================================
855 void SMESHGUI_ExtrusionDlg::ActivateThisDialog()
857 // Emit a signal to deactivate the active dialog
858 mySMESHGUI->EmitSignalDeactivateDialog();
859 ConstructorsBox->setEnabled(true);
860 GroupArguments->setEnabled(true);
861 GroupButtons->setEnabled(true);
863 mySMESHGUI->SetActiveDialogBox(this);
865 ConstructorsClicked(GetConstructorId());
866 SelectionIntoArgument();
869 //=================================================================================
870 // function : enterEvent()
871 // purpose : Mouse enter event
872 //=================================================================================
873 void SMESHGUI_ExtrusionDlg::enterEvent (QEvent*)
875 if (!ConstructorsBox->isEnabled())
876 ActivateThisDialog();
879 //=================================================================================
880 // function : closeEvent()
882 //=================================================================================
883 void SMESHGUI_ExtrusionDlg::closeEvent( QCloseEvent* )
885 /* same than click on cancel button */
886 disconnect(mySelectionMgr, 0, this, 0);
887 mySelectionMgr->clearFilters();
888 //mySelectionMgr->clearSelected();
889 if (SMESH::GetCurrentVtkView()) {
890 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
891 SMESH::SetPointRepresentation(false);
892 SMESH::SetPickable();
894 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
895 aViewWindow->SetSelectionMode(ActorSelection);
896 mySMESHGUI->ResetState();
899 void SMESHGUI_ExtrusionDlg::reject()
905 //=================================================================================
906 // function : onSelectMesh()
908 //=================================================================================
909 void SMESHGUI_ExtrusionDlg::onSelectMesh (bool toSelectMesh)
912 myIDs = LineEditElements->text();
913 TextLabelElements->setText(tr("SMESH_NAME"));
916 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
918 myFilterBtn->setEnabled(!toSelectMesh);
920 if (myEditCurrentArgument != LineEditElements) {
921 LineEditElements->clear();
925 mySelectionMgr->clearFilters();
928 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
929 aViewWindow->SetSelectionMode(ActorSelection);
930 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
931 LineEditElements->setReadOnly(true);
932 LineEditElements->setValidator(0);
934 int aConstructorId = GetConstructorId();
935 if (aConstructorId == 0)
937 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
938 aViewWindow->SetSelectionMode(EdgeSelection);
940 else if (aConstructorId == 1)
942 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
943 aViewWindow->SetSelectionMode(FaceSelection);
946 LineEditElements->setReadOnly(false);
947 LineEditElements->setValidator(myIdValidator);
948 onTextChange(LineEditElements->text());
951 SelectionIntoArgument();
954 LineEditElements->setText( myIDs );
957 //=================================================================================
958 // function : GetConstructorId()
960 //=================================================================================
961 int SMESHGUI_ExtrusionDlg::GetConstructorId()
963 return GroupConstructors->checkedId();
966 //=================================================================================
967 // function : keyPressEvent()
969 //=================================================================================
970 void SMESHGUI_ExtrusionDlg::keyPressEvent( QKeyEvent* e )
972 QDialog::keyPressEvent( e );
973 if ( e->isAccepted() )
976 if ( e->key() == Qt::Key_F1 ) {
982 //=================================================================================
983 // function : setFilters()
984 // purpose : SLOT. Called when "Filter" button pressed.
985 //=================================================================================
986 void SMESHGUI_ExtrusionDlg::setFilters()
988 if(myMesh->_is_nil()) {
989 SUIT_MessageBox::critical(this,
991 tr("NO_MESH_SELECTED"));
997 types.append( SMESH::EDGE );
998 types.append( SMESH::FACE );
999 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, types );
1001 myFilterDlg->Init( GetConstructorId() ? SMESH::FACE : SMESH::EDGE );
1003 myFilterDlg->SetSelection();
1004 myFilterDlg->SetMesh( myMesh );
1005 myFilterDlg->SetSourceWg( LineEditElements );
1007 myFilterDlg->show();
1010 //=================================================================================
1011 // function : isValid
1013 //=================================================================================
1014 bool SMESHGUI_ExtrusionDlg::isValid()
1018 if ( RadioButton3->isChecked() ) {
1019 ok = SpinBox_Dx->isValid( msg, true ) && ok;
1020 ok = SpinBox_Dy->isValid( msg, true ) && ok;
1021 ok = SpinBox_Dz->isValid( msg, true ) && ok;
1022 } else if ( RadioButton4->isChecked() ) {
1023 ok = SpinBox_Vx->isValid( msg, true ) && ok;
1024 ok = SpinBox_Vy->isValid( msg, true ) && ok;
1025 ok = SpinBox_Vz->isValid( msg, true ) && ok;
1026 ok = SpinBox_VDist->isValid( msg, true ) && ok;
1028 ok = SpinBox_NbSteps->isValid( msg, true ) && ok;
1031 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1032 if ( !msg.isEmpty() )
1034 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );