Back to index

salome-geom  6.5.0
PrimitiveGUI_SphereDlg.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   : PrimitiveGUI_SphereDlg.cxx
00025 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
00026 //
00027 #include "PrimitiveGUI_SphereDlg.h"
00028 
00029 #include <DlgRef.h>
00030 #include <GeometryGUI.h>
00031 #include <GEOMBase.h>
00032 
00033 #include <SUIT_ResourceMgr.h>
00034 #include <SUIT_Session.h>
00035 #include <SalomeApp_Application.h>
00036 #include <LightApp_SelectionMgr.h>
00037 
00038 #include <TopoDS_Shape.hxx>
00039 #include <TopoDS.hxx>
00040 #include <TopExp.hxx>
00041 #include <TColStd_IndexedMapOfInteger.hxx>
00042 #include <TopTools_IndexedMapOfShape.hxx>
00043 
00044 #include <GEOMImpl_Types.hxx>
00045 
00046 //=================================================================================
00047 // class    : PrimitiveGUI_SphereDlg()
00048 // purpose  : Constructs a PrimitiveGUI_SphereDlg which is a child of 'parent', with the 
00049 //            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 PrimitiveGUI_SphereDlg::PrimitiveGUI_SphereDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
00054                                                 bool modal, Qt::WindowFlags fl )
00055   :GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl )
00056 {
00057   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_SPHERE_P" ) ) );
00058   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_SPHERE_DXYZ" ) ) );
00059   QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
00060 
00061   setWindowTitle( tr( "GEOM_SPHERE_TITLE" ) );
00062 
00063   /***************************************************************/
00064   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_SPHERE" ) );
00065   mainFrame()->RadioButton1->setIcon( image0 );
00066   mainFrame()->RadioButton2->setIcon( image1 );
00067   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
00068   mainFrame()->RadioButton3->close();
00069 
00070   GroupPoints = new DlgRef_1Sel1Spin( centralWidget() );
00071   GroupPoints->GroupBox1->setTitle( tr( "GEOM_SPHERE_CR" ) );
00072   GroupPoints->TextLabel1->setText( tr( "GEOM_CENTER" ) );
00073   GroupPoints->TextLabel2->setText( tr( "GEOM_RADIUS" ) );
00074   GroupPoints->PushButton1->setIcon( image2 );
00075 
00076   GroupDimensions = new DlgRef_1Spin( centralWidget() );
00077   GroupDimensions->GroupBox1->setTitle( tr( "GEOM_SPHERE_RO" ) );
00078   GroupDimensions->TextLabel1->setText( tr( "GEOM_RADIUS" ) );
00079 
00080   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
00081   layout->setMargin( 0 ); layout->setSpacing( 6 );
00082   layout->addWidget( GroupPoints );
00083   layout->addWidget( GroupDimensions );
00084   /***************************************************************/
00085 
00086   setHelpFileName( "create_sphere_page.html" );
00087 
00088   Init();
00089 }
00090 
00091 
00092 //=================================================================================
00093 // function : ~PrimitiveGUI_SphereDlg()
00094 // purpose  : Destroys the object and frees any allocated resources
00095 //=================================================================================
00096 PrimitiveGUI_SphereDlg::~PrimitiveGUI_SphereDlg()
00097 {  
00098   /* no need to delete child widgets, Qt does it all for us */
00099 }
00100 
00101 
00102 //=================================================================================
00103 // function : Init()
00104 // purpose  :
00105 //=================================================================================
00106 void PrimitiveGUI_SphereDlg::Init()
00107 {
00108   /* init variables */
00109   myEditCurrentArgument = GroupPoints->LineEdit1;
00110   GroupPoints->LineEdit1->setReadOnly( true );
00111   
00112   myPoint.nullify();
00113   
00114   /* Get setting of step value from file configuration */
00115   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00116   double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
00117 
00118   /* min, max, step and decimals for spin boxes */
00119   initSpinBox( GroupPoints->SpinBox_DX, 0.000001, COORD_MAX, step, "length_precision" );
00120   initSpinBox( GroupDimensions->SpinBox_DX, 0.000001, COORD_MAX, step, "length_precision" );
00121   GroupPoints->SpinBox_DX->setValue( 100.0 );
00122   GroupDimensions->SpinBox_DX->setValue( 100.0 );
00123   
00124   /* signals and slots connections */
00125   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
00126   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
00127 
00128   connect( this,          SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
00129 
00130   connect( GroupPoints->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
00131 
00132   connect( GroupDimensions->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
00133   connect( GroupPoints->SpinBox_DX,     SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
00134 
00135   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
00136 
00137   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
00138            this, SLOT( SelectionIntoArgument() ) );
00139 
00140   initName( tr( "GEOM_SPHERE" ) );
00141 
00142   setConstructorId( 1 ); // simplest constructor
00143   ConstructorsClicked( 1 );
00144 }
00145 
00146 //=================================================================================
00147 // function : SetDoubleSpinBoxStep()
00148 // purpose  : Double spin box management
00149 //=================================================================================
00150 void PrimitiveGUI_SphereDlg::SetDoubleSpinBoxStep( double step )
00151 {
00152   GroupPoints->SpinBox_DX->setSingleStep(step);
00153   GroupDimensions->SpinBox_DX->setSingleStep(step);
00154 }
00155 
00156 //=================================================================================
00157 // function : ConstructorsClicked()
00158 // purpose  : Radio button management
00159 //=================================================================================
00160 void PrimitiveGUI_SphereDlg::ConstructorsClicked( int constructorId )
00161 {
00162   disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
00163   
00164   switch ( constructorId ) {
00165   case 0:
00166     {
00167       globalSelection(); // close local contexts, if any
00168       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
00169 
00170       GroupDimensions->hide();
00171       GroupPoints->show();
00172       
00173       myEditCurrentArgument = GroupPoints->LineEdit1;
00174       GroupPoints->LineEdit1->setText( "" );
00175       myPoint.nullify();
00176       
00177       connect( myGeomGUI->getApp()->selectionMgr(), 
00178                SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00179       break;
00180     }
00181   case 1:
00182     {
00183       globalSelection(); // close local contexts, if any
00184       
00185       GroupPoints->hide();
00186       GroupDimensions->show();
00187       
00188       break;
00189     }
00190   }
00191 
00192   qApp->processEvents();
00193   updateGeometry();
00194   resize( minimumSizeHint() );
00195   SelectionIntoArgument();
00196 
00197   displayPreview(true);
00198 }
00199 
00200 
00201 //=================================================================================
00202 // function : ClickOnOk()
00203 // purpose  :
00204 //=================================================================================
00205 void PrimitiveGUI_SphereDlg::ClickOnOk()
00206 {
00207   setIsApplyAndClose( true );
00208   if ( ClickOnApply() )
00209     ClickOnCancel();
00210 }
00211 
00212 
00213 //=================================================================================
00214 // function : ClickOnApply()
00215 // purpose  :
00216 //=================================================================================
00217 bool PrimitiveGUI_SphereDlg::ClickOnApply()
00218 {
00219   if ( !onAccept() )
00220     return false;
00221   
00222   initName();
00223   ConstructorsClicked( getConstructorId() );
00224   return true;
00225 }
00226 
00227 
00228 //=================================================================================
00229 // function : SelectionIntoArgument()
00230 // purpose  : Called when selection as changed or other case
00231 //=================================================================================
00232 void PrimitiveGUI_SphereDlg::SelectionIntoArgument()
00233 {
00234   if ( getConstructorId() != 0 )
00235     return;
00236 
00237   myEditCurrentArgument->setText( "" );
00238 
00239   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00240   SALOME_ListIO aSelList;
00241   aSelMgr->selectedObjects(aSelList);
00242 
00243   if (aSelList.Extent() != 1) {
00244     myPoint.nullify();
00245     return;
00246   }
00247 
00248   GEOM::GeomObjPtr aSelectedObject = getSelected( TopAbs_VERTEX );
00249   TopoDS_Shape aShape;
00250   if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
00251     QString aName = GEOMBase::GetName( aSelectedObject.get() );
00252     myEditCurrentArgument->setText( aName );
00253     myPoint = aSelectedObject;
00254   }
00255 
00256   displayPreview(true);
00257 }
00258 
00259 //=================================================================================
00260 // function : SetEditCurrentArgument()
00261 // purpose  :
00262 //=================================================================================
00263 void PrimitiveGUI_SphereDlg::SetEditCurrentArgument()
00264 {
00265   QPushButton* send = (QPushButton*)sender();
00266   
00267   if ( send == GroupPoints->PushButton1 ) {
00268     GroupPoints->LineEdit1->setFocus();
00269     myEditCurrentArgument = GroupPoints->LineEdit1;
00270     globalSelection(); // close local contexts, if any
00271     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
00272     SelectionIntoArgument();
00273   }
00274 }
00275 
00276 
00277 //=================================================================================
00278 // function : ActivateThisDialog()
00279 // purpose  :
00280 //=================================================================================
00281 void PrimitiveGUI_SphereDlg::ActivateThisDialog()
00282 {
00283   GEOMBase_Skeleton::ActivateThisDialog();
00284   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
00285            this, SLOT( SelectionIntoArgument() ) );
00286   
00287   ConstructorsClicked( getConstructorId() );
00288 }
00289 
00290 
00291 //=================================================================================
00292 // function : DeactivateActiveDialog()
00293 // purpose  : public slot to deactivate if active
00294 //=================================================================================
00295 void PrimitiveGUI_SphereDlg::DeactivateActiveDialog()
00296 {
00297   GEOMBase_Skeleton::DeactivateActiveDialog();
00298 }
00299 
00300 
00301 //=================================================================================
00302 // function : enterEvent()
00303 // purpose  :
00304 //=================================================================================
00305 void PrimitiveGUI_SphereDlg::enterEvent( QEvent* )
00306 {
00307   if ( !mainFrame()->GroupConstructors->isEnabled() )
00308     ActivateThisDialog();
00309 }
00310 
00311 
00312 //=================================================================================
00313 // function : ValueChangedInSpinBox()
00314 // purpose  :
00315 //=================================================================================
00316 void PrimitiveGUI_SphereDlg::ValueChangedInSpinBox()
00317 {
00318   displayPreview(true);
00319 }
00320 
00321 
00322 //=================================================================================
00323 // function : createOperation
00324 // purpose  :
00325 //=================================================================================
00326 GEOM::GEOM_IOperations_ptr PrimitiveGUI_SphereDlg::createOperation()
00327 {
00328   return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
00329 }
00330 
00331 
00332 //=================================================================================
00333 // function : isValid
00334 // purpose  :
00335 //=================================================================================
00336 bool PrimitiveGUI_SphereDlg::isValid( QString& msg  )
00337 {
00338   bool ok = false;
00339   if( getConstructorId() == 0 )
00340     ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) && myPoint;
00341   else if( getConstructorId() == 1 )
00342     ok = GroupDimensions->SpinBox_DX->isValid( msg, !IsPreview() );
00343   return ok;
00344 }
00345 
00346 //=================================================================================
00347 // function : execute
00348 // purpose  :
00349 //=================================================================================
00350 bool PrimitiveGUI_SphereDlg::execute( ObjectList& objects )
00351 {
00352   bool res = false;
00353   
00354   GEOM::GEOM_Object_var anObj;
00355 
00356   GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
00357 
00358   switch ( getConstructorId() ) {
00359   case 0 :
00360     {
00361       if ( myPoint ) {
00362         anObj = anOper->MakeSpherePntR( myPoint.get(), getRadius() );
00363         if (!anObj->_is_nil() && !IsPreview())
00364         {
00365           QStringList aParameters;
00366           aParameters << GroupPoints->SpinBox_DX->text();
00367           anObj->SetParameters(aParameters.join(":").toLatin1().constData());
00368         }
00369         res = true;
00370       }
00371       break;
00372     }
00373   case 1 :
00374     {
00375       anObj = anOper->MakeSphereR( getRadius() );
00376       if (!anObj->_is_nil() && !IsPreview())
00377       {
00378         QStringList aParameters;
00379         aParameters << GroupDimensions->SpinBox_DX->text();
00380         anObj->SetParameters(aParameters.join(":").toLatin1().constData());
00381       }
00382       res = true;
00383       break;
00384     }
00385   }
00386   
00387   if ( !anObj->_is_nil() )
00388     objects.push_back( anObj._retn() );
00389   
00390   return res;
00391 }
00392 
00393 
00394 //=================================================================================
00395 // function : getRadius()
00396 // purpose  :
00397 //=================================================================================
00398 double PrimitiveGUI_SphereDlg::getRadius() const
00399 {
00400   int aConstructorId = getConstructorId();
00401   if ( aConstructorId == 0 )
00402     return GroupPoints->SpinBox_DX->value();
00403   else if ( aConstructorId == 1 )
00404     return GroupDimensions->SpinBox_DX->value();
00405   return 0;
00406 }
00407 
00408 //=================================================================================
00409 // function : addSubshapeToStudy
00410 // purpose  : virtual method to add new SubObjects if local selection
00411 //=================================================================================
00412 void PrimitiveGUI_SphereDlg::addSubshapesToStudy()
00413 {
00414   if ( getConstructorId() == 0 ) {
00415     GEOMBase::PublishSubObject( myPoint.get() );
00416   }
00417 }