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 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
149 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
151 // Control for the whole mesh selection
152 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
154 // Controls for mirror selection
155 GroupMirror = new QGroupBox(GroupArguments);
156 QGridLayout* GroupMirrorLayout = new QGridLayout(GroupMirror);
157 GroupMirrorLayout->setSpacing(SPACING);
158 GroupMirrorLayout->setMargin(MARGIN);
160 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupMirror);
161 SelectPointButton = new QPushButton(GroupMirror);
162 SelectPointButton->setIcon(image3);
164 TextLabelX = new QLabel(tr("SMESH_X"), GroupMirror);
165 SpinBox_X = new SMESHGUI_SpinBox(GroupMirror);
166 TextLabelY = new QLabel(tr("SMESH_Y"), GroupMirror);
167 SpinBox_Y = new SMESHGUI_SpinBox(GroupMirror);
168 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupMirror);
169 SpinBox_Z = new SMESHGUI_SpinBox(GroupMirror);
171 TextLabelVector = new QLabel(GroupMirror);
172 SelectVectorButton = new QPushButton(GroupMirror);
173 SelectVectorButton->setIcon(image3);
175 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupMirror);
176 SpinBox_DX = new SMESHGUI_SpinBox(GroupMirror);
177 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupMirror);
178 SpinBox_DY = new SMESHGUI_SpinBox(GroupMirror);
179 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupMirror);
180 SpinBox_DZ = new SMESHGUI_SpinBox(GroupMirror);
182 GroupMirrorLayout->addWidget(TextLabelPoint, 0, 0);
183 GroupMirrorLayout->addWidget(SelectPointButton, 0, 1);
184 GroupMirrorLayout->addWidget(TextLabelX, 0, 2);
185 GroupMirrorLayout->addWidget(SpinBox_X, 0, 3);
186 GroupMirrorLayout->addWidget(TextLabelY, 0, 4);
187 GroupMirrorLayout->addWidget(SpinBox_Y, 0, 5);
188 GroupMirrorLayout->addWidget(TextLabelZ, 0, 6);
189 GroupMirrorLayout->addWidget(SpinBox_Z, 0, 7);
190 GroupMirrorLayout->addWidget(TextLabelVector, 1, 0);
191 GroupMirrorLayout->addWidget(SelectVectorButton, 1, 1);
192 GroupMirrorLayout->addWidget(TextLabelDX, 1, 2);
193 GroupMirrorLayout->addWidget(SpinBox_DX, 1, 3);
194 GroupMirrorLayout->addWidget(TextLabelDY, 1, 4);
195 GroupMirrorLayout->addWidget(SpinBox_DY, 1, 5);
196 GroupMirrorLayout->addWidget(TextLabelDZ, 1, 6);
197 GroupMirrorLayout->addWidget(SpinBox_DZ, 1, 7);
199 // switch of action type
200 ActionBox = new QGroupBox(GroupArguments);
201 ActionGroup = new QButtonGroup(GroupArguments);
202 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
203 ActionBoxLayout->addSpacing(SPACING);
204 ActionBoxLayout->setMargin(MARGIN);
206 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
207 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
208 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
210 ActionBoxLayout->addWidget(aMoveElements);
211 ActionBoxLayout->addWidget(aCopyElements);
212 ActionBoxLayout->addWidget(aCreateMesh);
213 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
214 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
215 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
217 // CheckBox for groups generation
218 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
219 MakeGroupsCheck->setChecked(false);
221 // Name of a mesh to create
222 LineEditNewMesh = new QLineEdit(GroupArguments);
225 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
226 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
227 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 1);
228 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 3);
229 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
230 GroupArgumentsLayout->addWidget(GroupMirror, 2, 0, 1, 4);
231 GroupArgumentsLayout->addWidget(ActionBox, 3, 0, 3, 3);
232 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 4, 3);
233 GroupArgumentsLayout->addWidget(LineEditNewMesh, 5, 3);
235 /***************************************************************/
236 GroupButtons = new QGroupBox(this);
237 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
238 GroupButtonsLayout->setSpacing(SPACING);
239 GroupButtonsLayout->setMargin(MARGIN);
241 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
242 buttonOk->setAutoDefault(true);
243 buttonOk->setDefault(true);
244 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
245 buttonApply->setAutoDefault(true);
246 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
247 buttonCancel->setAutoDefault(true);
248 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
249 buttonHelp->setAutoDefault(true);
251 GroupButtonsLayout->addWidget(buttonOk);
252 GroupButtonsLayout->addSpacing(10);
253 GroupButtonsLayout->addWidget(buttonApply);
254 GroupButtonsLayout->addSpacing(10);
255 GroupButtonsLayout->addStretch();
256 GroupButtonsLayout->addWidget(buttonCancel);
257 GroupButtonsLayout->addWidget(buttonHelp);
259 /***************************************************************/
260 SMESHGUI_SymmetryDlgLayout->addWidget(ConstructorsBox);
261 SMESHGUI_SymmetryDlgLayout->addWidget(GroupArguments);
262 SMESHGUI_SymmetryDlgLayout->addWidget(GroupButtons);
264 /* Initialisations */
265 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
266 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
267 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
268 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
269 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
270 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
272 RadioButton1->setChecked(true);
274 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
276 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
278 // Costruction of the logical filter
279 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
280 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
282 QList<SUIT_SelectionFilter*> aListOfFilters;
283 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
284 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
286 myMeshOrSubMeshOrGroupFilter =
287 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
289 myHelpFileName = "symmetry_page.html";
293 /* signals and slots connections */
294 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
295 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
296 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
297 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
298 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
300 connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
301 connect(SelectPointButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
302 connect(SelectVectorButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
304 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
305 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
306 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
308 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
309 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
310 /* to close dialog if study change */
311 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
312 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
313 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
314 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
316 ConstructorsClicked(0);
317 SelectionIntoArgument();
318 onActionClicked(MOVE_ELEMS_BUTTON);
321 //=================================================================================
322 // function : ~SMESHGUI_SymmetryDlg()
323 // purpose : Destroys the object and frees any allocated resources
324 //=================================================================================
325 SMESHGUI_SymmetryDlg::~SMESHGUI_SymmetryDlg()
327 if ( myFilterDlg != 0 ) {
328 myFilterDlg->setParent( 0 );
333 //=================================================================================
336 //=================================================================================
337 void SMESHGUI_SymmetryDlg::Init (bool ResetControls)
341 myEditCurrentArgument = 0;
342 LineEditElements->clear();
346 buttonOk->setEnabled(false);
347 buttonApply->setEnabled(false);
350 myMesh = SMESH::SMESH_Mesh::_nil();
353 SpinBox_X->SetValue(0.0);
354 SpinBox_Y->SetValue(0.0);
355 SpinBox_Z->SetValue(0.0);
356 SpinBox_DX->SetValue(0.0);
357 SpinBox_DY->SetValue(0.0);
358 SpinBox_DZ->SetValue(0.0);
360 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
361 CheckBoxMesh->setChecked(false);
362 // MakeGroupsCheck->setChecked(false);
363 // MakeGroupsCheck->setEnabled(false);
368 //=================================================================================
369 // function : ConstructorsClicked()
370 // purpose : Radio button management
371 //=================================================================================
372 void SMESHGUI_SymmetryDlg::ConstructorsClicked (int constructorId)
374 disconnect(mySelectionMgr, 0, this, 0);
376 if (constructorId != 0 && !TextLabelVector->isVisible()) {
377 TextLabelVector->show();
378 SelectVectorButton->show();
387 switch (constructorId) {
390 GroupMirror->setTitle(tr("SMESH_POINT"));
392 TextLabelVector->hide();
393 SelectVectorButton->hide();
404 GroupMirror->setTitle(tr("SMESH_AXIS"));
405 TextLabelVector->setText(tr("SMESH_VECTOR"));
410 GroupMirror->setTitle(tr("SMESH_PLANE"));
411 TextLabelVector->setText(tr("SMESH_NORMAL"));
416 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
417 SMESH::SetPointRepresentation(false);
418 if (!CheckBoxMesh->isChecked())
420 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
421 aViewWindow->SetSelectionMode(CellSelection);
425 myEditCurrentArgument = (QWidget*)LineEditElements;
426 LineEditElements->setFocus();
428 if (CheckBoxMesh->isChecked())
431 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
433 QApplication::instance()->processEvents();
438 //=================================================================================
439 // function : ClickOnApply()
441 //=================================================================================
442 bool SMESHGUI_SymmetryDlg::ClickOnApply()
444 if (mySMESHGUI->isActiveStudyLocked())
450 if (myNbOkElements && IsMirrorOk()) {
451 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
453 SMESH::long_array_var anElementsId = new SMESH::long_array;
455 anElementsId->length(aListElementsId.count());
456 for (int i = 0; i < aListElementsId.count(); i++)
457 anElementsId[i] = aListElementsId[i].toInt();
459 SMESH::AxisStruct aMirror;
461 aMirror.x = SpinBox_X->GetValue();
462 aMirror.y = SpinBox_Y->GetValue();
463 aMirror.z = SpinBox_Z->GetValue();
464 if (GetConstructorId() == 0) {
465 aMirror.vx = aMirror.vy = aMirror.vz = 0;
467 aMirror.vx = SpinBox_DX->GetValue();
468 aMirror.vy = SpinBox_DY->GetValue();
469 aMirror.vz = SpinBox_DZ->GetValue();
472 QStringList aParameters;
473 aParameters << SpinBox_X->text();
474 aParameters << SpinBox_Y->text();
475 aParameters << SpinBox_Z->text();
476 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DX->text() );
477 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DY->text() );
478 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DZ->text() );
480 SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
482 if (GetConstructorId() == 0)
483 aMirrorType = SMESH::SMESH_MeshEditor::POINT;
484 if (GetConstructorId() == 1)
485 aMirrorType = SMESH::SMESH_MeshEditor::AXIS;
486 if (GetConstructorId() == 2)
487 aMirrorType = SMESH::SMESH_MeshEditor::PLANE;
489 int actionButton = ActionGroup->checkedId();
490 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
493 SUIT_OverrideCursor aWaitCursor;
494 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
496 switch ( actionButton ) {
497 case MOVE_ELEMS_BUTTON: {
498 if(CheckBoxMesh->isChecked())
499 aMeshEditor->MirrorObject(mySelectedObject, aMirror, aMirrorType, false );
501 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, false );
503 if( !myMesh->_is_nil())
504 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
507 case COPY_ELEMS_BUTTON: {
508 SMESH::ListOfGroups_var groups;
510 if(CheckBoxMesh->isChecked())
511 groups = aMeshEditor->MirrorObjectMakeGroups(mySelectedObject, aMirror, aMirrorType);
513 groups = aMeshEditor->MirrorMakeGroups(anElementsId, aMirror, aMirrorType);
516 if(CheckBoxMesh->isChecked())
517 aMeshEditor->MirrorObject(mySelectedObject, aMirror, aMirrorType, true);
519 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, true);
521 if( !myMesh->_is_nil())
522 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
525 case MAKE_MESH_BUTTON: {
526 SMESH::SMESH_Mesh_var mesh;
527 if(CheckBoxMesh->isChecked())
528 mesh = aMeshEditor->MirrorObjectMakeMesh(mySelectedObject, aMirror, aMirrorType, makeGroups,
529 LineEditNewMesh->text().toLatin1().data());
531 mesh = aMeshEditor->MirrorMakeMesh(anElementsId, aMirror, aMirrorType, makeGroups,
532 LineEditNewMesh->text().toLatin1().data());
533 if( !mesh->_is_nil())
534 mesh->SetParameters( aParameters.join(":").toLatin1().constData() );
542 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
543 actionButton == MAKE_MESH_BUTTON )
544 mySMESHGUI->updateObjBrowser(true); // new groups may appear
546 ConstructorsClicked(GetConstructorId());
547 mySelectedObject = SMESH::SMESH_IDSource::_nil();
548 SelectionIntoArgument();
553 //=================================================================================
554 // function : ClickOnOk()
556 //=================================================================================
557 void SMESHGUI_SymmetryDlg::ClickOnOk()
563 //=================================================================================
564 // function : ClickOnCancel()
566 //=================================================================================
567 void SMESHGUI_SymmetryDlg::ClickOnCancel()
569 disconnect(mySelectionMgr, 0, this, 0);
570 mySelectionMgr->clearFilters();
571 //mySelectionMgr->clearSelected();
572 if (SMESH::GetCurrentVtkView()) {
573 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
574 SMESH::SetPointRepresentation(false);
576 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
577 aViewWindow->SetSelectionMode(ActorSelection);
578 mySMESHGUI->ResetState();
582 //=================================================================================
583 // function : ClickOnHelp()
585 //=================================================================================
586 void SMESHGUI_SymmetryDlg::ClickOnHelp()
588 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
590 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
594 platform = "winapplication";
596 platform = "application";
598 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
599 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
600 arg(app->resourceMgr()->stringValue("ExternalBrowser",
602 arg(myHelpFileName));
606 //=======================================================================
607 // function : onTextChange()
609 //=======================================================================
610 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
612 QLineEdit* send = (QLineEdit*)sender();
617 if (send == LineEditElements)
620 buttonOk->setEnabled(false);
621 buttonApply->setEnabled(false);
623 // hilight entered elements
624 SMDS_Mesh* aMesh = 0;
626 aMesh = myActor->GetObject()->GetMesh();
629 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
631 TColStd_MapOfInteger newIndices;
633 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
635 if (send == LineEditElements) {
636 for (int i = 0; i < aListId.count(); i++) {
637 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
639 newIndices.Add(e->GetID());
643 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
644 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
645 aViewWindow->highlight( anIO, true, true );
647 myElementsId = theNewText;
651 if (myNbOkElements && IsMirrorOk()) {
652 buttonOk->setEnabled(true);
653 buttonApply->setEnabled(true);
659 //=================================================================================
660 // function : SelectionIntoArgument()
661 // purpose : Called when selection as changed or other case
662 //=================================================================================
663 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
669 QString aString = "";
672 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
673 LineEditElements->setText(aString);
675 buttonOk->setEnabled(false);
676 buttonApply->setEnabled(false);
680 if (!GroupButtons->isEnabled()) // inactive
685 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
687 int nbSel = aList.Extent();
691 Handle(SALOME_InteractiveObject) IO = aList.First();
692 myMesh = SMESH::GetMeshByIO(IO);
693 if(myMesh->_is_nil())
696 myActor = SMESH::FindActorByObject(myMesh);
698 myActor = SMESH::FindActorByEntry(IO->getEntry());
699 if (!myActor && !CheckBoxMesh->isChecked())
704 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
707 // MakeGroups is available if there are groups and "Copy"
708 if ( myMesh->NbGroups() == 0 ) {
709 MakeGroupsCheck->setChecked(false);
710 MakeGroupsCheck->setEnabled(false);
712 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
713 MakeGroupsCheck->setEnabled(true);
715 if (CheckBoxMesh->isChecked()) {
716 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
718 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH
719 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
725 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
729 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
730 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
732 myElementsId += QString(" %1").arg(i);
737 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
739 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
741 // get IDs from submesh
743 SMESH::long_array_var anElementsIds = new SMESH::long_array;
744 anElementsIds = aSubMesh->GetElementsId();
745 for (int i = 0; i < anElementsIds->length(); i++) {
746 myElementsId += QString(" %1").arg(anElementsIds[i]);
748 aNbUnits = anElementsIds->length();
752 SMESH::SMESH_GroupBase_var aGroup =
753 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
754 if (aGroup->_is_nil())
757 // get IDs from smesh group
758 SMESH::long_array_var anElementsIds = new SMESH::long_array;
759 anElementsIds = aGroup->GetListOfID();
760 for (int i = 0; i < anElementsIds->length(); i++) {
761 myElementsId += QString(" %1").arg(anElementsIds[i]);
763 aNbUnits = anElementsIds->length();
767 aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, IO, aString);
768 myElementsId = aString;
773 myNbOkElements = true;
775 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
779 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
783 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
791 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
792 SpinBox_X->SetValue(x);
793 SpinBox_Y->SetValue(y);
794 SpinBox_Z->SetValue(z);
795 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
796 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
797 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
798 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
803 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
804 LineEditElements->setText(aString);
805 LineEditElements->repaint();
806 LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
807 LineEditElements->setEnabled(true);
813 if (myNbOkElements && IsMirrorOk()) {
814 buttonOk->setEnabled(true);
815 buttonApply->setEnabled(true);
819 //=================================================================================
820 // function : SetEditCurrentArgument()
822 //=================================================================================
823 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
825 QPushButton* send = (QPushButton*)sender();
827 disconnect(mySelectionMgr, 0, this, 0);
828 mySelectionMgr->clearSelected();
829 mySelectionMgr->clearFilters();
831 if (send == SelectElementsButton) {
832 myEditCurrentArgument = (QWidget*)LineEditElements;
833 SMESH::SetPointRepresentation(false);
834 if (CheckBoxMesh->isChecked()) {
835 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
836 aViewWindow->SetSelectionMode(ActorSelection);
837 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
839 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
840 aViewWindow->SetSelectionMode(CellSelection);
842 } else if (send == SelectPointButton) {
843 myEditCurrentArgument = (QWidget*)SpinBox_X;
844 SMESH::SetPointRepresentation(true);
845 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
846 aViewWindow->SetSelectionMode(NodeSelection);
847 } else if (send == SelectVectorButton) {
848 myEditCurrentArgument = (QWidget*)SpinBox_DX;
849 SMESH::SetPointRepresentation(true);
851 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
852 aViewWindow->SetSelectionMode(NodeSelection);
856 myEditCurrentArgument->setFocus();
857 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
858 SelectionIntoArgument();
861 //=================================================================================
862 // function : DeactivateActiveDialog()
864 //=================================================================================
865 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
867 if (ConstructorsBox->isEnabled()) {
868 ConstructorsBox->setEnabled(false);
869 GroupArguments->setEnabled(false);
870 GroupButtons->setEnabled(false);
871 mySMESHGUI->ResetState();
872 mySMESHGUI->SetActiveDialogBox(0);
876 //=================================================================================
877 // function : ActivateThisDialog()
879 //=================================================================================
880 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
882 /* Emit a signal to deactivate the active dialog */
883 mySMESHGUI->EmitSignalDeactivateDialog();
884 ConstructorsBox->setEnabled(true);
885 GroupArguments->setEnabled(true);
886 GroupButtons->setEnabled(true);
888 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
890 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
891 aViewWindow->SetSelectionMode(CellSelection);
892 SelectionIntoArgument();
895 //=================================================================================
896 // function : enterEvent()
898 //=================================================================================
899 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
901 if (!ConstructorsBox->isEnabled())
902 ActivateThisDialog();
905 //=================================================================================
906 // function : closeEvent()
908 //=================================================================================
909 void SMESHGUI_SymmetryDlg::closeEvent (QCloseEvent*)
911 /* same than click on cancel button */
915 //=======================================================================
916 // function : hideEvent()
917 // purpose : caused by ESC key
918 //=======================================================================
919 void SMESHGUI_SymmetryDlg::hideEvent (QHideEvent*)
925 //=======================================================================
926 //function : onSelectMesh
928 //=======================================================================
929 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
932 TextLabelElements->setText(tr("SMESH_NAME"));
934 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
935 myFilterBtn->setEnabled(!toSelectMesh);
937 if (myEditCurrentArgument != LineEditElements) {
938 LineEditElements->clear();
942 mySelectionMgr->clearFilters();
943 SMESH::SetPointRepresentation(false);
946 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
947 aViewWindow->SetSelectionMode(ActorSelection);
948 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
949 LineEditElements->setReadOnly(true);
950 LineEditElements->setValidator(0);
952 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
953 aViewWindow->SetSelectionMode(CellSelection);
954 LineEditElements->setReadOnly(false);
955 LineEditElements->setValidator(myIdValidator);
956 onTextChange(LineEditElements->text());
959 SelectionIntoArgument();
962 //=================================================================================
963 // function : GetConstructorId()
965 //=================================================================================
966 int SMESHGUI_SymmetryDlg::GetConstructorId()
968 return GroupConstructors->checkedId();
971 //=================================================================================
972 // function : IsMirrorOk()
974 //=================================================================================
975 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
979 if (GetConstructorId() != 0)
980 isOk = (SpinBox_DX->GetValue() != 0 ||
981 SpinBox_DY->GetValue() != 0 ||
982 SpinBox_DZ->GetValue() != 0);
987 //=================================================================================
988 // function : onVectorChanged()
990 //=================================================================================
991 void SMESHGUI_SymmetryDlg::onVectorChanged()
994 buttonOk->setEnabled(true);
995 buttonApply->setEnabled(true);
997 buttonOk->setEnabled(false);
998 buttonApply->setEnabled(false);
1002 //=======================================================================
1003 //function : onActionClicked
1004 //purpose : slot called when an action type changed
1005 //=======================================================================
1007 void SMESHGUI_SymmetryDlg::onActionClicked(int button)
1010 case MOVE_ELEMS_BUTTON:
1011 MakeGroupsCheck->setEnabled(false);
1012 LineEditNewMesh->setEnabled(false);
1014 case COPY_ELEMS_BUTTON:
1015 LineEditNewMesh->setEnabled(false);
1016 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1017 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1018 MakeGroupsCheck->setEnabled(true);
1020 MakeGroupsCheck->setEnabled(false);
1022 case MAKE_MESH_BUTTON:
1023 LineEditNewMesh->setEnabled(true);
1024 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1025 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1026 MakeGroupsCheck->setEnabled(true);
1028 MakeGroupsCheck->setEnabled(false);
1034 //=======================================================================
1035 //function : setNewMeshName
1036 //purpose : update contents of LineEditNewMesh
1037 //=======================================================================
1039 void SMESHGUI_SymmetryDlg::setNewMeshName()
1041 LineEditNewMesh->setText("");
1042 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
1044 if ( CheckBoxMesh->isChecked() ) {
1045 name = LineEditElements->text();
1048 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
1049 name = meshSO->GetName().c_str();
1051 if ( !name.isEmpty() )
1052 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "mirrored"));
1056 //=================================================================================
1057 // function : keyPressEvent()
1059 //=================================================================================
1060 void SMESHGUI_SymmetryDlg::keyPressEvent( QKeyEvent* e )
1062 QDialog::keyPressEvent( e );
1063 if ( e->isAccepted() )
1066 if ( e->key() == Qt::Key_F1 ) {
1072 //=================================================================================
1073 // function : setFilters()
1074 // purpose : SLOT. Called when "Filter" button pressed.
1075 //=================================================================================
1076 void SMESHGUI_SymmetryDlg::setFilters()
1078 if(myMesh->_is_nil()) {
1079 SUIT_MessageBox::critical(this,
1081 tr("NO_MESH_SELECTED"));
1085 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1087 myFilterDlg->SetSelection();
1088 myFilterDlg->SetMesh( myMesh );
1089 myFilterDlg->SetSourceWg( LineEditElements );
1091 myFilterDlg->show();
1094 //=================================================================================
1095 // function : isValid
1097 //=================================================================================
1098 bool SMESHGUI_SymmetryDlg::isValid()
1103 ok = SpinBox_X->isValid( msg, true ) && ok;
1104 ok = SpinBox_Y->isValid( msg, true ) && ok;
1105 ok = SpinBox_Z->isValid( msg, true ) && ok;
1106 if (GetConstructorId() != 0) {
1107 ok = SpinBox_DX->isValid( msg, true ) && ok;
1108 ok = SpinBox_DY->isValid( msg, true ) && ok;
1109 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1113 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1114 if ( !msg.isEmpty() )
1116 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );