1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_SymmetryDlg.cxx
24 // Author : Michael ZORIN
28 #include "SMESHGUI_SymmetryDlg.h"
31 #include "SMESHGUI_SpinBox.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_MeshUtils.h"
35 #include "SMESHGUI_IdValidator.h"
37 #include "SMESH_Actor.h"
38 #include "SMESH_TypeFilter.hxx"
39 #include "SMESH_LogicalFilter.hxx"
40 #include "SMDS_Mesh.hxx"
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"
49 #include "SVTK_ViewModel.h"
50 #include "SVTK_ViewWindow.h"
51 #include "SVTK_Selector.h"
52 #include "SVTK_Selection.h"
53 #include "SALOME_ListIO.hxx"
54 #include "SALOMEDSClient_SObject.hxx"
56 #include "utilities.h"
59 #include <TColStd_MapOfInteger.hxx>
60 #include <TColStd_IndexedMapOfInteger.hxx>
63 #include <qapplication.h>
64 #include <qbuttongroup.h>
65 #include <qgroupbox.h>
67 #include <qlineedit.h>
68 #include <qpushbutton.h>
69 #include <qradiobutton.h>
70 #include <qcheckbox.h>
75 #include "SALOMEconfig.h"
76 #include CORBA_SERVER_HEADER(SMESH_Group)
77 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
81 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
83 //=================================================================================
84 // class : SMESHGUI_SymmetryDlg()
86 //=================================================================================
88 SMESHGUI_SymmetryDlg::SMESHGUI_SymmetryDlg( SMESHGUI* theModule, const char* name,
89 bool modal, WFlags fl)
90 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
91 WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
92 mySMESHGUI( theModule ),
93 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
95 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_POINT")));
96 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_AXIS")));
97 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_PLANE")));
98 QPixmap image3 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
101 setName("SMESHGUI_SymmetryDlg");
103 setCaption(tr("SMESH_SYMMETRY"));
104 setSizeGripEnabled(TRUE);
105 SMESHGUI_SymmetryDlgLayout = new QGridLayout(this);
106 SMESHGUI_SymmetryDlgLayout->setSpacing(6);
107 SMESHGUI_SymmetryDlgLayout->setMargin(11);
109 /***************************************************************/
110 GroupConstructors = new QButtonGroup(this, "GroupConstructors");
111 GroupConstructors->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)5,
112 (QSizePolicy::SizeType)0, 0, 0,
113 GroupConstructors->sizePolicy().hasHeightForWidth()));
114 GroupConstructors->setTitle(tr("SMESH_SYMMETRY" ));
115 GroupConstructors->setExclusive(TRUE);
116 GroupConstructors->setColumnLayout(0, Qt::Vertical);
117 GroupConstructors->layout()->setSpacing(0);
118 GroupConstructors->layout()->setMargin(0);
119 GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
120 GroupConstructorsLayout->setAlignment(Qt::AlignTop);
121 GroupConstructorsLayout->setSpacing(6);
122 GroupConstructorsLayout->setMargin(11);
123 QHBoxLayout* RBLayout = new QHBoxLayout(0, 0, 6, "Layout2");
124 RadioButton1= new QRadioButton(GroupConstructors, "RadioButton1");
125 RadioButton1->setText(tr("" ));
126 RadioButton1->setPixmap(image0);
127 RBLayout->addWidget(RadioButton1);
128 RadioButton2= new QRadioButton(GroupConstructors, "RadioButton2");
129 RadioButton2->setText(tr("" ));
130 RadioButton2->setPixmap(image1);
131 RBLayout->addWidget(RadioButton2);
132 RadioButton3= new QRadioButton(GroupConstructors, "RadioButton3");
133 RadioButton3->setText(tr("" ));
134 RadioButton3->setPixmap(image2);
135 RBLayout->addWidget(RadioButton3);
136 GroupConstructorsLayout->addLayout(RBLayout, 0, 0);
137 SMESHGUI_SymmetryDlgLayout->addWidget(GroupConstructors, 0, 0);
139 /***************************************************************/
140 GroupButtons = new QGroupBox(this, "GroupButtons");
141 GroupButtons->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7,
142 (QSizePolicy::SizeType)0, 0, 0,
143 GroupButtons->sizePolicy().hasHeightForWidth()));
144 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
145 GroupButtons->setTitle(tr("" ));
146 GroupButtons->setColumnLayout(0, Qt::Vertical);
147 GroupButtons->layout()->setSpacing(0);
148 GroupButtons->layout()->setMargin(0);
149 GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
150 GroupButtonsLayout->setAlignment(Qt::AlignTop);
151 GroupButtonsLayout->setSpacing(6);
152 GroupButtonsLayout->setMargin(11);
153 buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
154 buttonHelp->setText(tr("SMESH_BUT_HELP" ));
155 buttonHelp->setAutoDefault(TRUE);
156 GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
157 buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
158 buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
159 buttonCancel->setAutoDefault(TRUE);
160 GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
161 buttonApply = new QPushButton(GroupButtons, "buttonApply");
162 buttonApply->setText(tr("SMESH_BUT_APPLY" ));
163 buttonApply->setAutoDefault(TRUE);
164 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
165 QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
166 GroupButtonsLayout->addItem(spacer_9, 0, 2);
167 buttonOk = new QPushButton(GroupButtons, "buttonOk");
168 buttonOk->setText(tr("SMESH_BUT_APPLY_AND_CLOSE" ));
169 buttonOk->setAutoDefault(TRUE);
170 buttonOk->setDefault(TRUE);
171 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
172 SMESHGUI_SymmetryDlgLayout->addWidget(GroupButtons, 2, 0);
174 /***************************************************************/
175 GroupArguments = new QGroupBox(this, "GroupArguments");
176 GroupArguments->setTitle(tr("SMESH_ARGUMENTS"));
177 GroupArguments->setColumnLayout(0, Qt::Vertical);
178 GroupArguments->layout()->setSpacing(0);
179 GroupArguments->layout()->setMargin(0);
180 GroupArgumentsLayout = new QGridLayout(GroupArguments->layout());
181 GroupArgumentsLayout->setAlignment(Qt::AlignTop);
182 GroupArgumentsLayout->setSpacing(6);
183 GroupArgumentsLayout->setMargin(11);
185 // Controls for elements selection
186 TextLabelElements = new QLabel(GroupArguments, "TextLabelElements");
187 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS" ));
188 //TextLabelElements->setFixedWidth(74);
189 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
190 //GroupArgumentsLayout->addMultiCellWidget(TextLabelElements, 0, 0, 0, 1);
192 SelectElementsButton = new QPushButton(GroupArguments, "SelectElementsButton");
193 SelectElementsButton->setText(tr("" ));
194 SelectElementsButton->setPixmap(image3);
195 SelectElementsButton->setToggleButton(FALSE);
196 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
198 LineEditElements = new QLineEdit(GroupArguments, "LineEditElements");
199 LineEditElements->setValidator(new SMESHGUI_IdValidator(this, "validator"));
200 //GroupArgumentsLayout->addWidget(LineEditElements, 0, 3);
201 GroupArgumentsLayout->addMultiCellWidget(LineEditElements, 0, 0, 2, 4);
203 // Control for the whole mesh selection
204 CheckBoxMesh = new QCheckBox(GroupArguments, "CheckBoxMesh");
205 CheckBoxMesh->setText(tr("SMESH_SELECT_WHOLE_MESH" ));
206 GroupArgumentsLayout->addMultiCellWidget(CheckBoxMesh, 1, 1, 0, 4);
208 // Controls for mirror selection
209 GroupMirror = new QGroupBox(GroupArguments, "GroupMirror");
210 GroupMirror->setColumnLayout(0, Qt::Vertical);
211 GroupMirror->layout()->setSpacing(0);
212 GroupMirror->layout()->setMargin(0);
213 QGridLayout* GroupMirrorLayout = new QGridLayout(GroupMirror->layout());
214 GroupMirrorLayout->setAlignment(Qt::AlignTop);
215 GroupMirrorLayout->setSpacing(6);
216 GroupMirrorLayout->setMargin(11);
218 TextLabelPoint = new QLabel(GroupMirror, "TextLabelPoint");
219 TextLabelPoint->setText(tr("SMESH_POINT"));
220 GroupMirrorLayout->addWidget(TextLabelPoint, 0, 0);
222 SelectPointButton = new QPushButton(GroupMirror, "SelectPointButton");
223 SelectPointButton->setPixmap(image3);
224 GroupMirrorLayout->addWidget(SelectPointButton, 0, 1);
226 TextLabelX = new QLabel(GroupMirror, "TextLabelX");
227 TextLabelX->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
228 TextLabelX->setText(tr("SMESH_X"));
229 GroupMirrorLayout->addWidget(TextLabelX, 0, 2);
231 SpinBox_X = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_X");
232 GroupMirrorLayout->addWidget(SpinBox_X, 0, 3);
234 TextLabelY = new QLabel(GroupMirror, "TextLabelY");
235 TextLabelY->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
236 TextLabelY->setText(tr("SMESH_Y"));
237 GroupMirrorLayout->addWidget(TextLabelY, 0, 4);
239 SpinBox_Y = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_Y");
240 GroupMirrorLayout->addWidget(SpinBox_Y, 0, 5);
242 TextLabelZ = new QLabel(GroupMirror, "TextLabelZ");
243 TextLabelZ->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
244 TextLabelZ->setText(tr("SMESH_Z"));
245 GroupMirrorLayout->addWidget(TextLabelZ, 0, 6);
247 SpinBox_Z = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_Z");
248 GroupMirrorLayout->addWidget(SpinBox_Z, 0, 7);
250 TextLabelVector = new QLabel(GroupMirror, "TextLabelVector");
251 GroupMirrorLayout->addWidget(TextLabelVector, 1, 0);
253 SelectVectorButton = new QPushButton(GroupMirror, "SelectVectorButton");
254 SelectVectorButton->setPixmap(image3);
255 GroupMirrorLayout->addWidget(SelectVectorButton, 1, 1);
257 TextLabelDX = new QLabel(GroupMirror, "TextLabelDX");
258 TextLabelDX->setText(tr("SMESH_DX"));
259 TextLabelDX->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
260 GroupMirrorLayout->addWidget(TextLabelDX, 1, 2);
262 SpinBox_DX = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_DX");
263 GroupMirrorLayout->addWidget(SpinBox_DX, 1, 3);
265 TextLabelDY = new QLabel(GroupMirror, "TextLabelDY");
266 TextLabelDY->setText(tr("SMESH_DY"));
267 TextLabelDY->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
268 GroupMirrorLayout->addWidget(TextLabelDY, 1, 4);
270 SpinBox_DY = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_DY");
271 GroupMirrorLayout->addWidget(SpinBox_DY, 1, 5);
273 TextLabelDZ = new QLabel(GroupMirror, "TextLabelDZ");
274 TextLabelDZ->setText(tr("SMESH_DZ"));
275 TextLabelDZ->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
276 GroupMirrorLayout->addWidget(TextLabelDZ, 1, 6);
278 SpinBox_DZ = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_DZ");
279 GroupMirrorLayout->addWidget(SpinBox_DZ, 1, 7);
281 GroupArgumentsLayout->addMultiCellWidget(GroupMirror, 2, 2, 0, 4);
283 // switch of action type
284 ActionGroup = new QButtonGroup(1, Qt::Horizontal, GroupArguments, "ActionGroup");
285 ActionGroup->setExclusive(true);
286 ActionGroup->insert(new QRadioButton(tr("SMESH_MOVE_ELEMENTS"),ActionGroup), MOVE_ELEMS_BUTTON);
287 ActionGroup->insert(new QRadioButton(tr("SMESH_COPY_ELEMENTS"),ActionGroup), COPY_ELEMS_BUTTON);
288 ActionGroup->insert(new QRadioButton(tr("SMESH_CREATE_MESH" ),ActionGroup), MAKE_MESH_BUTTON);
289 GroupArgumentsLayout->addMultiCellWidget(ActionGroup, 3, 5, 0, 3);
291 // CheckBox for groups generation
292 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
293 MakeGroupsCheck->setChecked(false);
294 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 4, 4);
296 // Name of a mesh to create
297 LineEditNewMesh = new QLineEdit(GroupArguments, "LineEditNewMesh");
298 GroupArgumentsLayout->addWidget(LineEditNewMesh, 5, 4);
300 SMESHGUI_SymmetryDlgLayout->addWidget(GroupArguments, 1, 0);
302 /* Initialisations */
303 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
304 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
305 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
306 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
307 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
308 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
310 GroupArguments->show();
311 RadioButton1->setChecked(TRUE);
313 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
315 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
317 // Costruction of the logical filter
318 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
319 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
321 QPtrList<SUIT_SelectionFilter> aListOfFilters;
322 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
323 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
325 myMeshOrSubMeshOrGroupFilter =
326 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
328 myHelpFileName = "symmetry_page.html";
332 /* signals and slots connections */
333 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
334 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
335 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
336 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
337 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
339 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
340 connect(SelectPointButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
341 connect(SelectVectorButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
343 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
344 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
345 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
347 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
348 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
349 /* to close dialog if study change */
350 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
351 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
352 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
353 connect(ActionGroup, SIGNAL(clicked(int)), SLOT(onActionClicked(int)));
355 this->show(); /* displays Dialog */
357 ConstructorsClicked(0);
358 SelectionIntoArgument();
359 onActionClicked(MOVE_ELEMS_BUTTON);
363 //=================================================================================
364 // function : ~SMESHGUI_SymmetryDlg()
365 // purpose : Destroys the object and frees any allocated resources
366 //=================================================================================
367 SMESHGUI_SymmetryDlg::~SMESHGUI_SymmetryDlg()
369 // no need to delete child widgets, Qt does it all for us
372 //=================================================================================
375 //=================================================================================
376 void SMESHGUI_SymmetryDlg::Init (bool ResetControls)
380 myEditCurrentArgument = 0;
381 LineEditElements->clear();
385 buttonOk->setEnabled(false);
386 buttonApply->setEnabled(false);
389 myMesh = SMESH::SMESH_Mesh::_nil();
392 SpinBox_X->SetValue(0.0);
393 SpinBox_Y->SetValue(0.0);
394 SpinBox_Z->SetValue(0.0);
395 SpinBox_DX->SetValue(0.0);
396 SpinBox_DY->SetValue(0.0);
397 SpinBox_DZ->SetValue(0.0);
399 ((QRadioButton*) ActionGroup->find( MOVE_ELEMS_BUTTON ))->setChecked(TRUE);
400 CheckBoxMesh->setChecked(false);
401 // MakeGroupsCheck->setChecked(false);
402 // MakeGroupsCheck->setEnabled(false);
407 //=================================================================================
408 // function : ConstructorsClicked()
409 // purpose : Radio button management
410 //=================================================================================
411 void SMESHGUI_SymmetryDlg::ConstructorsClicked (int constructorId)
413 disconnect(mySelectionMgr, 0, this, 0);
415 if (constructorId != 0 && !TextLabelVector->isVisible()) {
416 TextLabelVector->show();
417 SelectVectorButton->show();
426 switch (constructorId) {
429 GroupMirror->setTitle(tr("SMESH_POINT"));
431 TextLabelVector->hide();
432 SelectVectorButton->hide();
443 GroupMirror->setTitle(tr("SMESH_AXIS"));
444 TextLabelVector->setText(tr("SMESH_VECTOR"));
449 GroupMirror->setTitle(tr("SMESH_PLANE"));
450 TextLabelVector->setText(tr("SMESH_NORMAL"));
455 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
456 SMESH::SetPointRepresentation(false);
457 if (!CheckBoxMesh->isChecked())
459 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
460 aViewWindow->SetSelectionMode(CellSelection);
464 myEditCurrentArgument = (QWidget*)LineEditElements;
465 LineEditElements->setFocus();
467 if (CheckBoxMesh->isChecked())
470 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
473 //=================================================================================
474 // function : ClickOnApply()
476 //=================================================================================
477 void SMESHGUI_SymmetryDlg::ClickOnApply()
479 if (mySMESHGUI->isActiveStudyLocked())
482 if (myNbOkElements && IsMirrorOk()) {
483 QStringList aListElementsId = QStringList::split(" ", myElementsId, false);
485 SMESH::long_array_var anElementsId = new SMESH::long_array;
487 anElementsId->length(aListElementsId.count());
488 for (int i = 0; i < aListElementsId.count(); i++)
489 anElementsId[i] = aListElementsId[i].toInt();
491 SMESH::AxisStruct aMirror;
493 aMirror.x = SpinBox_X->GetValue();
494 aMirror.y = SpinBox_Y->GetValue();
495 aMirror.z = SpinBox_Z->GetValue();
496 if (GetConstructorId() == 0) {
497 aMirror.vx = aMirror.vy = aMirror.vz = 0;
499 aMirror.vx = SpinBox_DX->GetValue();
500 aMirror.vy = SpinBox_DY->GetValue();
501 aMirror.vz = SpinBox_DZ->GetValue();
505 SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
507 if (GetConstructorId() == 0)
508 aMirrorType = SMESH::SMESH_MeshEditor::POINT;
509 if (GetConstructorId() == 1)
510 aMirrorType = SMESH::SMESH_MeshEditor::AXIS;
511 if (GetConstructorId() == 2)
512 aMirrorType = SMESH::SMESH_MeshEditor::PLANE;
514 int actionButton = ActionGroup->id( ActionGroup->selected() );
515 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
518 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
519 QApplication::setOverrideCursor(Qt::waitCursor);
520 switch ( actionButton ) {
521 case MOVE_ELEMS_BUTTON:
522 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, false );
524 case COPY_ELEMS_BUTTON:
526 SMESH::ListOfGroups_var groups =
527 aMeshEditor->MirrorMakeGroups(anElementsId, aMirror, aMirrorType);
529 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, true);
531 case MAKE_MESH_BUTTON:
532 SMESH::SMESH_Mesh_var mesh =
533 aMeshEditor->MirrorMakeMesh(anElementsId, aMirror, aMirrorType, makeGroups,
534 LineEditNewMesh->text().latin1());
536 QApplication::restoreOverrideCursor();
541 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
542 actionButton == MAKE_MESH_BUTTON )
543 mySMESHGUI->updateObjBrowser(true); // new groups may appear
545 ConstructorsClicked(GetConstructorId());
546 SelectionIntoArgument();
550 //=================================================================================
551 // function : ClickOnOk()
553 //=================================================================================
554 void SMESHGUI_SymmetryDlg::ClickOnOk()
560 //=================================================================================
561 // function : ClickOnCancel()
563 //=================================================================================
564 void SMESHGUI_SymmetryDlg::ClickOnCancel()
566 disconnect(mySelectionMgr, 0, this, 0);
567 mySelectionMgr->clearFilters();
568 //mySelectionMgr->clearSelected();
569 SMESH::SetPointRepresentation(false);
570 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
571 aViewWindow->SetSelectionMode(ActorSelection);
572 mySMESHGUI->ResetState();
576 //=================================================================================
577 // function : ClickOnHelp()
579 //=================================================================================
580 void SMESHGUI_SymmetryDlg::ClickOnHelp()
582 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
584 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
588 platform = "winapplication";
590 platform = "application";
592 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
593 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
594 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
595 QObject::tr("BUT_OK"));
599 //=======================================================================
600 // function : onTextChange()
602 //=======================================================================
603 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
605 QLineEdit* send = (QLineEdit*)sender();
610 if (send == LineEditElements)
613 buttonOk->setEnabled(false);
614 buttonApply->setEnabled(false);
616 // hilight entered elements
617 SMDS_Mesh* aMesh = 0;
619 aMesh = myActor->GetObject()->GetMesh();
622 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
624 TColStd_MapOfInteger newIndices;
626 QStringList aListId = QStringList::split(" ", theNewText, false);
628 if (send == LineEditElements) {
629 for (int i = 0; i < aListId.count(); i++) {
630 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
632 newIndices.Add(e->GetID());
636 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
637 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
638 aViewWindow->highlight( anIO, true, true );
640 myElementsId = theNewText;
644 if (myNbOkElements && IsMirrorOk()) {
645 buttonOk->setEnabled(true);
646 buttonApply->setEnabled(true);
652 //=================================================================================
653 // function : SelectionIntoArgument()
654 // purpose : Called when selection as changed or other case
655 //=================================================================================
656 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
662 QString aString = "";
665 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
666 LineEditElements->setText(aString);
668 buttonOk->setEnabled(false);
669 buttonApply->setEnabled(false);
673 if (!GroupButtons->isEnabled()) // inactive
678 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
680 int nbSel = aList.Extent();
684 Handle(SALOME_InteractiveObject) IO = aList.First();
685 myMesh = SMESH::GetMeshByIO(IO);
686 if(myMesh->_is_nil())
689 myActor = SMESH::FindActorByObject(myMesh);
691 myActor = SMESH::FindActorByEntry(IO->getEntry());
697 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
700 // MakeGroups is available if there are groups and "Copy"
701 if ( myMesh->NbGroups() == 0 ) {
702 MakeGroupsCheck->setChecked(false);
703 MakeGroupsCheck->setEnabled(false);
705 else if ( ActionGroup->id( ActionGroup->selected() ) != MOVE_ELEMS_BUTTON ) {
706 MakeGroupsCheck->setEnabled(true);
708 if (CheckBoxMesh->isChecked()) {
709 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
711 if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
713 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
717 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
718 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
720 myElementsId += QString(" %1").arg(i);
724 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
726 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
728 // get IDs from submesh
729 SMESH::long_array_var anElementsIds = new SMESH::long_array;
730 anElementsIds = aSubMesh->GetElementsId();
731 for (int i = 0; i < anElementsIds->length(); i++) {
732 myElementsId += QString(" %1").arg(anElementsIds[i]);
734 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();
751 aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, IO, aString);
752 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);
790 LineEditElements->repaint();
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 )