Back to index

salome-geom  6.5.0
PrimitiveGUI_FaceDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 // GEOM GEOMGUI : GUI for Geometry component
00021 // File   : PrimitiveGUI_FaceDlg.cxx
00022 // Author : Dmitry Matveitchev, OCN.
00023 //
00024 #include "PrimitiveGUI_FaceDlg.h"
00025 
00026 #include <DlgRef.h>
00027 #include <GeometryGUI.h>
00028 #include <GEOMBase.h>
00029 
00030 #include <SUIT_ResourceMgr.h>
00031 #include <SUIT_Session.h>
00032 #include <SalomeApp_Application.h>
00033 #include <LightApp_SelectionMgr.h>
00034 
00035 #include <TopoDS_Shape.hxx>
00036 #include <TopoDS.hxx>
00037 #include <TopExp.hxx>
00038 #include <TColStd_IndexedMapOfInteger.hxx>
00039 #include <TopTools_IndexedMapOfShape.hxx>
00040 
00041 #include <GEOMImpl_Types.hxx>
00042 
00043 //=================================================================================
00044 // class    : PrimitiveGUI_FaceDlg()
00045 // purpose  : Constructs a PrimitiveGUI_FaceDlg which is a child of 'parent', with the 
00046 //            name 'name' and widget flags set to 'f'.
00047 //            The dialog will by default be modeless, unless you set 'modal' to
00048 //            TRUE to construct a modal dialog.
00049 //=================================================================================
00050 PrimitiveGUI_FaceDlg::PrimitiveGUI_FaceDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
00051                                     bool modal, Qt::WindowFlags fl )
00052   : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
00053 {
00054   QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FACE_OBJ_HW")));
00055   QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
00056   QPixmap image2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FACE_HW")));
00057 
00058   setWindowTitle( tr( "GEOM_RECTANGLE_TITLE" ) );
00059  
00060   /***************************************************************/
00061   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_RECTANGLE" ) );
00062   mainFrame()->RadioButton1->setIcon( image2 );
00063   mainFrame()->RadioButton2->setIcon( image0 );
00064   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
00065   mainFrame()->RadioButton3->close();
00066 
00067   GroupPlane = new DlgRef_1Sel2Spin( centralWidget() );
00068   GroupPlane->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
00069   GroupPlane->TextLabel1->setText( tr( "GEOM_EDGE" ) );
00070   GroupPlane->TextLabel2->setText( tr( "GEOM_HEIGHT" ) );
00071   GroupPlane->TextLabel3->setText( tr( "GEOM_WIDTH" ) );
00072   GroupPlane->PushButton1->setIcon( image1 );
00073   GroupPlane->LineEdit1->setReadOnly( true );
00074 
00075   GroupType = new DlgRef_3Radio( centralWidget() );
00076   GroupType->GroupBox1->setTitle( tr( "GEOM_OBJECT_TYPE" ) );
00077   GroupType->RadioButton1->setText( tr( "GEOM_EDGE" ) );
00078   GroupType->RadioButton2->setText( tr( "GEOM_FACE" ) );
00079   GroupType->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
00080   GroupType->RadioButton3->close();
00081 
00082   GroupDimensions = new DlgRef_2Spin( centralWidget() );
00083   GroupDimensions->GroupBox1->setTitle( tr( "GEOM_BOX_OBJ" ) );
00084   GroupDimensions->TextLabel1->setText( tr( "GEOM_HEIGHT" ) );
00085   GroupDimensions->TextLabel2->setText( tr( "GEOM_WIDTH" ) );
00086 
00087   GroupOrientation = new DlgRef_3Radio( centralWidget() );
00088 
00089   GroupOrientation->GroupBox1->setTitle( tr( "GEOM_ORIENTATION" ) );
00090   GroupOrientation->RadioButton1->setText( tr( "GEOM_WPLANE_OXY" ) );
00091   GroupOrientation->RadioButton2->setText( tr( "GEOM_WPLANE_OYZ" ) );
00092   GroupOrientation->RadioButton3->setText( tr( "GEOM_WPLANE_OZX" ) );
00093 
00094   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
00095   layout->setMargin( 0 ); layout->setSpacing( 6 );
00096   layout->addWidget( GroupType );
00097   layout->addWidget( GroupPlane );
00098   layout->addWidget( GroupDimensions );
00099   layout->addWidget( GroupOrientation );
00100 
00101   /***************************************************************/
00102 
00103   setHelpFileName( "create_squareface_page.html" );
00104 
00105   Init();
00106 }
00107 
00108 
00109 //=================================================================================
00110 // function : ~PrimitiveGUI_FaceDlg()
00111 // purpose  : Destroys the object and frees any allocated resources
00112 //=================================================================================
00113 PrimitiveGUI_FaceDlg::~PrimitiveGUI_FaceDlg()
00114 {  
00115 }
00116 
00117 
00118 //=================================================================================
00119 // function : Init()
00120 // purpose  :
00121 //=================================================================================
00122 void PrimitiveGUI_FaceDlg::Init()
00123 {
00124   /* init variables */
00125   myEditCurrentArgument = GroupPlane->LineEdit1;
00126   GroupType->RadioButton1->setChecked(true);
00127   myEdge.nullify();
00128   myFace.nullify();
00129   globalSelection(); // close local contexts, if any
00130   //  localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
00131 
00132   myOrientationType = 1;
00133 
00134   /* Get setting of step value from file configuration */
00135   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00136   double aStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
00137 
00138   double aDefaultSize = 100.0;
00139   /* min, max, step and decimals for spin boxes */
00140   initSpinBox( GroupPlane->SpinBox_DX, 0.00001, COORD_MAX, aStep, "length_precision" );
00141   GroupPlane->SpinBox_DX->setValue( aDefaultSize );
00142   initSpinBox( GroupPlane->SpinBox_DY, 0.00001, COORD_MAX, aStep, "length_precision" );
00143   GroupPlane->SpinBox_DY->setValue( aDefaultSize );
00144 
00145   initSpinBox( GroupDimensions->SpinBox_DX, 0.00001, COORD_MAX, aStep, "length_precision" );
00146   GroupDimensions->SpinBox_DX->setValue( aDefaultSize );
00147   initSpinBox( GroupDimensions->SpinBox_DY, 0.00001, COORD_MAX, aStep, "length_precision" );
00148   GroupDimensions->SpinBox_DY->setValue( aDefaultSize );
00149 
00150         
00151   /* signals and slots connections */
00152   connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
00153   connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
00154   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
00155 
00156   connect( this,           SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
00157 
00158   connect( buttonOk(),     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
00159   connect( buttonApply(),  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
00160 
00161   connect( GroupPlane->PushButton1,  SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
00162   connect( GroupPlane->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00163   connect( GroupPlane->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00164 
00165   connect( GroupDimensions->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00166   connect( GroupDimensions->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00167 
00168   connect( GroupOrientation->RadioButton1, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
00169   connect( GroupOrientation->RadioButton2, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
00170   connect( GroupOrientation->RadioButton3, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
00171 
00172   connect( GroupType->RadioButton1, SIGNAL( clicked() ), this, SLOT( TypeButtonClicked() ) );
00173   connect( GroupType->RadioButton2, SIGNAL( clicked() ), this, SLOT( TypeButtonClicked() ) );
00174 
00175   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
00176            this, SLOT( SelectionIntoArgument() ) );
00177   
00178   initName( tr( "GEOM_FACE" ) );
00179 
00180   ConstructorsClicked( 0 );
00181 }
00182 
00183 //=================================================================================
00184 // function : SetDoubleSpinBoxStep()
00185 // purpose  : Double spin box management
00186 //=================================================================================
00187 void PrimitiveGUI_FaceDlg::SetDoubleSpinBoxStep( double step )
00188 {
00189   GroupPlane->SpinBox_DX->setSingleStep(step);
00190   GroupPlane->SpinBox_DY->setSingleStep(step);
00191   GroupDimensions->SpinBox_DX->setSingleStep(step);
00192   GroupDimensions->SpinBox_DY->setSingleStep(step);
00193 }
00194 
00195 //=================================================================================
00196 // function : ValueChangedInSpinBox()
00197 // purpose  :
00198 //=================================================================================
00199 void PrimitiveGUI_FaceDlg::ValueChangedInSpinBox( double newValue )
00200 {
00201   displayPreview(true);
00202 }
00203 
00204 //=================================================================================
00205 // function : RadioBittonClicked()
00206 // purpose  : Radio button management
00207 //=================================================================================
00208 void PrimitiveGUI_FaceDlg::RadioButtonClicked()
00209 {
00210   if ( GroupOrientation->RadioButton1->isChecked() )
00211     myOrientationType = 1;
00212   else if ( GroupOrientation->RadioButton2->isChecked() )
00213     myOrientationType = 2;
00214   else if ( GroupOrientation->RadioButton3->isChecked() )
00215     myOrientationType = 3;
00216   displayPreview(true);
00217 }
00218 
00219 //=================================================================================
00220 // function : TypeBittonClicked()
00221 // purpose  : Radio button management
00222 //=================================================================================
00223 void PrimitiveGUI_FaceDlg::TypeButtonClicked()
00224 {
00225   if ( GroupType->RadioButton1->isChecked() ) {
00226     globalSelection(); // close local contexts, if any
00227     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
00228     GroupPlane->TextLabel1->setText( tr( "GEOM_EDGE" ) );
00229   }
00230   else if ( GroupType->RadioButton2->isChecked() ) {
00231     globalSelection(); // close local contexts, if any
00232     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
00233     GroupPlane->TextLabel1->setText( tr( "GEOM_FACE" ) );
00234   }
00235   myEditCurrentArgument = GroupPlane->LineEdit1;
00236   myEditCurrentArgument->setText( "" );
00237   myEdge.nullify();
00238   myFace.nullify();
00239 }
00240 
00241 //=================================================================================
00242 // function : ClickOnOk()
00243 // purpose  :
00244 //=================================================================================
00245 void PrimitiveGUI_FaceDlg::ClickOnOk()
00246 {
00247   setIsApplyAndClose( true );
00248   if ( ClickOnApply() )
00249     ClickOnCancel();
00250 }
00251 
00252 //=================================================================================
00253 // function : ClickOnApply()
00254 // purpose  :
00255 //=================================================================================
00256 bool PrimitiveGUI_FaceDlg::ClickOnApply()
00257 {
00258   if ( !onAccept() )
00259     return false;
00260   
00261   initName();
00262 
00263   myEditCurrentArgument->setText( "" );
00264   ConstructorsClicked( getConstructorId() );
00265 
00266   return true;
00267 }
00268 
00269 //=================================================================================
00270 // function : ConstructorsClicked()
00271 // purpose  : Radio button management
00272 //=================================================================================
00273 void PrimitiveGUI_FaceDlg::ConstructorsClicked( int constructorId )
00274 {  
00275   erasePreview();
00276   switch ( constructorId ) {
00277   case 0:
00278     {
00279       globalSelection(); // close local contexts, if any
00280       GroupPlane->hide();
00281       GroupDimensions->show();
00282       GroupOrientation->show();
00283       GroupType->hide();
00284       GroupOrientation->RadioButton1->setChecked( true );
00285       myOrientationType = 1;
00286       break;
00287     }
00288   case 1:
00289     {
00290       globalSelection(); // close local contexts, if any
00291       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
00292       myEditCurrentArgument = GroupPlane->LineEdit1;
00293       myEditCurrentArgument->setText("");
00294       myEdge.nullify();
00295       myFace.nullify();
00296       GroupType->RadioButton1->setChecked( true );
00297       TypeButtonClicked();
00298       GroupDimensions->hide();
00299       GroupOrientation->hide();
00300       GroupType->show();
00301       GroupPlane->show();
00302       break;
00303     }
00304   }
00305 
00306   qApp->processEvents();
00307   updateGeometry();
00308   resize( minimumSizeHint() );
00309   SelectionIntoArgument();
00310   //displayPreview(true);
00311 }
00312 
00313 //=================================================================================
00314 // function : SelectionIntoArgument()
00315 // purpose  : Called when selection as changed or other case
00316 //=================================================================================
00317 void PrimitiveGUI_FaceDlg::SelectionIntoArgument()
00318 {
00319   if (getConstructorId() == 0) {
00320     displayPreview(true);
00321     return;
00322   }
00323 
00324   myEditCurrentArgument->setText( "" );
00325 
00326   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00327   SALOME_ListIO aSelList;
00328   aSelMgr->selectedObjects(aSelList);
00329 
00330   if ( aSelList.Extent() != 1 ) {
00331     if ( myEditCurrentArgument == GroupPlane->LineEdit1 )  myEdge.nullify();
00332     return;
00333   }
00334 
00335   TopAbs_ShapeEnum aNeedType = GroupType->RadioButton2->isChecked() ? TopAbs_FACE : TopAbs_EDGE;
00336   GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
00337   TopoDS_Shape aShape;
00338   if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
00339     QString aName = GEOMBase::GetName( aSelectedObject.get() );
00340 
00341     myEditCurrentArgument->setText( aName );
00342     
00343     if ( myEditCurrentArgument == GroupPlane->LineEdit1 && aNeedType == TopAbs_EDGE )
00344       myEdge = aSelectedObject;
00345     else if ( myEditCurrentArgument == GroupPlane->LineEdit1 && aNeedType == TopAbs_FACE )
00346       myFace = aSelectedObject;
00347   }
00348 
00349   displayPreview(true);
00350 }
00351 
00352 
00353 //=================================================================================
00354 // function : SetEditCurrentArgument()
00355 // purpose  :
00356 //=================================================================================
00357 void PrimitiveGUI_FaceDlg::SetEditCurrentArgument()
00358 {
00359   QPushButton* send = (QPushButton*)sender();
00360 
00361   globalSelection(); // close previous local contexts
00362   if ( send == GroupPlane->PushButton1 ) {
00363     myEditCurrentArgument = GroupPlane->LineEdit1;
00364     if (GroupType->RadioButton1->isChecked())
00365       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
00366     else if (GroupType->RadioButton1->isChecked())
00367       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
00368   }
00369 
00370   myEditCurrentArgument->setFocus();
00371   SelectionIntoArgument();
00372 }
00373 
00374 //=================================================================================
00375 // function : ActivateThisDialog()
00376 // purpose  :
00377 //=================================================================================
00378 void PrimitiveGUI_FaceDlg::ActivateThisDialog()
00379 {
00380   GEOMBase_Skeleton::ActivateThisDialog();
00381   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
00382            this, SLOT( SelectionIntoArgument() ) );
00383 
00384   ConstructorsClicked( getConstructorId() );
00385 }
00386 
00387 //=================================================================================
00388 // function : DeactivateActiveDialog()
00389 // purpose  : public slot to deactivate if active
00390 //=================================================================================
00391 void PrimitiveGUI_FaceDlg::DeactivateActiveDialog()
00392 {
00393   GEOMBase_Skeleton::DeactivateActiveDialog();
00394 }
00395 
00396 //=================================================================================
00397 // function : enterEvent()
00398 // purpose  :
00399 //=================================================================================
00400 void PrimitiveGUI_FaceDlg::enterEvent( QEvent* )
00401 {
00402   if ( !mainFrame()->GroupConstructors->isEnabled() )
00403     ActivateThisDialog();
00404 }
00405 
00406 //=================================================================================
00407 // function : createOperation
00408 // purpose  :
00409 //=================================================================================
00410 GEOM::GEOM_IOperations_ptr PrimitiveGUI_FaceDlg::createOperation()
00411 {
00412   return myGeomGUI->GetGeomGen()->GetI3DPrimOperations( getStudyId() );
00413 }
00414 
00415 //=================================================================================
00416 // function : isValid
00417 // purpose  :
00418 //=================================================================================
00419 bool PrimitiveGUI_FaceDlg::isValid( QString& msg )
00420 {
00421   bool ok = false;
00422   if( getConstructorId() == 0 )
00423   {
00424     ok = GroupDimensions->SpinBox_DX->isValid( msg, !IsPreview() ) &&
00425          GroupDimensions->SpinBox_DY->isValid( msg, !IsPreview() );
00426   }
00427   else if( getConstructorId() == 1 )
00428   {
00429     ok = GroupPlane->SpinBox_DX->isValid( msg, !IsPreview() ) &&
00430          GroupPlane->SpinBox_DY->isValid( msg, !IsPreview() ) &&
00431          ( GroupType->RadioButton1->isChecked() ? myEdge : myFace );
00432   }
00433   return ok;
00434 }
00435 
00436 //=================================================================================
00437 // function : execute
00438 // purpose  :
00439 //=================================================================================
00440 bool PrimitiveGUI_FaceDlg::execute (ObjectList& objects)
00441 {
00442   bool res = false;
00443   QStringList aParameters;
00444   GEOM::GEOM_Object_var anObj;
00445 
00446   GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
00447 
00448   switch (getConstructorId()) {
00449   case 0:
00450     anObj = anOper->MakeFaceHW(GroupDimensions->SpinBox_DX->value(),
00451                                GroupDimensions->SpinBox_DY->value(), myOrientationType);
00452     if (!anObj->_is_nil() && !IsPreview())
00453     {
00454       aParameters << GroupDimensions->SpinBox_DX->text();
00455       aParameters << GroupDimensions->SpinBox_DY->text();
00456       anObj->SetParameters(aParameters.join(":").toLatin1().constData());
00457     }
00458     res = true;
00459     break;
00460   case 1:
00461     anObj = GroupType->RadioButton1->isChecked() ? 
00462       anOper->MakeFaceObjHW(myEdge.get(), GroupPlane->SpinBox_DX->value(), GroupPlane->SpinBox_DY->value()) : 
00463       anOper->MakeFaceObjHW(myFace.get(), GroupPlane->SpinBox_DX->value(), GroupPlane->SpinBox_DY->value());
00464     if (!anObj->_is_nil() && !IsPreview())
00465     {
00466       aParameters << GroupPlane->SpinBox_DX->text();
00467       aParameters << GroupPlane->SpinBox_DY->text();
00468       anObj->SetParameters(aParameters.join(":").toLatin1().constData());
00469     }
00470     res = true;
00471     break;
00472   }
00473 
00474   if (!anObj->_is_nil())
00475     objects.push_back(anObj._retn());
00476 
00477   return res;
00478 }
00479 
00480 //=================================================================================
00481 // function : addSubshapeToStudy
00482 // purpose  : virtual method to add new SubObjects if local selection
00483 //=================================================================================
00484 void PrimitiveGUI_FaceDlg::addSubshapesToStudy()
00485 {
00486   if ( getConstructorId() == 1 ) {
00487     if ( GroupType->RadioButton1->isChecked() )
00488      GEOMBase::PublishSubObject( myEdge.get() );
00489     if ( GroupType->RadioButton2->isChecked() )
00490      GEOMBase::PublishSubObject( myFace.get() );
00491   }
00492 }