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 // Controls for elements selection
136 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
137 SelectElementsButton = new QPushButton(GroupArguments);
138 SelectElementsButton->setIcon(image3);
139 LineEditElements = new QLineEdit(GroupArguments);
140 LineEditElements->setValidator(new SMESHGUI_IdValidator(this));
142 // Control for the whole mesh selection
143 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
145 // Controls for mirror selection
146 GroupMirror = new QGroupBox(GroupArguments);
147 QGridLayout* GroupMirrorLayout = new QGridLayout(GroupMirror);
148 GroupMirrorLayout->setSpacing(SPACING);
149 GroupMirrorLayout->setMargin(MARGIN);
151 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupMirror);
152 SelectPointButton = new QPushButton(GroupMirror);
153 SelectPointButton->setIcon(image3);
155 TextLabelX = new QLabel(tr("SMESH_X"), GroupMirror);
156 SpinBox_X = new SMESHGUI_SpinBox(GroupMirror);
157 TextLabelY = new QLabel(tr("SMESH_Y"), GroupMirror);
158 SpinBox_Y = new SMESHGUI_SpinBox(GroupMirror);
159 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupMirror);
160 SpinBox_Z = new SMESHGUI_SpinBox(GroupMirror);
162 TextLabelVector = new QLabel(GroupMirror);
163 SelectVectorButton = new QPushButton(GroupMirror);
164 SelectVectorButton->setIcon(image3);
166 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupMirror);
167 SpinBox_DX = new SMESHGUI_SpinBox(GroupMirror);
168 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupMirror);
169 SpinBox_DY = new SMESHGUI_SpinBox(GroupMirror);
170 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupMirror);
171 SpinBox_DZ = new SMESHGUI_SpinBox(GroupMirror);
173 GroupMirrorLayout->addWidget(TextLabelPoint, 0, 0);
174 GroupMirrorLayout->addWidget(SelectPointButton, 0, 1);
175 GroupMirrorLayout->addWidget(TextLabelX, 0, 2);
176 GroupMirrorLayout->addWidget(SpinBox_X, 0, 3);
177 GroupMirrorLayout->addWidget(TextLabelY, 0, 4);
178 GroupMirrorLayout->addWidget(SpinBox_Y, 0, 5);
179 GroupMirrorLayout->addWidget(TextLabelZ, 0, 6);
180 GroupMirrorLayout->addWidget(SpinBox_Z, 0, 7);
181 GroupMirrorLayout->addWidget(TextLabelVector, 1, 0);
182 GroupMirrorLayout->addWidget(SelectVectorButton, 1, 1);
183 GroupMirrorLayout->addWidget(TextLabelDX, 1, 2);
184 GroupMirrorLayout->addWidget(SpinBox_DX, 1, 3);
185 GroupMirrorLayout->addWidget(TextLabelDY, 1, 4);
186 GroupMirrorLayout->addWidget(SpinBox_DY, 1, 5);
187 GroupMirrorLayout->addWidget(TextLabelDZ, 1, 6);
188 GroupMirrorLayout->addWidget(SpinBox_DZ, 1, 7);
190 // switch of action type
191 ActionBox = new QGroupBox(tr("ACTION"), GroupArguments);
192 ActionGroup = new QButtonGroup(GroupArguments);
193 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
194 ActionBoxLayout->addSpacing(SPACING);
195 ActionBoxLayout->setMargin(MARGIN);
197 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
198 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
199 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
201 ActionBoxLayout->addWidget(aMoveElements);
202 ActionBoxLayout->addWidget(aCopyElements);
203 ActionBoxLayout->addWidget(aCreateMesh);
204 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
205 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
206 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
208 // CheckBox for groups generation
209 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
210 MakeGroupsCheck->setChecked(false);
212 // Name of a mesh to create
213 LineEditNewMesh = new QLineEdit(GroupArguments);
216 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
217 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
218 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 2);
219 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
220 GroupArgumentsLayout->addWidget(GroupMirror, 2, 0, 1, 4);
221 GroupArgumentsLayout->addWidget(ActionBox, 3, 0, 3, 3);
222 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 4, 4);
223 GroupArgumentsLayout->addWidget(LineEditNewMesh, 5, 4);
225 /***************************************************************/
226 GroupButtons = new QGroupBox(this);
227 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
228 GroupButtonsLayout->setSpacing(SPACING);
229 GroupButtonsLayout->setMargin(MARGIN);
231 buttonOk = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons);
232 buttonOk->setAutoDefault(true);
233 buttonOk->setDefault(true);
234 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
235 buttonApply->setAutoDefault(true);
236 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
237 buttonCancel->setAutoDefault(true);
238 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
239 buttonHelp->setAutoDefault(true);
241 GroupButtonsLayout->addWidget(buttonOk);
242 GroupButtonsLayout->addSpacing(10);
243 GroupButtonsLayout->addWidget(buttonApply);
244 GroupButtonsLayout->addSpacing(10);
245 GroupButtonsLayout->addStretch();
246 GroupButtonsLayout->addWidget(buttonCancel);
247 GroupButtonsLayout->addWidget(buttonHelp);
249 /***************************************************************/
250 SMESHGUI_SymmetryDlgLayout->addWidget(ConstructorsBox);
251 SMESHGUI_SymmetryDlgLayout->addWidget(GroupArguments);
252 SMESHGUI_SymmetryDlgLayout->addWidget(GroupButtons);
254 /* Initialisations */
255 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
256 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
257 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
258 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
259 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
260 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
262 RadioButton1->setChecked(true);
264 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
266 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
268 // Costruction of the logical filter
269 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
270 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
272 QList<SUIT_SelectionFilter*> aListOfFilters;
273 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
274 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
276 myMeshOrSubMeshOrGroupFilter =
277 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
279 myHelpFileName = "symmetry_page.html";
283 /* signals and slots connections */
284 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
285 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
286 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
287 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
288 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
290 connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
291 connect(SelectPointButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
292 connect(SelectVectorButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
294 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
295 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
296 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
298 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
299 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
300 /* to close dialog if study change */
301 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
302 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
303 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
304 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
306 ConstructorsClicked(0);
307 SelectionIntoArgument();
308 onActionClicked(MOVE_ELEMS_BUTTON);
311 //=================================================================================
312 // function : ~SMESHGUI_SymmetryDlg()
313 // purpose : Destroys the object and frees any allocated resources
314 //=================================================================================
315 SMESHGUI_SymmetryDlg::~SMESHGUI_SymmetryDlg()
319 //=================================================================================
322 //=================================================================================
323 void SMESHGUI_SymmetryDlg::Init (bool ResetControls)
327 myEditCurrentArgument = 0;
328 LineEditElements->clear();
332 buttonOk->setEnabled(false);
333 buttonApply->setEnabled(false);
336 myMesh = SMESH::SMESH_Mesh::_nil();
339 SpinBox_X->SetValue(0.0);
340 SpinBox_Y->SetValue(0.0);
341 SpinBox_Z->SetValue(0.0);
342 SpinBox_DX->SetValue(0.0);
343 SpinBox_DY->SetValue(0.0);
344 SpinBox_DZ->SetValue(0.0);
346 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
347 CheckBoxMesh->setChecked(false);
348 // MakeGroupsCheck->setChecked(false);
349 // MakeGroupsCheck->setEnabled(false);
354 //=================================================================================
355 // function : ConstructorsClicked()
356 // purpose : Radio button management
357 //=================================================================================
358 void SMESHGUI_SymmetryDlg::ConstructorsClicked (int constructorId)
360 disconnect(mySelectionMgr, 0, this, 0);
362 if (constructorId != 0 && !TextLabelVector->isVisible()) {
363 TextLabelVector->show();
364 SelectVectorButton->show();
373 switch (constructorId) {
376 GroupMirror->setTitle(tr("SMESH_POINT"));
378 TextLabelVector->hide();
379 SelectVectorButton->hide();
390 GroupMirror->setTitle(tr("SMESH_AXIS"));
391 TextLabelVector->setText(tr("SMESH_VECTOR"));
396 GroupMirror->setTitle(tr("SMESH_PLANE"));
397 TextLabelVector->setText(tr("SMESH_NORMAL"));
402 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
403 SMESH::SetPointRepresentation(false);
404 if (!CheckBoxMesh->isChecked())
406 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
407 aViewWindow->SetSelectionMode(CellSelection);
411 myEditCurrentArgument = (QWidget*)LineEditElements;
412 LineEditElements->setFocus();
414 if (CheckBoxMesh->isChecked())
417 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
419 QApplication::instance()->processEvents();
421 resize( minimumSize() );
424 //=================================================================================
425 // function : ClickOnApply()
427 //=================================================================================
428 void SMESHGUI_SymmetryDlg::ClickOnApply()
430 if (mySMESHGUI->isActiveStudyLocked())
433 if (myNbOkElements && IsMirrorOk()) {
434 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
436 SMESH::long_array_var anElementsId = new SMESH::long_array;
438 anElementsId->length(aListElementsId.count());
439 for (int i = 0; i < aListElementsId.count(); i++)
440 anElementsId[i] = aListElementsId[i].toInt();
442 SMESH::AxisStruct aMirror;
444 aMirror.x = SpinBox_X->GetValue();
445 aMirror.y = SpinBox_Y->GetValue();
446 aMirror.z = SpinBox_Z->GetValue();
447 if (GetConstructorId() == 0) {
448 aMirror.vx = aMirror.vy = aMirror.vz = 0;
450 aMirror.vx = SpinBox_DX->GetValue();
451 aMirror.vy = SpinBox_DY->GetValue();
452 aMirror.vz = SpinBox_DZ->GetValue();
456 SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
458 if (GetConstructorId() == 0)
459 aMirrorType = SMESH::SMESH_MeshEditor::POINT;
460 if (GetConstructorId() == 1)
461 aMirrorType = SMESH::SMESH_MeshEditor::AXIS;
462 if (GetConstructorId() == 2)
463 aMirrorType = SMESH::SMESH_MeshEditor::PLANE;
465 int actionButton = ActionGroup->checkedId();
466 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
469 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
470 QApplication::setOverrideCursor(Qt::WaitCursor);
471 switch ( actionButton ) {
472 case MOVE_ELEMS_BUTTON:
473 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, false );
475 case COPY_ELEMS_BUTTON:
477 SMESH::ListOfGroups_var groups =
478 aMeshEditor->MirrorMakeGroups(anElementsId, aMirror, aMirrorType);
480 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, true);
482 case MAKE_MESH_BUTTON:
483 SMESH::SMESH_Mesh_var mesh =
484 aMeshEditor->MirrorMakeMesh(anElementsId, aMirror, aMirrorType, makeGroups,
485 LineEditNewMesh->text().toLatin1().data());
487 QApplication::restoreOverrideCursor();
492 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
493 actionButton == MAKE_MESH_BUTTON )
494 mySMESHGUI->updateObjBrowser(true); // new groups may appear
496 ConstructorsClicked(GetConstructorId());
497 SelectionIntoArgument();
501 //=================================================================================
502 // function : ClickOnOk()
504 //=================================================================================
505 void SMESHGUI_SymmetryDlg::ClickOnOk()
511 //=================================================================================
512 // function : ClickOnCancel()
514 //=================================================================================
515 void SMESHGUI_SymmetryDlg::ClickOnCancel()
517 disconnect(mySelectionMgr, 0, this, 0);
518 mySelectionMgr->clearFilters();
519 //mySelectionMgr->clearSelected();
520 SMESH::SetPointRepresentation(false);
521 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
522 aViewWindow->SetSelectionMode(ActorSelection);
523 mySMESHGUI->ResetState();
527 //=================================================================================
528 // function : ClickOnHelp()
530 //=================================================================================
531 void SMESHGUI_SymmetryDlg::ClickOnHelp()
533 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
535 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
539 platform = "winapplication";
541 platform = "application";
543 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
544 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
545 arg(app->resourceMgr()->stringValue("ExternalBrowser",
547 arg(myHelpFileName));
551 //=======================================================================
552 // function : onTextChange()
554 //=======================================================================
555 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
557 QLineEdit* send = (QLineEdit*)sender();
562 if (send == LineEditElements)
565 buttonOk->setEnabled(false);
566 buttonApply->setEnabled(false);
568 // hilight entered elements
569 SMDS_Mesh* aMesh = 0;
571 aMesh = myActor->GetObject()->GetMesh();
574 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
576 TColStd_MapOfInteger newIndices;
578 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
580 if (send == LineEditElements) {
581 for (int i = 0; i < aListId.count(); i++) {
582 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
584 newIndices.Add(e->GetID());
588 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
589 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
590 aViewWindow->highlight( anIO, true, true );
592 myElementsId = theNewText;
596 if (myNbOkElements && IsMirrorOk()) {
597 buttonOk->setEnabled(true);
598 buttonApply->setEnabled(true);
604 //=================================================================================
605 // function : SelectionIntoArgument()
606 // purpose : Called when selection as changed or other case
607 //=================================================================================
608 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
614 QString aString = "";
617 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
618 LineEditElements->setText(aString);
620 buttonOk->setEnabled(false);
621 buttonApply->setEnabled(false);
625 if (!GroupButtons->isEnabled()) // inactive
630 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
632 int nbSel = aList.Extent();
636 Handle(SALOME_InteractiveObject) IO = aList.First();
637 myMesh = SMESH::GetMeshByIO(IO);
638 if(myMesh->_is_nil())
641 myActor = SMESH::FindActorByObject(myMesh);
643 myActor = SMESH::FindActorByEntry(IO->getEntry());
649 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
652 // MakeGroups is available if there are groups and "Copy"
653 if ( myMesh->NbGroups() == 0 ) {
654 MakeGroupsCheck->setChecked(false);
655 MakeGroupsCheck->setEnabled(false);
657 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
658 MakeGroupsCheck->setEnabled(true);
660 if (CheckBoxMesh->isChecked()) {
661 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
663 if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
665 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
669 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
670 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
672 myElementsId += QString(" %1").arg(i);
676 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
678 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
680 // get IDs from submesh
681 SMESH::long_array_var anElementsIds = new SMESH::long_array;
682 anElementsIds = aSubMesh->GetElementsId();
683 for (int i = 0; i < anElementsIds->length(); i++) {
684 myElementsId += QString(" %1").arg(anElementsIds[i]);
686 aNbUnits = anElementsIds->length();
689 SMESH::SMESH_GroupBase_var aGroup =
690 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
691 if (aGroup->_is_nil())
694 // get IDs from smesh group
695 SMESH::long_array_var anElementsIds = new SMESH::long_array;
696 anElementsIds = aGroup->GetListOfID();
697 for (int i = 0; i < anElementsIds->length(); i++) {
698 myElementsId += QString(" %1").arg(anElementsIds[i]);
700 aNbUnits = anElementsIds->length();
703 aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, IO, aString);
704 myElementsId = aString;
710 myNbOkElements = true;
712 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
716 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
720 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
728 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
729 SpinBox_X->SetValue(x);
730 SpinBox_Y->SetValue(y);
731 SpinBox_Z->SetValue(z);
732 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
733 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
734 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
735 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
740 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
741 LineEditElements->setText(aString);
747 if (myNbOkElements && IsMirrorOk()) {
748 buttonOk->setEnabled(true);
749 buttonApply->setEnabled(true);
753 //=================================================================================
754 // function : SetEditCurrentArgument()
756 //=================================================================================
757 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
759 QPushButton* send = (QPushButton*)sender();
761 disconnect(mySelectionMgr, 0, this, 0);
762 mySelectionMgr->clearSelected();
763 mySelectionMgr->clearFilters();
765 if (send == SelectElementsButton) {
766 myEditCurrentArgument = (QWidget*)LineEditElements;
767 SMESH::SetPointRepresentation(false);
768 if (CheckBoxMesh->isChecked()) {
769 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
770 aViewWindow->SetSelectionMode(ActorSelection);
771 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
773 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
774 aViewWindow->SetSelectionMode(CellSelection);
776 } else if (send == SelectPointButton) {
777 myEditCurrentArgument = (QWidget*)SpinBox_X;
778 SMESH::SetPointRepresentation(true);
779 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
780 aViewWindow->SetSelectionMode(NodeSelection);
781 } else if (send == SelectVectorButton) {
782 myEditCurrentArgument = (QWidget*)SpinBox_DX;
783 SMESH::SetPointRepresentation(true);
785 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
786 aViewWindow->SetSelectionMode(NodeSelection);
790 myEditCurrentArgument->setFocus();
791 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
792 SelectionIntoArgument();
795 //=================================================================================
796 // function : DeactivateActiveDialog()
798 //=================================================================================
799 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
801 if (ConstructorsBox->isEnabled()) {
802 ConstructorsBox->setEnabled(false);
803 GroupArguments->setEnabled(false);
804 GroupButtons->setEnabled(false);
805 mySMESHGUI->ResetState();
806 mySMESHGUI->SetActiveDialogBox(0);
810 //=================================================================================
811 // function : ActivateThisDialog()
813 //=================================================================================
814 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
816 /* Emit a signal to deactivate the active dialog */
817 mySMESHGUI->EmitSignalDeactivateDialog();
818 ConstructorsBox->setEnabled(true);
819 GroupArguments->setEnabled(true);
820 GroupButtons->setEnabled(true);
822 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
824 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
825 aViewWindow->SetSelectionMode(CellSelection);
826 SelectionIntoArgument();
829 //=================================================================================
830 // function : enterEvent()
832 //=================================================================================
833 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
835 if (!ConstructorsBox->isEnabled())
836 ActivateThisDialog();
839 //=================================================================================
840 // function : closeEvent()
842 //=================================================================================
843 void SMESHGUI_SymmetryDlg::closeEvent (QCloseEvent*)
845 /* same than click on cancel button */
849 //=======================================================================
850 // function : hideEvent()
851 // purpose : caused by ESC key
852 //=======================================================================
853 void SMESHGUI_SymmetryDlg::hideEvent (QHideEvent*)
859 //=======================================================================
860 //function : onSelectMesh
862 //=======================================================================
863 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
866 TextLabelElements->setText(tr("SMESH_NAME"));
868 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
870 if (myEditCurrentArgument != LineEditElements) {
871 LineEditElements->clear();
875 mySelectionMgr->clearFilters();
876 SMESH::SetPointRepresentation(false);
879 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
880 aViewWindow->SetSelectionMode(ActorSelection);
881 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
882 LineEditElements->setReadOnly(true);
884 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
885 aViewWindow->SetSelectionMode(CellSelection);
886 LineEditElements->setReadOnly(false);
887 onTextChange(LineEditElements->text());
890 SelectionIntoArgument();
893 //=================================================================================
894 // function : GetConstructorId()
896 //=================================================================================
897 int SMESHGUI_SymmetryDlg::GetConstructorId()
899 return GroupConstructors->checkedId();
902 //=================================================================================
903 // function : IsMirrorOk()
905 //=================================================================================
906 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
910 if (GetConstructorId() != 0)
911 isOk = (SpinBox_DX->GetValue() != 0 ||
912 SpinBox_DY->GetValue() != 0 ||
913 SpinBox_DZ->GetValue() != 0);
918 //=================================================================================
919 // function : onVectorChanged()
921 //=================================================================================
922 void SMESHGUI_SymmetryDlg::onVectorChanged()
925 buttonOk->setEnabled(true);
926 buttonApply->setEnabled(true);
928 buttonOk->setEnabled(false);
929 buttonApply->setEnabled(false);
933 //=======================================================================
934 //function : onActionClicked
935 //purpose : slot called when an action type changed
936 //=======================================================================
938 void SMESHGUI_SymmetryDlg::onActionClicked(int button)
941 case MOVE_ELEMS_BUTTON:
942 MakeGroupsCheck->setEnabled(false);
943 LineEditNewMesh->setEnabled(false);
945 case COPY_ELEMS_BUTTON:
946 LineEditNewMesh->setEnabled(false);
947 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
948 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
949 MakeGroupsCheck->setEnabled(true);
951 MakeGroupsCheck->setEnabled(false);
953 case MAKE_MESH_BUTTON:
954 LineEditNewMesh->setEnabled(true);
955 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
956 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
957 MakeGroupsCheck->setEnabled(true);
959 MakeGroupsCheck->setEnabled(false);
965 //=======================================================================
966 //function : setNewMeshName
967 //purpose : update contents of LineEditNewMesh
968 //=======================================================================
970 void SMESHGUI_SymmetryDlg::setNewMeshName()
972 LineEditNewMesh->setText("");
973 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
975 if ( CheckBoxMesh->isChecked() ) {
976 name = LineEditElements->text();
979 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
980 name = meshSO->GetName().c_str();
982 if ( !name.isEmpty() )
983 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "mirrored"));
987 //=================================================================================
988 // function : keyPressEvent()
990 //=================================================================================
991 void SMESHGUI_SymmetryDlg::keyPressEvent( QKeyEvent* e )
993 QDialog::keyPressEvent( e );
994 if ( e->isAccepted() )
997 if ( e->key() == Qt::Key_F1 ) {