1 // Copyright (C) 2007-2010 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
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_SymmetryDlg.cxx
25 // Author : Michael ZORIN, Open CASCADE S.A.S.
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"
36 #include "SMESHGUI_FilterDlg.h"
38 #include <SMESH_Actor.h>
39 #include <SMESH_TypeFilter.hxx>
40 #include <SMESH_LogicalFilter.hxx>
41 #include <SMDS_Mesh.hxx>
43 // SALOME GUI includes
44 #include <SUIT_Desktop.h>
45 #include <SUIT_ResourceMgr.h>
46 #include <SUIT_Session.h>
47 #include <SUIT_MessageBox.h>
48 #include <SUIT_OverrideCursor.h>
50 #include <LightApp_Application.h>
51 #include <LightApp_SelectionMgr.h>
53 #include <SVTK_ViewModel.h>
54 #include <SVTK_ViewWindow.h>
55 #include <SALOME_ListIO.hxx>
57 // SALOME KERNEL includes
58 #include <SALOMEDSClient_SObject.hxx>
61 #include <TColStd_MapOfInteger.hxx>
64 #include <QApplication>
65 #include <QButtonGroup>
69 #include <QPushButton>
70 #include <QRadioButton>
72 #include <QHBoxLayout>
73 #include <QVBoxLayout>
74 #include <QGridLayout>
78 #include <SALOMEconfig.h>
79 #include CORBA_SERVER_HEADER(SMESH_Group)
80 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
82 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
87 //=================================================================================
88 // class : SMESHGUI_SymmetryDlg()
90 //=================================================================================
92 SMESHGUI_SymmetryDlg::SMESHGUI_SymmetryDlg( SMESHGUI* theModule )
93 : QDialog( SMESH::GetDesktop( theModule ) ),
94 mySMESHGUI( theModule ),
95 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
97 mySelectedObject(SMESH::SMESH_IDSource::_nil())
99 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_POINT")));
100 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_AXIS")));
101 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_PLANE")));
102 QPixmap image3 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
105 setAttribute(Qt::WA_DeleteOnClose, true);
106 setWindowTitle(tr("SMESH_SYMMETRY"));
107 setSizeGripEnabled(true);
109 QVBoxLayout* SMESHGUI_SymmetryDlgLayout = new QVBoxLayout(this);
110 SMESHGUI_SymmetryDlgLayout->setSpacing(SPACING);
111 SMESHGUI_SymmetryDlgLayout->setMargin(MARGIN);
113 /***************************************************************/
114 ConstructorsBox = new QGroupBox(tr("SMESH_SYMMETRY"), this);
115 GroupConstructors = new QButtonGroup(this);
116 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
117 ConstructorsBoxLayout->setSpacing(SPACING);
118 ConstructorsBoxLayout->setMargin(MARGIN);
120 RadioButton1 = new QRadioButton(ConstructorsBox);
121 RadioButton1->setIcon(image0);
122 RadioButton2 = new QRadioButton(ConstructorsBox);
123 RadioButton2->setIcon(image1);
124 RadioButton3 = new QRadioButton(ConstructorsBox);
125 RadioButton3->setIcon(image2);
127 ConstructorsBoxLayout->addWidget(RadioButton1);
128 ConstructorsBoxLayout->addWidget(RadioButton2);
129 ConstructorsBoxLayout->addWidget(RadioButton3);
130 GroupConstructors->addButton(RadioButton1, 0);
131 GroupConstructors->addButton(RadioButton2, 1);
132 GroupConstructors->addButton(RadioButton3, 2);
134 /***************************************************************/
135 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
136 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
137 GroupArgumentsLayout->setSpacing(SPACING);
138 GroupArgumentsLayout->setMargin(MARGIN);
140 myIdValidator = new SMESHGUI_IdValidator(this);
142 // Controls for elements selection
143 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
144 SelectElementsButton = new QPushButton(GroupArguments);
145 SelectElementsButton->setIcon(image3);
146 LineEditElements = new QLineEdit(GroupArguments);
147 LineEditElements->setValidator(myIdValidator);
148 LineEditElements->setMaxLength(-1);
149 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
150 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
152 // Control for the whole mesh selection
153 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
155 // Controls for mirror selection
156 GroupMirror = new QGroupBox(GroupArguments);
157 QGridLayout* GroupMirrorLayout = new QGridLayout(GroupMirror);
158 GroupMirrorLayout->setSpacing(SPACING);
159 GroupMirrorLayout->setMargin(MARGIN);
161 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupMirror);
162 SelectPointButton = new QPushButton(GroupMirror);
163 SelectPointButton->setIcon(image3);
165 TextLabelX = new QLabel(tr("SMESH_X"), GroupMirror);
166 SpinBox_X = new SMESHGUI_SpinBox(GroupMirror);
167 TextLabelY = new QLabel(tr("SMESH_Y"), GroupMirror);
168 SpinBox_Y = new SMESHGUI_SpinBox(GroupMirror);
169 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupMirror);
170 SpinBox_Z = new SMESHGUI_SpinBox(GroupMirror);
172 TextLabelVector = new QLabel(GroupMirror);
173 SelectVectorButton = new QPushButton(GroupMirror);
174 SelectVectorButton->setIcon(image3);
176 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupMirror);
177 SpinBox_DX = new SMESHGUI_SpinBox(GroupMirror);
178 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupMirror);
179 SpinBox_DY = new SMESHGUI_SpinBox(GroupMirror);
180 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupMirror);
181 SpinBox_DZ = new SMESHGUI_SpinBox(GroupMirror);
183 GroupMirrorLayout->addWidget(TextLabelPoint, 0, 0);
184 GroupMirrorLayout->addWidget(SelectPointButton, 0, 1);
185 GroupMirrorLayout->addWidget(TextLabelX, 0, 2);
186 GroupMirrorLayout->addWidget(SpinBox_X, 0, 3);
187 GroupMirrorLayout->addWidget(TextLabelY, 0, 4);
188 GroupMirrorLayout->addWidget(SpinBox_Y, 0, 5);
189 GroupMirrorLayout->addWidget(TextLabelZ, 0, 6);
190 GroupMirrorLayout->addWidget(SpinBox_Z, 0, 7);
191 GroupMirrorLayout->addWidget(TextLabelVector, 1, 0);
192 GroupMirrorLayout->addWidget(SelectVectorButton, 1, 1);
193 GroupMirrorLayout->addWidget(TextLabelDX, 1, 2);
194 GroupMirrorLayout->addWidget(SpinBox_DX, 1, 3);
195 GroupMirrorLayout->addWidget(TextLabelDY, 1, 4);
196 GroupMirrorLayout->addWidget(SpinBox_DY, 1, 5);
197 GroupMirrorLayout->addWidget(TextLabelDZ, 1, 6);
198 GroupMirrorLayout->addWidget(SpinBox_DZ, 1, 7);
200 // switch of action type
201 ActionBox = new QGroupBox(GroupArguments);
202 ActionGroup = new QButtonGroup(GroupArguments);
203 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
204 ActionBoxLayout->addSpacing(SPACING);
205 ActionBoxLayout->setMargin(MARGIN);
207 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
208 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
209 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
211 ActionBoxLayout->addWidget(aMoveElements);
212 ActionBoxLayout->addWidget(aCopyElements);
213 ActionBoxLayout->addWidget(aCreateMesh);
214 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
215 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
216 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
218 // CheckBox for groups generation
219 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
220 MakeGroupsCheck->setChecked(false);
222 // Name of a mesh to create
223 LineEditNewMesh = new QLineEdit(GroupArguments);
226 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
227 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
228 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 1);
229 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 3);
230 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
231 GroupArgumentsLayout->addWidget(GroupMirror, 2, 0, 1, 4);
232 GroupArgumentsLayout->addWidget(ActionBox, 3, 0, 3, 3);
233 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 4, 3);
234 GroupArgumentsLayout->addWidget(LineEditNewMesh, 5, 3);
236 /***************************************************************/
237 GroupButtons = new QGroupBox(this);
238 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
239 GroupButtonsLayout->setSpacing(SPACING);
240 GroupButtonsLayout->setMargin(MARGIN);
242 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
243 buttonOk->setAutoDefault(true);
244 buttonOk->setDefault(true);
245 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
246 buttonApply->setAutoDefault(true);
247 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
248 buttonCancel->setAutoDefault(true);
249 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
250 buttonHelp->setAutoDefault(true);
252 GroupButtonsLayout->addWidget(buttonOk);
253 GroupButtonsLayout->addSpacing(10);
254 GroupButtonsLayout->addWidget(buttonApply);
255 GroupButtonsLayout->addSpacing(10);
256 GroupButtonsLayout->addStretch();
257 GroupButtonsLayout->addWidget(buttonCancel);
258 GroupButtonsLayout->addWidget(buttonHelp);
260 /***************************************************************/
261 SMESHGUI_SymmetryDlgLayout->addWidget(ConstructorsBox);
262 SMESHGUI_SymmetryDlgLayout->addWidget(GroupArguments);
263 SMESHGUI_SymmetryDlgLayout->addWidget(GroupButtons);
265 /* Initialisations */
266 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
267 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
268 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
269 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
270 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
271 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
273 RadioButton1->setChecked(true);
275 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
277 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
279 // Costruction of the logical filter
280 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
281 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
283 QList<SUIT_SelectionFilter*> aListOfFilters;
284 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
285 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
287 myMeshOrSubMeshOrGroupFilter =
288 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
290 myHelpFileName = "symmetry_page.html";
294 /* signals and slots connections */
295 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
296 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
297 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
298 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
299 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
301 connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
302 connect(SelectPointButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
303 connect(SelectVectorButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
305 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
306 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
307 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
309 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
310 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
311 /* to close dialog if study change */
312 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
313 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
314 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
315 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
317 ConstructorsClicked(0);
318 SelectionIntoArgument();
319 onActionClicked(MOVE_ELEMS_BUTTON);
322 //=================================================================================
323 // function : ~SMESHGUI_SymmetryDlg()
324 // purpose : Destroys the object and frees any allocated resources
325 //=================================================================================
326 SMESHGUI_SymmetryDlg::~SMESHGUI_SymmetryDlg()
328 if ( myFilterDlg != 0 ) {
329 myFilterDlg->setParent( 0 );
334 //=================================================================================
337 //=================================================================================
338 void SMESHGUI_SymmetryDlg::Init (bool ResetControls)
342 myEditCurrentArgument = 0;
343 LineEditElements->clear();
347 buttonOk->setEnabled(false);
348 buttonApply->setEnabled(false);
351 myMesh = SMESH::SMESH_Mesh::_nil();
354 SpinBox_X->SetValue(0.0);
355 SpinBox_Y->SetValue(0.0);
356 SpinBox_Z->SetValue(0.0);
357 SpinBox_DX->SetValue(0.0);
358 SpinBox_DY->SetValue(0.0);
359 SpinBox_DZ->SetValue(0.0);
361 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
362 CheckBoxMesh->setChecked(false);
363 // MakeGroupsCheck->setChecked(false);
364 // MakeGroupsCheck->setEnabled(false);
369 //=================================================================================
370 // function : ConstructorsClicked()
371 // purpose : Radio button management
372 //=================================================================================
373 void SMESHGUI_SymmetryDlg::ConstructorsClicked (int constructorId)
375 disconnect(mySelectionMgr, 0, this, 0);
377 if (constructorId != 0 && !TextLabelVector->isVisible()) {
378 TextLabelVector->show();
379 SelectVectorButton->show();
388 switch (constructorId) {
391 GroupMirror->setTitle(tr("SMESH_POINT"));
393 TextLabelVector->hide();
394 SelectVectorButton->hide();
405 GroupMirror->setTitle(tr("SMESH_AXIS"));
406 TextLabelVector->setText(tr("SMESH_VECTOR"));
411 GroupMirror->setTitle(tr("SMESH_PLANE"));
412 TextLabelVector->setText(tr("SMESH_NORMAL"));
417 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
418 SMESH::SetPointRepresentation(false);
419 if (!CheckBoxMesh->isChecked())
421 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
422 aViewWindow->SetSelectionMode(CellSelection);
426 myEditCurrentArgument = (QWidget*)LineEditElements;
427 LineEditElements->setFocus();
429 if (CheckBoxMesh->isChecked())
432 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
434 QApplication::instance()->processEvents();
439 //=================================================================================
440 // function : ClickOnApply()
442 //=================================================================================
443 bool SMESHGUI_SymmetryDlg::ClickOnApply()
445 if (mySMESHGUI->isActiveStudyLocked())
451 if (myNbOkElements && IsMirrorOk()) {
452 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
454 SMESH::long_array_var anElementsId = new SMESH::long_array;
456 anElementsId->length(aListElementsId.count());
457 for (int i = 0; i < aListElementsId.count(); i++)
458 anElementsId[i] = aListElementsId[i].toInt();
460 SMESH::AxisStruct aMirror;
462 aMirror.x = SpinBox_X->GetValue();
463 aMirror.y = SpinBox_Y->GetValue();
464 aMirror.z = SpinBox_Z->GetValue();
465 if (GetConstructorId() == 0) {
466 aMirror.vx = aMirror.vy = aMirror.vz = 0;
468 aMirror.vx = SpinBox_DX->GetValue();
469 aMirror.vy = SpinBox_DY->GetValue();
470 aMirror.vz = SpinBox_DZ->GetValue();
473 QStringList aParameters;
474 aParameters << SpinBox_X->text();
475 aParameters << SpinBox_Y->text();
476 aParameters << SpinBox_Z->text();
477 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DX->text() );
478 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DY->text() );
479 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DZ->text() );
481 SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
483 if (GetConstructorId() == 0)
484 aMirrorType = SMESH::SMESH_MeshEditor::POINT;
485 if (GetConstructorId() == 1)
486 aMirrorType = SMESH::SMESH_MeshEditor::AXIS;
487 if (GetConstructorId() == 2)
488 aMirrorType = SMESH::SMESH_MeshEditor::PLANE;
490 int actionButton = ActionGroup->checkedId();
491 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
494 SUIT_OverrideCursor aWaitCursor;
495 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
497 switch ( actionButton ) {
498 case MOVE_ELEMS_BUTTON: {
499 if(CheckBoxMesh->isChecked())
500 aMeshEditor->MirrorObject(mySelectedObject, aMirror, aMirrorType, false );
502 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, false );
504 if( !myMesh->_is_nil())
505 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
508 case COPY_ELEMS_BUTTON: {
509 SMESH::ListOfGroups_var groups;
511 if(CheckBoxMesh->isChecked())
512 groups = aMeshEditor->MirrorObjectMakeGroups(mySelectedObject, aMirror, aMirrorType);
514 groups = aMeshEditor->MirrorMakeGroups(anElementsId, aMirror, aMirrorType);
517 if(CheckBoxMesh->isChecked())
518 aMeshEditor->MirrorObject(mySelectedObject, aMirror, aMirrorType, true);
520 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, true);
522 if( !myMesh->_is_nil())
523 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
526 case MAKE_MESH_BUTTON: {
527 SMESH::SMESH_Mesh_var mesh;
528 if(CheckBoxMesh->isChecked())
529 mesh = aMeshEditor->MirrorObjectMakeMesh(mySelectedObject, aMirror, aMirrorType, makeGroups,
530 LineEditNewMesh->text().toLatin1().data());
532 mesh = aMeshEditor->MirrorMakeMesh(anElementsId, aMirror, aMirrorType, makeGroups,
533 LineEditNewMesh->text().toLatin1().data());
534 if( !mesh->_is_nil())
535 mesh->SetParameters( aParameters.join(":").toLatin1().constData() );
543 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
544 actionButton == MAKE_MESH_BUTTON )
545 mySMESHGUI->updateObjBrowser(true); // new groups may appear
547 ConstructorsClicked(GetConstructorId());
548 mySelectedObject = SMESH::SMESH_IDSource::_nil();
549 SelectionIntoArgument();
551 SMESHGUI::Modified();
556 //=================================================================================
557 // function : ClickOnOk()
559 //=================================================================================
560 void SMESHGUI_SymmetryDlg::ClickOnOk()
566 //=================================================================================
567 // function : ClickOnCancel()
569 //=================================================================================
570 void SMESHGUI_SymmetryDlg::ClickOnCancel()
572 disconnect(mySelectionMgr, 0, this, 0);
573 mySelectionMgr->clearFilters();
574 //mySelectionMgr->clearSelected();
575 if (SMESH::GetCurrentVtkView()) {
576 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
577 SMESH::SetPointRepresentation(false);
579 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
580 aViewWindow->SetSelectionMode(ActorSelection);
581 mySMESHGUI->ResetState();
585 //=================================================================================
586 // function : ClickOnHelp()
588 //=================================================================================
589 void SMESHGUI_SymmetryDlg::ClickOnHelp()
591 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
593 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
597 platform = "winapplication";
599 platform = "application";
601 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
602 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
603 arg(app->resourceMgr()->stringValue("ExternalBrowser",
605 arg(myHelpFileName));
609 //=======================================================================
610 // function : onTextChange()
612 //=======================================================================
613 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
615 QLineEdit* send = (QLineEdit*)sender();
620 if (send == LineEditElements)
623 buttonOk->setEnabled(false);
624 buttonApply->setEnabled(false);
626 // hilight entered elements
627 SMDS_Mesh* aMesh = 0;
629 aMesh = myActor->GetObject()->GetMesh();
632 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
634 TColStd_MapOfInteger newIndices;
636 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
638 if (send == LineEditElements) {
639 for (int i = 0; i < aListId.count(); i++) {
640 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
642 newIndices.Add(e->GetID());
646 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
647 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
648 aViewWindow->highlight( anIO, true, true );
650 myElementsId = theNewText;
654 if (myNbOkElements && IsMirrorOk()) {
655 buttonOk->setEnabled(true);
656 buttonApply->setEnabled(true);
662 //=================================================================================
663 // function : SelectionIntoArgument()
664 // purpose : Called when selection as changed or other case
665 //=================================================================================
666 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
672 QString aString = "";
675 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
676 LineEditElements->setText(aString);
678 buttonOk->setEnabled(false);
679 buttonApply->setEnabled(false);
683 if (!GroupButtons->isEnabled()) // inactive
688 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
690 int nbSel = aList.Extent();
694 Handle(SALOME_InteractiveObject) IO = aList.First();
695 myMesh = SMESH::GetMeshByIO(IO);
696 if(myMesh->_is_nil())
699 myActor = SMESH::FindActorByObject(myMesh);
701 myActor = SMESH::FindActorByEntry(IO->getEntry());
702 if (!myActor && !CheckBoxMesh->isChecked())
707 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
710 // MakeGroups is available if there are groups and "Copy"
711 if ( myMesh->NbGroups() == 0 ) {
712 MakeGroupsCheck->setChecked(false);
713 MakeGroupsCheck->setEnabled(false);
715 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
716 MakeGroupsCheck->setEnabled(true);
718 if (CheckBoxMesh->isChecked()) {
719 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
721 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH
722 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
728 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
732 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
733 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
735 myElementsId += QString(" %1").arg(i);
740 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
742 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
744 // get IDs from submesh
746 SMESH::long_array_var anElementsIds = new SMESH::long_array;
747 anElementsIds = aSubMesh->GetElementsId();
748 for (int i = 0; i < anElementsIds->length(); i++) {
749 myElementsId += QString(" %1").arg(anElementsIds[i]);
751 aNbUnits = anElementsIds->length();
755 SMESH::SMESH_GroupBase_var aGroup =
756 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
757 if (aGroup->_is_nil())
760 // get IDs from smesh group
761 SMESH::long_array_var anElementsIds = new SMESH::long_array;
762 anElementsIds = aGroup->GetListOfID();
763 for (int i = 0; i < anElementsIds->length(); i++) {
764 myElementsId += QString(" %1").arg(anElementsIds[i]);
766 aNbUnits = anElementsIds->length();
770 aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, IO, aString);
771 myElementsId = aString;
776 myNbOkElements = true;
778 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
782 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
786 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
794 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
795 SpinBox_X->SetValue(x);
796 SpinBox_Y->SetValue(y);
797 SpinBox_Z->SetValue(z);
798 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
799 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
800 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
801 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
806 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
807 LineEditElements->setText(aString);
808 LineEditElements->repaint();
809 LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
810 LineEditElements->setEnabled(true);
816 if (myNbOkElements && IsMirrorOk()) {
817 buttonOk->setEnabled(true);
818 buttonApply->setEnabled(true);
822 //=================================================================================
823 // function : SetEditCurrentArgument()
825 //=================================================================================
826 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
828 QPushButton* send = (QPushButton*)sender();
830 disconnect(mySelectionMgr, 0, this, 0);
831 mySelectionMgr->clearSelected();
832 mySelectionMgr->clearFilters();
834 if (send == SelectElementsButton) {
835 myEditCurrentArgument = (QWidget*)LineEditElements;
836 SMESH::SetPointRepresentation(false);
837 if (CheckBoxMesh->isChecked()) {
838 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
839 aViewWindow->SetSelectionMode(ActorSelection);
840 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
842 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
843 aViewWindow->SetSelectionMode(CellSelection);
845 } else if (send == SelectPointButton) {
846 myEditCurrentArgument = (QWidget*)SpinBox_X;
847 SMESH::SetPointRepresentation(true);
848 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
849 aViewWindow->SetSelectionMode(NodeSelection);
850 } else if (send == SelectVectorButton) {
851 myEditCurrentArgument = (QWidget*)SpinBox_DX;
852 SMESH::SetPointRepresentation(true);
854 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
855 aViewWindow->SetSelectionMode(NodeSelection);
859 myEditCurrentArgument->setFocus();
860 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
861 SelectionIntoArgument();
864 //=================================================================================
865 // function : DeactivateActiveDialog()
867 //=================================================================================
868 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
870 if (ConstructorsBox->isEnabled()) {
871 ConstructorsBox->setEnabled(false);
872 GroupArguments->setEnabled(false);
873 GroupButtons->setEnabled(false);
874 mySMESHGUI->ResetState();
875 mySMESHGUI->SetActiveDialogBox(0);
879 //=================================================================================
880 // function : ActivateThisDialog()
882 //=================================================================================
883 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
885 /* Emit a signal to deactivate the active dialog */
886 mySMESHGUI->EmitSignalDeactivateDialog();
887 ConstructorsBox->setEnabled(true);
888 GroupArguments->setEnabled(true);
889 GroupButtons->setEnabled(true);
891 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
893 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
894 aViewWindow->SetSelectionMode(CellSelection);
895 SelectionIntoArgument();
898 //=================================================================================
899 // function : enterEvent()
901 //=================================================================================
902 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
904 if (!ConstructorsBox->isEnabled())
905 ActivateThisDialog();
908 //=================================================================================
909 // function : closeEvent()
911 //=================================================================================
912 void SMESHGUI_SymmetryDlg::closeEvent (QCloseEvent*)
914 /* same than click on cancel button */
918 //=======================================================================
919 // function : hideEvent()
920 // purpose : caused by ESC key
921 //=======================================================================
922 void SMESHGUI_SymmetryDlg::hideEvent (QHideEvent*)
928 //=======================================================================
929 //function : onSelectMesh
931 //=======================================================================
932 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
935 TextLabelElements->setText(tr("SMESH_NAME"));
937 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
938 myFilterBtn->setEnabled(!toSelectMesh);
940 if (myEditCurrentArgument != LineEditElements) {
941 LineEditElements->clear();
945 mySelectionMgr->clearFilters();
946 SMESH::SetPointRepresentation(false);
949 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
950 aViewWindow->SetSelectionMode(ActorSelection);
951 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
952 LineEditElements->setReadOnly(true);
953 LineEditElements->setValidator(0);
955 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
956 aViewWindow->SetSelectionMode(CellSelection);
957 LineEditElements->setReadOnly(false);
958 LineEditElements->setValidator(myIdValidator);
959 onTextChange(LineEditElements->text());
962 SelectionIntoArgument();
965 //=================================================================================
966 // function : GetConstructorId()
968 //=================================================================================
969 int SMESHGUI_SymmetryDlg::GetConstructorId()
971 return GroupConstructors->checkedId();
974 //=================================================================================
975 // function : IsMirrorOk()
977 //=================================================================================
978 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
982 if (GetConstructorId() != 0)
983 isOk = (SpinBox_DX->GetValue() != 0 ||
984 SpinBox_DY->GetValue() != 0 ||
985 SpinBox_DZ->GetValue() != 0);
990 //=================================================================================
991 // function : onVectorChanged()
993 //=================================================================================
994 void SMESHGUI_SymmetryDlg::onVectorChanged()
997 buttonOk->setEnabled(true);
998 buttonApply->setEnabled(true);
1000 buttonOk->setEnabled(false);
1001 buttonApply->setEnabled(false);
1005 //=======================================================================
1006 //function : onActionClicked
1007 //purpose : slot called when an action type changed
1008 //=======================================================================
1010 void SMESHGUI_SymmetryDlg::onActionClicked(int button)
1013 case MOVE_ELEMS_BUTTON:
1014 MakeGroupsCheck->setEnabled(false);
1015 LineEditNewMesh->setEnabled(false);
1017 case COPY_ELEMS_BUTTON:
1018 LineEditNewMesh->setEnabled(false);
1019 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1020 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1021 MakeGroupsCheck->setEnabled(true);
1023 MakeGroupsCheck->setEnabled(false);
1025 case MAKE_MESH_BUTTON:
1026 LineEditNewMesh->setEnabled(true);
1027 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1028 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1029 MakeGroupsCheck->setEnabled(true);
1031 MakeGroupsCheck->setEnabled(false);
1037 //=======================================================================
1038 //function : setNewMeshName
1039 //purpose : update contents of LineEditNewMesh
1040 //=======================================================================
1042 void SMESHGUI_SymmetryDlg::setNewMeshName()
1044 LineEditNewMesh->setText("");
1045 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
1047 if ( CheckBoxMesh->isChecked() ) {
1048 name = LineEditElements->text();
1051 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
1052 name = meshSO->GetName().c_str();
1054 if ( !name.isEmpty() )
1055 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "mirrored"));
1059 //=================================================================================
1060 // function : keyPressEvent()
1062 //=================================================================================
1063 void SMESHGUI_SymmetryDlg::keyPressEvent( QKeyEvent* e )
1065 QDialog::keyPressEvent( e );
1066 if ( e->isAccepted() )
1069 if ( e->key() == Qt::Key_F1 ) {
1075 //=================================================================================
1076 // function : setFilters()
1077 // purpose : SLOT. Called when "Filter" button pressed.
1078 //=================================================================================
1079 void SMESHGUI_SymmetryDlg::setFilters()
1081 if(myMesh->_is_nil()) {
1082 SUIT_MessageBox::critical(this,
1084 tr("NO_MESH_SELECTED"));
1088 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1090 myFilterDlg->SetSelection();
1091 myFilterDlg->SetMesh( myMesh );
1092 myFilterDlg->SetSourceWg( LineEditElements );
1094 myFilterDlg->show();
1097 //=================================================================================
1098 // function : isValid
1100 //=================================================================================
1101 bool SMESHGUI_SymmetryDlg::isValid()
1106 ok = SpinBox_X->isValid( msg, true ) && ok;
1107 ok = SpinBox_Y->isValid( msg, true ) && ok;
1108 ok = SpinBox_Z->isValid( msg, true ) && ok;
1109 if (GetConstructorId() != 0) {
1110 ok = SpinBox_DX->isValid( msg, true ) && ok;
1111 ok = SpinBox_DY->isValid( msg, true ) && ok;
1112 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1116 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1117 if ( !msg.isEmpty() )
1119 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );