Salome HOME
1) Fix for bug IPAL19258 : Qt4 porting. Incorrect view of Preferences: no default...
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_SymmetryDlg.cxx
1 // SMESH SMESHGUI : GUI for SMESH component
2 //
3 // Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 //
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. 
10 //
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. 
15 //
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 
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : SMESHGUI_SymmetryDlg.cxx
23 // Author : Michael ZORIN, Open CASCADE S.A.S.
24 //
25
26 // SMESH includes
27 #include "SMESHGUI_SymmetryDlg.h"
28
29 #include "SMESHGUI.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
36 #include <SMESH_Actor.h>
37 #include <SMESH_TypeFilter.hxx>
38 #include <SMESH_LogicalFilter.hxx>
39 #include <SMDS_Mesh.hxx>
40
41 // SALOME GUI includes
42 #include <SUIT_Desktop.h>
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_MessageBox.h>
46
47 #include <LightApp_Application.h>
48 #include <LightApp_SelectionMgr.h>
49
50 #include <SVTK_ViewModel.h>
51 #include <SVTK_ViewWindow.h>
52 #include <SALOME_ListIO.hxx>
53
54 // SALOME KERNEL includes
55 #include <SALOMEDSClient_SObject.hxx>
56
57 // OCCT includes
58 #include <TColStd_MapOfInteger.hxx>
59
60 // Qt includes
61 #include <QApplication>
62 #include <QButtonGroup>
63 #include <QGroupBox>
64 #include <QLabel>
65 #include <QLineEdit>
66 #include <QPushButton>
67 #include <QRadioButton>
68 #include <QCheckBox>
69 #include <QHBoxLayout>
70 #include <QVBoxLayout>
71 #include <QGridLayout>
72 #include <QKeyEvent>
73
74 // IDL includes
75 #include <SALOMEconfig.h>
76 #include CORBA_SERVER_HEADER(SMESH_Group)
77 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
78
79 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
80
81 #define SPACING 6
82 #define MARGIN  11
83
84 //=================================================================================
85 // class    : SMESHGUI_SymmetryDlg()
86 // purpose  :
87 //=================================================================================
88
89 SMESHGUI_SymmetryDlg::SMESHGUI_SymmetryDlg( SMESHGUI* theModule )
90   : QDialog( SMESH::GetDesktop( theModule ) ),
91     mySMESHGUI( theModule ),
92     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
93 {
94   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_POINT")));
95   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_AXIS")));
96   QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_PLANE")));
97   QPixmap image3 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
98
99   setModal(false);
100   setAttribute(Qt::WA_DeleteOnClose, true);
101   setWindowTitle(tr("SMESH_SYMMETRY"));
102   setSizeGripEnabled(true);
103
104   QVBoxLayout* SMESHGUI_SymmetryDlgLayout = new QVBoxLayout(this);
105   SMESHGUI_SymmetryDlgLayout->setSpacing(SPACING);
106   SMESHGUI_SymmetryDlgLayout->setMargin(MARGIN);
107
108   /***************************************************************/
109   ConstructorsBox = new QGroupBox(tr("SMESH_SYMMETRY"), this);
110   GroupConstructors = new QButtonGroup(this);
111   QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
112   ConstructorsBoxLayout->setSpacing(SPACING);
113   ConstructorsBoxLayout->setMargin(MARGIN);
114
115   RadioButton1 = new QRadioButton(ConstructorsBox);
116   RadioButton1->setIcon(image0);
117   RadioButton2 = new QRadioButton(ConstructorsBox);
118   RadioButton2->setIcon(image1);
119   RadioButton3 = new QRadioButton(ConstructorsBox);
120   RadioButton3->setIcon(image2);
121
122   ConstructorsBoxLayout->addWidget(RadioButton1);
123   ConstructorsBoxLayout->addWidget(RadioButton2);
124   ConstructorsBoxLayout->addWidget(RadioButton3);
125   GroupConstructors->addButton(RadioButton1, 0);
126   GroupConstructors->addButton(RadioButton2, 1);
127   GroupConstructors->addButton(RadioButton3, 2);
128
129   /***************************************************************/
130   GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
131   QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
132   GroupArgumentsLayout->setSpacing(SPACING);
133   GroupArgumentsLayout->setMargin(MARGIN);
134
135   myIdValidator = new SMESHGUI_IdValidator(this);
136
137   // Controls for elements selection
138   TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
139   SelectElementsButton  = new QPushButton(GroupArguments);
140   SelectElementsButton->setIcon(image3);
141   LineEditElements = new QLineEdit(GroupArguments);
142   LineEditElements->setValidator(myIdValidator);
143
144   // Control for the whole mesh selection
145   CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
146
147   // Controls for mirror selection
148   GroupMirror = new QGroupBox(GroupArguments);
149   QGridLayout* GroupMirrorLayout = new QGridLayout(GroupMirror);
150   GroupMirrorLayout->setSpacing(SPACING);
151   GroupMirrorLayout->setMargin(MARGIN);
152
153   TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupMirror);
154   SelectPointButton  = new QPushButton(GroupMirror);
155   SelectPointButton->setIcon(image3);
156
157   TextLabelX = new QLabel(tr("SMESH_X"), GroupMirror);
158   SpinBox_X = new SMESHGUI_SpinBox(GroupMirror);
159   TextLabelY = new QLabel(tr("SMESH_Y"), GroupMirror);
160   SpinBox_Y = new SMESHGUI_SpinBox(GroupMirror);
161   TextLabelZ = new QLabel(tr("SMESH_Z"), GroupMirror);
162   SpinBox_Z = new SMESHGUI_SpinBox(GroupMirror);
163
164   TextLabelVector = new QLabel(GroupMirror);
165   SelectVectorButton = new QPushButton(GroupMirror);
166   SelectVectorButton->setIcon(image3);
167
168   TextLabelDX = new QLabel(tr("SMESH_DX"), GroupMirror);
169   SpinBox_DX = new SMESHGUI_SpinBox(GroupMirror);
170   TextLabelDY = new QLabel(tr("SMESH_DY"), GroupMirror);
171   SpinBox_DY = new SMESHGUI_SpinBox(GroupMirror);
172   TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupMirror);
173   SpinBox_DZ = new SMESHGUI_SpinBox(GroupMirror);
174
175   GroupMirrorLayout->addWidget(TextLabelPoint,     0, 0);
176   GroupMirrorLayout->addWidget(SelectPointButton,  0, 1);
177   GroupMirrorLayout->addWidget(TextLabelX,         0, 2);
178   GroupMirrorLayout->addWidget(SpinBox_X,          0, 3);
179   GroupMirrorLayout->addWidget(TextLabelY,         0, 4);
180   GroupMirrorLayout->addWidget(SpinBox_Y,          0, 5);
181   GroupMirrorLayout->addWidget(TextLabelZ,         0, 6);
182   GroupMirrorLayout->addWidget(SpinBox_Z,          0, 7);
183   GroupMirrorLayout->addWidget(TextLabelVector,    1, 0);
184   GroupMirrorLayout->addWidget(SelectVectorButton, 1, 1);
185   GroupMirrorLayout->addWidget(TextLabelDX,        1, 2);
186   GroupMirrorLayout->addWidget(SpinBox_DX,         1, 3);
187   GroupMirrorLayout->addWidget(TextLabelDY,        1, 4);
188   GroupMirrorLayout->addWidget(SpinBox_DY,         1, 5);
189   GroupMirrorLayout->addWidget(TextLabelDZ,        1, 6);
190   GroupMirrorLayout->addWidget(SpinBox_DZ,         1, 7);
191
192   // switch of action type
193   ActionBox = new QGroupBox(GroupArguments);
194   ActionGroup = new QButtonGroup(GroupArguments);
195   QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
196   ActionBoxLayout->addSpacing(SPACING);
197   ActionBoxLayout->setMargin(MARGIN);
198
199   QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
200   QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
201   QRadioButton* aCreateMesh   = new QRadioButton(tr("SMESH_CREATE_MESH"),   ActionBox);
202
203   ActionBoxLayout->addWidget(aMoveElements);
204   ActionBoxLayout->addWidget(aCopyElements);
205   ActionBoxLayout->addWidget(aCreateMesh);
206   ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
207   ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
208   ActionGroup->addButton(aCreateMesh,   MAKE_MESH_BUTTON);
209
210   // CheckBox for groups generation
211   MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
212   MakeGroupsCheck->setChecked(false);
213
214   // Name of a mesh to create
215   LineEditNewMesh = new QLineEdit(GroupArguments);
216
217   // layout
218   GroupArgumentsLayout->addWidget(TextLabelElements,    0, 0);
219   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
220   GroupArgumentsLayout->addWidget(LineEditElements,     0, 2, 1, 2);
221   GroupArgumentsLayout->addWidget(CheckBoxMesh,         1, 0, 1, 4);
222   GroupArgumentsLayout->addWidget(GroupMirror,          2, 0, 1, 4);
223   GroupArgumentsLayout->addWidget(ActionBox,            3, 0, 3, 3);
224   GroupArgumentsLayout->addWidget(MakeGroupsCheck,      4, 3);
225   GroupArgumentsLayout->addWidget(LineEditNewMesh,      5, 3);
226
227   /***************************************************************/
228   GroupButtons = new QGroupBox(this);
229   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
230   GroupButtonsLayout->setSpacing(SPACING);
231   GroupButtonsLayout->setMargin(MARGIN);
232
233   buttonOk = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons);
234   buttonOk->setAutoDefault(true);
235   buttonOk->setDefault(true);
236   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
237   buttonApply->setAutoDefault(true);
238   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
239   buttonCancel->setAutoDefault(true);
240   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
241   buttonHelp->setAutoDefault(true);
242
243   GroupButtonsLayout->addWidget(buttonOk);
244   GroupButtonsLayout->addSpacing(10);
245   GroupButtonsLayout->addWidget(buttonApply);
246   GroupButtonsLayout->addSpacing(10);
247   GroupButtonsLayout->addStretch();
248   GroupButtonsLayout->addWidget(buttonCancel);
249   GroupButtonsLayout->addWidget(buttonHelp);
250
251   /***************************************************************/
252   SMESHGUI_SymmetryDlgLayout->addWidget(ConstructorsBox);
253   SMESHGUI_SymmetryDlgLayout->addWidget(GroupArguments);
254   SMESHGUI_SymmetryDlgLayout->addWidget(GroupButtons);
255
256   /* Initialisations */
257   SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
258   SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
259   SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
260   SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
261   SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
262   SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
263
264   RadioButton1->setChecked(true);
265
266   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
267
268   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
269
270   // Costruction of the logical filter
271   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
272   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
273
274   QList<SUIT_SelectionFilter*> aListOfFilters;
275   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
276   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
277
278   myMeshOrSubMeshOrGroupFilter =
279     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
280
281   myHelpFileName = "symmetry_page.html";
282
283   Init();
284
285   /* signals and slots connections */
286   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
287   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
288   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
289   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
290   connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
291
292   connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
293   connect(SelectPointButton,    SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
294   connect(SelectVectorButton,   SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
295
296   connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
297   connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
298   connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
299
300   connect(mySMESHGUI,     SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
301   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),      this, SLOT(SelectionIntoArgument()));
302   /* to close dialog if study change */
303   connect(mySMESHGUI,       SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
304   connect(LineEditElements, SIGNAL(textChanged(const QString&)),   SLOT(onTextChange(const QString&)));
305   connect(CheckBoxMesh,     SIGNAL(toggled(bool)),                 SLOT(onSelectMesh(bool)));
306   connect(ActionGroup,      SIGNAL(buttonClicked(int)),            SLOT(onActionClicked(int)));
307
308   ConstructorsClicked(0);
309   SelectionIntoArgument();
310   onActionClicked(MOVE_ELEMS_BUTTON);
311 }
312
313 //=================================================================================
314 // function : ~SMESHGUI_SymmetryDlg()
315 // purpose  : Destroys the object and frees any allocated resources
316 //=================================================================================
317 SMESHGUI_SymmetryDlg::~SMESHGUI_SymmetryDlg()
318 {
319 }
320
321 //=================================================================================
322 // function : Init()
323 // purpose  :
324 //=================================================================================
325 void SMESHGUI_SymmetryDlg::Init (bool ResetControls)
326 {
327   myBusy = false;
328
329   myEditCurrentArgument = 0;
330   LineEditElements->clear();
331   myElementsId = "";
332   myNbOkElements = 0;
333
334   buttonOk->setEnabled(false);
335   buttonApply->setEnabled(false);
336
337   myActor = 0;
338   myMesh = SMESH::SMESH_Mesh::_nil();
339
340   if (ResetControls) {
341     SpinBox_X->SetValue(0.0);
342     SpinBox_Y->SetValue(0.0);
343     SpinBox_Z->SetValue(0.0);
344     SpinBox_DX->SetValue(0.0);
345     SpinBox_DY->SetValue(0.0);
346     SpinBox_DZ->SetValue(0.0);
347
348     ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
349     CheckBoxMesh->setChecked(false);
350 //     MakeGroupsCheck->setChecked(false);
351 //     MakeGroupsCheck->setEnabled(false);
352     onSelectMesh(false);
353   }
354 }
355
356 //=================================================================================
357 // function : ConstructorsClicked()
358 // purpose  : Radio button management
359 //=================================================================================
360 void SMESHGUI_SymmetryDlg::ConstructorsClicked (int constructorId)
361 {
362   disconnect(mySelectionMgr, 0, this, 0);
363
364   if (constructorId != 0 && !TextLabelVector->isVisible()) {
365     TextLabelVector->show();
366     SelectVectorButton->show();
367     TextLabelDX->show();
368     SpinBox_DX->show();
369     TextLabelDY->show();
370     SpinBox_DY->show();
371     TextLabelDZ->show();
372     SpinBox_DZ->show();
373   }
374
375   switch (constructorId) {
376   case 0:
377     {
378       GroupMirror->setTitle(tr("SMESH_POINT"));
379
380       TextLabelVector->hide();
381       SelectVectorButton->hide();
382       TextLabelDX->hide();
383       SpinBox_DX->hide();
384       TextLabelDY->hide();
385       SpinBox_DY->hide();
386       TextLabelDZ->hide();
387       SpinBox_DZ->hide();
388       break;
389     }
390   case 1:
391     {
392       GroupMirror->setTitle(tr("SMESH_AXIS"));
393       TextLabelVector->setText(tr("SMESH_VECTOR"));
394       break;
395     }
396   case 2:
397     {
398       GroupMirror->setTitle(tr("SMESH_PLANE"));
399       TextLabelVector->setText(tr("SMESH_NORMAL"));
400       break;
401     }
402   }
403
404   if (myEditCurrentArgument != (QWidget*)LineEditElements) {
405     SMESH::SetPointRepresentation(false);
406     if (!CheckBoxMesh->isChecked())
407       {
408         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
409           aViewWindow->SetSelectionMode(CellSelection);
410       }
411   }
412
413   myEditCurrentArgument = (QWidget*)LineEditElements;
414   LineEditElements->setFocus();
415
416   if (CheckBoxMesh->isChecked())
417     onSelectMesh(true);
418
419   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
420
421   QApplication::instance()->processEvents();
422   updateGeometry();
423   resize( minimumSize() );
424 }
425
426 //=================================================================================
427 // function : ClickOnApply()
428 // purpose  :
429 //=================================================================================
430 void SMESHGUI_SymmetryDlg::ClickOnApply()
431 {
432   if (mySMESHGUI->isActiveStudyLocked())
433     return;
434
435   if (myNbOkElements && IsMirrorOk()) {
436     QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
437
438     SMESH::long_array_var anElementsId = new SMESH::long_array;
439
440     anElementsId->length(aListElementsId.count());
441     for (int i = 0; i < aListElementsId.count(); i++)
442       anElementsId[i] = aListElementsId[i].toInt();
443
444     SMESH::AxisStruct aMirror;
445
446     aMirror.x =  SpinBox_X->GetValue();
447     aMirror.y =  SpinBox_Y->GetValue();
448     aMirror.z =  SpinBox_Z->GetValue();
449     if (GetConstructorId() == 0) {
450       aMirror.vx = aMirror.vy = aMirror.vz = 0;
451     } else {
452       aMirror.vx = SpinBox_DX->GetValue();
453       aMirror.vy = SpinBox_DY->GetValue();
454       aMirror.vz = SpinBox_DZ->GetValue();
455     }
456
457
458     SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
459
460     if (GetConstructorId() == 0)
461       aMirrorType = SMESH::SMESH_MeshEditor::POINT;
462     if (GetConstructorId() == 1)
463       aMirrorType = SMESH::SMESH_MeshEditor::AXIS;
464     if (GetConstructorId() == 2)
465       aMirrorType = SMESH::SMESH_MeshEditor::PLANE;
466
467     int actionButton = ActionGroup->checkedId();
468     bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
469
470     try {
471       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
472       QApplication::setOverrideCursor(Qt::WaitCursor);
473       switch ( actionButton ) {
474       case MOVE_ELEMS_BUTTON:
475         aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, false );
476         break;
477       case COPY_ELEMS_BUTTON:
478         if ( makeGroups )
479           SMESH::ListOfGroups_var groups = 
480             aMeshEditor->MirrorMakeGroups(anElementsId, aMirror, aMirrorType);
481         else
482           aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, true);
483         break;
484       case MAKE_MESH_BUTTON:
485         SMESH::SMESH_Mesh_var mesh = 
486           aMeshEditor->MirrorMakeMesh(anElementsId, aMirror, aMirrorType, makeGroups,
487                                       LineEditNewMesh->text().toLatin1().data());
488       }
489       QApplication::restoreOverrideCursor();
490     } catch (...) {
491     }
492
493     SMESH::UpdateView();
494     if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
495          actionButton == MAKE_MESH_BUTTON )
496       mySMESHGUI->updateObjBrowser(true); // new groups may appear
497     Init(false);
498     ConstructorsClicked(GetConstructorId());
499     SelectionIntoArgument();
500   }
501 }
502
503 //=================================================================================
504 // function : ClickOnOk()
505 // purpose  :
506 //=================================================================================
507 void SMESHGUI_SymmetryDlg::ClickOnOk()
508 {
509   ClickOnApply();
510   ClickOnCancel();
511 }
512
513 //=================================================================================
514 // function : ClickOnCancel()
515 // purpose  :
516 //=================================================================================
517 void SMESHGUI_SymmetryDlg::ClickOnCancel()
518 {
519   disconnect(mySelectionMgr, 0, this, 0);
520   mySelectionMgr->clearFilters();
521   //mySelectionMgr->clearSelected();
522   SMESH::SetPointRepresentation(false);
523   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
524     aViewWindow->SetSelectionMode(ActorSelection);
525   mySMESHGUI->ResetState();
526   reject();
527 }
528
529 //=================================================================================
530 // function : ClickOnHelp()
531 // purpose  :
532 //=================================================================================
533 void SMESHGUI_SymmetryDlg::ClickOnHelp()
534 {
535   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
536   if (app) 
537     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
538   else {
539     QString platform;
540 #ifdef WIN32
541     platform = "winapplication";
542 #else
543     platform = "application";
544 #endif
545     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
546                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
547                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
548                                                                  platform)).
549                              arg(myHelpFileName));
550   }
551 }
552
553 //=======================================================================
554 // function : onTextChange()
555 // purpose  :
556 //=======================================================================
557 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
558 {
559   QLineEdit* send = (QLineEdit*)sender();
560
561   if (myBusy) return;
562   myBusy = true;
563
564   if (send == LineEditElements)
565     myNbOkElements = 0;
566
567   buttonOk->setEnabled(false);
568   buttonApply->setEnabled(false);
569
570   // hilight entered elements
571   SMDS_Mesh* aMesh = 0;
572   if (myActor)
573     aMesh = myActor->GetObject()->GetMesh();
574
575   if (aMesh) {
576     Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
577
578     TColStd_MapOfInteger newIndices;
579     
580     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
581
582     if (send == LineEditElements) {
583       for (int i = 0; i < aListId.count(); i++) {
584         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
585         if (e)
586           newIndices.Add(e->GetID());
587         myNbOkElements++;
588       }
589
590       mySelector->AddOrRemoveIndex( anIO, newIndices, false );
591       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
592         aViewWindow->highlight( anIO, true, true );
593       
594       myElementsId = theNewText;
595     }
596   }
597
598   if (myNbOkElements &&  IsMirrorOk()) {
599     buttonOk->setEnabled(true);
600     buttonApply->setEnabled(true);
601   }
602
603   myBusy = false;
604 }
605
606 //=================================================================================
607 // function : SelectionIntoArgument()
608 // purpose  : Called when selection as changed or other case
609 //=================================================================================
610 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
611 {
612   if (myBusy) return;
613
614   // clear
615   myActor = 0;
616   QString aString = "";
617
618   myBusy = true;
619   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
620     LineEditElements->setText(aString);
621     myNbOkElements = 0;
622     buttonOk->setEnabled(false);
623     buttonApply->setEnabled(false);
624   }
625   myBusy = false;
626
627   if (!GroupButtons->isEnabled()) // inactive
628     return;
629
630   // get selected mesh
631   SALOME_ListIO aList;
632   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
633
634   int nbSel = aList.Extent();
635   if (nbSel != 1)
636     return;
637
638   Handle(SALOME_InteractiveObject) IO = aList.First();
639   myMesh = SMESH::GetMeshByIO(IO);
640   if(myMesh->_is_nil())
641     return;
642
643   myActor = SMESH::FindActorByObject(myMesh);
644   if (!myActor)
645     myActor = SMESH::FindActorByEntry(IO->getEntry());
646   if (!myActor)
647     return;
648
649   int aNbUnits = 0;
650
651   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
652     myElementsId = "";
653
654     // MakeGroups is available if there are groups and "Copy"
655     if ( myMesh->NbGroups() == 0 ) {
656       MakeGroupsCheck->setChecked(false);
657       MakeGroupsCheck->setEnabled(false);
658     }
659     else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
660       MakeGroupsCheck->setEnabled(true);
661     }
662     if (CheckBoxMesh->isChecked()) {
663       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
664
665       if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
666         // get IDs from mesh
667         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
668         if (!aSMDSMesh)
669           return;
670
671         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
672           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
673           if (e) {
674             myElementsId += QString(" %1").arg(i);
675             aNbUnits++;
676           }
677         }
678       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
679         // get submesh
680         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
681
682         // get IDs from submesh
683         SMESH::long_array_var anElementsIds = new SMESH::long_array;
684         anElementsIds = aSubMesh->GetElementsId();
685         for (int i = 0; i < anElementsIds->length(); i++) {
686           myElementsId += QString(" %1").arg(anElementsIds[i]);
687         }
688         aNbUnits = anElementsIds->length();
689       } else { // GROUP
690         // get smesh group
691         SMESH::SMESH_GroupBase_var aGroup =
692           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
693         if (aGroup->_is_nil())
694           return;
695
696         // get IDs from smesh group
697         SMESH::long_array_var anElementsIds = new SMESH::long_array;
698         anElementsIds = aGroup->GetListOfID();
699         for (int i = 0; i < anElementsIds->length(); i++) {
700           myElementsId += QString(" %1").arg(anElementsIds[i]);
701         }
702         aNbUnits = anElementsIds->length();
703       }
704     } else {
705       aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, IO, aString);
706       myElementsId = aString;
707     }
708
709     if (aNbUnits < 1)
710       return;
711
712     myNbOkElements = true;
713   } else {
714     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
715     if (aNbUnits != 1)
716       return;
717
718     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
719     if (!aMesh)
720       return;
721
722     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
723     if (!n)
724       return;
725
726     double x = n->X();
727     double y = n->Y();
728     double z = n->Z();
729
730     if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
731       SpinBox_X->SetValue(x);
732       SpinBox_Y->SetValue(y);
733       SpinBox_Z->SetValue(z);
734     } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
735       SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
736       SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
737       SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
738     }
739   }
740
741   myBusy = true;
742   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
743     LineEditElements->setText(aString);
744     setNewMeshName();
745   }
746   myBusy = false;
747
748   // OK
749   if (myNbOkElements && IsMirrorOk()) {
750     buttonOk->setEnabled(true);
751     buttonApply->setEnabled(true);
752   }
753 }
754
755 //=================================================================================
756 // function : SetEditCurrentArgument()
757 // purpose  :
758 //=================================================================================
759 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
760 {
761   QPushButton* send = (QPushButton*)sender();
762
763   disconnect(mySelectionMgr, 0, this, 0);
764   mySelectionMgr->clearSelected();
765   mySelectionMgr->clearFilters();
766
767   if (send == SelectElementsButton) {
768     myEditCurrentArgument = (QWidget*)LineEditElements;
769     SMESH::SetPointRepresentation(false);
770     if (CheckBoxMesh->isChecked()) {
771       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
772         aViewWindow->SetSelectionMode(ActorSelection);
773       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
774     } else {
775       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
776         aViewWindow->SetSelectionMode(CellSelection);
777     }
778   } else if (send == SelectPointButton) {
779     myEditCurrentArgument = (QWidget*)SpinBox_X;
780     SMESH::SetPointRepresentation(true);
781     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
782       aViewWindow->SetSelectionMode(NodeSelection);
783   } else if (send == SelectVectorButton) {
784     myEditCurrentArgument = (QWidget*)SpinBox_DX;
785     SMESH::SetPointRepresentation(true);
786
787     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
788       aViewWindow->SetSelectionMode(NodeSelection);
789   } else {
790   }
791
792   myEditCurrentArgument->setFocus();
793   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
794   SelectionIntoArgument();
795 }
796
797 //=================================================================================
798 // function : DeactivateActiveDialog()
799 // purpose  :
800 //=================================================================================
801 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
802 {
803   if (ConstructorsBox->isEnabled()) {
804     ConstructorsBox->setEnabled(false);
805     GroupArguments->setEnabled(false);
806     GroupButtons->setEnabled(false);
807     mySMESHGUI->ResetState();
808     mySMESHGUI->SetActiveDialogBox(0);
809   }
810 }
811
812 //=================================================================================
813 // function : ActivateThisDialog()
814 // purpose  :
815 //=================================================================================
816 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
817 {
818   /* Emit a signal to deactivate the active dialog */
819   mySMESHGUI->EmitSignalDeactivateDialog();
820   ConstructorsBox->setEnabled(true);
821   GroupArguments->setEnabled(true);
822   GroupButtons->setEnabled(true);
823
824   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
825
826   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
827     aViewWindow->SetSelectionMode(CellSelection);
828   SelectionIntoArgument();
829 }
830
831 //=================================================================================
832 // function : enterEvent()
833 // purpose  :
834 //=================================================================================
835 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
836 {
837   if (!ConstructorsBox->isEnabled())
838     ActivateThisDialog();
839 }
840
841 //=================================================================================
842 // function : closeEvent()
843 // purpose  :
844 //=================================================================================
845 void SMESHGUI_SymmetryDlg::closeEvent (QCloseEvent*)
846 {
847   /* same than click on cancel button */
848   ClickOnCancel();
849 }
850
851 //=======================================================================
852 // function : hideEvent()
853 // purpose  : caused by ESC key
854 //=======================================================================
855 void SMESHGUI_SymmetryDlg::hideEvent (QHideEvent*)
856 {
857   if (!isMinimized())
858     ClickOnCancel();
859 }
860
861 //=======================================================================
862 //function : onSelectMesh
863 //purpose  :
864 //=======================================================================
865 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
866 {
867   if (toSelectMesh)
868     TextLabelElements->setText(tr("SMESH_NAME"));
869   else
870     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
871
872   if (myEditCurrentArgument != LineEditElements) {
873     LineEditElements->clear();
874     return;
875   }
876
877   mySelectionMgr->clearFilters();
878   SMESH::SetPointRepresentation(false);
879
880   if (toSelectMesh) {
881     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
882       aViewWindow->SetSelectionMode(ActorSelection);
883     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
884     LineEditElements->setReadOnly(true);
885     LineEditElements->setValidator(0);
886   } else {
887     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
888       aViewWindow->SetSelectionMode(CellSelection);
889     LineEditElements->setReadOnly(false);
890     LineEditElements->setValidator(myIdValidator);
891     onTextChange(LineEditElements->text());
892   }
893
894   SelectionIntoArgument();
895 }
896
897 //=================================================================================
898 // function : GetConstructorId()
899 // purpose  :
900 //=================================================================================
901 int SMESHGUI_SymmetryDlg::GetConstructorId()
902 {
903   return GroupConstructors->checkedId();
904 }
905
906 //=================================================================================
907 // function : IsMirrorOk()
908 // purpose  :
909 //=================================================================================
910 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
911 {
912   bool isOk = true;
913
914   if (GetConstructorId() != 0)
915     isOk = (SpinBox_DX->GetValue() != 0 ||
916             SpinBox_DY->GetValue() != 0 ||
917             SpinBox_DZ->GetValue() != 0);
918
919   return isOk;
920 }
921
922 //=================================================================================
923 // function : onVectorChanged()
924 // purpose  :
925 //=================================================================================
926 void SMESHGUI_SymmetryDlg::onVectorChanged()
927 {
928   if (IsMirrorOk()) {
929     buttonOk->setEnabled(true);
930     buttonApply->setEnabled(true);
931   } else {
932     buttonOk->setEnabled(false);
933     buttonApply->setEnabled(false);
934   }
935 }
936
937 //=======================================================================
938 //function : onActionClicked
939 //purpose  : slot called when an action type changed
940 //=======================================================================
941
942 void SMESHGUI_SymmetryDlg::onActionClicked(int button)
943 {
944   switch ( button ) {
945   case MOVE_ELEMS_BUTTON:
946     MakeGroupsCheck->setEnabled(false);
947     LineEditNewMesh->setEnabled(false);
948     break;
949   case COPY_ELEMS_BUTTON:
950     LineEditNewMesh->setEnabled(false);
951     MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
952     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
953       MakeGroupsCheck->setEnabled(true);
954     else
955       MakeGroupsCheck->setEnabled(false);
956     break;
957   case MAKE_MESH_BUTTON:
958     LineEditNewMesh->setEnabled(true);
959     MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
960     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
961       MakeGroupsCheck->setEnabled(true);
962     else
963       MakeGroupsCheck->setEnabled(false);
964     break;
965   }
966   setNewMeshName();
967 }
968
969 //=======================================================================
970 //function : setNewMeshName
971 //purpose  : update contents of LineEditNewMesh
972 //=======================================================================
973
974 void SMESHGUI_SymmetryDlg::setNewMeshName()
975 {
976   LineEditNewMesh->setText("");
977   if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
978     QString name;
979     if ( CheckBoxMesh->isChecked() ) {
980       name = LineEditElements->text();
981     }
982     else {
983       _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
984       name = meshSO->GetName().c_str();
985     }
986     if ( !name.isEmpty() )
987       LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "mirrored"));
988   }
989 }
990
991 //=================================================================================
992 // function : keyPressEvent()
993 // purpose  :
994 //=================================================================================
995 void SMESHGUI_SymmetryDlg::keyPressEvent( QKeyEvent* e )
996 {
997   QDialog::keyPressEvent( e );
998   if ( e->isAccepted() )
999     return;
1000
1001   if ( e->key() == Qt::Key_F1 ) {
1002     e->accept();
1003     ClickOnHelp();
1004   }
1005 }