1 // Copyright (C) 2007-2011 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 // 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_SObject.hxx>
60 #include <TColStd_MapOfInteger.hxx>
63 #include <QApplication>
64 #include <QButtonGroup>
68 #include <QPushButton>
69 #include <QRadioButton>
71 #include <QHBoxLayout>
72 #include <QVBoxLayout>
73 #include <QGridLayout>
77 #include <SALOMEconfig.h>
78 #include CORBA_SERVER_HEADER(SMESH_Group)
79 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
81 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
86 //To disable automatic genericobj management, the following line should be commented.
87 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
88 #define WITHGENERICOBJ
90 //=================================================================================
91 // class : SMESHGUI_SymmetryDlg()
93 //=================================================================================
95 SMESHGUI_SymmetryDlg::SMESHGUI_SymmetryDlg( SMESHGUI* theModule )
96 : SMESHGUI_PreviewDlg( theModule ),
97 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
99 mySelectedObject(SMESH::SMESH_IDSource::_nil())
101 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_POINT")));
102 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_AXIS")));
103 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_PLANE")));
104 QPixmap image3 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
107 setAttribute(Qt::WA_DeleteOnClose, true);
108 setWindowTitle(tr("SMESH_SYMMETRY"));
109 setSizeGripEnabled(true);
111 QVBoxLayout* SMESHGUI_SymmetryDlgLayout = new QVBoxLayout(this);
112 SMESHGUI_SymmetryDlgLayout->setSpacing(SPACING);
113 SMESHGUI_SymmetryDlgLayout->setMargin(MARGIN);
115 /***************************************************************/
116 ConstructorsBox = new QGroupBox(tr("SMESH_SYMMETRY"), this);
117 GroupConstructors = new QButtonGroup(this);
118 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
119 ConstructorsBoxLayout->setSpacing(SPACING);
120 ConstructorsBoxLayout->setMargin(MARGIN);
122 RadioButton1 = new QRadioButton(ConstructorsBox);
123 RadioButton1->setIcon(image0);
124 RadioButton2 = new QRadioButton(ConstructorsBox);
125 RadioButton2->setIcon(image1);
126 RadioButton3 = new QRadioButton(ConstructorsBox);
127 RadioButton3->setIcon(image2);
129 ConstructorsBoxLayout->addWidget(RadioButton1);
130 ConstructorsBoxLayout->addWidget(RadioButton2);
131 ConstructorsBoxLayout->addWidget(RadioButton3);
132 GroupConstructors->addButton(RadioButton1, 0);
133 GroupConstructors->addButton(RadioButton2, 1);
134 GroupConstructors->addButton(RadioButton3, 2);
136 /***************************************************************/
137 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
138 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
139 GroupArgumentsLayout->setSpacing(SPACING);
140 GroupArgumentsLayout->setMargin(MARGIN);
142 myIdValidator = new SMESHGUI_IdValidator(this);
144 // Controls for elements selection
145 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
146 SelectElementsButton = new QPushButton(GroupArguments);
147 SelectElementsButton->setIcon(image3);
148 LineEditElements = new QLineEdit(GroupArguments);
149 LineEditElements->setValidator(myIdValidator);
150 LineEditElements->setMaxLength(-1);
151 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
152 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
154 // Control for the whole mesh selection
155 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
157 // Controls for mirror selection
158 GroupMirror = new QGroupBox(GroupArguments);
159 QGridLayout* GroupMirrorLayout = new QGridLayout(GroupMirror);
160 GroupMirrorLayout->setSpacing(SPACING);
161 GroupMirrorLayout->setMargin(MARGIN);
163 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupMirror);
164 SelectPointButton = new QPushButton(GroupMirror);
165 SelectPointButton->setIcon(image3);
167 TextLabelX = new QLabel(tr("SMESH_X"), GroupMirror);
168 SpinBox_X = new SMESHGUI_SpinBox(GroupMirror);
169 TextLabelY = new QLabel(tr("SMESH_Y"), GroupMirror);
170 SpinBox_Y = new SMESHGUI_SpinBox(GroupMirror);
171 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupMirror);
172 SpinBox_Z = new SMESHGUI_SpinBox(GroupMirror);
174 TextLabelVector = new QLabel(GroupMirror);
175 SelectVectorButton = new QPushButton(GroupMirror);
176 SelectVectorButton->setIcon(image3);
178 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupMirror);
179 SpinBox_DX = new SMESHGUI_SpinBox(GroupMirror);
180 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupMirror);
181 SpinBox_DY = new SMESHGUI_SpinBox(GroupMirror);
182 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupMirror);
183 SpinBox_DZ = new SMESHGUI_SpinBox(GroupMirror);
185 GroupMirrorLayout->addWidget(TextLabelPoint, 0, 0);
186 GroupMirrorLayout->addWidget(SelectPointButton, 0, 1);
187 GroupMirrorLayout->addWidget(TextLabelX, 0, 2);
188 GroupMirrorLayout->addWidget(SpinBox_X, 0, 3);
189 GroupMirrorLayout->addWidget(TextLabelY, 0, 4);
190 GroupMirrorLayout->addWidget(SpinBox_Y, 0, 5);
191 GroupMirrorLayout->addWidget(TextLabelZ, 0, 6);
192 GroupMirrorLayout->addWidget(SpinBox_Z, 0, 7);
193 GroupMirrorLayout->addWidget(TextLabelVector, 1, 0);
194 GroupMirrorLayout->addWidget(SelectVectorButton, 1, 1);
195 GroupMirrorLayout->addWidget(TextLabelDX, 1, 2);
196 GroupMirrorLayout->addWidget(SpinBox_DX, 1, 3);
197 GroupMirrorLayout->addWidget(TextLabelDY, 1, 4);
198 GroupMirrorLayout->addWidget(SpinBox_DY, 1, 5);
199 GroupMirrorLayout->addWidget(TextLabelDZ, 1, 6);
200 GroupMirrorLayout->addWidget(SpinBox_DZ, 1, 7);
202 // switch of action type
203 ActionBox = new QGroupBox(GroupArguments);
204 ActionGroup = new QButtonGroup(GroupArguments);
205 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
206 ActionBoxLayout->addSpacing(SPACING);
207 ActionBoxLayout->setMargin(MARGIN);
209 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
210 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
211 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
213 ActionBoxLayout->addWidget(aMoveElements);
214 ActionBoxLayout->addWidget(aCopyElements);
215 ActionBoxLayout->addWidget(aCreateMesh);
216 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
217 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
218 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
220 // CheckBox for groups generation
221 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
222 MakeGroupsCheck->setChecked(false);
224 // Name of a mesh to create
225 LineEditNewMesh = new QLineEdit(GroupArguments);
229 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
232 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
233 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
234 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 1);
235 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 3);
236 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
237 GroupArgumentsLayout->addWidget(GroupMirror, 2, 0, 1, 4);
238 GroupArgumentsLayout->addWidget(ActionBox, 3, 0, 3, 3);
239 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 4, 3);
240 GroupArgumentsLayout->addWidget(LineEditNewMesh, 5, 3);
241 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 6, 0);
243 /***************************************************************/
244 GroupButtons = new QGroupBox(this);
245 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
246 GroupButtonsLayout->setSpacing(SPACING);
247 GroupButtonsLayout->setMargin(MARGIN);
249 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
250 buttonOk->setAutoDefault(true);
251 buttonOk->setDefault(true);
252 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
253 buttonApply->setAutoDefault(true);
254 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
255 buttonCancel->setAutoDefault(true);
256 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
257 buttonHelp->setAutoDefault(true);
259 GroupButtonsLayout->addWidget(buttonOk);
260 GroupButtonsLayout->addSpacing(10);
261 GroupButtonsLayout->addWidget(buttonApply);
262 GroupButtonsLayout->addSpacing(10);
263 GroupButtonsLayout->addStretch();
264 GroupButtonsLayout->addWidget(buttonCancel);
265 GroupButtonsLayout->addWidget(buttonHelp);
267 /***************************************************************/
268 SMESHGUI_SymmetryDlgLayout->addWidget(ConstructorsBox);
269 SMESHGUI_SymmetryDlgLayout->addWidget(GroupArguments);
270 SMESHGUI_SymmetryDlgLayout->addWidget(GroupButtons);
272 /* Initialisations */
273 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
274 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
275 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
276 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
277 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
278 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
280 RadioButton1->setChecked(true);
282 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
284 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
286 // Costruction of the logical filter
287 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
288 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
290 QList<SUIT_SelectionFilter*> aListOfFilters;
291 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
292 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
294 myMeshOrSubMeshOrGroupFilter =
295 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
297 myHelpFileName = "symmetry_page.html";
301 /* signals and slots connections */
302 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
303 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
304 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
305 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
306 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
308 connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
309 connect(SelectPointButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
310 connect(SelectVectorButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
312 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
313 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
314 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
316 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
317 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
318 /* to close dialog if study change */
319 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
320 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
321 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
322 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
324 connect(SpinBox_X, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
325 connect(SpinBox_Y, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
326 connect(SpinBox_Z, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
327 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
328 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
329 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
331 //To Connect preview check box
332 connectPreviewControl();
334 ConstructorsClicked(0);
335 SelectionIntoArgument();
336 onActionClicked(MOVE_ELEMS_BUTTON);
339 //=================================================================================
340 // function : ~SMESHGUI_SymmetryDlg()
341 // purpose : Destroys the object and frees any allocated resources
342 //=================================================================================
343 SMESHGUI_SymmetryDlg::~SMESHGUI_SymmetryDlg()
345 if ( myFilterDlg != 0 ) {
346 myFilterDlg->setParent( 0 );
351 //=================================================================================
354 //=================================================================================
355 void SMESHGUI_SymmetryDlg::Init (bool ResetControls)
359 myEditCurrentArgument = 0;
360 LineEditElements->clear();
364 buttonOk->setEnabled(false);
365 buttonApply->setEnabled(false);
368 myMesh = SMESH::SMESH_Mesh::_nil();
371 SpinBox_X->SetValue(0.0);
372 SpinBox_Y->SetValue(0.0);
373 SpinBox_Z->SetValue(0.0);
374 SpinBox_DX->SetValue(0.0);
375 SpinBox_DY->SetValue(0.0);
376 SpinBox_DZ->SetValue(0.0);
378 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
379 CheckBoxMesh->setChecked(false);
380 myPreviewCheckBox->setChecked(false);
381 onDisplaySimulation(false);
383 // MakeGroupsCheck->setChecked(false);
384 // MakeGroupsCheck->setEnabled(false);
389 //=================================================================================
390 // function : ConstructorsClicked()
391 // purpose : Radio button management
392 //=================================================================================
393 void SMESHGUI_SymmetryDlg::ConstructorsClicked (int constructorId)
395 disconnect(mySelectionMgr, 0, this, 0);
397 if (constructorId != 0 && !TextLabelVector->isVisible()) {
398 TextLabelVector->show();
399 SelectVectorButton->show();
408 switch (constructorId) {
411 GroupMirror->setTitle(tr("SMESH_POINT"));
413 TextLabelVector->hide();
414 SelectVectorButton->hide();
425 GroupMirror->setTitle(tr("SMESH_AXIS"));
426 TextLabelVector->setText(tr("SMESH_VECTOR"));
431 GroupMirror->setTitle(tr("SMESH_PLANE"));
432 TextLabelVector->setText(tr("SMESH_NORMAL"));
437 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
438 SMESH::SetPointRepresentation(false);
439 if (!CheckBoxMesh->isChecked())
441 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
442 aViewWindow->SetSelectionMode(CellSelection);
446 myEditCurrentArgument = (QWidget*)LineEditElements;
447 LineEditElements->setFocus();
449 if (CheckBoxMesh->isChecked())
452 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
454 onDisplaySimulation(true);
456 QApplication::instance()->processEvents();
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;
499 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
501 switch ( actionButton ) {
502 case MOVE_ELEMS_BUTTON: {
503 if(CheckBoxMesh->isChecked())
504 aMeshEditor->MirrorObject(mySelectedObject, aMirror, aMirrorType, false );
506 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, false );
508 if( !myMesh->_is_nil())
509 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
512 case COPY_ELEMS_BUTTON: {
513 SMESH::ListOfGroups_var groups;
515 if(CheckBoxMesh->isChecked())
516 groups = aMeshEditor->MirrorObjectMakeGroups(mySelectedObject, aMirror, aMirrorType);
518 groups = aMeshEditor->MirrorMakeGroups(anElementsId, aMirror, aMirrorType);
521 if(CheckBoxMesh->isChecked())
522 aMeshEditor->MirrorObject(mySelectedObject, aMirror, aMirrorType, true);
524 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, true);
526 if( !myMesh->_is_nil())
527 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
530 case MAKE_MESH_BUTTON: {
531 SMESH::SMESH_Mesh_var mesh;
532 if (CheckBoxMesh->isChecked())
533 mesh = aMeshEditor->MirrorObjectMakeMesh(mySelectedObject, aMirror, aMirrorType, makeGroups,
534 LineEditNewMesh->text().toLatin1().data());
536 mesh = aMeshEditor->MirrorMakeMesh(anElementsId, aMirror, aMirrorType, makeGroups,
537 LineEditNewMesh->text().toLatin1().data());
538 if (!mesh->_is_nil()) {
539 mesh->SetParameters(aParameters.join(":").toLatin1().constData());
540 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
541 anEntryList.append( aSObject->GetID().c_str() );
542 #ifdef WITHGENERICOBJ
543 // obj has been published in study. Its refcount has been incremented.
544 // It is safe to decrement its refcount
545 // so that it will be destroyed when the entry in study will be removed
556 if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
557 actionButton == MAKE_MESH_BUTTON ) {
558 mySMESHGUI->updateObjBrowser(true); // new groups may appear
559 if( LightApp_Application* anApp =
560 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
561 anApp->browseObjects( anEntryList, isApplyAndClose() );
564 ConstructorsClicked(GetConstructorId());
565 mySelectedObject = SMESH::SMESH_IDSource::_nil();
566 SelectionIntoArgument();
568 SMESHGUI::Modified();
573 //=================================================================================
574 // function : ClickOnOk()
576 //=================================================================================
577 void SMESHGUI_SymmetryDlg::ClickOnOk()
579 setIsApplyAndClose( true );
584 //=================================================================================
585 // function : ClickOnCancel()
587 //=================================================================================
588 void SMESHGUI_SymmetryDlg::ClickOnCancel()
590 disconnect(mySelectionMgr, 0, this, 0);
591 mySelectionMgr->clearFilters();
592 //mySelectionMgr->clearSelected();
593 if (SMESH::GetCurrentVtkView()) {
594 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
595 SMESH::SetPointRepresentation(false);
597 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
598 aViewWindow->SetSelectionMode(ActorSelection);
599 mySMESHGUI->ResetState();
603 //=================================================================================
604 // function : ClickOnHelp()
606 //=================================================================================
607 void SMESHGUI_SymmetryDlg::ClickOnHelp()
609 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
611 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
615 platform = "winapplication";
617 platform = "application";
619 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
620 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
621 arg(app->resourceMgr()->stringValue("ExternalBrowser",
623 arg(myHelpFileName));
627 //=======================================================================
628 // function : onTextChange()
630 //=======================================================================
631 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
633 QLineEdit* send = (QLineEdit*)sender();
638 if (send == LineEditElements)
641 buttonOk->setEnabled(false);
642 buttonApply->setEnabled(false);
644 // hilight entered elements
645 SMDS_Mesh* aMesh = 0;
647 aMesh = myActor->GetObject()->GetMesh();
650 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
652 TColStd_MapOfInteger newIndices;
654 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
656 if (send == LineEditElements) {
657 for (int i = 0; i < aListId.count(); i++) {
658 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
660 newIndices.Add(e->GetID());
664 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
665 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
666 aViewWindow->highlight( anIO, true, true );
668 myElementsId = theNewText;
672 if (myNbOkElements && IsMirrorOk()) {
673 buttonOk->setEnabled(true);
674 buttonApply->setEnabled(true);
680 //=================================================================================
681 // function : SelectionIntoArgument()
682 // purpose : Called when selection as changed or other case
683 //=================================================================================
684 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
690 QString aString = "";
693 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
694 LineEditElements->setText(aString);
696 buttonOk->setEnabled(false);
697 buttonApply->setEnabled(false);
701 if (!GroupButtons->isEnabled()) // inactive
706 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
708 int nbSel = aList.Extent();
712 Handle(SALOME_InteractiveObject) IO = aList.First();
713 myMesh = SMESH::GetMeshByIO(IO);
714 if(myMesh->_is_nil())
717 myActor = SMESH::FindActorByObject(myMesh);
719 myActor = SMESH::FindActorByEntry(IO->getEntry());
720 if (!myActor && !CheckBoxMesh->isChecked())
725 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
728 // MakeGroups is available if there are groups and "Copy"
729 if ( myMesh->NbGroups() == 0 ) {
730 MakeGroupsCheck->setChecked(false);
731 MakeGroupsCheck->setEnabled(false);
733 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
734 MakeGroupsCheck->setEnabled(true);
736 if (CheckBoxMesh->isChecked()) {
737 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
739 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH
740 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
746 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
750 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
751 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
753 myElementsId += QString(" %1").arg(i);
757 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
759 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
761 // get IDs from submesh
763 SMESH::long_array_var anElementsIds = new SMESH::long_array;
764 anElementsIds = aSubMesh->GetElementsId();
765 for (int i = 0; i < anElementsIds->length(); i++) {
766 myElementsId += QString(" %1").arg(anElementsIds[i]);
768 aNbUnits = anElementsIds->length();
771 SMESH::SMESH_GroupBase_var aGroup =
772 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
773 if (aGroup->_is_nil())
776 // get IDs from smesh group
777 SMESH::long_array_var anElementsIds = new SMESH::long_array;
778 anElementsIds = aGroup->GetListOfID();
779 for (int i = 0; i < anElementsIds->length(); i++) {
780 myElementsId += QString(" %1").arg(anElementsIds[i]);
782 aNbUnits = anElementsIds->length();
786 aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, IO, aString);
787 myElementsId = aString;
792 myNbOkElements = true;
794 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
798 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
802 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
810 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
811 SpinBox_X->SetValue(x);
812 SpinBox_Y->SetValue(y);
813 SpinBox_Z->SetValue(z);
814 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
815 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
816 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
817 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
822 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
823 LineEditElements->setText(aString);
824 LineEditElements->repaint();
825 LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
826 LineEditElements->setEnabled(true);
832 if (myNbOkElements && IsMirrorOk()) {
833 buttonOk->setEnabled(true);
834 buttonApply->setEnabled(true);
836 onDisplaySimulation(true);
839 //=================================================================================
840 // function : SetEditCurrentArgument()
842 //=================================================================================
843 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
845 QPushButton* send = (QPushButton*)sender();
847 disconnect(mySelectionMgr, 0, this, 0);
848 mySelectionMgr->clearSelected();
849 mySelectionMgr->clearFilters();
851 if (send == SelectElementsButton) {
852 myEditCurrentArgument = (QWidget*)LineEditElements;
853 SMESH::SetPointRepresentation(false);
854 if (CheckBoxMesh->isChecked()) {
855 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
856 aViewWindow->SetSelectionMode(ActorSelection);
857 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
859 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
860 aViewWindow->SetSelectionMode(CellSelection);
862 } else if (send == SelectPointButton) {
863 myEditCurrentArgument = (QWidget*)SpinBox_X;
864 SMESH::SetPointRepresentation(true);
865 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
866 aViewWindow->SetSelectionMode(NodeSelection);
867 } else if (send == SelectVectorButton) {
868 myEditCurrentArgument = (QWidget*)SpinBox_DX;
869 SMESH::SetPointRepresentation(true);
871 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
872 aViewWindow->SetSelectionMode(NodeSelection);
876 myEditCurrentArgument->setFocus();
877 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
878 SelectionIntoArgument();
881 //=================================================================================
882 // function : DeactivateActiveDialog()
884 //=================================================================================
885 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
887 if (ConstructorsBox->isEnabled()) {
888 ConstructorsBox->setEnabled(false);
889 GroupArguments->setEnabled(false);
890 GroupButtons->setEnabled(false);
891 mySMESHGUI->ResetState();
892 mySMESHGUI->SetActiveDialogBox(0);
896 //=================================================================================
897 // function : ActivateThisDialog()
899 //=================================================================================
900 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
902 /* Emit a signal to deactivate the active dialog */
903 mySMESHGUI->EmitSignalDeactivateDialog();
904 ConstructorsBox->setEnabled(true);
905 GroupArguments->setEnabled(true);
906 GroupButtons->setEnabled(true);
908 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
910 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
911 aViewWindow->SetSelectionMode(CellSelection);
912 SelectionIntoArgument();
915 //=================================================================================
916 // function : enterEvent()
918 //=================================================================================
919 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
921 if (!ConstructorsBox->isEnabled())
922 ActivateThisDialog();
925 //=================================================================================
926 // function : closeEvent()
928 //=================================================================================
929 void SMESHGUI_SymmetryDlg::closeEvent (QCloseEvent*)
931 /* same than click on cancel button */
935 //=======================================================================
936 // function : hideEvent()
937 // purpose : caused by ESC key
938 //=======================================================================
939 void SMESHGUI_SymmetryDlg::hideEvent (QHideEvent*)
945 //=======================================================================
946 //function : onSelectMesh
948 //=======================================================================
949 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
952 TextLabelElements->setText(tr("SMESH_NAME"));
954 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
955 myFilterBtn->setEnabled(!toSelectMesh);
957 if (myEditCurrentArgument != LineEditElements) {
958 LineEditElements->clear();
962 mySelectionMgr->clearFilters();
963 SMESH::SetPointRepresentation(false);
966 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
967 aViewWindow->SetSelectionMode(ActorSelection);
968 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
969 LineEditElements->setReadOnly(true);
970 LineEditElements->setValidator(0);
972 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
973 aViewWindow->SetSelectionMode(CellSelection);
974 LineEditElements->setReadOnly(false);
975 LineEditElements->setValidator(myIdValidator);
976 onTextChange(LineEditElements->text());
980 SelectionIntoArgument();
983 //=================================================================================
984 // function : GetConstructorId()
986 //=================================================================================
987 int SMESHGUI_SymmetryDlg::GetConstructorId()
989 return GroupConstructors->checkedId();
992 //=================================================================================
993 // function : IsMirrorOk()
995 //=================================================================================
996 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
1000 if (GetConstructorId() != 0)
1001 isOk = (SpinBox_DX->GetValue() != 0 ||
1002 SpinBox_DY->GetValue() != 0 ||
1003 SpinBox_DZ->GetValue() != 0);
1008 //=================================================================================
1009 // function : onVectorChanged()
1011 //=================================================================================
1012 void SMESHGUI_SymmetryDlg::onVectorChanged()
1015 buttonOk->setEnabled(true);
1016 buttonApply->setEnabled(true);
1018 buttonOk->setEnabled(false);
1019 buttonApply->setEnabled(false);
1023 //=======================================================================
1024 //function : onActionClicked
1025 //purpose : slot called when an action type changed
1026 //=======================================================================
1028 void SMESHGUI_SymmetryDlg::onActionClicked(int button)
1031 case MOVE_ELEMS_BUTTON:
1032 MakeGroupsCheck->setEnabled(false);
1033 LineEditNewMesh->setEnabled(false);
1035 case COPY_ELEMS_BUTTON:
1036 LineEditNewMesh->setEnabled(false);
1037 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1038 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1039 MakeGroupsCheck->setEnabled(true);
1041 MakeGroupsCheck->setEnabled(false);
1043 case MAKE_MESH_BUTTON:
1044 LineEditNewMesh->setEnabled(true);
1045 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1046 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1047 MakeGroupsCheck->setEnabled(true);
1049 MakeGroupsCheck->setEnabled(false);
1053 toDisplaySimulation();
1056 //=======================================================================
1057 //function : setNewMeshName
1058 //purpose : update contents of LineEditNewMesh
1059 //=======================================================================
1061 void SMESHGUI_SymmetryDlg::setNewMeshName()
1063 LineEditNewMesh->setText("");
1064 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
1066 if ( CheckBoxMesh->isChecked() ) {
1067 name = LineEditElements->text();
1070 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
1071 name = meshSO->GetName().c_str();
1073 if ( !name.isEmpty() )
1074 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "mirrored"));
1078 //=================================================================================
1079 // function : keyPressEvent()
1081 //=================================================================================
1082 void SMESHGUI_SymmetryDlg::keyPressEvent( QKeyEvent* e )
1084 QDialog::keyPressEvent( e );
1085 if ( e->isAccepted() )
1088 if ( e->key() == Qt::Key_F1 ) {
1094 //=================================================================================
1095 // function : setFilters()
1096 // purpose : SLOT. Called when "Filter" button pressed.
1097 //=================================================================================
1098 void SMESHGUI_SymmetryDlg::setFilters()
1100 if(myMesh->_is_nil()) {
1101 SUIT_MessageBox::critical(this,
1103 tr("NO_MESH_SELECTED"));
1107 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1109 myFilterDlg->SetSelection();
1110 myFilterDlg->SetMesh( myMesh );
1111 myFilterDlg->SetSourceWg( LineEditElements );
1113 myFilterDlg->show();
1116 //=================================================================================
1117 // function : isValid
1119 //=================================================================================
1120 bool SMESHGUI_SymmetryDlg::isValid()
1125 ok = SpinBox_X->isValid( msg, true ) && ok;
1126 ok = SpinBox_Y->isValid( msg, true ) && ok;
1127 ok = SpinBox_Z->isValid( msg, true ) && ok;
1128 if (GetConstructorId() != 0) {
1129 ok = SpinBox_DX->isValid( msg, true ) && ok;
1130 ok = SpinBox_DY->isValid( msg, true ) && ok;
1131 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1135 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1136 if ( !msg.isEmpty() )
1138 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1144 //=================================================================================
1145 // function : onDisplaySimulation
1146 // purpose : Show/Hide preview
1147 //=================================================================================
1148 void SMESHGUI_SymmetryDlg::onDisplaySimulation( bool toDisplayPreview ) {
1149 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1150 if ( myNbOkElements && isValid() && IsMirrorOk() ) {
1151 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1152 SMESH::long_array_var anElementsId = new SMESH::long_array;
1154 anElementsId->length(aListElementsId.count());
1155 for (int i = 0; i < aListElementsId.count(); i++)
1156 anElementsId[i] = aListElementsId[i].toInt();
1158 SMESH::AxisStruct aMirror;
1159 SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
1161 getMirror(aMirror,aMirrorType);
1164 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1165 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1166 SUIT_OverrideCursor aWaitCursor;
1167 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
1168 if(CheckBoxMesh->isChecked())
1169 aMeshEditor->MirrorObject(mySelectedObject, aMirror, aMirrorType, copy );
1171 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, copy );
1173 SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
1174 mySimulation->SetData(aMeshPreviewStruct._retn());
1186 //=================================================================================
1187 // function : getMirror
1188 // purpose : return mirror parameters
1189 //=================================================================================
1190 void SMESHGUI_SymmetryDlg::getMirror(SMESH::AxisStruct& theMirror, SMESH::SMESH_MeshEditor::MirrorType& theMirrorType) {
1191 theMirror.x = SpinBox_X->GetValue();
1192 theMirror.y = SpinBox_Y->GetValue();
1193 theMirror.z = SpinBox_Z->GetValue();
1194 if (GetConstructorId() == 0) {
1195 theMirror.vx = theMirror.vy = theMirror.vz = 0;
1197 theMirror.vx = SpinBox_DX->GetValue();
1198 theMirror.vy = SpinBox_DY->GetValue();
1199 theMirror.vz = SpinBox_DZ->GetValue();
1201 if (GetConstructorId() == 0)
1202 theMirrorType = SMESH::SMESH_MeshEditor::POINT;
1203 if (GetConstructorId() == 1)
1204 theMirrorType = SMESH::SMESH_MeshEditor::AXIS;
1205 if (GetConstructorId() == 2)
1206 theMirrorType = SMESH::SMESH_MeshEditor::PLANE;