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>
47 #include <LightApp_Application.h>
48 #include <LightApp_SelectionMgr.h>
50 #include <SVTK_ViewModel.h>
51 #include <SVTK_ViewWindow.h>
52 #include <SALOME_ListIO.hxx>
54 // SALOME KERNEL includes
55 #include <SALOMEDSClient_SObject.hxx>
58 #include <TColStd_MapOfInteger.hxx>
61 #include <QApplication>
62 #include <QButtonGroup>
66 #include <QPushButton>
67 #include <QRadioButton>
69 #include <QHBoxLayout>
70 #include <QVBoxLayout>
71 #include <QGridLayout>
75 #include <SALOMEconfig.h>
76 #include CORBA_SERVER_HEADER(SMESH_Group)
77 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
79 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
84 //=================================================================================
85 // class : SMESHGUI_SymmetryDlg()
87 //=================================================================================
89 SMESHGUI_SymmetryDlg::SMESHGUI_SymmetryDlg( SMESHGUI* theModule )
90 : QDialog( SMESH::GetDesktop( theModule ) ),
91 mySMESHGUI( theModule ),
92 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
94 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_POINT")));
95 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_AXIS")));
96 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_PLANE")));
97 QPixmap image3 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
100 setAttribute(Qt::WA_DeleteOnClose, true);
101 setWindowTitle(tr("SMESH_SYMMETRY"));
102 setSizeGripEnabled(true);
104 QVBoxLayout* SMESHGUI_SymmetryDlgLayout = new QVBoxLayout(this);
105 SMESHGUI_SymmetryDlgLayout->setSpacing(SPACING);
106 SMESHGUI_SymmetryDlgLayout->setMargin(MARGIN);
108 /***************************************************************/
109 ConstructorsBox = new QGroupBox(tr("SMESH_SYMMETRY"), this);
110 GroupConstructors = new QButtonGroup(this);
111 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
112 ConstructorsBoxLayout->setSpacing(SPACING);
113 ConstructorsBoxLayout->setMargin(MARGIN);
115 RadioButton1 = new QRadioButton(ConstructorsBox);
116 RadioButton1->setIcon(image0);
117 RadioButton2 = new QRadioButton(ConstructorsBox);
118 RadioButton2->setIcon(image1);
119 RadioButton3 = new QRadioButton(ConstructorsBox);
120 RadioButton3->setIcon(image2);
122 ConstructorsBoxLayout->addWidget(RadioButton1);
123 ConstructorsBoxLayout->addWidget(RadioButton2);
124 ConstructorsBoxLayout->addWidget(RadioButton3);
125 GroupConstructors->addButton(RadioButton1, 0);
126 GroupConstructors->addButton(RadioButton2, 1);
127 GroupConstructors->addButton(RadioButton3, 2);
129 /***************************************************************/
130 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
131 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
132 GroupArgumentsLayout->setSpacing(SPACING);
133 GroupArgumentsLayout->setMargin(MARGIN);
135 myIdValidator = new SMESHGUI_IdValidator(this);
137 // Controls for elements selection
138 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
139 SelectElementsButton = new QPushButton(GroupArguments);
140 SelectElementsButton->setIcon(image3);
141 LineEditElements = new QLineEdit(GroupArguments);
142 LineEditElements->setValidator(myIdValidator);
144 // Control for the whole mesh selection
145 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
147 // Controls for mirror selection
148 GroupMirror = new QGroupBox(GroupArguments);
149 QGridLayout* GroupMirrorLayout = new QGridLayout(GroupMirror);
150 GroupMirrorLayout->setSpacing(SPACING);
151 GroupMirrorLayout->setMargin(MARGIN);
153 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupMirror);
154 SelectPointButton = new QPushButton(GroupMirror);
155 SelectPointButton->setIcon(image3);
157 TextLabelX = new QLabel(tr("SMESH_X"), GroupMirror);
158 SpinBox_X = new SMESHGUI_SpinBox(GroupMirror);
159 TextLabelY = new QLabel(tr("SMESH_Y"), GroupMirror);
160 SpinBox_Y = new SMESHGUI_SpinBox(GroupMirror);
161 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupMirror);
162 SpinBox_Z = new SMESHGUI_SpinBox(GroupMirror);
164 TextLabelVector = new QLabel(GroupMirror);
165 SelectVectorButton = new QPushButton(GroupMirror);
166 SelectVectorButton->setIcon(image3);
168 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupMirror);
169 SpinBox_DX = new SMESHGUI_SpinBox(GroupMirror);
170 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupMirror);
171 SpinBox_DY = new SMESHGUI_SpinBox(GroupMirror);
172 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupMirror);
173 SpinBox_DZ = new SMESHGUI_SpinBox(GroupMirror);
175 GroupMirrorLayout->addWidget(TextLabelPoint, 0, 0);
176 GroupMirrorLayout->addWidget(SelectPointButton, 0, 1);
177 GroupMirrorLayout->addWidget(TextLabelX, 0, 2);
178 GroupMirrorLayout->addWidget(SpinBox_X, 0, 3);
179 GroupMirrorLayout->addWidget(TextLabelY, 0, 4);
180 GroupMirrorLayout->addWidget(SpinBox_Y, 0, 5);
181 GroupMirrorLayout->addWidget(TextLabelZ, 0, 6);
182 GroupMirrorLayout->addWidget(SpinBox_Z, 0, 7);
183 GroupMirrorLayout->addWidget(TextLabelVector, 1, 0);
184 GroupMirrorLayout->addWidget(SelectVectorButton, 1, 1);
185 GroupMirrorLayout->addWidget(TextLabelDX, 1, 2);
186 GroupMirrorLayout->addWidget(SpinBox_DX, 1, 3);
187 GroupMirrorLayout->addWidget(TextLabelDY, 1, 4);
188 GroupMirrorLayout->addWidget(SpinBox_DY, 1, 5);
189 GroupMirrorLayout->addWidget(TextLabelDZ, 1, 6);
190 GroupMirrorLayout->addWidget(SpinBox_DZ, 1, 7);
192 // switch of action type
193 ActionBox = new QGroupBox(GroupArguments);
194 ActionGroup = new QButtonGroup(GroupArguments);
195 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
196 ActionBoxLayout->addSpacing(SPACING);
197 ActionBoxLayout->setMargin(MARGIN);
199 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
200 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
201 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
203 ActionBoxLayout->addWidget(aMoveElements);
204 ActionBoxLayout->addWidget(aCopyElements);
205 ActionBoxLayout->addWidget(aCreateMesh);
206 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
207 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
208 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
210 // CheckBox for groups generation
211 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
212 MakeGroupsCheck->setChecked(false);
214 // Name of a mesh to create
215 LineEditNewMesh = new QLineEdit(GroupArguments);
218 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
219 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
220 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 2);
221 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
222 GroupArgumentsLayout->addWidget(GroupMirror, 2, 0, 1, 4);
223 GroupArgumentsLayout->addWidget(ActionBox, 3, 0, 3, 3);
224 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 4, 3);
225 GroupArgumentsLayout->addWidget(LineEditNewMesh, 5, 3);
227 /***************************************************************/
228 GroupButtons = new QGroupBox(this);
229 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
230 GroupButtonsLayout->setSpacing(SPACING);
231 GroupButtonsLayout->setMargin(MARGIN);
233 buttonOk = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons);
234 buttonOk->setAutoDefault(true);
235 buttonOk->setDefault(true);
236 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
237 buttonApply->setAutoDefault(true);
238 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
239 buttonCancel->setAutoDefault(true);
240 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
241 buttonHelp->setAutoDefault(true);
243 GroupButtonsLayout->addWidget(buttonOk);
244 GroupButtonsLayout->addSpacing(10);
245 GroupButtonsLayout->addWidget(buttonApply);
246 GroupButtonsLayout->addSpacing(10);
247 GroupButtonsLayout->addStretch();
248 GroupButtonsLayout->addWidget(buttonCancel);
249 GroupButtonsLayout->addWidget(buttonHelp);
251 /***************************************************************/
252 SMESHGUI_SymmetryDlgLayout->addWidget(ConstructorsBox);
253 SMESHGUI_SymmetryDlgLayout->addWidget(GroupArguments);
254 SMESHGUI_SymmetryDlgLayout->addWidget(GroupButtons);
256 /* Initialisations */
257 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
258 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
259 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
260 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
261 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
262 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
264 RadioButton1->setChecked(true);
266 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
268 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
270 // Costruction of the logical filter
271 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
272 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
274 QList<SUIT_SelectionFilter*> aListOfFilters;
275 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
276 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
278 myMeshOrSubMeshOrGroupFilter =
279 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
281 myHelpFileName = "symmetry_page.html";
285 /* signals and slots connections */
286 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
287 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
288 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
289 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
290 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
292 connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
293 connect(SelectPointButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
294 connect(SelectVectorButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
296 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
297 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
298 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
300 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
301 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
302 /* to close dialog if study change */
303 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
304 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
305 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
306 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
308 ConstructorsClicked(0);
309 SelectionIntoArgument();
310 onActionClicked(MOVE_ELEMS_BUTTON);
313 //=================================================================================
314 // function : ~SMESHGUI_SymmetryDlg()
315 // purpose : Destroys the object and frees any allocated resources
316 //=================================================================================
317 SMESHGUI_SymmetryDlg::~SMESHGUI_SymmetryDlg()
321 //=================================================================================
324 //=================================================================================
325 void SMESHGUI_SymmetryDlg::Init (bool ResetControls)
329 myEditCurrentArgument = 0;
330 LineEditElements->clear();
334 buttonOk->setEnabled(false);
335 buttonApply->setEnabled(false);
338 myMesh = SMESH::SMESH_Mesh::_nil();
341 SpinBox_X->SetValue(0.0);
342 SpinBox_Y->SetValue(0.0);
343 SpinBox_Z->SetValue(0.0);
344 SpinBox_DX->SetValue(0.0);
345 SpinBox_DY->SetValue(0.0);
346 SpinBox_DZ->SetValue(0.0);
348 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
349 CheckBoxMesh->setChecked(false);
350 // MakeGroupsCheck->setChecked(false);
351 // MakeGroupsCheck->setEnabled(false);
356 //=================================================================================
357 // function : ConstructorsClicked()
358 // purpose : Radio button management
359 //=================================================================================
360 void SMESHGUI_SymmetryDlg::ConstructorsClicked (int constructorId)
362 disconnect(mySelectionMgr, 0, this, 0);
364 if (constructorId != 0 && !TextLabelVector->isVisible()) {
365 TextLabelVector->show();
366 SelectVectorButton->show();
375 switch (constructorId) {
378 GroupMirror->setTitle(tr("SMESH_POINT"));
380 TextLabelVector->hide();
381 SelectVectorButton->hide();
392 GroupMirror->setTitle(tr("SMESH_AXIS"));
393 TextLabelVector->setText(tr("SMESH_VECTOR"));
398 GroupMirror->setTitle(tr("SMESH_PLANE"));
399 TextLabelVector->setText(tr("SMESH_NORMAL"));
404 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
405 SMESH::SetPointRepresentation(false);
406 if (!CheckBoxMesh->isChecked())
408 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
409 aViewWindow->SetSelectionMode(CellSelection);
413 myEditCurrentArgument = (QWidget*)LineEditElements;
414 LineEditElements->setFocus();
416 if (CheckBoxMesh->isChecked())
419 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
421 QApplication::instance()->processEvents();
423 resize( minimumSize() );
426 //=================================================================================
427 // function : ClickOnApply()
429 //=================================================================================
430 void SMESHGUI_SymmetryDlg::ClickOnApply()
432 if (mySMESHGUI->isActiveStudyLocked())
435 if (myNbOkElements && IsMirrorOk()) {
436 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
438 SMESH::long_array_var anElementsId = new SMESH::long_array;
440 anElementsId->length(aListElementsId.count());
441 for (int i = 0; i < aListElementsId.count(); i++)
442 anElementsId[i] = aListElementsId[i].toInt();
444 SMESH::AxisStruct aMirror;
446 aMirror.x = SpinBox_X->GetValue();
447 aMirror.y = SpinBox_Y->GetValue();
448 aMirror.z = SpinBox_Z->GetValue();
449 if (GetConstructorId() == 0) {
450 aMirror.vx = aMirror.vy = aMirror.vz = 0;
452 aMirror.vx = SpinBox_DX->GetValue();
453 aMirror.vy = SpinBox_DY->GetValue();
454 aMirror.vz = SpinBox_DZ->GetValue();
458 SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
460 if (GetConstructorId() == 0)
461 aMirrorType = SMESH::SMESH_MeshEditor::POINT;
462 if (GetConstructorId() == 1)
463 aMirrorType = SMESH::SMESH_MeshEditor::AXIS;
464 if (GetConstructorId() == 2)
465 aMirrorType = SMESH::SMESH_MeshEditor::PLANE;
467 int actionButton = ActionGroup->checkedId();
468 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
471 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
472 QApplication::setOverrideCursor(Qt::WaitCursor);
473 switch ( actionButton ) {
474 case MOVE_ELEMS_BUTTON:
475 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, false );
477 case COPY_ELEMS_BUTTON:
479 SMESH::ListOfGroups_var groups =
480 aMeshEditor->MirrorMakeGroups(anElementsId, aMirror, aMirrorType);
482 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, true);
484 case MAKE_MESH_BUTTON:
485 SMESH::SMESH_Mesh_var mesh =
486 aMeshEditor->MirrorMakeMesh(anElementsId, aMirror, aMirrorType, makeGroups,
487 LineEditNewMesh->text().toLatin1().data());
489 QApplication::restoreOverrideCursor();
494 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
495 actionButton == MAKE_MESH_BUTTON )
496 mySMESHGUI->updateObjBrowser(true); // new groups may appear
498 ConstructorsClicked(GetConstructorId());
499 SelectionIntoArgument();
503 //=================================================================================
504 // function : ClickOnOk()
506 //=================================================================================
507 void SMESHGUI_SymmetryDlg::ClickOnOk()
513 //=================================================================================
514 // function : ClickOnCancel()
516 //=================================================================================
517 void SMESHGUI_SymmetryDlg::ClickOnCancel()
519 disconnect(mySelectionMgr, 0, this, 0);
520 mySelectionMgr->clearFilters();
521 //mySelectionMgr->clearSelected();
522 SMESH::SetPointRepresentation(false);
523 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
524 aViewWindow->SetSelectionMode(ActorSelection);
525 mySMESHGUI->ResetState();
529 //=================================================================================
530 // function : ClickOnHelp()
532 //=================================================================================
533 void SMESHGUI_SymmetryDlg::ClickOnHelp()
535 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
537 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
541 platform = "winapplication";
543 platform = "application";
545 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
546 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
547 arg(app->resourceMgr()->stringValue("ExternalBrowser",
549 arg(myHelpFileName));
553 //=======================================================================
554 // function : onTextChange()
556 //=======================================================================
557 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
559 QLineEdit* send = (QLineEdit*)sender();
564 if (send == LineEditElements)
567 buttonOk->setEnabled(false);
568 buttonApply->setEnabled(false);
570 // hilight entered elements
571 SMDS_Mesh* aMesh = 0;
573 aMesh = myActor->GetObject()->GetMesh();
576 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
578 TColStd_MapOfInteger newIndices;
580 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
582 if (send == LineEditElements) {
583 for (int i = 0; i < aListId.count(); i++) {
584 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
586 newIndices.Add(e->GetID());
590 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
591 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
592 aViewWindow->highlight( anIO, true, true );
594 myElementsId = theNewText;
598 if (myNbOkElements && IsMirrorOk()) {
599 buttonOk->setEnabled(true);
600 buttonApply->setEnabled(true);
606 //=================================================================================
607 // function : SelectionIntoArgument()
608 // purpose : Called when selection as changed or other case
609 //=================================================================================
610 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
616 QString aString = "";
619 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
620 LineEditElements->setText(aString);
622 buttonOk->setEnabled(false);
623 buttonApply->setEnabled(false);
627 if (!GroupButtons->isEnabled()) // inactive
632 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
634 int nbSel = aList.Extent();
638 Handle(SALOME_InteractiveObject) IO = aList.First();
639 myMesh = SMESH::GetMeshByIO(IO);
640 if(myMesh->_is_nil())
643 myActor = SMESH::FindActorByObject(myMesh);
645 myActor = SMESH::FindActorByEntry(IO->getEntry());
651 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
654 // MakeGroups is available if there are groups and "Copy"
655 if ( myMesh->NbGroups() == 0 ) {
656 MakeGroupsCheck->setChecked(false);
657 MakeGroupsCheck->setEnabled(false);
659 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
660 MakeGroupsCheck->setEnabled(true);
662 if (CheckBoxMesh->isChecked()) {
663 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
665 if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
667 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
671 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
672 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
674 myElementsId += QString(" %1").arg(i);
678 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
680 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
682 // get IDs from submesh
683 SMESH::long_array_var anElementsIds = new SMESH::long_array;
684 anElementsIds = aSubMesh->GetElementsId();
685 for (int i = 0; i < anElementsIds->length(); i++) {
686 myElementsId += QString(" %1").arg(anElementsIds[i]);
688 aNbUnits = anElementsIds->length();
691 SMESH::SMESH_GroupBase_var aGroup =
692 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
693 if (aGroup->_is_nil())
696 // get IDs from smesh group
697 SMESH::long_array_var anElementsIds = new SMESH::long_array;
698 anElementsIds = aGroup->GetListOfID();
699 for (int i = 0; i < anElementsIds->length(); i++) {
700 myElementsId += QString(" %1").arg(anElementsIds[i]);
702 aNbUnits = anElementsIds->length();
705 aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, IO, aString);
706 myElementsId = aString;
712 myNbOkElements = true;
714 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
718 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
722 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
730 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
731 SpinBox_X->SetValue(x);
732 SpinBox_Y->SetValue(y);
733 SpinBox_Z->SetValue(z);
734 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
735 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
736 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
737 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
742 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
743 LineEditElements->setText(aString);
749 if (myNbOkElements && IsMirrorOk()) {
750 buttonOk->setEnabled(true);
751 buttonApply->setEnabled(true);
755 //=================================================================================
756 // function : SetEditCurrentArgument()
758 //=================================================================================
759 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
761 QPushButton* send = (QPushButton*)sender();
763 disconnect(mySelectionMgr, 0, this, 0);
764 mySelectionMgr->clearSelected();
765 mySelectionMgr->clearFilters();
767 if (send == SelectElementsButton) {
768 myEditCurrentArgument = (QWidget*)LineEditElements;
769 SMESH::SetPointRepresentation(false);
770 if (CheckBoxMesh->isChecked()) {
771 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
772 aViewWindow->SetSelectionMode(ActorSelection);
773 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
775 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
776 aViewWindow->SetSelectionMode(CellSelection);
778 } else if (send == SelectPointButton) {
779 myEditCurrentArgument = (QWidget*)SpinBox_X;
780 SMESH::SetPointRepresentation(true);
781 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
782 aViewWindow->SetSelectionMode(NodeSelection);
783 } else if (send == SelectVectorButton) {
784 myEditCurrentArgument = (QWidget*)SpinBox_DX;
785 SMESH::SetPointRepresentation(true);
787 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
788 aViewWindow->SetSelectionMode(NodeSelection);
792 myEditCurrentArgument->setFocus();
793 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
794 SelectionIntoArgument();
797 //=================================================================================
798 // function : DeactivateActiveDialog()
800 //=================================================================================
801 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
803 if (ConstructorsBox->isEnabled()) {
804 ConstructorsBox->setEnabled(false);
805 GroupArguments->setEnabled(false);
806 GroupButtons->setEnabled(false);
807 mySMESHGUI->ResetState();
808 mySMESHGUI->SetActiveDialogBox(0);
812 //=================================================================================
813 // function : ActivateThisDialog()
815 //=================================================================================
816 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
818 /* Emit a signal to deactivate the active dialog */
819 mySMESHGUI->EmitSignalDeactivateDialog();
820 ConstructorsBox->setEnabled(true);
821 GroupArguments->setEnabled(true);
822 GroupButtons->setEnabled(true);
824 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
826 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
827 aViewWindow->SetSelectionMode(CellSelection);
828 SelectionIntoArgument();
831 //=================================================================================
832 // function : enterEvent()
834 //=================================================================================
835 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
837 if (!ConstructorsBox->isEnabled())
838 ActivateThisDialog();
841 //=================================================================================
842 // function : closeEvent()
844 //=================================================================================
845 void SMESHGUI_SymmetryDlg::closeEvent (QCloseEvent*)
847 /* same than click on cancel button */
851 //=======================================================================
852 // function : hideEvent()
853 // purpose : caused by ESC key
854 //=======================================================================
855 void SMESHGUI_SymmetryDlg::hideEvent (QHideEvent*)
861 //=======================================================================
862 //function : onSelectMesh
864 //=======================================================================
865 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
868 TextLabelElements->setText(tr("SMESH_NAME"));
870 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
872 if (myEditCurrentArgument != LineEditElements) {
873 LineEditElements->clear();
877 mySelectionMgr->clearFilters();
878 SMESH::SetPointRepresentation(false);
881 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
882 aViewWindow->SetSelectionMode(ActorSelection);
883 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
884 LineEditElements->setReadOnly(true);
885 LineEditElements->setValidator(0);
887 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
888 aViewWindow->SetSelectionMode(CellSelection);
889 LineEditElements->setReadOnly(false);
890 LineEditElements->setValidator(myIdValidator);
891 onTextChange(LineEditElements->text());
894 SelectionIntoArgument();
897 //=================================================================================
898 // function : GetConstructorId()
900 //=================================================================================
901 int SMESHGUI_SymmetryDlg::GetConstructorId()
903 return GroupConstructors->checkedId();
906 //=================================================================================
907 // function : IsMirrorOk()
909 //=================================================================================
910 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
914 if (GetConstructorId() != 0)
915 isOk = (SpinBox_DX->GetValue() != 0 ||
916 SpinBox_DY->GetValue() != 0 ||
917 SpinBox_DZ->GetValue() != 0);
922 //=================================================================================
923 // function : onVectorChanged()
925 //=================================================================================
926 void SMESHGUI_SymmetryDlg::onVectorChanged()
929 buttonOk->setEnabled(true);
930 buttonApply->setEnabled(true);
932 buttonOk->setEnabled(false);
933 buttonApply->setEnabled(false);
937 //=======================================================================
938 //function : onActionClicked
939 //purpose : slot called when an action type changed
940 //=======================================================================
942 void SMESHGUI_SymmetryDlg::onActionClicked(int button)
945 case MOVE_ELEMS_BUTTON:
946 MakeGroupsCheck->setEnabled(false);
947 LineEditNewMesh->setEnabled(false);
949 case COPY_ELEMS_BUTTON:
950 LineEditNewMesh->setEnabled(false);
951 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
952 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
953 MakeGroupsCheck->setEnabled(true);
955 MakeGroupsCheck->setEnabled(false);
957 case MAKE_MESH_BUTTON:
958 LineEditNewMesh->setEnabled(true);
959 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
960 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
961 MakeGroupsCheck->setEnabled(true);
963 MakeGroupsCheck->setEnabled(false);
969 //=======================================================================
970 //function : setNewMeshName
971 //purpose : update contents of LineEditNewMesh
972 //=======================================================================
974 void SMESHGUI_SymmetryDlg::setNewMeshName()
976 LineEditNewMesh->setText("");
977 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
979 if ( CheckBoxMesh->isChecked() ) {
980 name = LineEditElements->text();
983 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
984 name = meshSO->GetName().c_str();
986 if ( !name.isEmpty() )
987 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "mirrored"));
991 //=================================================================================
992 // function : keyPressEvent()
994 //=================================================================================
995 void SMESHGUI_SymmetryDlg::keyPressEvent( QKeyEvent* e )
997 QDialog::keyPressEvent( e );
998 if ( e->isAccepted() )
1001 if ( e->key() == Qt::Key_F1 ) {