1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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.
26 #include "SMESHGUI_SymmetryDlg.h"
29 #include "SMESHGUI_SpinBox.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_IdValidator.h"
34 #include "SMESHGUI_FilterDlg.h"
35 #include "SMESHGUI_MeshEditPreview.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>
55 #include <SALOME_ListIteratorOfListIO.hxx>
57 // SALOME KERNEL includes
58 #include <SALOMEDSClient.hxx>
59 #include <SALOMEDSClient_SObject.hxx>
62 #include <TColStd_MapOfInteger.hxx>
65 #include <QApplication>
66 #include <QButtonGroup>
70 #include <QPushButton>
71 #include <QRadioButton>
73 #include <QHBoxLayout>
74 #include <QVBoxLayout>
75 #include <QGridLayout>
79 #include <SALOMEconfig.h>
80 #include CORBA_SERVER_HEADER(SMESH_Group)
81 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
83 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
88 //=================================================================================
89 // class : SMESHGUI_SymmetryDlg()
91 //=================================================================================
93 SMESHGUI_SymmetryDlg::SMESHGUI_SymmetryDlg( SMESHGUI* theModule )
94 : SMESHGUI_MultiPreviewDlg( theModule ),
95 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
98 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_POINT")));
99 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_AXIS")));
100 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_PLANE")));
101 QPixmap image3 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
104 setAttribute(Qt::WA_DeleteOnClose, true);
105 setWindowTitle(tr("SMESH_SYMMETRY"));
106 setSizeGripEnabled(true);
108 QVBoxLayout* SMESHGUI_SymmetryDlgLayout = new QVBoxLayout(this);
109 SMESHGUI_SymmetryDlgLayout->setSpacing(SPACING);
110 SMESHGUI_SymmetryDlgLayout->setMargin(MARGIN);
112 /***************************************************************/
113 ConstructorsBox = new QGroupBox(tr("SMESH_SYMMETRY"), this);
114 GroupConstructors = new QButtonGroup(this);
115 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
116 ConstructorsBoxLayout->setSpacing(SPACING);
117 ConstructorsBoxLayout->setMargin(MARGIN);
119 RadioButton1 = new QRadioButton(ConstructorsBox);
120 RadioButton1->setIcon(image0);
121 RadioButton2 = new QRadioButton(ConstructorsBox);
122 RadioButton2->setIcon(image1);
123 RadioButton3 = new QRadioButton(ConstructorsBox);
124 RadioButton3->setIcon(image2);
126 ConstructorsBoxLayout->addWidget(RadioButton1);
127 ConstructorsBoxLayout->addWidget(RadioButton2);
128 ConstructorsBoxLayout->addWidget(RadioButton3);
129 GroupConstructors->addButton(RadioButton1, 0);
130 GroupConstructors->addButton(RadioButton2, 1);
131 GroupConstructors->addButton(RadioButton3, 2);
133 /***************************************************************/
134 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
135 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
136 GroupArgumentsLayout->setSpacing(SPACING);
137 GroupArgumentsLayout->setMargin(MARGIN);
139 myIdValidator = new SMESHGUI_IdValidator(this);
141 // Controls for elements selection
142 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
143 SelectElementsButton = new QPushButton(GroupArguments);
144 SelectElementsButton->setIcon(image3);
145 LineEditElements = new QLineEdit(GroupArguments);
146 LineEditElements->setValidator(myIdValidator);
147 LineEditElements->setMaxLength(-1);
148 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
149 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
151 // Control for the whole mesh selection
152 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
154 // Controls for mirror selection
155 GroupMirror = new QGroupBox(GroupArguments);
156 QGridLayout* GroupMirrorLayout = new QGridLayout(GroupMirror);
157 GroupMirrorLayout->setSpacing(SPACING);
158 GroupMirrorLayout->setMargin(MARGIN);
160 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupMirror);
161 SelectPointButton = new QPushButton(GroupMirror);
162 SelectPointButton->setIcon(image3);
164 TextLabelX = new QLabel(tr("SMESH_X"), GroupMirror);
165 SpinBox_X = new SMESHGUI_SpinBox(GroupMirror);
166 TextLabelY = new QLabel(tr("SMESH_Y"), GroupMirror);
167 SpinBox_Y = new SMESHGUI_SpinBox(GroupMirror);
168 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupMirror);
169 SpinBox_Z = new SMESHGUI_SpinBox(GroupMirror);
171 TextLabelVector = new QLabel(GroupMirror);
172 SelectVectorButton = new QPushButton(GroupMirror);
173 SelectVectorButton->setIcon(image3);
175 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupMirror);
176 SpinBox_DX = new SMESHGUI_SpinBox(GroupMirror);
177 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupMirror);
178 SpinBox_DY = new SMESHGUI_SpinBox(GroupMirror);
179 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupMirror);
180 SpinBox_DZ = new SMESHGUI_SpinBox(GroupMirror);
182 GroupMirrorLayout->addWidget(TextLabelPoint, 0, 0);
183 GroupMirrorLayout->addWidget(SelectPointButton, 0, 1);
184 GroupMirrorLayout->addWidget(TextLabelX, 0, 2);
185 GroupMirrorLayout->addWidget(SpinBox_X, 0, 3);
186 GroupMirrorLayout->addWidget(TextLabelY, 0, 4);
187 GroupMirrorLayout->addWidget(SpinBox_Y, 0, 5);
188 GroupMirrorLayout->addWidget(TextLabelZ, 0, 6);
189 GroupMirrorLayout->addWidget(SpinBox_Z, 0, 7);
190 GroupMirrorLayout->addWidget(TextLabelVector, 1, 0);
191 GroupMirrorLayout->addWidget(SelectVectorButton, 1, 1);
192 GroupMirrorLayout->addWidget(TextLabelDX, 1, 2);
193 GroupMirrorLayout->addWidget(SpinBox_DX, 1, 3);
194 GroupMirrorLayout->addWidget(TextLabelDY, 1, 4);
195 GroupMirrorLayout->addWidget(SpinBox_DY, 1, 5);
196 GroupMirrorLayout->addWidget(TextLabelDZ, 1, 6);
197 GroupMirrorLayout->addWidget(SpinBox_DZ, 1, 7);
199 // switch of action type
200 ActionBox = new QGroupBox(GroupArguments);
201 ActionGroup = new QButtonGroup(GroupArguments);
202 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
203 ActionBoxLayout->addSpacing(SPACING);
204 ActionBoxLayout->setMargin(MARGIN);
206 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
207 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
208 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
210 ActionBoxLayout->addWidget(aMoveElements);
211 ActionBoxLayout->addWidget(aCopyElements);
212 ActionBoxLayout->addWidget(aCreateMesh);
213 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
214 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
215 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
217 // CheckBox for groups generation
218 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
219 MakeGroupsCheck->setChecked(false);
221 // Name of a mesh to create
222 LineEditNewMesh = new QLineEdit(GroupArguments);
226 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), 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);
238 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 6, 0);
240 /***************************************************************/
241 GroupButtons = new QGroupBox(this);
242 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
243 GroupButtonsLayout->setSpacing(SPACING);
244 GroupButtonsLayout->setMargin(MARGIN);
246 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
247 buttonOk->setAutoDefault(true);
248 buttonOk->setDefault(true);
249 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
250 buttonApply->setAutoDefault(true);
251 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
252 buttonCancel->setAutoDefault(true);
253 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
254 buttonHelp->setAutoDefault(true);
256 GroupButtonsLayout->addWidget(buttonOk);
257 GroupButtonsLayout->addSpacing(10);
258 GroupButtonsLayout->addWidget(buttonApply);
259 GroupButtonsLayout->addSpacing(10);
260 GroupButtonsLayout->addStretch();
261 GroupButtonsLayout->addWidget(buttonCancel);
262 GroupButtonsLayout->addWidget(buttonHelp);
264 /***************************************************************/
265 SMESHGUI_SymmetryDlgLayout->addWidget(ConstructorsBox);
266 SMESHGUI_SymmetryDlgLayout->addWidget(GroupArguments);
267 SMESHGUI_SymmetryDlgLayout->addWidget(GroupButtons);
269 /* Initialisations */
270 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
271 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
272 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
273 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
274 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
275 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
277 RadioButton1->setChecked(true);
279 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
281 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
283 // Costruction of the logical filter
284 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (SMESH::MESHorSUBMESH);
285 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (SMESH::GROUP);
287 QList<SUIT_SelectionFilter*> aListOfFilters;
288 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
289 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
291 myMeshOrSubMeshOrGroupFilter =
292 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
294 myHelpFileName = "symmetry_page.html";
298 /* signals and slots connections */
299 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
300 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
301 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
302 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
303 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
305 connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
306 connect(SelectPointButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
307 connect(SelectVectorButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
309 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
310 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
311 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
313 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
314 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
315 /* to close dialog if study change */
316 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(reject()));
317 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
318 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
319 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
321 connect(SpinBox_X, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
322 connect(SpinBox_Y, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
323 connect(SpinBox_Z, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
324 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
325 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
326 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
328 //To Connect preview check box
329 connectPreviewControl();
331 ConstructorsClicked(0);
332 SelectionIntoArgument();
333 onActionClicked(MOVE_ELEMS_BUTTON);
336 //=================================================================================
337 // function : ~SMESHGUI_SymmetryDlg()
338 // purpose : Destroys the object and frees any allocated resources
339 //=================================================================================
340 SMESHGUI_SymmetryDlg::~SMESHGUI_SymmetryDlg()
342 if ( myFilterDlg != 0 ) {
343 myFilterDlg->setParent( 0 );
348 //=================================================================================
351 //=================================================================================
352 void SMESHGUI_SymmetryDlg::Init (bool ResetControls)
357 myObjectsNames.clear();
359 myEditCurrentArgument = 0;
360 LineEditElements->clear();
364 buttonOk->setEnabled(false);
365 buttonApply->setEnabled(false);
370 SpinBox_X->SetValue(0.0);
371 SpinBox_Y->SetValue(0.0);
372 SpinBox_Z->SetValue(0.0);
373 SpinBox_DX->SetValue(0.0);
374 SpinBox_DY->SetValue(0.0);
375 SpinBox_DZ->SetValue(0.0);
377 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
378 CheckBoxMesh->setChecked(false);
379 myPreviewCheckBox->setChecked(false);
380 onDisplaySimulation(false);
382 // MakeGroupsCheck->setChecked(false);
383 // MakeGroupsCheck->setEnabled(false);
388 //=================================================================================
389 // function : ConstructorsClicked()
390 // purpose : Radio button management
391 //=================================================================================
392 void SMESHGUI_SymmetryDlg::ConstructorsClicked (int constructorId)
394 disconnect(mySelectionMgr, 0, this, 0);
396 if (constructorId != 0 && !TextLabelVector->isVisible()) {
397 TextLabelVector->show();
398 SelectVectorButton->show();
407 switch (constructorId) {
410 GroupMirror->setTitle(tr("SMESH_POINT"));
412 TextLabelVector->hide();
413 SelectVectorButton->hide();
424 GroupMirror->setTitle(tr("SMESH_AXIS"));
425 TextLabelVector->setText(tr("SMESH_VECTOR"));
430 GroupMirror->setTitle(tr("SMESH_PLANE"));
431 TextLabelVector->setText(tr("SMESH_NORMAL"));
436 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
437 SMESH::SetPointRepresentation(false);
438 if (!CheckBoxMesh->isChecked())
440 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
441 aViewWindow->SetSelectionMode(CellSelection);
445 myEditCurrentArgument = (QWidget*)LineEditElements;
446 LineEditElements->setFocus();
448 if (CheckBoxMesh->isChecked())
451 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
453 onDisplaySimulation(true);
455 QApplication::instance()->processEvents();
460 //=================================================================================
461 // function : ClickOnApply()
463 //=================================================================================
464 bool SMESHGUI_SymmetryDlg::ClickOnApply()
466 if (mySMESHGUI->isActiveStudyLocked())
472 if (myNbOkElements && IsMirrorOk()) {
473 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
475 SMESH::long_array_var anElementsId = new SMESH::long_array;
477 anElementsId->length(aListElementsId.count());
478 for (int i = 0; i < aListElementsId.count(); i++)
479 anElementsId[i] = aListElementsId[i].toInt();
481 SMESH::AxisStruct aMirror;
482 SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
483 getMirror(aMirror,aMirrorType);
485 QStringList aParameters;
486 aParameters << SpinBox_X->text();
487 aParameters << SpinBox_Y->text();
488 aParameters << SpinBox_Z->text();
489 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DX->text() );
490 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DY->text() );
491 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DZ->text() );
493 int actionButton = ActionGroup->checkedId();
494 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
495 QStringList anEntryList;
497 SUIT_OverrideCursor aWaitCursor;
499 switch ( actionButton ) {
500 case MOVE_ELEMS_BUTTON: {
501 if(CheckBoxMesh->isChecked())
502 for ( int i = 0; i < myObjects.count(); i++ ) {
503 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
504 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
505 aMeshEditor->MirrorObject(myObjects[i], aMirror, aMirrorType, false );
508 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
509 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
510 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, false );
514 case COPY_ELEMS_BUTTON: {
515 SMESH::ListOfGroups_var groups;
517 if(CheckBoxMesh->isChecked())
518 for ( int i = 0; i < myObjects.count(); i++ ) {
519 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
520 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
521 groups = aMeshEditor->MirrorObjectMakeGroups(myObjects[i], aMirror, aMirrorType);
524 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
525 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
526 groups = aMeshEditor->MirrorMakeGroups(anElementsId, aMirror, aMirrorType);
530 if(CheckBoxMesh->isChecked())
531 for ( int i = 0; i < myObjects.count(); i++ ) {
532 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
533 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
534 aMeshEditor->MirrorObject(myObjects[i], aMirror, aMirrorType, true);
537 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
538 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
539 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, true);
544 case MAKE_MESH_BUTTON: {
545 SMESH::SMESH_Mesh_var mesh;
546 if (CheckBoxMesh->isChecked())
547 for ( int i = 0; i < myObjects.count(); i++ ) {
548 QString aName = SMESH::UniqueMeshName( LineEditNewMesh->text().replace( "*", myObjectsNames[i] ) );
549 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
550 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
551 mesh = aMeshEditor->MirrorObjectMakeMesh(myObjects[i], aMirror, aMirrorType, makeGroups,
552 aName.toLatin1().data());
553 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
554 anEntryList.append( aSObject->GetID().c_str() );
557 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
558 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
559 mesh = aMeshEditor->MirrorMakeMesh(anElementsId, aMirror, aMirrorType, makeGroups,
560 LineEditNewMesh->text().toLatin1().data());
561 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
562 anEntryList.append( aSObject->GetID().c_str() );
570 for ( int i = 0; i < myObjects.count(); i++ ) {
571 SMESH_Actor* actor = SMESH::FindActorByObject( myObjects[i] );
572 if ( actor ) SMESH::Update( actor->getIO(), true );
575 if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
576 actionButton == MAKE_MESH_BUTTON ) {
577 mySMESHGUI->updateObjBrowser(true); // new groups may appear
578 if( LightApp_Application* anApp =
579 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
580 anApp->browseObjects( anEntryList, isApplyAndClose() );
583 ConstructorsClicked(GetConstructorId());
584 SelectionIntoArgument();
586 SMESHGUI::Modified();
591 //=================================================================================
592 // function : ClickOnOk()
594 //=================================================================================
595 void SMESHGUI_SymmetryDlg::ClickOnOk()
597 setIsApplyAndClose( true );
602 //=================================================================================
603 // function : reject()
605 //=================================================================================
606 void SMESHGUI_SymmetryDlg::reject()
608 disconnect(mySelectionMgr, 0, this, 0);
609 mySelectionMgr->clearFilters();
610 //mySelectionMgr->clearSelected();
611 if (SMESH::GetCurrentVtkView()) {
612 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
613 SMESH::SetPointRepresentation(false);
615 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
616 aViewWindow->SetSelectionMode(ActorSelection);
617 mySMESHGUI->ResetState();
621 //=================================================================================
622 // function : ClickOnHelp()
624 //=================================================================================
625 void SMESHGUI_SymmetryDlg::ClickOnHelp()
627 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
629 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
633 platform = "winapplication";
635 platform = "application";
637 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
638 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
639 arg(app->resourceMgr()->stringValue("ExternalBrowser",
641 arg(myHelpFileName));
645 //=======================================================================
646 // function : onTextChange()
648 //=======================================================================
649 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
651 QLineEdit* send = (QLineEdit*)sender();
656 if (send == LineEditElements)
659 buttonOk->setEnabled(false);
660 buttonApply->setEnabled(false);
662 // hilight entered elements
663 SMDS_Mesh* aMesh = 0;
665 aMesh = myActor->GetObject()->GetMesh();
668 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
670 TColStd_MapOfInteger newIndices;
672 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
674 if (send == LineEditElements) {
675 for (int i = 0; i < aListId.count(); i++) {
676 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
678 newIndices.Add(e->GetID());
682 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
683 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
684 aViewWindow->highlight( anIO, true, true );
686 myElementsId = theNewText;
690 if (myNbOkElements && IsMirrorOk()) {
691 buttonOk->setEnabled(true);
692 buttonApply->setEnabled(true);
698 //=================================================================================
699 // function : SelectionIntoArgument()
700 // purpose : Called when selection as changed or other case
701 //=================================================================================
702 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
708 QString aString = "";
709 onDisplaySimulation(false);
712 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
713 LineEditElements->setText(aString);
715 buttonOk->setEnabled(false);
716 buttonApply->setEnabled(false);
720 if (!GroupButtons->isEnabled()) // inactive
725 mySelectionMgr->selectedObjects(aList);
727 int nbSel = aList.Extent();
733 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
736 myObjectsNames.clear();
739 for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() ) {
740 Handle(SALOME_InteractiveObject) IO = it.Value();
742 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( IO );
743 if( aMesh->_is_nil() )
746 myActor = SMESH::FindActorByObject( aMesh );
748 myActor = SMESH::FindActorByEntry( IO->getEntry() );
749 if ( !myActor && !CheckBoxMesh->isChecked() )
752 if ( !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO )->_is_nil() ) {
753 if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() ) {
754 _PTR(SObject) obj = aStudy->FindObjectID( qPrintable( QString( IO->getEntry() ) ) );
755 _PTR(GenericAttribute) anAttr;
756 if ( obj && obj->FindAttribute( anAttr, "AttributeName" ) ) {
757 _PTR(AttributeName) aNameAttr( anAttr );
758 myObjects << SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
759 myObjectsNames << aNameAttr->Value().c_str();
766 // MakeGroups is available if there are groups and "Copy"
768 for ( int i = 0; i < myMeshes.count(); i++ )
769 aNbGroups += myMeshes[i]->NbGroups();
771 if ( aNbGroups == 0 ) {
772 MakeGroupsCheck->setChecked(false);
773 MakeGroupsCheck->setEnabled(false);
775 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
776 MakeGroupsCheck->setEnabled(true);
778 if (CheckBoxMesh->isChecked()) {
779 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
781 if ( myObjects.isEmpty() )
785 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
789 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
790 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
792 myElementsId += QString(" %1").arg(i);
796 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
798 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
800 // get IDs from submesh
802 SMESH::long_array_var anElementsIds = new SMESH::long_array;
803 anElementsIds = aSubMesh->GetElementsId();
804 for (int i = 0; i < anElementsIds->length(); i++) {
805 myElementsId += QString(" %1").arg(anElementsIds[i]);
807 aNbUnits = anElementsIds->length();
810 SMESH::SMESH_GroupBase_var aGroup =
811 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
812 if (aGroup->_is_nil())
815 // get IDs from smesh group
816 SMESH::long_array_var anElementsIds = new SMESH::long_array;
817 anElementsIds = aGroup->GetListOfID();
818 for (int i = 0; i < anElementsIds->length(); i++) {
819 myElementsId += QString(" %1").arg(anElementsIds[i]);
821 aNbUnits = anElementsIds->length();
825 aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, aList.First(), aString);
826 myElementsId = aString;
831 myNbOkElements = true;
833 Handle(SALOME_InteractiveObject) IO = aList.First();
834 if ((SMESH::GetMeshByIO(IO))->_is_nil())
837 SMESH_Actor* anActor = SMESH::FindActorByObject(SMESH::GetMeshByIO(IO));
839 anActor = SMESH::FindActorByEntry(IO->getEntry());
840 if (!anActor && !CheckBoxMesh->isChecked())
843 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
847 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
851 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
859 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
860 SpinBox_X->SetValue(x);
861 SpinBox_Y->SetValue(y);
862 SpinBox_Z->SetValue(z);
863 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
864 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
865 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
866 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
871 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
872 LineEditElements->setText(aString);
873 LineEditElements->repaint();
874 LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
875 LineEditElements->setEnabled(true);
881 if (myNbOkElements && IsMirrorOk()) {
882 buttonOk->setEnabled(true);
883 buttonApply->setEnabled(true);
885 onDisplaySimulation(true);
888 //=================================================================================
889 // function : SetEditCurrentArgument()
891 //=================================================================================
892 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
894 QPushButton* send = (QPushButton*)sender();
896 disconnect(mySelectionMgr, 0, this, 0);
897 mySelectionMgr->clearSelected();
898 mySelectionMgr->clearFilters();
900 if (send == SelectElementsButton) {
901 myEditCurrentArgument = (QWidget*)LineEditElements;
902 SMESH::SetPointRepresentation(false);
903 if (CheckBoxMesh->isChecked()) {
904 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
905 aViewWindow->SetSelectionMode(ActorSelection);
906 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
908 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
909 aViewWindow->SetSelectionMode(CellSelection);
911 } else if (send == SelectPointButton) {
912 myEditCurrentArgument = (QWidget*)SpinBox_X;
913 SMESH::SetPointRepresentation(true);
914 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
915 aViewWindow->SetSelectionMode(NodeSelection);
916 } else if (send == SelectVectorButton) {
917 myEditCurrentArgument = (QWidget*)SpinBox_DX;
918 SMESH::SetPointRepresentation(true);
920 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
921 aViewWindow->SetSelectionMode(NodeSelection);
925 myEditCurrentArgument->setFocus();
926 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
927 SelectionIntoArgument();
930 //=================================================================================
931 // function : DeactivateActiveDialog()
933 //=================================================================================
934 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
936 if (ConstructorsBox->isEnabled()) {
937 ConstructorsBox->setEnabled(false);
938 GroupArguments->setEnabled(false);
939 GroupButtons->setEnabled(false);
940 mySMESHGUI->ResetState();
941 mySMESHGUI->SetActiveDialogBox(0);
945 //=================================================================================
946 // function : ActivateThisDialog()
948 //=================================================================================
949 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
951 /* Emit a signal to deactivate the active dialog */
952 mySMESHGUI->EmitSignalDeactivateDialog();
953 ConstructorsBox->setEnabled(true);
954 GroupArguments->setEnabled(true);
955 GroupButtons->setEnabled(true);
957 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
959 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
960 aViewWindow->SetSelectionMode(CellSelection);
961 SelectionIntoArgument();
964 //=================================================================================
965 // function : enterEvent()
967 //=================================================================================
968 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
970 if (!ConstructorsBox->isEnabled())
971 ActivateThisDialog();
974 //=======================================================================
975 //function : onSelectMesh
977 //=======================================================================
978 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
981 TextLabelElements->setText(tr("SMESH_NAME"));
983 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
984 myFilterBtn->setEnabled(!toSelectMesh);
986 if (myEditCurrentArgument != LineEditElements) {
987 LineEditElements->clear();
991 mySelectionMgr->clearFilters();
992 SMESH::SetPointRepresentation(false);
995 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
996 aViewWindow->SetSelectionMode(ActorSelection);
997 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
998 LineEditElements->setReadOnly(true);
999 LineEditElements->setValidator(0);
1001 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1002 aViewWindow->SetSelectionMode(CellSelection);
1003 LineEditElements->setReadOnly(false);
1004 LineEditElements->setValidator(myIdValidator);
1005 onTextChange(LineEditElements->text());
1009 SelectionIntoArgument();
1012 //=================================================================================
1013 // function : GetConstructorId()
1015 //=================================================================================
1016 int SMESHGUI_SymmetryDlg::GetConstructorId()
1018 return GroupConstructors->checkedId();
1021 //=================================================================================
1022 // function : IsMirrorOk()
1024 //=================================================================================
1025 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
1029 if (GetConstructorId() != 0)
1030 isOk = (SpinBox_DX->GetValue() != 0 ||
1031 SpinBox_DY->GetValue() != 0 ||
1032 SpinBox_DZ->GetValue() != 0);
1037 //=================================================================================
1038 // function : onVectorChanged()
1040 //=================================================================================
1041 void SMESHGUI_SymmetryDlg::onVectorChanged()
1044 buttonOk->setEnabled(true);
1045 buttonApply->setEnabled(true);
1047 buttonOk->setEnabled(false);
1048 buttonApply->setEnabled(false);
1052 //=======================================================================
1053 //function : onActionClicked
1054 //purpose : slot called when an action type changed
1055 //=======================================================================
1057 void SMESHGUI_SymmetryDlg::onActionClicked(int button)
1060 for ( int i = 0; i < myMeshes.count(); i++ )
1061 aNbGroups += myMeshes[i]->NbGroups();
1064 case MOVE_ELEMS_BUTTON:
1065 MakeGroupsCheck->setEnabled(false);
1066 LineEditNewMesh->setEnabled(false);
1068 case COPY_ELEMS_BUTTON:
1069 LineEditNewMesh->setEnabled(false);
1070 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1071 MakeGroupsCheck->setEnabled(myMeshes.isEmpty() || aNbGroups > 0);
1073 case MAKE_MESH_BUTTON:
1074 LineEditNewMesh->setEnabled(true);
1075 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1076 MakeGroupsCheck->setEnabled(myMeshes.isEmpty() || aNbGroups > 0);
1080 toDisplaySimulation();
1083 //=======================================================================
1084 //function : setNewMeshName
1085 //purpose : update contents of LineEditNewMesh
1086 //=======================================================================
1088 void SMESHGUI_SymmetryDlg::setNewMeshName()
1090 LineEditNewMesh->setText("");
1091 if ( LineEditNewMesh->isEnabled() && !myMeshes.isEmpty() ) {
1093 if ( CheckBoxMesh->isChecked() ) {
1094 name = myObjects.count() > 1 ? "*" : LineEditElements->text();
1097 _PTR(SObject) meshSO = SMESH::FindSObject( myMeshes[0] );
1098 name = meshSO->GetName().c_str();
1100 if ( !name.isEmpty() )
1101 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "mirrored"));
1105 //=================================================================================
1106 // function : keyPressEvent()
1108 //=================================================================================
1109 void SMESHGUI_SymmetryDlg::keyPressEvent( QKeyEvent* e )
1111 QDialog::keyPressEvent( e );
1112 if ( e->isAccepted() )
1115 if ( e->key() == Qt::Key_F1 ) {
1121 //=================================================================================
1122 // function : setFilters()
1123 // purpose : SLOT. Called when "Filter" button pressed.
1124 //=================================================================================
1125 void SMESHGUI_SymmetryDlg::setFilters()
1127 if(myMeshes.isEmpty()) {
1128 SUIT_MessageBox::critical(this,
1130 tr("NO_MESH_SELECTED"));
1134 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1136 myFilterDlg->SetSelection();
1137 myFilterDlg->SetMesh( myMeshes[0] );
1138 myFilterDlg->SetSourceWg( LineEditElements );
1140 myFilterDlg->show();
1143 //=================================================================================
1144 // function : isValid
1146 //=================================================================================
1147 bool SMESHGUI_SymmetryDlg::isValid()
1152 ok = SpinBox_X->isValid( msg, true ) && ok;
1153 ok = SpinBox_Y->isValid( msg, true ) && ok;
1154 ok = SpinBox_Z->isValid( msg, true ) && ok;
1155 if (GetConstructorId() != 0) {
1156 ok = SpinBox_DX->isValid( msg, true ) && ok;
1157 ok = SpinBox_DY->isValid( msg, true ) && ok;
1158 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1162 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1163 if ( !msg.isEmpty() )
1165 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1171 //=================================================================================
1172 // function : onDisplaySimulation
1173 // purpose : Show/Hide preview
1174 //=================================================================================
1175 void SMESHGUI_SymmetryDlg::onDisplaySimulation( bool toDisplayPreview ) {
1176 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1177 if ( myNbOkElements && isValid() && IsMirrorOk() ) {
1178 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1179 SMESH::long_array_var anElementsId = new SMESH::long_array;
1181 anElementsId->length(aListElementsId.count());
1182 for (int i = 0; i < aListElementsId.count(); i++)
1183 anElementsId[i] = aListElementsId[i].toInt();
1185 SMESH::AxisStruct aMirror;
1186 SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
1188 getMirror(aMirror,aMirrorType);
1191 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1192 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1193 SUIT_OverrideCursor aWaitCursor;
1194 QList<SMESH::MeshPreviewStruct_var> aMeshPreviewStruct;
1195 if(CheckBoxMesh->isChecked())
1196 for ( int i = 0; i < myMeshes.count(); i++ ) {
1197 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditPreviewer();
1198 aMeshEditor->MirrorObject(myObjects[i], aMirror, aMirrorType, copy );
1199 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1202 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditPreviewer();
1203 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, copy );
1204 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1206 setSimulationPreview(aMeshPreviewStruct);
1218 //=================================================================================
1219 // function : getMirror
1220 // purpose : return mirror parameters
1221 //=================================================================================
1222 void SMESHGUI_SymmetryDlg::getMirror(SMESH::AxisStruct& theMirror, SMESH::SMESH_MeshEditor::MirrorType& theMirrorType) {
1223 theMirror.x = SpinBox_X->GetValue();
1224 theMirror.y = SpinBox_Y->GetValue();
1225 theMirror.z = SpinBox_Z->GetValue();
1226 if (GetConstructorId() == 0) {
1227 theMirror.vx = theMirror.vy = theMirror.vz = 0;
1229 theMirror.vx = SpinBox_DX->GetValue();
1230 theMirror.vy = SpinBox_DY->GetValue();
1231 theMirror.vz = SpinBox_DZ->GetValue();
1233 if (GetConstructorId() == 0)
1234 theMirrorType = SMESH::SMESH_MeshEditor::POINT;
1235 if (GetConstructorId() == 1)
1236 theMirrorType = SMESH::SMESH_MeshEditor::AXIS;
1237 if (GetConstructorId() == 2)
1238 theMirrorType = SMESH::SMESH_MeshEditor::PLANE;