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"
36 #include "SMESHGUI_MeshEditPreview.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 //To disable automatic genericobj management, the following line should be commented.
88 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
89 #define WITHGENERICOBJ
91 //=================================================================================
92 // class : SMESHGUI_SymmetryDlg()
94 //=================================================================================
96 SMESHGUI_SymmetryDlg::SMESHGUI_SymmetryDlg( SMESHGUI* theModule )
97 : SMESHGUI_PreviewDlg( 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);
230 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
233 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
234 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
235 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 1);
236 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 3);
237 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
238 GroupArgumentsLayout->addWidget(GroupMirror, 2, 0, 1, 4);
239 GroupArgumentsLayout->addWidget(ActionBox, 3, 0, 3, 3);
240 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 4, 3);
241 GroupArgumentsLayout->addWidget(LineEditNewMesh, 5, 3);
242 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 6, 0);
244 /***************************************************************/
245 GroupButtons = new QGroupBox(this);
246 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
247 GroupButtonsLayout->setSpacing(SPACING);
248 GroupButtonsLayout->setMargin(MARGIN);
250 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
251 buttonOk->setAutoDefault(true);
252 buttonOk->setDefault(true);
253 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
254 buttonApply->setAutoDefault(true);
255 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
256 buttonCancel->setAutoDefault(true);
257 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
258 buttonHelp->setAutoDefault(true);
260 GroupButtonsLayout->addWidget(buttonOk);
261 GroupButtonsLayout->addSpacing(10);
262 GroupButtonsLayout->addWidget(buttonApply);
263 GroupButtonsLayout->addSpacing(10);
264 GroupButtonsLayout->addStretch();
265 GroupButtonsLayout->addWidget(buttonCancel);
266 GroupButtonsLayout->addWidget(buttonHelp);
268 /***************************************************************/
269 SMESHGUI_SymmetryDlgLayout->addWidget(ConstructorsBox);
270 SMESHGUI_SymmetryDlgLayout->addWidget(GroupArguments);
271 SMESHGUI_SymmetryDlgLayout->addWidget(GroupButtons);
273 /* Initialisations */
274 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
275 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
276 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
277 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
278 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
279 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
281 RadioButton1->setChecked(true);
283 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
285 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
287 // Costruction of the logical filter
288 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
289 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
291 QList<SUIT_SelectionFilter*> aListOfFilters;
292 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
293 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
295 myMeshOrSubMeshOrGroupFilter =
296 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
298 myHelpFileName = "symmetry_page.html";
302 /* signals and slots connections */
303 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
304 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
305 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
306 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
307 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
309 connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
310 connect(SelectPointButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
311 connect(SelectVectorButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
313 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
314 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
315 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
317 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
318 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
319 /* to close dialog if study change */
320 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
321 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
322 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
323 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
325 connect(SpinBox_X, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
326 connect(SpinBox_Y, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
327 connect(SpinBox_Z, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
328 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
329 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
330 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
332 //To Connect preview check box
333 connectPreviewControl();
335 ConstructorsClicked(0);
336 SelectionIntoArgument();
337 onActionClicked(MOVE_ELEMS_BUTTON);
340 //=================================================================================
341 // function : ~SMESHGUI_SymmetryDlg()
342 // purpose : Destroys the object and frees any allocated resources
343 //=================================================================================
344 SMESHGUI_SymmetryDlg::~SMESHGUI_SymmetryDlg()
346 if ( myFilterDlg != 0 ) {
347 myFilterDlg->setParent( 0 );
352 //=================================================================================
355 //=================================================================================
356 void SMESHGUI_SymmetryDlg::Init (bool ResetControls)
360 myEditCurrentArgument = 0;
361 LineEditElements->clear();
365 buttonOk->setEnabled(false);
366 buttonApply->setEnabled(false);
369 myMesh = SMESH::SMESH_Mesh::_nil();
372 SpinBox_X->SetValue(0.0);
373 SpinBox_Y->SetValue(0.0);
374 SpinBox_Z->SetValue(0.0);
375 SpinBox_DX->SetValue(0.0);
376 SpinBox_DY->SetValue(0.0);
377 SpinBox_DZ->SetValue(0.0);
379 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
380 CheckBoxMesh->setChecked(false);
381 myPreviewCheckBox->setChecked(false);
382 onDisplaySimulation(false);
384 // MakeGroupsCheck->setChecked(false);
385 // MakeGroupsCheck->setEnabled(false);
390 //=================================================================================
391 // function : ConstructorsClicked()
392 // purpose : Radio button management
393 //=================================================================================
394 void SMESHGUI_SymmetryDlg::ConstructorsClicked (int constructorId)
396 disconnect(mySelectionMgr, 0, this, 0);
398 if (constructorId != 0 && !TextLabelVector->isVisible()) {
399 TextLabelVector->show();
400 SelectVectorButton->show();
409 switch (constructorId) {
412 GroupMirror->setTitle(tr("SMESH_POINT"));
414 TextLabelVector->hide();
415 SelectVectorButton->hide();
426 GroupMirror->setTitle(tr("SMESH_AXIS"));
427 TextLabelVector->setText(tr("SMESH_VECTOR"));
432 GroupMirror->setTitle(tr("SMESH_PLANE"));
433 TextLabelVector->setText(tr("SMESH_NORMAL"));
438 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
439 SMESH::SetPointRepresentation(false);
440 if (!CheckBoxMesh->isChecked())
442 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
443 aViewWindow->SetSelectionMode(CellSelection);
447 myEditCurrentArgument = (QWidget*)LineEditElements;
448 LineEditElements->setFocus();
450 if (CheckBoxMesh->isChecked())
453 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
455 onDisplaySimulation(true);
457 QApplication::instance()->processEvents();
462 //=================================================================================
463 // function : ClickOnApply()
465 //=================================================================================
466 bool SMESHGUI_SymmetryDlg::ClickOnApply()
468 if (mySMESHGUI->isActiveStudyLocked())
474 if (myNbOkElements && IsMirrorOk()) {
475 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
477 SMESH::long_array_var anElementsId = new SMESH::long_array;
479 anElementsId->length(aListElementsId.count());
480 for (int i = 0; i < aListElementsId.count(); i++)
481 anElementsId[i] = aListElementsId[i].toInt();
483 SMESH::AxisStruct aMirror;
484 SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
485 getMirror(aMirror,aMirrorType);
487 QStringList aParameters;
488 aParameters << SpinBox_X->text();
489 aParameters << SpinBox_Y->text();
490 aParameters << SpinBox_Z->text();
491 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DX->text() );
492 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DY->text() );
493 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DZ->text() );
495 int actionButton = ActionGroup->checkedId();
496 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
499 SUIT_OverrideCursor aWaitCursor;
500 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
502 switch ( actionButton ) {
503 case MOVE_ELEMS_BUTTON: {
504 if(CheckBoxMesh->isChecked())
505 aMeshEditor->MirrorObject(mySelectedObject, aMirror, aMirrorType, false );
507 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, false );
509 if( !myMesh->_is_nil())
510 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
513 case COPY_ELEMS_BUTTON: {
514 SMESH::ListOfGroups_var groups;
516 if(CheckBoxMesh->isChecked())
517 groups = aMeshEditor->MirrorObjectMakeGroups(mySelectedObject, aMirror, aMirrorType);
519 groups = aMeshEditor->MirrorMakeGroups(anElementsId, aMirror, aMirrorType);
522 if(CheckBoxMesh->isChecked())
523 aMeshEditor->MirrorObject(mySelectedObject, aMirror, aMirrorType, true);
525 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, true);
527 if( !myMesh->_is_nil())
528 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
531 case MAKE_MESH_BUTTON: {
532 SMESH::SMESH_Mesh_var mesh;
533 if (CheckBoxMesh->isChecked())
534 mesh = aMeshEditor->MirrorObjectMakeMesh(mySelectedObject, aMirror, aMirrorType, makeGroups,
535 LineEditNewMesh->text().toLatin1().data());
537 mesh = aMeshEditor->MirrorMakeMesh(anElementsId, aMirror, aMirrorType, makeGroups,
538 LineEditNewMesh->text().toLatin1().data());
539 if (!mesh->_is_nil()) {
540 mesh->SetParameters(aParameters.join(":").toLatin1().constData());
541 #ifdef WITHGENERICOBJ
542 // obj has been published in study. Its refcount has been incremented.
543 // It is safe to decrement its refcount
544 // so that it will be destroyed when the entry in study will be removed
555 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
556 actionButton == MAKE_MESH_BUTTON )
557 mySMESHGUI->updateObjBrowser(true); // new groups may appear
559 ConstructorsClicked(GetConstructorId());
560 mySelectedObject = SMESH::SMESH_IDSource::_nil();
561 SelectionIntoArgument();
563 SMESHGUI::Modified();
568 //=================================================================================
569 // function : ClickOnOk()
571 //=================================================================================
572 void SMESHGUI_SymmetryDlg::ClickOnOk()
578 //=================================================================================
579 // function : ClickOnCancel()
581 //=================================================================================
582 void SMESHGUI_SymmetryDlg::ClickOnCancel()
584 disconnect(mySelectionMgr, 0, this, 0);
585 mySelectionMgr->clearFilters();
586 //mySelectionMgr->clearSelected();
587 if (SMESH::GetCurrentVtkView()) {
588 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
589 SMESH::SetPointRepresentation(false);
591 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
592 aViewWindow->SetSelectionMode(ActorSelection);
593 mySMESHGUI->ResetState();
597 //=================================================================================
598 // function : ClickOnHelp()
600 //=================================================================================
601 void SMESHGUI_SymmetryDlg::ClickOnHelp()
603 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
605 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
609 platform = "winapplication";
611 platform = "application";
613 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
614 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
615 arg(app->resourceMgr()->stringValue("ExternalBrowser",
617 arg(myHelpFileName));
621 //=======================================================================
622 // function : onTextChange()
624 //=======================================================================
625 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
627 QLineEdit* send = (QLineEdit*)sender();
632 if (send == LineEditElements)
635 buttonOk->setEnabled(false);
636 buttonApply->setEnabled(false);
638 // hilight entered elements
639 SMDS_Mesh* aMesh = 0;
641 aMesh = myActor->GetObject()->GetMesh();
644 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
646 TColStd_MapOfInteger newIndices;
648 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
650 if (send == LineEditElements) {
651 for (int i = 0; i < aListId.count(); i++) {
652 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
654 newIndices.Add(e->GetID());
658 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
659 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
660 aViewWindow->highlight( anIO, true, true );
662 myElementsId = theNewText;
666 if (myNbOkElements && IsMirrorOk()) {
667 buttonOk->setEnabled(true);
668 buttonApply->setEnabled(true);
674 //=================================================================================
675 // function : SelectionIntoArgument()
676 // purpose : Called when selection as changed or other case
677 //=================================================================================
678 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
684 QString aString = "";
687 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
688 LineEditElements->setText(aString);
690 buttonOk->setEnabled(false);
691 buttonApply->setEnabled(false);
695 if (!GroupButtons->isEnabled()) // inactive
700 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
702 int nbSel = aList.Extent();
706 Handle(SALOME_InteractiveObject) IO = aList.First();
707 myMesh = SMESH::GetMeshByIO(IO);
708 if(myMesh->_is_nil())
711 myActor = SMESH::FindActorByObject(myMesh);
713 myActor = SMESH::FindActorByEntry(IO->getEntry());
714 if (!myActor && !CheckBoxMesh->isChecked())
719 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
722 // MakeGroups is available if there are groups and "Copy"
723 if ( myMesh->NbGroups() == 0 ) {
724 MakeGroupsCheck->setChecked(false);
725 MakeGroupsCheck->setEnabled(false);
727 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
728 MakeGroupsCheck->setEnabled(true);
730 if (CheckBoxMesh->isChecked()) {
731 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
733 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH
734 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
740 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
744 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
745 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
747 myElementsId += QString(" %1").arg(i);
751 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
753 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
755 // get IDs from submesh
757 SMESH::long_array_var anElementsIds = new SMESH::long_array;
758 anElementsIds = aSubMesh->GetElementsId();
759 for (int i = 0; i < anElementsIds->length(); i++) {
760 myElementsId += QString(" %1").arg(anElementsIds[i]);
762 aNbUnits = anElementsIds->length();
765 SMESH::SMESH_GroupBase_var aGroup =
766 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
767 if (aGroup->_is_nil())
770 // get IDs from smesh group
771 SMESH::long_array_var anElementsIds = new SMESH::long_array;
772 anElementsIds = aGroup->GetListOfID();
773 for (int i = 0; i < anElementsIds->length(); i++) {
774 myElementsId += QString(" %1").arg(anElementsIds[i]);
776 aNbUnits = anElementsIds->length();
780 aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, IO, aString);
781 myElementsId = aString;
786 myNbOkElements = true;
788 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
792 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
796 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
804 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
805 SpinBox_X->SetValue(x);
806 SpinBox_Y->SetValue(y);
807 SpinBox_Z->SetValue(z);
808 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
809 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
810 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
811 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
816 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
817 LineEditElements->setText(aString);
818 LineEditElements->repaint();
819 LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
820 LineEditElements->setEnabled(true);
826 if (myNbOkElements && IsMirrorOk()) {
827 buttonOk->setEnabled(true);
828 buttonApply->setEnabled(true);
830 onDisplaySimulation(true);
833 //=================================================================================
834 // function : SetEditCurrentArgument()
836 //=================================================================================
837 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
839 QPushButton* send = (QPushButton*)sender();
841 disconnect(mySelectionMgr, 0, this, 0);
842 mySelectionMgr->clearSelected();
843 mySelectionMgr->clearFilters();
845 if (send == SelectElementsButton) {
846 myEditCurrentArgument = (QWidget*)LineEditElements;
847 SMESH::SetPointRepresentation(false);
848 if (CheckBoxMesh->isChecked()) {
849 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
850 aViewWindow->SetSelectionMode(ActorSelection);
851 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
853 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
854 aViewWindow->SetSelectionMode(CellSelection);
856 } else if (send == SelectPointButton) {
857 myEditCurrentArgument = (QWidget*)SpinBox_X;
858 SMESH::SetPointRepresentation(true);
859 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
860 aViewWindow->SetSelectionMode(NodeSelection);
861 } else if (send == SelectVectorButton) {
862 myEditCurrentArgument = (QWidget*)SpinBox_DX;
863 SMESH::SetPointRepresentation(true);
865 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
866 aViewWindow->SetSelectionMode(NodeSelection);
870 myEditCurrentArgument->setFocus();
871 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
872 SelectionIntoArgument();
875 //=================================================================================
876 // function : DeactivateActiveDialog()
878 //=================================================================================
879 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
881 if (ConstructorsBox->isEnabled()) {
882 ConstructorsBox->setEnabled(false);
883 GroupArguments->setEnabled(false);
884 GroupButtons->setEnabled(false);
885 mySMESHGUI->ResetState();
886 mySMESHGUI->SetActiveDialogBox(0);
890 //=================================================================================
891 // function : ActivateThisDialog()
893 //=================================================================================
894 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
896 /* Emit a signal to deactivate the active dialog */
897 mySMESHGUI->EmitSignalDeactivateDialog();
898 ConstructorsBox->setEnabled(true);
899 GroupArguments->setEnabled(true);
900 GroupButtons->setEnabled(true);
902 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
904 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
905 aViewWindow->SetSelectionMode(CellSelection);
906 SelectionIntoArgument();
909 //=================================================================================
910 // function : enterEvent()
912 //=================================================================================
913 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
915 if (!ConstructorsBox->isEnabled())
916 ActivateThisDialog();
919 //=================================================================================
920 // function : closeEvent()
922 //=================================================================================
923 void SMESHGUI_SymmetryDlg::closeEvent (QCloseEvent*)
925 /* same than click on cancel button */
929 //=======================================================================
930 // function : hideEvent()
931 // purpose : caused by ESC key
932 //=======================================================================
933 void SMESHGUI_SymmetryDlg::hideEvent (QHideEvent*)
939 //=======================================================================
940 //function : onSelectMesh
942 //=======================================================================
943 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
946 TextLabelElements->setText(tr("SMESH_NAME"));
948 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
949 myFilterBtn->setEnabled(!toSelectMesh);
951 if (myEditCurrentArgument != LineEditElements) {
952 LineEditElements->clear();
956 mySelectionMgr->clearFilters();
957 SMESH::SetPointRepresentation(false);
960 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
961 aViewWindow->SetSelectionMode(ActorSelection);
962 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
963 LineEditElements->setReadOnly(true);
964 LineEditElements->setValidator(0);
966 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
967 aViewWindow->SetSelectionMode(CellSelection);
968 LineEditElements->setReadOnly(false);
969 LineEditElements->setValidator(myIdValidator);
970 onTextChange(LineEditElements->text());
974 SelectionIntoArgument();
977 //=================================================================================
978 // function : GetConstructorId()
980 //=================================================================================
981 int SMESHGUI_SymmetryDlg::GetConstructorId()
983 return GroupConstructors->checkedId();
986 //=================================================================================
987 // function : IsMirrorOk()
989 //=================================================================================
990 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
994 if (GetConstructorId() != 0)
995 isOk = (SpinBox_DX->GetValue() != 0 ||
996 SpinBox_DY->GetValue() != 0 ||
997 SpinBox_DZ->GetValue() != 0);
1002 //=================================================================================
1003 // function : onVectorChanged()
1005 //=================================================================================
1006 void SMESHGUI_SymmetryDlg::onVectorChanged()
1009 buttonOk->setEnabled(true);
1010 buttonApply->setEnabled(true);
1012 buttonOk->setEnabled(false);
1013 buttonApply->setEnabled(false);
1017 //=======================================================================
1018 //function : onActionClicked
1019 //purpose : slot called when an action type changed
1020 //=======================================================================
1022 void SMESHGUI_SymmetryDlg::onActionClicked(int button)
1025 case MOVE_ELEMS_BUTTON:
1026 MakeGroupsCheck->setEnabled(false);
1027 LineEditNewMesh->setEnabled(false);
1029 case COPY_ELEMS_BUTTON:
1030 LineEditNewMesh->setEnabled(false);
1031 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1032 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1033 MakeGroupsCheck->setEnabled(true);
1035 MakeGroupsCheck->setEnabled(false);
1037 case MAKE_MESH_BUTTON:
1038 LineEditNewMesh->setEnabled(true);
1039 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1040 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1041 MakeGroupsCheck->setEnabled(true);
1043 MakeGroupsCheck->setEnabled(false);
1049 //=======================================================================
1050 //function : setNewMeshName
1051 //purpose : update contents of LineEditNewMesh
1052 //=======================================================================
1054 void SMESHGUI_SymmetryDlg::setNewMeshName()
1056 LineEditNewMesh->setText("");
1057 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
1059 if ( CheckBoxMesh->isChecked() ) {
1060 name = LineEditElements->text();
1063 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
1064 name = meshSO->GetName().c_str();
1066 if ( !name.isEmpty() )
1067 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "mirrored"));
1071 //=================================================================================
1072 // function : keyPressEvent()
1074 //=================================================================================
1075 void SMESHGUI_SymmetryDlg::keyPressEvent( QKeyEvent* e )
1077 QDialog::keyPressEvent( e );
1078 if ( e->isAccepted() )
1081 if ( e->key() == Qt::Key_F1 ) {
1087 //=================================================================================
1088 // function : setFilters()
1089 // purpose : SLOT. Called when "Filter" button pressed.
1090 //=================================================================================
1091 void SMESHGUI_SymmetryDlg::setFilters()
1093 if(myMesh->_is_nil()) {
1094 SUIT_MessageBox::critical(this,
1096 tr("NO_MESH_SELECTED"));
1100 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1102 myFilterDlg->SetSelection();
1103 myFilterDlg->SetMesh( myMesh );
1104 myFilterDlg->SetSourceWg( LineEditElements );
1106 myFilterDlg->show();
1109 //=================================================================================
1110 // function : isValid
1112 //=================================================================================
1113 bool SMESHGUI_SymmetryDlg::isValid()
1118 ok = SpinBox_X->isValid( msg, true ) && ok;
1119 ok = SpinBox_Y->isValid( msg, true ) && ok;
1120 ok = SpinBox_Z->isValid( msg, true ) && ok;
1121 if (GetConstructorId() != 0) {
1122 ok = SpinBox_DX->isValid( msg, true ) && ok;
1123 ok = SpinBox_DY->isValid( msg, true ) && ok;
1124 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1128 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1129 if ( !msg.isEmpty() )
1131 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1137 //=================================================================================
1138 // function : onDisplaySimulation
1139 // purpose : Show/Hide preview
1140 //=================================================================================
1141 void SMESHGUI_SymmetryDlg::onDisplaySimulation( bool toDisplayPreview ) {
1142 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1143 if ( myNbOkElements && isValid() && IsMirrorOk() ) {
1144 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1145 SMESH::long_array_var anElementsId = new SMESH::long_array;
1147 anElementsId->length(aListElementsId.count());
1148 for (int i = 0; i < aListElementsId.count(); i++)
1149 anElementsId[i] = aListElementsId[i].toInt();
1151 SMESH::AxisStruct aMirror;
1152 SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
1154 getMirror(aMirror,aMirrorType);
1157 bool copy = ActionGroup->checkedId() == COPY_ELEMS_BUTTON;
1158 SUIT_OverrideCursor aWaitCursor;
1159 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
1160 if(CheckBoxMesh->isChecked())
1161 aMeshEditor->MirrorObject(mySelectedObject, aMirror, aMirrorType, copy );
1163 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, copy );
1165 SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
1166 mySimulation->SetData(aMeshPreviewStruct._retn());
1178 //=================================================================================
1179 // function : getMirror
1180 // purpose : return mirror parameters
1181 //=================================================================================
1182 void SMESHGUI_SymmetryDlg::getMirror(SMESH::AxisStruct& theMirror, SMESH::SMESH_MeshEditor::MirrorType& theMirrorType) {
1183 theMirror.x = SpinBox_X->GetValue();
1184 theMirror.y = SpinBox_Y->GetValue();
1185 theMirror.z = SpinBox_Z->GetValue();
1186 if (GetConstructorId() == 0) {
1187 theMirror.vx = theMirror.vy = theMirror.vz = 0;
1189 theMirror.vx = SpinBox_DX->GetValue();
1190 theMirror.vy = SpinBox_DY->GetValue();
1191 theMirror.vz = SpinBox_DZ->GetValue();
1193 if (GetConstructorId() == 0)
1194 theMirrorType = SMESH::SMESH_MeshEditor::POINT;
1195 if (GetConstructorId() == 1)
1196 theMirrorType = SMESH::SMESH_MeshEditor::AXIS;
1197 if (GetConstructorId() == 2)
1198 theMirrorType = SMESH::SMESH_MeshEditor::PLANE;