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