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