1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : OperationGUI_ChamferDlg.cxx
25 // Author : Damien COQUERET, Open CASCADE S.A.S.
27 #include "OperationGUI_ChamferDlg.h"
28 #include <SalomeApp_DoubleSpinBox.h>
31 #include <GeometryGUI.h>
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>
44 #include <TColStd_MapOfInteger.hxx>
46 #include <GEOMImpl_Types.hxx>
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),
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")));
65 QPixmap iconSelect (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
67 setWindowTitle(tr("GEOM_CHAMFER_TITLE"));
69 /***************************************************************/
70 mainFrame()->GroupConstructors->setTitle(tr("GEOM_CHAMFER"));
72 mainFrame()->RadioButton1->setIcon(image1);
73 mainFrame()->RadioButton2->setIcon(image2);
74 mainFrame()->RadioButton3->setIcon(image3);
75 mainFrame()->RadioButton4->show();
76 mainFrame()->RadioButton4->setIcon(image4);
80 myGrp1 = new QGroupBox(tr("GEOM_CHAMFER_ALL"), centralWidget());
82 QGridLayout* aLayout = new QGridLayout(myGrp1);
83 aLayout->setMargin(9); aLayout->setSpacing(6);
85 createSelWg(tr("GEOM_MAIN_OBJECT"), iconSelect, myGrp1, aLayout, MainObj1);
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);
92 // Create second group
94 myGrp2 = new QGroupBox(tr("GEOM_CHAMFER_EDGES"), centralWidget());
96 aLayout = new QGridLayout(myGrp2);
97 aLayout->setMargin(9); aLayout->setSpacing(6);
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);
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);
106 aLayout->setRowStretch(aLayout->rowCount(), 10);
108 // Create third group
110 myGrp3 = new QGroupBox(tr("GEOM_CHAMFER_FACES"), centralWidget());
112 aLayout = new QGridLayout(myGrp3);
113 aLayout->setMargin(9); aLayout->setSpacing(6);
115 createSelWg(tr("GEOM_MAIN_OBJECT"), iconSelect, myGrp3, aLayout, MainObj3);
116 createSelWg(tr("SELECTED_FACES"), iconSelect, myGrp3, aLayout, Faces);
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);
121 aLayout->setRowStretch(aLayout->rowCount(), 10);
123 // Create fourth group
125 myGrp4 = new QGroupBox(tr("GEOM_CHAMFER_EDGE"), centralWidget());
127 aLayout = new QGridLayout(myGrp4);
128 aLayout->setMargin(9); aLayout->setSpacing(6);
130 createSelWg(tr("GEOM_MAIN_OBJECT"), iconSelect, myGrp4, aLayout, MainObj4);
131 createSelWg(tr("SELECTED_EDGE"), iconSelect, myGrp4, aLayout, Edges);
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);
136 aLayout->setRowStretch(aLayout->rowCount(), 10);
138 // Add groups to layout
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 /***************************************************************/
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" );
155 initSpinBox(anIter.value(), 0.001, COORD_MAX, SpecificStep, "length_precision" );
158 setHelpFileName("chamfer_operation_page.html");
162 myRadioButton[ RadioButton21 ]->click();
165 //=================================================================================
166 // function : ~OperationGUI_ChamferDlg()
167 // purpose : Destroys the object and frees any allocated resources
168 //=================================================================================
169 OperationGUI_ChamferDlg::~OperationGUI_ChamferDlg()
173 //=================================================================================
176 //=================================================================================
177 void OperationGUI_ChamferDlg::Init()
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);
185 QMap< int, QLineEdit* >::iterator anIterLE;
186 for (anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE)
187 anIterLE.value()->setText("");
189 myShape = GEOM::GEOM_Object::_nil();
193 myFace[ Face1 ] = -1;
194 myFace[ Face2 ] = -1;
196 // signals and slots connections
199 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk() ));
200 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
203 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
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()));
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()));
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)));
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()));
229 initName(tr("GEOM_CHAMFER"));
231 myConstructorId = -1;
232 ConstructorsClicked(0);
235 //=================================================================================
236 // function : ConstructorsClicked()
237 // purpose : Radio button management
238 //=================================================================================
239 void OperationGUI_ChamferDlg::ConstructorsClicked (int constructorId)
241 // Activate next widget
242 if (myGeomGUI->getApp()->desktop()->activeWindow()->getViewManager()->getType()
243 != OCCViewer_Viewer::Type()) {
244 mainFrame()->RadioButton1->setChecked(true);
248 if (myConstructorId == constructorId)
251 //disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
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();
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();
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();
276 myConstructorId = constructorId;
278 switch (constructorId) {
284 mySpinBox[ SpinBox1 ]->setText(D1);
291 mySpinBox[ SpinBox21 ]->setText(D1);
292 mySpinBox[ SpinBox22 ]->setText(D2);
293 mySpinBox[ SpinBox23 ]->setText(D);
294 mySpinBox[ SpinBox24 ]->setText(Angle);
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);
312 mySpinBox[ SpinBox41 ]->setText(D1);
313 mySpinBox[ SpinBox42 ]->setText(D2);
314 mySpinBox[ SpinBox43 ]->setText(D);
315 mySpinBox[ SpinBox44 ]->setText(Angle);
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();
330 SelectionIntoArgument();
333 if (!myShape->_is_nil()) {
334 myEditCurrentArgument->setText(GEOMBase::GetName(myShape));
335 GEOMBase_Skeleton::LineEditReturnPressed();
336 switch (getConstructorId()) {
338 if (myFace[ Face1 ] == -1)
339 mySelBtn[ Face1 ]->click();
342 if (myFaces.Extent() == 0)
343 mySelBtn[ Faces ]->click();
346 if (myEdges.Extent() == 0)
347 mySelBtn[ Edges ]->click();
354 myEditCurrentArgument->setText("");
360 qApp->processEvents();
362 resize(minimumSizeHint());
365 //=================================================================================
366 // function : ClickOnOk()
368 //=================================================================================
369 void OperationGUI_ChamferDlg::ClickOnOk()
375 //=================================================================================
376 // function : ClickOnApply()
378 //=================================================================================
379 bool OperationGUI_ChamferDlg::ClickOnApply()
385 // activate selection and connect selection manager
386 ConstructorsClicked(getConstructorId());
390 //=================================================================================
391 // function : SelectionIntoArgument()
392 // purpose : Called when selection is changed or on dialog initialization or activation
393 //=================================================================================
394 void OperationGUI_ChamferDlg::SelectionIntoArgument()
397 myEditCurrentArgument->setText("");
399 // Get index of current selection focus
401 QMap< int, QLineEdit* >::iterator anIter;
402 for (anIter = mySelName.begin(); anIter != mySelName.end(); ++anIter) {
403 if (myEditCurrentArgument == anIter.value()) {
404 aCurrFocus = anIter.key();
409 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
410 SALOME_ListIO aSelList;
411 aSelMgr->selectedObjects(aSelList);
413 // If selection of main object is activated
414 if (aCurrFocus == MainObj1 || aCurrFocus == MainObj2 || aCurrFocus == MainObj3 || aCurrFocus == MainObj4)
416 myShape = GEOM::GEOM_Object::_nil();
417 if (aSelList.Extent() == 1) {
418 Standard_Boolean aResult = Standard_False;
419 GEOM::GEOM_Object_var anObj =
420 GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
422 if (aResult && !anObj->_is_nil()) {
424 myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
431 // If face selection of second tab is activated
432 else if (aCurrFocus == Face1 || aCurrFocus == Face2)
434 myFace[ aCurrFocus ] = -1;
435 if (aSelList.Extent() == 1) {
436 Standard_Boolean aResult = Standard_False;
437 GEOM::GEOM_Object_var anObj =
438 GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
440 if (aResult && !anObj->_is_nil()) {
441 TColStd_IndexedMapOfInteger anIndexes;
442 aSelMgr->GetIndexes(aSelList.First(), anIndexes);
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;
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 Standard_Boolean aResult = Standard_False;
460 GEOM::GEOM_Object_var anObj =
461 GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
463 if (aResult && !anObj->_is_nil()) {
464 TColStd_IndexedMapOfInteger anIndexes;
465 aSelMgr->GetIndexes(aSelList.First(), anIndexes);
467 if (anIndexes.Extent() > 0) {
469 if (anIndexes.Extent() == 1) {
470 int anIndex = anIndexes(1);
472 aName = QString(GEOMBase::GetName(anObj)) + QString(":%1").arg(anIndex);
475 aName = tr("GEOM_MEN_POPUP_NAME").arg(anIndexes.Extent());
478 myEditCurrentArgument->setText(aName);
479 int aConstructorId = getConstructorId();
480 if (aConstructorId == 2)
482 else if (aConstructorId == 3)
492 if (aCurrFocus != Faces && aCurrFocus != Edges) {
493 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
494 myGeomGUI->getApp()->selectionMgr()->clearSelected();
495 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
496 this, SLOT(SelectionIntoArgument()));
499 switch (getConstructorId()) {
501 if (aCurrFocus == MainObj2) {
502 if (!myShape->_is_nil() && myFace[ Face1 ] == -1)
503 mySelBtn[ Face1 ]->click();
505 else if (aCurrFocus == Face1) {
506 if (myFace[ Face1 ] != -1 && myFace[ Face2 ] == -1)
507 mySelBtn[ Face2 ]->click();
509 else if (aCurrFocus == Face2) {
510 if (myFace[ Face2 ] != -1 && myShape->_is_nil())
511 mySelBtn[ MainObj2 ]->click();
515 if (aCurrFocus == MainObj3) {
516 if (!myShape->_is_nil() && myFaces.Extent() == 0)
517 mySelBtn[ Faces ]->click();
521 if (aCurrFocus == MainObj4) {
522 if (!myShape->_is_nil() && myEdges.Extent() == 0)
523 mySelBtn[ Edges ]->click();
531 //=================================================================================
532 // function : SetEditCurrentArgument()
534 //=================================================================================
535 void OperationGUI_ChamferDlg::SetEditCurrentArgument()
537 QPushButton* send = (QPushButton*)sender();
539 QMap< int, QPushButton* >::iterator anIter;
540 for (anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter) {
541 if (anIter.value() == send) {
542 mySelName[ anIter.key() ]->setFocus();
543 myEditCurrentArgument = mySelName[ anIter.key() ];
546 anIter.value()->setDown(false);
547 mySelName[ anIter.key() ]->setEnabled(false);
552 myEditCurrentArgument->setEnabled(true);
553 myEditCurrentArgument->setFocus();
554 // after setFocus(), because it will be setDown(false) when loses focus
559 // seems we need it only to avoid preview disappearing, caused by selection mode change
563 //=================================================================================
564 // function : LineEditReturnPressed()
566 //=================================================================================
567 void OperationGUI_ChamferDlg::LineEditReturnPressed()
569 QLineEdit* send = (QLineEdit*)sender();
571 QMap< int, QLineEdit* >::iterator anIterLE;
572 for (anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE)
573 if (anIterLE.value() == send)
574 myEditCurrentArgument = anIterLE.value();
576 GEOMBase_Skeleton::LineEditReturnPressed();
579 //=================================================================================
580 // function : ActivateThisDialog()
582 //=================================================================================
583 void OperationGUI_ChamferDlg::ActivateThisDialog()
585 GEOMBase_Skeleton::ActivateThisDialog();
586 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
587 this, SLOT( SelectionIntoArgument() ) );
589 ConstructorsClicked( getConstructorId() );
592 //=================================================================================
593 // function : enterEvent()
595 //=================================================================================
596 void OperationGUI_ChamferDlg::enterEvent (QEvent*)
598 if (!mainFrame()->GroupConstructors->isEnabled())
599 this->ActivateThisDialog();
602 //=================================================================================
603 // function : ValueChangedInSpinBox()
605 //=================================================================================
606 void OperationGUI_ChamferDlg::ValueChangedInSpinBox (double)
611 //=================================================================================
612 // function : createSelWg()
614 //=================================================================================
615 void OperationGUI_ChamferDlg::createSelWg (const QString& theLbl,
618 QGridLayout* theLayout,
621 QLabel* lab = new QLabel(theLbl, theParent);
622 mySelBtn[ theId ] = new QPushButton(theParent);
623 mySelBtn[ theId ]->setIcon(thePix);
624 mySelName[ theId ] = new QLineEdit(theParent);
625 mySelName[ theId ]->setReadOnly(true);
626 int row = theLayout->rowCount();
627 theLayout->addWidget(lab, row, 0);
628 theLayout->addWidget(mySelBtn[ theId ], row, 1);
629 theLayout->addWidget(mySelName[ theId ], row, 2, 1, 4); // take into account createRadioWg()
632 //=================================================================================
633 // function : createRadioWg()
635 //=================================================================================
636 void OperationGUI_ChamferDlg::createRadioWg(const QString& theLbl1,
637 const QString& theLbl2,
639 QGridLayout* theLayout,
641 const int theSpin1Id,
642 const int theSpin2Id)
644 myRadioButton[ theRbId ] = new QRadioButton(theParent);
645 QLabel* lab1 = new QLabel(theLbl1, theParent);
646 QLabel* lab2 = new QLabel(theLbl2, theParent);
647 mySpinBox[ theSpin1Id ] = new SalomeApp_DoubleSpinBox(theParent);
648 mySpinBox[ theSpin2Id ] = new SalomeApp_DoubleSpinBox(theParent);
649 int row = theLayout->rowCount();
650 theLayout->addWidget(myRadioButton[ theRbId ], row, 0);
651 theLayout->addWidget(lab1, row, 2);
652 theLayout->addWidget(mySpinBox[ theSpin1Id ], row, 3);
653 theLayout->addWidget(lab2, row, 4);
654 theLayout->addWidget(mySpinBox[ theSpin2Id ], row, 5);
657 //=================================================================================
658 // function : activateSelection
659 // purpose : Activate selection in accordance with myEditCurrentArgument
660 //=================================================================================
661 void OperationGUI_ChamferDlg::activateSelection()
663 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
665 if (!myShape->_is_nil() &&
666 (myEditCurrentArgument == mySelName[ Face1 ] ||
667 myEditCurrentArgument == mySelName[ Face2 ] ||
668 myEditCurrentArgument == mySelName[ Faces ])) {
669 localSelection(myShape, TopAbs_FACE);
671 else if (!myShape->_is_nil() && myEditCurrentArgument == mySelName[ Edges ]) {
672 localSelection(myShape, TopAbs_EDGE);
675 TColStd_MapOfInteger aMap;
676 aMap.Add(GEOM_SHELL);
677 aMap.Add(GEOM_SOLID);
678 aMap.Add(GEOM_COMPOUND);
679 globalSelection(aMap);
682 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
683 this, SLOT(SelectionIntoArgument()));
686 //=================================================================================
687 // function : enableWidgets
688 // purpose : Enable widgets of faces in accordance with value of main object
689 //=================================================================================
690 void OperationGUI_ChamferDlg::enableWidgets()
692 int anId = getConstructorId();
694 bool toEnable = !myShape->_is_nil();
698 //mySelName[ Face1 ]->setEnabled(toEnable);
699 //mySelName[ Face2 ]->setEnabled(toEnable);
700 mySelBtn[ Face1 ]->setEnabled(toEnable);
701 mySelBtn[ Face2 ]->setEnabled(toEnable);
705 mySelName[ Face1 ]->setText("");
706 mySelName[ Face2 ]->setText("");
707 myFace[ Face1 ] = -1;
708 myFace[ Face2 ] = -1;
713 //mySelName[ Faces ]->setEnabled(toEnable);
714 mySelBtn[ Faces ]->setEnabled(toEnable);
716 mySelName[ Faces ]->setText("");
720 else if (anId == 3) {
721 //mySelName[ Edges ]->setEnabled(toEnable);
722 mySelBtn[ Edges ]->setEnabled(toEnable);
725 mySelName[ Edges ]->setText("");
731 //=================================================================================
732 // function : createOperation
734 //=================================================================================
735 GEOM::GEOM_IOperations_ptr OperationGUI_ChamferDlg::createOperation()
737 return getGeomEngine()->GetILocalOperations(getStudyId());
740 //=================================================================================
741 // function : isValid()
742 // purpose : Verify validity of input data
743 //=================================================================================
744 bool OperationGUI_ChamferDlg::isValid (QString& msg)
747 switch (getConstructorId())
750 ok = mySpinBox[ SpinBox1 ]->isValid( msg, !IsPreview() );
751 return !myShape->_is_nil() && ok;
753 if (myRadioButton[ RadioButton21 ]->isChecked())
755 ok = mySpinBox[ SpinBox21 ]->isValid( msg, !IsPreview() ) && ok;
756 ok = mySpinBox[ SpinBox22 ]->isValid( msg, !IsPreview() ) && ok;
760 ok = mySpinBox[ SpinBox23 ]->isValid( msg, !IsPreview() ) && ok;
761 ok = mySpinBox[ SpinBox24 ]->isValid( msg, !IsPreview() ) && ok;
763 return !myShape->_is_nil() && myFace[ Face1 ] > 0 && myFace[ Face2 ] > 0 && ok;
765 if (myRadioButton[ RadioButton31 ]->isChecked())
767 ok = mySpinBox[ SpinBox31 ]->isValid( msg, !IsPreview() ) && ok;
768 ok = mySpinBox[ SpinBox32 ]->isValid( msg, !IsPreview() ) && ok;
772 ok = mySpinBox[ SpinBox33 ]->isValid( msg, !IsPreview() ) && ok;
773 ok = mySpinBox[ SpinBox34 ]->isValid( msg, !IsPreview() ) && ok;
775 return !myShape->_is_nil() && myFaces.Extent() > 0 && ok;
777 if (myRadioButton[ RadioButton41 ]->isChecked())
779 ok = mySpinBox[ SpinBox41 ]->isValid( msg, !IsPreview() ) && ok;
780 ok = mySpinBox[ SpinBox42 ]->isValid( msg, !IsPreview() ) && ok;
784 ok = mySpinBox[ SpinBox43 ]->isValid( msg, !IsPreview() ) && ok;
785 ok = mySpinBox[ SpinBox44 ]->isValid( msg, !IsPreview() ) && ok;
787 return !myShape->_is_nil() && myEdges.Extent() > 0 && ok;
788 default: return false;
792 //=================================================================================
793 // function : execute
795 //=================================================================================
796 bool OperationGUI_ChamferDlg::execute (ObjectList& objects)
798 QStringList aParameters;
799 GEOM::GEOM_Object_var anObj;
800 bool flag = (myRadioButton[ RadioButton21 ]->isChecked() &&
801 myRadioButton[ RadioButton31 ]->isChecked() &&
802 myRadioButton[ RadioButton41 ]->isChecked());
804 int anId = getConstructorId();
806 GEOM::GEOM_ILocalOperations_var anOper = GEOM::GEOM_ILocalOperations::_narrow(getOperation());
809 anObj = anOper->MakeChamferAll(myShape, mySpinBox[ SpinBox1 ]->value());
810 if (!anObj->_is_nil())
811 aParameters << mySpinBox[ SpinBox1 ]->text();
813 else if (anId == 1) {
815 anObj = anOper->MakeChamferEdge(myShape,
816 mySpinBox[ SpinBox21 ]->value(),
817 mySpinBox[ SpinBox22 ]->value(),
820 if (!anObj->_is_nil())
822 aParameters << mySpinBox[ SpinBox21 ]->text();
823 aParameters << mySpinBox[ SpinBox22 ]->text();
827 anObj = anOper->MakeChamferEdgeAD(myShape,
828 mySpinBox[ SpinBox23 ]->value(),
829 mySpinBox[ SpinBox24 ]->value() * PI180,
832 if (!anObj->_is_nil())
834 aParameters << mySpinBox[ SpinBox23 ]->text();
835 aParameters << mySpinBox[ SpinBox24 ]->text();
841 GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
842 anArray->length(myFaces.Extent());
844 for (int i = 1, n = myFaces.Extent(); i <= n; i++)
845 anArray[ i - 1 ] = myFaces(i);
848 anObj = anOper->MakeChamferFaces(myShape,
849 mySpinBox[ SpinBox31 ]->value(),
850 mySpinBox[ SpinBox32 ]->value(),
852 if (!anObj->_is_nil())
854 aParameters << mySpinBox[ SpinBox31 ]->text();
855 aParameters << mySpinBox[ SpinBox32 ]->text();
859 anObj = anOper->MakeChamferFacesAD(myShape,
860 mySpinBox[ SpinBox33 ]->value(),
861 mySpinBox[ SpinBox34 ]->value() * PI180,
863 if (!anObj->_is_nil())
865 aParameters << mySpinBox[ SpinBox33 ]->text();
866 aParameters << mySpinBox[ SpinBox34 ]->text();
870 else if (anId == 3) {
871 GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
872 anArray->length(myEdges.Extent());
873 for (int i = 1, n = myEdges.Extent(); i <= n; i++)
874 anArray[ i - 1 ] = myEdges(i);
876 anObj = anOper->MakeChamferEdges(myShape,
877 mySpinBox[ SpinBox41 ]->value(),
878 mySpinBox[ SpinBox42 ]->value(),
880 if (!anObj->_is_nil())
882 aParameters << mySpinBox[ SpinBox41 ]->text();
883 aParameters << mySpinBox[ SpinBox42 ]->text();
887 anObj = anOper->MakeChamferEdgesAD(myShape,
888 mySpinBox[ SpinBox43 ]->value(),
889 mySpinBox[ SpinBox44 ]->value() * PI180,
891 if (!anObj->_is_nil())
893 aParameters << mySpinBox[ SpinBox43 ]->text();
894 aParameters << mySpinBox[ SpinBox44 ]->text();
899 if (!anObj->_is_nil())
902 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
903 objects.push_back(anObj._retn());
909 //=================================================================================
910 // function : RadioButtonPressed()
912 //=================================================================================
913 void OperationGUI_ChamferDlg::RadioButtonPressed()
915 const QObject* s = sender();
916 bool flag = s == myRadioButton[ RadioButton21 ] ||
917 s == myRadioButton[ RadioButton31 ] ||
918 s == myRadioButton[ RadioButton41 ];
920 myRadioButton[ RadioButton21 ]->blockSignals(true);
921 myRadioButton[ RadioButton22 ]->blockSignals(true);
922 myRadioButton[ RadioButton31 ]->blockSignals(true);
923 myRadioButton[ RadioButton32 ]->blockSignals(true);
924 myRadioButton[ RadioButton41 ]->blockSignals(true);
925 myRadioButton[ RadioButton42 ]->blockSignals(true);
927 myRadioButton[ RadioButton21 ]->setChecked(flag);
928 myRadioButton[ RadioButton31 ]->setChecked(flag);
929 myRadioButton[ RadioButton41 ]->setChecked(flag);
930 myRadioButton[ RadioButton22 ]->setChecked(!flag);
931 myRadioButton[ RadioButton32 ]->setChecked(!flag);
932 myRadioButton[ RadioButton42 ]->setChecked(!flag);
933 mySpinBox[ SpinBox21 ]->setEnabled(flag);
934 mySpinBox[ SpinBox22 ]->setEnabled(flag);
935 mySpinBox[ SpinBox31 ]->setEnabled(flag);
936 mySpinBox[ SpinBox32 ]->setEnabled(flag);
937 mySpinBox[ SpinBox41 ]->setEnabled(flag);
938 mySpinBox[ SpinBox42 ]->setEnabled(flag);
939 mySpinBox[ SpinBox23 ]->setEnabled(!flag);
940 mySpinBox[ SpinBox24 ]->setEnabled(!flag);
941 mySpinBox[ SpinBox33 ]->setEnabled(!flag);
942 mySpinBox[ SpinBox34 ]->setEnabled(!flag);
943 mySpinBox[ SpinBox43 ]->setEnabled(!flag);
944 mySpinBox[ SpinBox44 ]->setEnabled(!flag);
946 myRadioButton[ RadioButton21 ]->blockSignals(false);
947 myRadioButton[ RadioButton22 ]->blockSignals(false);
948 myRadioButton[ RadioButton31 ]->blockSignals(false);
949 myRadioButton[ RadioButton32 ]->blockSignals(false);
950 myRadioButton[ RadioButton41 ]->blockSignals(false);
951 myRadioButton[ RadioButton42 ]->blockSignals(false);