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
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 //To disable automatic genericobj management, the following line should be commented.
87 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
88 #define WITHGENERICOBJ
90 //=================================================================================
91 // class : SMESHGUI_SymmetryDlg()
93 //=================================================================================
95 SMESHGUI_SymmetryDlg::SMESHGUI_SymmetryDlg( SMESHGUI* theModule )
96 : QDialog( SMESH::GetDesktop( theModule ) ),
97 mySMESHGUI( theModule ),
98 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
100 mySelectedObject(SMESH::SMESH_IDSource::_nil())
102 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_POINT")));
103 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_AXIS")));
104 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_PLANE")));
105 QPixmap image3 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
108 setAttribute(Qt::WA_DeleteOnClose, true);
109 setWindowTitle(tr("SMESH_SYMMETRY"));
110 setSizeGripEnabled(true);
112 QVBoxLayout* SMESHGUI_SymmetryDlgLayout = new QVBoxLayout(this);
113 SMESHGUI_SymmetryDlgLayout->setSpacing(SPACING);
114 SMESHGUI_SymmetryDlgLayout->setMargin(MARGIN);
116 /***************************************************************/
117 ConstructorsBox = new QGroupBox(tr("SMESH_SYMMETRY"), this);
118 GroupConstructors = new QButtonGroup(this);
119 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
120 ConstructorsBoxLayout->setSpacing(SPACING);
121 ConstructorsBoxLayout->setMargin(MARGIN);
123 RadioButton1 = new QRadioButton(ConstructorsBox);
124 RadioButton1->setIcon(image0);
125 RadioButton2 = new QRadioButton(ConstructorsBox);
126 RadioButton2->setIcon(image1);
127 RadioButton3 = new QRadioButton(ConstructorsBox);
128 RadioButton3->setIcon(image2);
130 ConstructorsBoxLayout->addWidget(RadioButton1);
131 ConstructorsBoxLayout->addWidget(RadioButton2);
132 ConstructorsBoxLayout->addWidget(RadioButton3);
133 GroupConstructors->addButton(RadioButton1, 0);
134 GroupConstructors->addButton(RadioButton2, 1);
135 GroupConstructors->addButton(RadioButton3, 2);
137 /***************************************************************/
138 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
139 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
140 GroupArgumentsLayout->setSpacing(SPACING);
141 GroupArgumentsLayout->setMargin(MARGIN);
143 myIdValidator = new SMESHGUI_IdValidator(this);
145 // Controls for elements selection
146 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
147 SelectElementsButton = new QPushButton(GroupArguments);
148 SelectElementsButton->setIcon(image3);
149 LineEditElements = new QLineEdit(GroupArguments);
150 LineEditElements->setValidator(myIdValidator);
151 LineEditElements->setMaxLength(-1);
152 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
153 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
155 // Control for the whole mesh selection
156 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
158 // Controls for mirror selection
159 GroupMirror = new QGroupBox(GroupArguments);
160 QGridLayout* GroupMirrorLayout = new QGridLayout(GroupMirror);
161 GroupMirrorLayout->setSpacing(SPACING);
162 GroupMirrorLayout->setMargin(MARGIN);
164 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupMirror);
165 SelectPointButton = new QPushButton(GroupMirror);
166 SelectPointButton->setIcon(image3);
168 TextLabelX = new QLabel(tr("SMESH_X"), GroupMirror);
169 SpinBox_X = new SMESHGUI_SpinBox(GroupMirror);
170 TextLabelY = new QLabel(tr("SMESH_Y"), GroupMirror);
171 SpinBox_Y = new SMESHGUI_SpinBox(GroupMirror);
172 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupMirror);
173 SpinBox_Z = new SMESHGUI_SpinBox(GroupMirror);
175 TextLabelVector = new QLabel(GroupMirror);
176 SelectVectorButton = new QPushButton(GroupMirror);
177 SelectVectorButton->setIcon(image3);
179 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupMirror);
180 SpinBox_DX = new SMESHGUI_SpinBox(GroupMirror);
181 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupMirror);
182 SpinBox_DY = new SMESHGUI_SpinBox(GroupMirror);
183 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupMirror);
184 SpinBox_DZ = new SMESHGUI_SpinBox(GroupMirror);
186 GroupMirrorLayout->addWidget(TextLabelPoint, 0, 0);
187 GroupMirrorLayout->addWidget(SelectPointButton, 0, 1);
188 GroupMirrorLayout->addWidget(TextLabelX, 0, 2);
189 GroupMirrorLayout->addWidget(SpinBox_X, 0, 3);
190 GroupMirrorLayout->addWidget(TextLabelY, 0, 4);
191 GroupMirrorLayout->addWidget(SpinBox_Y, 0, 5);
192 GroupMirrorLayout->addWidget(TextLabelZ, 0, 6);
193 GroupMirrorLayout->addWidget(SpinBox_Z, 0, 7);
194 GroupMirrorLayout->addWidget(TextLabelVector, 1, 0);
195 GroupMirrorLayout->addWidget(SelectVectorButton, 1, 1);
196 GroupMirrorLayout->addWidget(TextLabelDX, 1, 2);
197 GroupMirrorLayout->addWidget(SpinBox_DX, 1, 3);
198 GroupMirrorLayout->addWidget(TextLabelDY, 1, 4);
199 GroupMirrorLayout->addWidget(SpinBox_DY, 1, 5);
200 GroupMirrorLayout->addWidget(TextLabelDZ, 1, 6);
201 GroupMirrorLayout->addWidget(SpinBox_DZ, 1, 7);
203 // switch of action type
204 ActionBox = new QGroupBox(GroupArguments);
205 ActionGroup = new QButtonGroup(GroupArguments);
206 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
207 ActionBoxLayout->addSpacing(SPACING);
208 ActionBoxLayout->setMargin(MARGIN);
210 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
211 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
212 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
214 ActionBoxLayout->addWidget(aMoveElements);
215 ActionBoxLayout->addWidget(aCopyElements);
216 ActionBoxLayout->addWidget(aCreateMesh);
217 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
218 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
219 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
221 // CheckBox for groups generation
222 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
223 MakeGroupsCheck->setChecked(false);
225 // Name of a mesh to create
226 LineEditNewMesh = new QLineEdit(GroupArguments);
229 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
230 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
231 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 1);
232 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 3);
233 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
234 GroupArgumentsLayout->addWidget(GroupMirror, 2, 0, 1, 4);
235 GroupArgumentsLayout->addWidget(ActionBox, 3, 0, 3, 3);
236 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 4, 3);
237 GroupArgumentsLayout->addWidget(LineEditNewMesh, 5, 3);
239 /***************************************************************/
240 GroupButtons = new QGroupBox(this);
241 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
242 GroupButtonsLayout->setSpacing(SPACING);
243 GroupButtonsLayout->setMargin(MARGIN);
245 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
246 buttonOk->setAutoDefault(true);
247 buttonOk->setDefault(true);
248 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
249 buttonApply->setAutoDefault(true);
250 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
251 buttonCancel->setAutoDefault(true);
252 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
253 buttonHelp->setAutoDefault(true);
255 GroupButtonsLayout->addWidget(buttonOk);
256 GroupButtonsLayout->addSpacing(10);
257 GroupButtonsLayout->addWidget(buttonApply);
258 GroupButtonsLayout->addSpacing(10);
259 GroupButtonsLayout->addStretch();
260 GroupButtonsLayout->addWidget(buttonCancel);
261 GroupButtonsLayout->addWidget(buttonHelp);
263 /***************************************************************/
264 SMESHGUI_SymmetryDlgLayout->addWidget(ConstructorsBox);
265 SMESHGUI_SymmetryDlgLayout->addWidget(GroupArguments);
266 SMESHGUI_SymmetryDlgLayout->addWidget(GroupButtons);
268 /* Initialisations */
269 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
270 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
271 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
272 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
273 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
274 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
276 RadioButton1->setChecked(true);
278 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
280 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
282 // Costruction of the logical filter
283 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
284 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
286 QList<SUIT_SelectionFilter*> aListOfFilters;
287 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
288 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
290 myMeshOrSubMeshOrGroupFilter =
291 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
293 myHelpFileName = "symmetry_page.html";
297 /* signals and slots connections */
298 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
299 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
300 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
301 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
302 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
304 connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
305 connect(SelectPointButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
306 connect(SelectVectorButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
308 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
309 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
310 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
312 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
313 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
314 /* to close dialog if study change */
315 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
316 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
317 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
318 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
320 ConstructorsClicked(0);
321 SelectionIntoArgument();
322 onActionClicked(MOVE_ELEMS_BUTTON);
325 //=================================================================================
326 // function : ~SMESHGUI_SymmetryDlg()
327 // purpose : Destroys the object and frees any allocated resources
328 //=================================================================================
329 SMESHGUI_SymmetryDlg::~SMESHGUI_SymmetryDlg()
331 if ( myFilterDlg != 0 ) {
332 myFilterDlg->setParent( 0 );
337 //=================================================================================
340 //=================================================================================
341 void SMESHGUI_SymmetryDlg::Init (bool ResetControls)
345 myEditCurrentArgument = 0;
346 LineEditElements->clear();
350 buttonOk->setEnabled(false);
351 buttonApply->setEnabled(false);
354 myMesh = SMESH::SMESH_Mesh::_nil();
357 SpinBox_X->SetValue(0.0);
358 SpinBox_Y->SetValue(0.0);
359 SpinBox_Z->SetValue(0.0);
360 SpinBox_DX->SetValue(0.0);
361 SpinBox_DY->SetValue(0.0);
362 SpinBox_DZ->SetValue(0.0);
364 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
365 CheckBoxMesh->setChecked(false);
366 // MakeGroupsCheck->setChecked(false);
367 // MakeGroupsCheck->setEnabled(false);
372 //=================================================================================
373 // function : ConstructorsClicked()
374 // purpose : Radio button management
375 //=================================================================================
376 void SMESHGUI_SymmetryDlg::ConstructorsClicked (int constructorId)
378 disconnect(mySelectionMgr, 0, this, 0);
380 if (constructorId != 0 && !TextLabelVector->isVisible()) {
381 TextLabelVector->show();
382 SelectVectorButton->show();
391 switch (constructorId) {
394 GroupMirror->setTitle(tr("SMESH_POINT"));
396 TextLabelVector->hide();
397 SelectVectorButton->hide();
408 GroupMirror->setTitle(tr("SMESH_AXIS"));
409 TextLabelVector->setText(tr("SMESH_VECTOR"));
414 GroupMirror->setTitle(tr("SMESH_PLANE"));
415 TextLabelVector->setText(tr("SMESH_NORMAL"));
420 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
421 SMESH::SetPointRepresentation(false);
422 if (!CheckBoxMesh->isChecked())
424 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
425 aViewWindow->SetSelectionMode(CellSelection);
429 myEditCurrentArgument = (QWidget*)LineEditElements;
430 LineEditElements->setFocus();
432 if (CheckBoxMesh->isChecked())
435 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
437 QApplication::instance()->processEvents();
442 //=================================================================================
443 // function : ClickOnApply()
445 //=================================================================================
446 bool SMESHGUI_SymmetryDlg::ClickOnApply()
448 if (mySMESHGUI->isActiveStudyLocked())
454 if (myNbOkElements && IsMirrorOk()) {
455 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
457 SMESH::long_array_var anElementsId = new SMESH::long_array;
459 anElementsId->length(aListElementsId.count());
460 for (int i = 0; i < aListElementsId.count(); i++)
461 anElementsId[i] = aListElementsId[i].toInt();
463 SMESH::AxisStruct aMirror;
465 aMirror.x = SpinBox_X->GetValue();
466 aMirror.y = SpinBox_Y->GetValue();
467 aMirror.z = SpinBox_Z->GetValue();
468 if (GetConstructorId() == 0) {
469 aMirror.vx = aMirror.vy = aMirror.vz = 0;
471 aMirror.vx = SpinBox_DX->GetValue();
472 aMirror.vy = SpinBox_DY->GetValue();
473 aMirror.vz = SpinBox_DZ->GetValue();
476 QStringList aParameters;
477 aParameters << SpinBox_X->text();
478 aParameters << SpinBox_Y->text();
479 aParameters << SpinBox_Z->text();
480 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DX->text() );
481 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DY->text() );
482 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DZ->text() );
484 SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
486 if (GetConstructorId() == 0)
487 aMirrorType = SMESH::SMESH_MeshEditor::POINT;
488 if (GetConstructorId() == 1)
489 aMirrorType = SMESH::SMESH_MeshEditor::AXIS;
490 if (GetConstructorId() == 2)
491 aMirrorType = SMESH::SMESH_MeshEditor::PLANE;
493 int actionButton = ActionGroup->checkedId();
494 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
497 SUIT_OverrideCursor aWaitCursor;
498 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
500 switch ( actionButton ) {
501 case MOVE_ELEMS_BUTTON: {
502 if(CheckBoxMesh->isChecked())
503 aMeshEditor->MirrorObject(mySelectedObject, aMirror, aMirrorType, false );
505 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, false );
507 if( !myMesh->_is_nil())
508 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
511 case COPY_ELEMS_BUTTON: {
512 SMESH::ListOfGroups_var groups;
514 if(CheckBoxMesh->isChecked())
515 groups = aMeshEditor->MirrorObjectMakeGroups(mySelectedObject, aMirror, aMirrorType);
517 groups = aMeshEditor->MirrorMakeGroups(anElementsId, aMirror, aMirrorType);
520 if(CheckBoxMesh->isChecked())
521 aMeshEditor->MirrorObject(mySelectedObject, aMirror, aMirrorType, true);
523 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, true);
525 if( !myMesh->_is_nil())
526 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
529 case MAKE_MESH_BUTTON: {
530 SMESH::SMESH_Mesh_var mesh;
531 if (CheckBoxMesh->isChecked())
532 mesh = aMeshEditor->MirrorObjectMakeMesh(mySelectedObject, aMirror, aMirrorType, makeGroups,
533 LineEditNewMesh->text().toLatin1().data());
535 mesh = aMeshEditor->MirrorMakeMesh(anElementsId, aMirror, aMirrorType, makeGroups,
536 LineEditNewMesh->text().toLatin1().data());
537 if (!mesh->_is_nil()) {
538 mesh->SetParameters(aParameters.join(":").toLatin1().constData());
539 #ifdef WITHGENERICOBJ
540 // obj has been published in study. Its refcount has been incremented.
541 // It is safe to decrement its refcount
542 // so that it will be destroyed when the entry in study will be removed
553 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
554 actionButton == MAKE_MESH_BUTTON )
555 mySMESHGUI->updateObjBrowser(true); // new groups may appear
557 ConstructorsClicked(GetConstructorId());
558 mySelectedObject = SMESH::SMESH_IDSource::_nil();
559 SelectionIntoArgument();
561 SMESHGUI::Modified();
566 //=================================================================================
567 // function : ClickOnOk()
569 //=================================================================================
570 void SMESHGUI_SymmetryDlg::ClickOnOk()
576 //=================================================================================
577 // function : ClickOnCancel()
579 //=================================================================================
580 void SMESHGUI_SymmetryDlg::ClickOnCancel()
582 disconnect(mySelectionMgr, 0, this, 0);
583 mySelectionMgr->clearFilters();
584 //mySelectionMgr->clearSelected();
585 if (SMESH::GetCurrentVtkView()) {
586 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
587 SMESH::SetPointRepresentation(false);
589 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
590 aViewWindow->SetSelectionMode(ActorSelection);
591 mySMESHGUI->ResetState();
595 //=================================================================================
596 // function : ClickOnHelp()
598 //=================================================================================
599 void SMESHGUI_SymmetryDlg::ClickOnHelp()
601 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
603 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
607 platform = "winapplication";
609 platform = "application";
611 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
612 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
613 arg(app->resourceMgr()->stringValue("ExternalBrowser",
615 arg(myHelpFileName));
619 //=======================================================================
620 // function : onTextChange()
622 //=======================================================================
623 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
625 QLineEdit* send = (QLineEdit*)sender();
630 if (send == LineEditElements)
633 buttonOk->setEnabled(false);
634 buttonApply->setEnabled(false);
636 // hilight entered elements
637 SMDS_Mesh* aMesh = 0;
639 aMesh = myActor->GetObject()->GetMesh();
642 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
644 TColStd_MapOfInteger newIndices;
646 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
648 if (send == LineEditElements) {
649 for (int i = 0; i < aListId.count(); i++) {
650 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
652 newIndices.Add(e->GetID());
656 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
657 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
658 aViewWindow->highlight( anIO, true, true );
660 myElementsId = theNewText;
664 if (myNbOkElements && IsMirrorOk()) {
665 buttonOk->setEnabled(true);
666 buttonApply->setEnabled(true);
672 //=================================================================================
673 // function : SelectionIntoArgument()
674 // purpose : Called when selection as changed or other case
675 //=================================================================================
676 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
682 QString aString = "";
685 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
686 LineEditElements->setText(aString);
688 buttonOk->setEnabled(false);
689 buttonApply->setEnabled(false);
693 if (!GroupButtons->isEnabled()) // inactive
698 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
700 int nbSel = aList.Extent();
704 Handle(SALOME_InteractiveObject) IO = aList.First();
705 myMesh = SMESH::GetMeshByIO(IO);
706 if(myMesh->_is_nil())
709 myActor = SMESH::FindActorByObject(myMesh);
711 myActor = SMESH::FindActorByEntry(IO->getEntry());
712 if (!myActor && !CheckBoxMesh->isChecked())
717 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
720 // MakeGroups is available if there are groups and "Copy"
721 if ( myMesh->NbGroups() == 0 ) {
722 MakeGroupsCheck->setChecked(false);
723 MakeGroupsCheck->setEnabled(false);
725 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
726 MakeGroupsCheck->setEnabled(true);
728 if (CheckBoxMesh->isChecked()) {
729 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
731 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH
732 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
738 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
742 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
743 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
745 myElementsId += QString(" %1").arg(i);
749 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
751 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
753 // get IDs from submesh
755 SMESH::long_array_var anElementsIds = new SMESH::long_array;
756 anElementsIds = aSubMesh->GetElementsId();
757 for (int i = 0; i < anElementsIds->length(); i++) {
758 myElementsId += QString(" %1").arg(anElementsIds[i]);
760 aNbUnits = anElementsIds->length();
763 SMESH::SMESH_GroupBase_var aGroup =
764 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
765 if (aGroup->_is_nil())
768 // get IDs from smesh group
769 SMESH::long_array_var anElementsIds = new SMESH::long_array;
770 anElementsIds = aGroup->GetListOfID();
771 for (int i = 0; i < anElementsIds->length(); i++) {
772 myElementsId += QString(" %1").arg(anElementsIds[i]);
774 aNbUnits = anElementsIds->length();
778 aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, IO, aString);
779 myElementsId = aString;
784 myNbOkElements = true;
786 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
790 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
794 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
802 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
803 SpinBox_X->SetValue(x);
804 SpinBox_Y->SetValue(y);
805 SpinBox_Z->SetValue(z);
806 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
807 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
808 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
809 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
814 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
815 LineEditElements->setText(aString);
816 LineEditElements->repaint();
817 LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
818 LineEditElements->setEnabled(true);
824 if (myNbOkElements && IsMirrorOk()) {
825 buttonOk->setEnabled(true);
826 buttonApply->setEnabled(true);
830 //=================================================================================
831 // function : SetEditCurrentArgument()
833 //=================================================================================
834 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
836 QPushButton* send = (QPushButton*)sender();
838 disconnect(mySelectionMgr, 0, this, 0);
839 mySelectionMgr->clearSelected();
840 mySelectionMgr->clearFilters();
842 if (send == SelectElementsButton) {
843 myEditCurrentArgument = (QWidget*)LineEditElements;
844 SMESH::SetPointRepresentation(false);
845 if (CheckBoxMesh->isChecked()) {
846 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
847 aViewWindow->SetSelectionMode(ActorSelection);
848 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
850 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
851 aViewWindow->SetSelectionMode(CellSelection);
853 } else if (send == SelectPointButton) {
854 myEditCurrentArgument = (QWidget*)SpinBox_X;
855 SMESH::SetPointRepresentation(true);
856 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
857 aViewWindow->SetSelectionMode(NodeSelection);
858 } else if (send == SelectVectorButton) {
859 myEditCurrentArgument = (QWidget*)SpinBox_DX;
860 SMESH::SetPointRepresentation(true);
862 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
863 aViewWindow->SetSelectionMode(NodeSelection);
867 myEditCurrentArgument->setFocus();
868 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
869 SelectionIntoArgument();
872 //=================================================================================
873 // function : DeactivateActiveDialog()
875 //=================================================================================
876 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
878 if (ConstructorsBox->isEnabled()) {
879 ConstructorsBox->setEnabled(false);
880 GroupArguments->setEnabled(false);
881 GroupButtons->setEnabled(false);
882 mySMESHGUI->ResetState();
883 mySMESHGUI->SetActiveDialogBox(0);
887 //=================================================================================
888 // function : ActivateThisDialog()
890 //=================================================================================
891 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
893 /* Emit a signal to deactivate the active dialog */
894 mySMESHGUI->EmitSignalDeactivateDialog();
895 ConstructorsBox->setEnabled(true);
896 GroupArguments->setEnabled(true);
897 GroupButtons->setEnabled(true);
899 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
901 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
902 aViewWindow->SetSelectionMode(CellSelection);
903 SelectionIntoArgument();
906 //=================================================================================
907 // function : enterEvent()
909 //=================================================================================
910 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
912 if (!ConstructorsBox->isEnabled())
913 ActivateThisDialog();
916 //=================================================================================
917 // function : closeEvent()
919 //=================================================================================
920 void SMESHGUI_SymmetryDlg::closeEvent (QCloseEvent*)
922 /* same than click on cancel button */
926 //=======================================================================
927 // function : hideEvent()
928 // purpose : caused by ESC key
929 //=======================================================================
930 void SMESHGUI_SymmetryDlg::hideEvent (QHideEvent*)
936 //=======================================================================
937 //function : onSelectMesh
939 //=======================================================================
940 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
943 TextLabelElements->setText(tr("SMESH_NAME"));
945 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
946 myFilterBtn->setEnabled(!toSelectMesh);
948 if (myEditCurrentArgument != LineEditElements) {
949 LineEditElements->clear();
953 mySelectionMgr->clearFilters();
954 SMESH::SetPointRepresentation(false);
957 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
958 aViewWindow->SetSelectionMode(ActorSelection);
959 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
960 LineEditElements->setReadOnly(true);
961 LineEditElements->setValidator(0);
963 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
964 aViewWindow->SetSelectionMode(CellSelection);
965 LineEditElements->setReadOnly(false);
966 LineEditElements->setValidator(myIdValidator);
967 onTextChange(LineEditElements->text());
970 SelectionIntoArgument();
973 //=================================================================================
974 // function : GetConstructorId()
976 //=================================================================================
977 int SMESHGUI_SymmetryDlg::GetConstructorId()
979 return GroupConstructors->checkedId();
982 //=================================================================================
983 // function : IsMirrorOk()
985 //=================================================================================
986 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
990 if (GetConstructorId() != 0)
991 isOk = (SpinBox_DX->GetValue() != 0 ||
992 SpinBox_DY->GetValue() != 0 ||
993 SpinBox_DZ->GetValue() != 0);
998 //=================================================================================
999 // function : onVectorChanged()
1001 //=================================================================================
1002 void SMESHGUI_SymmetryDlg::onVectorChanged()
1005 buttonOk->setEnabled(true);
1006 buttonApply->setEnabled(true);
1008 buttonOk->setEnabled(false);
1009 buttonApply->setEnabled(false);
1013 //=======================================================================
1014 //function : onActionClicked
1015 //purpose : slot called when an action type changed
1016 //=======================================================================
1018 void SMESHGUI_SymmetryDlg::onActionClicked(int button)
1021 case MOVE_ELEMS_BUTTON:
1022 MakeGroupsCheck->setEnabled(false);
1023 LineEditNewMesh->setEnabled(false);
1025 case COPY_ELEMS_BUTTON:
1026 LineEditNewMesh->setEnabled(false);
1027 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1028 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1029 MakeGroupsCheck->setEnabled(true);
1031 MakeGroupsCheck->setEnabled(false);
1033 case MAKE_MESH_BUTTON:
1034 LineEditNewMesh->setEnabled(true);
1035 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1036 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1037 MakeGroupsCheck->setEnabled(true);
1039 MakeGroupsCheck->setEnabled(false);
1045 //=======================================================================
1046 //function : setNewMeshName
1047 //purpose : update contents of LineEditNewMesh
1048 //=======================================================================
1050 void SMESHGUI_SymmetryDlg::setNewMeshName()
1052 LineEditNewMesh->setText("");
1053 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
1055 if ( CheckBoxMesh->isChecked() ) {
1056 name = LineEditElements->text();
1059 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
1060 name = meshSO->GetName().c_str();
1062 if ( !name.isEmpty() )
1063 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "mirrored"));
1067 //=================================================================================
1068 // function : keyPressEvent()
1070 //=================================================================================
1071 void SMESHGUI_SymmetryDlg::keyPressEvent( QKeyEvent* e )
1073 QDialog::keyPressEvent( e );
1074 if ( e->isAccepted() )
1077 if ( e->key() == Qt::Key_F1 ) {
1083 //=================================================================================
1084 // function : setFilters()
1085 // purpose : SLOT. Called when "Filter" button pressed.
1086 //=================================================================================
1087 void SMESHGUI_SymmetryDlg::setFilters()
1089 if(myMesh->_is_nil()) {
1090 SUIT_MessageBox::critical(this,
1092 tr("NO_MESH_SELECTED"));
1096 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1098 myFilterDlg->SetSelection();
1099 myFilterDlg->SetMesh( myMesh );
1100 myFilterDlg->SetSourceWg( LineEditElements );
1102 myFilterDlg->show();
1105 //=================================================================================
1106 // function : isValid
1108 //=================================================================================
1109 bool SMESHGUI_SymmetryDlg::isValid()
1114 ok = SpinBox_X->isValid( msg, true ) && ok;
1115 ok = SpinBox_Y->isValid( msg, true ) && ok;
1116 ok = SpinBox_Z->isValid( msg, true ) && ok;
1117 if (GetConstructorId() != 0) {
1118 ok = SpinBox_DX->isValid( msg, true ) && ok;
1119 ok = SpinBox_DY->isValid( msg, true ) && ok;
1120 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1124 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1125 if ( !msg.isEmpty() )
1127 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );