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();
550 SMESHGUI::Modified();
555 //=================================================================================
556 // function : ClickOnOk()
558 //=================================================================================
559 void SMESHGUI_SymmetryDlg::ClickOnOk()
565 //=================================================================================
566 // function : ClickOnCancel()
568 //=================================================================================
569 void SMESHGUI_SymmetryDlg::ClickOnCancel()
571 disconnect(mySelectionMgr, 0, this, 0);
572 mySelectionMgr->clearFilters();
573 //mySelectionMgr->clearSelected();
574 if (SMESH::GetCurrentVtkView()) {
575 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
576 SMESH::SetPointRepresentation(false);
578 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
579 aViewWindow->SetSelectionMode(ActorSelection);
580 mySMESHGUI->ResetState();
584 //=================================================================================
585 // function : ClickOnHelp()
587 //=================================================================================
588 void SMESHGUI_SymmetryDlg::ClickOnHelp()
590 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
592 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
596 platform = "winapplication";
598 platform = "application";
600 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
601 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
602 arg(app->resourceMgr()->stringValue("ExternalBrowser",
604 arg(myHelpFileName));
608 //=======================================================================
609 // function : onTextChange()
611 //=======================================================================
612 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
614 QLineEdit* send = (QLineEdit*)sender();
619 if (send == LineEditElements)
622 buttonOk->setEnabled(false);
623 buttonApply->setEnabled(false);
625 // hilight entered elements
626 SMDS_Mesh* aMesh = 0;
628 aMesh = myActor->GetObject()->GetMesh();
631 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
633 TColStd_MapOfInteger newIndices;
635 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
637 if (send == LineEditElements) {
638 for (int i = 0; i < aListId.count(); i++) {
639 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
641 newIndices.Add(e->GetID());
645 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
646 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
647 aViewWindow->highlight( anIO, true, true );
649 myElementsId = theNewText;
653 if (myNbOkElements && IsMirrorOk()) {
654 buttonOk->setEnabled(true);
655 buttonApply->setEnabled(true);
661 //=================================================================================
662 // function : SelectionIntoArgument()
663 // purpose : Called when selection as changed or other case
664 //=================================================================================
665 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
671 QString aString = "";
674 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
675 LineEditElements->setText(aString);
677 buttonOk->setEnabled(false);
678 buttonApply->setEnabled(false);
682 if (!GroupButtons->isEnabled()) // inactive
687 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
689 int nbSel = aList.Extent();
693 Handle(SALOME_InteractiveObject) IO = aList.First();
694 myMesh = SMESH::GetMeshByIO(IO);
695 if(myMesh->_is_nil())
698 myActor = SMESH::FindActorByObject(myMesh);
700 myActor = SMESH::FindActorByEntry(IO->getEntry());
701 if (!myActor && !CheckBoxMesh->isChecked())
706 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
709 // MakeGroups is available if there are groups and "Copy"
710 if ( myMesh->NbGroups() == 0 ) {
711 MakeGroupsCheck->setChecked(false);
712 MakeGroupsCheck->setEnabled(false);
714 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
715 MakeGroupsCheck->setEnabled(true);
717 if (CheckBoxMesh->isChecked()) {
718 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
720 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH
721 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
727 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
731 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
732 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
734 myElementsId += QString(" %1").arg(i);
739 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
741 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
743 // get IDs from submesh
745 SMESH::long_array_var anElementsIds = new SMESH::long_array;
746 anElementsIds = aSubMesh->GetElementsId();
747 for (int i = 0; i < anElementsIds->length(); i++) {
748 myElementsId += QString(" %1").arg(anElementsIds[i]);
750 aNbUnits = anElementsIds->length();
754 SMESH::SMESH_GroupBase_var aGroup =
755 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
756 if (aGroup->_is_nil())
759 // get IDs from smesh group
760 SMESH::long_array_var anElementsIds = new SMESH::long_array;
761 anElementsIds = aGroup->GetListOfID();
762 for (int i = 0; i < anElementsIds->length(); i++) {
763 myElementsId += QString(" %1").arg(anElementsIds[i]);
765 aNbUnits = anElementsIds->length();
769 aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, IO, aString);
770 myElementsId = aString;
775 myNbOkElements = true;
777 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
781 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
785 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
793 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
794 SpinBox_X->SetValue(x);
795 SpinBox_Y->SetValue(y);
796 SpinBox_Z->SetValue(z);
797 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
798 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
799 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
800 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
805 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
806 LineEditElements->setText(aString);
807 LineEditElements->repaint();
808 LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
809 LineEditElements->setEnabled(true);
815 if (myNbOkElements && IsMirrorOk()) {
816 buttonOk->setEnabled(true);
817 buttonApply->setEnabled(true);
821 //=================================================================================
822 // function : SetEditCurrentArgument()
824 //=================================================================================
825 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
827 QPushButton* send = (QPushButton*)sender();
829 disconnect(mySelectionMgr, 0, this, 0);
830 mySelectionMgr->clearSelected();
831 mySelectionMgr->clearFilters();
833 if (send == SelectElementsButton) {
834 myEditCurrentArgument = (QWidget*)LineEditElements;
835 SMESH::SetPointRepresentation(false);
836 if (CheckBoxMesh->isChecked()) {
837 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
838 aViewWindow->SetSelectionMode(ActorSelection);
839 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
841 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
842 aViewWindow->SetSelectionMode(CellSelection);
844 } else if (send == SelectPointButton) {
845 myEditCurrentArgument = (QWidget*)SpinBox_X;
846 SMESH::SetPointRepresentation(true);
847 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
848 aViewWindow->SetSelectionMode(NodeSelection);
849 } else if (send == SelectVectorButton) {
850 myEditCurrentArgument = (QWidget*)SpinBox_DX;
851 SMESH::SetPointRepresentation(true);
853 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
854 aViewWindow->SetSelectionMode(NodeSelection);
858 myEditCurrentArgument->setFocus();
859 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
860 SelectionIntoArgument();
863 //=================================================================================
864 // function : DeactivateActiveDialog()
866 //=================================================================================
867 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
869 if (ConstructorsBox->isEnabled()) {
870 ConstructorsBox->setEnabled(false);
871 GroupArguments->setEnabled(false);
872 GroupButtons->setEnabled(false);
873 mySMESHGUI->ResetState();
874 mySMESHGUI->SetActiveDialogBox(0);
878 //=================================================================================
879 // function : ActivateThisDialog()
881 //=================================================================================
882 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
884 /* Emit a signal to deactivate the active dialog */
885 mySMESHGUI->EmitSignalDeactivateDialog();
886 ConstructorsBox->setEnabled(true);
887 GroupArguments->setEnabled(true);
888 GroupButtons->setEnabled(true);
890 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
892 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
893 aViewWindow->SetSelectionMode(CellSelection);
894 SelectionIntoArgument();
897 //=================================================================================
898 // function : enterEvent()
900 //=================================================================================
901 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
903 if (!ConstructorsBox->isEnabled())
904 ActivateThisDialog();
907 //=================================================================================
908 // function : closeEvent()
910 //=================================================================================
911 void SMESHGUI_SymmetryDlg::closeEvent (QCloseEvent*)
913 /* same than click on cancel button */
917 //=======================================================================
918 // function : hideEvent()
919 // purpose : caused by ESC key
920 //=======================================================================
921 void SMESHGUI_SymmetryDlg::hideEvent (QHideEvent*)
927 //=======================================================================
928 //function : onSelectMesh
930 //=======================================================================
931 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
934 TextLabelElements->setText(tr("SMESH_NAME"));
936 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
937 myFilterBtn->setEnabled(!toSelectMesh);
939 if (myEditCurrentArgument != LineEditElements) {
940 LineEditElements->clear();
944 mySelectionMgr->clearFilters();
945 SMESH::SetPointRepresentation(false);
948 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
949 aViewWindow->SetSelectionMode(ActorSelection);
950 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
951 LineEditElements->setReadOnly(true);
952 LineEditElements->setValidator(0);
954 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
955 aViewWindow->SetSelectionMode(CellSelection);
956 LineEditElements->setReadOnly(false);
957 LineEditElements->setValidator(myIdValidator);
958 onTextChange(LineEditElements->text());
961 SelectionIntoArgument();
964 //=================================================================================
965 // function : GetConstructorId()
967 //=================================================================================
968 int SMESHGUI_SymmetryDlg::GetConstructorId()
970 return GroupConstructors->checkedId();
973 //=================================================================================
974 // function : IsMirrorOk()
976 //=================================================================================
977 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
981 if (GetConstructorId() != 0)
982 isOk = (SpinBox_DX->GetValue() != 0 ||
983 SpinBox_DY->GetValue() != 0 ||
984 SpinBox_DZ->GetValue() != 0);
989 //=================================================================================
990 // function : onVectorChanged()
992 //=================================================================================
993 void SMESHGUI_SymmetryDlg::onVectorChanged()
996 buttonOk->setEnabled(true);
997 buttonApply->setEnabled(true);
999 buttonOk->setEnabled(false);
1000 buttonApply->setEnabled(false);
1004 //=======================================================================
1005 //function : onActionClicked
1006 //purpose : slot called when an action type changed
1007 //=======================================================================
1009 void SMESHGUI_SymmetryDlg::onActionClicked(int button)
1012 case MOVE_ELEMS_BUTTON:
1013 MakeGroupsCheck->setEnabled(false);
1014 LineEditNewMesh->setEnabled(false);
1016 case COPY_ELEMS_BUTTON:
1017 LineEditNewMesh->setEnabled(false);
1018 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1019 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1020 MakeGroupsCheck->setEnabled(true);
1022 MakeGroupsCheck->setEnabled(false);
1024 case MAKE_MESH_BUTTON:
1025 LineEditNewMesh->setEnabled(true);
1026 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1027 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1028 MakeGroupsCheck->setEnabled(true);
1030 MakeGroupsCheck->setEnabled(false);
1036 //=======================================================================
1037 //function : setNewMeshName
1038 //purpose : update contents of LineEditNewMesh
1039 //=======================================================================
1041 void SMESHGUI_SymmetryDlg::setNewMeshName()
1043 LineEditNewMesh->setText("");
1044 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
1046 if ( CheckBoxMesh->isChecked() ) {
1047 name = LineEditElements->text();
1050 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
1051 name = meshSO->GetName().c_str();
1053 if ( !name.isEmpty() )
1054 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "mirrored"));
1058 //=================================================================================
1059 // function : keyPressEvent()
1061 //=================================================================================
1062 void SMESHGUI_SymmetryDlg::keyPressEvent( QKeyEvent* e )
1064 QDialog::keyPressEvent( e );
1065 if ( e->isAccepted() )
1068 if ( e->key() == Qt::Key_F1 ) {
1074 //=================================================================================
1075 // function : setFilters()
1076 // purpose : SLOT. Called when "Filter" button pressed.
1077 //=================================================================================
1078 void SMESHGUI_SymmetryDlg::setFilters()
1080 if(myMesh->_is_nil()) {
1081 SUIT_MessageBox::critical(this,
1083 tr("NO_MESH_SELECTED"));
1087 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1089 myFilterDlg->SetSelection();
1090 myFilterDlg->SetMesh( myMesh );
1091 myFilterDlg->SetSourceWg( LineEditElements );
1093 myFilterDlg->show();
1096 //=================================================================================
1097 // function : isValid
1099 //=================================================================================
1100 bool SMESHGUI_SymmetryDlg::isValid()
1105 ok = SpinBox_X->isValid( msg, true ) && ok;
1106 ok = SpinBox_Y->isValid( msg, true ) && ok;
1107 ok = SpinBox_Z->isValid( msg, true ) && ok;
1108 if (GetConstructorId() != 0) {
1109 ok = SpinBox_DX->isValid( msg, true ) && ok;
1110 ok = SpinBox_DY->isValid( msg, true ) && ok;
1111 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1115 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1116 if ( !msg.isEmpty() )
1118 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );