]> SALOME platform Git repositories - modules/geom.git/blob - src/OperationGUI/OperationGUI_ChamferDlg.cxx
Salome HOME
Code refactoring
[modules/geom.git] / src / OperationGUI / OperationGUI_ChamferDlg.cxx
1 //  Copyright (C) 2007-2010  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
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_EDGES"), 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_EDGE"), 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   // signals and slots connections
197
198   // main buttons
199   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()   ));
200   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
201
202   // group box
203   connect(this,          SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
204
205   // push buttons
206   QMap< int, QPushButton* >::iterator anIterBtn;
207   for (anIterBtn = mySelBtn.begin(); anIterBtn != mySelBtn.end(); ++anIterBtn)
208     connect(anIterBtn.value(), SIGNAL(clicked()),
209             this, SLOT(SetEditCurrentArgument()));
210
211   // line edits
212   QMap< int, QLineEdit* >::iterator anIterLE2;
213   for (anIterLE2 = mySelName.begin(); anIterLE2 != mySelName.end(); ++anIterLE2)
214     connect(anIterLE2.value(), SIGNAL(returnPressed()),
215             this, SLOT(LineEditReturnPressed()));
216
217   // spin boxes
218   QMap< int, SalomeApp_DoubleSpinBox* >::iterator anIterSpin;
219   for (anIterSpin = mySpinBox.begin(); anIterSpin != mySpinBox.end(); ++anIterSpin)
220     connect(anIterSpin.value(), SIGNAL(valueChanged(double)),
221             this, SLOT(ValueChangedInSpinBox(double)));
222
223   // radio buttons
224   QMap< int, QRadioButton* >::iterator anIterRadio;
225   for (anIterRadio = myRadioButton.begin(); anIterRadio != myRadioButton.end(); ++anIterRadio)
226     connect(anIterRadio.value(), SIGNAL(clicked()),
227             this, SLOT(RadioButtonPressed()));
228
229   initName(tr("GEOM_CHAMFER"));
230
231   myConstructorId = -1;
232   ConstructorsClicked(0);
233 }
234
235 //=================================================================================
236 // function : ConstructorsClicked()
237 // purpose  : Radio button management
238 //=================================================================================
239 void OperationGUI_ChamferDlg::ConstructorsClicked (int constructorId)
240 {
241    // Activate next widget
242   if (myGeomGUI->getApp()->desktop()->activeWindow()->getViewManager()->getType()
243       != OCCViewer_Viewer::Type()) {
244     mainFrame()->RadioButton1->setChecked(true);
245     return;
246   }
247
248   if (myConstructorId == constructorId)
249     return;
250
251   //disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
252
253   // Get values from previous widget
254   QString D1 = "5", D2 = "5", D = "5", Angle = "5";
255   if (myConstructorId == 0)
256     D1 = D2 = mySpinBox[ SpinBox1 ]->text();
257   else if (myConstructorId == 1) {
258     D1 = mySpinBox[ SpinBox21 ]->text();
259     D2 = mySpinBox[ SpinBox22 ]->text();
260     D =  mySpinBox[ SpinBox23 ]->text();
261     Angle = mySpinBox[ SpinBox24 ]->text();
262   }
263   else if (myConstructorId == 2) {
264     D1 = mySpinBox[ SpinBox31 ]->text();
265     D2 = mySpinBox[ SpinBox32 ]->text();
266     D =  mySpinBox[ SpinBox33 ]->text();
267     Angle = mySpinBox[ SpinBox34 ]->text();
268   }
269   else if (myConstructorId == 3) {
270     D1 = mySpinBox[ SpinBox41 ]->text();
271     D2 = mySpinBox[ SpinBox42 ]->text();
272     D =  mySpinBox[ SpinBox43 ]->text();
273     Angle = mySpinBox[ SpinBox44 ]->text();
274   }
275
276   myConstructorId = constructorId;
277
278   switch (constructorId) {
279   case 0:
280     myGrp2->hide();
281     myGrp3->hide();
282     myGrp4->hide();
283     myGrp1->show();
284     mySpinBox[ SpinBox1 ]->setText(D1);
285     break;
286   case 1:
287     myGrp1->hide();
288     myGrp3->hide();
289     myGrp4->hide();
290     myGrp2->show();
291     mySpinBox[ SpinBox21 ]->setText(D1);
292     mySpinBox[ SpinBox22 ]->setText(D2);
293     mySpinBox[ SpinBox23 ]->setText(D);
294     mySpinBox[ SpinBox24 ]->setText(Angle);
295     break;
296   case 2:
297     myGrp1->hide();
298     myGrp2->hide();
299     myGrp4->hide();
300     myGrp3->show();
301     mySpinBox[ SpinBox31 ]->setText(D1);
302     mySpinBox[ SpinBox32 ]->setText(D2);
303     mySpinBox[ SpinBox32 ]->setText(D2);
304     mySpinBox[ SpinBox33 ]->setText(D);
305     mySpinBox[ SpinBox34 ]->setText(Angle);
306     break;
307   case 3:
308     myGrp1->hide();
309     myGrp2->hide();
310     myGrp3->hide();
311     myGrp4->show();
312     mySpinBox[ SpinBox41 ]->setText(D1);
313     mySpinBox[ SpinBox42 ]->setText(D2);
314     mySpinBox[ SpinBox43 ]->setText(D);
315     mySpinBox[ SpinBox44 ]->setText(Angle);
316     break;
317   default:
318     break;
319   }
320
321   if      (constructorId == 0) mySelBtn[ MainObj1 ]->click();
322   else if (constructorId == 1) mySelBtn[ MainObj2 ]->click();
323   else if (constructorId == 2) mySelBtn[ MainObj3 ]->click();
324   else                         mySelBtn[ MainObj4 ]->click();
325
326   enableWidgets();
327
328   if (myInitial) {
329     myInitial = false;
330     SelectionIntoArgument();
331   }
332   else {
333     if (!myShape->_is_nil()) {
334       myEditCurrentArgument->setText(GEOMBase::GetName(myShape));
335       GEOMBase_Skeleton::LineEditReturnPressed();
336       switch (getConstructorId()) {
337       case 1:
338         if (myFace[ Face1 ] == -1)
339           mySelBtn[ Face1 ]->click();
340         break;
341       case 2:
342         if (myFaces.Extent() == 0)
343           mySelBtn[ Faces ]->click();
344         break;
345       case 3:
346         if (myEdges.Extent() == 0)
347           mySelBtn[ Edges ]->click();
348         break;
349       default:
350         break;
351       }
352     }
353     else {
354       myEditCurrentArgument->setText("");
355     }
356
357     displayPreview();
358   }
359
360   qApp->processEvents();
361   updateGeometry();
362   resize(minimumSizeHint());
363 }
364
365 //=================================================================================
366 // function : ClickOnOk()
367 // purpose  :
368 //=================================================================================
369 void OperationGUI_ChamferDlg::ClickOnOk()
370 {
371   if (ClickOnApply())
372     ClickOnCancel();
373 }
374
375 //=================================================================================
376 // function : ClickOnApply()
377 // purpose  :
378 //=================================================================================
379 bool OperationGUI_ChamferDlg::ClickOnApply()
380 {
381   if (!onAccept())
382     return false;
383
384   initName();
385   // activate selection and connect selection manager
386   ConstructorsClicked(getConstructorId());
387   return true;
388 }
389
390 //=================================================================================
391 // function : SelectionIntoArgument()
392 // purpose  : Called when selection is changed or on dialog initialization or activation
393 //=================================================================================
394 void OperationGUI_ChamferDlg::SelectionIntoArgument()
395 {
396   erasePreview();
397   myEditCurrentArgument->setText("");
398
399   // Get index of current selection focus
400   int aCurrFocus = -1;
401   QMap< int, QLineEdit* >::iterator anIter;
402   for (anIter = mySelName.begin(); anIter != mySelName.end(); ++anIter) {
403     if (myEditCurrentArgument == anIter.value()) {
404       aCurrFocus = anIter.key();
405       break;
406     }
407   }
408
409   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
410   SALOME_ListIO aSelList;
411   aSelMgr->selectedObjects(aSelList);
412
413   // If selection of main object is activated
414   if (aCurrFocus == MainObj1 || aCurrFocus == MainObj2 || aCurrFocus == MainObj3 || aCurrFocus == MainObj4)
415   {
416     myShape = GEOM::GEOM_Object::_nil();
417     if (aSelList.Extent() == 1) {
418       GEOM::GEOM_Object_var anObj =
419         GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
420
421       if ( !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       GEOM::GEOM_Object_var anObj =
436         GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
437
438       if ( !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       GEOM::GEOM_Object_var anObj =
458         GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
459
460       if ( !anObj->_is_nil() ) {
461         TColStd_IndexedMapOfInteger anIndexes;
462         aSelMgr->GetIndexes(aSelList.First(), anIndexes);
463
464         if (anIndexes.Extent() > 0) {
465           QString aName;
466           if (anIndexes.Extent() == 1) {
467             int anIndex = anIndexes(1);
468
469             aName = QString(GEOMBase::GetName(anObj)) + QString(":%1").arg(anIndex);
470           }
471           else {
472             aName = tr("GEOM_MEN_POPUP_NAME").arg(anIndexes.Extent());
473           }
474
475           myEditCurrentArgument->setText(aName);
476           int aConstructorId = getConstructorId();
477           if (aConstructorId == 2)
478             myFaces = anIndexes;
479           else if (aConstructorId == 3)
480             myEdges = anIndexes;
481
482           displayPreview();
483         }
484       }
485     }
486   }
487
488   // clear selection
489   if (aCurrFocus != Faces && aCurrFocus != Edges) {
490     disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
491     myGeomGUI->getApp()->selectionMgr()->clearSelected();
492     connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
493             this, SLOT(SelectionIntoArgument()));
494   }
495
496   switch (getConstructorId()) {
497   case 1:
498     if (aCurrFocus == MainObj2) {
499       if (!myShape->_is_nil() && myFace[ Face1 ] == -1)
500         mySelBtn[ Face1 ]->click();
501     }
502     else if (aCurrFocus == Face1) {
503       if (myFace[ Face1 ] != -1 && myFace[ Face2 ] == -1)
504         mySelBtn[ Face2 ]->click();
505     }
506     else if (aCurrFocus == Face2) {
507       if (myFace[ Face2 ] != -1 && myShape->_is_nil())
508         mySelBtn[ MainObj2 ]->click();
509     }
510     break;
511   case 2:
512     if (aCurrFocus == MainObj3) {
513       if (!myShape->_is_nil() && myFaces.Extent() == 0)
514         mySelBtn[ Faces ]->click();
515     }
516     break;
517   case 3:
518     if (aCurrFocus == MainObj4) {
519       if (!myShape->_is_nil() && myEdges.Extent() == 0)
520         mySelBtn[ Edges ]->click();
521     }
522     break;
523   default:
524     break;
525   }
526
527   //rnv: To fix the bug IPAL22041 TC5.1.5: "Fillet Construcion" dialog loses current selection.
528   // Restore selection of the main shape, if need,
529   // because it was canceled.
530   aSelMgr->selectedObjects(aSelList);
531   if (aSelList.Extent() == 0 && !myShape->_is_nil()) {
532     disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
533     ObjectList list;
534         list.push_back(myShape);
535     selectObjects(list);
536     connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
537             this, SLOT(SelectionIntoArgument()));
538   }
539 }
540
541 //=================================================================================
542 // function : SetEditCurrentArgument()
543 // purpose  :
544 //=================================================================================
545 void OperationGUI_ChamferDlg::SetEditCurrentArgument()
546 {
547   QPushButton* send = (QPushButton*)sender();
548
549   QMap< int, QPushButton* >::iterator anIter;
550   for (anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter) {
551     if (anIter.value() == send) {
552       mySelName[ anIter.key() ]->setFocus();
553       myEditCurrentArgument = mySelName[ anIter.key() ];
554     }
555     else {
556       anIter.value()->setDown(false);
557       mySelName[ anIter.key() ]->setEnabled(false);
558     }
559   }
560
561   // enable line edit
562   myEditCurrentArgument->setEnabled(true);
563   myEditCurrentArgument->setFocus();
564   // after setFocus(), because it will be setDown(false) when loses focus
565   send->setDown(true);
566
567   activateSelection();
568
569   // seems we need it only to avoid preview disappearing, caused by selection mode change
570   displayPreview();
571 }
572
573 //=================================================================================
574 // function : LineEditReturnPressed()
575 // purpose  :
576 //=================================================================================
577 void OperationGUI_ChamferDlg::LineEditReturnPressed()
578 {
579   QLineEdit* send = (QLineEdit*)sender();
580
581   QMap< int, QLineEdit* >::iterator anIterLE;
582   for (anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE)
583     if (anIterLE.value() == send)
584       myEditCurrentArgument = anIterLE.value();
585
586   GEOMBase_Skeleton::LineEditReturnPressed();
587 }
588
589 //=================================================================================
590 // function : ActivateThisDialog()
591 // purpose  :
592 //=================================================================================
593 void OperationGUI_ChamferDlg::ActivateThisDialog()
594 {
595   GEOMBase_Skeleton::ActivateThisDialog();
596   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
597            this, SLOT( SelectionIntoArgument() ) );
598
599   ConstructorsClicked( getConstructorId() );
600 }
601
602 //=================================================================================
603 // function : enterEvent()
604 // purpose  :
605 //=================================================================================
606 void OperationGUI_ChamferDlg::enterEvent (QEvent*)
607 {
608   if (!mainFrame()->GroupConstructors->isEnabled())
609     this->ActivateThisDialog();
610 }
611
612 //=================================================================================
613 // function : ValueChangedInSpinBox()
614 // purpose  :
615 //=================================================================================
616 void OperationGUI_ChamferDlg::ValueChangedInSpinBox (double)
617 {
618   displayPreview();
619 }
620
621 //=================================================================================
622 // function : createSelWg()
623 // purpose  :
624 //=================================================================================
625 void OperationGUI_ChamferDlg::createSelWg (const QString& theLbl,
626                                            QPixmap&       thePix,
627                                            QWidget*       theParent,
628                                            QGridLayout*   theLayout,
629                                            const int      theId)
630 {
631   QLabel* lab = new QLabel(theLbl, theParent);
632   mySelBtn[ theId ] = new QPushButton(theParent);
633   mySelBtn[ theId ]->setIcon(thePix);
634   mySelName[ theId ] = new QLineEdit(theParent);
635   mySelName[ theId ]->setReadOnly(true);
636   int row = theLayout->rowCount();
637   theLayout->addWidget(lab,                row, 0);
638   theLayout->addWidget(mySelBtn[ theId ],  row, 1);
639   theLayout->addWidget(mySelName[ theId ], row, 2, 1, 4); // take into account createRadioWg()
640 }
641
642 //=================================================================================
643 // function : createRadioWg()
644 // purpose  :
645 //=================================================================================
646 void OperationGUI_ChamferDlg::createRadioWg(const QString& theLbl1,
647                                              const QString& theLbl2,
648                                              QWidget*       theParent,
649                                              QGridLayout*   theLayout,
650                                              const int      theRbId,
651                                              const int      theSpin1Id,
652                                              const int      theSpin2Id)
653 {
654   myRadioButton[ theRbId ] = new QRadioButton(theParent);
655   QLabel* lab1 = new QLabel(theLbl1, theParent);
656   QLabel* lab2 = new QLabel(theLbl2, theParent);
657   mySpinBox[ theSpin1Id ]  = new SalomeApp_DoubleSpinBox(theParent);
658   mySpinBox[ theSpin2Id ]  = new SalomeApp_DoubleSpinBox(theParent);
659   int row = theLayout->rowCount();
660   theLayout->addWidget(myRadioButton[ theRbId ], row, 0);
661   theLayout->addWidget(lab1,                     row, 2);
662   theLayout->addWidget(mySpinBox[ theSpin1Id ],  row, 3);
663   theLayout->addWidget(lab2,                     row, 4);
664   theLayout->addWidget(mySpinBox[ theSpin2Id ],  row, 5);
665 }
666
667 //=================================================================================
668 // function : activateSelection
669 // purpose  : Activate selection in accordance with myEditCurrentArgument
670 //=================================================================================
671 void OperationGUI_ChamferDlg::activateSelection()
672 {
673   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
674
675   if (!myShape->_is_nil() &&
676       (myEditCurrentArgument == mySelName[ Face1 ] ||
677        myEditCurrentArgument == mySelName[ Face2 ] ||
678        myEditCurrentArgument == mySelName[ Faces ])) {
679     localSelection(myShape, TopAbs_FACE);
680   }
681   else if (!myShape->_is_nil() && myEditCurrentArgument == mySelName[ Edges ]) {
682     localSelection(myShape, TopAbs_EDGE);
683   }
684   else {
685     TColStd_MapOfInteger aMap;
686     aMap.Add(GEOM_SHELL);
687     aMap.Add(GEOM_SOLID);
688     aMap.Add(GEOM_COMPOUND);
689     globalSelection(aMap);
690   }
691
692   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
693           this, SLOT(SelectionIntoArgument()));
694 }
695
696 //=================================================================================
697 // function : enableWidgets
698 // purpose  : Enable widgets of faces in accordance with value of main object
699 //=================================================================================
700 void OperationGUI_ChamferDlg::enableWidgets()
701 {
702   int anId = getConstructorId();
703
704   bool toEnable = !myShape->_is_nil();
705
706   if (anId == 1)
707   {
708     //mySelName[ Face1 ]->setEnabled(toEnable);
709     //mySelName[ Face2 ]->setEnabled(toEnable);
710     mySelBtn[ Face1 ]->setEnabled(toEnable);
711     mySelBtn[ Face2 ]->setEnabled(toEnable);
712
713     if (!toEnable)
714     {
715       mySelName[ Face1 ]->setText("");
716       mySelName[ Face2 ]->setText("");
717       myFace[ Face1 ] = -1;
718       myFace[ Face2 ] = -1;
719     }
720   }
721   else if (anId == 2)
722   {
723     //mySelName[ Faces ]->setEnabled(toEnable);
724     mySelBtn[ Faces ]->setEnabled(toEnable);
725     if (!toEnable) {
726       mySelName[ Faces ]->setText("");
727       myFaces.Clear();
728     }
729   }
730   else if (anId == 3) {
731     //mySelName[ Edges ]->setEnabled(toEnable);
732     mySelBtn[ Edges ]->setEnabled(toEnable);
733
734     if (!toEnable) {
735       mySelName[ Edges ]->setText("");
736       myEdges.Clear();
737     }
738   }
739 }
740
741 //=================================================================================
742 // function : createOperation
743 // purpose  :
744 //=================================================================================
745 GEOM::GEOM_IOperations_ptr OperationGUI_ChamferDlg::createOperation()
746 {
747   return getGeomEngine()->GetILocalOperations(getStudyId());
748 }
749
750 //=================================================================================
751 // function : isValid()
752 // purpose  : Verify validity of input data
753 //=================================================================================
754 bool OperationGUI_ChamferDlg::isValid (QString& msg)
755 {
756   bool ok = true;
757   switch (getConstructorId())
758   {
759     case 0:
760       ok = mySpinBox[ SpinBox1 ]->isValid( msg, !IsPreview() );
761       return !myShape->_is_nil() && ok;
762     case 1:
763       if (myRadioButton[ RadioButton21 ]->isChecked())
764       {
765         ok = mySpinBox[ SpinBox21 ]->isValid( msg, !IsPreview() ) && ok;
766         ok = mySpinBox[ SpinBox22 ]->isValid( msg, !IsPreview() ) && ok;
767       }
768       else
769       {
770         ok = mySpinBox[ SpinBox23 ]->isValid( msg, !IsPreview() ) && ok;
771         ok = mySpinBox[ SpinBox24 ]->isValid( msg, !IsPreview() ) && ok;
772       }
773       return !myShape->_is_nil() && myFace[ Face1 ] > 0 && myFace[ Face2 ] > 0 && ok;
774     case 2:
775       if (myRadioButton[ RadioButton31 ]->isChecked())
776       {
777         ok = mySpinBox[ SpinBox31 ]->isValid( msg, !IsPreview() ) && ok;
778         ok = mySpinBox[ SpinBox32 ]->isValid( msg, !IsPreview() ) && ok;
779       }
780       else
781       {
782         ok = mySpinBox[ SpinBox33 ]->isValid( msg, !IsPreview() ) && ok;
783         ok = mySpinBox[ SpinBox34 ]->isValid( msg, !IsPreview() ) && ok;
784       }
785       return !myShape->_is_nil() && myFaces.Extent() > 0 && ok;
786     case 3:
787       if (myRadioButton[ RadioButton41 ]->isChecked())
788       {
789         ok = mySpinBox[ SpinBox41 ]->isValid( msg, !IsPreview() ) && ok;
790         ok = mySpinBox[ SpinBox42 ]->isValid( msg, !IsPreview() ) && ok;
791       }
792       else
793       {
794         ok = mySpinBox[ SpinBox43 ]->isValid( msg, !IsPreview() ) && ok;
795         ok = mySpinBox[ SpinBox44 ]->isValid( msg, !IsPreview() ) && ok;
796       }
797       return !myShape->_is_nil() && myEdges.Extent() > 0 && ok;
798     default: return false;
799   }
800 }
801
802 //=================================================================================
803 // function : execute
804 // purpose  :
805 //=================================================================================
806 bool OperationGUI_ChamferDlg::execute (ObjectList& objects)
807 {
808   QStringList aParameters;
809   GEOM::GEOM_Object_var anObj;
810   bool flag = (myRadioButton[ RadioButton21 ]->isChecked() &&
811                myRadioButton[ RadioButton31 ]->isChecked() &&
812                myRadioButton[ RadioButton41 ]->isChecked());
813
814   int anId = getConstructorId();
815
816   GEOM::GEOM_ILocalOperations_var anOper = GEOM::GEOM_ILocalOperations::_narrow(getOperation());
817
818   if (anId == 0) {
819     anObj = anOper->MakeChamferAll(myShape, mySpinBox[ SpinBox1 ]->value());
820     if (!anObj->_is_nil())
821       aParameters << mySpinBox[ SpinBox1 ]->text();
822   }
823   else if (anId == 1) {
824     if (flag) {
825       anObj = anOper->MakeChamferEdge(myShape,
826                                       mySpinBox[ SpinBox21 ]->value(),
827                                       mySpinBox[ SpinBox22 ]->value(),
828                                       myFace[ Face1 ],
829                                       myFace[ Face2 ]);
830       if (!anObj->_is_nil())
831       {
832         aParameters << mySpinBox[ SpinBox21 ]->text();
833         aParameters << mySpinBox[ SpinBox22 ]->text();
834       }
835     }
836     else {
837       anObj = anOper->MakeChamferEdgeAD(myShape,
838                                         mySpinBox[ SpinBox23 ]->value(),
839                                         mySpinBox[ SpinBox24 ]->value() * PI180,
840                                         myFace[ Face1 ],
841                                         myFace[ Face2 ]);
842       if (!anObj->_is_nil())
843       {
844         aParameters << mySpinBox[ SpinBox23 ]->text();
845         aParameters << mySpinBox[ SpinBox24 ]->text();
846       }
847     }
848   }
849   else if (anId == 2)
850   {
851     GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
852     anArray->length(myFaces.Extent());
853
854     for (int i = 1, n = myFaces.Extent(); i <= n; i++)
855       anArray[ i - 1 ] = myFaces(i);
856
857     if (flag) {
858       anObj = anOper->MakeChamferFaces(myShape,
859                                        mySpinBox[ SpinBox31 ]->value(),
860                                        mySpinBox[ SpinBox32 ]->value(),
861                                        anArray);
862       if (!anObj->_is_nil())
863       {
864         aParameters << mySpinBox[ SpinBox31 ]->text();
865         aParameters << mySpinBox[ SpinBox32 ]->text();
866       }
867     }
868     else {
869       anObj = anOper->MakeChamferFacesAD(myShape,
870                                          mySpinBox[ SpinBox33 ]->value(),
871                                          mySpinBox[ SpinBox34 ]->value() * PI180,
872                                          anArray);
873       if (!anObj->_is_nil())
874       {
875         aParameters << mySpinBox[ SpinBox33 ]->text();
876         aParameters << mySpinBox[ SpinBox34 ]->text();
877       }
878     }
879   }
880   else if (anId == 3) {
881     GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
882     anArray->length(myEdges.Extent());
883     for (int i = 1, n = myEdges.Extent(); i <= n; i++)
884       anArray[ i - 1 ] = myEdges(i);
885     if (flag) {
886       anObj = anOper->MakeChamferEdges(myShape,
887                                        mySpinBox[ SpinBox41 ]->value(),
888                                        mySpinBox[ SpinBox42 ]->value(),
889                                        anArray);
890       if (!anObj->_is_nil())
891       {
892         aParameters << mySpinBox[ SpinBox41 ]->text();
893         aParameters << mySpinBox[ SpinBox42 ]->text();
894       }
895     }
896     else {
897       anObj = anOper->MakeChamferEdgesAD(myShape,
898                                          mySpinBox[ SpinBox43 ]->value(),
899                                          mySpinBox[ SpinBox44 ]->value() * PI180,
900                                          anArray);
901       if (!anObj->_is_nil())
902       {
903         aParameters << mySpinBox[ SpinBox43 ]->text();
904         aParameters << mySpinBox[ SpinBox44 ]->text();
905       }
906     }
907   }
908
909   if (!anObj->_is_nil())
910   {
911     if (!IsPreview())
912       anObj->SetParameters(aParameters.join(":").toLatin1().constData());
913     objects.push_back(anObj._retn());
914   }
915
916   return true;
917 }
918
919 //=================================================================================
920 // function : RadioButtonPressed()
921 // purpose  :
922 //=================================================================================
923 void OperationGUI_ChamferDlg::RadioButtonPressed()
924 {
925   const QObject* s = sender();
926   bool flag = s == myRadioButton[ RadioButton21 ] ||
927               s == myRadioButton[ RadioButton31 ] ||
928               s == myRadioButton[ RadioButton41 ];
929
930   myRadioButton[ RadioButton21 ]->blockSignals(true);
931   myRadioButton[ RadioButton22 ]->blockSignals(true);
932   myRadioButton[ RadioButton31 ]->blockSignals(true);
933   myRadioButton[ RadioButton32 ]->blockSignals(true);
934   myRadioButton[ RadioButton41 ]->blockSignals(true);
935   myRadioButton[ RadioButton42 ]->blockSignals(true);
936
937   myRadioButton[ RadioButton21 ]->setChecked(flag);
938   myRadioButton[ RadioButton31 ]->setChecked(flag);
939   myRadioButton[ RadioButton41 ]->setChecked(flag);
940   myRadioButton[ RadioButton22 ]->setChecked(!flag);
941   myRadioButton[ RadioButton32 ]->setChecked(!flag);
942   myRadioButton[ RadioButton42 ]->setChecked(!flag);
943   mySpinBox[ SpinBox21 ]->setEnabled(flag);
944   mySpinBox[ SpinBox22 ]->setEnabled(flag);
945   mySpinBox[ SpinBox31 ]->setEnabled(flag);
946   mySpinBox[ SpinBox32 ]->setEnabled(flag);
947   mySpinBox[ SpinBox41 ]->setEnabled(flag);
948   mySpinBox[ SpinBox42 ]->setEnabled(flag);
949   mySpinBox[ SpinBox23 ]->setEnabled(!flag);
950   mySpinBox[ SpinBox24 ]->setEnabled(!flag);
951   mySpinBox[ SpinBox33 ]->setEnabled(!flag);
952   mySpinBox[ SpinBox34 ]->setEnabled(!flag);
953   mySpinBox[ SpinBox43 ]->setEnabled(!flag);
954   mySpinBox[ SpinBox44 ]->setEnabled(!flag);
955
956   myRadioButton[ RadioButton21 ]->blockSignals(false);
957   myRadioButton[ RadioButton22 ]->blockSignals(false);
958   myRadioButton[ RadioButton31 ]->blockSignals(false);
959   myRadioButton[ RadioButton32 ]->blockSignals(false);
960   myRadioButton[ RadioButton41 ]->blockSignals(false);
961   myRadioButton[ RadioButton42 ]->blockSignals(false);
962
963   displayPreview();
964 }