1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_ExtrusionDlg.cxx
24 // Author : Michael ZORIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_ExtrusionDlg.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_SpinBox.h"
34 #include "SMESHGUI_IdValidator.h"
35 #include "SMESHGUI_FilterDlg.h"
37 #include <SMESH_Actor.h>
38 #include <SMESH_TypeFilter.hxx>
39 #include <SMESH_LogicalFilter.hxx>
41 #include <SMDS_Mesh.hxx>
43 // SALOME GUI includes
44 #include <SUIT_ResourceMgr.h>
45 #include <SUIT_Desktop.h>
46 #include <SUIT_MessageBox.h>
47 #include <SUIT_Session.h>
48 #include <SUIT_OverrideCursor.h>
50 #include <LightApp_Application.h>
51 #include <LightApp_SelectionMgr.h>
53 #include <SVTK_ViewModel.h>
54 #include <SVTK_ViewWindow.h>
56 #include <SalomeApp_IntSpinBox.h>
59 #include <TColStd_MapOfInteger.hxx>
60 #include <TColStd_IndexedMapOfInteger.hxx>
64 #include <QApplication>
65 #include <QButtonGroup>
69 #include <QPushButton>
70 #include <QRadioButton>
72 #include <QHBoxLayout>
73 #include <QVBoxLayout>
74 #include <QGridLayout>
78 #include <SALOMEconfig.h>
79 #include CORBA_SERVER_HEADER(SMESH_Group)
80 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
85 //=================================================================================
86 // function : SMESHGUI_ExtrusionDlg()
87 // purpose : constructor
88 //=================================================================================
89 SMESHGUI_ExtrusionDlg::SMESHGUI_ExtrusionDlg (SMESHGUI* theModule)
90 : QDialog( SMESH::GetDesktop( theModule ) ),
91 mySMESHGUI( theModule ),
92 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
94 mySelectedObject(SMESH::SMESH_IDSource::_nil())
96 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_EDGE")));
97 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_TRIANGLE")));
98 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
101 setAttribute( Qt::WA_DeleteOnClose, true );
102 setWindowTitle(tr("EXTRUSION_ALONG_LINE"));
103 setSizeGripEnabled(true);
105 QVBoxLayout* SMESHGUI_ExtrusionDlgLayout = new QVBoxLayout(this);
106 SMESHGUI_ExtrusionDlgLayout->setSpacing(SPACING);
107 SMESHGUI_ExtrusionDlgLayout->setMargin(MARGIN);
109 /***************************************************************/
110 ConstructorsBox = new QGroupBox(tr("SMESH_EXTRUSION"), this);
111 GroupConstructors = new QButtonGroup(this);
112 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
113 ConstructorsBoxLayout->setSpacing(SPACING);
114 ConstructorsBoxLayout->setMargin(MARGIN);
116 RadioButton1= new QRadioButton(ConstructorsBox);
117 RadioButton1->setIcon(image0);
118 RadioButton2= new QRadioButton(ConstructorsBox);
119 RadioButton2->setIcon(image1);
121 ConstructorsBoxLayout->addWidget(RadioButton1);
122 ConstructorsBoxLayout->addWidget(RadioButton2);
124 GroupConstructors->addButton(RadioButton1, 0);
125 GroupConstructors->addButton(RadioButton2, 1);
127 /***************************************************************/
128 GroupButtons = new QGroupBox(this);
129 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
130 GroupButtonsLayout->setSpacing(SPACING);
131 GroupButtonsLayout->setMargin(MARGIN);
133 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
134 buttonOk->setAutoDefault(true);
135 buttonOk->setDefault(true);
136 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
137 buttonApply->setAutoDefault(true);
138 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
139 buttonCancel->setAutoDefault(true);
140 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
141 buttonHelp->setAutoDefault(true);
143 GroupButtonsLayout->addWidget(buttonOk);
144 GroupButtonsLayout->addSpacing(10);
145 GroupButtonsLayout->addWidget(buttonApply);
146 GroupButtonsLayout->addSpacing(10);
147 GroupButtonsLayout->addStretch();
148 GroupButtonsLayout->addWidget(buttonCancel);
149 GroupButtonsLayout->addWidget(buttonHelp);
151 /***************************************************************/
152 GroupArguments = new QGroupBox(tr("EXTRUSION_1D"), this);
153 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
154 GroupArgumentsLayout->setSpacing(SPACING);
155 GroupArgumentsLayout->setMargin(MARGIN);
157 myIdValidator = new SMESHGUI_IdValidator(this);
159 // Controls for elements selection
160 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
162 SelectElementsButton = new QPushButton(GroupArguments);
163 SelectElementsButton->setIcon(image2);
165 LineEditElements = new QLineEdit(GroupArguments);
166 LineEditElements->setValidator(myIdValidator);
167 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
168 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
170 // Control for the whole mesh selection
171 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
173 RadioButton3 = new QRadioButton(GroupArguments);
174 RadioButton3->setText( tr("SMESH_EXTRUSION_TO_DISTANCE") );
175 RadioButton4 = new QRadioButton(GroupArguments);
176 RadioButton4->setText( tr("SMESH_EXTRUSION_ALONG_VECTOR") );
178 //Control for the Distance selection
179 TextLabelDistance = new QLabel(tr("SMESH_DISTANCE"), GroupArguments);
181 TextLabelDx = new QLabel(tr("SMESH_X"), GroupArguments);
182 SpinBox_Dx = new SMESHGUI_SpinBox(GroupArguments);
184 TextLabelDy = new QLabel(tr("SMESH_Y"), GroupArguments);
185 SpinBox_Dy = new SMESHGUI_SpinBox(GroupArguments);
187 TextLabelDz = new QLabel(tr("SMESH_Z"), GroupArguments);
188 SpinBox_Dz = new SMESHGUI_SpinBox(GroupArguments);
190 // Controls for vector selection
192 TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupArguments);
194 SelectVectorButton = new QPushButton(GroupArguments);
195 SelectVectorButton->setIcon(image2);
197 TextLabelVx = new QLabel(tr("SMESH_DX"), GroupArguments);
198 SpinBox_Vx = new SMESHGUI_SpinBox(GroupArguments);
200 TextLabelVy = new QLabel(tr("SMESH_DY"), GroupArguments);
201 SpinBox_Vy = new SMESHGUI_SpinBox(GroupArguments);
203 TextLabelVz = new QLabel(tr("SMESH_DZ"), GroupArguments);
204 SpinBox_Vz = new SMESHGUI_SpinBox(GroupArguments);
206 TextLabelDist = new QLabel(tr("SMESH_DISTANCE"), GroupArguments);
207 SpinBox_VDist = new SMESHGUI_SpinBox(GroupArguments);
209 // Controls for nb. steps defining
210 TextLabelNbSteps = new QLabel(tr("SMESH_NUMBEROFSTEPS"), GroupArguments);
211 SpinBox_NbSteps = new SalomeApp_IntSpinBox(GroupArguments);
213 // CheckBox for groups generation
214 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
216 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
217 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
218 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 5);
219 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 7);
220 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
221 GroupArgumentsLayout->addWidget(RadioButton3, 2, 1, 1, 3);
222 GroupArgumentsLayout->addWidget(RadioButton4, 2, 5, 1, 3);
223 GroupArgumentsLayout->addWidget(TextLabelDistance, 3, 0);
224 GroupArgumentsLayout->addWidget(TextLabelDx, 3, 2);
225 GroupArgumentsLayout->addWidget(SpinBox_Dx, 3, 3);
226 GroupArgumentsLayout->addWidget(TextLabelDy, 3, 4);
227 GroupArgumentsLayout->addWidget(SpinBox_Dy, 3, 5);
228 GroupArgumentsLayout->addWidget(TextLabelDz, 3, 6);
229 GroupArgumentsLayout->addWidget(SpinBox_Dz, 3, 7);
230 GroupArgumentsLayout->addWidget(TextLabelVector, 4, 0);
231 GroupArgumentsLayout->addWidget(SelectVectorButton, 4, 1);
232 GroupArgumentsLayout->addWidget(TextLabelVx, 4, 2);
233 GroupArgumentsLayout->addWidget(SpinBox_Vx, 4, 3);
234 GroupArgumentsLayout->addWidget(TextLabelVy, 4, 4);
235 GroupArgumentsLayout->addWidget(SpinBox_Vy, 4, 5);
236 GroupArgumentsLayout->addWidget(TextLabelVz, 4, 6);
237 GroupArgumentsLayout->addWidget(SpinBox_Vz, 4, 7);
238 GroupArgumentsLayout->addWidget(TextLabelDist, 5, 0);
239 GroupArgumentsLayout->addWidget(SpinBox_VDist, 5, 3);
240 GroupArgumentsLayout->addWidget(TextLabelNbSteps, 6, 0, 1, 3);
241 GroupArgumentsLayout->addWidget(SpinBox_NbSteps, 6, 3);
242 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 7, 0, 1, 8);
243 GroupArgumentsLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding), 8, 0);
246 /***************************************************************/
247 SMESHGUI_ExtrusionDlgLayout->addWidget(ConstructorsBox);
248 SMESHGUI_ExtrusionDlgLayout->addWidget(GroupArguments);
249 SMESHGUI_ExtrusionDlgLayout->addWidget(GroupButtons);
251 /* Initialisations */
252 SpinBox_Vx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, 3);
253 SpinBox_Vy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, 3);
254 SpinBox_Vz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, 3);
256 SpinBox_Dx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
257 SpinBox_Dy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
258 SpinBox_Dz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
260 SpinBox_NbSteps->setRange(1, 999999);
261 SpinBox_VDist->RangeStepAndValidator(0, COORD_MAX, 10.0, 3);
263 RadioButton1->setChecked(true);
264 RadioButton3->setChecked(true);
265 MakeGroupsCheck->setChecked(true);
267 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
269 mySMESHGUI->SetActiveDialogBox(this);
271 // Costruction of the logical filter for the elements: mesh/sub-mesh/group
272 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
273 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
275 QList<SUIT_SelectionFilter*> aListOfFilters;
276 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
277 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
279 myMeshOrSubMeshOrGroupFilter =
280 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
282 myHelpFileName = "extrusion_page.html";
286 /***************************************************************/
287 // signals and slots connections
288 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
289 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
290 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
291 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
293 connect(RadioButton3, SIGNAL(clicked()), this, SLOT(ClickOnRadio()));
294 connect(RadioButton4, SIGNAL(clicked()), this, SLOT(ClickOnRadio()));
296 // to update state of the Ok & Apply buttons
297 connect(SpinBox_Vx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
298 connect(SpinBox_Vy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
299 connect(SpinBox_Vz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
300 connect(SpinBox_Dx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
301 connect(SpinBox_Dy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
302 connect(SpinBox_Dz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
304 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
305 connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
306 connect(SelectVectorButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
307 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
308 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
309 /* to close dialog if study change */
310 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
311 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
312 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
314 /***************************************************************/
316 ConstructorsClicked(0);
318 SelectionIntoArgument();
321 //=================================================================================
322 // function : ~SMESHGUI_ExtrusionDlg()
323 // purpose : destructor
324 //=================================================================================
325 SMESHGUI_ExtrusionDlg::~SMESHGUI_ExtrusionDlg()
327 if ( myFilterDlg != 0 ) {
328 myFilterDlg->setParent( 0 );
333 //=================================================================================
335 // purpose : initialization
336 //=================================================================================
337 void SMESHGUI_ExtrusionDlg::Init (bool ResetControls)
342 LineEditElements->clear();
346 myMesh = SMESH::SMESH_Mesh::_nil();
349 SpinBox_NbSteps->setValue(1);
350 SpinBox_VDist->setValue(10);
351 SpinBox_Dx->SetValue(0);
352 SpinBox_Dy->SetValue(0);
353 SpinBox_Dz->SetValue(0);
354 SpinBox_Vx->SetValue(0);
355 SpinBox_Vy->SetValue(0);
356 SpinBox_Vz->SetValue(0);
358 CheckBoxMesh->setChecked(false);
365 //=================================================================================
366 // function : CheckIsEnable()
367 // purpose : Check whether the Ok and Apply buttons should be enabled or not
368 //=================================================================================
369 void SMESHGUI_ExtrusionDlg::CheckIsEnable()
371 double aX, aY, aZ, aModule;
372 if ( RadioButton3->isChecked() ) {
373 aX = SpinBox_Dx->GetValue();
374 aY = SpinBox_Dy->GetValue();
375 aZ = SpinBox_Dz->GetValue();
376 aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
377 } else if ( RadioButton4->isChecked() ) {
378 aX = SpinBox_Vx->GetValue();
379 aY = SpinBox_Vy->GetValue();
380 aZ = SpinBox_Vz->GetValue();
381 aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
384 bool anIsEnable = myNbOkElements > 0 && aModule > 1.0E-38;
386 buttonOk->setEnabled(anIsEnable);
387 buttonApply->setEnabled(anIsEnable);
390 //=================================================================================
391 // function : ConstructorsClicked()
392 // purpose : Radio button management
393 //=================================================================================
394 void SMESHGUI_ExtrusionDlg::ConstructorsClicked (int constructorId)
396 disconnect(mySelectionMgr, 0, this, 0);
398 switch (constructorId) {
401 GroupArguments->setTitle(tr("EXTRUSION_1D"));
402 if (!CheckBoxMesh->isChecked())
404 LineEditElements->clear();
406 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
407 aViewWindow->SetSelectionMode(EdgeSelection);
413 GroupArguments->setTitle(tr("EXTRUSION_2D"));
414 if (!CheckBoxMesh->isChecked())
416 LineEditElements->clear();
418 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
419 aViewWindow->SetSelectionMode(FaceSelection);
425 myEditCurrentArgument = (QWidget*)LineEditElements;
426 LineEditElements->setFocus();
428 if (CheckBoxMesh->isChecked())
431 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
434 //=================================================================================
435 // function : ConstructorsClicked()
436 // purpose : Radio button management
437 //=================================================================================
438 void SMESHGUI_ExtrusionDlg::ClickOnRadio()
440 if ( RadioButton3->isChecked() ) {
441 TextLabelDistance->show();
449 TextLabelVector->hide();
456 TextLabelDist->hide();
457 SpinBox_VDist->hide();
458 SelectVectorButton->hide();
459 } else if ( RadioButton4->isChecked() ) {
460 TextLabelDistance->hide();
468 TextLabelVector->show();
475 TextLabelDist->show();
476 SpinBox_VDist->show();
477 SelectVectorButton->show();
480 qApp->processEvents();
482 resize( minimumSizeHint() );
485 //=================================================================================
486 // function : ClickOnApply()
487 // purpose : Called when user presses <Apply> button
488 //=================================================================================
489 bool SMESHGUI_ExtrusionDlg::ClickOnApply()
491 if (mySMESHGUI->isActiveStudyLocked())
497 if (myNbOkElements) {
499 SMESH::DirStruct aVector;
500 QStringList aParameters;
502 if ( RadioButton3->isChecked() ) {
503 aVector.PS.x = SpinBox_Dx->GetValue();
504 aVector.PS.y = SpinBox_Dy->GetValue();
505 aVector.PS.z = SpinBox_Dz->GetValue();
507 aParameters << SpinBox_Dx->text();
508 aParameters << SpinBox_Dy->text();
509 aParameters << SpinBox_Dz->text();
510 } else if ( RadioButton4->isChecked() ) {
511 gp_XYZ aNormale(SpinBox_Vx->GetValue(),
512 SpinBox_Vy->GetValue(),
513 SpinBox_Vz->GetValue());
516 aNormale /= aNormale.Modulus();
517 long aVDist = (long)SpinBox_VDist->value();
519 aVector.PS.x = aNormale.X()*aVDist;
520 aVector.PS.y = aNormale.Y()*aVDist;
521 aVector.PS.z = aNormale.Z()*aVDist;
523 aParameters << SpinBox_Vx->text();
524 aParameters << SpinBox_Vy->text();
525 aParameters << SpinBox_Vz->text();
526 aParameters << SpinBox_VDist->text();
529 long aNbSteps = (long)SpinBox_NbSteps->value();
531 aParameters << SpinBox_NbSteps->text();
534 SUIT_OverrideCursor aWaitCursor;
535 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
537 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) {
538 if( CheckBoxMesh->isChecked() ) {
539 if( GetConstructorId() == 0 )
540 SMESH::ListOfGroups_var groups =
541 aMeshEditor->ExtrusionSweepObject1DMakeGroups(mySelectedObject, aVector, aNbSteps);
543 SMESH::ListOfGroups_var groups =
544 aMeshEditor->ExtrusionSweepObject2DMakeGroups(mySelectedObject, aVector, aNbSteps);
547 SMESH::ListOfGroups_var groups =
548 aMeshEditor->ExtrusionSweepMakeGroups(myElementsId.inout(), aVector, aNbSteps);
551 if( CheckBoxMesh->isChecked() ) {
552 if( GetConstructorId() == 0 )
553 aMeshEditor->ExtrusionSweepObject1D(mySelectedObject, aVector, aNbSteps);
555 aMeshEditor->ExtrusionSweepObject2D(mySelectedObject, aVector, aNbSteps);
558 aMeshEditor->ExtrusionSweep(myElementsId.inout(), aVector, aNbSteps);
561 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
566 SMESH::Update(myIO, SMESH::eDisplay);
567 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() )
568 mySMESHGUI->updateObjBrowser(true); // new groups may appear
570 ConstructorsClicked(GetConstructorId());
571 mySelectionMgr->clearSelected();
572 mySelectedObject = SMESH::SMESH_IDSource::_nil();
573 SelectionIntoArgument();
578 //=================================================================================
579 // function : ClickOnOk()
580 // purpose : Called when user presses <OK> button
581 //=================================================================================
582 void SMESHGUI_ExtrusionDlg::ClickOnOk()
588 //=================================================================================
589 // function : ClickOnCancel()
590 // purpose : Called when dialog box is closed
591 //=================================================================================
592 void SMESHGUI_ExtrusionDlg::ClickOnCancel()
597 //=================================================================================
598 // function : ClickOnHelp()
600 //=================================================================================
601 void SMESHGUI_ExtrusionDlg::ClickOnHelp()
603 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
605 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
609 platform = "winapplication";
611 platform = "application";
613 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
614 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
615 arg(app->resourceMgr()->stringValue("ExternalBrowser",
617 arg(myHelpFileName));
621 //=================================================================================
622 // function : onTextChange()
624 //=================================================================================
625 void SMESHGUI_ExtrusionDlg::onTextChange (const QString& theNewText)
627 QLineEdit* send = (QLineEdit*)sender();
635 if (send == LineEditElements)
638 // hilight entered elements/nodes
640 if (!myIO.IsNull()) {
641 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
643 if (send == LineEditElements)
645 SMDS_Mesh* aMesh = myActor ? myActor->GetObject()->GetMesh() : 0;
646 SMESH::ElementType SMESHType = GetConstructorId() ? SMESH::FACE : SMESH::EDGE;
647 SMDSAbs_ElementType SMDSType = GetConstructorId() ? SMDSAbs_Face: SMDSAbs_Edge;
649 myElementsId = new SMESH::long_array;
650 myElementsId->length( aListId.count() );
651 TColStd_MapOfInteger newIndices;
652 for (int i = 0; i < aListId.count(); i++) {
653 int id = aListId[ i ].toInt();
654 bool validId = false;
657 const SMDS_MeshElement * e = aMesh->FindElement( id );
658 validId = ( e && e->GetType() == SMDSType );
660 validId = ( myMesh->GetElementType( id, true ) == SMESHType );
663 if ( validId && newIndices.Add( id ))
664 myElementsId[ newIndices.Extent()-1 ] = id;
666 myElementsId->length( myNbOkElements = newIndices.Extent() );
667 mySelector->AddOrRemoveIndex(myIO, newIndices, false);
668 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
669 aViewWindow->highlight( myIO, true, true );
678 //=================================================================================
679 // function : SelectionIntoArgument()
680 // purpose : Called when selection as changed or other case
681 //=================================================================================
682 void SMESHGUI_ExtrusionDlg::SelectionIntoArgument()
686 // return if dialog box is inactive
687 if (!GroupButtons->isEnabled())
691 if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
693 Handle(SALOME_InteractiveObject) resIO = myIO;
697 QString aString = "";
699 if(myEditCurrentArgument == (QWidget*)LineEditElements) {
701 LineEditElements->setText(aString);
707 mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
708 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
712 Handle(SALOME_InteractiveObject) IO = aList.First();
714 if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
715 myMesh = SMESH::GetMeshByIO(IO);
716 if (myMesh->_is_nil())
719 myActor = SMESH::FindActorByObject(myMesh);
722 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
725 // MakeGroups is available if there are groups
726 if ( myMesh->NbGroups() == 0 ) {
727 MakeGroupsCheck->setChecked(false);
728 MakeGroupsCheck->setEnabled(false);
730 MakeGroupsCheck->setEnabled(true);
733 if (CheckBoxMesh->isChecked()) {
734 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
736 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
737 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
741 // get indices of selcted elements
742 TColStd_IndexedMapOfInteger aMapIndex;
743 mySelector->GetIndex(IO,aMapIndex);
744 aNbElements = aMapIndex.Extent();
749 myElementsId = new SMESH::long_array;
750 myElementsId->length( aNbElements );
752 for ( int i = 0; i < aNbElements; ++i )
753 aString += QString(" %1").arg( myElementsId[ i ] = aMapIndex( i+1 ) );
756 myNbOkElements = true;
759 ((QLineEdit*)myEditCurrentArgument)->setText(aString);
762 else if(myEditCurrentArgument == (QWidget*)SpinBox_Vx){
763 TColStd_IndexedMapOfInteger aMapIndex;
764 mySelector->GetIndex(IO,aMapIndex);
765 int aNbElements = aMapIndex.Extent();
766 SMESH::SMESH_Mesh_var aMesh_var = SMESH::GetMeshByIO(IO);
767 SMESH_Actor* anActor = SMESH::FindActorByObject(aMesh_var);
768 SMDS_Mesh* aMesh = anActor ? anActor->GetObject()->GetMesh() : 0;
770 if(aNbElements != 1 || !aMesh)
773 const SMDS_MeshFace* face = dynamic_cast<const SMDS_MeshFace*>(aMesh->FindElement(aMapIndex(aNbElements)));
778 gp_XYZ aNormale = SMESH::getNormale(face);
779 SpinBox_Vx->SetValue(aNormale.X());
780 SpinBox_Vy->SetValue(aNormale.Y());
781 SpinBox_Vz->SetValue(aNormale.Z());
789 //=================================================================================
790 // function : SetEditCurrentArgument()
792 //=================================================================================
793 void SMESHGUI_ExtrusionDlg::SetEditCurrentArgument()
795 QPushButton* send = (QPushButton*)sender();
797 disconnect(mySelectionMgr, 0, this, 0);
798 mySelectionMgr->clearSelected();
799 mySelectionMgr->clearFilters();
801 if (send == SelectElementsButton) {
802 myEditCurrentArgument = (QWidget*)LineEditElements;
803 if (CheckBoxMesh->isChecked()) {
804 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
805 aViewWindow->SetSelectionMode(ActorSelection);
806 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
808 int aConstructorId = GetConstructorId();
809 if (aConstructorId == 0)
811 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
812 aViewWindow->SetSelectionMode(EdgeSelection);
814 else if (aConstructorId == 1)
816 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
817 aViewWindow->SetSelectionMode(FaceSelection);
821 else if (send == SelectVectorButton){
822 myEditCurrentArgument = (QWidget*)SpinBox_Vx;
823 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
824 aViewWindow->SetSelectionMode(FaceSelection);
827 myEditCurrentArgument->setFocus();
828 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
829 SelectionIntoArgument();
832 //=================================================================================
833 // function : DeactivateActiveDialog()
834 // purpose : Deactivates this dialog
835 //=================================================================================
836 void SMESHGUI_ExtrusionDlg::DeactivateActiveDialog()
838 if (ConstructorsBox->isEnabled()) {
839 ConstructorsBox->setEnabled(false);
840 GroupArguments->setEnabled(false);
841 GroupButtons->setEnabled(false);
842 mySMESHGUI->ResetState();
843 mySMESHGUI->SetActiveDialogBox(0);
847 //=================================================================================
848 // function : ActivateThisDialog()
849 // purpose : Activates this dialog
850 //=================================================================================
851 void SMESHGUI_ExtrusionDlg::ActivateThisDialog()
853 // Emit a signal to deactivate the active dialog
854 mySMESHGUI->EmitSignalDeactivateDialog();
855 ConstructorsBox->setEnabled(true);
856 GroupArguments->setEnabled(true);
857 GroupButtons->setEnabled(true);
859 mySMESHGUI->SetActiveDialogBox(this);
861 ConstructorsClicked(GetConstructorId());
862 SelectionIntoArgument();
865 //=================================================================================
866 // function : enterEvent()
867 // purpose : Mouse enter event
868 //=================================================================================
869 void SMESHGUI_ExtrusionDlg::enterEvent (QEvent*)
871 if (!ConstructorsBox->isEnabled())
872 ActivateThisDialog();
875 //=================================================================================
876 // function : closeEvent()
878 //=================================================================================
879 void SMESHGUI_ExtrusionDlg::closeEvent( QCloseEvent* )
881 /* same than click on cancel button */
882 disconnect(mySelectionMgr, 0, this, 0);
883 mySelectionMgr->clearFilters();
884 //mySelectionMgr->clearSelected();
885 if (SMESH::GetCurrentVtkView()) {
886 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
887 SMESH::SetPointRepresentation(false);
888 SMESH::SetPickable();
890 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
891 aViewWindow->SetSelectionMode(ActorSelection);
892 mySMESHGUI->ResetState();
895 void SMESHGUI_ExtrusionDlg::reject()
901 //=================================================================================
902 // function : onSelectMesh()
904 //=================================================================================
905 void SMESHGUI_ExtrusionDlg::onSelectMesh (bool toSelectMesh)
908 myIDs = LineEditElements->text();
909 TextLabelElements->setText(tr("SMESH_NAME"));
912 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
914 myFilterBtn->setEnabled(!toSelectMesh);
916 if (myEditCurrentArgument != LineEditElements) {
917 LineEditElements->clear();
921 mySelectionMgr->clearFilters();
924 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
925 aViewWindow->SetSelectionMode(ActorSelection);
926 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
927 LineEditElements->setReadOnly(true);
928 LineEditElements->setValidator(0);
930 int aConstructorId = GetConstructorId();
931 if (aConstructorId == 0)
933 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
934 aViewWindow->SetSelectionMode(EdgeSelection);
936 else if (aConstructorId == 1)
938 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
939 aViewWindow->SetSelectionMode(FaceSelection);
942 LineEditElements->setReadOnly(false);
943 LineEditElements->setValidator(myIdValidator);
944 onTextChange(LineEditElements->text());
947 SelectionIntoArgument();
950 LineEditElements->setText( myIDs );
953 //=================================================================================
954 // function : GetConstructorId()
956 //=================================================================================
957 int SMESHGUI_ExtrusionDlg::GetConstructorId()
959 return GroupConstructors->checkedId();
962 //=================================================================================
963 // function : keyPressEvent()
965 //=================================================================================
966 void SMESHGUI_ExtrusionDlg::keyPressEvent( QKeyEvent* e )
968 QDialog::keyPressEvent( e );
969 if ( e->isAccepted() )
972 if ( e->key() == Qt::Key_F1 ) {
978 //=================================================================================
979 // function : setFilters()
980 // purpose : SLOT. Called when "Filter" button pressed.
981 //=================================================================================
982 void SMESHGUI_ExtrusionDlg::setFilters()
984 if(myMesh->_is_nil()) {
985 SUIT_MessageBox::critical(this,
987 tr("NO_MESH_SELECTED"));
993 types.append( SMESH::EDGE );
994 types.append( SMESH::FACE );
995 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, types );
997 myFilterDlg->Init( GetConstructorId() ? SMESH::FACE : SMESH::EDGE );
999 myFilterDlg->SetSelection();
1000 myFilterDlg->SetMesh( myMesh );
1001 myFilterDlg->SetSourceWg( LineEditElements );
1003 myFilterDlg->show();
1006 //=================================================================================
1007 // function : isValid
1009 //=================================================================================
1010 bool SMESHGUI_ExtrusionDlg::isValid()
1014 if ( RadioButton3->isChecked() ) {
1015 ok = SpinBox_Dx->isValid( msg, true ) && ok;
1016 ok = SpinBox_Dy->isValid( msg, true ) && ok;
1017 ok = SpinBox_Dz->isValid( msg, true ) && ok;
1018 } else if ( RadioButton4->isChecked() ) {
1019 ok = SpinBox_Vx->isValid( msg, true ) && ok;
1020 ok = SpinBox_Vy->isValid( msg, true ) && ok;
1021 ok = SpinBox_Vz->isValid( msg, true ) && ok;
1022 ok = SpinBox_VDist->isValid( msg, true ) && ok;
1024 ok = SpinBox_NbSteps->isValid( msg, true ) && ok;
1027 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1028 if ( !msg.isEmpty() )
1030 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );