1 // Copyright (C) 2007-2013 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 (SMESH::MESHorSUBMESH);
288 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (SMESH::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(reject()));
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(reject()));
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 myMesh->SetParameters(aParameters.join(":").toLatin1().constData());
503 switch ( actionButton ) {
504 case MOVE_ELEMS_BUTTON: {
505 if(CheckBoxMesh->isChecked())
506 aMeshEditor->MirrorObject(mySelectedObject, aMirror, aMirrorType, false );
508 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, false );
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);
528 case MAKE_MESH_BUTTON: {
529 SMESH::SMESH_Mesh_var mesh;
530 if (CheckBoxMesh->isChecked())
531 mesh = aMeshEditor->MirrorObjectMakeMesh(mySelectedObject, aMirror, aMirrorType, makeGroups,
532 LineEditNewMesh->text().toLatin1().data());
534 mesh = aMeshEditor->MirrorMakeMesh(anElementsId, aMirror, aMirrorType, makeGroups,
535 LineEditNewMesh->text().toLatin1().data());
536 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
537 anEntryList.append( aSObject->GetID().c_str() );
538 #ifdef WITHGENERICOBJ
539 // obj has been published in study. Its refcount has been incremented.
540 // It is safe to decrement its refcount
541 // so that it will be destroyed when the entry in study will be removed
551 if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
552 actionButton == MAKE_MESH_BUTTON ) {
553 mySMESHGUI->updateObjBrowser(true); // new groups may appear
554 if( LightApp_Application* anApp =
555 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
556 anApp->browseObjects( anEntryList, isApplyAndClose() );
559 ConstructorsClicked(GetConstructorId());
560 mySelectedObject = SMESH::SMESH_IDSource::_nil();
561 SelectionIntoArgument();
563 SMESHGUI::Modified();
568 //=================================================================================
569 // function : ClickOnOk()
571 //=================================================================================
572 void SMESHGUI_SymmetryDlg::ClickOnOk()
574 setIsApplyAndClose( true );
579 //=================================================================================
580 // function : reject()
582 //=================================================================================
583 void SMESHGUI_SymmetryDlg::reject()
585 disconnect(mySelectionMgr, 0, this, 0);
586 mySelectionMgr->clearFilters();
587 //mySelectionMgr->clearSelected();
588 if (SMESH::GetCurrentVtkView()) {
589 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
590 SMESH::SetPointRepresentation(false);
592 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
593 aViewWindow->SetSelectionMode(ActorSelection);
594 mySMESHGUI->ResetState();
598 //=================================================================================
599 // function : ClickOnHelp()
601 //=================================================================================
602 void SMESHGUI_SymmetryDlg::ClickOnHelp()
604 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
606 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
610 platform = "winapplication";
612 platform = "application";
614 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
615 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
616 arg(app->resourceMgr()->stringValue("ExternalBrowser",
618 arg(myHelpFileName));
622 //=======================================================================
623 // function : onTextChange()
625 //=======================================================================
626 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
628 QLineEdit* send = (QLineEdit*)sender();
633 if (send == LineEditElements)
636 buttonOk->setEnabled(false);
637 buttonApply->setEnabled(false);
639 // hilight entered elements
640 SMDS_Mesh* aMesh = 0;
642 aMesh = myActor->GetObject()->GetMesh();
645 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
647 TColStd_MapOfInteger newIndices;
649 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
651 if (send == LineEditElements) {
652 for (int i = 0; i < aListId.count(); i++) {
653 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
655 newIndices.Add(e->GetID());
659 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
660 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
661 aViewWindow->highlight( anIO, true, true );
663 myElementsId = theNewText;
667 if (myNbOkElements && IsMirrorOk()) {
668 buttonOk->setEnabled(true);
669 buttonApply->setEnabled(true);
675 //=================================================================================
676 // function : SelectionIntoArgument()
677 // purpose : Called when selection as changed or other case
678 //=================================================================================
679 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
685 QString aString = "";
688 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
689 LineEditElements->setText(aString);
691 buttonOk->setEnabled(false);
692 buttonApply->setEnabled(false);
696 if (!GroupButtons->isEnabled()) // inactive
701 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
703 int nbSel = aList.Extent();
707 Handle(SALOME_InteractiveObject) IO = aList.First();
708 myMesh = SMESH::GetMeshByIO(IO);
709 if(myMesh->_is_nil())
712 myActor = SMESH::FindActorByObject(myMesh);
714 myActor = SMESH::FindActorByEntry(IO->getEntry());
715 if (!myActor && !CheckBoxMesh->isChecked())
720 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
723 // MakeGroups is available if there are groups and "Copy"
724 if ( myMesh->NbGroups() == 0 ) {
725 MakeGroupsCheck->setChecked(false);
726 MakeGroupsCheck->setEnabled(false);
728 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
729 MakeGroupsCheck->setEnabled(true);
731 if (CheckBoxMesh->isChecked()) {
732 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
734 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH
735 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
741 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
745 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
746 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
748 myElementsId += QString(" %1").arg(i);
752 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
754 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
756 // get IDs from submesh
758 SMESH::long_array_var anElementsIds = new SMESH::long_array;
759 anElementsIds = aSubMesh->GetElementsId();
760 for (int i = 0; i < anElementsIds->length(); i++) {
761 myElementsId += QString(" %1").arg(anElementsIds[i]);
763 aNbUnits = anElementsIds->length();
766 SMESH::SMESH_GroupBase_var aGroup =
767 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
768 if (aGroup->_is_nil())
771 // get IDs from smesh group
772 SMESH::long_array_var anElementsIds = new SMESH::long_array;
773 anElementsIds = aGroup->GetListOfID();
774 for (int i = 0; i < anElementsIds->length(); i++) {
775 myElementsId += QString(" %1").arg(anElementsIds[i]);
777 aNbUnits = anElementsIds->length();
781 aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, IO, aString);
782 myElementsId = aString;
787 myNbOkElements = true;
789 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
793 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
797 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
805 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
806 SpinBox_X->SetValue(x);
807 SpinBox_Y->SetValue(y);
808 SpinBox_Z->SetValue(z);
809 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
810 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
811 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
812 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
817 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
818 LineEditElements->setText(aString);
819 LineEditElements->repaint();
820 LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
821 LineEditElements->setEnabled(true);
827 if (myNbOkElements && IsMirrorOk()) {
828 buttonOk->setEnabled(true);
829 buttonApply->setEnabled(true);
831 onDisplaySimulation(true);
834 //=================================================================================
835 // function : SetEditCurrentArgument()
837 //=================================================================================
838 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
840 QPushButton* send = (QPushButton*)sender();
842 disconnect(mySelectionMgr, 0, this, 0);
843 mySelectionMgr->clearSelected();
844 mySelectionMgr->clearFilters();
846 if (send == SelectElementsButton) {
847 myEditCurrentArgument = (QWidget*)LineEditElements;
848 SMESH::SetPointRepresentation(false);
849 if (CheckBoxMesh->isChecked()) {
850 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
851 aViewWindow->SetSelectionMode(ActorSelection);
852 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
854 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
855 aViewWindow->SetSelectionMode(CellSelection);
857 } else if (send == SelectPointButton) {
858 myEditCurrentArgument = (QWidget*)SpinBox_X;
859 SMESH::SetPointRepresentation(true);
860 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
861 aViewWindow->SetSelectionMode(NodeSelection);
862 } else if (send == SelectVectorButton) {
863 myEditCurrentArgument = (QWidget*)SpinBox_DX;
864 SMESH::SetPointRepresentation(true);
866 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
867 aViewWindow->SetSelectionMode(NodeSelection);
871 myEditCurrentArgument->setFocus();
872 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
873 SelectionIntoArgument();
876 //=================================================================================
877 // function : DeactivateActiveDialog()
879 //=================================================================================
880 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
882 if (ConstructorsBox->isEnabled()) {
883 ConstructorsBox->setEnabled(false);
884 GroupArguments->setEnabled(false);
885 GroupButtons->setEnabled(false);
886 mySMESHGUI->ResetState();
887 mySMESHGUI->SetActiveDialogBox(0);
891 //=================================================================================
892 // function : ActivateThisDialog()
894 //=================================================================================
895 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
897 /* Emit a signal to deactivate the active dialog */
898 mySMESHGUI->EmitSignalDeactivateDialog();
899 ConstructorsBox->setEnabled(true);
900 GroupArguments->setEnabled(true);
901 GroupButtons->setEnabled(true);
903 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
905 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
906 aViewWindow->SetSelectionMode(CellSelection);
907 SelectionIntoArgument();
910 //=================================================================================
911 // function : enterEvent()
913 //=================================================================================
914 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
916 if (!ConstructorsBox->isEnabled())
917 ActivateThisDialog();
920 //=======================================================================
921 //function : onSelectMesh
923 //=======================================================================
924 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
927 TextLabelElements->setText(tr("SMESH_NAME"));
929 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
930 myFilterBtn->setEnabled(!toSelectMesh);
932 if (myEditCurrentArgument != LineEditElements) {
933 LineEditElements->clear();
937 mySelectionMgr->clearFilters();
938 SMESH::SetPointRepresentation(false);
941 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
942 aViewWindow->SetSelectionMode(ActorSelection);
943 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
944 LineEditElements->setReadOnly(true);
945 LineEditElements->setValidator(0);
947 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
948 aViewWindow->SetSelectionMode(CellSelection);
949 LineEditElements->setReadOnly(false);
950 LineEditElements->setValidator(myIdValidator);
951 onTextChange(LineEditElements->text());
955 SelectionIntoArgument();
958 //=================================================================================
959 // function : GetConstructorId()
961 //=================================================================================
962 int SMESHGUI_SymmetryDlg::GetConstructorId()
964 return GroupConstructors->checkedId();
967 //=================================================================================
968 // function : IsMirrorOk()
970 //=================================================================================
971 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
975 if (GetConstructorId() != 0)
976 isOk = (SpinBox_DX->GetValue() != 0 ||
977 SpinBox_DY->GetValue() != 0 ||
978 SpinBox_DZ->GetValue() != 0);
983 //=================================================================================
984 // function : onVectorChanged()
986 //=================================================================================
987 void SMESHGUI_SymmetryDlg::onVectorChanged()
990 buttonOk->setEnabled(true);
991 buttonApply->setEnabled(true);
993 buttonOk->setEnabled(false);
994 buttonApply->setEnabled(false);
998 //=======================================================================
999 //function : onActionClicked
1000 //purpose : slot called when an action type changed
1001 //=======================================================================
1003 void SMESHGUI_SymmetryDlg::onActionClicked(int button)
1006 case MOVE_ELEMS_BUTTON:
1007 MakeGroupsCheck->setEnabled(false);
1008 LineEditNewMesh->setEnabled(false);
1010 case COPY_ELEMS_BUTTON:
1011 LineEditNewMesh->setEnabled(false);
1012 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1013 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1014 MakeGroupsCheck->setEnabled(true);
1016 MakeGroupsCheck->setEnabled(false);
1018 case MAKE_MESH_BUTTON:
1019 LineEditNewMesh->setEnabled(true);
1020 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1021 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1022 MakeGroupsCheck->setEnabled(true);
1024 MakeGroupsCheck->setEnabled(false);
1028 toDisplaySimulation();
1031 //=======================================================================
1032 //function : setNewMeshName
1033 //purpose : update contents of LineEditNewMesh
1034 //=======================================================================
1036 void SMESHGUI_SymmetryDlg::setNewMeshName()
1038 LineEditNewMesh->setText("");
1039 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
1041 if ( CheckBoxMesh->isChecked() ) {
1042 name = LineEditElements->text();
1045 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
1046 name = meshSO->GetName().c_str();
1048 if ( !name.isEmpty() )
1049 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "mirrored"));
1053 //=================================================================================
1054 // function : keyPressEvent()
1056 //=================================================================================
1057 void SMESHGUI_SymmetryDlg::keyPressEvent( QKeyEvent* e )
1059 QDialog::keyPressEvent( e );
1060 if ( e->isAccepted() )
1063 if ( e->key() == Qt::Key_F1 ) {
1069 //=================================================================================
1070 // function : setFilters()
1071 // purpose : SLOT. Called when "Filter" button pressed.
1072 //=================================================================================
1073 void SMESHGUI_SymmetryDlg::setFilters()
1075 if(myMesh->_is_nil()) {
1076 SUIT_MessageBox::critical(this,
1078 tr("NO_MESH_SELECTED"));
1082 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1084 myFilterDlg->SetSelection();
1085 myFilterDlg->SetMesh( myMesh );
1086 myFilterDlg->SetSourceWg( LineEditElements );
1088 myFilterDlg->show();
1091 //=================================================================================
1092 // function : isValid
1094 //=================================================================================
1095 bool SMESHGUI_SymmetryDlg::isValid()
1100 ok = SpinBox_X->isValid( msg, true ) && ok;
1101 ok = SpinBox_Y->isValid( msg, true ) && ok;
1102 ok = SpinBox_Z->isValid( msg, true ) && ok;
1103 if (GetConstructorId() != 0) {
1104 ok = SpinBox_DX->isValid( msg, true ) && ok;
1105 ok = SpinBox_DY->isValid( msg, true ) && ok;
1106 ok = SpinBox_DZ->isValid( msg, true ) && ok;
1110 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1111 if ( !msg.isEmpty() )
1113 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1119 //=================================================================================
1120 // function : onDisplaySimulation
1121 // purpose : Show/Hide preview
1122 //=================================================================================
1123 void SMESHGUI_SymmetryDlg::onDisplaySimulation( bool toDisplayPreview ) {
1124 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1125 if ( myNbOkElements && isValid() && IsMirrorOk() ) {
1126 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1127 SMESH::long_array_var anElementsId = new SMESH::long_array;
1129 anElementsId->length(aListElementsId.count());
1130 for (int i = 0; i < aListElementsId.count(); i++)
1131 anElementsId[i] = aListElementsId[i].toInt();
1133 SMESH::AxisStruct aMirror;
1134 SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
1136 getMirror(aMirror,aMirrorType);
1139 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1140 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1141 SUIT_OverrideCursor aWaitCursor;
1142 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
1143 if(CheckBoxMesh->isChecked())
1144 aMeshEditor->MirrorObject(mySelectedObject, aMirror, aMirrorType, copy );
1146 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, copy );
1148 SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
1149 mySimulation->SetData(aMeshPreviewStruct._retn());
1161 //=================================================================================
1162 // function : getMirror
1163 // purpose : return mirror parameters
1164 //=================================================================================
1165 void SMESHGUI_SymmetryDlg::getMirror(SMESH::AxisStruct& theMirror, SMESH::SMESH_MeshEditor::MirrorType& theMirrorType) {
1166 theMirror.x = SpinBox_X->GetValue();
1167 theMirror.y = SpinBox_Y->GetValue();
1168 theMirror.z = SpinBox_Z->GetValue();
1169 if (GetConstructorId() == 0) {
1170 theMirror.vx = theMirror.vy = theMirror.vz = 0;
1172 theMirror.vx = SpinBox_DX->GetValue();
1173 theMirror.vy = SpinBox_DY->GetValue();
1174 theMirror.vz = SpinBox_DZ->GetValue();
1176 if (GetConstructorId() == 0)
1177 theMirrorType = SMESH::SMESH_MeshEditor::POINT;
1178 if (GetConstructorId() == 1)
1179 theMirrorType = SMESH::SMESH_MeshEditor::AXIS;
1180 if (GetConstructorId() == 2)
1181 theMirrorType = SMESH::SMESH_MeshEditor::PLANE;