Salome HOME
09524789d37d38d819ab689f8ffa0b10336f3680
[modules/geom.git] / src / OperationGUI / OperationGUI_ChamferDlg.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : OperationGUI_ChamferDlg.cxx
25 // Author : Damien COQUERET, Open CASCADE S.A.S.
26
27 #include "OperationGUI_ChamferDlg.h"
28 #include <SalomeApp_DoubleSpinBox.h>
29
30 #include <DlgRef.h>
31 #include <GeometryGUI.h>
32 #include <GEOMBase.h>
33
34 #include <SUIT_Desktop.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_ResourceMgr.h>
37 #include <SUIT_ViewWindow.h>
38 #include <SUIT_ViewManager.h>
39 #include <SalomeApp_Application.h>
40 #include <LightApp_SelectionMgr.h>
41 #include <OCCViewer_ViewModel.h>
42
43 // OCCT Includes
44 #include <TColStd_MapOfInteger.hxx>
45
46 #include <GEOMImpl_Types.hxx>
47
48 //=================================================================================
49 // class    : OperationGUI_ChamferDlg()
50 // purpose  : Constructs a OperationGUI_ChamferDlg which is a child of 'parent', with the
51 //            name 'name' and widget flags set to 'f'.
52 //            The dialog will by default be modeless, unless you set 'modal' to
53 //            TRUE to construct a modal dialog.
54 //=================================================================================
55 OperationGUI_ChamferDlg::OperationGUI_ChamferDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
56   : GEOMBase_Skeleton(theGeometryGUI, parent, false),
57     myInitial(true)
58 {
59   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
60   QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_CHAMFER_ALL")));
61   QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_CHAMFER_EDGE_FROM_FACE")));
62   QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_CHAMFER_FACE")));
63   QPixmap image4 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_CHAMFER_EDGE")));
64
65   QPixmap iconSelect (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
66
67   setWindowTitle(tr("GEOM_CHAMFER_TITLE"));
68
69   /***************************************************************/
70   mainFrame()->GroupConstructors->setTitle(tr("GEOM_CHAMFER"));
71
72   mainFrame()->RadioButton1->setIcon(image1);
73   mainFrame()->RadioButton2->setIcon(image2);
74   mainFrame()->RadioButton3->setIcon(image3);
75   mainFrame()->RadioButton4->show();
76   mainFrame()->RadioButton4->setIcon(image4);
77
78   // Create first group
79
80   myGrp1 = new QGroupBox(tr("GEOM_CHAMFER_ALL"), centralWidget());
81
82   QGridLayout* aLayout = new QGridLayout(myGrp1);
83   aLayout->setMargin(9); aLayout->setSpacing(6);
84
85   createSelWg(tr("GEOM_MAIN_OBJECT"), iconSelect, myGrp1, aLayout, MainObj1);
86
87   int row = aLayout->rowCount();
88   aLayout->addWidget(new QLabel(tr("D"), myGrp1), row, 0);
89   aLayout->addWidget((mySpinBox[ SpinBox1 ] = new SalomeApp_DoubleSpinBox(myGrp1)), row++, 2);
90   aLayout->setRowStretch(row, 10);
91
92   // Create second group
93
94   myGrp2 = new QGroupBox(tr("GEOM_CHAMFER_EDGE"), centralWidget());
95
96   aLayout = new QGridLayout(myGrp2);
97   aLayout->setMargin(9); aLayout->setSpacing(6);
98
99   createSelWg(tr("GEOM_MAIN_OBJECT"), iconSelect, myGrp2, aLayout, MainObj2);
100   createSelWg(tr("FACE_1"),           iconSelect, myGrp2, aLayout, Face1);
101   createSelWg(tr("FACE_2"),           iconSelect, myGrp2, aLayout, Face2);
102
103   createRadioWg(tr("GEOM_D1"), tr("GEOM_D2"),    myGrp2, aLayout, RadioButton21, SpinBox21, SpinBox22);
104   createRadioWg(tr("GEOM_D"),  tr("GEOM_ANGLE"), myGrp2, aLayout, RadioButton22, SpinBox23, SpinBox24);
105
106   aLayout->setRowStretch(aLayout->rowCount(), 10);
107
108   // Create third group
109
110   myGrp3 = new QGroupBox(tr("GEOM_CHAMFER_FACES"), centralWidget());
111
112   aLayout = new QGridLayout(myGrp3);
113   aLayout->setMargin(9); aLayout->setSpacing(6);
114
115   createSelWg(tr("GEOM_MAIN_OBJECT"), iconSelect, myGrp3, aLayout, MainObj3);
116   createSelWg(tr("SELECTED_FACES"),   iconSelect, myGrp3, aLayout, Faces);
117
118   createRadioWg(tr("GEOM_D1"), tr("GEOM_D2"),    myGrp3, aLayout, RadioButton31, SpinBox31, SpinBox32);
119   createRadioWg(tr("GEOM_D"),  tr("GEOM_ANGLE"), myGrp3, aLayout, RadioButton32, SpinBox33, SpinBox34);
120
121   aLayout->setRowStretch(aLayout->rowCount(), 10);
122
123   // Create fourth group
124
125   myGrp4 = new QGroupBox(tr("GEOM_CHAMFER_EDGES"), centralWidget());
126
127   aLayout = new QGridLayout(myGrp4);
128   aLayout->setMargin(9); aLayout->setSpacing(6);
129
130   createSelWg(tr("GEOM_MAIN_OBJECT"), iconSelect, myGrp4, aLayout, MainObj4);
131   createSelWg(tr("SELECTED_EDGE"),    iconSelect, myGrp4, aLayout, Edges);
132
133   createRadioWg(tr("GEOM_D1"), tr("GEOM_D2"),    myGrp4, aLayout, RadioButton41, SpinBox41, SpinBox42);
134   createRadioWg(tr("GEOM_D"),  tr("GEOM_ANGLE"), myGrp4, aLayout, RadioButton42, SpinBox43, SpinBox44);
135
136   aLayout->setRowStretch(aLayout->rowCount(), 10);
137
138   // Add groups to layout
139
140   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
141   layout->setMargin(0); layout->setSpacing(6);
142   layout->addWidget(myGrp1);
143   layout->addWidget(myGrp2);
144   layout->addWidget(myGrp3);
145   layout->addWidget(myGrp4);
146   /***************************************************************/
147
148   // Set range of spinboxes
149   double SpecificStep = 10.0;
150   QMap< int, SalomeApp_DoubleSpinBox* >::iterator anIter;
151   for (anIter = mySpinBox.begin(); anIter != mySpinBox.end(); ++anIter) {
152     if (anIter.key() == SpinBox44 || anIter.key() == SpinBox34 || anIter.key() == SpinBox24)
153       initSpinBox(anIter.value(), 0.001, 89.999, 5, "angle_precision" );
154     else
155       initSpinBox(anIter.value(), 0.001, COORD_MAX, SpecificStep, "length_precision" );
156   }
157
158   setHelpFileName("chamfer_operation_page.html");
159
160   // Initialisation
161   Init();
162   myRadioButton[ RadioButton21 ]->click();
163 }
164
165 //=================================================================================
166 // function : ~OperationGUI_ChamferDlg()
167 // purpose  : Destroys the object and frees any allocated resources
168 //=================================================================================
169 OperationGUI_ChamferDlg::~OperationGUI_ChamferDlg()
170 {
171 }
172
173 //=================================================================================
174 // function : Init()
175 // purpose  :
176 //=================================================================================
177 void OperationGUI_ChamferDlg::Init()
178 {
179   // Set Initial values of spinboxes
180   QMap< int, SalomeApp_DoubleSpinBox* >::iterator anIter;
181   for (anIter = mySpinBox.begin(); anIter != mySpinBox.end(); ++anIter)
182     anIter.value()->setValue(5);
183
184   // Clear line edits
185   QMap< int, QLineEdit* >::iterator anIterLE;
186   for (anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE)
187     anIterLE.value()->setText("");
188
189   myShape = GEOM::GEOM_Object::_nil();
190
191   myFaces.Clear();
192   myEdges.Clear();
193   myFace[ Face1 ] = -1;
194   myFace[ Face2 ] = -1;
195
196   showOnlyPreviewControl();
197
198   // signals and slots connections
199
200   // main buttons
201   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()   ));
202   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
203
204   // group box
205   connect(this,          SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
206
207   // push buttons
208   QMap< int, QPushButton* >::iterator anIterBtn;
209   for (anIterBtn = mySelBtn.begin(); anIterBtn != mySelBtn.end(); ++anIterBtn)
210     connect(anIterBtn.value(), SIGNAL(clicked()),
211             this, SLOT(SetEditCurrentArgument()));
212
213   // line edits
214   QMap< int, QLineEdit* >::iterator anIterLE2;
215   for (anIterLE2 = mySelName.begin(); anIterLE2 != mySelName.end(); ++anIterLE2)
216     connect(anIterLE2.value(), SIGNAL(returnPressed()),
217             this, SLOT(LineEditReturnPressed()));
218
219   // spin boxes
220   QMap< int, SalomeApp_DoubleSpinBox* >::iterator anIterSpin;
221   for (anIterSpin = mySpinBox.begin(); anIterSpin != mySpinBox.end(); ++anIterSpin)
222     connect(anIterSpin.value(), SIGNAL(valueChanged(double)),
223             this, SLOT(ValueChangedInSpinBox(double)));
224
225   // radio buttons
226   QMap< int, QRadioButton* >::iterator anIterRadio;
227   for (anIterRadio = myRadioButton.begin(); anIterRadio != myRadioButton.end(); ++anIterRadio)
228     connect(anIterRadio.value(), SIGNAL(clicked()),
229             this, SLOT(RadioButtonPressed()));
230
231   initName(tr("GEOM_CHAMFER"));
232
233   myConstructorId = -1;
234   ConstructorsClicked(0);
235 }
236
237 //=================================================================================
238 // function : ConstructorsClicked()
239 // purpose  : Radio button management
240 //=================================================================================
241 void OperationGUI_ChamferDlg::ConstructorsClicked (int constructorId)
242 {
243    // Activate next widget
244   if (myGeomGUI->getApp()->desktop()->activeWindow()->getViewManager()->getType()
245       != OCCViewer_Viewer::Type()) {
246     mainFrame()->RadioButton1->setChecked(true);
247     return;
248   }
249
250   if (myConstructorId == constructorId)
251     return;
252
253   //disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
254
255   // Get values from previous widget
256   QString D1 = "5", D2 = "5", D = "5", Angle = "5";
257   if (myConstructorId == 0)
258     D1 = D2 = mySpinBox[ SpinBox1 ]->text();
259   else if (myConstructorId == 1) {
260     D1 = mySpinBox[ SpinBox21 ]->text();
261     D2 = mySpinBox[ SpinBox22 ]->text();
262     D =  mySpinBox[ SpinBox23 ]->text();
263     Angle = mySpinBox[ SpinBox24 ]->text();
264   }
265   else if (myConstructorId == 2) {
266     D1 = mySpinBox[ SpinBox31 ]->text();
267     D2 = mySpinBox[ SpinBox32 ]->text();
268     D =  mySpinBox[ SpinBox33 ]->text();
269     Angle = mySpinBox[ SpinBox34 ]->text();
270   }
271   else if (myConstructorId == 3) {
272     D1 = mySpinBox[ SpinBox41 ]->text();
273     D2 = mySpinBox[ SpinBox42 ]->text();
274     D =  mySpinBox[ SpinBox43 ]->text();
275     Angle = mySpinBox[ SpinBox44 ]->text();
276   }
277
278   myConstructorId = constructorId;
279
280   switch (constructorId) {
281   case 0:
282     myGrp2->hide();
283     myGrp3->hide();
284     myGrp4->hide();
285     myGrp1->show();
286     mySpinBox[ SpinBox1 ]->setText(D1);
287     break;
288   case 1:
289     myGrp1->hide();
290     myGrp3->hide();
291     myGrp4->hide();
292     myGrp2->show();
293     mySpinBox[ SpinBox21 ]->setText(D1);
294     mySpinBox[ SpinBox22 ]->setText(D2);
295     mySpinBox[ SpinBox23 ]->setText(D);
296     mySpinBox[ SpinBox24 ]->setText(Angle);
297     break;
298   case 2:
299     myGrp1->hide();
300     myGrp2->hide();
301     myGrp4->hide();
302     myGrp3->show();
303     mySpinBox[ SpinBox31 ]->setText(D1);
304     mySpinBox[ SpinBox32 ]->setText(D2);
305     mySpinBox[ SpinBox32 ]->setText(D2);
306     mySpinBox[ SpinBox33 ]->setText(D);
307     mySpinBox[ SpinBox34 ]->setText(Angle);
308     break;
309   case 3:
310     myGrp1->hide();
311     myGrp2->hide();
312     myGrp3->hide();
313     myGrp4->show();
314     mySpinBox[ SpinBox41 ]->setText(D1);
315     mySpinBox[ SpinBox42 ]->setText(D2);
316     mySpinBox[ SpinBox43 ]->setText(D);
317     mySpinBox[ SpinBox44 ]->setText(Angle);
318     break;
319   default:
320     break;
321   }
322
323   if      (constructorId == 0) mySelBtn[ MainObj1 ]->click();
324   else if (constructorId == 1) mySelBtn[ MainObj2 ]->click();
325   else if (constructorId == 2) mySelBtn[ MainObj3 ]->click();
326   else                         mySelBtn[ MainObj4 ]->click();
327
328   enableWidgets();
329
330   if (myInitial) {
331     myInitial = false;
332     SelectionIntoArgument();
333   }
334   else {
335     if (!myShape->_is_nil()) {
336       myEditCurrentArgument->setText(GEOMBase::GetName(myShape));
337       GEOMBase_Skeleton::LineEditReturnPressed();
338       switch (getConstructorId()) {
339       case 1:
340         if (myFace[ Face1 ] == -1)
341           mySelBtn[ Face1 ]->click();
342         break;
343       case 2:
344         if (myFaces.Extent() == 0)
345           mySelBtn[ Faces ]->click();
346         break;
347       case 3:
348         if (myEdges.Extent() == 0)
349           mySelBtn[ Edges ]->click();
350         break;
351       default:
352         break;
353       }
354     }
355     else {
356       myEditCurrentArgument->setText("");
357     }
358
359     processPreview();
360   }
361
362   qApp->processEvents();
363   updateGeometry();
364   resize(minimumSizeHint());
365 }
366
367 //=================================================================================
368 // function : ClickOnOk()
369 // purpose  :
370 //=================================================================================
371 void OperationGUI_ChamferDlg::ClickOnOk()
372 {
373   setIsApplyAndClose( true );
374   if (ClickOnApply())
375     ClickOnCancel();
376 }
377
378 //=================================================================================
379 // function : ClickOnApply()
380 // purpose  :
381 //=================================================================================
382 bool OperationGUI_ChamferDlg::ClickOnApply()
383 {
384   if (!onAccept())
385     return false;
386
387   initName();
388   // activate selection and connect selection manager
389   ConstructorsClicked(getConstructorId());
390   return true;
391 }
392
393 //=================================================================================
394 // function : SelectionIntoArgument()
395 // purpose  : Called when selection is changed or on dialog initialization or activation
396 //=================================================================================
397 void OperationGUI_ChamferDlg::SelectionIntoArgument()
398 {
399   erasePreview();
400   myEditCurrentArgument->setText("");
401
402   // Get index of current selection focus
403   int aCurrFocus = -1;
404   QMap< int, QLineEdit* >::iterator anIter;
405   for (anIter = mySelName.begin(); anIter != mySelName.end(); ++anIter) {
406     if (myEditCurrentArgument == anIter.value()) {
407       aCurrFocus = anIter.key();
408       break;
409     }
410   }
411
412   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
413   SALOME_ListIO aSelList;
414   aSelMgr->selectedObjects(aSelList);
415
416   // If selection of main object is activated
417   if (aCurrFocus == MainObj1 || aCurrFocus == MainObj2 || aCurrFocus == MainObj3 || aCurrFocus == MainObj4)
418   {
419     myShape = GEOM::GEOM_Object::_nil();
420     if (aSelList.Extent() == 1) {
421       GEOM::GEOM_Object_var anObj =
422         GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
423
424       if ( !anObj->_is_nil() ) {
425         myShape = anObj;
426         myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
427         processPreview();
428       }
429     }
430
431     enableWidgets();
432   }
433   // If face selection of second tab is activated
434   else if (aCurrFocus == Face1 || aCurrFocus == Face2)
435   {
436     myFace[ aCurrFocus ] = -1;
437     if (aSelList.Extent() == 1) {
438       GEOM::GEOM_Object_var anObj =
439         GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
440
441       if ( !anObj->_is_nil() ) {
442          TColStd_IndexedMapOfInteger anIndexes;
443          aSelMgr->GetIndexes(aSelList.First(), anIndexes);
444
445          if (anIndexes.Extent() == 1) {
446             int anIndex = anIndexes(1);
447             QString aFaceName = QString(GEOMBase::GetName(anObj)) + ":%1";
448             myEditCurrentArgument->setText(aFaceName.arg(anIndex));
449             myFace[ aCurrFocus ] = anIndex;
450             processPreview();
451          }
452       }
453     }
454   }
455   // If face selection of third or fourth tab is activated
456   else if (aCurrFocus == Faces || aCurrFocus == Edges) {
457     if (aCurrFocus == Faces) myFaces.Clear();
458     else myEdges.Clear();
459     if (aSelList.Extent() == 1) {
460       GEOM::GEOM_Object_var anObj =
461         GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
462
463       if ( !anObj->_is_nil() ) {
464         TColStd_IndexedMapOfInteger anIndexes;
465         aSelMgr->GetIndexes(aSelList.First(), anIndexes);
466
467         if (anIndexes.Extent() > 0) {
468           QString aName;
469           if (anIndexes.Extent() == 1) {
470             int anIndex = anIndexes(1);
471
472             aName = QString(GEOMBase::GetName(anObj)) + QString(":%1").arg(anIndex);
473           }
474           else {
475             aName = tr("GEOM_MEN_POPUP_NAME").arg(anIndexes.Extent());
476           }
477
478           myEditCurrentArgument->setText(aName);
479           int aConstructorId = getConstructorId();
480           if (aConstructorId == 2)
481             myFaces = anIndexes;
482           else if (aConstructorId == 3)
483             myEdges = anIndexes;
484
485           processPreview();
486         }
487       }
488     }
489   }
490
491   // clear selection
492   if (aCurrFocus != Face1 && aCurrFocus != Face2 &&
493       aCurrFocus != Faces && aCurrFocus != Edges) {
494     disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
495     myGeomGUI->getApp()->selectionMgr()->clearSelected();
496     connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
497             this, SLOT(SelectionIntoArgument()));
498   }
499
500   switch (getConstructorId()) {
501   case 1:
502     if (aCurrFocus == MainObj2) {
503       if (!myShape->_is_nil() && myFace[ Face1 ] == -1)
504         mySelBtn[ Face1 ]->click();
505     }
506     else if (aCurrFocus == Face1) {
507       if (myFace[ Face1 ] != -1 && myFace[ Face2 ] == -1)
508         mySelBtn[ Face2 ]->click();
509     }
510     else if (aCurrFocus == Face2) {
511       if (myFace[ Face2 ] != -1 && myShape->_is_nil())
512         mySelBtn[ MainObj2 ]->click();
513     }
514     break;
515   case 2:
516     if (aCurrFocus == MainObj3) {
517       if (!myShape->_is_nil() && myFaces.Extent() == 0)
518         mySelBtn[ Faces ]->click();
519     }
520     break;
521   case 3:
522     if (aCurrFocus == MainObj4) {
523       if (!myShape->_is_nil() && myEdges.Extent() == 0)
524         mySelBtn[ Edges ]->click();
525     }
526     break;
527   default:
528     break;
529   }
530
531   //rnv: To fix the bug IPAL22041 TC5.1.5: "Fillet Construcion" dialog loses current selection.
532   // Restore selection of the main shape, if need,
533   // because it was canceled.
534   aSelMgr->selectedObjects(aSelList);
535   if (aSelList.Extent() == 0 && !myShape->_is_nil()) {
536     disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
537     ObjectList list;
538         list.push_back(myShape);
539     selectObjects(list);
540     connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
541             this, SLOT(SelectionIntoArgument()));
542   }
543 }
544
545 //=================================================================================
546 // function : SetEditCurrentArgument()
547 // purpose  :
548 //=================================================================================
549 void OperationGUI_ChamferDlg::SetEditCurrentArgument()
550 {
551   QPushButton* send = (QPushButton*)sender();
552
553   QMap< int, QPushButton* >::iterator anIter;
554   for (anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter) {
555     if (anIter.value() == send) {
556       mySelName[ anIter.key() ]->setFocus();
557       myEditCurrentArgument = mySelName[ anIter.key() ];
558     }
559     else {
560       anIter.value()->setDown(false);
561       mySelName[ anIter.key() ]->setEnabled(false);
562     }
563   }
564
565   // enable line edit
566   myEditCurrentArgument->setEnabled(true);
567   myEditCurrentArgument->setFocus();
568   // after setFocus(), because it will be setDown(false) when loses focus
569   send->setDown(true);
570
571   activateSelection();
572
573   // seems we need it only to avoid preview disappearing, caused by selection mode change
574   processPreview();
575 }
576
577 //=================================================================================
578 // function : LineEditReturnPressed()
579 // purpose  :
580 //=================================================================================
581 void OperationGUI_ChamferDlg::LineEditReturnPressed()
582 {
583   QLineEdit* send = (QLineEdit*)sender();
584
585   QMap< int, QLineEdit* >::iterator anIterLE;
586   for (anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE)
587     if (anIterLE.value() == send)
588       myEditCurrentArgument = anIterLE.value();
589
590   GEOMBase_Skeleton::LineEditReturnPressed();
591 }
592
593 //=================================================================================
594 // function : ActivateThisDialog()
595 // purpose  :
596 //=================================================================================
597 void OperationGUI_ChamferDlg::ActivateThisDialog()
598 {
599   GEOMBase_Skeleton::ActivateThisDialog();
600   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
601            this, SLOT( SelectionIntoArgument() ) );
602
603   ConstructorsClicked( getConstructorId() );
604 }
605
606 //=================================================================================
607 // function : enterEvent()
608 // purpose  :
609 //=================================================================================
610 void OperationGUI_ChamferDlg::enterEvent (QEvent*)
611 {
612   if (!mainFrame()->GroupConstructors->isEnabled())
613     this->ActivateThisDialog();
614 }
615
616 //=================================================================================
617 // function : ValueChangedInSpinBox()
618 // purpose  :
619 //=================================================================================
620 void OperationGUI_ChamferDlg::ValueChangedInSpinBox (double)
621 {
622   processPreview();
623 }
624
625 //=================================================================================
626 // function : createSelWg()
627 // purpose  :
628 //=================================================================================
629 void OperationGUI_ChamferDlg::createSelWg (const QString& theLbl,
630                                            QPixmap&       thePix,
631                                            QWidget*       theParent,
632                                            QGridLayout*   theLayout,
633                                            const int      theId)
634 {
635   QLabel* lab = new QLabel(theLbl, theParent);
636   mySelBtn[ theId ] = new QPushButton(theParent);
637   mySelBtn[ theId ]->setIcon(thePix);
638   mySelName[ theId ] = new QLineEdit(theParent);
639   mySelName[ theId ]->setReadOnly(true);
640   int row = theLayout->rowCount();
641   theLayout->addWidget(lab,                row, 0);
642   theLayout->addWidget(mySelBtn[ theId ],  row, 1);
643   theLayout->addWidget(mySelName[ theId ], row, 2, 1, 4); // take into account createRadioWg()
644 }
645
646 //=================================================================================
647 // function : createRadioWg()
648 // purpose  :
649 //=================================================================================
650 void OperationGUI_ChamferDlg::createRadioWg(const QString& theLbl1,
651                                              const QString& theLbl2,
652                                              QWidget*       theParent,
653                                              QGridLayout*   theLayout,
654                                              const int      theRbId,
655                                              const int      theSpin1Id,
656                                              const int      theSpin2Id)
657 {
658   myRadioButton[ theRbId ] = new QRadioButton(theParent);
659   QLabel* lab1 = new QLabel(theLbl1, theParent);
660   QLabel* lab2 = new QLabel(theLbl2, theParent);
661   mySpinBox[ theSpin1Id ]  = new SalomeApp_DoubleSpinBox(theParent);
662   mySpinBox[ theSpin2Id ]  = new SalomeApp_DoubleSpinBox(theParent);
663   int row = theLayout->rowCount();
664   theLayout->addWidget(myRadioButton[ theRbId ], row, 0);
665   theLayout->addWidget(lab1,                     row, 2);
666   theLayout->addWidget(mySpinBox[ theSpin1Id ],  row, 3);
667   theLayout->addWidget(lab2,                     row, 4);
668   theLayout->addWidget(mySpinBox[ theSpin2Id ],  row, 5);
669 }
670
671 //=================================================================================
672 // function : activateSelection
673 // purpose  : Activate selection in accordance with myEditCurrentArgument
674 //=================================================================================
675 void OperationGUI_ChamferDlg::activateSelection()
676 {
677   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
678
679   if (!myShape->_is_nil() &&
680       (myEditCurrentArgument == mySelName[ Face1 ] ||
681        myEditCurrentArgument == mySelName[ Face2 ] ||
682        myEditCurrentArgument == mySelName[ Faces ])) {
683     localSelection(myShape, TopAbs_FACE);
684   }
685   else if (!myShape->_is_nil() && myEditCurrentArgument == mySelName[ Edges ]) {
686     localSelection(myShape, TopAbs_EDGE);
687   }
688   else {
689     TColStd_MapOfInteger aMap;
690     aMap.Add(GEOM_SHELL);
691     aMap.Add(GEOM_SOLID);
692     aMap.Add(GEOM_COMPOUND);
693     globalSelection(aMap);
694   }
695
696   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
697           this, SLOT(SelectionIntoArgument()));
698 }
699
700 //=================================================================================
701 // function : enableWidgets
702 // purpose  : Enable widgets of faces in accordance with value of main object
703 //=================================================================================
704 void OperationGUI_ChamferDlg::enableWidgets()
705 {
706   int anId = getConstructorId();
707
708   bool toEnable = !myShape->_is_nil();
709
710   if (anId == 1)
711   {
712     //mySelName[ Face1 ]->setEnabled(toEnable);
713     //mySelName[ Face2 ]->setEnabled(toEnable);
714     mySelBtn[ Face1 ]->setEnabled(toEnable);
715     mySelBtn[ Face2 ]->setEnabled(toEnable);
716
717     if (!toEnable)
718     {
719       mySelName[ Face1 ]->setText("");
720       mySelName[ Face2 ]->setText("");
721       myFace[ Face1 ] = -1;
722       myFace[ Face2 ] = -1;
723     }
724   }
725   else if (anId == 2)
726   {
727     //mySelName[ Faces ]->setEnabled(toEnable);
728     mySelBtn[ Faces ]->setEnabled(toEnable);
729     if (!toEnable) {
730       mySelName[ Faces ]->setText("");
731       myFaces.Clear();
732     }
733   }
734   else if (anId == 3) {
735     //mySelName[ Edges ]->setEnabled(toEnable);
736     mySelBtn[ Edges ]->setEnabled(toEnable);
737
738     if (!toEnable) {
739       mySelName[ Edges ]->setText("");
740       myEdges.Clear();
741     }
742   }
743 }
744
745 //=================================================================================
746 // function : createOperation
747 // purpose  :
748 //=================================================================================
749 GEOM::GEOM_IOperations_ptr OperationGUI_ChamferDlg::createOperation()
750 {
751   return getGeomEngine()->GetILocalOperations();
752 }
753
754 //=================================================================================
755 // function : isValid()
756 // purpose  : Verify validity of input data
757 //=================================================================================
758 bool OperationGUI_ChamferDlg::isValid (QString& msg)
759 {
760   bool ok = true;
761   switch (getConstructorId())
762   {
763     case 0:
764       ok = mySpinBox[ SpinBox1 ]->isValid( msg, !IsPreview() );
765       return !myShape->_is_nil() && ok;
766     case 1:
767       if (myRadioButton[ RadioButton21 ]->isChecked())
768       {
769         ok = mySpinBox[ SpinBox21 ]->isValid( msg, !IsPreview() ) && ok;
770         ok = mySpinBox[ SpinBox22 ]->isValid( msg, !IsPreview() ) && ok;
771       }
772       else
773       {
774         ok = mySpinBox[ SpinBox23 ]->isValid( msg, !IsPreview() ) && ok;
775         ok = mySpinBox[ SpinBox24 ]->isValid( msg, !IsPreview() ) && ok;
776       }
777       return !myShape->_is_nil() && myFace[ Face1 ] > 0 && myFace[ Face2 ] > 0 && ok;
778     case 2:
779       if (myRadioButton[ RadioButton31 ]->isChecked())
780       {
781         ok = mySpinBox[ SpinBox31 ]->isValid( msg, !IsPreview() ) && ok;
782         ok = mySpinBox[ SpinBox32 ]->isValid( msg, !IsPreview() ) && ok;
783       }
784       else
785       {
786         ok = mySpinBox[ SpinBox33 ]->isValid( msg, !IsPreview() ) && ok;
787         ok = mySpinBox[ SpinBox34 ]->isValid( msg, !IsPreview() ) && ok;
788       }
789       return !myShape->_is_nil() && myFaces.Extent() > 0 && ok;
790     case 3:
791       if (myRadioButton[ RadioButton41 ]->isChecked())
792       {
793         ok = mySpinBox[ SpinBox41 ]->isValid( msg, !IsPreview() ) && ok;
794         ok = mySpinBox[ SpinBox42 ]->isValid( msg, !IsPreview() ) && ok;
795       }
796       else
797       {
798         ok = mySpinBox[ SpinBox43 ]->isValid( msg, !IsPreview() ) && ok;
799         ok = mySpinBox[ SpinBox44 ]->isValid( msg, !IsPreview() ) && ok;
800       }
801       return !myShape->_is_nil() && myEdges.Extent() > 0 && ok;
802     default: return false;
803   }
804 }
805
806 //=================================================================================
807 // function : execute
808 // purpose  :
809 //=================================================================================
810 bool OperationGUI_ChamferDlg::execute (ObjectList& objects)
811 {
812   QStringList aParameters;
813   GEOM::GEOM_Object_var anObj;
814   bool flag = (myRadioButton[ RadioButton21 ]->isChecked() &&
815                myRadioButton[ RadioButton31 ]->isChecked() &&
816                myRadioButton[ RadioButton41 ]->isChecked());
817
818   int anId = getConstructorId();
819
820   GEOM::GEOM_ILocalOperations_var anOper = GEOM::GEOM_ILocalOperations::_narrow(getOperation());
821
822   if (anId == 0) {
823     anObj = anOper->MakeChamferAll(myShape, mySpinBox[ SpinBox1 ]->value());
824     if (!anObj->_is_nil())
825       aParameters << mySpinBox[ SpinBox1 ]->text();
826   }
827   else if (anId == 1) {
828     if (flag) {
829       anObj = anOper->MakeChamferEdge(myShape,
830                                       mySpinBox[ SpinBox21 ]->value(),
831                                       mySpinBox[ SpinBox22 ]->value(),
832                                       myFace[ Face1 ],
833                                       myFace[ Face2 ]);
834       if (!anObj->_is_nil())
835       {
836         aParameters << mySpinBox[ SpinBox21 ]->text();
837         aParameters << mySpinBox[ SpinBox22 ]->text();
838       }
839     }
840     else {
841       anObj = anOper->MakeChamferEdgeAD(myShape,
842                                         mySpinBox[ SpinBox23 ]->value(),
843                                         mySpinBox[ SpinBox24 ]->value() * M_PI / 180.,
844                                         myFace[ Face1 ],
845                                         myFace[ Face2 ]);
846       if (!anObj->_is_nil())
847       {
848         aParameters << mySpinBox[ SpinBox23 ]->text();
849         aParameters << mySpinBox[ SpinBox24 ]->text();
850       }
851     }
852   }
853   else if (anId == 2)
854   {
855     GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
856     anArray->length(myFaces.Extent());
857
858     for (int i = 1, n = myFaces.Extent(); i <= n; i++)
859       anArray[ i - 1 ] = myFaces(i);
860
861     if (flag) {
862       anObj = anOper->MakeChamferFaces(myShape,
863                                        mySpinBox[ SpinBox31 ]->value(),
864                                        mySpinBox[ SpinBox32 ]->value(),
865                                        anArray);
866       if (!anObj->_is_nil())
867       {
868         aParameters << mySpinBox[ SpinBox31 ]->text();
869         aParameters << mySpinBox[ SpinBox32 ]->text();
870       }
871     }
872     else {
873       anObj = anOper->MakeChamferFacesAD(myShape,
874                                          mySpinBox[ SpinBox33 ]->value(),
875                                          mySpinBox[ SpinBox34 ]->value() * M_PI / 180.,
876                                          anArray);
877       if (!anObj->_is_nil())
878       {
879         aParameters << mySpinBox[ SpinBox33 ]->text();
880         aParameters << mySpinBox[ SpinBox34 ]->text();
881       }
882     }
883   }
884   else if (anId == 3) {
885     GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
886     anArray->length(myEdges.Extent());
887     for (int i = 1, n = myEdges.Extent(); i <= n; i++)
888       anArray[ i - 1 ] = myEdges(i);
889     if (flag) {
890       anObj = anOper->MakeChamferEdges(myShape,
891                                        mySpinBox[ SpinBox41 ]->value(),
892                                        mySpinBox[ SpinBox42 ]->value(),
893                                        anArray);
894       if (!anObj->_is_nil())
895       {
896         aParameters << mySpinBox[ SpinBox41 ]->text();
897         aParameters << mySpinBox[ SpinBox42 ]->text();
898       }
899     }
900     else {
901       anObj = anOper->MakeChamferEdgesAD(myShape,
902                                          mySpinBox[ SpinBox43 ]->value(),
903                                          mySpinBox[ SpinBox44 ]->value() * M_PI / 180.,
904                                          anArray);
905       if (!anObj->_is_nil())
906       {
907         aParameters << mySpinBox[ SpinBox43 ]->text();
908         aParameters << mySpinBox[ SpinBox44 ]->text();
909       }
910     }
911   }
912
913   if (!anObj->_is_nil())
914   {
915     if (!IsPreview())
916       anObj->SetParameters(aParameters.join(":").toLatin1().constData());
917     objects.push_back(anObj._retn());
918   }
919
920   return true;
921 }
922
923 //=================================================================================
924 // function : RadioButtonPressed()
925 // purpose  :
926 //=================================================================================
927 void OperationGUI_ChamferDlg::RadioButtonPressed()
928 {
929   const QObject* s = sender();
930   bool flag = s == myRadioButton[ RadioButton21 ] ||
931               s == myRadioButton[ RadioButton31 ] ||
932               s == myRadioButton[ RadioButton41 ];
933
934   myRadioButton[ RadioButton21 ]->blockSignals(true);
935   myRadioButton[ RadioButton22 ]->blockSignals(true);
936   myRadioButton[ RadioButton31 ]->blockSignals(true);
937   myRadioButton[ RadioButton32 ]->blockSignals(true);
938   myRadioButton[ RadioButton41 ]->blockSignals(true);
939   myRadioButton[ RadioButton42 ]->blockSignals(true);
940
941   myRadioButton[ RadioButton21 ]->setChecked(flag);
942   myRadioButton[ RadioButton31 ]->setChecked(flag);
943   myRadioButton[ RadioButton41 ]->setChecked(flag);
944   myRadioButton[ RadioButton22 ]->setChecked(!flag);
945   myRadioButton[ RadioButton32 ]->setChecked(!flag);
946   myRadioButton[ RadioButton42 ]->setChecked(!flag);
947   mySpinBox[ SpinBox21 ]->setEnabled(flag);
948   mySpinBox[ SpinBox22 ]->setEnabled(flag);
949   mySpinBox[ SpinBox31 ]->setEnabled(flag);
950   mySpinBox[ SpinBox32 ]->setEnabled(flag);
951   mySpinBox[ SpinBox41 ]->setEnabled(flag);
952   mySpinBox[ SpinBox42 ]->setEnabled(flag);
953   mySpinBox[ SpinBox23 ]->setEnabled(!flag);
954   mySpinBox[ SpinBox24 ]->setEnabled(!flag);
955   mySpinBox[ SpinBox33 ]->setEnabled(!flag);
956   mySpinBox[ SpinBox34 ]->setEnabled(!flag);
957   mySpinBox[ SpinBox43 ]->setEnabled(!flag);
958   mySpinBox[ SpinBox44 ]->setEnabled(!flag);
959
960   myRadioButton[ RadioButton21 ]->blockSignals(false);
961   myRadioButton[ RadioButton22 ]->blockSignals(false);
962   myRadioButton[ RadioButton31 ]->blockSignals(false);
963   myRadioButton[ RadioButton32 ]->blockSignals(false);
964   myRadioButton[ RadioButton41 ]->blockSignals(false);
965   myRadioButton[ RadioButton42 ]->blockSignals(false);
966
967   processPreview();
968 }
969
970 //=================================================================================
971 // function : getSourceObjects
972 // purpose  : virtual method to get source objects
973 //=================================================================================
974 QList<GEOM::GeomObjPtr> OperationGUI_ChamferDlg::getSourceObjects()
975 {
976   QList<GEOM::GeomObjPtr> res;
977   GEOM::GeomObjPtr aGeomObjPtr(myShape);
978   res << aGeomObjPtr;
979   return res;
980 }