Back to index

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