1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 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 // File : SMESHGUI_SymmetryDlg.cxx
23 // Author : Michael ZORIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_SymmetryDlg.h"
30 #include "SMESHGUI_SpinBox.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_IdValidator.h"
36 #include <SMESH_Actor.h>
37 #include <SMESH_TypeFilter.hxx>
38 #include <SMESH_LogicalFilter.hxx>
39 #include <SMDS_Mesh.hxx>
41 // SALOME GUI includes
42 #include <SUIT_Desktop.h>
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_OverrideCursor.h>
48 #include <LightApp_Application.h>
49 #include <LightApp_SelectionMgr.h>
51 #include <SVTK_ViewModel.h>
52 #include <SVTK_ViewWindow.h>
53 #include <SALOME_ListIO.hxx>
55 // SALOME KERNEL includes
56 #include <SALOMEDSClient_SObject.hxx>
59 #include <TColStd_MapOfInteger.hxx>
62 #include <QApplication>
63 #include <QButtonGroup>
67 #include <QPushButton>
68 #include <QRadioButton>
70 #include <QHBoxLayout>
71 #include <QVBoxLayout>
72 #include <QGridLayout>
76 #include <SALOMEconfig.h>
77 #include CORBA_SERVER_HEADER(SMESH_Group)
78 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
80 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
85 //=================================================================================
86 // class : SMESHGUI_SymmetryDlg()
88 //=================================================================================
90 SMESHGUI_SymmetryDlg::SMESHGUI_SymmetryDlg( SMESHGUI* theModule )
91 : QDialog( SMESH::GetDesktop( theModule ) ),
92 mySMESHGUI( theModule ),
93 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
95 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_POINT")));
96 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_AXIS")));
97 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_PLANE")));
98 QPixmap image3 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
101 setAttribute(Qt::WA_DeleteOnClose, true);
102 setWindowTitle(tr("SMESH_SYMMETRY"));
103 setSizeGripEnabled(true);
105 QVBoxLayout* SMESHGUI_SymmetryDlgLayout = new QVBoxLayout(this);
106 SMESHGUI_SymmetryDlgLayout->setSpacing(SPACING);
107 SMESHGUI_SymmetryDlgLayout->setMargin(MARGIN);
109 /***************************************************************/
110 ConstructorsBox = new QGroupBox(tr("SMESH_SYMMETRY"), 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);
120 RadioButton3 = new QRadioButton(ConstructorsBox);
121 RadioButton3->setIcon(image2);
123 ConstructorsBoxLayout->addWidget(RadioButton1);
124 ConstructorsBoxLayout->addWidget(RadioButton2);
125 ConstructorsBoxLayout->addWidget(RadioButton3);
126 GroupConstructors->addButton(RadioButton1, 0);
127 GroupConstructors->addButton(RadioButton2, 1);
128 GroupConstructors->addButton(RadioButton3, 2);
130 /***************************************************************/
131 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
132 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
133 GroupArgumentsLayout->setSpacing(SPACING);
134 GroupArgumentsLayout->setMargin(MARGIN);
136 myIdValidator = new SMESHGUI_IdValidator(this);
138 // Controls for elements selection
139 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
140 SelectElementsButton = new QPushButton(GroupArguments);
141 SelectElementsButton->setIcon(image3);
142 LineEditElements = new QLineEdit(GroupArguments);
143 LineEditElements->setValidator(myIdValidator);
145 // Control for the whole mesh selection
146 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
148 // Controls for mirror selection
149 GroupMirror = new QGroupBox(GroupArguments);
150 QGridLayout* GroupMirrorLayout = new QGridLayout(GroupMirror);
151 GroupMirrorLayout->setSpacing(SPACING);
152 GroupMirrorLayout->setMargin(MARGIN);
154 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupMirror);
155 SelectPointButton = new QPushButton(GroupMirror);
156 SelectPointButton->setIcon(image3);
158 TextLabelX = new QLabel(tr("SMESH_X"), GroupMirror);
159 SpinBox_X = new SMESHGUI_SpinBox(GroupMirror);
160 TextLabelY = new QLabel(tr("SMESH_Y"), GroupMirror);
161 SpinBox_Y = new SMESHGUI_SpinBox(GroupMirror);
162 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupMirror);
163 SpinBox_Z = new SMESHGUI_SpinBox(GroupMirror);
165 TextLabelVector = new QLabel(GroupMirror);
166 SelectVectorButton = new QPushButton(GroupMirror);
167 SelectVectorButton->setIcon(image3);
169 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupMirror);
170 SpinBox_DX = new SMESHGUI_SpinBox(GroupMirror);
171 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupMirror);
172 SpinBox_DY = new SMESHGUI_SpinBox(GroupMirror);
173 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupMirror);
174 SpinBox_DZ = new SMESHGUI_SpinBox(GroupMirror);
176 GroupMirrorLayout->addWidget(TextLabelPoint, 0, 0);
177 GroupMirrorLayout->addWidget(SelectPointButton, 0, 1);
178 GroupMirrorLayout->addWidget(TextLabelX, 0, 2);
179 GroupMirrorLayout->addWidget(SpinBox_X, 0, 3);
180 GroupMirrorLayout->addWidget(TextLabelY, 0, 4);
181 GroupMirrorLayout->addWidget(SpinBox_Y, 0, 5);
182 GroupMirrorLayout->addWidget(TextLabelZ, 0, 6);
183 GroupMirrorLayout->addWidget(SpinBox_Z, 0, 7);
184 GroupMirrorLayout->addWidget(TextLabelVector, 1, 0);
185 GroupMirrorLayout->addWidget(SelectVectorButton, 1, 1);
186 GroupMirrorLayout->addWidget(TextLabelDX, 1, 2);
187 GroupMirrorLayout->addWidget(SpinBox_DX, 1, 3);
188 GroupMirrorLayout->addWidget(TextLabelDY, 1, 4);
189 GroupMirrorLayout->addWidget(SpinBox_DY, 1, 5);
190 GroupMirrorLayout->addWidget(TextLabelDZ, 1, 6);
191 GroupMirrorLayout->addWidget(SpinBox_DZ, 1, 7);
193 // switch of action type
194 ActionBox = new QGroupBox(GroupArguments);
195 ActionGroup = new QButtonGroup(GroupArguments);
196 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
197 ActionBoxLayout->addSpacing(SPACING);
198 ActionBoxLayout->setMargin(MARGIN);
200 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
201 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
202 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
204 ActionBoxLayout->addWidget(aMoveElements);
205 ActionBoxLayout->addWidget(aCopyElements);
206 ActionBoxLayout->addWidget(aCreateMesh);
207 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
208 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
209 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
211 // CheckBox for groups generation
212 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
213 MakeGroupsCheck->setChecked(false);
215 // Name of a mesh to create
216 LineEditNewMesh = new QLineEdit(GroupArguments);
219 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
220 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
221 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 2);
222 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
223 GroupArgumentsLayout->addWidget(GroupMirror, 2, 0, 1, 4);
224 GroupArgumentsLayout->addWidget(ActionBox, 3, 0, 3, 3);
225 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 4, 3);
226 GroupArgumentsLayout->addWidget(LineEditNewMesh, 5, 3);
228 /***************************************************************/
229 GroupButtons = new QGroupBox(this);
230 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
231 GroupButtonsLayout->setSpacing(SPACING);
232 GroupButtonsLayout->setMargin(MARGIN);
234 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
235 buttonOk->setAutoDefault(true);
236 buttonOk->setDefault(true);
237 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
238 buttonApply->setAutoDefault(true);
239 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
240 buttonCancel->setAutoDefault(true);
241 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
242 buttonHelp->setAutoDefault(true);
244 GroupButtonsLayout->addWidget(buttonOk);
245 GroupButtonsLayout->addSpacing(10);
246 GroupButtonsLayout->addWidget(buttonApply);
247 GroupButtonsLayout->addSpacing(10);
248 GroupButtonsLayout->addStretch();
249 GroupButtonsLayout->addWidget(buttonCancel);
250 GroupButtonsLayout->addWidget(buttonHelp);
252 /***************************************************************/
253 SMESHGUI_SymmetryDlgLayout->addWidget(ConstructorsBox);
254 SMESHGUI_SymmetryDlgLayout->addWidget(GroupArguments);
255 SMESHGUI_SymmetryDlgLayout->addWidget(GroupButtons);
257 /* Initialisations */
258 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
259 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
260 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
261 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
262 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
263 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
265 RadioButton1->setChecked(true);
267 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
269 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
271 // Costruction of the logical filter
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 = "symmetry_page.html";
286 /* signals and slots connections */
287 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
288 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
289 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
290 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
291 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
293 connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
294 connect(SelectPointButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
295 connect(SelectVectorButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
297 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
298 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
299 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
301 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
302 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
303 /* to close dialog if study change */
304 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
305 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
306 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
307 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
309 ConstructorsClicked(0);
310 SelectionIntoArgument();
311 onActionClicked(MOVE_ELEMS_BUTTON);
314 //=================================================================================
315 // function : ~SMESHGUI_SymmetryDlg()
316 // purpose : Destroys the object and frees any allocated resources
317 //=================================================================================
318 SMESHGUI_SymmetryDlg::~SMESHGUI_SymmetryDlg()
322 //=================================================================================
325 //=================================================================================
326 void SMESHGUI_SymmetryDlg::Init (bool ResetControls)
330 myEditCurrentArgument = 0;
331 LineEditElements->clear();
335 buttonOk->setEnabled(false);
336 buttonApply->setEnabled(false);
339 myMesh = SMESH::SMESH_Mesh::_nil();
342 SpinBox_X->SetValue(0.0);
343 SpinBox_Y->SetValue(0.0);
344 SpinBox_Z->SetValue(0.0);
345 SpinBox_DX->SetValue(0.0);
346 SpinBox_DY->SetValue(0.0);
347 SpinBox_DZ->SetValue(0.0);
349 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
350 CheckBoxMesh->setChecked(false);
351 // MakeGroupsCheck->setChecked(false);
352 // MakeGroupsCheck->setEnabled(false);
357 //=================================================================================
358 // function : ConstructorsClicked()
359 // purpose : Radio button management
360 //=================================================================================
361 void SMESHGUI_SymmetryDlg::ConstructorsClicked (int constructorId)
363 disconnect(mySelectionMgr, 0, this, 0);
365 if (constructorId != 0 && !TextLabelVector->isVisible()) {
366 TextLabelVector->show();
367 SelectVectorButton->show();
376 switch (constructorId) {
379 GroupMirror->setTitle(tr("SMESH_POINT"));
381 TextLabelVector->hide();
382 SelectVectorButton->hide();
393 GroupMirror->setTitle(tr("SMESH_AXIS"));
394 TextLabelVector->setText(tr("SMESH_VECTOR"));
399 GroupMirror->setTitle(tr("SMESH_PLANE"));
400 TextLabelVector->setText(tr("SMESH_NORMAL"));
405 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
406 SMESH::SetPointRepresentation(false);
407 if (!CheckBoxMesh->isChecked())
409 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
410 aViewWindow->SetSelectionMode(CellSelection);
414 myEditCurrentArgument = (QWidget*)LineEditElements;
415 LineEditElements->setFocus();
417 if (CheckBoxMesh->isChecked())
420 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
422 QApplication::instance()->processEvents();
424 resize( minimumSize() );
427 //=================================================================================
428 // function : ClickOnApply()
430 //=================================================================================
431 void SMESHGUI_SymmetryDlg::ClickOnApply()
433 if (mySMESHGUI->isActiveStudyLocked())
436 if (myNbOkElements && IsMirrorOk()) {
437 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
439 SMESH::long_array_var anElementsId = new SMESH::long_array;
441 anElementsId->length(aListElementsId.count());
442 for (int i = 0; i < aListElementsId.count(); i++)
443 anElementsId[i] = aListElementsId[i].toInt();
445 SMESH::AxisStruct aMirror;
447 aMirror.x = SpinBox_X->GetValue();
448 aMirror.y = SpinBox_Y->GetValue();
449 aMirror.z = SpinBox_Z->GetValue();
450 if (GetConstructorId() == 0) {
451 aMirror.vx = aMirror.vy = aMirror.vz = 0;
453 aMirror.vx = SpinBox_DX->GetValue();
454 aMirror.vy = SpinBox_DY->GetValue();
455 aMirror.vz = SpinBox_DZ->GetValue();
459 SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
461 if (GetConstructorId() == 0)
462 aMirrorType = SMESH::SMESH_MeshEditor::POINT;
463 if (GetConstructorId() == 1)
464 aMirrorType = SMESH::SMESH_MeshEditor::AXIS;
465 if (GetConstructorId() == 2)
466 aMirrorType = SMESH::SMESH_MeshEditor::PLANE;
468 int actionButton = ActionGroup->checkedId();
469 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
472 SUIT_OverrideCursor aWaitCursor;
473 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
475 switch ( actionButton ) {
476 case MOVE_ELEMS_BUTTON:
477 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, false );
479 case COPY_ELEMS_BUTTON:
481 SMESH::ListOfGroups_var groups =
482 aMeshEditor->MirrorMakeGroups(anElementsId, aMirror, aMirrorType);
484 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, true);
486 case MAKE_MESH_BUTTON:
487 SMESH::SMESH_Mesh_var mesh =
488 aMeshEditor->MirrorMakeMesh(anElementsId, aMirror, aMirrorType, makeGroups,
489 LineEditNewMesh->text().toLatin1().data());
495 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
496 actionButton == MAKE_MESH_BUTTON )
497 mySMESHGUI->updateObjBrowser(true); // new groups may appear
499 ConstructorsClicked(GetConstructorId());
500 SelectionIntoArgument();
504 //=================================================================================
505 // function : ClickOnOk()
507 //=================================================================================
508 void SMESHGUI_SymmetryDlg::ClickOnOk()
514 //=================================================================================
515 // function : ClickOnCancel()
517 //=================================================================================
518 void SMESHGUI_SymmetryDlg::ClickOnCancel()
520 disconnect(mySelectionMgr, 0, this, 0);
521 mySelectionMgr->clearFilters();
522 //mySelectionMgr->clearSelected();
523 SMESH::SetPointRepresentation(false);
524 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
525 aViewWindow->SetSelectionMode(ActorSelection);
526 mySMESHGUI->ResetState();
530 //=================================================================================
531 // function : ClickOnHelp()
533 //=================================================================================
534 void SMESHGUI_SymmetryDlg::ClickOnHelp()
536 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
538 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
542 platform = "winapplication";
544 platform = "application";
546 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
547 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
548 arg(app->resourceMgr()->stringValue("ExternalBrowser",
550 arg(myHelpFileName));
554 //=======================================================================
555 // function : onTextChange()
557 //=======================================================================
558 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
560 QLineEdit* send = (QLineEdit*)sender();
565 if (send == LineEditElements)
568 buttonOk->setEnabled(false);
569 buttonApply->setEnabled(false);
571 // hilight entered elements
572 SMDS_Mesh* aMesh = 0;
574 aMesh = myActor->GetObject()->GetMesh();
577 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
579 TColStd_MapOfInteger newIndices;
581 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
583 if (send == LineEditElements) {
584 for (int i = 0; i < aListId.count(); i++) {
585 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
587 newIndices.Add(e->GetID());
591 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
592 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
593 aViewWindow->highlight( anIO, true, true );
595 myElementsId = theNewText;
599 if (myNbOkElements && IsMirrorOk()) {
600 buttonOk->setEnabled(true);
601 buttonApply->setEnabled(true);
607 //=================================================================================
608 // function : SelectionIntoArgument()
609 // purpose : Called when selection as changed or other case
610 //=================================================================================
611 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
617 QString aString = "";
620 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
621 LineEditElements->setText(aString);
623 buttonOk->setEnabled(false);
624 buttonApply->setEnabled(false);
628 if (!GroupButtons->isEnabled()) // inactive
633 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
635 int nbSel = aList.Extent();
639 Handle(SALOME_InteractiveObject) IO = aList.First();
640 myMesh = SMESH::GetMeshByIO(IO);
641 if(myMesh->_is_nil())
644 myActor = SMESH::FindActorByObject(myMesh);
646 myActor = SMESH::FindActorByEntry(IO->getEntry());
652 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
655 // MakeGroups is available if there are groups and "Copy"
656 if ( myMesh->NbGroups() == 0 ) {
657 MakeGroupsCheck->setChecked(false);
658 MakeGroupsCheck->setEnabled(false);
660 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
661 MakeGroupsCheck->setEnabled(true);
663 if (CheckBoxMesh->isChecked()) {
664 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
666 if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
668 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
672 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
673 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
675 myElementsId += QString(" %1").arg(i);
679 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
681 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
683 // get IDs from submesh
684 SMESH::long_array_var anElementsIds = new SMESH::long_array;
685 anElementsIds = aSubMesh->GetElementsId();
686 for (int i = 0; i < anElementsIds->length(); i++) {
687 myElementsId += QString(" %1").arg(anElementsIds[i]);
689 aNbUnits = anElementsIds->length();
692 SMESH::SMESH_GroupBase_var aGroup =
693 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
694 if (aGroup->_is_nil())
697 // get IDs from smesh group
698 SMESH::long_array_var anElementsIds = new SMESH::long_array;
699 anElementsIds = aGroup->GetListOfID();
700 for (int i = 0; i < anElementsIds->length(); i++) {
701 myElementsId += QString(" %1").arg(anElementsIds[i]);
703 aNbUnits = anElementsIds->length();
706 aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, IO, aString);
707 myElementsId = aString;
713 myNbOkElements = true;
715 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
719 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
723 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
731 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
732 SpinBox_X->SetValue(x);
733 SpinBox_Y->SetValue(y);
734 SpinBox_Z->SetValue(z);
735 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
736 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
737 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
738 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
743 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
744 LineEditElements->setEnabled(true);
745 LineEditElements->setText(aString);
746 LineEditElements->repaint();
747 LineEditElements->setEnabled(false);
753 if (myNbOkElements && IsMirrorOk()) {
754 buttonOk->setEnabled(true);
755 buttonApply->setEnabled(true);
759 //=================================================================================
760 // function : SetEditCurrentArgument()
762 //=================================================================================
763 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
765 QPushButton* send = (QPushButton*)sender();
767 disconnect(mySelectionMgr, 0, this, 0);
768 mySelectionMgr->clearSelected();
769 mySelectionMgr->clearFilters();
771 if (send == SelectElementsButton) {
772 myEditCurrentArgument = (QWidget*)LineEditElements;
773 SMESH::SetPointRepresentation(false);
774 if (CheckBoxMesh->isChecked()) {
775 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
776 aViewWindow->SetSelectionMode(ActorSelection);
777 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
779 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
780 aViewWindow->SetSelectionMode(CellSelection);
782 } else if (send == SelectPointButton) {
783 myEditCurrentArgument = (QWidget*)SpinBox_X;
784 SMESH::SetPointRepresentation(true);
785 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
786 aViewWindow->SetSelectionMode(NodeSelection);
787 } else if (send == SelectVectorButton) {
788 myEditCurrentArgument = (QWidget*)SpinBox_DX;
789 SMESH::SetPointRepresentation(true);
791 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
792 aViewWindow->SetSelectionMode(NodeSelection);
796 myEditCurrentArgument->setFocus();
797 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
798 SelectionIntoArgument();
801 //=================================================================================
802 // function : DeactivateActiveDialog()
804 //=================================================================================
805 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
807 if (ConstructorsBox->isEnabled()) {
808 ConstructorsBox->setEnabled(false);
809 GroupArguments->setEnabled(false);
810 GroupButtons->setEnabled(false);
811 mySMESHGUI->ResetState();
812 mySMESHGUI->SetActiveDialogBox(0);
816 //=================================================================================
817 // function : ActivateThisDialog()
819 //=================================================================================
820 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
822 /* Emit a signal to deactivate the active dialog */
823 mySMESHGUI->EmitSignalDeactivateDialog();
824 ConstructorsBox->setEnabled(true);
825 GroupArguments->setEnabled(true);
826 GroupButtons->setEnabled(true);
828 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
830 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
831 aViewWindow->SetSelectionMode(CellSelection);
832 SelectionIntoArgument();
835 //=================================================================================
836 // function : enterEvent()
838 //=================================================================================
839 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
841 if (!ConstructorsBox->isEnabled())
842 ActivateThisDialog();
845 //=================================================================================
846 // function : closeEvent()
848 //=================================================================================
849 void SMESHGUI_SymmetryDlg::closeEvent (QCloseEvent*)
851 /* same than click on cancel button */
855 //=======================================================================
856 // function : hideEvent()
857 // purpose : caused by ESC key
858 //=======================================================================
859 void SMESHGUI_SymmetryDlg::hideEvent (QHideEvent*)
865 //=======================================================================
866 //function : onSelectMesh
868 //=======================================================================
869 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
872 TextLabelElements->setText(tr("SMESH_NAME"));
874 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
876 if (myEditCurrentArgument != LineEditElements) {
877 LineEditElements->clear();
881 mySelectionMgr->clearFilters();
882 SMESH::SetPointRepresentation(false);
885 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
886 aViewWindow->SetSelectionMode(ActorSelection);
887 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
888 LineEditElements->setReadOnly(true);
889 LineEditElements->setValidator(0);
891 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
892 aViewWindow->SetSelectionMode(CellSelection);
893 LineEditElements->setReadOnly(false);
894 LineEditElements->setValidator(myIdValidator);
895 onTextChange(LineEditElements->text());
898 SelectionIntoArgument();
901 //=================================================================================
902 // function : GetConstructorId()
904 //=================================================================================
905 int SMESHGUI_SymmetryDlg::GetConstructorId()
907 return GroupConstructors->checkedId();
910 //=================================================================================
911 // function : IsMirrorOk()
913 //=================================================================================
914 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
918 if (GetConstructorId() != 0)
919 isOk = (SpinBox_DX->GetValue() != 0 ||
920 SpinBox_DY->GetValue() != 0 ||
921 SpinBox_DZ->GetValue() != 0);
926 //=================================================================================
927 // function : onVectorChanged()
929 //=================================================================================
930 void SMESHGUI_SymmetryDlg::onVectorChanged()
933 buttonOk->setEnabled(true);
934 buttonApply->setEnabled(true);
936 buttonOk->setEnabled(false);
937 buttonApply->setEnabled(false);
941 //=======================================================================
942 //function : onActionClicked
943 //purpose : slot called when an action type changed
944 //=======================================================================
946 void SMESHGUI_SymmetryDlg::onActionClicked(int button)
949 case MOVE_ELEMS_BUTTON:
950 MakeGroupsCheck->setEnabled(false);
951 LineEditNewMesh->setEnabled(false);
953 case COPY_ELEMS_BUTTON:
954 LineEditNewMesh->setEnabled(false);
955 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
956 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
957 MakeGroupsCheck->setEnabled(true);
959 MakeGroupsCheck->setEnabled(false);
961 case MAKE_MESH_BUTTON:
962 LineEditNewMesh->setEnabled(true);
963 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
964 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
965 MakeGroupsCheck->setEnabled(true);
967 MakeGroupsCheck->setEnabled(false);
973 //=======================================================================
974 //function : setNewMeshName
975 //purpose : update contents of LineEditNewMesh
976 //=======================================================================
978 void SMESHGUI_SymmetryDlg::setNewMeshName()
980 LineEditNewMesh->setText("");
981 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
983 if ( CheckBoxMesh->isChecked() ) {
984 name = LineEditElements->text();
987 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
988 name = meshSO->GetName().c_str();
990 if ( !name.isEmpty() )
991 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "mirrored"));
995 //=================================================================================
996 // function : keyPressEvent()
998 //=================================================================================
999 void SMESHGUI_SymmetryDlg::keyPressEvent( QKeyEvent* e )
1001 QDialog::keyPressEvent( e );
1002 if ( e->isAccepted() )
1005 if ( e->key() == Qt::Key_F1 ) {