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 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
169 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
171 // Control for the whole mesh selection
172 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
174 RadioButton3 = new QRadioButton(GroupArguments);
175 RadioButton3->setText( tr("SMESH_EXTRUSION_TO_DISTANCE") );
176 RadioButton4 = new QRadioButton(GroupArguments);
177 RadioButton4->setText( tr("SMESH_EXTRUSION_ALONG_VECTOR") );
179 //Control for the Distance selection
180 TextLabelDistance = new QLabel(tr("SMESH_DISTANCE"), GroupArguments);
182 TextLabelDx = new QLabel(tr("SMESH_X"), GroupArguments);
183 SpinBox_Dx = new SMESHGUI_SpinBox(GroupArguments);
185 TextLabelDy = new QLabel(tr("SMESH_Y"), GroupArguments);
186 SpinBox_Dy = new SMESHGUI_SpinBox(GroupArguments);
188 TextLabelDz = new QLabel(tr("SMESH_Z"), GroupArguments);
189 SpinBox_Dz = new SMESHGUI_SpinBox(GroupArguments);
191 // Controls for vector selection
193 TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupArguments);
195 SelectVectorButton = new QPushButton(GroupArguments);
196 SelectVectorButton->setIcon(image2);
198 TextLabelVx = new QLabel(tr("SMESH_DX"), GroupArguments);
199 SpinBox_Vx = new SMESHGUI_SpinBox(GroupArguments);
201 TextLabelVy = new QLabel(tr("SMESH_DY"), GroupArguments);
202 SpinBox_Vy = new SMESHGUI_SpinBox(GroupArguments);
204 TextLabelVz = new QLabel(tr("SMESH_DZ"), GroupArguments);
205 SpinBox_Vz = new SMESHGUI_SpinBox(GroupArguments);
207 TextLabelDist = new QLabel(tr("SMESH_DISTANCE"), GroupArguments);
208 SpinBox_VDist = new SMESHGUI_SpinBox(GroupArguments);
210 // Controls for nb. steps defining
211 TextLabelNbSteps = new QLabel(tr("SMESH_NUMBEROFSTEPS"), GroupArguments);
212 SpinBox_NbSteps = new SalomeApp_IntSpinBox(GroupArguments);
214 // CheckBox for groups generation
215 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
217 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
218 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
219 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 5);
220 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 7);
221 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
222 GroupArgumentsLayout->addWidget(RadioButton3, 2, 1, 1, 3);
223 GroupArgumentsLayout->addWidget(RadioButton4, 2, 5, 1, 3);
224 GroupArgumentsLayout->addWidget(TextLabelDistance, 3, 0);
225 GroupArgumentsLayout->addWidget(TextLabelDx, 3, 2);
226 GroupArgumentsLayout->addWidget(SpinBox_Dx, 3, 3);
227 GroupArgumentsLayout->addWidget(TextLabelDy, 3, 4);
228 GroupArgumentsLayout->addWidget(SpinBox_Dy, 3, 5);
229 GroupArgumentsLayout->addWidget(TextLabelDz, 3, 6);
230 GroupArgumentsLayout->addWidget(SpinBox_Dz, 3, 7);
231 GroupArgumentsLayout->addWidget(TextLabelVector, 4, 0);
232 GroupArgumentsLayout->addWidget(SelectVectorButton, 4, 1);
233 GroupArgumentsLayout->addWidget(TextLabelVx, 4, 2);
234 GroupArgumentsLayout->addWidget(SpinBox_Vx, 4, 3);
235 GroupArgumentsLayout->addWidget(TextLabelVy, 4, 4);
236 GroupArgumentsLayout->addWidget(SpinBox_Vy, 4, 5);
237 GroupArgumentsLayout->addWidget(TextLabelVz, 4, 6);
238 GroupArgumentsLayout->addWidget(SpinBox_Vz, 4, 7);
239 GroupArgumentsLayout->addWidget(TextLabelDist, 5, 0);
240 GroupArgumentsLayout->addWidget(SpinBox_VDist, 5, 3);
241 GroupArgumentsLayout->addWidget(TextLabelNbSteps, 6, 0, 1, 3);
242 GroupArgumentsLayout->addWidget(SpinBox_NbSteps, 6, 3);
243 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 7, 0, 1, 8);
244 GroupArgumentsLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding), 8, 0);
247 /***************************************************************/
248 SMESHGUI_ExtrusionDlgLayout->addWidget(ConstructorsBox);
249 SMESHGUI_ExtrusionDlgLayout->addWidget(GroupArguments);
250 SMESHGUI_ExtrusionDlgLayout->addWidget(GroupButtons);
252 /* Initialisations */
253 SpinBox_Vx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, "length_precision");
254 SpinBox_Vy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, "length_precision");
255 SpinBox_Vz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, "length_precision");
257 SpinBox_Dx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
258 SpinBox_Dy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
259 SpinBox_Dz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
261 SpinBox_NbSteps->setRange(1, 999999);
262 SpinBox_VDist->RangeStepAndValidator(0, COORD_MAX, 10.0, "length_precision");
264 RadioButton1->setChecked(true);
265 RadioButton3->setChecked(true);
266 MakeGroupsCheck->setChecked(true);
268 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
270 mySMESHGUI->SetActiveDialogBox(this);
272 // Costruction of the logical filter for the elements: mesh/sub-mesh/group
273 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
274 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
276 QList<SUIT_SelectionFilter*> aListOfFilters;
277 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
278 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
280 myMeshOrSubMeshOrGroupFilter =
281 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
283 myHelpFileName = "extrusion_page.html";
287 /***************************************************************/
288 // signals and slots connections
289 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
290 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
291 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
292 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
294 connect(RadioButton3, SIGNAL(clicked()), this, SLOT(ClickOnRadio()));
295 connect(RadioButton4, SIGNAL(clicked()), this, SLOT(ClickOnRadio()));
297 // to update state of the Ok & Apply buttons
298 connect(SpinBox_Vx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
299 connect(SpinBox_Vy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
300 connect(SpinBox_Vz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
301 connect(SpinBox_Dx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
302 connect(SpinBox_Dy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
303 connect(SpinBox_Dz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
305 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
306 connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
307 connect(SelectVectorButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
308 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
309 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
310 /* to close dialog if study change */
311 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
312 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
313 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
315 /***************************************************************/
317 ConstructorsClicked(0);
319 SelectionIntoArgument();
322 //=================================================================================
323 // function : ~SMESHGUI_ExtrusionDlg()
324 // purpose : destructor
325 //=================================================================================
326 SMESHGUI_ExtrusionDlg::~SMESHGUI_ExtrusionDlg()
328 if ( myFilterDlg != 0 ) {
329 myFilterDlg->setParent( 0 );
334 //=================================================================================
336 // purpose : initialization
337 //=================================================================================
338 void SMESHGUI_ExtrusionDlg::Init (bool ResetControls)
343 LineEditElements->clear();
347 myMesh = SMESH::SMESH_Mesh::_nil();
350 SpinBox_NbSteps->setValue(1);
351 SpinBox_VDist->setValue(10);
352 SpinBox_Dx->SetValue(0);
353 SpinBox_Dy->SetValue(0);
354 SpinBox_Dz->SetValue(0);
355 SpinBox_Vx->SetValue(0);
356 SpinBox_Vy->SetValue(0);
357 SpinBox_Vz->SetValue(0);
359 CheckBoxMesh->setChecked(false);
366 //=================================================================================
367 // function : CheckIsEnable()
368 // purpose : Check whether the Ok and Apply buttons should be enabled or not
369 //=================================================================================
370 void SMESHGUI_ExtrusionDlg::CheckIsEnable()
372 double aX, aY, aZ, aModule;
373 if ( RadioButton3->isChecked() ) {
374 aX = SpinBox_Dx->GetValue();
375 aY = SpinBox_Dy->GetValue();
376 aZ = SpinBox_Dz->GetValue();
377 aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
378 } else if ( RadioButton4->isChecked() ) {
379 aX = SpinBox_Vx->GetValue();
380 aY = SpinBox_Vy->GetValue();
381 aZ = SpinBox_Vz->GetValue();
382 aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
385 bool anIsEnable = myNbOkElements > 0 && aModule > 1.0E-38;
387 buttonOk->setEnabled(anIsEnable);
388 buttonApply->setEnabled(anIsEnable);
391 //=================================================================================
392 // function : ConstructorsClicked()
393 // purpose : Radio button management
394 //=================================================================================
395 void SMESHGUI_ExtrusionDlg::ConstructorsClicked (int constructorId)
397 disconnect(mySelectionMgr, 0, this, 0);
399 switch (constructorId) {
402 GroupArguments->setTitle(tr("EXTRUSION_1D"));
403 if (!CheckBoxMesh->isChecked())
405 LineEditElements->clear();
407 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
408 aViewWindow->SetSelectionMode(EdgeSelection);
414 GroupArguments->setTitle(tr("EXTRUSION_2D"));
415 if (!CheckBoxMesh->isChecked())
417 LineEditElements->clear();
419 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
420 aViewWindow->SetSelectionMode(FaceSelection);
426 myEditCurrentArgument = (QWidget*)LineEditElements;
427 LineEditElements->setFocus();
429 if (CheckBoxMesh->isChecked())
432 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
435 //=================================================================================
436 // function : ConstructorsClicked()
437 // purpose : Radio button management
438 //=================================================================================
439 void SMESHGUI_ExtrusionDlg::ClickOnRadio()
441 if ( RadioButton3->isChecked() ) {
442 TextLabelDistance->show();
450 TextLabelVector->hide();
457 TextLabelDist->hide();
458 SpinBox_VDist->hide();
459 SelectVectorButton->hide();
460 } else if ( RadioButton4->isChecked() ) {
461 TextLabelDistance->hide();
469 TextLabelVector->show();
476 TextLabelDist->show();
477 SpinBox_VDist->show();
478 SelectVectorButton->show();
481 qApp->processEvents();
483 resize( minimumSizeHint() );
486 //=================================================================================
487 // function : ClickOnApply()
488 // purpose : Called when user presses <Apply> button
489 //=================================================================================
490 bool SMESHGUI_ExtrusionDlg::ClickOnApply()
492 if (mySMESHGUI->isActiveStudyLocked())
498 if (myNbOkElements) {
500 SMESH::DirStruct aVector;
501 QStringList aParameters;
503 if ( RadioButton3->isChecked() ) {
504 aVector.PS.x = SpinBox_Dx->GetValue();
505 aVector.PS.y = SpinBox_Dy->GetValue();
506 aVector.PS.z = SpinBox_Dz->GetValue();
508 aParameters << SpinBox_Dx->text();
509 aParameters << SpinBox_Dy->text();
510 aParameters << SpinBox_Dz->text();
511 } else if ( RadioButton4->isChecked() ) {
512 gp_XYZ aNormale(SpinBox_Vx->GetValue(),
513 SpinBox_Vy->GetValue(),
514 SpinBox_Vz->GetValue());
517 aNormale /= aNormale.Modulus();
518 long aVDist = (long)SpinBox_VDist->value();
520 aVector.PS.x = aNormale.X()*aVDist;
521 aVector.PS.y = aNormale.Y()*aVDist;
522 aVector.PS.z = aNormale.Z()*aVDist;
524 aParameters << SpinBox_Vx->text();
525 aParameters << SpinBox_Vy->text();
526 aParameters << SpinBox_Vz->text();
527 aParameters << SpinBox_VDist->text();
530 long aNbSteps = (long)SpinBox_NbSteps->value();
532 aParameters << SpinBox_NbSteps->text();
535 SUIT_OverrideCursor aWaitCursor;
536 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
538 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) {
539 if( CheckBoxMesh->isChecked() ) {
540 if( GetConstructorId() == 0 )
541 SMESH::ListOfGroups_var groups =
542 aMeshEditor->ExtrusionSweepObject1DMakeGroups(mySelectedObject, aVector, aNbSteps);
544 SMESH::ListOfGroups_var groups =
545 aMeshEditor->ExtrusionSweepObject2DMakeGroups(mySelectedObject, aVector, aNbSteps);
548 SMESH::ListOfGroups_var groups =
549 aMeshEditor->ExtrusionSweepMakeGroups(myElementsId.inout(), aVector, aNbSteps);
552 if( CheckBoxMesh->isChecked() ) {
553 if( GetConstructorId() == 0 )
554 aMeshEditor->ExtrusionSweepObject1D(mySelectedObject, aVector, aNbSteps);
556 aMeshEditor->ExtrusionSweepObject2D(mySelectedObject, aVector, aNbSteps);
559 aMeshEditor->ExtrusionSweep(myElementsId.inout(), aVector, aNbSteps);
562 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
567 SMESH::Update(myIO, SMESH::eDisplay);
568 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() )
569 mySMESHGUI->updateObjBrowser(true); // new groups may appear
571 ConstructorsClicked(GetConstructorId());
572 mySelectionMgr->clearSelected();
573 mySelectedObject = SMESH::SMESH_IDSource::_nil();
574 SelectionIntoArgument();
579 //=================================================================================
580 // function : ClickOnOk()
581 // purpose : Called when user presses <OK> button
582 //=================================================================================
583 void SMESHGUI_ExtrusionDlg::ClickOnOk()
589 //=================================================================================
590 // function : ClickOnCancel()
591 // purpose : Called when dialog box is closed
592 //=================================================================================
593 void SMESHGUI_ExtrusionDlg::ClickOnCancel()
598 //=================================================================================
599 // function : ClickOnHelp()
601 //=================================================================================
602 void SMESHGUI_ExtrusionDlg::ClickOnHelp()
604 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
606 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
610 platform = "winapplication";
612 platform = "application";
614 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
615 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
616 arg(app->resourceMgr()->stringValue("ExternalBrowser",
618 arg(myHelpFileName));
622 //=================================================================================
623 // function : onTextChange()
625 //=================================================================================
626 void SMESHGUI_ExtrusionDlg::onTextChange (const QString& theNewText)
628 QLineEdit* send = (QLineEdit*)sender();
636 if (send == LineEditElements)
639 // hilight entered elements/nodes
641 if (!myIO.IsNull()) {
642 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
644 if (send == LineEditElements)
646 SMDS_Mesh* aMesh = myActor ? myActor->GetObject()->GetMesh() : 0;
647 SMESH::ElementType SMESHType = GetConstructorId() ? SMESH::FACE : SMESH::EDGE;
648 SMDSAbs_ElementType SMDSType = GetConstructorId() ? SMDSAbs_Face: SMDSAbs_Edge;
650 myElementsId = new SMESH::long_array;
651 myElementsId->length( aListId.count() );
652 TColStd_MapOfInteger newIndices;
653 for (int i = 0; i < aListId.count(); i++) {
654 int id = aListId[ i ].toInt();
655 bool validId = false;
658 const SMDS_MeshElement * e = aMesh->FindElement( id );
659 validId = ( e && e->GetType() == SMDSType );
661 validId = ( myMesh->GetElementType( id, true ) == SMESHType );
664 if ( validId && newIndices.Add( id ))
665 myElementsId[ newIndices.Extent()-1 ] = id;
667 myElementsId->length( myNbOkElements = newIndices.Extent() );
668 mySelector->AddOrRemoveIndex(myIO, newIndices, false);
669 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
670 aViewWindow->highlight( myIO, true, true );
679 //=================================================================================
680 // function : SelectionIntoArgument()
681 // purpose : Called when selection as changed or other case
682 //=================================================================================
683 void SMESHGUI_ExtrusionDlg::SelectionIntoArgument()
687 // return if dialog box is inactive
688 if (!GroupButtons->isEnabled())
692 if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
694 Handle(SALOME_InteractiveObject) resIO = myIO;
698 QString aString = "";
700 if(myEditCurrentArgument == (QWidget*)LineEditElements) {
702 LineEditElements->setText(aString);
708 mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
709 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
713 Handle(SALOME_InteractiveObject) IO = aList.First();
715 if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
716 myMesh = SMESH::GetMeshByIO(IO);
717 if (myMesh->_is_nil())
720 myActor = SMESH::FindActorByObject(myMesh);
723 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
726 // MakeGroups is available if there are groups
727 if ( myMesh->NbGroups() == 0 ) {
728 MakeGroupsCheck->setChecked(false);
729 MakeGroupsCheck->setEnabled(false);
731 MakeGroupsCheck->setEnabled(true);
734 if (CheckBoxMesh->isChecked()) {
735 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
737 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
738 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
742 // get indices of selcted elements
743 TColStd_IndexedMapOfInteger aMapIndex;
744 mySelector->GetIndex(IO,aMapIndex);
745 aNbElements = aMapIndex.Extent();
750 myElementsId = new SMESH::long_array;
751 myElementsId->length( aNbElements );
753 for ( int i = 0; i < aNbElements; ++i )
754 aString += QString(" %1").arg( myElementsId[ i ] = aMapIndex( i+1 ) );
757 myNbOkElements = true;
760 ((QLineEdit*)myEditCurrentArgument)->setText(aString);
763 else if(myEditCurrentArgument == (QWidget*)SpinBox_Vx){
764 TColStd_IndexedMapOfInteger aMapIndex;
765 mySelector->GetIndex(IO,aMapIndex);
766 int aNbElements = aMapIndex.Extent();
767 SMESH::SMESH_Mesh_var aMesh_var = SMESH::GetMeshByIO(IO);
768 SMESH_Actor* anActor = SMESH::FindActorByObject(aMesh_var);
769 SMDS_Mesh* aMesh = anActor ? anActor->GetObject()->GetMesh() : 0;
771 if(aNbElements != 1 || !aMesh)
774 const SMDS_MeshFace* face = dynamic_cast<const SMDS_MeshFace*>(aMesh->FindElement(aMapIndex(aNbElements)));
779 gp_XYZ aNormale = SMESH::getNormale(face);
780 SpinBox_Vx->SetValue(aNormale.X());
781 SpinBox_Vy->SetValue(aNormale.Y());
782 SpinBox_Vz->SetValue(aNormale.Z());
790 //=================================================================================
791 // function : SetEditCurrentArgument()
793 //=================================================================================
794 void SMESHGUI_ExtrusionDlg::SetEditCurrentArgument()
796 QPushButton* send = (QPushButton*)sender();
798 disconnect(mySelectionMgr, 0, this, 0);
799 mySelectionMgr->clearSelected();
800 mySelectionMgr->clearFilters();
802 if (send == SelectElementsButton) {
803 myEditCurrentArgument = (QWidget*)LineEditElements;
804 if (CheckBoxMesh->isChecked()) {
805 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
806 aViewWindow->SetSelectionMode(ActorSelection);
807 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
809 int aConstructorId = GetConstructorId();
810 if (aConstructorId == 0)
812 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
813 aViewWindow->SetSelectionMode(EdgeSelection);
815 else if (aConstructorId == 1)
817 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
818 aViewWindow->SetSelectionMode(FaceSelection);
822 else if (send == SelectVectorButton){
823 myEditCurrentArgument = (QWidget*)SpinBox_Vx;
824 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
825 aViewWindow->SetSelectionMode(FaceSelection);
828 myEditCurrentArgument->setFocus();
829 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
830 SelectionIntoArgument();
833 //=================================================================================
834 // function : DeactivateActiveDialog()
835 // purpose : Deactivates this dialog
836 //=================================================================================
837 void SMESHGUI_ExtrusionDlg::DeactivateActiveDialog()
839 if (ConstructorsBox->isEnabled()) {
840 ConstructorsBox->setEnabled(false);
841 GroupArguments->setEnabled(false);
842 GroupButtons->setEnabled(false);
843 mySMESHGUI->ResetState();
844 mySMESHGUI->SetActiveDialogBox(0);
848 //=================================================================================
849 // function : ActivateThisDialog()
850 // purpose : Activates this dialog
851 //=================================================================================
852 void SMESHGUI_ExtrusionDlg::ActivateThisDialog()
854 // Emit a signal to deactivate the active dialog
855 mySMESHGUI->EmitSignalDeactivateDialog();
856 ConstructorsBox->setEnabled(true);
857 GroupArguments->setEnabled(true);
858 GroupButtons->setEnabled(true);
860 mySMESHGUI->SetActiveDialogBox(this);
862 ConstructorsClicked(GetConstructorId());
863 SelectionIntoArgument();
866 //=================================================================================
867 // function : enterEvent()
868 // purpose : Mouse enter event
869 //=================================================================================
870 void SMESHGUI_ExtrusionDlg::enterEvent (QEvent*)
872 if (!ConstructorsBox->isEnabled())
873 ActivateThisDialog();
876 //=================================================================================
877 // function : closeEvent()
879 //=================================================================================
880 void SMESHGUI_ExtrusionDlg::closeEvent( QCloseEvent* )
882 /* same than click on cancel button */
883 disconnect(mySelectionMgr, 0, this, 0);
884 mySelectionMgr->clearFilters();
885 //mySelectionMgr->clearSelected();
886 if (SMESH::GetCurrentVtkView()) {
887 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
888 SMESH::SetPointRepresentation(false);
889 SMESH::SetPickable();
891 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
892 aViewWindow->SetSelectionMode(ActorSelection);
893 mySMESHGUI->ResetState();
896 void SMESHGUI_ExtrusionDlg::reject()
902 //=================================================================================
903 // function : onSelectMesh()
905 //=================================================================================
906 void SMESHGUI_ExtrusionDlg::onSelectMesh (bool toSelectMesh)
909 myIDs = LineEditElements->text();
910 TextLabelElements->setText(tr("SMESH_NAME"));
913 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
915 myFilterBtn->setEnabled(!toSelectMesh);
917 if (myEditCurrentArgument != LineEditElements) {
918 LineEditElements->clear();
922 mySelectionMgr->clearFilters();
925 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
926 aViewWindow->SetSelectionMode(ActorSelection);
927 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
928 LineEditElements->setReadOnly(true);
929 LineEditElements->setValidator(0);
931 int aConstructorId = GetConstructorId();
932 if (aConstructorId == 0)
934 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
935 aViewWindow->SetSelectionMode(EdgeSelection);
937 else if (aConstructorId == 1)
939 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
940 aViewWindow->SetSelectionMode(FaceSelection);
943 LineEditElements->setReadOnly(false);
944 LineEditElements->setValidator(myIdValidator);
945 onTextChange(LineEditElements->text());
948 SelectionIntoArgument();
951 LineEditElements->setText( myIDs );
954 //=================================================================================
955 // function : GetConstructorId()
957 //=================================================================================
958 int SMESHGUI_ExtrusionDlg::GetConstructorId()
960 return GroupConstructors->checkedId();
963 //=================================================================================
964 // function : keyPressEvent()
966 //=================================================================================
967 void SMESHGUI_ExtrusionDlg::keyPressEvent( QKeyEvent* e )
969 QDialog::keyPressEvent( e );
970 if ( e->isAccepted() )
973 if ( e->key() == Qt::Key_F1 ) {
979 //=================================================================================
980 // function : setFilters()
981 // purpose : SLOT. Called when "Filter" button pressed.
982 //=================================================================================
983 void SMESHGUI_ExtrusionDlg::setFilters()
985 if(myMesh->_is_nil()) {
986 SUIT_MessageBox::critical(this,
988 tr("NO_MESH_SELECTED"));
994 types.append( SMESH::EDGE );
995 types.append( SMESH::FACE );
996 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, types );
998 myFilterDlg->Init( GetConstructorId() ? SMESH::FACE : SMESH::EDGE );
1000 myFilterDlg->SetSelection();
1001 myFilterDlg->SetMesh( myMesh );
1002 myFilterDlg->SetSourceWg( LineEditElements );
1004 myFilterDlg->show();
1007 //=================================================================================
1008 // function : isValid
1010 //=================================================================================
1011 bool SMESHGUI_ExtrusionDlg::isValid()
1015 if ( RadioButton3->isChecked() ) {
1016 ok = SpinBox_Dx->isValid( msg, true ) && ok;
1017 ok = SpinBox_Dy->isValid( msg, true ) && ok;
1018 ok = SpinBox_Dz->isValid( msg, true ) && ok;
1019 } else if ( RadioButton4->isChecked() ) {
1020 ok = SpinBox_Vx->isValid( msg, true ) && ok;
1021 ok = SpinBox_Vy->isValid( msg, true ) && ok;
1022 ok = SpinBox_Vz->isValid( msg, true ) && ok;
1023 ok = SpinBox_VDist->isValid( msg, true ) && ok;
1025 ok = SpinBox_NbSteps->isValid( msg, true ) && ok;
1028 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1029 if ( !msg.isEmpty() )
1031 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );