Back to index

salome-geom  6.5.0
OperationGUI_ExtrudedFeatureDlg.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_ExtrudedFeatureDlg.cxx
00025 //  Author : Renaud NEDELEC, Open CASCADE S.A.S.
00026 
00027 #include "OperationGUI.h"
00028 #include "OperationGUI_ExtrudedFeatureDlg.h"
00029 
00030 #include <SUIT_Session.h>
00031 #include <SUIT_ResourceMgr.h>
00032 #include <SalomeApp_Application.h>
00033 #include <LightApp_SelectionMgr.h>
00034 
00035 #include <GeometryGUI.h>
00036 #include <GEOMBase.h>
00037 
00038 #include <DlgRef.h>
00039 #include <GEOM_Object.hxx>
00040 
00041 // OCCT Includes
00042 #include <TColStd_HSequenceOfTransient.hxx>
00043 
00044 #include <GEOMImpl_Types.hxx>
00045 
00046 //=================================================================================
00047 // class    : OperationGUI_ExtrudedFeatureDlg()
00048 // purpose  : Constructs a OperationGUI_ExtrudedCutDlg which is a child of 'parent',
00049 //            with the name 'name' and widget flags set to 'f'.
00050 //            The dialog will by default be modeless, unless you set 'modal' to
00051 //            TRUE to construct a modal dialog.
00052 //=================================================================================
00053 
00054 OperationGUI_ExtrudedFeatureDlg::OperationGUI_ExtrudedFeatureDlg(const int theOperation,
00055                                                                  GeometryGUI* theGeometryGUI,
00056                                                                  QWidget* parent,bool modal, 
00057                                                                  Qt::WindowFlags fl)
00058   : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
00059     myOperation(theOperation)
00060 {
00061   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
00062   QPixmap image0;
00063   QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
00064   QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICO_DRAFT")));
00065   QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_CHANGE_DIRECTION")));
00066   QString aTitle;
00067   switch (myOperation) 
00068   {
00069     case OperationGUI::BOSS:
00070       image0 = QPixmap(aResMgr->loadPixmap("GEOM", tr("ICO_EXTRUDED_BOSS")));
00071       aTitle = tr("GEOM_EXTRUDED_BOSS_TITLE");
00072       setHelpFileName("extruded_boss_operation_page.html");
00073       break;
00074     case OperationGUI::CUT:
00075       image0 = QPixmap( aResMgr->loadPixmap("GEOM", tr("ICO_EXTRUDED_CUT")));
00076       aTitle = tr("GEOM_EXTRUDED_CUT_TITLE");
00077       setHelpFileName("extruded_cut_operation_page.html");
00078       break;
00079   }
00080     
00081   setWindowTitle(aTitle);
00082   mainFrame()->GroupConstructors->setTitle(aTitle);
00083   mainFrame()->RadioButton1->setIcon(image0);
00084   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
00085   mainFrame()->RadioButton2->close();
00086   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
00087   mainFrame()->RadioButton3->close();
00088   
00089   mainFrame()->RadioButton1->setChecked(true);
00090   
00091   myGroup = new DlgRef_2Sel2Spin2Push(centralWidget());
00092   
00093   myGroup->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
00094   
00095   myGroup->PushButton1->setIcon(image1);
00096   myGroup->PushButton2->setIcon(image1);
00097   myGroup->PushButton3->setIcon(image2);
00098   myGroup->PushButton4->setIcon(image3);
00099   myGroup->LineEdit1->setReadOnly(true);
00100   myGroup->LineEdit2->setReadOnly(true);
00101   myGroup->TextLabel1->setText(tr("GEOM_INIT_SHAPE"));
00102   myGroup->TextLabel2->setText(tr("GEOM_PROFILE"));
00103   myGroup->TextLabel3->setText(tr("GEOM_HEIGHT"));
00104   myGroup->TextLabel4->setText(tr("GEOM_DRAFT_ANGLE"));
00105   myGroup->TextLabel5->setText(tr("GEOM_CHANGE_DIRECTION"));
00106  
00107   
00108   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
00109   layout->setMargin(0); 
00110   layout->setSpacing(6);
00111   layout->addWidget(myGroup);
00112 
00113   Init();
00114    
00115 }
00116 
00117 //=================================================================================
00118 // function : ~OperationGUI_ExtrudedFeatureDlg()
00119 // purpose  : Destroys the object and frees any allocated resources
00120 //=================================================================================
00121 OperationGUI_ExtrudedFeatureDlg::~OperationGUI_ExtrudedFeatureDlg()
00122 {
00123 }
00124 
00125 //=================================================================================
00126 // function : Init()
00127 // purpose  :
00128 //=================================================================================
00129 void OperationGUI_ExtrudedFeatureDlg::Init()
00130 {
00131   // init variables
00132   myEditCurrentArgument = myGroup->LineEdit1;
00133   
00134   // Get setting of step value from file configuration
00135   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00136   double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
00137   
00138   initSpinBox(myGroup->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
00139   initSpinBox(myGroup->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
00140 
00141   myGroup->LineEdit1->setText("");
00142   myGroup->LineEdit2->setText("");
00143   myGroup->SpinBox_DX->setValue(10.0);
00144   myGroup->SpinBox_DY->setValue(10.0);
00145   myGroup->SpinBox_DY->setEnabled(false);
00146   myObject1.nullify();
00147   myObject2.nullify();
00148   
00149   // signals and slots connections
00150   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00151   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00152 
00153   connect(myGroup->PushButton1, SIGNAL(clicked()),     this, SLOT(SetEditCurrentArgument()));
00154   connect(myGroup->PushButton2, SIGNAL(clicked()),     this, SLOT(SetEditCurrentArgument()));
00155   connect(myGroup->PushButton3, SIGNAL(clicked(bool)), this, SLOT(ButtonClicked(bool)));
00156   connect(myGroup->PushButton4, SIGNAL(clicked(bool)), this, SLOT(ButtonClicked(bool)));
00157   connect(myGroup->SpinBox_DX,  SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
00158   connect(myGroup->SpinBox_DY,  SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
00159   
00160 
00161   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
00162            SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
00163   
00164   switch (myOperation) 
00165   {
00166     case OperationGUI::BOSS:
00167       initName(tr("GEOM_EXTRUDED_BOSS"));     
00168       break;
00169     case OperationGUI::CUT:
00170       initName(tr("GEOM_EXTRUDED_CUT"));  
00171       break;
00172   }
00173   
00174   mainFrame()->RadioButton1->setFocus();
00175   
00176   globalSelection(GEOM_ALLSHAPES);
00177   
00178   myGroup->PushButton1->click();
00179   SelectionIntoArgument();
00180   
00181   resize(minimumSizeHint());
00182 }
00183 
00184 //=================================================================================
00185 // function : ClickOnOk()
00186 // purpose  :
00187 //=================================================================================
00188 void OperationGUI_ExtrudedFeatureDlg::ClickOnOk()
00189 {
00190   setIsApplyAndClose( true );
00191   if (ClickOnApply())
00192     ClickOnCancel();
00193 }
00194 
00195 //=================================================================================
00196 // function : ClickOnApply()
00197 // purpose  :
00198 //=================================================================================
00199 bool OperationGUI_ExtrudedFeatureDlg::ClickOnApply()
00200 {
00201   if (!onAccept())
00202     return false;
00203 
00204   initName();
00205   // activate selection and connect selection manager
00206   myGroup->PushButton1->click();
00207   return true;
00208 }
00209 
00210 //=================================================================================
00211 // function : SetEditCurrentArgument()
00212 // purpose  :
00213 //=================================================================================
00214 void OperationGUI_ExtrudedFeatureDlg::SetEditCurrentArgument()
00215 {
00216   QPushButton* send = (QPushButton*)sender();
00217   
00218   if (send == myGroup->PushButton1) {
00219     myEditCurrentArgument = myGroup->LineEdit1;
00220 
00221     myGroup->PushButton2->setDown(false);
00222     myGroup->LineEdit2->setEnabled(false);
00223   }
00224   else if (send == myGroup->PushButton2) {
00225     myEditCurrentArgument = myGroup->LineEdit2;
00226 
00227     myGroup->PushButton1->setDown(false);
00228     myGroup->LineEdit1->setEnabled(false);
00229   }
00230   
00231   // enable line edit
00232   myEditCurrentArgument->setEnabled(true);
00233   myEditCurrentArgument->setFocus();
00234   // after setFocus(), because it will be setDown(false) when loses focus
00235   send->setDown(true);
00236 }
00237 
00238 
00239 //=================================================================================
00240 // function : SelectionIntoArgument()
00241 // purpose  : Called when selection is changed or on dialog initialization or activation
00242 //=================================================================================
00243 void OperationGUI_ExtrudedFeatureDlg::SelectionIntoArgument()
00244 {
00245   myEditCurrentArgument->setText("");
00246 
00247   QList<TopAbs_ShapeEnum> types;
00248   types<<TopAbs_SHAPE;
00249   
00250   if (myEditCurrentArgument == myGroup->LineEdit1)
00251   {
00252     types.clear();
00253     types<<TopAbs_COMPOUND<<TopAbs_SOLID;
00254   }
00255   if (myEditCurrentArgument == myGroup->LineEdit2)
00256   {
00257     types.clear();
00258     types << TopAbs_EDGE << TopAbs_WIRE << TopAbs_FACE;
00259   }
00260 
00261   GEOM::GeomObjPtr aSelectedObject = getSelected( types );
00262   TopoDS_Shape aShape;
00263   if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
00264     QString aName = GEOMBase::GetName( aSelectedObject.get() );
00265     myEditCurrentArgument->setText( aName );
00266 
00267     // clear selection
00268     disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00269     myGeomGUI->getApp()->selectionMgr()->clearSelected();
00270     connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00271             this, SLOT(SelectionIntoArgument()));
00272 
00273     if (myEditCurrentArgument == myGroup->LineEdit1) {
00274       myObject1 = aSelectedObject;
00275       if (!myObject2)
00276         myGroup->PushButton2->click();
00277     }
00278     else if (myEditCurrentArgument == myGroup->LineEdit2) {
00279       myObject2 = aSelectedObject;
00280       if (!myObject1)
00281         myGroup->PushButton1->click();
00282     }
00283     
00284     displayPreview(true);
00285   }
00286   else {
00287     if      (myEditCurrentArgument == myGroup->LineEdit1) myObject1.nullify();
00288     else if (myEditCurrentArgument == myGroup->LineEdit2) myObject2.nullify();
00289   }
00290 }
00291 
00292 //=================================================================================
00293 // function : ActivateThisDialog()
00294 // purpose  :
00295 //=================================================================================
00296 void OperationGUI_ExtrudedFeatureDlg::ActivateThisDialog()
00297 {
00298   GEOMBase_Skeleton::ActivateThisDialog();
00299 
00300   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
00301            this, SLOT( SelectionIntoArgument() ) );
00302   processPreview();
00303 }
00304 
00305 
00306 //=================================================================================
00307 // function : enterEvent()
00308 // purpose  : when mouse enter onto the QWidget
00309 //=================================================================================
00310 void OperationGUI_ExtrudedFeatureDlg::enterEvent (QEvent*)
00311 {
00312   if (!mainFrame()->GroupConstructors->isEnabled())
00313     ActivateThisDialog();
00314 }
00315 
00316 //=================================================================================
00317 // function : ValueChangedInSpinBox()
00318 // purpose  :
00319 //=================================================================================
00320 void OperationGUI_ExtrudedFeatureDlg::ValueChangedInSpinBox()
00321 {
00322   displayPreview(true);
00323 }
00324 
00325 //=================================================================================
00326 // function : ButtonClicked(bool checked)
00327 // purpose  :
00328 //=================================================================================
00329 void OperationGUI_ExtrudedFeatureDlg::ButtonClicked(bool checked)
00330 {
00331   QPushButton* send = (QPushButton*)sender();
00332   if (send == myGroup->PushButton3)
00333     myGroup->SpinBox_DY->setEnabled(checked);
00334  
00335   displayPreview(true);
00336 }
00337 
00338 //=================================================================================
00339 // function : createOperation
00340 // purpose  :
00341 //=================================================================================
00342 GEOM::GEOM_IOperations_ptr OperationGUI_ExtrudedFeatureDlg::createOperation()
00343 {
00344   return getGeomEngine()->GetI3DPrimOperations(getStudyId());
00345 }
00346 
00347 //=================================================================================
00348 // function : isValid
00349 // purpose  :
00350 //=================================================================================
00351 bool OperationGUI_ExtrudedFeatureDlg::isValid (QString&)
00352 {
00353   return myObject1 && myObject2; 
00354 }
00355 
00356 //=================================================================================
00357 // function : execute
00358 // purpose  :
00359 //=================================================================================
00360 bool OperationGUI_ExtrudedFeatureDlg::execute (ObjectList& objects)
00361 {
00362   GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
00363   
00364   double angle=0.0;
00365   double aHeight = myGroup->SpinBox_DX->value();
00366   
00367   if (myGroup->PushButton3->isChecked())
00368     angle=myGroup->SpinBox_DY->value();
00369   
00370   if (myGroup->PushButton4->isChecked())
00371   {
00372     aHeight = -aHeight;
00373     angle   = -angle;
00374   }
00375     
00376   bool isProtrusion = (myOperation == OperationGUI::BOSS);  
00377   
00378   // Hide the initial shape in order to see the modifications on the preview
00379   erase(myObject1.get(),false); 
00380   
00381   GEOM::GEOM_Object_var anObj = anOper->MakeDraftPrism(myObject1.get(), myObject2.get(), 
00382                                                        aHeight,
00383                                                        angle,
00384                                                        isProtrusion);
00385   if (!anObj->_is_nil())
00386     objects.push_back(anObj._retn());
00387 
00388   return true;
00389 }
00390 
00391 // //=================================================================================
00392 // // function : addSubshapeToStudy
00393 // // purpose  : virtual method to add new SubObjects if local selection
00394 // //=================================================================================
00395 // void OperationGUI_ExtrudedFeatureDlg::addSubshapesToStudy()
00396 // {
00397 //   GEOMBase::PublishSubObject( myObject2.get() );
00398 // }