1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_SymmetryDlg.cxx
24 // Author : Michael ZORIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_SymmetryDlg.h"
30 #include "SMESHGUI_SpinBox.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_IdValidator.h"
35 #include "SMESHGUI_FilterDlg.h"
36 #include "SMESHGUI_MeshEditPreview.h"
38 #include <SMESH_Actor.h>
39 #include <SMESH_TypeFilter.hxx>
40 #include <SMESH_LogicalFilter.hxx>
41 #include <SMDS_Mesh.hxx>
43 // SALOME GUI includes
44 #include <SUIT_Desktop.h>
45 #include <SUIT_ResourceMgr.h>
46 #include <SUIT_Session.h>
47 #include <SUIT_MessageBox.h>
48 #include <SUIT_OverrideCursor.h>
50 #include <LightApp_Application.h>
51 #include <LightApp_SelectionMgr.h>
53 #include <SVTK_ViewModel.h>
54 #include <SVTK_ViewWindow.h>
55 #include <SALOME_ListIO.hxx>
57 // SALOME KERNEL includes
58 #include <SALOMEDSClient_SObject.hxx>
61 #include <TColStd_MapOfInteger.hxx>
64 #include <QApplication>
65 #include <QButtonGroup>
69 #include <QPushButton>
70 #include <QRadioButton>
72 #include <QHBoxLayout>
73 #include <QVBoxLayout>
74 #include <QGridLayout>
78 #include <SALOMEconfig.h>
79 #include CORBA_SERVER_HEADER(SMESH_Group)
80 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
82 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
87 //To disable automatic genericobj management, the following line should be commented.
88 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
89 #define WITHGENERICOBJ
91 //=================================================================================
92 // class : SMESHGUI_SymmetryDlg()
94 //=================================================================================
96 SMESHGUI_SymmetryDlg::SMESHGUI_SymmetryDlg( SMESHGUI* theModule )
97 : SMESHGUI_PreviewDlg( theModule ),
98 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
100 mySelectedObject(SMESH::SMESH_IDSource::_nil())
102 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_POINT")));
103 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_AXIS")));
104 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_PLANE")));
105 QPixmap image3 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
108 setAttribute(Qt::WA_DeleteOnClose, true);
109 setWindowTitle(tr("SMESH_SYMMETRY"));
110 setSizeGripEnabled(true);
112 QVBoxLayout* SMESHGUI_SymmetryDlgLayout = new QVBoxLayout(this);
113 SMESHGUI_SymmetryDlgLayout->setSpacing(SPACING);
114 SMESHGUI_SymmetryDlgLayout->setMargin(MARGIN);
116 /***************************************************************/
117 ConstructorsBox = new QGroupBox(tr("SMESH_SYMMETRY"), this);
118 GroupConstructors = new QButtonGroup(this);
119 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
120 ConstructorsBoxLayout->setSpacing(SPACING);
121 ConstructorsBoxLayout->setMargin(MARGIN);
123 RadioButton1 = new QRadioButton(ConstructorsBox);
124 RadioButton1->setIcon(image0);
125 RadioButton2 = new QRadioButton(ConstructorsBox);
126 RadioButton2->setIcon(image1);
127 RadioButton3 = new QRadioButton(ConstructorsBox);
128 RadioButton3->setIcon(image2);
130 ConstructorsBoxLayout->addWidget(RadioButton1);
131 ConstructorsBoxLayout->addWidget(RadioButton2);
132 ConstructorsBoxLayout->addWidget(RadioButton3);
133 GroupConstructors->addButton(RadioButton1, 0);
134 GroupConstructors->addButton(RadioButton2, 1);
135 GroupConstructors->addButton(RadioButton3, 2);
137 /***************************************************************/
138 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
139 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
140 GroupArgumentsLayout->setSpacing(SPACING);
141 GroupArgumentsLayout->setMargin(MARGIN);
143 myIdValidator = new SMESHGUI_IdValidator(this);
145 // Controls for elements selection
146 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
147 SelectElementsButton = new QPushButton(GroupArguments);
148 SelectElementsButton->setIcon(image3);
149 LineEditElements = new QLineEdit(GroupArguments);
150 LineEditElements->setValidator(myIdValidator);
151 LineEditElements->setMaxLength(-1);
152 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
153 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
155 // Control for the whole mesh selection
156 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
158 // Controls for mirror selection
159 GroupMirror = new QGroupBox(GroupArguments);
160 QGridLayout* GroupMirrorLayout = new QGridLayout(GroupMirror);
161 GroupMirrorLayout->setSpacing(SPACING);
162 GroupMirrorLayout->setMargin(MARGIN);
164 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupMirror);
165 SelectPointButton = new QPushButton(GroupMirror);
166 SelectPointButton->setIcon(image3);
168 TextLabelX = new QLabel(tr("SMESH_X"), GroupMirror);
169 SpinBox_X = new SMESHGUI_SpinBox(GroupMirror);
170 TextLabelY = new QLabel(tr("SMESH_Y"), GroupMirror);
171 SpinBox_Y = new SMESHGUI_SpinBox(GroupMirror);
172 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupMirror);
173 SpinBox_Z = new SMESHGUI_SpinBox(GroupMirror);
175 TextLabelVector = new QLabel(GroupMirror);
176 SelectVectorButton = new QPushButton(GroupMirror);
177 SelectVectorButton->setIcon(image3);
179 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupMirror);
180 SpinBox_DX = new SMESHGUI_SpinBox(GroupMirror);
181 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupMirror);
182 SpinBox_DY = new SMESHGUI_SpinBox(GroupMirror);
183 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupMirror);
184 SpinBox_DZ = new SMESHGUI_SpinBox(GroupMirror);
186 GroupMirrorLayout->addWidget(TextLabelPoint, 0, 0);
187 GroupMirrorLayout->addWidget(SelectPointButton, 0, 1);
188 GroupMirrorLayout->addWidget(TextLabelX, 0, 2);
189 GroupMirrorLayout->addWidget(SpinBox_X, 0, 3);
190 GroupMirrorLayout->addWidget(TextLabelY, 0, 4);
191 GroupMirrorLayout->addWidget(SpinBox_Y, 0, 5);
192 GroupMirrorLayout->addWidget(TextLabelZ, 0, 6);
193 GroupMirrorLayout->addWidget(SpinBox_Z, 0, 7);
194 GroupMirrorLayout->addWidget(TextLabelVector, 1, 0);
195 GroupMirrorLayout->addWidget(SelectVectorButton, 1, 1);
196 GroupMirrorLayout->addWidget(TextLabelDX, 1, 2);
197 GroupMirrorLayout->addWidget(SpinBox_DX, 1, 3);
198 GroupMirrorLayout->addWidget(TextLabelDY, 1, 4);
199 GroupMirrorLayout->addWidget(SpinBox_DY, 1, 5);
200 GroupMirrorLayout->addWidget(TextLabelDZ, 1, 6);
201 GroupMirrorLayout->addWidget(SpinBox_DZ, 1, 7);
203 // switch of action type
204 ActionBox = new QGroupBox(GroupArguments);
205 ActionGroup = new QButtonGroup(GroupArguments);
206 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
207 ActionBoxLayout->addSpacing(SPACING);
208 ActionBoxLayout->setMargin(MARGIN);
210 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
211 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
212 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
214 ActionBoxLayout->addWidget(aMoveElements);
215 ActionBoxLayout->addWidget(aCopyElements);
216 ActionBoxLayout->addWidget(aCreateMesh);
217 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
218 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
219 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
221 // CheckBox for groups generation
222 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
223 MakeGroupsCheck->setChecked(false);
225 // Name of a mesh to create
226 LineEditNewMesh = new QLineEdit(GroupArguments);
230 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
233 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
234 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
235 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 1);
236 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 3);
237 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
238 GroupArgumentsLayout->addWidget(GroupMirror, 2, 0, 1, 4);
239 GroupArgumentsLayout->addWidget(ActionBox, 3, 0, 3, 3);
240 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 4, 3);
241 GroupArgumentsLayout->addWidget(LineEditNewMesh, 5, 3);
242 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 6, 0);
244 /***************************************************************/
245 GroupButtons = new QGroupBox(this);
246 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
247 GroupButtonsLayout->setSpacing(SPACING);
248 GroupButtonsLayout->setMargin(MARGIN);
250 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
251 buttonOk->setAutoDefault(true);
252 buttonOk->setDefault(true);
253 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
254 buttonApply->setAutoDefault(true);
255 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
256 buttonCancel->setAutoDefault(true);
257 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
258 buttonHelp->setAutoDefault(true);
260 GroupButtonsLayout->addWidget(buttonOk);
261 GroupButtonsLayout->addSpacing(10);
262 GroupButtonsLayout->addWidget(buttonApply);
263 GroupButtonsLayout->addSpacing(10);
264 GroupButtonsLayout->addStretch();
265 GroupButtonsLayout->addWidget(buttonCancel);
266 GroupButtonsLayout->addWidget(buttonHelp);
268 /***************************************************************/
269 SMESHGUI_SymmetryDlgLayout->addWidget(ConstructorsBox);
270 SMESHGUI_SymmetryDlgLayout->addWidget(GroupArguments);
271 SMESHGUI_SymmetryDlgLayout->addWidget(GroupButtons);
273 /* Initialisations */
274 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
275 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
276 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
277 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
278 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
279 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
281 RadioButton1->setChecked(true);
283 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
285 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
287 // Costruction of the logical filter
288 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
289 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
291 QList<SUIT_SelectionFilter*> aListOfFilters;
292 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
293 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
295 myMeshOrSubMeshOrGroupFilter =
296 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
298 myHelpFileName = "symmetry_page.html";
302 /* signals and slots connections */
303 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
304 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
305 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
306 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
307 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
309 connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
310 connect(SelectPointButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
311 connect(SelectVectorButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
313 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
314 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
315 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
317 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
318 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
319 /* to close dialog if study change */
320 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
321 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
322 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
323 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
325 connect(SpinBox_X, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
326 connect(SpinBox_Y, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
327 connect(SpinBox_Z, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
328 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
329 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
330 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
332 //To Connect preview check box
333 connectPreviewControl();
335 ConstructorsClicked(0);
336 SelectionIntoArgument();
337 onActionClicked(MOVE_ELEMS_BUTTON);
340 //=================================================================================
341 // function : ~SMESHGUI_SymmetryDlg()
342 // purpose : Destroys the object and frees any allocated resources
343 //=================================================================================
344 SMESHGUI_SymmetryDlg::~SMESHGUI_SymmetryDlg()
346 if ( myFilterDlg != 0 ) {
347 myFilterDlg->setParent( 0 );
352 //=================================================================================
355 //=================================================================================
356 void SMESHGUI_SymmetryDlg::Init (bool ResetControls)
360 myEditCurrentArgument = 0;
361 LineEditElements->clear();
365 buttonOk->setEnabled(false);
366 buttonApply->setEnabled(false);
369 myMesh = SMESH::SMESH_Mesh::_nil();
372 SpinBox_X->SetValue(0.0);
373 SpinBox_Y->SetValue(0.0);
374 SpinBox_Z->SetValue(0.0);
375 SpinBox_DX->SetValue(0.0);
376 SpinBox_DY->SetValue(0.0);
377 SpinBox_DZ->SetValue(0.0);
379 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
380 CheckBoxMesh->setChecked(false);
381 myPreviewCheckBox->setChecked(false);
382 onDisplaySimulation(false);
384 // MakeGroupsCheck->setChecked(false);
385 // MakeGroupsCheck->setEnabled(false);
390 //=================================================================================
391 // function : ConstructorsClicked()
392 // purpose : Radio button management
393 //=================================================================================
394 void SMESHGUI_SymmetryDlg::ConstructorsClicked (int constructorId)
396 disconnect(mySelectionMgr, 0, this, 0);
398 if (constructorId != 0 && !TextLabelVector->isVisible()) {
399 TextLabelVector->show();
400 SelectVectorButton->show();
409 switch (constructorId) {
412 GroupMirror->setTitle(tr("SMESH_POINT"));
414 TextLabelVector->hide();
415 SelectVectorButton->hide();
426 GroupMirror->setTitle(tr("SMESH_AXIS"));
427 TextLabelVector->setText(tr("SMESH_VECTOR"));
432 GroupMirror->setTitle(tr("SMESH_PLANE"));
433 TextLabelVector->setText(tr("SMESH_NORMAL"));
438 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
439 SMESH::SetPointRepresentation(false);
440 if (!CheckBoxMesh->isChecked())
442 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
443 aViewWindow->SetSelectionMode(CellSelection);
447 myEditCurrentArgument = (QWidget*)LineEditElements;
448 LineEditElements->setFocus();
450 if (CheckBoxMesh->isChecked())
453 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
455 onDisplaySimulation(true);
457 QApplication::instance()->processEvents();
462 //=================================================================================
463 // function : ClickOnApply()
465 //=================================================================================
466 bool SMESHGUI_SymmetryDlg::ClickOnApply()
468 if (mySMESHGUI->isActiveStudyLocked())
474 if (myNbOkElements && IsMirrorOk()) {
475 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
477 SMESH::long_array_var anElementsId = new SMESH::long_array;
479 anElementsId->length(aListElementsId.count());
480 for (int i = 0; i < aListElementsId.count(); i++)
481 anElementsId[i] = aListElementsId[i].toInt();
483 SMESH::AxisStruct aMirror;
484 SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
485 getMirror(aMirror,aMirrorType);
487 QStringList aParameters;
488 aParameters << SpinBox_X->text();
489 aParameters << SpinBox_Y->text();
490 aParameters << SpinBox_Z->text();
491 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DX->text() );
492 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DY->text() );
493 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DZ->text() );
495 int actionButton = ActionGroup->checkedId();
496 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
497 QStringList anEntryList;
499 SUIT_OverrideCursor aWaitCursor;
500 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
502 switch ( actionButton ) {
503 case MOVE_ELEMS_BUTTON: {
504 if(CheckBoxMesh->isChecked())
505 aMeshEditor->MirrorObject(mySelectedObject, aMirror, aMirrorType, false );
507 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, false );
509 if( !myMesh->_is_nil())
510 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
513 case COPY_ELEMS_BUTTON: {
514 SMESH::ListOfGroups_var groups;
516 if(CheckBoxMesh->isChecked())
517 groups = aMeshEditor->MirrorObjectMakeGroups(mySelectedObject, aMirror, aMirrorType);
519 groups = aMeshEditor->MirrorMakeGroups(anElementsId, aMirror, aMirrorType);
522 if(CheckBoxMesh->isChecked())
523 aMeshEditor->MirrorObject(mySelectedObject, aMirror, aMirrorType, true);
525 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, true);
527 if( !myMesh->_is_nil())
528 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
531 case MAKE_MESH_BUTTON: {
532 SMESH::SMESH_Mesh_var mesh;
533 if (CheckBoxMesh->isChecked())
534 mesh = aMeshEditor->MirrorObjectMakeMesh(mySelectedObject, aMirror, aMirrorType, makeGroups,
535 LineEditNewMesh->text().toLatin1().data());
537 mesh = aMeshEditor->MirrorMakeMesh(anElementsId, aMirror, aMirrorType, makeGroups,
538 LineEditNewMesh->text().toLatin1().data());
539 if (!mesh->_is_nil()) {
540 mesh->SetParameters(aParameters.join(":").toLatin1().constData());
541 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
542 anEntryList.append( aSObject->GetID().c_str() );
543 #ifdef WITHGENERICOBJ
544 // obj has been published in study. Its refcount has been incremented.
545 // It is safe to decrement its refcount
546 // so that it will be destroyed when the entry in study will be removed
557 if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
558 actionButton == MAKE_MESH_BUTTON ) {
559 mySMESHGUI->updateObjBrowser(true); // new groups may appear
560 if( LightApp_Application* anApp =
561 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
562 anApp->browseObjects( anEntryList, isApplyAndClose() );
565 ConstructorsClicked(GetConstructorId());
566 mySelectedObject = SMESH::SMESH_IDSource::_nil();
567 SelectionIntoArgument();
569 SMESHGUI::Modified();
574 //=================================================================================
575 // function : ClickOnOk()
577 //=================================================================================
578 void SMESHGUI_SymmetryDlg::ClickOnOk()
580 setIsApplyAndClose( true );
585 //=================================================================================
586 // function : ClickOnCancel()
588 //=================================================================================
589 void SMESHGUI_SymmetryDlg::ClickOnCancel()
591 disconnect(mySelectionMgr, 0, this, 0);
592 mySelectionMgr->clearFilters();
593 //mySelectionMgr->clearSelected();
594 if (SMESH::GetCurrentVtkView()) {
595 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
596 SMESH::SetPointRepresentation(false);
598 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
599 aViewWindow->SetSelectionMode(ActorSelection);
600 mySMESHGUI->ResetState();
604 //=================================================================================
605 // function : ClickOnHelp()
607 //=================================================================================
608 void SMESHGUI_SymmetryDlg::ClickOnHelp()
610 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
612 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
616 platform = "winapplication";
618 platform = "application";
620 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
621 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
622 arg(app->resourceMgr()->stringValue("ExternalBrowser",
624 arg(myHelpFileName));
628 //=======================================================================
629 // function : onTextChange()
631 //=======================================================================
632 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
634 QLineEdit* send = (QLineEdit*)sender();
639 if (send == LineEditElements)
642 buttonOk->setEnabled(false);
643 buttonApply->setEnabled(false);
645 // hilight entered elements
646 SMDS_Mesh* aMesh = 0;
648 aMesh = myActor->GetObject()->GetMesh();
651 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
653 TColStd_MapOfInteger newIndices;
655 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
657 if (send == LineEditElements) {
658 for (int i = 0; i < aListId.count(); i++) {
659 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
661 newIndices.Add(e->GetID());
665 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
666 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
667 aViewWindow->highlight( anIO, true, true );
669 myElementsId = theNewText;
673 if (myNbOkElements && IsMirrorOk()) {
674 buttonOk->setEnabled(true);
675 buttonApply->setEnabled(true);
681 //=================================================================================
682 // function : SelectionIntoArgument()
683 // purpose : Called when selection as changed or other case
684 //=================================================================================
685 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
691 QString aString = "";
694 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
695 LineEditElements->setText(aString);
697 buttonOk->setEnabled(false);
698 buttonApply->setEnabled(false);
702 if (!GroupButtons->isEnabled()) // inactive
707 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
709 int nbSel = aList.Extent();
713 Handle(SALOME_InteractiveObject) IO = aList.First();
714 myMesh = SMESH::GetMeshByIO(IO);
715 if(myMesh->_is_nil())
718 myActor = SMESH::FindActorByObject(myMesh);
720 myActor = SMESH::FindActorByEntry(IO->getEntry());
721 if (!myActor && !CheckBoxMesh->isChecked())
726 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
729 // MakeGroups is available if there are groups and "Copy"
730 if ( myMesh->NbGroups() == 0 ) {
731 MakeGroupsCheck->setChecked(false);
732 MakeGroupsCheck->setEnabled(false);
734 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
735 MakeGroupsCheck->setEnabled(true);
737 if (CheckBoxMesh->isChecked()) {
738 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
740 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH
741 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
747 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
751 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
752 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
754 myElementsId += QString(" %1").arg(i);
758 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
760 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
762 // get IDs from submesh
764 SMESH::long_array_var anElementsIds = new SMESH::long_array;
765 anElementsIds = aSubMesh->GetElementsId();
766 for (int i = 0; i < anElementsIds->length(); i++) {
767 myElementsId += QString(" %1").arg(anElementsIds[i]);
769 aNbUnits = anElementsIds->length();
772 SMESH::SMESH_GroupBase_var aGroup =
773 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
774 if (aGroup->_is_nil())
777 // get IDs from smesh group
778 SMESH::long_array_var anElementsIds = new SMESH::long_array;
779 anElementsIds = aGroup->GetListOfID();
780 for (int i = 0; i < anElementsIds->length(); i++) {
781 myElementsId += QString(" %1").arg(anElementsIds[i]);
783 aNbUnits = anElementsIds->length();
787 aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, IO, aString);
788 myElementsId = aString;
793 myNbOkElements = true;
795 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
799 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
803 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
811 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
812 SpinBox_X->SetValue(x);
813 SpinBox_Y->SetValue(y);
814 SpinBox_Z->SetValue(z);
815 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
816 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
817 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
818 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
823 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
824 LineEditElements->setText(aString);
825 LineEditElements->repaint();
826 LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
827 LineEditElements->setEnabled(true);
833 if (myNbOkElements && IsMirrorOk()) {
834 buttonOk->setEnabled(true);
835 buttonApply->setEnabled(true);
837 onDisplaySimulation(true);
840 //=================================================================================
841 // function : SetEditCurrentArgument()
843 //=================================================================================
844 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
846 QPushButton* send = (QPushButton*)sender();
848 disconnect(mySelectionMgr, 0, this, 0);
849 mySelectionMgr->clearSelected();
850 mySelectionMgr->clearFilters();
852 if (send == SelectElementsButton) {
853 myEditCurrentArgument = (QWidget*)LineEditElements;
854 SMESH::SetPointRepresentation(false);
855 if (CheckBoxMesh->isChecked()) {
856 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
857 aViewWindow->SetSelectionMode(ActorSelection);
858 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
860 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
861 aViewWindow->SetSelectionMode(CellSelection);
863 } else if (send == SelectPointButton) {
864 myEditCurrentArgument = (QWidget*)SpinBox_X;
865 SMESH::SetPointRepresentation(true);
866 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
867 aViewWindow->SetSelectionMode(NodeSelection);
868 } else if (send == SelectVectorButton) {
869 myEditCurrentArgument = (QWidget*)SpinBox_DX;
870 SMESH::SetPointRepresentation(true);
872 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
873 aViewWindow->SetSelectionMode(NodeSelection);
877 myEditCurrentArgument->setFocus();
878 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
879 SelectionIntoArgument();
882 //=================================================================================
883 // function : DeactivateActiveDialog()
885 //=================================================================================
886 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
888 if (ConstructorsBox->isEnabled()) {
889 ConstructorsBox->setEnabled(false);
890 GroupArguments->setEnabled(false);
891 GroupButtons->setEnabled(false);
892 mySMESHGUI->ResetState();
893 mySMESHGUI->SetActiveDialogBox(0);
897 //=================================================================================
898 // function : ActivateThisDialog()
900 //=================================================================================
901 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
903 /* Emit a signal to deactivate the active dialog */
904 mySMESHGUI->EmitSignalDeactivateDialog();
905 ConstructorsBox->setEnabled(true);
906 GroupArguments->setEnabled(true);
907 GroupButtons->setEnabled(true);
909 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
911 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
912 aViewWindow->SetSelectionMode(CellSelection);
913 SelectionIntoArgument();
916 //=================================================================================
917 // function : enterEvent()
919 //=================================================================================
920 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
922 if (!ConstructorsBox->isEnabled())
923 ActivateThisDialog();
926 //=================================================================================
927 // function : closeEvent()
929 //=================================================================================
930 void SMESHGUI_SymmetryDlg::closeEvent (QCloseEvent*)
932 /* same than click on cancel button */
936 //=======================================================================
937 // function : hideEvent()
938 // purpose : caused by ESC key
939 //=======================================================================
940 void SMESHGUI_SymmetryDlg::hideEvent (QHideEvent*)
946 //=======================================================================
947 //function : onSelectMesh
949 //=======================================================================
950 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
953 TextLabelElements->setText(tr("SMESH_NAME"));
955 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
956 myFilterBtn->setEnabled(!toSelectMesh);
958 if (myEditCurrentArgument != LineEditElements) {
959 LineEditElements->clear();
963 mySelectionMgr->clearFilters();
964 SMESH::SetPointRepresentation(false);
967 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
968 aViewWindow->SetSelectionMode(ActorSelection);
969 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
970 LineEditElements->setReadOnly(true);
971 LineEditElements->setValidator(0);
973 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
974 aViewWindow->SetSelectionMode(CellSelection);
975 LineEditElements->setReadOnly(false);
976 LineEditElements->setValidator(myIdValidator);
977 onTextChange(LineEditElements->text());
981 SelectionIntoArgument();
984 //=================================================================================
985 // function : GetConstructorId()
987 //=================================================================================
988 int SMESHGUI_SymmetryDlg::GetConstructorId()
990 return GroupConstructors->checkedId();
993 //=================================================================================
994 // function : IsMirrorOk()
996 //=================================================================================
997 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
1001 if (GetConstructorId() != 0)
1002 isOk = (SpinBox_DX->GetValue() != 0 ||
1003 SpinBox_DY->GetValue() != 0 ||
1004 SpinBox_DZ->GetValue() != 0);
1009 //=================================================================================
1010 // function : onVectorChanged()
1012 //=================================================================================
1013 void SMESHGUI_SymmetryDlg::onVectorChanged()
1016 buttonOk->setEnabled(true);
1017 buttonApply->setEnabled(true);
1019 buttonOk->setEnabled(false);
1020 buttonApply->setEnabled(false);
1024 //=======================================================================
1025 //function : onActionClicked
1026 //purpose : slot called when an action type changed
1027 //=======================================================================
1029 void SMESHGUI_SymmetryDlg::onActionClicked(int button)
1032 case MOVE_ELEMS_BUTTON:
1033 MakeGroupsCheck->setEnabled(false);
1034 LineEditNewMesh->setEnabled(false);
1036 case COPY_ELEMS_BUTTON:
1037 LineEditNewMesh->setEnabled(false);
1038 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1039 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1040 MakeGroupsCheck->setEnabled(true);
1042 MakeGroupsCheck->setEnabled(false);
1044 case MAKE_MESH_BUTTON:
1045 LineEditNewMesh->setEnabled(true);
1046 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1047 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1048 MakeGroupsCheck->setEnabled(true);
1050 MakeGroupsCheck->setEnabled(false);
1054 toDisplaySimulation();
1057 //=======================================================================
1058 //function : setNewMeshName
1059 //purpose : update contents of LineEditNewMesh
1060 //=======================================================================
1062 void SMESHGUI_SymmetryDlg::setNewMeshName()
1064 LineEditNewMesh->setText("");
1065 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
1067 if ( CheckBoxMesh->isChecked() ) {
1068 name = LineEditElements->text();
1071 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
1072 name = meshSO->GetName().c_str();
1074 if ( !name.isEmpty() )
1075 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "mirrored"));
1079 //=================================================================================
1080 // function : keyPressEvent()
1082 //=================================================================================
1083 void SMESHGUI_SymmetryDlg::keyPressEvent( QKeyEvent* e )
1085 QDialog::keyPressEvent( e );
1086 if ( e->isAccepted() )
1089 if ( e->key() == Qt::Key_F1 ) {
1095 //=================================================================================
1096 // function : setFilters()
1097 // purpose : SLOT. Called when "Filter" button pressed.
1098 //=================================================================================
1099 void SMESHGUI_SymmetryDlg::setFilters()
1101 if(myMesh->_is_nil()) {
1102 SUIT_MessageBox::critical(this,
1104 tr("NO_MESH_SELECTED"));
1108 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1110 myFilterDlg->SetSelection();
1111 myFilterDlg->SetMesh( myMesh );
1112 myFilterDlg->SetSourceWg( LineEditElements );
1114 myFilterDlg->show();
1117 //=================================================================================
1118 // function : isValid
1120 //=================================================================================
1121 bool SMESHGUI_SymmetryDlg::isValid()
1126 ok = SpinBox_X->isValid( msg, true ) && ok;
1127 ok = SpinBox_Y->isValid( msg, true ) && ok;
1128 ok = SpinBox_Z->isValid( msg, true ) && ok;
1129 if (GetConstructorId() != 0) {
1130 ok = SpinBox_DX->isValid( msg, true ) && ok;
1131 ok = SpinBox_DY->isValid( msg, true ) && ok;
1132 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1136 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1137 if ( !msg.isEmpty() )
1139 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1145 //=================================================================================
1146 // function : onDisplaySimulation
1147 // purpose : Show/Hide preview
1148 //=================================================================================
1149 void SMESHGUI_SymmetryDlg::onDisplaySimulation( bool toDisplayPreview ) {
1150 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1151 if ( myNbOkElements && isValid() && IsMirrorOk() ) {
1152 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1153 SMESH::long_array_var anElementsId = new SMESH::long_array;
1155 anElementsId->length(aListElementsId.count());
1156 for (int i = 0; i < aListElementsId.count(); i++)
1157 anElementsId[i] = aListElementsId[i].toInt();
1159 SMESH::AxisStruct aMirror;
1160 SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
1162 getMirror(aMirror,aMirrorType);
1165 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1166 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1167 SUIT_OverrideCursor aWaitCursor;
1168 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
1169 if(CheckBoxMesh->isChecked())
1170 aMeshEditor->MirrorObject(mySelectedObject, aMirror, aMirrorType, copy );
1172 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, copy );
1174 SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
1175 mySimulation->SetData(aMeshPreviewStruct._retn());
1187 //=================================================================================
1188 // function : getMirror
1189 // purpose : return mirror parameters
1190 //=================================================================================
1191 void SMESHGUI_SymmetryDlg::getMirror(SMESH::AxisStruct& theMirror, SMESH::SMESH_MeshEditor::MirrorType& theMirrorType) {
1192 theMirror.x = SpinBox_X->GetValue();
1193 theMirror.y = SpinBox_Y->GetValue();
1194 theMirror.z = SpinBox_Z->GetValue();
1195 if (GetConstructorId() == 0) {
1196 theMirror.vx = theMirror.vy = theMirror.vz = 0;
1198 theMirror.vx = SpinBox_DX->GetValue();
1199 theMirror.vy = SpinBox_DY->GetValue();
1200 theMirror.vz = SpinBox_DZ->GetValue();
1202 if (GetConstructorId() == 0)
1203 theMirrorType = SMESH::SMESH_MeshEditor::POINT;
1204 if (GetConstructorId() == 1)
1205 theMirrorType = SMESH::SMESH_MeshEditor::AXIS;
1206 if (GetConstructorId() == 2)
1207 theMirrorType = SMESH::SMESH_MeshEditor::PLANE;