Back to index

salome-geom  6.5.0
OperationGUI_ChamferDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // GEOM GEOMGUI : GUI for Geometry component
00024 // File   : OperationGUI_ChamferDlg.cxx
00025 // Author : Damien COQUERET, Open CASCADE S.A.S.
00026 
00027 #include "OperationGUI_ChamferDlg.h"
00028 #include <SalomeApp_DoubleSpinBox.h>
00029 
00030 #include <DlgRef.h>
00031 #include <GeometryGUI.h>
00032 #include <GEOMBase.h>
00033 
00034 #include <SUIT_Desktop.h>
00035 #include <SUIT_Session.h>
00036 #include <SUIT_ResourceMgr.h>
00037 #include <SUIT_ViewWindow.h>
00038 #include <SUIT_ViewManager.h>
00039 #include <SalomeApp_Application.h>
00040 #include <LightApp_SelectionMgr.h>
00041 #include <OCCViewer_ViewModel.h>
00042 
00043 // OCCT Includes
00044 #include <TColStd_MapOfInteger.hxx>
00045 
00046 #include <GEOMImpl_Types.hxx>
00047 
00048 //=================================================================================
00049 // class    : OperationGUI_ChamferDlg()
00050 // purpose  : Constructs a OperationGUI_ChamferDlg which is a child of 'parent', with the
00051 //            name 'name' and widget flags set to 'f'.
00052 //            The dialog will by default be modeless, unless you set 'modal' to
00053 //            TRUE to construct a modal dialog.
00054 //=================================================================================
00055 OperationGUI_ChamferDlg::OperationGUI_ChamferDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
00056   : GEOMBase_Skeleton(theGeometryGUI, parent, false),
00057     myInitial(true)
00058 {
00059   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
00060   QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_CHAMFER_ALL")));
00061   QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_CHAMFER_EDGE_FROM_FACE")));
00062   QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_CHAMFER_FACE")));
00063   QPixmap image4 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_CHAMFER_EDGE")));
00064 
00065   QPixmap iconSelect (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
00066 
00067   setWindowTitle(tr("GEOM_CHAMFER_TITLE"));
00068 
00069   /***************************************************************/
00070   mainFrame()->GroupConstructors->setTitle(tr("GEOM_CHAMFER"));
00071 
00072   mainFrame()->RadioButton1->setIcon(image1);
00073   mainFrame()->RadioButton2->setIcon(image2);
00074   mainFrame()->RadioButton3->setIcon(image3);
00075   mainFrame()->RadioButton4->show();
00076   mainFrame()->RadioButton4->setIcon(image4);
00077 
00078   // Create first group
00079 
00080   myGrp1 = new QGroupBox(tr("GEOM_CHAMFER_ALL"), centralWidget());
00081 
00082   QGridLayout* aLayout = new QGridLayout(myGrp1);
00083   aLayout->setMargin(9); aLayout->setSpacing(6);
00084 
00085   createSelWg(tr("GEOM_MAIN_OBJECT"), iconSelect, myGrp1, aLayout, MainObj1);
00086 
00087   int row = aLayout->rowCount();
00088   aLayout->addWidget(new QLabel(tr("D"), myGrp1), row, 0);
00089   aLayout->addWidget((mySpinBox[ SpinBox1 ] = new SalomeApp_DoubleSpinBox(myGrp1)), row++, 2);
00090   aLayout->setRowStretch(row, 10);
00091 
00092   // Create second group
00093 
00094   myGrp2 = new QGroupBox(tr("GEOM_CHAMFER_EDGE"), centralWidget());
00095 
00096   aLayout = new QGridLayout(myGrp2);
00097   aLayout->setMargin(9); aLayout->setSpacing(6);
00098 
00099   createSelWg(tr("GEOM_MAIN_OBJECT"), iconSelect, myGrp2, aLayout, MainObj2);
00100   createSelWg(tr("FACE_1"),           iconSelect, myGrp2, aLayout, Face1);
00101   createSelWg(tr("FACE_2"),           iconSelect, myGrp2, aLayout, Face2);
00102 
00103   createRadioWg(tr("GEOM_D1"), tr("GEOM_D2"),    myGrp2, aLayout, RadioButton21, SpinBox21, SpinBox22);
00104   createRadioWg(tr("GEOM_D"),  tr("GEOM_ANGLE"), myGrp2, aLayout, RadioButton22, SpinBox23, SpinBox24);
00105 
00106   aLayout->setRowStretch(aLayout->rowCount(), 10);
00107 
00108   // Create third group
00109 
00110   myGrp3 = new QGroupBox(tr("GEOM_CHAMFER_FACES"), centralWidget());
00111 
00112   aLayout = new QGridLayout(myGrp3);
00113   aLayout->setMargin(9); aLayout->setSpacing(6);
00114 
00115   createSelWg(tr("GEOM_MAIN_OBJECT"), iconSelect, myGrp3, aLayout, MainObj3);
00116   createSelWg(tr("SELECTED_FACES"),   iconSelect, myGrp3, aLayout, Faces);
00117 
00118   createRadioWg(tr("GEOM_D1"), tr("GEOM_D2"),    myGrp3, aLayout, RadioButton31, SpinBox31, SpinBox32);
00119   createRadioWg(tr("GEOM_D"),  tr("GEOM_ANGLE"), myGrp3, aLayout, RadioButton32, SpinBox33, SpinBox34);
00120 
00121   aLayout->setRowStretch(aLayout->rowCount(), 10);
00122 
00123   // Create fourth group
00124 
00125   myGrp4 = new QGroupBox(tr("GEOM_CHAMFER_EDGES"), centralWidget());
00126 
00127   aLayout = new QGridLayout(myGrp4);
00128   aLayout->setMargin(9); aLayout->setSpacing(6);
00129 
00130   createSelWg(tr("GEOM_MAIN_OBJECT"), iconSelect, myGrp4, aLayout, MainObj4);
00131   createSelWg(tr("SELECTED_EDGE"),    iconSelect, myGrp4, aLayout, Edges);
00132 
00133   createRadioWg(tr("GEOM_D1"), tr("GEOM_D2"),    myGrp4, aLayout, RadioButton41, SpinBox41, SpinBox42);
00134   createRadioWg(tr("GEOM_D"),  tr("GEOM_ANGLE"), myGrp4, aLayout, RadioButton42, SpinBox43, SpinBox44);
00135 
00136   aLayout->setRowStretch(aLayout->rowCount(), 10);
00137 
00138   // Add groups to layout
00139 
00140   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
00141   layout->setMargin(0); layout->setSpacing(6);
00142   layout->addWidget(myGrp1);
00143   layout->addWidget(myGrp2);
00144   layout->addWidget(myGrp3);
00145   layout->addWidget(myGrp4);
00146   /***************************************************************/
00147 
00148   // Set range of spinboxes
00149   double SpecificStep = 10.0;
00150   QMap< int, SalomeApp_DoubleSpinBox* >::iterator anIter;
00151   for (anIter = mySpinBox.begin(); anIter != mySpinBox.end(); ++anIter) {
00152     if (anIter.key() == SpinBox44 || anIter.key() == SpinBox34 || anIter.key() == SpinBox24)
00153       initSpinBox(anIter.value(), 0.001, 89.999, 5, "angle_precision" );
00154     else
00155       initSpinBox(anIter.value(), 0.001, COORD_MAX, SpecificStep, "length_precision" );
00156   }
00157 
00158   setHelpFileName("chamfer_operation_page.html");
00159 
00160   // Initialisation
00161   Init();
00162   myRadioButton[ RadioButton21 ]->click();
00163 }
00164 
00165 //=================================================================================
00166 // function : ~OperationGUI_ChamferDlg()
00167 // purpose  : Destroys the object and frees any allocated resources
00168 //=================================================================================
00169 OperationGUI_ChamferDlg::~OperationGUI_ChamferDlg()
00170 {
00171 }
00172 
00173 //=================================================================================
00174 // function : Init()
00175 // purpose  :
00176 //=================================================================================
00177 void OperationGUI_ChamferDlg::Init()
00178 {
00179   // Set Initial values of spinboxes
00180   QMap< int, SalomeApp_DoubleSpinBox* >::iterator anIter;
00181   for (anIter = mySpinBox.begin(); anIter != mySpinBox.end(); ++anIter)
00182     anIter.value()->setValue(5);
00183 
00184   // Clear line edits
00185   QMap< int, QLineEdit* >::iterator anIterLE;
00186   for (anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE)
00187     anIterLE.value()->setText("");
00188 
00189   myShape = GEOM::GEOM_Object::_nil();
00190 
00191   myFaces.Clear();
00192   myEdges.Clear();
00193   myFace[ Face1 ] = -1;
00194   myFace[ Face2 ] = -1;
00195 
00196   showOnlyPreviewControl();
00197 
00198   // signals and slots connections
00199 
00200   // main buttons
00201   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()   ));
00202   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00203 
00204   // group box
00205   connect(this,          SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
00206 
00207   // push buttons
00208   QMap< int, QPushButton* >::iterator anIterBtn;
00209   for (anIterBtn = mySelBtn.begin(); anIterBtn != mySelBtn.end(); ++anIterBtn)
00210     connect(anIterBtn.value(), SIGNAL(clicked()),
00211             this, SLOT(SetEditCurrentArgument()));
00212 
00213   // line edits
00214   QMap< int, QLineEdit* >::iterator anIterLE2;
00215   for (anIterLE2 = mySelName.begin(); anIterLE2 != mySelName.end(); ++anIterLE2)
00216     connect(anIterLE2.value(), SIGNAL(returnPressed()),
00217             this, SLOT(LineEditReturnPressed()));
00218 
00219   // spin boxes
00220   QMap< int, SalomeApp_DoubleSpinBox* >::iterator anIterSpin;
00221   for (anIterSpin = mySpinBox.begin(); anIterSpin != mySpinBox.end(); ++anIterSpin)
00222     connect(anIterSpin.value(), SIGNAL(valueChanged(double)),
00223             this, SLOT(ValueChangedInSpinBox(double)));
00224 
00225   // radio buttons
00226   QMap< int, QRadioButton* >::iterator anIterRadio;
00227   for (anIterRadio = myRadioButton.begin(); anIterRadio != myRadioButton.end(); ++anIterRadio)
00228     connect(anIterRadio.value(), SIGNAL(clicked()),
00229             this, SLOT(RadioButtonPressed()));
00230 
00231   initName(tr("GEOM_CHAMFER"));
00232 
00233   myConstructorId = -1;
00234   ConstructorsClicked(0);
00235 }
00236 
00237 //=================================================================================
00238 // function : ConstructorsClicked()
00239 // purpose  : Radio button management
00240 //=================================================================================
00241 void OperationGUI_ChamferDlg::ConstructorsClicked (int constructorId)
00242 {
00243    // Activate next widget
00244   if (myGeomGUI->getApp()->desktop()->activeWindow()->getViewManager()->getType()
00245       != OCCViewer_Viewer::Type()) {
00246     mainFrame()->RadioButton1->setChecked(true);
00247     return;
00248   }
00249 
00250   if (myConstructorId == constructorId)
00251     return;
00252 
00253   //disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00254 
00255   // Get values from previous widget
00256   QString D1 = "5", D2 = "5", D = "5", Angle = "5";
00257   if (myConstructorId == 0)
00258     D1 = D2 = mySpinBox[ SpinBox1 ]->text();
00259   else if (myConstructorId == 1) {
00260     D1 = mySpinBox[ SpinBox21 ]->text();
00261     D2 = mySpinBox[ SpinBox22 ]->text();
00262     D =  mySpinBox[ SpinBox23 ]->text();
00263     Angle = mySpinBox[ SpinBox24 ]->text();
00264   }
00265   else if (myConstructorId == 2) {
00266     D1 = mySpinBox[ SpinBox31 ]->text();
00267     D2 = mySpinBox[ SpinBox32 ]->text();
00268     D =  mySpinBox[ SpinBox33 ]->text();
00269     Angle = mySpinBox[ SpinBox34 ]->text();
00270   }
00271   else if (myConstructorId == 3) {
00272     D1 = mySpinBox[ SpinBox41 ]->text();
00273     D2 = mySpinBox[ SpinBox42 ]->text();
00274     D =  mySpinBox[ SpinBox43 ]->text();
00275     Angle = mySpinBox[ SpinBox44 ]->text();
00276   }
00277 
00278   myConstructorId = constructorId;
00279 
00280   switch (constructorId) {
00281   case 0:
00282     myGrp2->hide();
00283     myGrp3->hide();
00284     myGrp4->hide();
00285     myGrp1->show();
00286     mySpinBox[ SpinBox1 ]->setText(D1);
00287     break;
00288   case 1:
00289     myGrp1->hide();
00290     myGrp3->hide();
00291     myGrp4->hide();
00292     myGrp2->show();
00293     mySpinBox[ SpinBox21 ]->setText(D1);
00294     mySpinBox[ SpinBox22 ]->setText(D2);
00295     mySpinBox[ SpinBox23 ]->setText(D);
00296     mySpinBox[ SpinBox24 ]->setText(Angle);
00297     break;
00298   case 2:
00299     myGrp1->hide();
00300     myGrp2->hide();
00301     myGrp4->hide();
00302     myGrp3->show();
00303     mySpinBox[ SpinBox31 ]->setText(D1);
00304     mySpinBox[ SpinBox32 ]->setText(D2);
00305     mySpinBox[ SpinBox32 ]->setText(D2);
00306     mySpinBox[ SpinBox33 ]->setText(D);
00307     mySpinBox[ SpinBox34 ]->setText(Angle);
00308     break;
00309   case 3:
00310     myGrp1->hide();
00311     myGrp2->hide();
00312     myGrp3->hide();
00313     myGrp4->show();
00314     mySpinBox[ SpinBox41 ]->setText(D1);
00315     mySpinBox[ SpinBox42 ]->setText(D2);
00316     mySpinBox[ SpinBox43 ]->setText(D);
00317     mySpinBox[ SpinBox44 ]->setText(Angle);
00318     break;
00319   default:
00320     break;
00321   }
00322 
00323   if      (constructorId == 0) mySelBtn[ MainObj1 ]->click();
00324   else if (constructorId == 1) mySelBtn[ MainObj2 ]->click();
00325   else if (constructorId == 2) mySelBtn[ MainObj3 ]->click();
00326   else                         mySelBtn[ MainObj4 ]->click();
00327 
00328   enableWidgets();
00329 
00330   if (myInitial) {
00331     myInitial = false;
00332     SelectionIntoArgument();
00333   }
00334   else {
00335     if (!myShape->_is_nil()) {
00336       myEditCurrentArgument->setText(GEOMBase::GetName(myShape));
00337       GEOMBase_Skeleton::LineEditReturnPressed();
00338       switch (getConstructorId()) {
00339       case 1:
00340         if (myFace[ Face1 ] == -1)
00341           mySelBtn[ Face1 ]->click();
00342         break;
00343       case 2:
00344         if (myFaces.Extent() == 0)
00345           mySelBtn[ Faces ]->click();
00346         break;
00347       case 3:
00348         if (myEdges.Extent() == 0)
00349           mySelBtn[ Edges ]->click();
00350         break;
00351       default:
00352         break;
00353       }
00354     }
00355     else {
00356       myEditCurrentArgument->setText("");
00357     }
00358 
00359     processPreview();
00360   }
00361 
00362   qApp->processEvents();
00363   updateGeometry();
00364   resize(minimumSizeHint());
00365 }
00366 
00367 //=================================================================================
00368 // function : ClickOnOk()
00369 // purpose  :
00370 //=================================================================================
00371 void OperationGUI_ChamferDlg::ClickOnOk()
00372 {
00373   setIsApplyAndClose( true );
00374   if (ClickOnApply())
00375     ClickOnCancel();
00376 }
00377 
00378 //=================================================================================
00379 // function : ClickOnApply()
00380 // purpose  :
00381 //=================================================================================
00382 bool OperationGUI_ChamferDlg::ClickOnApply()
00383 {
00384   if (!onAccept())
00385     return false;
00386 
00387   initName();
00388   // activate selection and connect selection manager
00389   ConstructorsClicked(getConstructorId());
00390   return true;
00391 }
00392 
00393 //=================================================================================
00394 // function : SelectionIntoArgument()
00395 // purpose  : Called when selection is changed or on dialog initialization or activation
00396 //=================================================================================
00397 void OperationGUI_ChamferDlg::SelectionIntoArgument()
00398 {
00399   erasePreview();
00400   myEditCurrentArgument->setText("");
00401 
00402   // Get index of current selection focus
00403   int aCurrFocus = -1;
00404   QMap< int, QLineEdit* >::iterator anIter;
00405   for (anIter = mySelName.begin(); anIter != mySelName.end(); ++anIter) {
00406     if (myEditCurrentArgument == anIter.value()) {
00407       aCurrFocus = anIter.key();
00408       break;
00409     }
00410   }
00411 
00412   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00413   SALOME_ListIO aSelList;
00414   aSelMgr->selectedObjects(aSelList);
00415 
00416   // If selection of main object is activated
00417   if (aCurrFocus == MainObj1 || aCurrFocus == MainObj2 || aCurrFocus == MainObj3 || aCurrFocus == MainObj4)
00418   {
00419     myShape = GEOM::GEOM_Object::_nil();
00420     if (aSelList.Extent() == 1) {
00421       GEOM::GEOM_Object_var anObj =
00422         GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
00423 
00424       if ( !anObj->_is_nil() ) {
00425         myShape = anObj;
00426         myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
00427         processPreview();
00428       }
00429     }
00430 
00431     enableWidgets();
00432   }
00433   // If face selection of second tab is activated
00434   else if (aCurrFocus == Face1 || aCurrFocus == Face2)
00435   {
00436     myFace[ aCurrFocus ] = -1;
00437     if (aSelList.Extent() == 1) {
00438       GEOM::GEOM_Object_var anObj =
00439         GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
00440 
00441       if ( !anObj->_is_nil() ) {
00442          TColStd_IndexedMapOfInteger anIndexes;
00443          aSelMgr->GetIndexes(aSelList.First(), anIndexes);
00444 
00445          if (anIndexes.Extent() == 1) {
00446             int anIndex = anIndexes(1);
00447             QString aFaceName = QString(GEOMBase::GetName(anObj)) + ":%1";
00448             myEditCurrentArgument->setText(aFaceName.arg(anIndex));
00449             myFace[ aCurrFocus ] = anIndex;
00450             processPreview();
00451          }
00452       }
00453     }
00454   }
00455   // If face selection of third or fourth tab is activated
00456   else if (aCurrFocus == Faces || aCurrFocus == Edges) {
00457     if (aCurrFocus == Faces) myFaces.Clear();
00458     else myEdges.Clear();
00459     if (aSelList.Extent() == 1) {
00460       GEOM::GEOM_Object_var anObj =
00461         GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
00462 
00463       if ( !anObj->_is_nil() ) {
00464         TColStd_IndexedMapOfInteger anIndexes;
00465         aSelMgr->GetIndexes(aSelList.First(), anIndexes);
00466 
00467         if (anIndexes.Extent() > 0) {
00468           QString aName;
00469           if (anIndexes.Extent() == 1) {
00470             int anIndex = anIndexes(1);
00471 
00472             aName = QString(GEOMBase::GetName(anObj)) + QString(":%1").arg(anIndex);
00473           }
00474           else {
00475             aName = tr("GEOM_MEN_POPUP_NAME").arg(anIndexes.Extent());
00476           }
00477 
00478           myEditCurrentArgument->setText(aName);
00479           int aConstructorId = getConstructorId();
00480           if (aConstructorId == 2)
00481             myFaces = anIndexes;
00482           else if (aConstructorId == 3)
00483             myEdges = anIndexes;
00484 
00485           processPreview();
00486         }
00487       }
00488     }
00489   }
00490 
00491   // clear selection
00492   if (aCurrFocus != Face1 && aCurrFocus != Face2 &&
00493       aCurrFocus != Faces && aCurrFocus != Edges) {
00494     disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00495     myGeomGUI->getApp()->selectionMgr()->clearSelected();
00496     connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00497             this, SLOT(SelectionIntoArgument()));
00498   }
00499 
00500   switch (getConstructorId()) {
00501   case 1:
00502     if (aCurrFocus == MainObj2) {
00503       if (!myShape->_is_nil() && myFace[ Face1 ] == -1)
00504         mySelBtn[ Face1 ]->click();
00505     }
00506     else if (aCurrFocus == Face1) {
00507       if (myFace[ Face1 ] != -1 && myFace[ Face2 ] == -1)
00508         mySelBtn[ Face2 ]->click();
00509     }
00510     else if (aCurrFocus == Face2) {
00511       if (myFace[ Face2 ] != -1 && myShape->_is_nil())
00512         mySelBtn[ MainObj2 ]->click();
00513     }
00514     break;
00515   case 2:
00516     if (aCurrFocus == MainObj3) {
00517       if (!myShape->_is_nil() && myFaces.Extent() == 0)
00518         mySelBtn[ Faces ]->click();
00519     }
00520     break;
00521   case 3:
00522     if (aCurrFocus == MainObj4) {
00523       if (!myShape->_is_nil() && myEdges.Extent() == 0)
00524         mySelBtn[ Edges ]->click();
00525     }
00526     break;
00527   default:
00528     break;
00529   }
00530 
00531   //rnv: To fix the bug IPAL22041 TC5.1.5: "Fillet Construcion" dialog loses current selection.
00532   // Restore selection of the main shape, if need,
00533   // because it was canceled.
00534   aSelMgr->selectedObjects(aSelList);
00535   if (aSelList.Extent() == 0 && !myShape->_is_nil()) {
00536     disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00537     ObjectList list;
00538        list.push_back(myShape);
00539     selectObjects(list);
00540     connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00541             this, SLOT(SelectionIntoArgument()));
00542   }
00543 }
00544 
00545 //=================================================================================
00546 // function : SetEditCurrentArgument()
00547 // purpose  :
00548 //=================================================================================
00549 void OperationGUI_ChamferDlg::SetEditCurrentArgument()
00550 {
00551   QPushButton* send = (QPushButton*)sender();
00552 
00553   QMap< int, QPushButton* >::iterator anIter;
00554   for (anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter) {
00555     if (anIter.value() == send) {
00556       mySelName[ anIter.key() ]->setFocus();
00557       myEditCurrentArgument = mySelName[ anIter.key() ];
00558     }
00559     else {
00560       anIter.value()->setDown(false);
00561       mySelName[ anIter.key() ]->setEnabled(false);
00562     }
00563   }
00564 
00565   // enable line edit
00566   myEditCurrentArgument->setEnabled(true);
00567   myEditCurrentArgument->setFocus();
00568   // after setFocus(), because it will be setDown(false) when loses focus
00569   send->setDown(true);
00570 
00571   activateSelection();
00572 
00573   // seems we need it only to avoid preview disappearing, caused by selection mode change
00574   processPreview();
00575 }
00576 
00577 //=================================================================================
00578 // function : LineEditReturnPressed()
00579 // purpose  :
00580 //=================================================================================
00581 void OperationGUI_ChamferDlg::LineEditReturnPressed()
00582 {
00583   QLineEdit* send = (QLineEdit*)sender();
00584 
00585   QMap< int, QLineEdit* >::iterator anIterLE;
00586   for (anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE)
00587     if (anIterLE.value() == send)
00588       myEditCurrentArgument = anIterLE.value();
00589 
00590   GEOMBase_Skeleton::LineEditReturnPressed();
00591 }
00592 
00593 //=================================================================================
00594 // function : ActivateThisDialog()
00595 // purpose  :
00596 //=================================================================================
00597 void OperationGUI_ChamferDlg::ActivateThisDialog()
00598 {
00599   GEOMBase_Skeleton::ActivateThisDialog();
00600   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
00601            this, SLOT( SelectionIntoArgument() ) );
00602 
00603   ConstructorsClicked( getConstructorId() );
00604 }
00605 
00606 //=================================================================================
00607 // function : enterEvent()
00608 // purpose  :
00609 //=================================================================================
00610 void OperationGUI_ChamferDlg::enterEvent (QEvent*)
00611 {
00612   if (!mainFrame()->GroupConstructors->isEnabled())
00613     this->ActivateThisDialog();
00614 }
00615 
00616 //=================================================================================
00617 // function : ValueChangedInSpinBox()
00618 // purpose  :
00619 //=================================================================================
00620 void OperationGUI_ChamferDlg::ValueChangedInSpinBox (double)
00621 {
00622   processPreview();
00623 }
00624 
00625 //=================================================================================
00626 // function : createSelWg()
00627 // purpose  :
00628 //=================================================================================
00629 void OperationGUI_ChamferDlg::createSelWg (const QString& theLbl,
00630                                            QPixmap&       thePix,
00631                                            QWidget*       theParent,
00632                                            QGridLayout*   theLayout,
00633                                            const int      theId)
00634 {
00635   QLabel* lab = new QLabel(theLbl, theParent);
00636   mySelBtn[ theId ] = new QPushButton(theParent);
00637   mySelBtn[ theId ]->setIcon(thePix);
00638   mySelName[ theId ] = new QLineEdit(theParent);
00639   mySelName[ theId ]->setReadOnly(true);
00640   int row = theLayout->rowCount();
00641   theLayout->addWidget(lab,                row, 0);
00642   theLayout->addWidget(mySelBtn[ theId ],  row, 1);
00643   theLayout->addWidget(mySelName[ theId ], row, 2, 1, 4); // take into account createRadioWg()
00644 }
00645 
00646 //=================================================================================
00647 // function : createRadioWg()
00648 // purpose  :
00649 //=================================================================================
00650 void OperationGUI_ChamferDlg::createRadioWg(const QString& theLbl1,
00651                                              const QString& theLbl2,
00652                                              QWidget*       theParent,
00653                                              QGridLayout*   theLayout,
00654                                              const int      theRbId,
00655                                              const int      theSpin1Id,
00656                                              const int      theSpin2Id)
00657 {
00658   myRadioButton[ theRbId ] = new QRadioButton(theParent);
00659   QLabel* lab1 = new QLabel(theLbl1, theParent);
00660   QLabel* lab2 = new QLabel(theLbl2, theParent);
00661   mySpinBox[ theSpin1Id ]  = new SalomeApp_DoubleSpinBox(theParent);
00662   mySpinBox[ theSpin2Id ]  = new SalomeApp_DoubleSpinBox(theParent);
00663   int row = theLayout->rowCount();
00664   theLayout->addWidget(myRadioButton[ theRbId ], row, 0);
00665   theLayout->addWidget(lab1,                     row, 2);
00666   theLayout->addWidget(mySpinBox[ theSpin1Id ],  row, 3);
00667   theLayout->addWidget(lab2,                     row, 4);
00668   theLayout->addWidget(mySpinBox[ theSpin2Id ],  row, 5);
00669 }
00670 
00671 //=================================================================================
00672 // function : activateSelection
00673 // purpose  : Activate selection in accordance with myEditCurrentArgument
00674 //=================================================================================
00675 void OperationGUI_ChamferDlg::activateSelection()
00676 {
00677   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00678 
00679   if (!myShape->_is_nil() &&
00680       (myEditCurrentArgument == mySelName[ Face1 ] ||
00681        myEditCurrentArgument == mySelName[ Face2 ] ||
00682        myEditCurrentArgument == mySelName[ Faces ])) {
00683     localSelection(myShape, TopAbs_FACE);
00684   }
00685   else if (!myShape->_is_nil() && myEditCurrentArgument == mySelName[ Edges ]) {
00686     localSelection(myShape, TopAbs_EDGE);
00687   }
00688   else {
00689     TColStd_MapOfInteger aMap;
00690     aMap.Add(GEOM_SHELL);
00691     aMap.Add(GEOM_SOLID);
00692     aMap.Add(GEOM_COMPOUND);
00693     globalSelection(aMap);
00694   }
00695 
00696   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00697           this, SLOT(SelectionIntoArgument()));
00698 }
00699 
00700 //=================================================================================
00701 // function : enableWidgets
00702 // purpose  : Enable widgets of faces in accordance with value of main object
00703 //=================================================================================
00704 void OperationGUI_ChamferDlg::enableWidgets()
00705 {
00706   int anId = getConstructorId();
00707 
00708   bool toEnable = !myShape->_is_nil();
00709 
00710   if (anId == 1)
00711   {
00712     //mySelName[ Face1 ]->setEnabled(toEnable);
00713     //mySelName[ Face2 ]->setEnabled(toEnable);
00714     mySelBtn[ Face1 ]->setEnabled(toEnable);
00715     mySelBtn[ Face2 ]->setEnabled(toEnable);
00716 
00717     if (!toEnable)
00718     {
00719       mySelName[ Face1 ]->setText("");
00720       mySelName[ Face2 ]->setText("");
00721       myFace[ Face1 ] = -1;
00722       myFace[ Face2 ] = -1;
00723     }
00724   }
00725   else if (anId == 2)
00726   {
00727     //mySelName[ Faces ]->setEnabled(toEnable);
00728     mySelBtn[ Faces ]->setEnabled(toEnable);
00729     if (!toEnable) {
00730       mySelName[ Faces ]->setText("");
00731       myFaces.Clear();
00732     }
00733   }
00734   else if (anId == 3) {
00735     //mySelName[ Edges ]->setEnabled(toEnable);
00736     mySelBtn[ Edges ]->setEnabled(toEnable);
00737 
00738     if (!toEnable) {
00739       mySelName[ Edges ]->setText("");
00740       myEdges.Clear();
00741     }
00742   }
00743 }
00744 
00745 //=================================================================================
00746 // function : createOperation
00747 // purpose  :
00748 //=================================================================================
00749 GEOM::GEOM_IOperations_ptr OperationGUI_ChamferDlg::createOperation()
00750 {
00751   return getGeomEngine()->GetILocalOperations(getStudyId());
00752 }
00753 
00754 //=================================================================================
00755 // function : isValid()
00756 // purpose  : Verify validity of input data
00757 //=================================================================================
00758 bool OperationGUI_ChamferDlg::isValid (QString& msg)
00759 {
00760   bool ok = true;
00761   switch (getConstructorId())
00762   {
00763     case 0:
00764       ok = mySpinBox[ SpinBox1 ]->isValid( msg, !IsPreview() );
00765       return !myShape->_is_nil() && ok;
00766     case 1:
00767       if (myRadioButton[ RadioButton21 ]->isChecked())
00768       {
00769         ok = mySpinBox[ SpinBox21 ]->isValid( msg, !IsPreview() ) && ok;
00770         ok = mySpinBox[ SpinBox22 ]->isValid( msg, !IsPreview() ) && ok;
00771       }
00772       else
00773       {
00774         ok = mySpinBox[ SpinBox23 ]->isValid( msg, !IsPreview() ) && ok;
00775         ok = mySpinBox[ SpinBox24 ]->isValid( msg, !IsPreview() ) && ok;
00776       }
00777       return !myShape->_is_nil() && myFace[ Face1 ] > 0 && myFace[ Face2 ] > 0 && ok;
00778     case 2:
00779       if (myRadioButton[ RadioButton31 ]->isChecked())
00780       {
00781         ok = mySpinBox[ SpinBox31 ]->isValid( msg, !IsPreview() ) && ok;
00782         ok = mySpinBox[ SpinBox32 ]->isValid( msg, !IsPreview() ) && ok;
00783       }
00784       else
00785       {
00786         ok = mySpinBox[ SpinBox33 ]->isValid( msg, !IsPreview() ) && ok;
00787         ok = mySpinBox[ SpinBox34 ]->isValid( msg, !IsPreview() ) && ok;
00788       }
00789       return !myShape->_is_nil() && myFaces.Extent() > 0 && ok;
00790     case 3:
00791       if (myRadioButton[ RadioButton41 ]->isChecked())
00792       {
00793         ok = mySpinBox[ SpinBox41 ]->isValid( msg, !IsPreview() ) && ok;
00794         ok = mySpinBox[ SpinBox42 ]->isValid( msg, !IsPreview() ) && ok;
00795       }
00796       else
00797       {
00798         ok = mySpinBox[ SpinBox43 ]->isValid( msg, !IsPreview() ) && ok;
00799         ok = mySpinBox[ SpinBox44 ]->isValid( msg, !IsPreview() ) && ok;
00800       }
00801       return !myShape->_is_nil() && myEdges.Extent() > 0 && ok;
00802     default: return false;
00803   }
00804 }
00805 
00806 //=================================================================================
00807 // function : execute
00808 // purpose  :
00809 //=================================================================================
00810 bool OperationGUI_ChamferDlg::execute (ObjectList& objects)
00811 {
00812   QStringList aParameters;
00813   GEOM::GEOM_Object_var anObj;
00814   bool flag = (myRadioButton[ RadioButton21 ]->isChecked() &&
00815                myRadioButton[ RadioButton31 ]->isChecked() &&
00816                myRadioButton[ RadioButton41 ]->isChecked());
00817 
00818   int anId = getConstructorId();
00819 
00820   GEOM::GEOM_ILocalOperations_var anOper = GEOM::GEOM_ILocalOperations::_narrow(getOperation());
00821 
00822   if (anId == 0) {
00823     anObj = anOper->MakeChamferAll(myShape, mySpinBox[ SpinBox1 ]->value());
00824     if (!anObj->_is_nil())
00825       aParameters << mySpinBox[ SpinBox1 ]->text();
00826   }
00827   else if (anId == 1) {
00828     if (flag) {
00829       anObj = anOper->MakeChamferEdge(myShape,
00830                                       mySpinBox[ SpinBox21 ]->value(),
00831                                       mySpinBox[ SpinBox22 ]->value(),
00832                                       myFace[ Face1 ],
00833                                       myFace[ Face2 ]);
00834       if (!anObj->_is_nil())
00835       {
00836         aParameters << mySpinBox[ SpinBox21 ]->text();
00837         aParameters << mySpinBox[ SpinBox22 ]->text();
00838       }
00839     }
00840     else {
00841       anObj = anOper->MakeChamferEdgeAD(myShape,
00842                                         mySpinBox[ SpinBox23 ]->value(),
00843                                         mySpinBox[ SpinBox24 ]->value() * M_PI / 180.,
00844                                         myFace[ Face1 ],
00845                                         myFace[ Face2 ]);
00846       if (!anObj->_is_nil())
00847       {
00848         aParameters << mySpinBox[ SpinBox23 ]->text();
00849         aParameters << mySpinBox[ SpinBox24 ]->text();
00850       }
00851     }
00852   }
00853   else if (anId == 2)
00854   {
00855     GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
00856     anArray->length(myFaces.Extent());
00857 
00858     for (int i = 1, n = myFaces.Extent(); i <= n; i++)
00859       anArray[ i - 1 ] = myFaces(i);
00860 
00861     if (flag) {
00862       anObj = anOper->MakeChamferFaces(myShape,
00863                                        mySpinBox[ SpinBox31 ]->value(),
00864                                        mySpinBox[ SpinBox32 ]->value(),
00865                                        anArray);
00866       if (!anObj->_is_nil())
00867       {
00868         aParameters << mySpinBox[ SpinBox31 ]->text();
00869         aParameters << mySpinBox[ SpinBox32 ]->text();
00870       }
00871     }
00872     else {
00873       anObj = anOper->MakeChamferFacesAD(myShape,
00874                                          mySpinBox[ SpinBox33 ]->value(),
00875                                          mySpinBox[ SpinBox34 ]->value() * M_PI / 180.,
00876                                          anArray);
00877       if (!anObj->_is_nil())
00878       {
00879         aParameters << mySpinBox[ SpinBox33 ]->text();
00880         aParameters << mySpinBox[ SpinBox34 ]->text();
00881       }
00882     }
00883   }
00884   else if (anId == 3) {
00885     GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
00886     anArray->length(myEdges.Extent());
00887     for (int i = 1, n = myEdges.Extent(); i <= n; i++)
00888       anArray[ i - 1 ] = myEdges(i);
00889     if (flag) {
00890       anObj = anOper->MakeChamferEdges(myShape,
00891                                        mySpinBox[ SpinBox41 ]->value(),
00892                                        mySpinBox[ SpinBox42 ]->value(),
00893                                        anArray);
00894       if (!anObj->_is_nil())
00895       {
00896         aParameters << mySpinBox[ SpinBox41 ]->text();
00897         aParameters << mySpinBox[ SpinBox42 ]->text();
00898       }
00899     }
00900     else {
00901       anObj = anOper->MakeChamferEdgesAD(myShape,
00902                                          mySpinBox[ SpinBox43 ]->value(),
00903                                          mySpinBox[ SpinBox44 ]->value() * M_PI / 180.,
00904                                          anArray);
00905       if (!anObj->_is_nil())
00906       {
00907         aParameters << mySpinBox[ SpinBox43 ]->text();
00908         aParameters << mySpinBox[ SpinBox44 ]->text();
00909       }
00910     }
00911   }
00912 
00913   if (!anObj->_is_nil())
00914   {
00915     if (!IsPreview())
00916       anObj->SetParameters(aParameters.join(":").toLatin1().constData());
00917     objects.push_back(anObj._retn());
00918   }
00919 
00920   return true;
00921 }
00922 
00923 //=================================================================================
00924 // function : RadioButtonPressed()
00925 // purpose  :
00926 //=================================================================================
00927 void OperationGUI_ChamferDlg::RadioButtonPressed()
00928 {
00929   const QObject* s = sender();
00930   bool flag = s == myRadioButton[ RadioButton21 ] ||
00931               s == myRadioButton[ RadioButton31 ] ||
00932               s == myRadioButton[ RadioButton41 ];
00933 
00934   myRadioButton[ RadioButton21 ]->blockSignals(true);
00935   myRadioButton[ RadioButton22 ]->blockSignals(true);
00936   myRadioButton[ RadioButton31 ]->blockSignals(true);
00937   myRadioButton[ RadioButton32 ]->blockSignals(true);
00938   myRadioButton[ RadioButton41 ]->blockSignals(true);
00939   myRadioButton[ RadioButton42 ]->blockSignals(true);
00940 
00941   myRadioButton[ RadioButton21 ]->setChecked(flag);
00942   myRadioButton[ RadioButton31 ]->setChecked(flag);
00943   myRadioButton[ RadioButton41 ]->setChecked(flag);
00944   myRadioButton[ RadioButton22 ]->setChecked(!flag);
00945   myRadioButton[ RadioButton32 ]->setChecked(!flag);
00946   myRadioButton[ RadioButton42 ]->setChecked(!flag);
00947   mySpinBox[ SpinBox21 ]->setEnabled(flag);
00948   mySpinBox[ SpinBox22 ]->setEnabled(flag);
00949   mySpinBox[ SpinBox31 ]->setEnabled(flag);
00950   mySpinBox[ SpinBox32 ]->setEnabled(flag);
00951   mySpinBox[ SpinBox41 ]->setEnabled(flag);
00952   mySpinBox[ SpinBox42 ]->setEnabled(flag);
00953   mySpinBox[ SpinBox23 ]->setEnabled(!flag);
00954   mySpinBox[ SpinBox24 ]->setEnabled(!flag);
00955   mySpinBox[ SpinBox33 ]->setEnabled(!flag);
00956   mySpinBox[ SpinBox34 ]->setEnabled(!flag);
00957   mySpinBox[ SpinBox43 ]->setEnabled(!flag);
00958   mySpinBox[ SpinBox44 ]->setEnabled(!flag);
00959 
00960   myRadioButton[ RadioButton21 ]->blockSignals(false);
00961   myRadioButton[ RadioButton22 ]->blockSignals(false);
00962   myRadioButton[ RadioButton31 ]->blockSignals(false);
00963   myRadioButton[ RadioButton32 ]->blockSignals(false);
00964   myRadioButton[ RadioButton41 ]->blockSignals(false);
00965   myRadioButton[ RadioButton42 ]->blockSignals(false);
00966 
00967   processPreview();
00968 }