1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 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 // File : SMESHGUI_SymmetryDlg.cxx
23 // 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"
36 #include <SMESH_Actor.h>
37 #include <SMESH_TypeFilter.hxx>
38 #include <SMESH_LogicalFilter.hxx>
39 #include <SMDS_Mesh.hxx>
41 // SALOME GUI includes
42 #include <SUIT_Desktop.h>
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_OverrideCursor.h>
48 #include <LightApp_Application.h>
49 #include <LightApp_SelectionMgr.h>
51 #include <SVTK_ViewModel.h>
52 #include <SVTK_ViewWindow.h>
53 #include <SALOME_ListIO.hxx>
55 // SALOME KERNEL includes
56 #include <SALOMEDSClient_SObject.hxx>
59 #include <TColStd_MapOfInteger.hxx>
62 #include <QApplication>
63 #include <QButtonGroup>
67 #include <QPushButton>
68 #include <QRadioButton>
70 #include <QHBoxLayout>
71 #include <QVBoxLayout>
72 #include <QGridLayout>
76 #include <SALOMEconfig.h>
77 #include CORBA_SERVER_HEADER(SMESH_Group)
78 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
80 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
85 //=================================================================================
86 // class : SMESHGUI_SymmetryDlg()
88 //=================================================================================
90 SMESHGUI_SymmetryDlg::SMESHGUI_SymmetryDlg( SMESHGUI* theModule )
91 : QDialog( SMESH::GetDesktop( theModule ) ),
92 mySMESHGUI( theModule ),
93 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
95 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_POINT")));
96 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_AXIS")));
97 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_PLANE")));
98 QPixmap image3 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
101 setAttribute(Qt::WA_DeleteOnClose, true);
102 setWindowTitle(tr("SMESH_SYMMETRY"));
103 setSizeGripEnabled(true);
105 QVBoxLayout* SMESHGUI_SymmetryDlgLayout = new QVBoxLayout(this);
106 SMESHGUI_SymmetryDlgLayout->setSpacing(SPACING);
107 SMESHGUI_SymmetryDlgLayout->setMargin(MARGIN);
109 /***************************************************************/
110 ConstructorsBox = new QGroupBox(tr("SMESH_SYMMETRY"), this);
111 GroupConstructors = new QButtonGroup(this);
112 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
113 ConstructorsBoxLayout->setSpacing(SPACING);
114 ConstructorsBoxLayout->setMargin(MARGIN);
116 RadioButton1 = new QRadioButton(ConstructorsBox);
117 RadioButton1->setIcon(image0);
118 RadioButton2 = new QRadioButton(ConstructorsBox);
119 RadioButton2->setIcon(image1);
120 RadioButton3 = new QRadioButton(ConstructorsBox);
121 RadioButton3->setIcon(image2);
123 ConstructorsBoxLayout->addWidget(RadioButton1);
124 ConstructorsBoxLayout->addWidget(RadioButton2);
125 ConstructorsBoxLayout->addWidget(RadioButton3);
126 GroupConstructors->addButton(RadioButton1, 0);
127 GroupConstructors->addButton(RadioButton2, 1);
128 GroupConstructors->addButton(RadioButton3, 2);
130 /***************************************************************/
131 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
132 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
133 GroupArgumentsLayout->setSpacing(SPACING);
134 GroupArgumentsLayout->setMargin(MARGIN);
136 myIdValidator = new SMESHGUI_IdValidator(this);
138 // Controls for elements selection
139 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
140 SelectElementsButton = new QPushButton(GroupArguments);
141 SelectElementsButton->setIcon(image3);
142 LineEditElements = new QLineEdit(GroupArguments);
143 LineEditElements->setValidator(myIdValidator);
145 // Control for the whole mesh selection
146 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
148 // Controls for mirror selection
149 GroupMirror = new QGroupBox(GroupArguments);
150 QGridLayout* GroupMirrorLayout = new QGridLayout(GroupMirror);
151 GroupMirrorLayout->setSpacing(SPACING);
152 GroupMirrorLayout->setMargin(MARGIN);
154 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupMirror);
155 SelectPointButton = new QPushButton(GroupMirror);
156 SelectPointButton->setIcon(image3);
158 TextLabelX = new QLabel(tr("SMESH_X"), GroupMirror);
159 SpinBox_X = new SMESHGUI_SpinBox(GroupMirror);
160 TextLabelY = new QLabel(tr("SMESH_Y"), GroupMirror);
161 SpinBox_Y = new SMESHGUI_SpinBox(GroupMirror);
162 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupMirror);
163 SpinBox_Z = new SMESHGUI_SpinBox(GroupMirror);
165 TextLabelVector = new QLabel(GroupMirror);
166 SelectVectorButton = new QPushButton(GroupMirror);
167 SelectVectorButton->setIcon(image3);
169 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupMirror);
170 SpinBox_DX = new SMESHGUI_SpinBox(GroupMirror);
171 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupMirror);
172 SpinBox_DY = new SMESHGUI_SpinBox(GroupMirror);
173 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupMirror);
174 SpinBox_DZ = new SMESHGUI_SpinBox(GroupMirror);
176 GroupMirrorLayout->addWidget(TextLabelPoint, 0, 0);
177 GroupMirrorLayout->addWidget(SelectPointButton, 0, 1);
178 GroupMirrorLayout->addWidget(TextLabelX, 0, 2);
179 GroupMirrorLayout->addWidget(SpinBox_X, 0, 3);
180 GroupMirrorLayout->addWidget(TextLabelY, 0, 4);
181 GroupMirrorLayout->addWidget(SpinBox_Y, 0, 5);
182 GroupMirrorLayout->addWidget(TextLabelZ, 0, 6);
183 GroupMirrorLayout->addWidget(SpinBox_Z, 0, 7);
184 GroupMirrorLayout->addWidget(TextLabelVector, 1, 0);
185 GroupMirrorLayout->addWidget(SelectVectorButton, 1, 1);
186 GroupMirrorLayout->addWidget(TextLabelDX, 1, 2);
187 GroupMirrorLayout->addWidget(SpinBox_DX, 1, 3);
188 GroupMirrorLayout->addWidget(TextLabelDY, 1, 4);
189 GroupMirrorLayout->addWidget(SpinBox_DY, 1, 5);
190 GroupMirrorLayout->addWidget(TextLabelDZ, 1, 6);
191 GroupMirrorLayout->addWidget(SpinBox_DZ, 1, 7);
193 // switch of action type
194 ActionBox = new QGroupBox(GroupArguments);
195 ActionGroup = new QButtonGroup(GroupArguments);
196 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
197 ActionBoxLayout->addSpacing(SPACING);
198 ActionBoxLayout->setMargin(MARGIN);
200 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
201 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
202 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
204 ActionBoxLayout->addWidget(aMoveElements);
205 ActionBoxLayout->addWidget(aCopyElements);
206 ActionBoxLayout->addWidget(aCreateMesh);
207 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
208 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
209 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
211 // CheckBox for groups generation
212 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
213 MakeGroupsCheck->setChecked(false);
215 // Name of a mesh to create
216 LineEditNewMesh = new QLineEdit(GroupArguments);
219 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
220 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
221 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 2);
222 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
223 GroupArgumentsLayout->addWidget(GroupMirror, 2, 0, 1, 4);
224 GroupArgumentsLayout->addWidget(ActionBox, 3, 0, 3, 3);
225 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 4, 3);
226 GroupArgumentsLayout->addWidget(LineEditNewMesh, 5, 3);
228 /***************************************************************/
229 GroupButtons = new QGroupBox(this);
230 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
231 GroupButtonsLayout->setSpacing(SPACING);
232 GroupButtonsLayout->setMargin(MARGIN);
234 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
235 buttonOk->setAutoDefault(true);
236 buttonOk->setDefault(true);
237 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
238 buttonApply->setAutoDefault(true);
239 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
240 buttonCancel->setAutoDefault(true);
241 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
242 buttonHelp->setAutoDefault(true);
244 GroupButtonsLayout->addWidget(buttonOk);
245 GroupButtonsLayout->addSpacing(10);
246 GroupButtonsLayout->addWidget(buttonApply);
247 GroupButtonsLayout->addSpacing(10);
248 GroupButtonsLayout->addStretch();
249 GroupButtonsLayout->addWidget(buttonCancel);
250 GroupButtonsLayout->addWidget(buttonHelp);
252 /***************************************************************/
253 SMESHGUI_SymmetryDlgLayout->addWidget(ConstructorsBox);
254 SMESHGUI_SymmetryDlgLayout->addWidget(GroupArguments);
255 SMESHGUI_SymmetryDlgLayout->addWidget(GroupButtons);
257 /* Initialisations */
258 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
259 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
260 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
261 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
262 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
263 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
265 RadioButton1->setChecked(true);
267 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
269 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
271 // Costruction of the logical filter
272 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
273 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
275 QList<SUIT_SelectionFilter*> aListOfFilters;
276 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
277 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
279 myMeshOrSubMeshOrGroupFilter =
280 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
282 myHelpFileName = "symmetry_page.html";
286 /* signals and slots connections */
287 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
288 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
289 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
290 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
291 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
293 connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
294 connect(SelectPointButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
295 connect(SelectVectorButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
297 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
298 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
299 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
301 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
302 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
303 /* to close dialog if study change */
304 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
305 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
306 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
307 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
309 ConstructorsClicked(0);
310 SelectionIntoArgument();
311 onActionClicked(MOVE_ELEMS_BUTTON);
314 //=================================================================================
315 // function : ~SMESHGUI_SymmetryDlg()
316 // purpose : Destroys the object and frees any allocated resources
317 //=================================================================================
318 SMESHGUI_SymmetryDlg::~SMESHGUI_SymmetryDlg()
322 //=================================================================================
325 //=================================================================================
326 void SMESHGUI_SymmetryDlg::Init (bool ResetControls)
330 myEditCurrentArgument = 0;
331 LineEditElements->clear();
335 buttonOk->setEnabled(false);
336 buttonApply->setEnabled(false);
339 myMesh = SMESH::SMESH_Mesh::_nil();
342 SpinBox_X->SetValue(0.0);
343 SpinBox_Y->SetValue(0.0);
344 SpinBox_Z->SetValue(0.0);
345 SpinBox_DX->SetValue(0.0);
346 SpinBox_DY->SetValue(0.0);
347 SpinBox_DZ->SetValue(0.0);
349 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
350 CheckBoxMesh->setChecked(false);
351 // MakeGroupsCheck->setChecked(false);
352 // MakeGroupsCheck->setEnabled(false);
357 //=================================================================================
358 // function : ConstructorsClicked()
359 // purpose : Radio button management
360 //=================================================================================
361 void SMESHGUI_SymmetryDlg::ConstructorsClicked (int constructorId)
363 disconnect(mySelectionMgr, 0, this, 0);
365 if (constructorId != 0 && !TextLabelVector->isVisible()) {
366 TextLabelVector->show();
367 SelectVectorButton->show();
376 switch (constructorId) {
379 GroupMirror->setTitle(tr("SMESH_POINT"));
381 TextLabelVector->hide();
382 SelectVectorButton->hide();
393 GroupMirror->setTitle(tr("SMESH_AXIS"));
394 TextLabelVector->setText(tr("SMESH_VECTOR"));
399 GroupMirror->setTitle(tr("SMESH_PLANE"));
400 TextLabelVector->setText(tr("SMESH_NORMAL"));
405 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
406 SMESH::SetPointRepresentation(false);
407 if (!CheckBoxMesh->isChecked())
409 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
410 aViewWindow->SetSelectionMode(CellSelection);
414 myEditCurrentArgument = (QWidget*)LineEditElements;
415 LineEditElements->setFocus();
417 if (CheckBoxMesh->isChecked())
420 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
422 QApplication::instance()->processEvents();
424 resize( minimumSize() );
427 //=================================================================================
428 // function : ClickOnApply()
430 //=================================================================================
431 bool SMESHGUI_SymmetryDlg::ClickOnApply()
433 if (mySMESHGUI->isActiveStudyLocked())
439 if (myNbOkElements && IsMirrorOk()) {
440 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
442 SMESH::long_array_var anElementsId = new SMESH::long_array;
444 anElementsId->length(aListElementsId.count());
445 for (int i = 0; i < aListElementsId.count(); i++)
446 anElementsId[i] = aListElementsId[i].toInt();
448 SMESH::AxisStruct aMirror;
450 aMirror.x = SpinBox_X->GetValue();
451 aMirror.y = SpinBox_Y->GetValue();
452 aMirror.z = SpinBox_Z->GetValue();
453 if (GetConstructorId() == 0) {
454 aMirror.vx = aMirror.vy = aMirror.vz = 0;
456 aMirror.vx = SpinBox_DX->GetValue();
457 aMirror.vy = SpinBox_DY->GetValue();
458 aMirror.vz = SpinBox_DZ->GetValue();
461 QStringList aParameters;
462 aParameters << SpinBox_X->text();
463 aParameters << SpinBox_Y->text();
464 aParameters << SpinBox_Z->text();
465 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DX->text() );
466 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DY->text() );
467 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DZ->text() );
469 SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
471 if (GetConstructorId() == 0)
472 aMirrorType = SMESH::SMESH_MeshEditor::POINT;
473 if (GetConstructorId() == 1)
474 aMirrorType = SMESH::SMESH_MeshEditor::AXIS;
475 if (GetConstructorId() == 2)
476 aMirrorType = SMESH::SMESH_MeshEditor::PLANE;
478 int actionButton = ActionGroup->checkedId();
479 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
482 SUIT_OverrideCursor aWaitCursor;
483 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
485 switch ( actionButton ) {
486 case MOVE_ELEMS_BUTTON:
487 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, false );
488 if( !myMesh->_is_nil())
489 myMesh->SetParameters(SMESHGUI::JoinObjectParameters(aParameters));
491 case COPY_ELEMS_BUTTON:
493 SMESH::ListOfGroups_var groups =
494 aMeshEditor->MirrorMakeGroups(anElementsId, aMirror, aMirrorType);
496 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, true);
497 if( !myMesh->_is_nil())
498 myMesh->SetParameters(SMESHGUI::JoinObjectParameters(aParameters));
500 case MAKE_MESH_BUTTON:
501 SMESH::SMESH_Mesh_var mesh =
502 aMeshEditor->MirrorMakeMesh(anElementsId, aMirror, aMirrorType, makeGroups,
503 LineEditNewMesh->text().toLatin1().data());
504 if( !mesh->_is_nil())
505 mesh->SetParameters(SMESHGUI::JoinObjectParameters(aParameters));
511 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
512 actionButton == MAKE_MESH_BUTTON )
513 mySMESHGUI->updateObjBrowser(true); // new groups may appear
515 ConstructorsClicked(GetConstructorId());
516 SelectionIntoArgument();
522 //=================================================================================
523 // function : ClickOnOk()
525 //=================================================================================
526 void SMESHGUI_SymmetryDlg::ClickOnOk()
532 //=================================================================================
533 // function : ClickOnCancel()
535 //=================================================================================
536 void SMESHGUI_SymmetryDlg::ClickOnCancel()
538 disconnect(mySelectionMgr, 0, this, 0);
539 mySelectionMgr->clearFilters();
540 //mySelectionMgr->clearSelected();
541 SMESH::SetPointRepresentation(false);
542 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
543 aViewWindow->SetSelectionMode(ActorSelection);
544 mySMESHGUI->ResetState();
548 //=================================================================================
549 // function : ClickOnHelp()
551 //=================================================================================
552 void SMESHGUI_SymmetryDlg::ClickOnHelp()
554 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
556 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
560 platform = "winapplication";
562 platform = "application";
564 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
565 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
566 arg(app->resourceMgr()->stringValue("ExternalBrowser",
568 arg(myHelpFileName));
572 //=======================================================================
573 // function : onTextChange()
575 //=======================================================================
576 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
578 QLineEdit* send = (QLineEdit*)sender();
583 if (send == LineEditElements)
586 buttonOk->setEnabled(false);
587 buttonApply->setEnabled(false);
589 // hilight entered elements
590 SMDS_Mesh* aMesh = 0;
592 aMesh = myActor->GetObject()->GetMesh();
595 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
597 TColStd_MapOfInteger newIndices;
599 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
601 if (send == LineEditElements) {
602 for (int i = 0; i < aListId.count(); i++) {
603 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
605 newIndices.Add(e->GetID());
609 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
610 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
611 aViewWindow->highlight( anIO, true, true );
613 myElementsId = theNewText;
617 if (myNbOkElements && IsMirrorOk()) {
618 buttonOk->setEnabled(true);
619 buttonApply->setEnabled(true);
625 //=================================================================================
626 // function : SelectionIntoArgument()
627 // purpose : Called when selection as changed or other case
628 //=================================================================================
629 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
635 QString aString = "";
638 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
639 LineEditElements->setText(aString);
641 buttonOk->setEnabled(false);
642 buttonApply->setEnabled(false);
646 if (!GroupButtons->isEnabled()) // inactive
651 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
653 int nbSel = aList.Extent();
657 Handle(SALOME_InteractiveObject) IO = aList.First();
658 myMesh = SMESH::GetMeshByIO(IO);
659 if(myMesh->_is_nil())
662 myActor = SMESH::FindActorByObject(myMesh);
664 myActor = SMESH::FindActorByEntry(IO->getEntry());
670 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
673 // MakeGroups is available if there are groups and "Copy"
674 if ( myMesh->NbGroups() == 0 ) {
675 MakeGroupsCheck->setChecked(false);
676 MakeGroupsCheck->setEnabled(false);
678 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
679 MakeGroupsCheck->setEnabled(true);
681 if (CheckBoxMesh->isChecked()) {
682 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
684 if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
686 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
690 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
691 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
693 myElementsId += QString(" %1").arg(i);
697 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
699 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
701 // get IDs from submesh
702 SMESH::long_array_var anElementsIds = new SMESH::long_array;
703 anElementsIds = aSubMesh->GetElementsId();
704 for (int i = 0; i < anElementsIds->length(); i++) {
705 myElementsId += QString(" %1").arg(anElementsIds[i]);
707 aNbUnits = anElementsIds->length();
710 SMESH::SMESH_GroupBase_var aGroup =
711 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
712 if (aGroup->_is_nil())
715 // get IDs from smesh group
716 SMESH::long_array_var anElementsIds = new SMESH::long_array;
717 anElementsIds = aGroup->GetListOfID();
718 for (int i = 0; i < anElementsIds->length(); i++) {
719 myElementsId += QString(" %1").arg(anElementsIds[i]);
721 aNbUnits = anElementsIds->length();
724 aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, IO, aString);
725 myElementsId = aString;
731 myNbOkElements = true;
733 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
737 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
741 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
749 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
750 SpinBox_X->SetValue(x);
751 SpinBox_Y->SetValue(y);
752 SpinBox_Z->SetValue(z);
753 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
754 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
755 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
756 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
761 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
762 LineEditElements->setText(aString);
768 if (myNbOkElements && IsMirrorOk()) {
769 buttonOk->setEnabled(true);
770 buttonApply->setEnabled(true);
774 //=================================================================================
775 // function : SetEditCurrentArgument()
777 //=================================================================================
778 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
780 QPushButton* send = (QPushButton*)sender();
782 disconnect(mySelectionMgr, 0, this, 0);
783 mySelectionMgr->clearSelected();
784 mySelectionMgr->clearFilters();
786 if (send == SelectElementsButton) {
787 myEditCurrentArgument = (QWidget*)LineEditElements;
788 SMESH::SetPointRepresentation(false);
789 if (CheckBoxMesh->isChecked()) {
790 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
791 aViewWindow->SetSelectionMode(ActorSelection);
792 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
794 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
795 aViewWindow->SetSelectionMode(CellSelection);
797 } else if (send == SelectPointButton) {
798 myEditCurrentArgument = (QWidget*)SpinBox_X;
799 SMESH::SetPointRepresentation(true);
800 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
801 aViewWindow->SetSelectionMode(NodeSelection);
802 } else if (send == SelectVectorButton) {
803 myEditCurrentArgument = (QWidget*)SpinBox_DX;
804 SMESH::SetPointRepresentation(true);
806 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
807 aViewWindow->SetSelectionMode(NodeSelection);
811 myEditCurrentArgument->setFocus();
812 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
813 SelectionIntoArgument();
816 //=================================================================================
817 // function : DeactivateActiveDialog()
819 //=================================================================================
820 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
822 if (ConstructorsBox->isEnabled()) {
823 ConstructorsBox->setEnabled(false);
824 GroupArguments->setEnabled(false);
825 GroupButtons->setEnabled(false);
826 mySMESHGUI->ResetState();
827 mySMESHGUI->SetActiveDialogBox(0);
831 //=================================================================================
832 // function : ActivateThisDialog()
834 //=================================================================================
835 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
837 /* Emit a signal to deactivate the active dialog */
838 mySMESHGUI->EmitSignalDeactivateDialog();
839 ConstructorsBox->setEnabled(true);
840 GroupArguments->setEnabled(true);
841 GroupButtons->setEnabled(true);
843 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
845 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
846 aViewWindow->SetSelectionMode(CellSelection);
847 SelectionIntoArgument();
850 //=================================================================================
851 // function : enterEvent()
853 //=================================================================================
854 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
856 if (!ConstructorsBox->isEnabled())
857 ActivateThisDialog();
860 //=================================================================================
861 // function : closeEvent()
863 //=================================================================================
864 void SMESHGUI_SymmetryDlg::closeEvent (QCloseEvent*)
866 /* same than click on cancel button */
870 //=======================================================================
871 // function : hideEvent()
872 // purpose : caused by ESC key
873 //=======================================================================
874 void SMESHGUI_SymmetryDlg::hideEvent (QHideEvent*)
880 //=======================================================================
881 //function : onSelectMesh
883 //=======================================================================
884 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
887 TextLabelElements->setText(tr("SMESH_NAME"));
889 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
891 if (myEditCurrentArgument != LineEditElements) {
892 LineEditElements->clear();
896 mySelectionMgr->clearFilters();
897 SMESH::SetPointRepresentation(false);
900 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
901 aViewWindow->SetSelectionMode(ActorSelection);
902 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
903 LineEditElements->setReadOnly(true);
904 LineEditElements->setValidator(0);
906 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
907 aViewWindow->SetSelectionMode(CellSelection);
908 LineEditElements->setReadOnly(false);
909 LineEditElements->setValidator(myIdValidator);
910 onTextChange(LineEditElements->text());
913 SelectionIntoArgument();
916 //=================================================================================
917 // function : GetConstructorId()
919 //=================================================================================
920 int SMESHGUI_SymmetryDlg::GetConstructorId()
922 return GroupConstructors->checkedId();
925 //=================================================================================
926 // function : IsMirrorOk()
928 //=================================================================================
929 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
933 if (GetConstructorId() != 0)
934 isOk = (SpinBox_DX->GetValue() != 0 ||
935 SpinBox_DY->GetValue() != 0 ||
936 SpinBox_DZ->GetValue() != 0);
941 //=================================================================================
942 // function : onVectorChanged()
944 //=================================================================================
945 void SMESHGUI_SymmetryDlg::onVectorChanged()
948 buttonOk->setEnabled(true);
949 buttonApply->setEnabled(true);
951 buttonOk->setEnabled(false);
952 buttonApply->setEnabled(false);
956 //=======================================================================
957 //function : onActionClicked
958 //purpose : slot called when an action type changed
959 //=======================================================================
961 void SMESHGUI_SymmetryDlg::onActionClicked(int button)
964 case MOVE_ELEMS_BUTTON:
965 MakeGroupsCheck->setEnabled(false);
966 LineEditNewMesh->setEnabled(false);
968 case COPY_ELEMS_BUTTON:
969 LineEditNewMesh->setEnabled(false);
970 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
971 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
972 MakeGroupsCheck->setEnabled(true);
974 MakeGroupsCheck->setEnabled(false);
976 case MAKE_MESH_BUTTON:
977 LineEditNewMesh->setEnabled(true);
978 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
979 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
980 MakeGroupsCheck->setEnabled(true);
982 MakeGroupsCheck->setEnabled(false);
988 //=======================================================================
989 //function : setNewMeshName
990 //purpose : update contents of LineEditNewMesh
991 //=======================================================================
993 void SMESHGUI_SymmetryDlg::setNewMeshName()
995 LineEditNewMesh->setText("");
996 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
998 if ( CheckBoxMesh->isChecked() ) {
999 name = LineEditElements->text();
1002 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
1003 name = meshSO->GetName().c_str();
1005 if ( !name.isEmpty() )
1006 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "mirrored"));
1010 //=================================================================================
1011 // function : keyPressEvent()
1013 //=================================================================================
1014 void SMESHGUI_SymmetryDlg::keyPressEvent( QKeyEvent* e )
1016 QDialog::keyPressEvent( e );
1017 if ( e->isAccepted() )
1020 if ( e->key() == Qt::Key_F1 ) {
1026 //=================================================================================
1027 // function : isValid
1029 //=================================================================================
1030 bool SMESHGUI_SymmetryDlg::isValid()
1035 ok = SpinBox_X->isValid( msg, true ) && ok;
1036 ok = SpinBox_Y->isValid( msg, true ) && ok;
1037 ok = SpinBox_Z->isValid( msg, true ) && ok;
1038 if (GetConstructorId() != 0) {
1039 ok = SpinBox_DX->isValid( msg, true ) && ok;
1040 ok = SpinBox_DY->isValid( msg, true ) && ok;
1041 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1045 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1046 if ( !msg.isEmpty() )
1048 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );