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();
456 myEditCurrentArgument->hide();
457 myEditCurrentArgument->show();
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() );
497 QStringList anEntryList;
499 SUIT_OverrideCursor aWaitCursor;
501 switch ( actionButton ) {
502 case MOVE_ELEMS_BUTTON: {
503 if(CheckBoxMesh->isChecked())
504 for ( int i = 0; i < myObjects.count(); i++ ) {
505 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
506 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
507 aMeshEditor->MirrorObject(myObjects[i], aMirror, aMirrorType, false );
510 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
511 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
512 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, false );
516 case COPY_ELEMS_BUTTON: {
517 SMESH::ListOfGroups_var groups;
519 if(CheckBoxMesh->isChecked())
520 for ( int i = 0; i < myObjects.count(); i++ ) {
521 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
522 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
523 groups = aMeshEditor->MirrorObjectMakeGroups(myObjects[i], aMirror, aMirrorType);
526 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
527 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
528 groups = aMeshEditor->MirrorMakeGroups(anElementsId, aMirror, aMirrorType);
532 if(CheckBoxMesh->isChecked())
533 for ( int i = 0; i < myObjects.count(); i++ ) {
534 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
535 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
536 aMeshEditor->MirrorObject(myObjects[i], aMirror, aMirrorType, true);
539 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
540 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
541 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, true);
546 case MAKE_MESH_BUTTON: {
547 SMESH::SMESH_Mesh_var mesh;
548 if (CheckBoxMesh->isChecked())
549 for ( int i = 0; i < myObjects.count(); i++ ) {
550 QString aName = SMESH::UniqueMeshName( LineEditNewMesh->text().replace( "*", myObjectsNames[i] ) );
551 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
552 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
553 mesh = aMeshEditor->MirrorObjectMakeMesh(myObjects[i], aMirror, aMirrorType, makeGroups,
554 aName.toLatin1().data());
555 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
556 anEntryList.append( aSObject->GetID().c_str() );
559 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
560 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
561 mesh = aMeshEditor->MirrorMakeMesh(anElementsId, aMirror, aMirrorType, makeGroups,
562 LineEditNewMesh->text().toLatin1().data());
563 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
564 anEntryList.append( aSObject->GetID().c_str() );
572 for ( int i = 0; i < myObjects.count(); i++ ) {
573 SMESH_Actor* actor = SMESH::FindActorByObject( myObjects[i] );
574 if ( actor ) SMESH::Update( actor->getIO(), true );
577 if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
578 actionButton == MAKE_MESH_BUTTON ) {
579 mySMESHGUI->updateObjBrowser(true); // new groups may appear
580 if( LightApp_Application* anApp =
581 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
582 anApp->browseObjects( anEntryList, isApplyAndClose() );
585 ConstructorsClicked(GetConstructorId());
586 SelectionIntoArgument();
588 SMESHGUI::Modified();
593 //=================================================================================
594 // function : ClickOnOk()
596 //=================================================================================
597 void SMESHGUI_SymmetryDlg::ClickOnOk()
599 setIsApplyAndClose( true );
604 //=================================================================================
605 // function : reject()
607 //=================================================================================
608 void SMESHGUI_SymmetryDlg::reject()
610 disconnect(mySelectionMgr, 0, this, 0);
611 mySelectionMgr->clearFilters();
612 //mySelectionMgr->clearSelected();
613 if (SMESH::GetCurrentVtkView()) {
614 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
615 SMESH::SetPointRepresentation(false);
617 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
618 aViewWindow->SetSelectionMode(ActorSelection);
619 mySMESHGUI->ResetState();
623 //=================================================================================
624 // function : ClickOnHelp()
626 //=================================================================================
627 void SMESHGUI_SymmetryDlg::ClickOnHelp()
629 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
631 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
635 platform = "winapplication";
637 platform = "application";
639 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
640 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
641 arg(app->resourceMgr()->stringValue("ExternalBrowser",
643 arg(myHelpFileName));
647 //=======================================================================
648 // function : onTextChange()
650 //=======================================================================
651 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
653 QLineEdit* send = (QLineEdit*)sender();
658 if (send == LineEditElements)
661 buttonOk->setEnabled(false);
662 buttonApply->setEnabled(false);
664 // hilight entered elements
665 SMDS_Mesh* aMesh = 0;
667 aMesh = myActor->GetObject()->GetMesh();
670 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
672 TColStd_MapOfInteger newIndices;
674 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
676 if (send == LineEditElements) {
677 for (int i = 0; i < aListId.count(); i++) {
678 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
680 newIndices.Add(e->GetID());
684 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
685 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
686 aViewWindow->highlight( anIO, true, true );
688 myElementsId = theNewText;
692 if (myNbOkElements && IsMirrorOk()) {
693 buttonOk->setEnabled(true);
694 buttonApply->setEnabled(true);
700 //=================================================================================
701 // function : SelectionIntoArgument()
702 // purpose : Called when selection as changed or other case
703 //=================================================================================
704 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
710 QString aString = "";
711 onDisplaySimulation(false);
714 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
715 LineEditElements->setText(aString);
717 buttonOk->setEnabled(false);
718 buttonApply->setEnabled(false);
722 if (!GroupButtons->isEnabled()) // inactive
727 mySelectionMgr->selectedObjects(aList);
729 int nbSel = aList.Extent();
735 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
738 myObjectsNames.clear();
741 for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() ) {
742 Handle(SALOME_InteractiveObject) IO = it.Value();
744 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( IO );
745 if( aMesh->_is_nil() )
748 myActor = SMESH::FindActorByObject( aMesh );
750 myActor = SMESH::FindActorByEntry( IO->getEntry() );
751 if ( !myActor && !CheckBoxMesh->isChecked() )
754 if ( !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO )->_is_nil() ) {
755 if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() ) {
756 _PTR(SObject) obj = aStudy->FindObjectID( qPrintable( QString( IO->getEntry() ) ) );
757 _PTR(GenericAttribute) anAttr;
758 if ( obj && obj->FindAttribute( anAttr, "AttributeName" ) ) {
759 _PTR(AttributeName) aNameAttr( anAttr );
760 myObjects << SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
761 myObjectsNames << aNameAttr->Value().c_str();
768 // MakeGroups is available if there are groups and "Copy"
770 for ( int i = 0; i < myMeshes.count(); i++ )
771 aNbGroups += myMeshes[i]->NbGroups();
773 if ( aNbGroups == 0 ) {
774 MakeGroupsCheck->setChecked(false);
775 MakeGroupsCheck->setEnabled(false);
777 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
778 MakeGroupsCheck->setEnabled(true);
780 if (CheckBoxMesh->isChecked()) {
781 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
783 if ( myObjects.isEmpty() )
787 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
791 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
792 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
794 myElementsId += QString(" %1").arg(i);
798 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
800 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
802 // get IDs from submesh
804 SMESH::long_array_var anElementsIds = new SMESH::long_array;
805 anElementsIds = aSubMesh->GetElementsId();
806 for (int i = 0; i < anElementsIds->length(); i++) {
807 myElementsId += QString(" %1").arg(anElementsIds[i]);
809 aNbUnits = anElementsIds->length();
812 SMESH::SMESH_GroupBase_var aGroup =
813 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
814 if (aGroup->_is_nil())
817 // get IDs from smesh group
818 SMESH::long_array_var anElementsIds = new SMESH::long_array;
819 anElementsIds = aGroup->GetListOfID();
820 for (int i = 0; i < anElementsIds->length(); i++) {
821 myElementsId += QString(" %1").arg(anElementsIds[i]);
823 aNbUnits = anElementsIds->length();
827 aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, aList.First(), aString);
828 myElementsId = aString;
833 myNbOkElements = true;
835 Handle(SALOME_InteractiveObject) IO = aList.First();
836 if ((SMESH::GetMeshByIO(IO))->_is_nil())
839 SMESH_Actor* anActor = SMESH::FindActorByObject(SMESH::GetMeshByIO(IO));
841 anActor = SMESH::FindActorByEntry(IO->getEntry());
842 if (!anActor && !CheckBoxMesh->isChecked())
845 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
849 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
853 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
861 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
862 SpinBox_X->SetValue(x);
863 SpinBox_Y->SetValue(y);
864 SpinBox_Z->SetValue(z);
865 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
866 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
867 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
868 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
873 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
874 LineEditElements->setText(aString);
875 LineEditElements->repaint();
876 LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
877 LineEditElements->setEnabled(true);
883 if (myNbOkElements && IsMirrorOk()) {
884 buttonOk->setEnabled(true);
885 buttonApply->setEnabled(true);
887 onDisplaySimulation(true);
890 //=================================================================================
891 // function : SetEditCurrentArgument()
893 //=================================================================================
894 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
896 QPushButton* send = (QPushButton*)sender();
898 disconnect(mySelectionMgr, 0, this, 0);
899 mySelectionMgr->clearSelected();
900 mySelectionMgr->clearFilters();
902 if (send == SelectElementsButton) {
903 myEditCurrentArgument = (QWidget*)LineEditElements;
904 SMESH::SetPointRepresentation(false);
905 if (CheckBoxMesh->isChecked()) {
906 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
907 aViewWindow->SetSelectionMode(ActorSelection);
908 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
910 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
911 aViewWindow->SetSelectionMode(CellSelection);
913 } else if (send == SelectPointButton) {
914 myEditCurrentArgument = (QWidget*)SpinBox_X;
915 SMESH::SetPointRepresentation(true);
916 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
917 aViewWindow->SetSelectionMode(NodeSelection);
918 } else if (send == SelectVectorButton) {
919 myEditCurrentArgument = (QWidget*)SpinBox_DX;
920 SMESH::SetPointRepresentation(true);
922 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
923 aViewWindow->SetSelectionMode(NodeSelection);
927 myEditCurrentArgument->setFocus();
928 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
929 SelectionIntoArgument();
932 //=================================================================================
933 // function : DeactivateActiveDialog()
935 //=================================================================================
936 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
938 if (ConstructorsBox->isEnabled()) {
939 ConstructorsBox->setEnabled(false);
940 GroupArguments->setEnabled(false);
941 GroupButtons->setEnabled(false);
942 mySMESHGUI->ResetState();
943 mySMESHGUI->SetActiveDialogBox(0);
947 //=================================================================================
948 // function : ActivateThisDialog()
950 //=================================================================================
951 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
953 /* Emit a signal to deactivate the active dialog */
954 mySMESHGUI->EmitSignalDeactivateDialog();
955 ConstructorsBox->setEnabled(true);
956 GroupArguments->setEnabled(true);
957 GroupButtons->setEnabled(true);
959 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
961 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
962 aViewWindow->SetSelectionMode(CellSelection);
963 SelectionIntoArgument();
966 //=================================================================================
967 // function : enterEvent()
969 //=================================================================================
970 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
972 if (!ConstructorsBox->isEnabled())
973 ActivateThisDialog();
976 //=======================================================================
977 //function : onSelectMesh
979 //=======================================================================
980 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
983 TextLabelElements->setText(tr("SMESH_NAME"));
985 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
986 myFilterBtn->setEnabled(!toSelectMesh);
988 if (myEditCurrentArgument != LineEditElements) {
989 LineEditElements->clear();
993 mySelectionMgr->clearFilters();
994 SMESH::SetPointRepresentation(false);
997 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
998 aViewWindow->SetSelectionMode(ActorSelection);
999 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
1000 LineEditElements->setReadOnly(true);
1001 LineEditElements->setValidator(0);
1003 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1004 aViewWindow->SetSelectionMode(CellSelection);
1005 LineEditElements->setReadOnly(false);
1006 LineEditElements->setValidator(myIdValidator);
1007 onTextChange(LineEditElements->text());
1011 SelectionIntoArgument();
1014 //=================================================================================
1015 // function : GetConstructorId()
1017 //=================================================================================
1018 int SMESHGUI_SymmetryDlg::GetConstructorId()
1020 return GroupConstructors->checkedId();
1023 //=================================================================================
1024 // function : IsMirrorOk()
1026 //=================================================================================
1027 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
1031 if (GetConstructorId() != 0)
1032 isOk = (SpinBox_DX->GetValue() != 0 ||
1033 SpinBox_DY->GetValue() != 0 ||
1034 SpinBox_DZ->GetValue() != 0);
1039 //=================================================================================
1040 // function : onVectorChanged()
1042 //=================================================================================
1043 void SMESHGUI_SymmetryDlg::onVectorChanged()
1046 buttonOk->setEnabled(true);
1047 buttonApply->setEnabled(true);
1049 buttonOk->setEnabled(false);
1050 buttonApply->setEnabled(false);
1054 //=======================================================================
1055 //function : onActionClicked
1056 //purpose : slot called when an action type changed
1057 //=======================================================================
1059 void SMESHGUI_SymmetryDlg::onActionClicked(int button)
1062 for ( int i = 0; i < myMeshes.count(); i++ )
1063 aNbGroups += myMeshes[i]->NbGroups();
1066 case MOVE_ELEMS_BUTTON:
1067 MakeGroupsCheck->setEnabled(false);
1068 LineEditNewMesh->setEnabled(false);
1070 case COPY_ELEMS_BUTTON:
1071 LineEditNewMesh->setEnabled(false);
1072 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1073 MakeGroupsCheck->setEnabled(myMeshes.isEmpty() || aNbGroups > 0);
1075 case MAKE_MESH_BUTTON:
1076 LineEditNewMesh->setEnabled(true);
1077 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1078 MakeGroupsCheck->setEnabled(myMeshes.isEmpty() || aNbGroups > 0);
1082 toDisplaySimulation();
1085 //=======================================================================
1086 //function : setNewMeshName
1087 //purpose : update contents of LineEditNewMesh
1088 //=======================================================================
1090 void SMESHGUI_SymmetryDlg::setNewMeshName()
1092 LineEditNewMesh->setText("");
1093 if ( LineEditNewMesh->isEnabled() && !myMeshes.isEmpty() ) {
1095 if ( CheckBoxMesh->isChecked() ) {
1096 name = myObjects.count() > 1 ? "*" : LineEditElements->text();
1099 _PTR(SObject) meshSO = SMESH::FindSObject( myMeshes[0] );
1100 name = meshSO->GetName().c_str();
1102 if ( !name.isEmpty() )
1103 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "mirrored"));
1107 //=================================================================================
1108 // function : keyPressEvent()
1110 //=================================================================================
1111 void SMESHGUI_SymmetryDlg::keyPressEvent( QKeyEvent* e )
1113 QDialog::keyPressEvent( e );
1114 if ( e->isAccepted() )
1117 if ( e->key() == Qt::Key_F1 ) {
1123 //=================================================================================
1124 // function : setFilters()
1125 // purpose : SLOT. Called when "Filter" button pressed.
1126 //=================================================================================
1127 void SMESHGUI_SymmetryDlg::setFilters()
1129 if(myMeshes.isEmpty()) {
1130 SUIT_MessageBox::critical(this,
1132 tr("NO_MESH_SELECTED"));
1136 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1138 myFilterDlg->SetSelection();
1139 myFilterDlg->SetMesh( myMeshes[0] );
1140 myFilterDlg->SetSourceWg( LineEditElements );
1142 myFilterDlg->show();
1145 //=================================================================================
1146 // function : isValid
1148 //=================================================================================
1149 bool SMESHGUI_SymmetryDlg::isValid()
1154 ok = SpinBox_X->isValid( msg, true ) && ok;
1155 ok = SpinBox_Y->isValid( msg, true ) && ok;
1156 ok = SpinBox_Z->isValid( msg, true ) && ok;
1157 if (GetConstructorId() != 0) {
1158 ok = SpinBox_DX->isValid( msg, true ) && ok;
1159 ok = SpinBox_DY->isValid( msg, true ) && ok;
1160 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1164 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1165 if ( !msg.isEmpty() )
1167 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1173 //=================================================================================
1174 // function : onDisplaySimulation
1175 // purpose : Show/Hide preview
1176 //=================================================================================
1177 void SMESHGUI_SymmetryDlg::onDisplaySimulation( bool toDisplayPreview ) {
1178 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1179 if ( myNbOkElements && isValid() && IsMirrorOk() ) {
1180 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1181 SMESH::long_array_var anElementsId = new SMESH::long_array;
1183 anElementsId->length(aListElementsId.count());
1184 for (int i = 0; i < aListElementsId.count(); i++)
1185 anElementsId[i] = aListElementsId[i].toInt();
1187 SMESH::AxisStruct aMirror;
1188 SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
1190 getMirror(aMirror,aMirrorType);
1193 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1194 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1195 SUIT_OverrideCursor aWaitCursor;
1196 QList<SMESH::MeshPreviewStruct_var> aMeshPreviewStruct;
1197 if(CheckBoxMesh->isChecked())
1198 for ( int i = 0; i < myMeshes.count(); i++ ) {
1199 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditPreviewer();
1200 aMeshEditor->MirrorObject(myObjects[i], aMirror, aMirrorType, copy );
1201 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1204 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditPreviewer();
1205 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, copy );
1206 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1208 setSimulationPreview(aMeshPreviewStruct);
1220 //=================================================================================
1221 // function : getMirror
1222 // purpose : return mirror parameters
1223 //=================================================================================
1224 void SMESHGUI_SymmetryDlg::getMirror(SMESH::AxisStruct& theMirror, SMESH::SMESH_MeshEditor::MirrorType& theMirrorType) {
1225 theMirror.x = SpinBox_X->GetValue();
1226 theMirror.y = SpinBox_Y->GetValue();
1227 theMirror.z = SpinBox_Z->GetValue();
1228 if (GetConstructorId() == 0) {
1229 theMirror.vx = theMirror.vy = theMirror.vz = 0;
1231 theMirror.vx = SpinBox_DX->GetValue();
1232 theMirror.vy = SpinBox_DY->GetValue();
1233 theMirror.vz = SpinBox_DZ->GetValue();
1235 if (GetConstructorId() == 0)
1236 theMirrorType = SMESH::SMESH_MeshEditor::POINT;
1237 if (GetConstructorId() == 1)
1238 theMirrorType = SMESH::SMESH_MeshEditor::AXIS;
1239 if (GetConstructorId() == 2)
1240 theMirrorType = SMESH::SMESH_MeshEditor::PLANE;