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 //Control for the Distance selection
174 TextLabelDistance = new QLabel(tr("SMESH_DISTANCE"), GroupArguments);
176 TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupArguments);
177 TextLabelDx = new QLabel(tr("SMESH_X"), GroupArguments);
178 SpinBox_Dx = new SMESHGUI_SpinBox(GroupArguments);
180 TextLabelDy = new QLabel(tr("SMESH_Y"), GroupArguments);
181 SpinBox_Dy = new SMESHGUI_SpinBox(GroupArguments);
183 TextLabelDz = new QLabel(tr("SMESH_Z"), GroupArguments);
184 SpinBox_Dz = new SMESHGUI_SpinBox(GroupArguments);
186 // Controls for vector selection
188 SelectVectorButton = new QPushButton(GroupArguments);
189 SelectVectorButton->setIcon(image2);
191 TextLabelVx = new QLabel(tr("SMESH_DX"), GroupArguments);
192 SpinBox_Vx = new SMESHGUI_SpinBox(GroupArguments);
194 TextLabelVy = new QLabel(tr("SMESH_DY"), GroupArguments);
195 SpinBox_Vy = new SMESHGUI_SpinBox(GroupArguments);
197 TextLabelVz = new QLabel(tr("SMESH_DZ"), GroupArguments);
198 SpinBox_Vz = new SMESHGUI_SpinBox(GroupArguments);
200 // Controls for nb. steps defining
201 TextLabelNbSteps = new QLabel(tr("SMESH_NUMBEROFSTEPS"), GroupArguments);
202 SpinBox_NbSteps = new SalomeApp_IntSpinBox(GroupArguments);
204 // CheckBox for groups generation
205 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
207 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
208 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
209 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 5);
210 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 7);
211 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
212 GroupArgumentsLayout->addWidget(TextLabelDistance, 2, 0);
213 GroupArgumentsLayout->addWidget(TextLabelDx, 2, 2);
214 GroupArgumentsLayout->addWidget(SpinBox_Dx, 2, 3);
215 GroupArgumentsLayout->addWidget(TextLabelDy, 2, 4);
216 GroupArgumentsLayout->addWidget(SpinBox_Dy, 2, 5);
217 GroupArgumentsLayout->addWidget(TextLabelDz, 2, 6);
218 GroupArgumentsLayout->addWidget(SpinBox_Dz, 2, 7);
219 GroupArgumentsLayout->addWidget(TextLabelVector, 3, 0);
220 GroupArgumentsLayout->addWidget(SelectVectorButton, 3, 1);
221 GroupArgumentsLayout->addWidget(TextLabelVx, 3, 2);
222 GroupArgumentsLayout->addWidget(SpinBox_Vx, 3, 3);
223 GroupArgumentsLayout->addWidget(TextLabelVy, 3, 4);
224 GroupArgumentsLayout->addWidget(SpinBox_Vy, 3, 5);
225 GroupArgumentsLayout->addWidget(TextLabelVz, 3, 6);
226 GroupArgumentsLayout->addWidget(SpinBox_Vz, 3, 7);
227 GroupArgumentsLayout->addWidget(TextLabelNbSteps, 4, 0);
228 GroupArgumentsLayout->addWidget(SpinBox_NbSteps, 4, 2, 1, 6);
229 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 0, 1, 8);
231 /***************************************************************/
232 SMESHGUI_ExtrusionDlgLayout->addWidget(ConstructorsBox);
233 SMESHGUI_ExtrusionDlgLayout->addWidget(GroupArguments);
234 SMESHGUI_ExtrusionDlgLayout->addWidget(GroupButtons);
236 /* Initialisations */
237 SpinBox_Vx->RangeStepAndValidator(-1, 1, 0.01, 3);
238 SpinBox_Vy->RangeStepAndValidator(-1, 1, 0.01, 3);
239 SpinBox_Vz->RangeStepAndValidator(-1, 1, 0.01, 3);
241 SpinBox_Dx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
242 SpinBox_Dy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
243 SpinBox_Dz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
245 SpinBox_NbSteps->setRange(1, 999999);
247 RadioButton1->setChecked(true);
248 MakeGroupsCheck->setChecked(true);
250 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
252 mySMESHGUI->SetActiveDialogBox(this);
254 // Costruction of the logical filter for the elements: mesh/sub-mesh/group
255 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
256 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
258 QList<SUIT_SelectionFilter*> aListOfFilters;
259 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
260 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
262 myMeshOrSubMeshOrGroupFilter =
263 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
265 myHelpFileName = "extrusion_page.html";
269 /***************************************************************/
270 // signals and slots connections
271 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
272 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
273 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
274 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
276 // to update state of the Ok & Apply buttons
277 connect(SpinBox_Vx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
278 connect(SpinBox_Vy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
279 connect(SpinBox_Vz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
280 connect(SpinBox_Dx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
281 connect(SpinBox_Dy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
282 connect(SpinBox_Dz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
284 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
285 connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
286 connect(SelectVectorButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
287 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
288 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
289 /* to close dialog if study change */
290 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
291 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
292 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
294 /***************************************************************/
296 ConstructorsClicked(0);
297 SelectionIntoArgument();
300 //=================================================================================
301 // function : ~SMESHGUI_ExtrusionDlg()
302 // purpose : destructor
303 //=================================================================================
304 SMESHGUI_ExtrusionDlg::~SMESHGUI_ExtrusionDlg()
306 if ( myFilterDlg != 0 ) {
307 myFilterDlg->setParent( 0 );
312 //=================================================================================
314 // purpose : initialization
315 //=================================================================================
316 void SMESHGUI_ExtrusionDlg::Init (bool ResetControls)
320 LineEditElements->clear();
324 myMesh = SMESH::SMESH_Mesh::_nil();
327 SpinBox_NbSteps->setValue(1);
328 SpinBox_Dx->SetValue(0);
329 SpinBox_Dy->SetValue(0);
330 SpinBox_Dz->SetValue(0);
331 SpinBox_Vx->SetValue(0);
332 SpinBox_Vy->SetValue(0);
333 SpinBox_Vz->SetValue(0);
335 CheckBoxMesh->setChecked(false);
342 //=================================================================================
343 // function : CheckIsEnable()
344 // purpose : Check whether the Ok and Apply buttons should be enabled or not
345 //=================================================================================
346 void SMESHGUI_ExtrusionDlg::CheckIsEnable()
349 double aX = SpinBox_Vx->GetValue()*SpinBox_Dx->GetValue();
350 double aY = SpinBox_Vy->GetValue()*SpinBox_Dy->GetValue();
351 double aZ = SpinBox_Vz->GetValue()*SpinBox_Dz->GetValue();
352 double aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
354 bool anIsEnable = myNbOkElements > 0 && aModule > 1.0E-38;
356 buttonOk->setEnabled(anIsEnable);
357 buttonApply->setEnabled(anIsEnable);
360 //=================================================================================
361 // function : ConstructorsClicked()
362 // purpose : Radio button management
363 //=================================================================================
364 void SMESHGUI_ExtrusionDlg::ConstructorsClicked (int constructorId)
366 disconnect(mySelectionMgr, 0, this, 0);
368 switch (constructorId) {
371 GroupArguments->setTitle(tr("EXTRUSION_1D"));
372 if (!CheckBoxMesh->isChecked())
374 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
375 aViewWindow->SetSelectionMode(EdgeSelection);
381 GroupArguments->setTitle(tr("EXTRUSION_2D"));
382 if (!CheckBoxMesh->isChecked())
384 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
385 aViewWindow->SetSelectionMode(FaceSelection);
391 myEditCurrentArgument = (QWidget*)LineEditElements;
392 LineEditElements->setFocus();
394 if (CheckBoxMesh->isChecked())
397 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
400 //=================================================================================
401 // function : ClickOnApply()
402 // purpose : Called when user presses <Apply> button
403 //=================================================================================
404 bool SMESHGUI_ExtrusionDlg::ClickOnApply()
406 if (mySMESHGUI->isActiveStudyLocked())
412 if (myNbOkElements) {
414 gp_XYZ aNormale(SpinBox_Vx->GetValue(),
415 SpinBox_Vy->GetValue(),
416 SpinBox_Vz->GetValue());
418 aNormale /= aNormale.Modulus();
420 SMESH::DirStruct aVector;
421 aVector.PS.x = SpinBox_Dx->GetValue()*aNormale.X();
422 aVector.PS.y = SpinBox_Dy->GetValue()*aNormale.Y();
423 aVector.PS.z = SpinBox_Dz->GetValue()*aNormale.Z();
425 long aNbSteps = (long)SpinBox_NbSteps->value();
427 QStringList aParameters;
428 aParameters << SpinBox_Dx->text();
429 aParameters << SpinBox_Dy->text();
430 aParameters << SpinBox_Dz->text();
431 aParameters << SpinBox_NbSteps->text();
434 SUIT_OverrideCursor aWaitCursor;
435 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
437 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) {
438 if( CheckBoxMesh->isChecked() ) {
439 if( GetConstructorId() == 0 )
440 SMESH::ListOfGroups_var groups =
441 aMeshEditor->ExtrusionSweepObject1DMakeGroups(mySelectedObject, aVector, aNbSteps);
443 SMESH::ListOfGroups_var groups =
444 aMeshEditor->ExtrusionSweepObject2DMakeGroups(mySelectedObject, aVector, aNbSteps);
447 SMESH::ListOfGroups_var groups =
448 aMeshEditor->ExtrusionSweepMakeGroups(myElementsId.inout(), aVector, aNbSteps);
451 if( CheckBoxMesh->isChecked() ) {
452 if( GetConstructorId() == 0 )
453 aMeshEditor->ExtrusionSweepObject1D(mySelectedObject, aVector, aNbSteps);
455 aMeshEditor->ExtrusionSweepObject2D(mySelectedObject, aVector, aNbSteps);
458 aMeshEditor->ExtrusionSweep(myElementsId.inout(), aVector, aNbSteps);
461 myMesh->SetParameters( SMESHGUI::JoinObjectParameters(aParameters) );
467 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() )
468 mySMESHGUI->updateObjBrowser(true); // new groups may appear
470 ConstructorsClicked(GetConstructorId());
471 mySelectedObject = SMESH::SMESH_IDSource::_nil();
472 SelectionIntoArgument();
477 //=================================================================================
478 // function : ClickOnOk()
479 // purpose : Called when user presses <OK> button
480 //=================================================================================
481 void SMESHGUI_ExtrusionDlg::ClickOnOk()
487 //=================================================================================
488 // function : ClickOnCancel()
489 // purpose : Called when dialog box is closed
490 //=================================================================================
491 void SMESHGUI_ExtrusionDlg::ClickOnCancel()
493 disconnect(mySelectionMgr, 0, this, 0);
494 mySelectionMgr->clearFilters();
495 //mySelectionMgr->clearSelected();
496 if (SMESH::GetCurrentVtkView()) {
497 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
498 SMESH::SetPointRepresentation(false);
499 SMESH::SetPickable();
501 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
502 aViewWindow->SetSelectionMode(ActorSelection);
503 mySMESHGUI->ResetState();
507 //=================================================================================
508 // function : ClickOnHelp()
510 //=================================================================================
511 void SMESHGUI_ExtrusionDlg::ClickOnHelp()
513 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
515 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
519 platform = "winapplication";
521 platform = "application";
523 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
524 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
525 arg(app->resourceMgr()->stringValue("ExternalBrowser",
527 arg(myHelpFileName));
531 //=================================================================================
532 // function : onTextChange()
534 //=================================================================================
535 void SMESHGUI_ExtrusionDlg::onTextChange (const QString& theNewText)
537 QLineEdit* send = (QLineEdit*)sender();
545 if (send == LineEditElements)
548 // hilight entered elements/nodes
550 if (!myIO.IsNull()) {
551 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
553 if (send == LineEditElements)
555 SMDS_Mesh* aMesh = myActor ? myActor->GetObject()->GetMesh() : 0;
556 SMESH::ElementType SMESHType = GetConstructorId() ? SMESH::FACE : SMESH::EDGE;
557 SMDSAbs_ElementType SMDSType = GetConstructorId() ? SMDSAbs_Face: SMDSAbs_Edge;
559 myElementsId = new SMESH::long_array;
560 myElementsId->length( aListId.count() );
561 TColStd_MapOfInteger newIndices;
562 for (int i = 0; i < aListId.count(); i++) {
563 int id = aListId[ i ].toInt();
564 bool validId = false;
567 const SMDS_MeshElement * e = aMesh->FindElement( id );
568 validId = ( e && e->GetType() == SMDSType );
570 validId = ( myMesh->GetElementType( id, true ) == SMESHType );
573 if ( validId && newIndices.Add( id ))
574 myElementsId[ newIndices.Extent()-1 ] = id;
576 myElementsId->length( myNbOkElements = newIndices.Extent() );
577 mySelector->AddOrRemoveIndex(myIO, newIndices, false);
578 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
579 aViewWindow->highlight( myIO, true, true );
588 //=================================================================================
589 // function : SelectionIntoArgument()
590 // purpose : Called when selection as changed or other case
591 //=================================================================================
592 void SMESHGUI_ExtrusionDlg::SelectionIntoArgument()
596 // return if dialog box is inactive
597 if (!GroupButtons->isEnabled())
604 QString aString = "";
606 if(myEditCurrentArgument == (QWidget*)LineEditElements) {
608 LineEditElements->setText(aString);
614 mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
615 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
619 Handle(SALOME_InteractiveObject) IO = aList.First();
620 myMesh = SMESH::GetMeshByIO(IO);
621 if (myMesh->_is_nil())
624 myActor = SMESH::FindActorByObject(myMesh);
626 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
629 // MakeGroups is available if there are groups
630 if ( myMesh->NbGroups() == 0 ) {
631 MakeGroupsCheck->setChecked(false);
632 MakeGroupsCheck->setEnabled(false);
634 MakeGroupsCheck->setEnabled(true);
637 if (CheckBoxMesh->isChecked()) {
638 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
640 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
641 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
645 // get indices of selcted elements
646 TColStd_IndexedMapOfInteger aMapIndex;
647 mySelector->GetIndex(IO,aMapIndex);
648 aNbElements = aMapIndex.Extent();
653 myElementsId = new SMESH::long_array;
654 myElementsId->length( aNbElements );
656 for ( int i = 0; i < aNbElements; ++i )
657 aString += QString(" %1").arg( myElementsId[ i ] = aMapIndex( i+1 ) );
660 myNbOkElements = true;
663 ((QLineEdit*)myEditCurrentArgument)->setText(aString);
666 else if(myEditCurrentArgument == (QWidget*)SpinBox_Vx){
667 TColStd_IndexedMapOfInteger aMapIndex;
668 mySelector->GetIndex(IO,aMapIndex);
669 int aNbElements = aMapIndex.Extent();
670 SMDS_Mesh* aMesh = myActor ? myActor->GetObject()->GetMesh() : 0;
672 if(aNbElements != 1 || !aMesh)
675 const SMDS_MeshFace* face = dynamic_cast<const SMDS_MeshFace*>(aMesh->FindElement(aMapIndex(aNbElements)));
680 gp_XYZ aNormale = SMESH::getNormale(face);
681 SpinBox_Vx->SetValue(aNormale.X());
682 SpinBox_Vy->SetValue(aNormale.Y());
683 SpinBox_Vz->SetValue(aNormale.Z());
691 //=================================================================================
692 // function : SetEditCurrentArgument()
694 //=================================================================================
695 void SMESHGUI_ExtrusionDlg::SetEditCurrentArgument()
697 QPushButton* send = (QPushButton*)sender();
699 disconnect(mySelectionMgr, 0, this, 0);
700 mySelectionMgr->clearSelected();
701 mySelectionMgr->clearFilters();
703 if (send == SelectElementsButton) {
704 myEditCurrentArgument = (QWidget*)LineEditElements;
705 if (CheckBoxMesh->isChecked()) {
706 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
707 aViewWindow->SetSelectionMode(ActorSelection);
708 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
710 int aConstructorId = GetConstructorId();
711 if (aConstructorId == 0)
713 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
714 aViewWindow->SetSelectionMode(EdgeSelection);
716 else if (aConstructorId == 1)
718 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
719 aViewWindow->SetSelectionMode(FaceSelection);
723 else if (send == SelectVectorButton){
724 myEditCurrentArgument = (QWidget*)SpinBox_Vx;
725 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
726 aViewWindow->SetSelectionMode(FaceSelection);
729 myEditCurrentArgument->setFocus();
730 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
731 SelectionIntoArgument();
734 //=================================================================================
735 // function : DeactivateActiveDialog()
736 // purpose : Deactivates this dialog
737 //=================================================================================
738 void SMESHGUI_ExtrusionDlg::DeactivateActiveDialog()
740 if (ConstructorsBox->isEnabled()) {
741 ConstructorsBox->setEnabled(false);
742 GroupArguments->setEnabled(false);
743 GroupButtons->setEnabled(false);
744 mySMESHGUI->ResetState();
745 mySMESHGUI->SetActiveDialogBox(0);
749 //=================================================================================
750 // function : ActivateThisDialog()
751 // purpose : Activates this dialog
752 //=================================================================================
753 void SMESHGUI_ExtrusionDlg::ActivateThisDialog()
755 // Emit a signal to deactivate the active dialog
756 mySMESHGUI->EmitSignalDeactivateDialog();
757 ConstructorsBox->setEnabled(true);
758 GroupArguments->setEnabled(true);
759 GroupButtons->setEnabled(true);
761 mySMESHGUI->SetActiveDialogBox(this);
763 ConstructorsClicked(GetConstructorId());
764 SelectionIntoArgument();
767 //=================================================================================
768 // function : enterEvent()
769 // purpose : Mouse enter event
770 //=================================================================================
771 void SMESHGUI_ExtrusionDlg::enterEvent (QEvent*)
773 if (!ConstructorsBox->isEnabled())
774 ActivateThisDialog();
777 //=================================================================================
778 // function : onSelectMesh()
780 //=================================================================================
781 void SMESHGUI_ExtrusionDlg::onSelectMesh (bool toSelectMesh)
784 TextLabelElements->setText(tr("SMESH_NAME"));
786 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
787 myFilterBtn->setEnabled(!toSelectMesh);
789 if (myEditCurrentArgument != LineEditElements) {
790 LineEditElements->clear();
794 mySelectionMgr->clearFilters();
797 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
798 aViewWindow->SetSelectionMode(ActorSelection);
799 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
800 LineEditElements->setReadOnly(true);
801 LineEditElements->setValidator(0);
803 int aConstructorId = GetConstructorId();
804 if (aConstructorId == 0)
806 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
807 aViewWindow->SetSelectionMode(EdgeSelection);
809 else if (aConstructorId == 0)
811 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
812 aViewWindow->SetSelectionMode(FaceSelection);
815 LineEditElements->setReadOnly(false);
816 LineEditElements->setValidator(myIdValidator);
817 onTextChange(LineEditElements->text());
820 SelectionIntoArgument();
823 //=================================================================================
824 // function : GetConstructorId()
826 //=================================================================================
827 int SMESHGUI_ExtrusionDlg::GetConstructorId()
829 return GroupConstructors->checkedId();
832 //=================================================================================
833 // function : keyPressEvent()
835 //=================================================================================
836 void SMESHGUI_ExtrusionDlg::keyPressEvent( QKeyEvent* e )
838 QDialog::keyPressEvent( e );
839 if ( e->isAccepted() )
842 if ( e->key() == Qt::Key_F1 ) {
848 //=================================================================================
849 // function : setFilters()
850 // purpose : SLOT. Called when "Filter" button pressed.
851 //=================================================================================
852 void SMESHGUI_ExtrusionDlg::setFilters()
854 if(myMesh->_is_nil()) {
855 SUIT_MessageBox::critical(this,
857 tr("NO_MESH_SELECTED"));
863 types.append( SMESH::EDGE );
864 types.append( SMESH::FACE );
865 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, types );
867 myFilterDlg->Init( GetConstructorId() ? SMESH::FACE : SMESH::EDGE );
869 myFilterDlg->SetSelection();
870 myFilterDlg->SetMesh( myMesh );
871 myFilterDlg->SetSourceWg( LineEditElements );
876 //=================================================================================
877 // function : isValid
879 //=================================================================================
880 bool SMESHGUI_ExtrusionDlg::isValid()
884 ok = SpinBox_Dx->isValid( msg, true ) && ok;
885 ok = SpinBox_Dy->isValid( msg, true ) && ok;
886 ok = SpinBox_Dz->isValid( msg, true ) && ok;
887 ok = SpinBox_NbSteps->isValid( msg, true ) && ok;
890 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
891 if ( !msg.isEmpty() )
893 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );