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 ) ),
94 mySelectedObject(SMESH::SMESH_IDSource::_nil())
96 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_POINT")));
97 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_AXIS")));
98 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_PLANE")));
99 QPixmap image3 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
102 setAttribute(Qt::WA_DeleteOnClose, true);
103 setWindowTitle(tr("SMESH_SYMMETRY"));
104 setSizeGripEnabled(true);
106 QVBoxLayout* SMESHGUI_SymmetryDlgLayout = new QVBoxLayout(this);
107 SMESHGUI_SymmetryDlgLayout->setSpacing(SPACING);
108 SMESHGUI_SymmetryDlgLayout->setMargin(MARGIN);
110 /***************************************************************/
111 ConstructorsBox = new QGroupBox(tr("SMESH_SYMMETRY"), this);
112 GroupConstructors = new QButtonGroup(this);
113 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
114 ConstructorsBoxLayout->setSpacing(SPACING);
115 ConstructorsBoxLayout->setMargin(MARGIN);
117 RadioButton1 = new QRadioButton(ConstructorsBox);
118 RadioButton1->setIcon(image0);
119 RadioButton2 = new QRadioButton(ConstructorsBox);
120 RadioButton2->setIcon(image1);
121 RadioButton3 = new QRadioButton(ConstructorsBox);
122 RadioButton3->setIcon(image2);
124 ConstructorsBoxLayout->addWidget(RadioButton1);
125 ConstructorsBoxLayout->addWidget(RadioButton2);
126 ConstructorsBoxLayout->addWidget(RadioButton3);
127 GroupConstructors->addButton(RadioButton1, 0);
128 GroupConstructors->addButton(RadioButton2, 1);
129 GroupConstructors->addButton(RadioButton3, 2);
131 /***************************************************************/
132 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
133 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
134 GroupArgumentsLayout->setSpacing(SPACING);
135 GroupArgumentsLayout->setMargin(MARGIN);
137 myIdValidator = new SMESHGUI_IdValidator(this);
139 // Controls for elements selection
140 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
141 SelectElementsButton = new QPushButton(GroupArguments);
142 SelectElementsButton->setIcon(image3);
143 LineEditElements = new QLineEdit(GroupArguments);
144 LineEditElements->setValidator(myIdValidator);
146 // Control for the whole mesh selection
147 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
149 // Controls for mirror selection
150 GroupMirror = new QGroupBox(GroupArguments);
151 QGridLayout* GroupMirrorLayout = new QGridLayout(GroupMirror);
152 GroupMirrorLayout->setSpacing(SPACING);
153 GroupMirrorLayout->setMargin(MARGIN);
155 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupMirror);
156 SelectPointButton = new QPushButton(GroupMirror);
157 SelectPointButton->setIcon(image3);
159 TextLabelX = new QLabel(tr("SMESH_X"), GroupMirror);
160 SpinBox_X = new SMESHGUI_SpinBox(GroupMirror);
161 TextLabelY = new QLabel(tr("SMESH_Y"), GroupMirror);
162 SpinBox_Y = new SMESHGUI_SpinBox(GroupMirror);
163 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupMirror);
164 SpinBox_Z = new SMESHGUI_SpinBox(GroupMirror);
166 TextLabelVector = new QLabel(GroupMirror);
167 SelectVectorButton = new QPushButton(GroupMirror);
168 SelectVectorButton->setIcon(image3);
170 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupMirror);
171 SpinBox_DX = new SMESHGUI_SpinBox(GroupMirror);
172 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupMirror);
173 SpinBox_DY = new SMESHGUI_SpinBox(GroupMirror);
174 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupMirror);
175 SpinBox_DZ = new SMESHGUI_SpinBox(GroupMirror);
177 GroupMirrorLayout->addWidget(TextLabelPoint, 0, 0);
178 GroupMirrorLayout->addWidget(SelectPointButton, 0, 1);
179 GroupMirrorLayout->addWidget(TextLabelX, 0, 2);
180 GroupMirrorLayout->addWidget(SpinBox_X, 0, 3);
181 GroupMirrorLayout->addWidget(TextLabelY, 0, 4);
182 GroupMirrorLayout->addWidget(SpinBox_Y, 0, 5);
183 GroupMirrorLayout->addWidget(TextLabelZ, 0, 6);
184 GroupMirrorLayout->addWidget(SpinBox_Z, 0, 7);
185 GroupMirrorLayout->addWidget(TextLabelVector, 1, 0);
186 GroupMirrorLayout->addWidget(SelectVectorButton, 1, 1);
187 GroupMirrorLayout->addWidget(TextLabelDX, 1, 2);
188 GroupMirrorLayout->addWidget(SpinBox_DX, 1, 3);
189 GroupMirrorLayout->addWidget(TextLabelDY, 1, 4);
190 GroupMirrorLayout->addWidget(SpinBox_DY, 1, 5);
191 GroupMirrorLayout->addWidget(TextLabelDZ, 1, 6);
192 GroupMirrorLayout->addWidget(SpinBox_DZ, 1, 7);
194 // switch of action type
195 ActionBox = new QGroupBox(GroupArguments);
196 ActionGroup = new QButtonGroup(GroupArguments);
197 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
198 ActionBoxLayout->addSpacing(SPACING);
199 ActionBoxLayout->setMargin(MARGIN);
201 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
202 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
203 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
205 ActionBoxLayout->addWidget(aMoveElements);
206 ActionBoxLayout->addWidget(aCopyElements);
207 ActionBoxLayout->addWidget(aCreateMesh);
208 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
209 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
210 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
212 // CheckBox for groups generation
213 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
214 MakeGroupsCheck->setChecked(false);
216 // Name of a mesh to create
217 LineEditNewMesh = new QLineEdit(GroupArguments);
220 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
221 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
222 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 2);
223 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
224 GroupArgumentsLayout->addWidget(GroupMirror, 2, 0, 1, 4);
225 GroupArgumentsLayout->addWidget(ActionBox, 3, 0, 3, 3);
226 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 4, 3);
227 GroupArgumentsLayout->addWidget(LineEditNewMesh, 5, 3);
229 /***************************************************************/
230 GroupButtons = new QGroupBox(this);
231 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
232 GroupButtonsLayout->setSpacing(SPACING);
233 GroupButtonsLayout->setMargin(MARGIN);
235 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
236 buttonOk->setAutoDefault(true);
237 buttonOk->setDefault(true);
238 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
239 buttonApply->setAutoDefault(true);
240 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
241 buttonCancel->setAutoDefault(true);
242 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
243 buttonHelp->setAutoDefault(true);
245 GroupButtonsLayout->addWidget(buttonOk);
246 GroupButtonsLayout->addSpacing(10);
247 GroupButtonsLayout->addWidget(buttonApply);
248 GroupButtonsLayout->addSpacing(10);
249 GroupButtonsLayout->addStretch();
250 GroupButtonsLayout->addWidget(buttonCancel);
251 GroupButtonsLayout->addWidget(buttonHelp);
253 /***************************************************************/
254 SMESHGUI_SymmetryDlgLayout->addWidget(ConstructorsBox);
255 SMESHGUI_SymmetryDlgLayout->addWidget(GroupArguments);
256 SMESHGUI_SymmetryDlgLayout->addWidget(GroupButtons);
258 /* Initialisations */
259 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
260 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
261 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
262 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
263 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
264 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
266 RadioButton1->setChecked(true);
268 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
270 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
272 // Costruction of the logical filter
273 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
274 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
276 QList<SUIT_SelectionFilter*> aListOfFilters;
277 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
278 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
280 myMeshOrSubMeshOrGroupFilter =
281 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
283 myHelpFileName = "symmetry_page.html";
287 /* signals and slots connections */
288 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
289 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
290 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
291 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
292 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
294 connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
295 connect(SelectPointButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
296 connect(SelectVectorButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
298 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
299 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
300 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
302 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
303 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
304 /* to close dialog if study change */
305 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
306 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
307 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
308 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
310 ConstructorsClicked(0);
311 SelectionIntoArgument();
312 onActionClicked(MOVE_ELEMS_BUTTON);
315 //=================================================================================
316 // function : ~SMESHGUI_SymmetryDlg()
317 // purpose : Destroys the object and frees any allocated resources
318 //=================================================================================
319 SMESHGUI_SymmetryDlg::~SMESHGUI_SymmetryDlg()
323 //=================================================================================
326 //=================================================================================
327 void SMESHGUI_SymmetryDlg::Init (bool ResetControls)
331 myEditCurrentArgument = 0;
332 LineEditElements->clear();
336 buttonOk->setEnabled(false);
337 buttonApply->setEnabled(false);
340 myMesh = SMESH::SMESH_Mesh::_nil();
343 SpinBox_X->SetValue(0.0);
344 SpinBox_Y->SetValue(0.0);
345 SpinBox_Z->SetValue(0.0);
346 SpinBox_DX->SetValue(0.0);
347 SpinBox_DY->SetValue(0.0);
348 SpinBox_DZ->SetValue(0.0);
350 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
351 CheckBoxMesh->setChecked(false);
352 // MakeGroupsCheck->setChecked(false);
353 // MakeGroupsCheck->setEnabled(false);
358 //=================================================================================
359 // function : ConstructorsClicked()
360 // purpose : Radio button management
361 //=================================================================================
362 void SMESHGUI_SymmetryDlg::ConstructorsClicked (int constructorId)
364 disconnect(mySelectionMgr, 0, this, 0);
366 if (constructorId != 0 && !TextLabelVector->isVisible()) {
367 TextLabelVector->show();
368 SelectVectorButton->show();
377 switch (constructorId) {
380 GroupMirror->setTitle(tr("SMESH_POINT"));
382 TextLabelVector->hide();
383 SelectVectorButton->hide();
394 GroupMirror->setTitle(tr("SMESH_AXIS"));
395 TextLabelVector->setText(tr("SMESH_VECTOR"));
400 GroupMirror->setTitle(tr("SMESH_PLANE"));
401 TextLabelVector->setText(tr("SMESH_NORMAL"));
406 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
407 SMESH::SetPointRepresentation(false);
408 if (!CheckBoxMesh->isChecked())
410 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
411 aViewWindow->SetSelectionMode(CellSelection);
415 myEditCurrentArgument = (QWidget*)LineEditElements;
416 LineEditElements->setFocus();
418 if (CheckBoxMesh->isChecked())
421 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
423 QApplication::instance()->processEvents();
425 resize( minimumSize() );
428 //=================================================================================
429 // function : ClickOnApply()
431 //=================================================================================
432 bool SMESHGUI_SymmetryDlg::ClickOnApply()
434 if (mySMESHGUI->isActiveStudyLocked())
440 if (myNbOkElements && IsMirrorOk()) {
441 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
443 SMESH::long_array_var anElementsId = new SMESH::long_array;
445 anElementsId->length(aListElementsId.count());
446 for (int i = 0; i < aListElementsId.count(); i++)
447 anElementsId[i] = aListElementsId[i].toInt();
449 SMESH::AxisStruct aMirror;
451 aMirror.x = SpinBox_X->GetValue();
452 aMirror.y = SpinBox_Y->GetValue();
453 aMirror.z = SpinBox_Z->GetValue();
454 if (GetConstructorId() == 0) {
455 aMirror.vx = aMirror.vy = aMirror.vz = 0;
457 aMirror.vx = SpinBox_DX->GetValue();
458 aMirror.vy = SpinBox_DY->GetValue();
459 aMirror.vz = SpinBox_DZ->GetValue();
462 QStringList aParameters;
463 aParameters << SpinBox_X->text();
464 aParameters << SpinBox_Y->text();
465 aParameters << SpinBox_Z->text();
466 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DX->text() );
467 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DY->text() );
468 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DZ->text() );
470 SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
472 if (GetConstructorId() == 0)
473 aMirrorType = SMESH::SMESH_MeshEditor::POINT;
474 if (GetConstructorId() == 1)
475 aMirrorType = SMESH::SMESH_MeshEditor::AXIS;
476 if (GetConstructorId() == 2)
477 aMirrorType = SMESH::SMESH_MeshEditor::PLANE;
479 int actionButton = ActionGroup->checkedId();
480 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
483 SUIT_OverrideCursor aWaitCursor;
484 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
486 switch ( actionButton ) {
487 case MOVE_ELEMS_BUTTON: {
488 if(CheckBoxMesh->isChecked())
489 aMeshEditor->MirrorObject(mySelectedObject, aMirror, aMirrorType, false );
491 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, false );
493 if( !myMesh->_is_nil())
494 myMesh->SetParameters(SMESHGUI::JoinObjectParameters(aParameters));
497 case COPY_ELEMS_BUTTON: {
498 SMESH::ListOfGroups_var groups;
500 if(CheckBoxMesh->isChecked())
501 groups = aMeshEditor->MirrorObjectMakeGroups(mySelectedObject, aMirror, aMirrorType);
503 groups = aMeshEditor->MirrorMakeGroups(anElementsId, aMirror, aMirrorType);
505 if(CheckBoxMesh->isChecked())
506 aMeshEditor->MirrorObject(mySelectedObject, aMirror, aMirrorType, true);
508 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, true);
509 if( !myMesh->_is_nil())
510 myMesh->SetParameters(SMESHGUI::JoinObjectParameters(aParameters));
513 case MAKE_MESH_BUTTON: {
514 SMESH::SMESH_Mesh_var mesh;
515 if(CheckBoxMesh->isChecked())
516 mesh = aMeshEditor->MirrorObjectMakeMesh(mySelectedObject, aMirror, aMirrorType, makeGroups,
517 LineEditNewMesh->text().toLatin1().data());
519 mesh = aMeshEditor->MirrorMakeMesh(anElementsId, aMirror, aMirrorType, makeGroups,
520 LineEditNewMesh->text().toLatin1().data());
521 if( !mesh->_is_nil())
522 mesh->SetParameters(SMESHGUI::JoinObjectParameters(aParameters));
530 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
531 actionButton == MAKE_MESH_BUTTON )
532 mySMESHGUI->updateObjBrowser(true); // new groups may appear
534 ConstructorsClicked(GetConstructorId());
535 mySelectedObject = SMESH::SMESH_IDSource::_nil();
536 SelectionIntoArgument();
541 //=================================================================================
542 // function : ClickOnOk()
544 //=================================================================================
545 void SMESHGUI_SymmetryDlg::ClickOnOk()
551 //=================================================================================
552 // function : ClickOnCancel()
554 //=================================================================================
555 void SMESHGUI_SymmetryDlg::ClickOnCancel()
557 disconnect(mySelectionMgr, 0, this, 0);
558 mySelectionMgr->clearFilters();
559 //mySelectionMgr->clearSelected();
560 SMESH::SetPointRepresentation(false);
561 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
562 aViewWindow->SetSelectionMode(ActorSelection);
563 mySMESHGUI->ResetState();
567 //=================================================================================
568 // function : ClickOnHelp()
570 //=================================================================================
571 void SMESHGUI_SymmetryDlg::ClickOnHelp()
573 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
575 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
579 platform = "winapplication";
581 platform = "application";
583 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
584 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
585 arg(app->resourceMgr()->stringValue("ExternalBrowser",
587 arg(myHelpFileName));
591 //=======================================================================
592 // function : onTextChange()
594 //=======================================================================
595 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
597 QLineEdit* send = (QLineEdit*)sender();
602 if (send == LineEditElements)
605 buttonOk->setEnabled(false);
606 buttonApply->setEnabled(false);
608 // hilight entered elements
609 SMDS_Mesh* aMesh = 0;
611 aMesh = myActor->GetObject()->GetMesh();
614 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
616 TColStd_MapOfInteger newIndices;
618 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
620 if (send == LineEditElements) {
621 for (int i = 0; i < aListId.count(); i++) {
622 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
624 newIndices.Add(e->GetID());
628 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
629 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
630 aViewWindow->highlight( anIO, true, true );
632 myElementsId = theNewText;
636 if (myNbOkElements && IsMirrorOk()) {
637 buttonOk->setEnabled(true);
638 buttonApply->setEnabled(true);
644 //=================================================================================
645 // function : SelectionIntoArgument()
646 // purpose : Called when selection as changed or other case
647 //=================================================================================
648 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
654 QString aString = "";
657 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
658 LineEditElements->setText(aString);
660 buttonOk->setEnabled(false);
661 buttonApply->setEnabled(false);
665 if (!GroupButtons->isEnabled()) // inactive
670 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
672 int nbSel = aList.Extent();
676 Handle(SALOME_InteractiveObject) IO = aList.First();
677 myMesh = SMESH::GetMeshByIO(IO);
678 if(myMesh->_is_nil())
681 myActor = SMESH::FindActorByObject(myMesh);
683 myActor = SMESH::FindActorByEntry(IO->getEntry());
689 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
692 // MakeGroups is available if there are groups and "Copy"
693 if ( myMesh->NbGroups() == 0 ) {
694 MakeGroupsCheck->setChecked(false);
695 MakeGroupsCheck->setEnabled(false);
697 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
698 MakeGroupsCheck->setEnabled(true);
700 if (CheckBoxMesh->isChecked()) {
701 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
703 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH
704 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
710 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
714 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
715 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
717 myElementsId += QString(" %1").arg(i);
722 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
724 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
726 // get IDs from submesh
728 SMESH::long_array_var anElementsIds = new SMESH::long_array;
729 anElementsIds = aSubMesh->GetElementsId();
730 for (int i = 0; i < anElementsIds->length(); i++) {
731 myElementsId += QString(" %1").arg(anElementsIds[i]);
733 aNbUnits = anElementsIds->length();
737 SMESH::SMESH_GroupBase_var aGroup =
738 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
739 if (aGroup->_is_nil())
742 // get IDs from smesh group
743 SMESH::long_array_var anElementsIds = new SMESH::long_array;
744 anElementsIds = aGroup->GetListOfID();
745 for (int i = 0; i < anElementsIds->length(); i++) {
746 myElementsId += QString(" %1").arg(anElementsIds[i]);
748 aNbUnits = anElementsIds->length();
752 aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, IO, aString);
753 myElementsId = aString;
758 myNbOkElements = true;
760 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
764 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
768 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
776 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
777 SpinBox_X->SetValue(x);
778 SpinBox_Y->SetValue(y);
779 SpinBox_Z->SetValue(z);
780 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
781 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
782 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
783 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
788 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
789 LineEditElements->setText(aString);
795 if (myNbOkElements && IsMirrorOk()) {
796 buttonOk->setEnabled(true);
797 buttonApply->setEnabled(true);
801 //=================================================================================
802 // function : SetEditCurrentArgument()
804 //=================================================================================
805 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
807 QPushButton* send = (QPushButton*)sender();
809 disconnect(mySelectionMgr, 0, this, 0);
810 mySelectionMgr->clearSelected();
811 mySelectionMgr->clearFilters();
813 if (send == SelectElementsButton) {
814 myEditCurrentArgument = (QWidget*)LineEditElements;
815 SMESH::SetPointRepresentation(false);
816 if (CheckBoxMesh->isChecked()) {
817 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
818 aViewWindow->SetSelectionMode(ActorSelection);
819 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
821 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
822 aViewWindow->SetSelectionMode(CellSelection);
824 } else if (send == SelectPointButton) {
825 myEditCurrentArgument = (QWidget*)SpinBox_X;
826 SMESH::SetPointRepresentation(true);
827 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
828 aViewWindow->SetSelectionMode(NodeSelection);
829 } else if (send == SelectVectorButton) {
830 myEditCurrentArgument = (QWidget*)SpinBox_DX;
831 SMESH::SetPointRepresentation(true);
833 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
834 aViewWindow->SetSelectionMode(NodeSelection);
838 myEditCurrentArgument->setFocus();
839 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
840 SelectionIntoArgument();
843 //=================================================================================
844 // function : DeactivateActiveDialog()
846 //=================================================================================
847 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
849 if (ConstructorsBox->isEnabled()) {
850 ConstructorsBox->setEnabled(false);
851 GroupArguments->setEnabled(false);
852 GroupButtons->setEnabled(false);
853 mySMESHGUI->ResetState();
854 mySMESHGUI->SetActiveDialogBox(0);
858 //=================================================================================
859 // function : ActivateThisDialog()
861 //=================================================================================
862 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
864 /* Emit a signal to deactivate the active dialog */
865 mySMESHGUI->EmitSignalDeactivateDialog();
866 ConstructorsBox->setEnabled(true);
867 GroupArguments->setEnabled(true);
868 GroupButtons->setEnabled(true);
870 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
872 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
873 aViewWindow->SetSelectionMode(CellSelection);
874 SelectionIntoArgument();
877 //=================================================================================
878 // function : enterEvent()
880 //=================================================================================
881 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
883 if (!ConstructorsBox->isEnabled())
884 ActivateThisDialog();
887 //=================================================================================
888 // function : closeEvent()
890 //=================================================================================
891 void SMESHGUI_SymmetryDlg::closeEvent (QCloseEvent*)
893 /* same than click on cancel button */
897 //=======================================================================
898 // function : hideEvent()
899 // purpose : caused by ESC key
900 //=======================================================================
901 void SMESHGUI_SymmetryDlg::hideEvent (QHideEvent*)
907 //=======================================================================
908 //function : onSelectMesh
910 //=======================================================================
911 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
914 TextLabelElements->setText(tr("SMESH_NAME"));
916 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
918 if (myEditCurrentArgument != LineEditElements) {
919 LineEditElements->clear();
923 mySelectionMgr->clearFilters();
924 SMESH::SetPointRepresentation(false);
927 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
928 aViewWindow->SetSelectionMode(ActorSelection);
929 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
930 LineEditElements->setReadOnly(true);
931 LineEditElements->setValidator(0);
933 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
934 aViewWindow->SetSelectionMode(CellSelection);
935 LineEditElements->setReadOnly(false);
936 LineEditElements->setValidator(myIdValidator);
937 onTextChange(LineEditElements->text());
940 SelectionIntoArgument();
943 //=================================================================================
944 // function : GetConstructorId()
946 //=================================================================================
947 int SMESHGUI_SymmetryDlg::GetConstructorId()
949 return GroupConstructors->checkedId();
952 //=================================================================================
953 // function : IsMirrorOk()
955 //=================================================================================
956 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
960 if (GetConstructorId() != 0)
961 isOk = (SpinBox_DX->GetValue() != 0 ||
962 SpinBox_DY->GetValue() != 0 ||
963 SpinBox_DZ->GetValue() != 0);
968 //=================================================================================
969 // function : onVectorChanged()
971 //=================================================================================
972 void SMESHGUI_SymmetryDlg::onVectorChanged()
975 buttonOk->setEnabled(true);
976 buttonApply->setEnabled(true);
978 buttonOk->setEnabled(false);
979 buttonApply->setEnabled(false);
983 //=======================================================================
984 //function : onActionClicked
985 //purpose : slot called when an action type changed
986 //=======================================================================
988 void SMESHGUI_SymmetryDlg::onActionClicked(int button)
991 case MOVE_ELEMS_BUTTON:
992 MakeGroupsCheck->setEnabled(false);
993 LineEditNewMesh->setEnabled(false);
995 case COPY_ELEMS_BUTTON:
996 LineEditNewMesh->setEnabled(false);
997 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
998 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
999 MakeGroupsCheck->setEnabled(true);
1001 MakeGroupsCheck->setEnabled(false);
1003 case MAKE_MESH_BUTTON:
1004 LineEditNewMesh->setEnabled(true);
1005 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1006 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1007 MakeGroupsCheck->setEnabled(true);
1009 MakeGroupsCheck->setEnabled(false);
1015 //=======================================================================
1016 //function : setNewMeshName
1017 //purpose : update contents of LineEditNewMesh
1018 //=======================================================================
1020 void SMESHGUI_SymmetryDlg::setNewMeshName()
1022 LineEditNewMesh->setText("");
1023 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
1025 if ( CheckBoxMesh->isChecked() ) {
1026 name = LineEditElements->text();
1029 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
1030 name = meshSO->GetName().c_str();
1032 if ( !name.isEmpty() )
1033 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "mirrored"));
1037 //=================================================================================
1038 // function : keyPressEvent()
1040 //=================================================================================
1041 void SMESHGUI_SymmetryDlg::keyPressEvent( QKeyEvent* e )
1043 QDialog::keyPressEvent( e );
1044 if ( e->isAccepted() )
1047 if ( e->key() == Qt::Key_F1 ) {
1053 //=================================================================================
1054 // function : isValid
1056 //=================================================================================
1057 bool SMESHGUI_SymmetryDlg::isValid()
1062 ok = SpinBox_X->isValid( msg, true ) && ok;
1063 ok = SpinBox_Y->isValid( msg, true ) && ok;
1064 ok = SpinBox_Z->isValid( msg, true ) && ok;
1065 if (GetConstructorId() != 0) {
1066 ok = SpinBox_DX->isValid( msg, true ) && ok;
1067 ok = SpinBox_DY->isValid( msg, true ) && ok;
1068 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1072 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1073 if ( !msg.isEmpty() )
1075 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );