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>
56 // SALOME KERNEL includes
57 #include <SALOMEDSClient.hxx>
58 #include <SALOMEDSClient_SObject.hxx>
61 #include <TColStd_MapOfInteger.hxx>
64 #include <QApplication>
65 #include <QButtonGroup>
69 #include <QPushButton>
70 #include <QRadioButton>
72 #include <QHBoxLayout>
73 #include <QVBoxLayout>
74 #include <QGridLayout>
78 #include <SALOMEconfig.h>
79 #include CORBA_SERVER_HEADER(SMESH_Group)
80 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
82 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
87 //=================================================================================
88 // class : SMESHGUI_SymmetryDlg()
90 //=================================================================================
92 SMESHGUI_SymmetryDlg::SMESHGUI_SymmetryDlg( SMESHGUI* theModule )
93 : SMESHGUI_MultiPreviewDlg( theModule ),
94 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
97 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_POINT")));
98 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_AXIS")));
99 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_PLANE")));
100 QPixmap image3 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
103 setAttribute(Qt::WA_DeleteOnClose, true);
104 setWindowTitle(tr("SMESH_SYMMETRY"));
105 setSizeGripEnabled(true);
107 QVBoxLayout* SMESHGUI_SymmetryDlgLayout = new QVBoxLayout(this);
108 SMESHGUI_SymmetryDlgLayout->setSpacing(SPACING);
109 SMESHGUI_SymmetryDlgLayout->setMargin(MARGIN);
111 /***************************************************************/
112 ConstructorsBox = new QGroupBox(tr("SMESH_SYMMETRY"), this);
113 GroupConstructors = new QButtonGroup(this);
114 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
115 ConstructorsBoxLayout->setSpacing(SPACING);
116 ConstructorsBoxLayout->setMargin(MARGIN);
118 RadioButton1 = new QRadioButton(ConstructorsBox);
119 RadioButton1->setIcon(image0);
120 RadioButton2 = new QRadioButton(ConstructorsBox);
121 RadioButton2->setIcon(image1);
122 RadioButton3 = new QRadioButton(ConstructorsBox);
123 RadioButton3->setIcon(image2);
125 ConstructorsBoxLayout->addWidget(RadioButton1);
126 ConstructorsBoxLayout->addWidget(RadioButton2);
127 ConstructorsBoxLayout->addWidget(RadioButton3);
128 GroupConstructors->addButton(RadioButton1, 0);
129 GroupConstructors->addButton(RadioButton2, 1);
130 GroupConstructors->addButton(RadioButton3, 2);
132 /***************************************************************/
133 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
134 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
135 GroupArgumentsLayout->setSpacing(SPACING);
136 GroupArgumentsLayout->setMargin(MARGIN);
138 myIdValidator = new SMESHGUI_IdValidator(this);
140 // Controls for elements selection
141 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
142 SelectElementsButton = new QPushButton(GroupArguments);
143 SelectElementsButton->setIcon(image3);
144 LineEditElements = new QLineEdit(GroupArguments);
145 LineEditElements->setValidator(myIdValidator);
146 LineEditElements->setMaxLength(-1);
147 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
148 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
150 // Control for the whole mesh selection
151 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
153 // Controls for mirror selection
154 GroupMirror = new QGroupBox(GroupArguments);
155 QGridLayout* GroupMirrorLayout = new QGridLayout(GroupMirror);
156 GroupMirrorLayout->setSpacing(SPACING);
157 GroupMirrorLayout->setMargin(MARGIN);
159 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupMirror);
160 SelectPointButton = new QPushButton(GroupMirror);
161 SelectPointButton->setIcon(image3);
163 TextLabelX = new QLabel(tr("SMESH_X"), GroupMirror);
164 SpinBox_X = new SMESHGUI_SpinBox(GroupMirror);
165 TextLabelY = new QLabel(tr("SMESH_Y"), GroupMirror);
166 SpinBox_Y = new SMESHGUI_SpinBox(GroupMirror);
167 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupMirror);
168 SpinBox_Z = new SMESHGUI_SpinBox(GroupMirror);
170 TextLabelVector = new QLabel(GroupMirror);
171 SelectVectorButton = new QPushButton(GroupMirror);
172 SelectVectorButton->setIcon(image3);
174 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupMirror);
175 SpinBox_DX = new SMESHGUI_SpinBox(GroupMirror);
176 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupMirror);
177 SpinBox_DY = new SMESHGUI_SpinBox(GroupMirror);
178 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupMirror);
179 SpinBox_DZ = new SMESHGUI_SpinBox(GroupMirror);
181 GroupMirrorLayout->addWidget(TextLabelPoint, 0, 0);
182 GroupMirrorLayout->addWidget(SelectPointButton, 0, 1);
183 GroupMirrorLayout->addWidget(TextLabelX, 0, 2);
184 GroupMirrorLayout->addWidget(SpinBox_X, 0, 3);
185 GroupMirrorLayout->addWidget(TextLabelY, 0, 4);
186 GroupMirrorLayout->addWidget(SpinBox_Y, 0, 5);
187 GroupMirrorLayout->addWidget(TextLabelZ, 0, 6);
188 GroupMirrorLayout->addWidget(SpinBox_Z, 0, 7);
189 GroupMirrorLayout->addWidget(TextLabelVector, 1, 0);
190 GroupMirrorLayout->addWidget(SelectVectorButton, 1, 1);
191 GroupMirrorLayout->addWidget(TextLabelDX, 1, 2);
192 GroupMirrorLayout->addWidget(SpinBox_DX, 1, 3);
193 GroupMirrorLayout->addWidget(TextLabelDY, 1, 4);
194 GroupMirrorLayout->addWidget(SpinBox_DY, 1, 5);
195 GroupMirrorLayout->addWidget(TextLabelDZ, 1, 6);
196 GroupMirrorLayout->addWidget(SpinBox_DZ, 1, 7);
198 // switch of action type
199 ActionBox = new QGroupBox(GroupArguments);
200 ActionGroup = new QButtonGroup(GroupArguments);
201 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
202 ActionBoxLayout->addSpacing(SPACING);
203 ActionBoxLayout->setMargin(MARGIN);
205 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
206 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
207 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
209 ActionBoxLayout->addWidget(aMoveElements);
210 ActionBoxLayout->addWidget(aCopyElements);
211 ActionBoxLayout->addWidget(aCreateMesh);
212 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
213 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
214 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
216 // CheckBox for groups generation
217 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
218 MakeGroupsCheck->setChecked(false);
220 // Name of a mesh to create
221 LineEditNewMesh = new QLineEdit(GroupArguments);
225 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
228 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
229 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
230 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 1);
231 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 3);
232 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
233 GroupArgumentsLayout->addWidget(GroupMirror, 2, 0, 1, 4);
234 GroupArgumentsLayout->addWidget(ActionBox, 3, 0, 3, 3);
235 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 4, 3);
236 GroupArgumentsLayout->addWidget(LineEditNewMesh, 5, 3);
237 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 6, 0);
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 (SMESH::MESHorSUBMESH);
284 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (SMESH::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(reject()));
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(reject()));
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 connect(SpinBox_X, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
321 connect(SpinBox_Y, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
322 connect(SpinBox_Z, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
323 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
324 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
325 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
327 //To Connect preview check box
328 connectPreviewControl();
330 ConstructorsClicked(0);
331 SelectionIntoArgument();
332 onActionClicked(MOVE_ELEMS_BUTTON);
335 //=================================================================================
336 // function : ~SMESHGUI_SymmetryDlg()
337 // purpose : Destroys the object and frees any allocated resources
338 //=================================================================================
339 SMESHGUI_SymmetryDlg::~SMESHGUI_SymmetryDlg()
341 if ( myFilterDlg != 0 ) {
342 myFilterDlg->setParent( 0 );
347 //=================================================================================
350 //=================================================================================
351 void SMESHGUI_SymmetryDlg::Init (bool ResetControls)
356 myObjectsNames.clear();
358 myEditCurrentArgument = 0;
359 LineEditElements->clear();
363 buttonOk->setEnabled(false);
364 buttonApply->setEnabled(false);
369 SpinBox_X->SetValue(0.0);
370 SpinBox_Y->SetValue(0.0);
371 SpinBox_Z->SetValue(0.0);
372 SpinBox_DX->SetValue(0.0);
373 SpinBox_DY->SetValue(0.0);
374 SpinBox_DZ->SetValue(0.0);
376 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
377 CheckBoxMesh->setChecked(false);
378 myPreviewCheckBox->setChecked(false);
379 onDisplaySimulation(false);
381 // MakeGroupsCheck->setChecked(false);
382 // MakeGroupsCheck->setEnabled(false);
387 //=================================================================================
388 // function : ConstructorsClicked()
389 // purpose : Radio button management
390 //=================================================================================
391 void SMESHGUI_SymmetryDlg::ConstructorsClicked (int constructorId)
393 disconnect(mySelectionMgr, 0, this, 0);
395 if (constructorId != 0 && !TextLabelVector->isVisible()) {
396 TextLabelVector->show();
397 SelectVectorButton->show();
406 switch (constructorId) {
409 GroupMirror->setTitle(tr("SMESH_POINT"));
411 TextLabelVector->hide();
412 SelectVectorButton->hide();
423 GroupMirror->setTitle(tr("SMESH_AXIS"));
424 TextLabelVector->setText(tr("SMESH_VECTOR"));
429 GroupMirror->setTitle(tr("SMESH_PLANE"));
430 TextLabelVector->setText(tr("SMESH_NORMAL"));
435 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
436 SMESH::SetPointRepresentation(false);
437 if (!CheckBoxMesh->isChecked())
439 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
440 aViewWindow->SetSelectionMode(CellSelection);
444 myEditCurrentArgument = (QWidget*)LineEditElements;
445 LineEditElements->setFocus();
447 if (CheckBoxMesh->isChecked())
450 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
452 onDisplaySimulation(true);
454 QApplication::instance()->processEvents();
455 myEditCurrentArgument->hide();
456 myEditCurrentArgument->show();
461 //=================================================================================
462 // function : ClickOnApply()
464 //=================================================================================
465 bool SMESHGUI_SymmetryDlg::ClickOnApply()
467 if (mySMESHGUI->isActiveStudyLocked())
473 if (myNbOkElements && IsMirrorOk()) {
474 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
476 SMESH::long_array_var anElementsId = new SMESH::long_array;
478 anElementsId->length(aListElementsId.count());
479 for (int i = 0; i < aListElementsId.count(); i++)
480 anElementsId[i] = aListElementsId[i].toInt();
482 SMESH::AxisStruct aMirror;
483 SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
484 getMirror(aMirror,aMirrorType);
486 QStringList aParameters;
487 aParameters << SpinBox_X->text();
488 aParameters << SpinBox_Y->text();
489 aParameters << SpinBox_Z->text();
490 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DX->text() );
491 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DY->text() );
492 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DZ->text() );
494 int actionButton = ActionGroup->checkedId();
495 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
496 QStringList anEntryList;
498 SUIT_OverrideCursor aWaitCursor;
500 switch ( actionButton ) {
501 case MOVE_ELEMS_BUTTON: {
502 if(CheckBoxMesh->isChecked())
503 for ( int i = 0; i < myObjects.count(); i++ ) {
504 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
505 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
506 aMeshEditor->MirrorObject(myObjects[i], aMirror, aMirrorType, false );
509 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
510 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
511 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, false );
515 case COPY_ELEMS_BUTTON: {
516 SMESH::ListOfGroups_var groups;
518 if(CheckBoxMesh->isChecked())
519 for ( int i = 0; i < myObjects.count(); i++ ) {
520 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
521 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
522 groups = aMeshEditor->MirrorObjectMakeGroups(myObjects[i], aMirror, aMirrorType);
525 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
526 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
527 groups = aMeshEditor->MirrorMakeGroups(anElementsId, aMirror, aMirrorType);
531 if(CheckBoxMesh->isChecked())
532 for ( int i = 0; i < myObjects.count(); i++ ) {
533 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
534 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
535 aMeshEditor->MirrorObject(myObjects[i], aMirror, aMirrorType, true);
538 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
539 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
540 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, true);
545 case MAKE_MESH_BUTTON: {
546 SMESH::SMESH_Mesh_var mesh;
547 if (CheckBoxMesh->isChecked())
548 for ( int i = 0; i < myObjects.count(); i++ ) {
549 QString aName = SMESH::UniqueMeshName( LineEditNewMesh->text().replace( "*", myObjectsNames[i] ) );
550 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
551 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
552 mesh = aMeshEditor->MirrorObjectMakeMesh(myObjects[i], aMirror, aMirrorType, makeGroups,
553 aName.toLatin1().data());
554 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
555 anEntryList.append( aSObject->GetID().c_str() );
558 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
559 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
560 mesh = aMeshEditor->MirrorMakeMesh(anElementsId, aMirror, aMirrorType, makeGroups,
561 LineEditNewMesh->text().toLatin1().data());
562 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
563 anEntryList.append( aSObject->GetID().c_str() );
571 for ( int i = 0; i < myObjects.count(); i++ ) {
572 SMESH_Actor* actor = SMESH::FindActorByObject( myObjects[i] );
573 if ( actor ) SMESH::Update( actor->getIO(), true );
576 if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
577 actionButton == MAKE_MESH_BUTTON ) {
578 mySMESHGUI->updateObjBrowser(true); // new groups may appear
579 if( LightApp_Application* anApp =
580 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
581 anApp->browseObjects( anEntryList, isApplyAndClose() );
584 ConstructorsClicked(GetConstructorId());
585 SelectionIntoArgument();
587 SMESHGUI::Modified();
592 //=================================================================================
593 // function : ClickOnOk()
595 //=================================================================================
596 void SMESHGUI_SymmetryDlg::ClickOnOk()
598 setIsApplyAndClose( true );
603 //=================================================================================
604 // function : reject()
606 //=================================================================================
607 void SMESHGUI_SymmetryDlg::reject()
609 disconnect(mySelectionMgr, 0, this, 0);
610 mySelectionMgr->clearFilters();
611 //mySelectionMgr->clearSelected();
612 if (SMESH::GetCurrentVtkView()) {
613 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
614 SMESH::SetPointRepresentation(false);
616 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
617 aViewWindow->SetSelectionMode(ActorSelection);
618 mySMESHGUI->ResetState();
622 //=================================================================================
623 // function : ClickOnHelp()
625 //=================================================================================
626 void SMESHGUI_SymmetryDlg::ClickOnHelp()
628 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
630 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
634 platform = "winapplication";
636 platform = "application";
638 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
639 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
640 arg(app->resourceMgr()->stringValue("ExternalBrowser",
642 arg(myHelpFileName));
646 //=======================================================================
647 // function : onTextChange()
649 //=======================================================================
650 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
652 QLineEdit* send = (QLineEdit*)sender();
657 if (send == LineEditElements)
660 buttonOk->setEnabled(false);
661 buttonApply->setEnabled(false);
663 // hilight entered elements
664 SMDS_Mesh* aMesh = 0;
666 aMesh = myActor->GetObject()->GetMesh();
669 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
671 TColStd_MapOfInteger newIndices;
673 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
675 if (send == LineEditElements) {
676 for (int i = 0; i < aListId.count(); i++) {
677 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
679 newIndices.Add(e->GetID());
683 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
684 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
685 aViewWindow->highlight( anIO, true, true );
687 myElementsId = theNewText;
691 if (myNbOkElements && IsMirrorOk()) {
692 buttonOk->setEnabled(true);
693 buttonApply->setEnabled(true);
699 //=================================================================================
700 // function : SelectionIntoArgument()
701 // purpose : Called when selection as changed or other case
702 //=================================================================================
703 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
709 QString aString = "";
710 onDisplaySimulation(false);
713 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
714 LineEditElements->setText(aString);
716 buttonOk->setEnabled(false);
717 buttonApply->setEnabled(false);
721 if (!GroupButtons->isEnabled()) // inactive
726 mySelectionMgr->selectedObjects(aList);
728 int nbSel = aList.Extent();
734 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
737 myObjectsNames.clear();
740 for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() ) {
741 Handle(SALOME_InteractiveObject) IO = it.Value();
743 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( IO );
744 if( aMesh->_is_nil() )
747 myActor = SMESH::FindActorByObject( aMesh );
749 myActor = SMESH::FindActorByEntry( IO->getEntry() );
750 if ( !myActor && !CheckBoxMesh->isChecked() )
753 if ( !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO )->_is_nil() ) {
754 if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() ) {
755 _PTR(SObject) obj = aStudy->FindObjectID( qPrintable( QString( IO->getEntry() ) ) );
756 _PTR(GenericAttribute) anAttr;
757 if ( obj && obj->FindAttribute( anAttr, "AttributeName" ) ) {
758 _PTR(AttributeName) aNameAttr( anAttr );
759 myObjects << SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
760 myObjectsNames << aNameAttr->Value().c_str();
767 // MakeGroups is available if there are groups and "Copy"
769 for ( int i = 0; i < myMeshes.count(); i++ )
770 aNbGroups += myMeshes[i]->NbGroups();
772 if ( aNbGroups == 0 ) {
773 MakeGroupsCheck->setChecked(false);
774 MakeGroupsCheck->setEnabled(false);
776 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
777 MakeGroupsCheck->setEnabled(true);
779 if (CheckBoxMesh->isChecked()) {
780 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
782 if ( myObjects.isEmpty() )
786 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
790 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
791 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
793 myElementsId += QString(" %1").arg(i);
797 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
799 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
801 // get IDs from submesh
803 SMESH::long_array_var anElementsIds = new SMESH::long_array;
804 anElementsIds = aSubMesh->GetElementsId();
805 for (int i = 0; i < anElementsIds->length(); i++) {
806 myElementsId += QString(" %1").arg(anElementsIds[i]);
808 aNbUnits = anElementsIds->length();
811 SMESH::SMESH_GroupBase_var aGroup =
812 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
813 if (aGroup->_is_nil())
816 // get IDs from smesh group
817 SMESH::long_array_var anElementsIds = new SMESH::long_array;
818 anElementsIds = aGroup->GetListOfID();
819 for (int i = 0; i < anElementsIds->length(); i++) {
820 myElementsId += QString(" %1").arg(anElementsIds[i]);
822 aNbUnits = anElementsIds->length();
826 aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, aList.First(), aString);
827 myElementsId = aString;
832 myNbOkElements = true;
834 Handle(SALOME_InteractiveObject) IO = aList.First();
835 if ((SMESH::GetMeshByIO(IO))->_is_nil())
838 SMESH_Actor* anActor = SMESH::FindActorByObject(SMESH::GetMeshByIO(IO));
840 anActor = SMESH::FindActorByEntry(IO->getEntry());
841 if (!anActor && !CheckBoxMesh->isChecked())
844 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
848 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
852 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
860 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
861 SpinBox_X->SetValue(x);
862 SpinBox_Y->SetValue(y);
863 SpinBox_Z->SetValue(z);
864 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
865 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
866 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
867 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
872 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
873 LineEditElements->setText(aString);
874 LineEditElements->repaint();
875 LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
876 LineEditElements->setEnabled(true);
882 if (myNbOkElements && IsMirrorOk()) {
883 buttonOk->setEnabled(true);
884 buttonApply->setEnabled(true);
886 onDisplaySimulation(true);
889 //=================================================================================
890 // function : SetEditCurrentArgument()
892 //=================================================================================
893 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
895 QPushButton* send = (QPushButton*)sender();
897 disconnect(mySelectionMgr, 0, this, 0);
898 mySelectionMgr->clearSelected();
899 mySelectionMgr->clearFilters();
901 if (send == SelectElementsButton) {
902 myEditCurrentArgument = (QWidget*)LineEditElements;
903 SMESH::SetPointRepresentation(false);
904 if (CheckBoxMesh->isChecked()) {
905 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
906 aViewWindow->SetSelectionMode(ActorSelection);
907 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
909 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
910 aViewWindow->SetSelectionMode(CellSelection);
912 } else if (send == SelectPointButton) {
913 myEditCurrentArgument = (QWidget*)SpinBox_X;
914 SMESH::SetPointRepresentation(true);
915 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
916 aViewWindow->SetSelectionMode(NodeSelection);
917 } else if (send == SelectVectorButton) {
918 myEditCurrentArgument = (QWidget*)SpinBox_DX;
919 SMESH::SetPointRepresentation(true);
921 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
922 aViewWindow->SetSelectionMode(NodeSelection);
926 myEditCurrentArgument->setFocus();
927 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
928 SelectionIntoArgument();
931 //=================================================================================
932 // function : DeactivateActiveDialog()
934 //=================================================================================
935 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
937 if (ConstructorsBox->isEnabled()) {
938 ConstructorsBox->setEnabled(false);
939 GroupArguments->setEnabled(false);
940 GroupButtons->setEnabled(false);
941 mySMESHGUI->ResetState();
942 mySMESHGUI->SetActiveDialogBox(0);
946 //=================================================================================
947 // function : ActivateThisDialog()
949 //=================================================================================
950 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
952 /* Emit a signal to deactivate the active dialog */
953 mySMESHGUI->EmitSignalDeactivateDialog();
954 ConstructorsBox->setEnabled(true);
955 GroupArguments->setEnabled(true);
956 GroupButtons->setEnabled(true);
958 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
960 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
961 aViewWindow->SetSelectionMode(CellSelection);
962 SelectionIntoArgument();
965 //=================================================================================
966 // function : enterEvent()
968 //=================================================================================
969 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
971 if (!ConstructorsBox->isEnabled())
972 ActivateThisDialog();
975 //=======================================================================
976 //function : onSelectMesh
978 //=======================================================================
979 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
982 TextLabelElements->setText(tr("SMESH_NAME"));
984 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
985 myFilterBtn->setEnabled(!toSelectMesh);
987 if (myEditCurrentArgument != LineEditElements) {
988 LineEditElements->clear();
992 mySelectionMgr->clearFilters();
993 SMESH::SetPointRepresentation(false);
996 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
997 aViewWindow->SetSelectionMode(ActorSelection);
998 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
999 LineEditElements->setReadOnly(true);
1000 LineEditElements->setValidator(0);
1002 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1003 aViewWindow->SetSelectionMode(CellSelection);
1004 LineEditElements->setReadOnly(false);
1005 LineEditElements->setValidator(myIdValidator);
1006 onTextChange(LineEditElements->text());
1010 SelectionIntoArgument();
1013 //=================================================================================
1014 // function : GetConstructorId()
1016 //=================================================================================
1017 int SMESHGUI_SymmetryDlg::GetConstructorId()
1019 return GroupConstructors->checkedId();
1022 //=================================================================================
1023 // function : IsMirrorOk()
1025 //=================================================================================
1026 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
1030 if (GetConstructorId() != 0)
1031 isOk = (SpinBox_DX->GetValue() != 0 ||
1032 SpinBox_DY->GetValue() != 0 ||
1033 SpinBox_DZ->GetValue() != 0);
1038 //=================================================================================
1039 // function : onVectorChanged()
1041 //=================================================================================
1042 void SMESHGUI_SymmetryDlg::onVectorChanged()
1045 buttonOk->setEnabled(true);
1046 buttonApply->setEnabled(true);
1048 buttonOk->setEnabled(false);
1049 buttonApply->setEnabled(false);
1053 //=======================================================================
1054 //function : onActionClicked
1055 //purpose : slot called when an action type changed
1056 //=======================================================================
1058 void SMESHGUI_SymmetryDlg::onActionClicked(int button)
1061 for ( int i = 0; i < myMeshes.count(); i++ )
1062 aNbGroups += myMeshes[i]->NbGroups();
1065 case MOVE_ELEMS_BUTTON:
1066 MakeGroupsCheck->setEnabled(false);
1067 LineEditNewMesh->setEnabled(false);
1069 case COPY_ELEMS_BUTTON:
1070 LineEditNewMesh->setEnabled(false);
1071 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1072 MakeGroupsCheck->setEnabled(myMeshes.isEmpty() || aNbGroups > 0);
1074 case MAKE_MESH_BUTTON:
1075 LineEditNewMesh->setEnabled(true);
1076 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1077 MakeGroupsCheck->setEnabled(myMeshes.isEmpty() || aNbGroups > 0);
1081 toDisplaySimulation();
1084 //=======================================================================
1085 //function : setNewMeshName
1086 //purpose : update contents of LineEditNewMesh
1087 //=======================================================================
1089 void SMESHGUI_SymmetryDlg::setNewMeshName()
1091 LineEditNewMesh->setText("");
1092 if ( LineEditNewMesh->isEnabled() && !myMeshes.isEmpty() ) {
1094 if ( CheckBoxMesh->isChecked() ) {
1095 name = myObjects.count() > 1 ? "*" : LineEditElements->text();
1098 _PTR(SObject) meshSO = SMESH::FindSObject( myMeshes[0] );
1099 name = meshSO->GetName().c_str();
1101 if ( !name.isEmpty() )
1102 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "mirrored"));
1106 //=================================================================================
1107 // function : keyPressEvent()
1109 //=================================================================================
1110 void SMESHGUI_SymmetryDlg::keyPressEvent( QKeyEvent* e )
1112 QDialog::keyPressEvent( e );
1113 if ( e->isAccepted() )
1116 if ( e->key() == Qt::Key_F1 ) {
1122 //=================================================================================
1123 // function : setFilters()
1124 // purpose : SLOT. Called when "Filter" button pressed.
1125 //=================================================================================
1126 void SMESHGUI_SymmetryDlg::setFilters()
1128 if(myMeshes.isEmpty()) {
1129 SUIT_MessageBox::critical(this,
1131 tr("NO_MESH_SELECTED"));
1135 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1137 myFilterDlg->SetSelection();
1138 myFilterDlg->SetMesh( myMeshes[0] );
1139 myFilterDlg->SetSourceWg( LineEditElements );
1141 myFilterDlg->show();
1144 //=================================================================================
1145 // function : isValid
1147 //=================================================================================
1148 bool SMESHGUI_SymmetryDlg::isValid()
1153 ok = SpinBox_X->isValid( msg, true ) && ok;
1154 ok = SpinBox_Y->isValid( msg, true ) && ok;
1155 ok = SpinBox_Z->isValid( msg, true ) && ok;
1156 if (GetConstructorId() != 0) {
1157 ok = SpinBox_DX->isValid( msg, true ) && ok;
1158 ok = SpinBox_DY->isValid( msg, true ) && ok;
1159 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1163 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1164 if ( !msg.isEmpty() )
1166 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1172 //=================================================================================
1173 // function : onDisplaySimulation
1174 // purpose : Show/Hide preview
1175 //=================================================================================
1176 void SMESHGUI_SymmetryDlg::onDisplaySimulation( bool toDisplayPreview ) {
1177 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1178 if ( myNbOkElements && isValid() && IsMirrorOk() ) {
1179 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1180 SMESH::long_array_var anElementsId = new SMESH::long_array;
1182 anElementsId->length(aListElementsId.count());
1183 for (int i = 0; i < aListElementsId.count(); i++)
1184 anElementsId[i] = aListElementsId[i].toInt();
1186 SMESH::AxisStruct aMirror;
1187 SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
1189 getMirror(aMirror,aMirrorType);
1192 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1193 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1194 SUIT_OverrideCursor aWaitCursor;
1195 QList<SMESH::MeshPreviewStruct_var> aMeshPreviewStruct;
1196 if(CheckBoxMesh->isChecked())
1197 for ( int i = 0; i < myMeshes.count(); i++ ) {
1198 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditPreviewer();
1199 aMeshEditor->MirrorObject(myObjects[i], aMirror, aMirrorType, copy );
1200 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1203 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditPreviewer();
1204 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, copy );
1205 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1207 setSimulationPreview(aMeshPreviewStruct);
1219 //=================================================================================
1220 // function : getMirror
1221 // purpose : return mirror parameters
1222 //=================================================================================
1223 void SMESHGUI_SymmetryDlg::getMirror(SMESH::AxisStruct& theMirror, SMESH::SMESH_MeshEditor::MirrorType& theMirrorType) {
1224 theMirror.x = SpinBox_X->GetValue();
1225 theMirror.y = SpinBox_Y->GetValue();
1226 theMirror.z = SpinBox_Z->GetValue();
1227 if (GetConstructorId() == 0) {
1228 theMirror.vx = theMirror.vy = theMirror.vz = 0;
1230 theMirror.vx = SpinBox_DX->GetValue();
1231 theMirror.vy = SpinBox_DY->GetValue();
1232 theMirror.vz = SpinBox_DZ->GetValue();
1234 if (GetConstructorId() == 0)
1235 theMirrorType = SMESH::SMESH_MeshEditor::POINT;
1236 if (GetConstructorId() == 1)
1237 theMirrorType = SMESH::SMESH_MeshEditor::AXIS;
1238 if (GetConstructorId() == 2)
1239 theMirrorType = SMESH::SMESH_MeshEditor::PLANE;