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
24 // File : SMESHGUI_SymmetryDlg.cxx
25 // Author : Michael ZORIN
29 #include "SMESHGUI_SymmetryDlg.h"
32 #include "SMESHGUI_SpinBox.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESHGUI_VTKUtils.h"
35 #include "SMESHGUI_MeshUtils.h"
36 #include "SMESHGUI_IdValidator.h"
38 #include "SMESH_Actor.h"
39 #include "SMESH_TypeFilter.hxx"
40 #include "SMESH_LogicalFilter.hxx"
41 #include "SMDS_Mesh.hxx"
43 #include "SUIT_Desktop.h"
44 #include "SUIT_ResourceMgr.h"
45 #include "SUIT_Session.h"
46 #include "SUIT_MessageBox.h"
48 #include "LightApp_Application.h"
50 #include "SVTK_ViewModel.h"
51 #include "SVTK_ViewWindow.h"
52 #include "SVTK_Selector.h"
53 #include "SVTK_Selection.h"
54 #include "SALOME_ListIO.hxx"
55 #include "SALOMEDSClient_SObject.hxx"
57 #include "utilities.h"
60 #include <TColStd_MapOfInteger.hxx>
61 #include <TColStd_IndexedMapOfInteger.hxx>
64 #include <qapplication.h>
65 #include <qbuttongroup.h>
66 #include <qgroupbox.h>
68 #include <qlineedit.h>
69 #include <qpushbutton.h>
70 #include <qradiobutton.h>
71 #include <qcheckbox.h>
76 #include "SALOMEconfig.h"
77 #include CORBA_SERVER_HEADER(SMESH_Group)
78 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
82 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, const char* name,
90 bool modal, WFlags fl)
91 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
92 WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
93 mySMESHGUI( theModule ),
94 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
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 setName("SMESHGUI_SymmetryDlg");
104 setCaption(tr("SMESH_SYMMETRY"));
105 setSizeGripEnabled(TRUE);
106 SMESHGUI_SymmetryDlgLayout = new QGridLayout(this);
107 SMESHGUI_SymmetryDlgLayout->setSpacing(6);
108 SMESHGUI_SymmetryDlgLayout->setMargin(11);
110 /***************************************************************/
111 GroupConstructors = new QButtonGroup(this, "GroupConstructors");
112 GroupConstructors->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)5,
113 (QSizePolicy::SizeType)0, 0, 0,
114 GroupConstructors->sizePolicy().hasHeightForWidth()));
115 GroupConstructors->setTitle(tr("SMESH_SYMMETRY" ));
116 GroupConstructors->setExclusive(TRUE);
117 GroupConstructors->setColumnLayout(0, Qt::Vertical);
118 GroupConstructors->layout()->setSpacing(0);
119 GroupConstructors->layout()->setMargin(0);
120 GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
121 GroupConstructorsLayout->setAlignment(Qt::AlignTop);
122 GroupConstructorsLayout->setSpacing(6);
123 GroupConstructorsLayout->setMargin(11);
124 QHBoxLayout* RBLayout = new QHBoxLayout(0, 0, 6, "Layout2");
125 RadioButton1= new QRadioButton(GroupConstructors, "RadioButton1");
126 RadioButton1->setText(tr("" ));
127 RadioButton1->setPixmap(image0);
128 RBLayout->addWidget(RadioButton1);
129 RadioButton2= new QRadioButton(GroupConstructors, "RadioButton2");
130 RadioButton2->setText(tr("" ));
131 RadioButton2->setPixmap(image1);
132 RBLayout->addWidget(RadioButton2);
133 RadioButton3= new QRadioButton(GroupConstructors, "RadioButton3");
134 RadioButton3->setText(tr("" ));
135 RadioButton3->setPixmap(image2);
136 RBLayout->addWidget(RadioButton3);
137 GroupConstructorsLayout->addLayout(RBLayout, 0, 0);
138 SMESHGUI_SymmetryDlgLayout->addWidget(GroupConstructors, 0, 0);
140 /***************************************************************/
141 GroupButtons = new QGroupBox(this, "GroupButtons");
142 GroupButtons->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7,
143 (QSizePolicy::SizeType)0, 0, 0,
144 GroupButtons->sizePolicy().hasHeightForWidth()));
145 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
146 GroupButtons->setTitle(tr("" ));
147 GroupButtons->setColumnLayout(0, Qt::Vertical);
148 GroupButtons->layout()->setSpacing(0);
149 GroupButtons->layout()->setMargin(0);
150 GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
151 GroupButtonsLayout->setAlignment(Qt::AlignTop);
152 GroupButtonsLayout->setSpacing(6);
153 GroupButtonsLayout->setMargin(11);
154 buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
155 buttonHelp->setText(tr("SMESH_BUT_HELP" ));
156 buttonHelp->setAutoDefault(TRUE);
157 GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
158 buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
159 buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
160 buttonCancel->setAutoDefault(TRUE);
161 GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
162 buttonApply = new QPushButton(GroupButtons, "buttonApply");
163 buttonApply->setText(tr("SMESH_BUT_APPLY" ));
164 buttonApply->setAutoDefault(TRUE);
165 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
166 QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
167 GroupButtonsLayout->addItem(spacer_9, 0, 2);
168 buttonOk = new QPushButton(GroupButtons, "buttonOk");
169 buttonOk->setText(tr("SMESH_BUT_APPLY_AND_CLOSE" ));
170 buttonOk->setAutoDefault(TRUE);
171 buttonOk->setDefault(TRUE);
172 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
173 SMESHGUI_SymmetryDlgLayout->addWidget(GroupButtons, 2, 0);
175 /***************************************************************/
176 GroupArguments = new QGroupBox(this, "GroupArguments");
177 GroupArguments->setTitle(tr("SMESH_ARGUMENTS"));
178 GroupArguments->setColumnLayout(0, Qt::Vertical);
179 GroupArguments->layout()->setSpacing(0);
180 GroupArguments->layout()->setMargin(0);
181 GroupArgumentsLayout = new QGridLayout(GroupArguments->layout());
182 GroupArgumentsLayout->setAlignment(Qt::AlignTop);
183 GroupArgumentsLayout->setSpacing(6);
184 GroupArgumentsLayout->setMargin(11);
186 // Controls for elements selection
187 TextLabelElements = new QLabel(GroupArguments, "TextLabelElements");
188 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS" ));
189 //TextLabelElements->setFixedWidth(74);
190 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
191 //GroupArgumentsLayout->addMultiCellWidget(TextLabelElements, 0, 0, 0, 1);
193 SelectElementsButton = new QPushButton(GroupArguments, "SelectElementsButton");
194 SelectElementsButton->setText(tr("" ));
195 SelectElementsButton->setPixmap(image3);
196 SelectElementsButton->setToggleButton(FALSE);
197 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
199 LineEditElements = new QLineEdit(GroupArguments, "LineEditElements");
200 LineEditElements->setValidator(new SMESHGUI_IdValidator(this, "validator"));
201 //GroupArgumentsLayout->addWidget(LineEditElements, 0, 3);
202 GroupArgumentsLayout->addMultiCellWidget(LineEditElements, 0, 0, 2, 4);
204 // Control for the whole mesh selection
205 CheckBoxMesh = new QCheckBox(GroupArguments, "CheckBoxMesh");
206 CheckBoxMesh->setText(tr("SMESH_SELECT_WHOLE_MESH" ));
207 GroupArgumentsLayout->addMultiCellWidget(CheckBoxMesh, 1, 1, 0, 4);
209 // Controls for mirror selection
210 GroupMirror = new QGroupBox(GroupArguments, "GroupMirror");
211 GroupMirror->setColumnLayout(0, Qt::Vertical);
212 GroupMirror->layout()->setSpacing(0);
213 GroupMirror->layout()->setMargin(0);
214 QGridLayout* GroupMirrorLayout = new QGridLayout(GroupMirror->layout());
215 GroupMirrorLayout->setAlignment(Qt::AlignTop);
216 GroupMirrorLayout->setSpacing(6);
217 GroupMirrorLayout->setMargin(11);
219 TextLabelPoint = new QLabel(GroupMirror, "TextLabelPoint");
220 TextLabelPoint->setText(tr("SMESH_POINT"));
221 GroupMirrorLayout->addWidget(TextLabelPoint, 0, 0);
223 SelectPointButton = new QPushButton(GroupMirror, "SelectPointButton");
224 SelectPointButton->setPixmap(image3);
225 GroupMirrorLayout->addWidget(SelectPointButton, 0, 1);
227 TextLabelX = new QLabel(GroupMirror, "TextLabelX");
228 TextLabelX->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
229 TextLabelX->setText(tr("SMESH_X"));
230 GroupMirrorLayout->addWidget(TextLabelX, 0, 2);
232 SpinBox_X = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_X");
233 GroupMirrorLayout->addWidget(SpinBox_X, 0, 3);
235 TextLabelY = new QLabel(GroupMirror, "TextLabelY");
236 TextLabelY->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
237 TextLabelY->setText(tr("SMESH_Y"));
238 GroupMirrorLayout->addWidget(TextLabelY, 0, 4);
240 SpinBox_Y = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_Y");
241 GroupMirrorLayout->addWidget(SpinBox_Y, 0, 5);
243 TextLabelZ = new QLabel(GroupMirror, "TextLabelZ");
244 TextLabelZ->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
245 TextLabelZ->setText(tr("SMESH_Z"));
246 GroupMirrorLayout->addWidget(TextLabelZ, 0, 6);
248 SpinBox_Z = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_Z");
249 GroupMirrorLayout->addWidget(SpinBox_Z, 0, 7);
251 TextLabelVector = new QLabel(GroupMirror, "TextLabelVector");
252 GroupMirrorLayout->addWidget(TextLabelVector, 1, 0);
254 SelectVectorButton = new QPushButton(GroupMirror, "SelectVectorButton");
255 SelectVectorButton->setPixmap(image3);
256 GroupMirrorLayout->addWidget(SelectVectorButton, 1, 1);
258 TextLabelDX = new QLabel(GroupMirror, "TextLabelDX");
259 TextLabelDX->setText(tr("SMESH_DX"));
260 TextLabelDX->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
261 GroupMirrorLayout->addWidget(TextLabelDX, 1, 2);
263 SpinBox_DX = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_DX");
264 GroupMirrorLayout->addWidget(SpinBox_DX, 1, 3);
266 TextLabelDY = new QLabel(GroupMirror, "TextLabelDY");
267 TextLabelDY->setText(tr("SMESH_DY"));
268 TextLabelDY->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
269 GroupMirrorLayout->addWidget(TextLabelDY, 1, 4);
271 SpinBox_DY = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_DY");
272 GroupMirrorLayout->addWidget(SpinBox_DY, 1, 5);
274 TextLabelDZ = new QLabel(GroupMirror, "TextLabelDZ");
275 TextLabelDZ->setText(tr("SMESH_DZ"));
276 TextLabelDZ->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
277 GroupMirrorLayout->addWidget(TextLabelDZ, 1, 6);
279 SpinBox_DZ = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_DZ");
280 GroupMirrorLayout->addWidget(SpinBox_DZ, 1, 7);
282 GroupArgumentsLayout->addMultiCellWidget(GroupMirror, 2, 2, 0, 4);
284 // switch of action type
285 ActionGroup = new QButtonGroup(1, Qt::Horizontal, GroupArguments, "ActionGroup");
286 ActionGroup->setExclusive(true);
287 ActionGroup->insert(new QRadioButton(tr("SMESH_MOVE_ELEMENTS"),ActionGroup), MOVE_ELEMS_BUTTON);
288 ActionGroup->insert(new QRadioButton(tr("SMESH_COPY_ELEMENTS"),ActionGroup), COPY_ELEMS_BUTTON);
289 ActionGroup->insert(new QRadioButton(tr("SMESH_CREATE_MESH" ),ActionGroup), MAKE_MESH_BUTTON);
290 GroupArgumentsLayout->addMultiCellWidget(ActionGroup, 3, 5, 0, 3);
292 // CheckBox for groups generation
293 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
294 MakeGroupsCheck->setChecked(false);
295 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 4, 4);
297 // Name of a mesh to create
298 LineEditNewMesh = new QLineEdit(GroupArguments, "LineEditNewMesh");
299 GroupArgumentsLayout->addWidget(LineEditNewMesh, 5, 4);
301 SMESHGUI_SymmetryDlgLayout->addWidget(GroupArguments, 1, 0);
303 /* Initialisations */
304 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
305 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
306 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
307 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
308 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
309 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
311 GroupArguments->show();
312 RadioButton1->setChecked(TRUE);
314 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
316 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
318 // Costruction of the logical filter
319 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
320 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
322 QPtrList<SUIT_SelectionFilter> aListOfFilters;
323 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
324 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
326 myMeshOrSubMeshOrGroupFilter =
327 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
329 myHelpFileName = "symmetry_page.html";
333 /* signals and slots connections */
334 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
335 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
336 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
337 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
338 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
340 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
341 connect(SelectPointButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
342 connect(SelectVectorButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
344 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
345 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
346 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
348 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
349 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
350 /* to close dialog if study change */
351 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
352 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
353 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
354 connect(ActionGroup, SIGNAL(clicked(int)), SLOT(onActionClicked(int)));
356 this->show(); /* displays Dialog */
358 ConstructorsClicked(0);
359 SelectionIntoArgument();
360 onActionClicked(MOVE_ELEMS_BUTTON);
364 //=================================================================================
365 // function : ~SMESHGUI_SymmetryDlg()
366 // purpose : Destroys the object and frees any allocated resources
367 //=================================================================================
368 SMESHGUI_SymmetryDlg::~SMESHGUI_SymmetryDlg()
370 // no need to delete child widgets, Qt does it all for us
373 //=================================================================================
376 //=================================================================================
377 void SMESHGUI_SymmetryDlg::Init (bool ResetControls)
381 myEditCurrentArgument = 0;
382 LineEditElements->clear();
386 buttonOk->setEnabled(false);
387 buttonApply->setEnabled(false);
390 myMesh = SMESH::SMESH_Mesh::_nil();
393 SpinBox_X->SetValue(0.0);
394 SpinBox_Y->SetValue(0.0);
395 SpinBox_Z->SetValue(0.0);
396 SpinBox_DX->SetValue(0.0);
397 SpinBox_DY->SetValue(0.0);
398 SpinBox_DZ->SetValue(0.0);
400 ((QRadioButton*) ActionGroup->find( MOVE_ELEMS_BUTTON ))->setChecked(TRUE);
401 CheckBoxMesh->setChecked(false);
402 // MakeGroupsCheck->setChecked(false);
403 // MakeGroupsCheck->setEnabled(false);
408 //=================================================================================
409 // function : ConstructorsClicked()
410 // purpose : Radio button management
411 //=================================================================================
412 void SMESHGUI_SymmetryDlg::ConstructorsClicked (int constructorId)
414 disconnect(mySelectionMgr, 0, this, 0);
416 if (constructorId != 0 && !TextLabelVector->isVisible()) {
417 TextLabelVector->show();
418 SelectVectorButton->show();
427 switch (constructorId) {
430 GroupMirror->setTitle(tr("SMESH_POINT"));
432 TextLabelVector->hide();
433 SelectVectorButton->hide();
444 GroupMirror->setTitle(tr("SMESH_AXIS"));
445 TextLabelVector->setText(tr("SMESH_VECTOR"));
450 GroupMirror->setTitle(tr("SMESH_PLANE"));
451 TextLabelVector->setText(tr("SMESH_NORMAL"));
456 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
457 SMESH::SetPointRepresentation(false);
458 if (!CheckBoxMesh->isChecked())
460 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
461 aViewWindow->SetSelectionMode(CellSelection);
465 myEditCurrentArgument = (QWidget*)LineEditElements;
466 LineEditElements->setFocus();
468 if (CheckBoxMesh->isChecked())
471 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
474 //=================================================================================
475 // function : ClickOnApply()
477 //=================================================================================
478 void SMESHGUI_SymmetryDlg::ClickOnApply()
480 if (mySMESHGUI->isActiveStudyLocked())
483 if (myNbOkElements && IsMirrorOk()) {
484 QStringList aListElementsId = QStringList::split(" ", myElementsId, false);
486 SMESH::long_array_var anElementsId = new SMESH::long_array;
488 anElementsId->length(aListElementsId.count());
489 for (int i = 0; i < aListElementsId.count(); i++)
490 anElementsId[i] = aListElementsId[i].toInt();
492 SMESH::AxisStruct aMirror;
494 aMirror.x = SpinBox_X->GetValue();
495 aMirror.y = SpinBox_Y->GetValue();
496 aMirror.z = SpinBox_Z->GetValue();
497 if (GetConstructorId() == 0) {
498 aMirror.vx = aMirror.vy = aMirror.vz = 0;
500 aMirror.vx = SpinBox_DX->GetValue();
501 aMirror.vy = SpinBox_DY->GetValue();
502 aMirror.vz = SpinBox_DZ->GetValue();
506 SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
508 if (GetConstructorId() == 0)
509 aMirrorType = SMESH::SMESH_MeshEditor::POINT;
510 if (GetConstructorId() == 1)
511 aMirrorType = SMESH::SMESH_MeshEditor::AXIS;
512 if (GetConstructorId() == 2)
513 aMirrorType = SMESH::SMESH_MeshEditor::PLANE;
515 int actionButton = ActionGroup->id( ActionGroup->selected() );
516 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
519 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
520 QApplication::setOverrideCursor(Qt::waitCursor);
521 switch ( actionButton ) {
522 case MOVE_ELEMS_BUTTON:
523 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, false );
525 case COPY_ELEMS_BUTTON:
527 SMESH::ListOfGroups_var groups =
528 aMeshEditor->MirrorMakeGroups(anElementsId, aMirror, aMirrorType);
530 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, true);
532 case MAKE_MESH_BUTTON:
533 SMESH::SMESH_Mesh_var mesh =
534 aMeshEditor->MirrorMakeMesh(anElementsId, aMirror, aMirrorType, makeGroups,
535 LineEditNewMesh->text().latin1());
537 QApplication::restoreOverrideCursor();
542 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
543 actionButton == MAKE_MESH_BUTTON )
544 mySMESHGUI->updateObjBrowser(true); // new groups may appear
546 ConstructorsClicked(GetConstructorId());
547 SelectionIntoArgument();
551 //=================================================================================
552 // function : ClickOnOk()
554 //=================================================================================
555 void SMESHGUI_SymmetryDlg::ClickOnOk()
561 //=================================================================================
562 // function : ClickOnCancel()
564 //=================================================================================
565 void SMESHGUI_SymmetryDlg::ClickOnCancel()
567 disconnect(mySelectionMgr, 0, this, 0);
568 mySelectionMgr->clearFilters();
569 //mySelectionMgr->clearSelected();
570 SMESH::SetPointRepresentation(false);
571 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
572 aViewWindow->SetSelectionMode(ActorSelection);
573 mySMESHGUI->ResetState();
577 //=================================================================================
578 // function : ClickOnHelp()
580 //=================================================================================
581 void SMESHGUI_SymmetryDlg::ClickOnHelp()
583 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
585 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
589 platform = "winapplication";
591 platform = "application";
593 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
594 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
595 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
596 QObject::tr("BUT_OK"));
600 //=======================================================================
601 // function : onTextChange()
603 //=======================================================================
604 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
606 QLineEdit* send = (QLineEdit*)sender();
611 if (send == LineEditElements)
614 buttonOk->setEnabled(false);
615 buttonApply->setEnabled(false);
617 // hilight entered elements
618 SMDS_Mesh* aMesh = 0;
620 aMesh = myActor->GetObject()->GetMesh();
623 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
625 TColStd_MapOfInteger newIndices;
627 QStringList aListId = QStringList::split(" ", theNewText, false);
629 if (send == LineEditElements) {
630 for (int i = 0; i < aListId.count(); i++) {
631 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
633 newIndices.Add(e->GetID());
637 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
638 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
639 aViewWindow->highlight( anIO, true, true );
641 myElementsId = theNewText;
645 if (myNbOkElements && IsMirrorOk()) {
646 buttonOk->setEnabled(true);
647 buttonApply->setEnabled(true);
653 //=================================================================================
654 // function : SelectionIntoArgument()
655 // purpose : Called when selection as changed or other case
656 //=================================================================================
657 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
663 QString aString = "";
666 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
667 LineEditElements->setText(aString);
669 buttonOk->setEnabled(false);
670 buttonApply->setEnabled(false);
674 if (!GroupButtons->isEnabled()) // inactive
679 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
681 int nbSel = aList.Extent();
685 Handle(SALOME_InteractiveObject) IO = aList.First();
686 myMesh = SMESH::GetMeshByIO(IO);
687 if(myMesh->_is_nil())
690 myActor = SMESH::FindActorByObject(myMesh);
692 myActor = SMESH::FindActorByEntry(IO->getEntry());
698 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
701 // MakeGroups is available if there are groups and "Copy"
702 if ( myMesh->NbGroups() == 0 ) {
703 MakeGroupsCheck->setChecked(false);
704 MakeGroupsCheck->setEnabled(false);
706 else if ( ActionGroup->id( ActionGroup->selected() ) != MOVE_ELEMS_BUTTON ) {
707 MakeGroupsCheck->setEnabled(true);
709 if (CheckBoxMesh->isChecked()) {
710 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
712 if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
714 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
718 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
719 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
721 myElementsId += QString(" %1").arg(i);
725 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
727 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
729 // get IDs from submesh
730 SMESH::long_array_var anElementsIds = new SMESH::long_array;
731 anElementsIds = aSubMesh->GetElementsId();
732 for (int i = 0; i < anElementsIds->length(); i++) {
733 myElementsId += QString(" %1").arg(anElementsIds[i]);
735 aNbUnits = anElementsIds->length();
738 SMESH::SMESH_GroupBase_var aGroup =
739 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
740 if (aGroup->_is_nil())
743 // get IDs from smesh group
744 SMESH::long_array_var anElementsIds = new SMESH::long_array;
745 anElementsIds = aGroup->GetListOfID();
746 for (int i = 0; i < anElementsIds->length(); i++) {
747 myElementsId += QString(" %1").arg(anElementsIds[i]);
749 aNbUnits = anElementsIds->length();
752 aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, IO, aString);
753 myElementsId = aString;
759 myNbOkElements = true;
761 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
765 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
769 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
777 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
778 SpinBox_X->SetValue(x);
779 SpinBox_Y->SetValue(y);
780 SpinBox_Z->SetValue(z);
781 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
782 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
783 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
784 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
789 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
790 LineEditElements->setText(aString);
796 if (myNbOkElements && IsMirrorOk()) {
797 buttonOk->setEnabled(true);
798 buttonApply->setEnabled(true);
802 //=================================================================================
803 // function : SetEditCurrentArgument()
805 //=================================================================================
806 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
808 QPushButton* send = (QPushButton*)sender();
810 disconnect(mySelectionMgr, 0, this, 0);
811 mySelectionMgr->clearSelected();
812 mySelectionMgr->clearFilters();
814 if (send == SelectElementsButton) {
815 myEditCurrentArgument = (QWidget*)LineEditElements;
816 SMESH::SetPointRepresentation(false);
817 if (CheckBoxMesh->isChecked()) {
818 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
819 aViewWindow->SetSelectionMode(ActorSelection);
820 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
822 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
823 aViewWindow->SetSelectionMode(CellSelection);
825 } else if (send == SelectPointButton) {
826 myEditCurrentArgument = (QWidget*)SpinBox_X;
827 SMESH::SetPointRepresentation(true);
828 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
829 aViewWindow->SetSelectionMode(NodeSelection);
830 } else if (send == SelectVectorButton) {
831 myEditCurrentArgument = (QWidget*)SpinBox_DX;
832 SMESH::SetPointRepresentation(true);
834 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
835 aViewWindow->SetSelectionMode(NodeSelection);
839 myEditCurrentArgument->setFocus();
840 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
841 SelectionIntoArgument();
844 //=================================================================================
845 // function : DeactivateActiveDialog()
847 //=================================================================================
848 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
850 if (GroupConstructors->isEnabled()) {
851 GroupConstructors->setEnabled(false);
852 GroupArguments->setEnabled(false);
853 GroupButtons->setEnabled(false);
854 mySMESHGUI->ResetState();
855 mySMESHGUI->SetActiveDialogBox(0);
859 //=================================================================================
860 // function : ActivateThisDialog()
862 //=================================================================================
863 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
865 /* Emit a signal to deactivate the active dialog */
866 mySMESHGUI->EmitSignalDeactivateDialog();
867 GroupConstructors->setEnabled(true);
868 GroupArguments->setEnabled(true);
869 GroupButtons->setEnabled(true);
871 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
873 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
874 aViewWindow->SetSelectionMode(CellSelection);
875 SelectionIntoArgument();
878 //=================================================================================
879 // function : enterEvent()
881 //=================================================================================
882 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
884 if (!GroupConstructors->isEnabled())
885 ActivateThisDialog();
888 //=================================================================================
889 // function : closeEvent()
891 //=================================================================================
892 void SMESHGUI_SymmetryDlg::closeEvent (QCloseEvent*)
894 /* same than click on cancel button */
895 this->ClickOnCancel();
898 //=======================================================================
899 // function : hideEvent()
900 // purpose : caused by ESC key
901 //=======================================================================
902 void SMESHGUI_SymmetryDlg::hideEvent (QHideEvent*)
908 //=======================================================================
909 //function : onSelectMesh
911 //=======================================================================
912 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
915 TextLabelElements->setText(tr("SMESH_NAME"));
917 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
919 if (myEditCurrentArgument != LineEditElements) {
920 LineEditElements->clear();
924 mySelectionMgr->clearFilters();
925 SMESH::SetPointRepresentation(false);
928 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
929 aViewWindow->SetSelectionMode(ActorSelection);
930 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
931 LineEditElements->setReadOnly(true);
933 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
934 aViewWindow->SetSelectionMode(CellSelection);
935 LineEditElements->setReadOnly(false);
936 onTextChange(LineEditElements->text());
939 SelectionIntoArgument();
942 //=================================================================================
943 // function : GetConstructorId()
945 //=================================================================================
946 int SMESHGUI_SymmetryDlg::GetConstructorId()
948 if (GroupConstructors != NULL && GroupConstructors->selected() != NULL)
949 return GroupConstructors->id(GroupConstructors->selected());
953 //=================================================================================
954 // function : IsMirrorOk()
956 //=================================================================================
957 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
961 if (GetConstructorId() != 0)
962 isOk = (SpinBox_DX->GetValue() != 0 ||
963 SpinBox_DY->GetValue() != 0 ||
964 SpinBox_DZ->GetValue() != 0);
969 //=================================================================================
970 // function : onVectorChanged()
972 //=================================================================================
973 void SMESHGUI_SymmetryDlg::onVectorChanged()
976 buttonOk->setEnabled(true);
977 buttonApply->setEnabled(true);
979 buttonOk->setEnabled(false);
980 buttonApply->setEnabled(false);
984 //=======================================================================
985 //function : onActionClicked
986 //purpose : slot called when an action type changed
987 //=======================================================================
989 void SMESHGUI_SymmetryDlg::onActionClicked(int button)
992 case MOVE_ELEMS_BUTTON:
993 MakeGroupsCheck->setEnabled(false);
994 LineEditNewMesh->setEnabled(false);
996 case COPY_ELEMS_BUTTON:
997 LineEditNewMesh->setEnabled(false);
998 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
999 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1000 MakeGroupsCheck->setEnabled(true);
1002 MakeGroupsCheck->setEnabled(false);
1004 case MAKE_MESH_BUTTON:
1005 LineEditNewMesh->setEnabled(true);
1006 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1007 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1008 MakeGroupsCheck->setEnabled(true);
1010 MakeGroupsCheck->setEnabled(false);
1016 //=======================================================================
1017 //function : setNewMeshName
1018 //purpose : update contents of LineEditNewMesh
1019 //=======================================================================
1021 void SMESHGUI_SymmetryDlg::setNewMeshName()
1023 LineEditNewMesh->setText("");
1024 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
1026 if ( CheckBoxMesh->isChecked() ) {
1027 name = LineEditElements->text();
1030 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
1031 name = meshSO->GetName();
1033 if ( !name.isEmpty() )
1034 LineEditNewMesh->setText( SMESH::UniqueMeshName( name.latin1(), "mirrored"));
1038 //=================================================================================
1039 // function : keyPressEvent()
1041 //=================================================================================
1042 void SMESHGUI_SymmetryDlg::keyPressEvent( QKeyEvent* e )
1044 QDialog::keyPressEvent( e );
1045 if ( e->isAccepted() )
1048 if ( e->key() == Key_F1 )