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, Open CASCADE S.A.S.
27 #include "SMESHGUI_SymmetryDlg.h"
30 #include "SMESHGUI_SpinBox.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_IdValidator.h"
35 #include "SMESHGUI_FilterDlg.h"
37 #include <SMESH_Actor.h>
38 #include <SMESH_TypeFilter.hxx>
39 #include <SMESH_LogicalFilter.hxx>
40 #include <SMDS_Mesh.hxx>
42 // SALOME GUI includes
43 #include <SUIT_Desktop.h>
44 #include <SUIT_ResourceMgr.h>
45 #include <SUIT_Session.h>
46 #include <SUIT_MessageBox.h>
47 #include <SUIT_OverrideCursor.h>
49 #include <LightApp_Application.h>
50 #include <LightApp_SelectionMgr.h>
52 #include <SVTK_ViewModel.h>
53 #include <SVTK_ViewWindow.h>
54 #include <SALOME_ListIO.hxx>
56 // SALOME KERNEL includes
57 #include <SALOMEDSClient_SObject.hxx>
60 #include <TColStd_MapOfInteger.hxx>
63 #include <QApplication>
64 #include <QButtonGroup>
68 #include <QPushButton>
69 #include <QRadioButton>
71 #include <QHBoxLayout>
72 #include <QVBoxLayout>
73 #include <QGridLayout>
77 #include <SALOMEconfig.h>
78 #include CORBA_SERVER_HEADER(SMESH_Group)
79 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
81 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
86 //=================================================================================
87 // class : SMESHGUI_SymmetryDlg()
89 //=================================================================================
91 SMESHGUI_SymmetryDlg::SMESHGUI_SymmetryDlg( SMESHGUI* theModule )
92 : QDialog( SMESH::GetDesktop( theModule ) ),
93 mySMESHGUI( theModule ),
94 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
96 mySelectedObject(SMESH::SMESH_IDSource::_nil())
98 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_POINT")));
99 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_AXIS")));
100 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_PLANE")));
101 QPixmap image3 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
104 setAttribute(Qt::WA_DeleteOnClose, true);
105 setWindowTitle(tr("SMESH_SYMMETRY"));
106 setSizeGripEnabled(true);
108 QVBoxLayout* SMESHGUI_SymmetryDlgLayout = new QVBoxLayout(this);
109 SMESHGUI_SymmetryDlgLayout->setSpacing(SPACING);
110 SMESHGUI_SymmetryDlgLayout->setMargin(MARGIN);
112 /***************************************************************/
113 ConstructorsBox = new QGroupBox(tr("SMESH_SYMMETRY"), this);
114 GroupConstructors = new QButtonGroup(this);
115 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
116 ConstructorsBoxLayout->setSpacing(SPACING);
117 ConstructorsBoxLayout->setMargin(MARGIN);
119 RadioButton1 = new QRadioButton(ConstructorsBox);
120 RadioButton1->setIcon(image0);
121 RadioButton2 = new QRadioButton(ConstructorsBox);
122 RadioButton2->setIcon(image1);
123 RadioButton3 = new QRadioButton(ConstructorsBox);
124 RadioButton3->setIcon(image2);
126 ConstructorsBoxLayout->addWidget(RadioButton1);
127 ConstructorsBoxLayout->addWidget(RadioButton2);
128 ConstructorsBoxLayout->addWidget(RadioButton3);
129 GroupConstructors->addButton(RadioButton1, 0);
130 GroupConstructors->addButton(RadioButton2, 1);
131 GroupConstructors->addButton(RadioButton3, 2);
133 /***************************************************************/
134 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
135 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
136 GroupArgumentsLayout->setSpacing(SPACING);
137 GroupArgumentsLayout->setMargin(MARGIN);
139 myIdValidator = new SMESHGUI_IdValidator(this);
141 // Controls for elements selection
142 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
143 SelectElementsButton = new QPushButton(GroupArguments);
144 SelectElementsButton->setIcon(image3);
145 LineEditElements = new QLineEdit(GroupArguments);
146 LineEditElements->setValidator(myIdValidator);
147 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
148 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
150 // Control for the whole mesh selection
151 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
153 // Controls for mirror selection
154 GroupMirror = new QGroupBox(GroupArguments);
155 QGridLayout* GroupMirrorLayout = new QGridLayout(GroupMirror);
156 GroupMirrorLayout->setSpacing(SPACING);
157 GroupMirrorLayout->setMargin(MARGIN);
159 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupMirror);
160 SelectPointButton = new QPushButton(GroupMirror);
161 SelectPointButton->setIcon(image3);
163 TextLabelX = new QLabel(tr("SMESH_X"), GroupMirror);
164 SpinBox_X = new SMESHGUI_SpinBox(GroupMirror);
165 TextLabelY = new QLabel(tr("SMESH_Y"), GroupMirror);
166 SpinBox_Y = new SMESHGUI_SpinBox(GroupMirror);
167 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupMirror);
168 SpinBox_Z = new SMESHGUI_SpinBox(GroupMirror);
170 TextLabelVector = new QLabel(GroupMirror);
171 SelectVectorButton = new QPushButton(GroupMirror);
172 SelectVectorButton->setIcon(image3);
174 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupMirror);
175 SpinBox_DX = new SMESHGUI_SpinBox(GroupMirror);
176 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupMirror);
177 SpinBox_DY = new SMESHGUI_SpinBox(GroupMirror);
178 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupMirror);
179 SpinBox_DZ = new SMESHGUI_SpinBox(GroupMirror);
181 GroupMirrorLayout->addWidget(TextLabelPoint, 0, 0);
182 GroupMirrorLayout->addWidget(SelectPointButton, 0, 1);
183 GroupMirrorLayout->addWidget(TextLabelX, 0, 2);
184 GroupMirrorLayout->addWidget(SpinBox_X, 0, 3);
185 GroupMirrorLayout->addWidget(TextLabelY, 0, 4);
186 GroupMirrorLayout->addWidget(SpinBox_Y, 0, 5);
187 GroupMirrorLayout->addWidget(TextLabelZ, 0, 6);
188 GroupMirrorLayout->addWidget(SpinBox_Z, 0, 7);
189 GroupMirrorLayout->addWidget(TextLabelVector, 1, 0);
190 GroupMirrorLayout->addWidget(SelectVectorButton, 1, 1);
191 GroupMirrorLayout->addWidget(TextLabelDX, 1, 2);
192 GroupMirrorLayout->addWidget(SpinBox_DX, 1, 3);
193 GroupMirrorLayout->addWidget(TextLabelDY, 1, 4);
194 GroupMirrorLayout->addWidget(SpinBox_DY, 1, 5);
195 GroupMirrorLayout->addWidget(TextLabelDZ, 1, 6);
196 GroupMirrorLayout->addWidget(SpinBox_DZ, 1, 7);
198 // switch of action type
199 ActionBox = new QGroupBox(GroupArguments);
200 ActionGroup = new QButtonGroup(GroupArguments);
201 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
202 ActionBoxLayout->addSpacing(SPACING);
203 ActionBoxLayout->setMargin(MARGIN);
205 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
206 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
207 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
209 ActionBoxLayout->addWidget(aMoveElements);
210 ActionBoxLayout->addWidget(aCopyElements);
211 ActionBoxLayout->addWidget(aCreateMesh);
212 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
213 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
214 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
216 // CheckBox for groups generation
217 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
218 MakeGroupsCheck->setChecked(false);
220 // Name of a mesh to create
221 LineEditNewMesh = new QLineEdit(GroupArguments);
224 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
225 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
226 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 1);
227 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 3);
228 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
229 GroupArgumentsLayout->addWidget(GroupMirror, 2, 0, 1, 4);
230 GroupArgumentsLayout->addWidget(ActionBox, 3, 0, 3, 3);
231 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 4, 3);
232 GroupArgumentsLayout->addWidget(LineEditNewMesh, 5, 3);
234 /***************************************************************/
235 GroupButtons = new QGroupBox(this);
236 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
237 GroupButtonsLayout->setSpacing(SPACING);
238 GroupButtonsLayout->setMargin(MARGIN);
240 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
241 buttonOk->setAutoDefault(true);
242 buttonOk->setDefault(true);
243 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
244 buttonApply->setAutoDefault(true);
245 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
246 buttonCancel->setAutoDefault(true);
247 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
248 buttonHelp->setAutoDefault(true);
250 GroupButtonsLayout->addWidget(buttonOk);
251 GroupButtonsLayout->addSpacing(10);
252 GroupButtonsLayout->addWidget(buttonApply);
253 GroupButtonsLayout->addSpacing(10);
254 GroupButtonsLayout->addStretch();
255 GroupButtonsLayout->addWidget(buttonCancel);
256 GroupButtonsLayout->addWidget(buttonHelp);
258 /***************************************************************/
259 SMESHGUI_SymmetryDlgLayout->addWidget(ConstructorsBox);
260 SMESHGUI_SymmetryDlgLayout->addWidget(GroupArguments);
261 SMESHGUI_SymmetryDlgLayout->addWidget(GroupButtons);
263 /* Initialisations */
264 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
265 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
266 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
267 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
268 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
269 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
271 RadioButton1->setChecked(true);
273 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
275 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
277 // Costruction of the logical filter
278 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
279 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
281 QList<SUIT_SelectionFilter*> aListOfFilters;
282 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
283 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
285 myMeshOrSubMeshOrGroupFilter =
286 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
288 myHelpFileName = "symmetry_page.html";
292 /* signals and slots connections */
293 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
294 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
295 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
296 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
297 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
299 connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
300 connect(SelectPointButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
301 connect(SelectVectorButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
303 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
304 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
305 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
307 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
308 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
309 /* to close dialog if study change */
310 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
311 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
312 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
313 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
315 ConstructorsClicked(0);
316 SelectionIntoArgument();
317 onActionClicked(MOVE_ELEMS_BUTTON);
320 //=================================================================================
321 // function : ~SMESHGUI_SymmetryDlg()
322 // purpose : Destroys the object and frees any allocated resources
323 //=================================================================================
324 SMESHGUI_SymmetryDlg::~SMESHGUI_SymmetryDlg()
326 if ( myFilterDlg != 0 ) {
327 myFilterDlg->setParent( 0 );
332 //=================================================================================
335 //=================================================================================
336 void SMESHGUI_SymmetryDlg::Init (bool ResetControls)
340 myEditCurrentArgument = 0;
341 LineEditElements->clear();
345 buttonOk->setEnabled(false);
346 buttonApply->setEnabled(false);
349 myMesh = SMESH::SMESH_Mesh::_nil();
352 SpinBox_X->SetValue(0.0);
353 SpinBox_Y->SetValue(0.0);
354 SpinBox_Z->SetValue(0.0);
355 SpinBox_DX->SetValue(0.0);
356 SpinBox_DY->SetValue(0.0);
357 SpinBox_DZ->SetValue(0.0);
359 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
360 CheckBoxMesh->setChecked(false);
361 // MakeGroupsCheck->setChecked(false);
362 // MakeGroupsCheck->setEnabled(false);
367 //=================================================================================
368 // function : ConstructorsClicked()
369 // purpose : Radio button management
370 //=================================================================================
371 void SMESHGUI_SymmetryDlg::ConstructorsClicked (int constructorId)
373 disconnect(mySelectionMgr, 0, this, 0);
375 if (constructorId != 0 && !TextLabelVector->isVisible()) {
376 TextLabelVector->show();
377 SelectVectorButton->show();
386 switch (constructorId) {
389 GroupMirror->setTitle(tr("SMESH_POINT"));
391 TextLabelVector->hide();
392 SelectVectorButton->hide();
403 GroupMirror->setTitle(tr("SMESH_AXIS"));
404 TextLabelVector->setText(tr("SMESH_VECTOR"));
409 GroupMirror->setTitle(tr("SMESH_PLANE"));
410 TextLabelVector->setText(tr("SMESH_NORMAL"));
415 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
416 SMESH::SetPointRepresentation(false);
417 if (!CheckBoxMesh->isChecked())
419 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
420 aViewWindow->SetSelectionMode(CellSelection);
424 myEditCurrentArgument = (QWidget*)LineEditElements;
425 LineEditElements->setFocus();
427 if (CheckBoxMesh->isChecked())
430 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
432 QApplication::instance()->processEvents();
437 //=================================================================================
438 // function : ClickOnApply()
440 //=================================================================================
441 bool SMESHGUI_SymmetryDlg::ClickOnApply()
443 if (mySMESHGUI->isActiveStudyLocked())
449 if (myNbOkElements && IsMirrorOk()) {
450 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
452 SMESH::long_array_var anElementsId = new SMESH::long_array;
454 anElementsId->length(aListElementsId.count());
455 for (int i = 0; i < aListElementsId.count(); i++)
456 anElementsId[i] = aListElementsId[i].toInt();
458 SMESH::AxisStruct aMirror;
460 aMirror.x = SpinBox_X->GetValue();
461 aMirror.y = SpinBox_Y->GetValue();
462 aMirror.z = SpinBox_Z->GetValue();
463 if (GetConstructorId() == 0) {
464 aMirror.vx = aMirror.vy = aMirror.vz = 0;
466 aMirror.vx = SpinBox_DX->GetValue();
467 aMirror.vy = SpinBox_DY->GetValue();
468 aMirror.vz = SpinBox_DZ->GetValue();
471 QStringList aParameters;
472 aParameters << SpinBox_X->text();
473 aParameters << SpinBox_Y->text();
474 aParameters << SpinBox_Z->text();
475 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DX->text() );
476 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DY->text() );
477 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DZ->text() );
479 SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
481 if (GetConstructorId() == 0)
482 aMirrorType = SMESH::SMESH_MeshEditor::POINT;
483 if (GetConstructorId() == 1)
484 aMirrorType = SMESH::SMESH_MeshEditor::AXIS;
485 if (GetConstructorId() == 2)
486 aMirrorType = SMESH::SMESH_MeshEditor::PLANE;
488 int actionButton = ActionGroup->checkedId();
489 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
492 SUIT_OverrideCursor aWaitCursor;
493 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
495 switch ( actionButton ) {
496 case MOVE_ELEMS_BUTTON: {
497 if(CheckBoxMesh->isChecked())
498 aMeshEditor->MirrorObject(mySelectedObject, aMirror, aMirrorType, false );
500 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, false );
502 if( !myMesh->_is_nil())
503 myMesh->SetParameters(SMESHGUI::JoinObjectParameters(aParameters));
506 case COPY_ELEMS_BUTTON: {
507 SMESH::ListOfGroups_var groups;
509 if(CheckBoxMesh->isChecked())
510 groups = aMeshEditor->MirrorObjectMakeGroups(mySelectedObject, aMirror, aMirrorType);
512 groups = aMeshEditor->MirrorMakeGroups(anElementsId, aMirror, aMirrorType);
515 if(CheckBoxMesh->isChecked())
516 aMeshEditor->MirrorObject(mySelectedObject, aMirror, aMirrorType, true);
518 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, true);
520 if( !myMesh->_is_nil())
521 myMesh->SetParameters(SMESHGUI::JoinObjectParameters(aParameters));
524 case MAKE_MESH_BUTTON: {
525 SMESH::SMESH_Mesh_var mesh;
526 if(CheckBoxMesh->isChecked())
527 mesh = aMeshEditor->MirrorObjectMakeMesh(mySelectedObject, aMirror, aMirrorType, makeGroups,
528 LineEditNewMesh->text().toLatin1().data());
530 mesh = aMeshEditor->MirrorMakeMesh(anElementsId, aMirror, aMirrorType, makeGroups,
531 LineEditNewMesh->text().toLatin1().data());
532 if( !mesh->_is_nil())
533 mesh->SetParameters(SMESHGUI::JoinObjectParameters(aParameters));
541 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
542 actionButton == MAKE_MESH_BUTTON )
543 mySMESHGUI->updateObjBrowser(true); // new groups may appear
545 ConstructorsClicked(GetConstructorId());
546 mySelectedObject = SMESH::SMESH_IDSource::_nil();
547 SelectionIntoArgument();
552 //=================================================================================
553 // function : ClickOnOk()
555 //=================================================================================
556 void SMESHGUI_SymmetryDlg::ClickOnOk()
562 //=================================================================================
563 // function : ClickOnCancel()
565 //=================================================================================
566 void SMESHGUI_SymmetryDlg::ClickOnCancel()
568 disconnect(mySelectionMgr, 0, this, 0);
569 mySelectionMgr->clearFilters();
570 //mySelectionMgr->clearSelected();
571 if (SMESH::GetCurrentVtkView()) {
572 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
573 SMESH::SetPointRepresentation(false);
575 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
576 aViewWindow->SetSelectionMode(ActorSelection);
577 mySMESHGUI->ResetState();
581 //=================================================================================
582 // function : ClickOnHelp()
584 //=================================================================================
585 void SMESHGUI_SymmetryDlg::ClickOnHelp()
587 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
589 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
593 platform = "winapplication";
595 platform = "application";
597 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
598 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
599 arg(app->resourceMgr()->stringValue("ExternalBrowser",
601 arg(myHelpFileName));
605 //=======================================================================
606 // function : onTextChange()
608 //=======================================================================
609 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
611 QLineEdit* send = (QLineEdit*)sender();
616 if (send == LineEditElements)
619 buttonOk->setEnabled(false);
620 buttonApply->setEnabled(false);
622 // hilight entered elements
623 SMDS_Mesh* aMesh = 0;
625 aMesh = myActor->GetObject()->GetMesh();
628 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
630 TColStd_MapOfInteger newIndices;
632 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
634 if (send == LineEditElements) {
635 for (int i = 0; i < aListId.count(); i++) {
636 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
638 newIndices.Add(e->GetID());
642 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
643 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
644 aViewWindow->highlight( anIO, true, true );
646 myElementsId = theNewText;
650 if (myNbOkElements && IsMirrorOk()) {
651 buttonOk->setEnabled(true);
652 buttonApply->setEnabled(true);
658 //=================================================================================
659 // function : SelectionIntoArgument()
660 // purpose : Called when selection as changed or other case
661 //=================================================================================
662 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
668 QString aString = "";
671 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
672 LineEditElements->setText(aString);
674 buttonOk->setEnabled(false);
675 buttonApply->setEnabled(false);
679 if (!GroupButtons->isEnabled()) // inactive
684 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
686 int nbSel = aList.Extent();
690 Handle(SALOME_InteractiveObject) IO = aList.First();
691 myMesh = SMESH::GetMeshByIO(IO);
692 if(myMesh->_is_nil())
695 myActor = SMESH::FindActorByObject(myMesh);
697 myActor = SMESH::FindActorByEntry(IO->getEntry());
703 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
706 // MakeGroups is available if there are groups and "Copy"
707 if ( myMesh->NbGroups() == 0 ) {
708 MakeGroupsCheck->setChecked(false);
709 MakeGroupsCheck->setEnabled(false);
711 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
712 MakeGroupsCheck->setEnabled(true);
714 if (CheckBoxMesh->isChecked()) {
715 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
717 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH
718 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
724 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
728 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
729 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
731 myElementsId += QString(" %1").arg(i);
736 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
738 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
740 // get IDs from submesh
742 SMESH::long_array_var anElementsIds = new SMESH::long_array;
743 anElementsIds = aSubMesh->GetElementsId();
744 for (int i = 0; i < anElementsIds->length(); i++) {
745 myElementsId += QString(" %1").arg(anElementsIds[i]);
747 aNbUnits = anElementsIds->length();
751 SMESH::SMESH_GroupBase_var aGroup =
752 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
753 if (aGroup->_is_nil())
756 // get IDs from smesh group
757 SMESH::long_array_var anElementsIds = new SMESH::long_array;
758 anElementsIds = aGroup->GetListOfID();
759 for (int i = 0; i < anElementsIds->length(); i++) {
760 myElementsId += QString(" %1").arg(anElementsIds[i]);
762 aNbUnits = anElementsIds->length();
766 aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, IO, aString);
767 myElementsId = aString;
772 myNbOkElements = true;
774 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
778 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
782 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
790 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
791 SpinBox_X->SetValue(x);
792 SpinBox_Y->SetValue(y);
793 SpinBox_Z->SetValue(z);
794 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
795 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
796 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
797 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
802 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
803 LineEditElements->setText(aString);
804 LineEditElements->repaint();
805 LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
806 LineEditElements->setEnabled(true);
812 if (myNbOkElements && IsMirrorOk()) {
813 buttonOk->setEnabled(true);
814 buttonApply->setEnabled(true);
818 //=================================================================================
819 // function : SetEditCurrentArgument()
821 //=================================================================================
822 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
824 QPushButton* send = (QPushButton*)sender();
826 disconnect(mySelectionMgr, 0, this, 0);
827 mySelectionMgr->clearSelected();
828 mySelectionMgr->clearFilters();
830 if (send == SelectElementsButton) {
831 myEditCurrentArgument = (QWidget*)LineEditElements;
832 SMESH::SetPointRepresentation(false);
833 if (CheckBoxMesh->isChecked()) {
834 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
835 aViewWindow->SetSelectionMode(ActorSelection);
836 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
838 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
839 aViewWindow->SetSelectionMode(CellSelection);
841 } else if (send == SelectPointButton) {
842 myEditCurrentArgument = (QWidget*)SpinBox_X;
843 SMESH::SetPointRepresentation(true);
844 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
845 aViewWindow->SetSelectionMode(NodeSelection);
846 } else if (send == SelectVectorButton) {
847 myEditCurrentArgument = (QWidget*)SpinBox_DX;
848 SMESH::SetPointRepresentation(true);
850 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
851 aViewWindow->SetSelectionMode(NodeSelection);
855 myEditCurrentArgument->setFocus();
856 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
857 SelectionIntoArgument();
860 //=================================================================================
861 // function : DeactivateActiveDialog()
863 //=================================================================================
864 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
866 if (ConstructorsBox->isEnabled()) {
867 ConstructorsBox->setEnabled(false);
868 GroupArguments->setEnabled(false);
869 GroupButtons->setEnabled(false);
870 mySMESHGUI->ResetState();
871 mySMESHGUI->SetActiveDialogBox(0);
875 //=================================================================================
876 // function : ActivateThisDialog()
878 //=================================================================================
879 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
881 /* Emit a signal to deactivate the active dialog */
882 mySMESHGUI->EmitSignalDeactivateDialog();
883 ConstructorsBox->setEnabled(true);
884 GroupArguments->setEnabled(true);
885 GroupButtons->setEnabled(true);
887 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
889 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
890 aViewWindow->SetSelectionMode(CellSelection);
891 SelectionIntoArgument();
894 //=================================================================================
895 // function : enterEvent()
897 //=================================================================================
898 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
900 if (!ConstructorsBox->isEnabled())
901 ActivateThisDialog();
904 //=================================================================================
905 // function : closeEvent()
907 //=================================================================================
908 void SMESHGUI_SymmetryDlg::closeEvent (QCloseEvent*)
910 /* same than click on cancel button */
914 //=======================================================================
915 // function : hideEvent()
916 // purpose : caused by ESC key
917 //=======================================================================
918 void SMESHGUI_SymmetryDlg::hideEvent (QHideEvent*)
924 //=======================================================================
925 //function : onSelectMesh
927 //=======================================================================
928 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
931 TextLabelElements->setText(tr("SMESH_NAME"));
933 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
934 myFilterBtn->setEnabled(!toSelectMesh);
936 if (myEditCurrentArgument != LineEditElements) {
937 LineEditElements->clear();
941 mySelectionMgr->clearFilters();
942 SMESH::SetPointRepresentation(false);
945 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
946 aViewWindow->SetSelectionMode(ActorSelection);
947 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
948 LineEditElements->setReadOnly(true);
949 LineEditElements->setValidator(0);
951 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
952 aViewWindow->SetSelectionMode(CellSelection);
953 LineEditElements->setReadOnly(false);
954 LineEditElements->setValidator(myIdValidator);
955 onTextChange(LineEditElements->text());
958 SelectionIntoArgument();
961 //=================================================================================
962 // function : GetConstructorId()
964 //=================================================================================
965 int SMESHGUI_SymmetryDlg::GetConstructorId()
967 return GroupConstructors->checkedId();
970 //=================================================================================
971 // function : IsMirrorOk()
973 //=================================================================================
974 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
978 if (GetConstructorId() != 0)
979 isOk = (SpinBox_DX->GetValue() != 0 ||
980 SpinBox_DY->GetValue() != 0 ||
981 SpinBox_DZ->GetValue() != 0);
986 //=================================================================================
987 // function : onVectorChanged()
989 //=================================================================================
990 void SMESHGUI_SymmetryDlg::onVectorChanged()
993 buttonOk->setEnabled(true);
994 buttonApply->setEnabled(true);
996 buttonOk->setEnabled(false);
997 buttonApply->setEnabled(false);
1001 //=======================================================================
1002 //function : onActionClicked
1003 //purpose : slot called when an action type changed
1004 //=======================================================================
1006 void SMESHGUI_SymmetryDlg::onActionClicked(int button)
1009 case MOVE_ELEMS_BUTTON:
1010 MakeGroupsCheck->setEnabled(false);
1011 LineEditNewMesh->setEnabled(false);
1013 case COPY_ELEMS_BUTTON:
1014 LineEditNewMesh->setEnabled(false);
1015 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1016 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1017 MakeGroupsCheck->setEnabled(true);
1019 MakeGroupsCheck->setEnabled(false);
1021 case MAKE_MESH_BUTTON:
1022 LineEditNewMesh->setEnabled(true);
1023 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1024 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1025 MakeGroupsCheck->setEnabled(true);
1027 MakeGroupsCheck->setEnabled(false);
1033 //=======================================================================
1034 //function : setNewMeshName
1035 //purpose : update contents of LineEditNewMesh
1036 //=======================================================================
1038 void SMESHGUI_SymmetryDlg::setNewMeshName()
1040 LineEditNewMesh->setText("");
1041 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
1043 if ( CheckBoxMesh->isChecked() ) {
1044 name = LineEditElements->text();
1047 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
1048 name = meshSO->GetName().c_str();
1050 if ( !name.isEmpty() )
1051 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "mirrored"));
1055 //=================================================================================
1056 // function : keyPressEvent()
1058 //=================================================================================
1059 void SMESHGUI_SymmetryDlg::keyPressEvent( QKeyEvent* e )
1061 QDialog::keyPressEvent( e );
1062 if ( e->isAccepted() )
1065 if ( e->key() == Qt::Key_F1 ) {
1071 //=================================================================================
1072 // function : setFilters()
1073 // purpose : SLOT. Called when "Filter" button pressed.
1074 //=================================================================================
1075 void SMESHGUI_SymmetryDlg::setFilters()
1077 if(myMesh->_is_nil()) {
1078 SUIT_MessageBox::critical(this,
1080 tr("NO_MESH_SELECTED"));
1084 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1086 myFilterDlg->SetSelection();
1087 myFilterDlg->SetMesh( myMesh );
1088 myFilterDlg->SetSourceWg( LineEditElements );
1090 myFilterDlg->show();
1093 //=================================================================================
1094 // function : isValid
1096 //=================================================================================
1097 bool SMESHGUI_SymmetryDlg::isValid()
1102 ok = SpinBox_X->isValid( msg, true ) && ok;
1103 ok = SpinBox_Y->isValid( msg, true ) && ok;
1104 ok = SpinBox_Z->isValid( msg, true ) && ok;
1105 if (GetConstructorId() != 0) {
1106 ok = SpinBox_DX->isValid( msg, true ) && ok;
1107 ok = SpinBox_DY->isValid( msg, true ) && ok;
1108 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1112 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1113 if ( !msg.isEmpty() )
1115 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );