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