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();
576 SMESHGUI::Modified();
581 //=================================================================================
582 // function : ClickOnOk()
583 // purpose : Called when user presses <OK> button
584 //=================================================================================
585 void SMESHGUI_ExtrusionDlg::ClickOnOk()
591 //=================================================================================
592 // function : ClickOnCancel()
593 // purpose : Called when dialog box is closed
594 //=================================================================================
595 void SMESHGUI_ExtrusionDlg::ClickOnCancel()
600 //=================================================================================
601 // function : ClickOnHelp()
603 //=================================================================================
604 void SMESHGUI_ExtrusionDlg::ClickOnHelp()
606 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
608 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
612 platform = "winapplication";
614 platform = "application";
616 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
617 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
618 arg(app->resourceMgr()->stringValue("ExternalBrowser",
620 arg(myHelpFileName));
624 //=================================================================================
625 // function : onTextChange()
627 //=================================================================================
628 void SMESHGUI_ExtrusionDlg::onTextChange (const QString& theNewText)
630 QLineEdit* send = (QLineEdit*)sender();
638 if (send == LineEditElements)
641 // hilight entered elements/nodes
643 if (!myIO.IsNull()) {
644 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
646 if (send == LineEditElements)
648 SMDS_Mesh* aMesh = myActor ? myActor->GetObject()->GetMesh() : 0;
649 SMESH::ElementType SMESHType = GetConstructorId() ? SMESH::FACE : SMESH::EDGE;
650 SMDSAbs_ElementType SMDSType = GetConstructorId() ? SMDSAbs_Face: SMDSAbs_Edge;
652 myElementsId = new SMESH::long_array;
653 myElementsId->length( aListId.count() );
654 TColStd_MapOfInteger newIndices;
655 for (int i = 0; i < aListId.count(); i++) {
656 int id = aListId[ i ].toInt();
657 bool validId = false;
660 const SMDS_MeshElement * e = aMesh->FindElement( id );
661 validId = ( e && e->GetType() == SMDSType );
663 validId = ( myMesh->GetElementType( id, true ) == SMESHType );
666 if ( validId && newIndices.Add( id ))
667 myElementsId[ newIndices.Extent()-1 ] = id;
669 myElementsId->length( myNbOkElements = newIndices.Extent() );
670 mySelector->AddOrRemoveIndex(myIO, newIndices, false);
671 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
672 aViewWindow->highlight( myIO, true, true );
681 //=================================================================================
682 // function : SelectionIntoArgument()
683 // purpose : Called when selection as changed or other case
684 //=================================================================================
685 void SMESHGUI_ExtrusionDlg::SelectionIntoArgument()
689 // return if dialog box is inactive
690 if (!GroupButtons->isEnabled())
694 if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
696 Handle(SALOME_InteractiveObject) resIO = myIO;
700 QString aString = "";
702 if(myEditCurrentArgument == (QWidget*)LineEditElements) {
704 LineEditElements->setText(aString);
710 mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
711 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
715 Handle(SALOME_InteractiveObject) IO = aList.First();
717 if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
718 myMesh = SMESH::GetMeshByIO(IO);
719 if (myMesh->_is_nil())
722 myActor = SMESH::FindActorByObject(myMesh);
725 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
728 // MakeGroups is available if there are groups
729 if ( myMesh->NbGroups() == 0 ) {
730 MakeGroupsCheck->setChecked(false);
731 MakeGroupsCheck->setEnabled(false);
733 MakeGroupsCheck->setEnabled(true);
736 if (CheckBoxMesh->isChecked()) {
737 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
739 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
740 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
744 // get indices of selcted elements
745 TColStd_IndexedMapOfInteger aMapIndex;
746 mySelector->GetIndex(IO,aMapIndex);
747 aNbElements = aMapIndex.Extent();
752 myElementsId = new SMESH::long_array;
753 myElementsId->length( aNbElements );
755 for ( int i = 0; i < aNbElements; ++i )
756 aString += QString(" %1").arg( myElementsId[ i ] = aMapIndex( i+1 ) );
759 myNbOkElements = true;
762 ((QLineEdit*)myEditCurrentArgument)->setText(aString);
765 else if(myEditCurrentArgument == (QWidget*)SpinBox_Vx){
766 TColStd_IndexedMapOfInteger aMapIndex;
767 mySelector->GetIndex(IO,aMapIndex);
768 int aNbElements = aMapIndex.Extent();
769 SMESH::SMESH_Mesh_var aMesh_var = SMESH::GetMeshByIO(IO);
770 SMESH_Actor* anActor = SMESH::FindActorByObject(aMesh_var);
771 SMDS_Mesh* aMesh = anActor ? anActor->GetObject()->GetMesh() : 0;
773 if(aNbElements != 1 || !aMesh)
776 const SMDS_MeshFace* face = dynamic_cast<const SMDS_MeshFace*>(aMesh->FindElement(aMapIndex(aNbElements)));
781 gp_XYZ aNormale = SMESH::getNormale(face);
782 SpinBox_Vx->SetValue(aNormale.X());
783 SpinBox_Vy->SetValue(aNormale.Y());
784 SpinBox_Vz->SetValue(aNormale.Z());
792 //=================================================================================
793 // function : SetEditCurrentArgument()
795 //=================================================================================
796 void SMESHGUI_ExtrusionDlg::SetEditCurrentArgument()
798 QPushButton* send = (QPushButton*)sender();
800 disconnect(mySelectionMgr, 0, this, 0);
801 mySelectionMgr->clearSelected();
802 mySelectionMgr->clearFilters();
804 if (send == SelectElementsButton) {
805 myEditCurrentArgument = (QWidget*)LineEditElements;
806 if (CheckBoxMesh->isChecked()) {
807 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
808 aViewWindow->SetSelectionMode(ActorSelection);
809 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
811 int aConstructorId = GetConstructorId();
812 if (aConstructorId == 0)
814 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
815 aViewWindow->SetSelectionMode(EdgeSelection);
817 else if (aConstructorId == 1)
819 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
820 aViewWindow->SetSelectionMode(FaceSelection);
824 else if (send == SelectVectorButton){
825 myEditCurrentArgument = (QWidget*)SpinBox_Vx;
826 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
827 aViewWindow->SetSelectionMode(FaceSelection);
830 myEditCurrentArgument->setFocus();
831 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
832 SelectionIntoArgument();
835 //=================================================================================
836 // function : DeactivateActiveDialog()
837 // purpose : Deactivates this dialog
838 //=================================================================================
839 void SMESHGUI_ExtrusionDlg::DeactivateActiveDialog()
841 if (ConstructorsBox->isEnabled()) {
842 ConstructorsBox->setEnabled(false);
843 GroupArguments->setEnabled(false);
844 GroupButtons->setEnabled(false);
845 mySMESHGUI->ResetState();
846 mySMESHGUI->SetActiveDialogBox(0);
850 //=================================================================================
851 // function : ActivateThisDialog()
852 // purpose : Activates this dialog
853 //=================================================================================
854 void SMESHGUI_ExtrusionDlg::ActivateThisDialog()
856 // Emit a signal to deactivate the active dialog
857 mySMESHGUI->EmitSignalDeactivateDialog();
858 ConstructorsBox->setEnabled(true);
859 GroupArguments->setEnabled(true);
860 GroupButtons->setEnabled(true);
862 mySMESHGUI->SetActiveDialogBox(this);
864 ConstructorsClicked(GetConstructorId());
865 SelectionIntoArgument();
868 //=================================================================================
869 // function : enterEvent()
870 // purpose : Mouse enter event
871 //=================================================================================
872 void SMESHGUI_ExtrusionDlg::enterEvent (QEvent*)
874 if (!ConstructorsBox->isEnabled())
875 ActivateThisDialog();
878 //=================================================================================
879 // function : closeEvent()
881 //=================================================================================
882 void SMESHGUI_ExtrusionDlg::closeEvent( QCloseEvent* )
884 /* same than click on cancel button */
885 disconnect(mySelectionMgr, 0, this, 0);
886 mySelectionMgr->clearFilters();
887 //mySelectionMgr->clearSelected();
888 if (SMESH::GetCurrentVtkView()) {
889 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
890 SMESH::SetPointRepresentation(false);
891 SMESH::SetPickable();
893 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
894 aViewWindow->SetSelectionMode(ActorSelection);
895 mySMESHGUI->ResetState();
898 void SMESHGUI_ExtrusionDlg::reject()
904 //=================================================================================
905 // function : onSelectMesh()
907 //=================================================================================
908 void SMESHGUI_ExtrusionDlg::onSelectMesh (bool toSelectMesh)
911 myIDs = LineEditElements->text();
912 TextLabelElements->setText(tr("SMESH_NAME"));
915 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
917 myFilterBtn->setEnabled(!toSelectMesh);
919 if (myEditCurrentArgument != LineEditElements) {
920 LineEditElements->clear();
924 mySelectionMgr->clearFilters();
927 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
928 aViewWindow->SetSelectionMode(ActorSelection);
929 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
930 LineEditElements->setReadOnly(true);
931 LineEditElements->setValidator(0);
933 int aConstructorId = GetConstructorId();
934 if (aConstructorId == 0)
936 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
937 aViewWindow->SetSelectionMode(EdgeSelection);
939 else if (aConstructorId == 1)
941 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
942 aViewWindow->SetSelectionMode(FaceSelection);
945 LineEditElements->setReadOnly(false);
946 LineEditElements->setValidator(myIdValidator);
947 onTextChange(LineEditElements->text());
950 SelectionIntoArgument();
953 LineEditElements->setText( myIDs );
956 //=================================================================================
957 // function : GetConstructorId()
959 //=================================================================================
960 int SMESHGUI_ExtrusionDlg::GetConstructorId()
962 return GroupConstructors->checkedId();
965 //=================================================================================
966 // function : keyPressEvent()
968 //=================================================================================
969 void SMESHGUI_ExtrusionDlg::keyPressEvent( QKeyEvent* e )
971 QDialog::keyPressEvent( e );
972 if ( e->isAccepted() )
975 if ( e->key() == Qt::Key_F1 ) {
981 //=================================================================================
982 // function : setFilters()
983 // purpose : SLOT. Called when "Filter" button pressed.
984 //=================================================================================
985 void SMESHGUI_ExtrusionDlg::setFilters()
987 if(myMesh->_is_nil()) {
988 SUIT_MessageBox::critical(this,
990 tr("NO_MESH_SELECTED"));
996 types.append( SMESH::EDGE );
997 types.append( SMESH::FACE );
998 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, types );
1000 myFilterDlg->Init( GetConstructorId() ? SMESH::FACE : SMESH::EDGE );
1002 myFilterDlg->SetSelection();
1003 myFilterDlg->SetMesh( myMesh );
1004 myFilterDlg->SetSourceWg( LineEditElements );
1006 myFilterDlg->show();
1009 //=================================================================================
1010 // function : isValid
1012 //=================================================================================
1013 bool SMESHGUI_ExtrusionDlg::isValid()
1017 if ( RadioButton3->isChecked() ) {
1018 ok = SpinBox_Dx->isValid( msg, true ) && ok;
1019 ok = SpinBox_Dy->isValid( msg, true ) && ok;
1020 ok = SpinBox_Dz->isValid( msg, true ) && ok;
1021 } else if ( RadioButton4->isChecked() ) {
1022 ok = SpinBox_Vx->isValid( msg, true ) && ok;
1023 ok = SpinBox_Vy->isValid( msg, true ) && ok;
1024 ok = SpinBox_Vz->isValid( msg, true ) && ok;
1025 ok = SpinBox_VDist->isValid( msg, true ) && ok;
1027 ok = SpinBox_NbSteps->isValid( msg, true ) && ok;
1030 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1031 if ( !msg.isEmpty() )
1033 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );