Back to index

salome-geom  6.5.0
BasicGUI_VectorDlg.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_VectorDlg.cxx
00025 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
00026 //
00027 #include "BasicGUI_VectorDlg.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    : BasicGUI_VectorDlg()
00048 // purpose  : Constructs a BasicGUI_VectorDlg 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 BasicGUI_VectorDlg::BasicGUI_VectorDlg( 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_VECTOR_2P" ) ) );
00058   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_VECTOR_DXYZ" ) ) );
00059   QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
00060 
00061   setWindowTitle( tr( "GEOM_VECTOR_TITLE" ) );
00062 
00063   /***************************************************************/
00064   mainFrame()->GroupConstructors->setTitle(tr("GEOM_VECTOR"));
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_2Sel( centralWidget() );
00071 
00072   GroupPoints->GroupBox1->setTitle( tr( "GEOM_POINTS" ) );
00073   GroupPoints->TextLabel1->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
00074   GroupPoints->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( 2 ) );
00075   GroupPoints->PushButton1->setIcon( image2 );
00076   GroupPoints->PushButton2->setIcon( image2 );
00077   GroupPoints->PushButton1->setDown( true );
00078 
00079   GroupPoints->LineEdit1->setReadOnly( true );
00080   GroupPoints->LineEdit2->setReadOnly( true );
00081   GroupPoints->LineEdit1->setEnabled( true );
00082   GroupPoints->LineEdit2->setEnabled( false );
00083 
00084   GroupDimensions = new DlgRef_3Spin1Check( centralWidget() );
00085   GroupDimensions->GroupBox1->setTitle( tr( "GEOM_COORDINATES" ) );
00086   GroupDimensions->TextLabel1->setText( tr( "GEOM_DX" ) );
00087   GroupDimensions->TextLabel2->setText( tr( "GEOM_DY" ) );
00088   GroupDimensions->TextLabel3->setText( tr( "GEOM_DZ" ) );
00089   GroupDimensions->CheckButton1->setText( tr( "GEOM_REVERSE_VECTOR" ) );
00090 
00091   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
00092   layout->setMargin( 0 ); layout->setSpacing( 6 );
00093   layout->addWidget( GroupPoints );
00094   layout->addWidget( GroupDimensions );
00095   /***************************************************************/
00096 
00097   setHelpFileName( "create_vector_page.html" );
00098 
00099   /* Initialisations */
00100   Init();
00101 }
00102 
00103 
00104 //=================================================================================
00105 // function : ~BasicGUI_VectorDlg()
00106 // purpose  : Destroys the object and frees any allocated resources
00107 //=================================================================================
00108 BasicGUI_VectorDlg::~BasicGUI_VectorDlg()
00109 {
00110 }
00111 
00112 
00113 //=================================================================================
00114 // function : Init()
00115 // purpose  :
00116 //=================================================================================
00117 void BasicGUI_VectorDlg::Init()
00118 {
00119     /* init variables */
00120   myEditCurrentArgument = GroupPoints->LineEdit1;
00121 
00122   myPoint1.nullify();
00123   myPoint2.nullify();
00124 
00125   /* Get setting of step value from file configuration */
00126   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00127   double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
00128 
00129   /* min, max, step and decimals for spin boxes */
00130   initSpinBox( GroupDimensions->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
00131   initSpinBox( GroupDimensions->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
00132   initSpinBox( GroupDimensions->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
00133 
00134   double dx( 0. ), dy( 0. ), dz( 200. );
00135   GroupDimensions->SpinBox_DX->setValue( dx );
00136   GroupDimensions->SpinBox_DY->setValue( dy );
00137   GroupDimensions->SpinBox_DZ->setValue( dz );
00138 
00139   GroupDimensions->CheckButton1->setChecked( false );
00140 
00141   /* signals and slots connections */
00142   connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
00143   connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
00144 
00145   connect( buttonOk(),     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
00146   connect( buttonApply(),  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
00147 
00148   connect( this,           SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
00149 
00150   connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
00151   connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
00152 
00153   connect( GroupDimensions->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00154   connect( GroupDimensions->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00155   connect( GroupDimensions->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00156 
00157   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
00158 
00159   connect( GroupDimensions->CheckButton1, SIGNAL( stateChanged( int ) ), this, SLOT( ReverseVector( int ) ) );
00160 
00161   connect( myGeomGUI->getApp()->selectionMgr(),
00162            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00163 
00164   initName( tr("GEOM_VECTOR") );
00165 
00166   setConstructorId( 1 ); // simplest constructor
00167   ConstructorsClicked( 1 );
00168 }
00169 
00170 //=================================================================================
00171 // function : SetDoubleSpinBoxStep()
00172 // purpose  : Double spin box management
00173 //=================================================================================
00174 void BasicGUI_VectorDlg::SetDoubleSpinBoxStep( double step )
00175 {
00176   GroupDimensions->SpinBox_DX->setSingleStep(step);
00177   GroupDimensions->SpinBox_DY->setSingleStep(step);
00178   GroupDimensions->SpinBox_DZ->setSingleStep(step);
00179 }
00180 
00181 
00182 //=================================================================================
00183 // function : ConstructorsClicked()
00184 // purpose  : Radio button management
00185 //=================================================================================
00186 void BasicGUI_VectorDlg::ConstructorsClicked( int constructorId )
00187 {
00188   disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
00189   myPoint1.nullify();
00190   myPoint2.nullify();
00191 
00192   switch ( constructorId ) {
00193   case 0:
00194     {
00195       GroupDimensions->hide();
00196       GroupPoints->show();
00197 
00198       myEditCurrentArgument = GroupPoints->LineEdit1;
00199       GroupPoints->LineEdit1->setText( "" );
00200       GroupPoints->LineEdit2->setText( "" );
00201       GroupPoints->PushButton1->setDown( true );
00202       GroupPoints->PushButton2->setDown( false );
00203       GroupPoints->LineEdit1->setEnabled( true );
00204       GroupPoints->LineEdit2->setEnabled( false );
00205 
00206       globalSelection(); // close local contexts, if any
00207       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
00208       connect( myGeomGUI->getApp()->selectionMgr(),
00209                SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00210       break;
00211     }
00212   case 1:
00213     {
00214       GroupPoints->hide();
00215       GroupDimensions->show();
00216       globalSelection(); // close local contexts, if any
00217 
00218       double dx( 0. ), dy( 0. ), dz( 0. );
00219       GroupDimensions->SpinBox_DX->setValue( dx );
00220       GroupDimensions->SpinBox_DY->setValue( dy );
00221       GroupDimensions->SpinBox_DZ->setValue( dz );
00222 
00223       GroupDimensions->CheckButton1->setChecked( false );
00224       break;
00225     }
00226   }
00227 
00228   qApp->processEvents();
00229   updateGeometry();
00230   resize( minimumSizeHint() );
00231   SelectionIntoArgument();
00232 
00233   displayPreview(true);
00234 }
00235 
00236 
00237 //=================================================================================
00238 // function : ClickOnOk()
00239 // purpose  :
00240 //=================================================================================
00241 void BasicGUI_VectorDlg::ClickOnOk()
00242 {
00243   setIsApplyAndClose( true );
00244   if ( ClickOnApply() )
00245     ClickOnCancel();
00246 }
00247 
00248 //=================================================================================
00249 // function : ClickOnApply()
00250 // purpose  :
00251 //=================================================================================
00252 bool BasicGUI_VectorDlg::ClickOnApply()
00253 {
00254   buttonApply()->setFocus();
00255 
00256   if ( !onAccept() )
00257     return false;
00258 
00259   initName();
00260   if ( getConstructorId() != 1 )
00261     ConstructorsClicked( getConstructorId() );
00262   return true;
00263 }
00264 
00265 
00266 //=================================================================================
00267 // function : SelectionIntoArgument()
00268 // purpose  : Called when selection as changed or other case
00269 //=================================================================================
00270 void BasicGUI_VectorDlg::SelectionIntoArgument()
00271 {
00272   myEditCurrentArgument->setText( "" );
00273   
00274   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00275   SALOME_ListIO aSelList;
00276   aSelMgr->selectedObjects(aSelList);
00277 
00278   if (aSelList.Extent() != 1) {
00279     if (myEditCurrentArgument == GroupPoints->LineEdit1)
00280       myPoint1.nullify();
00281     else if (myEditCurrentArgument == GroupPoints->LineEdit2)
00282       myPoint2.nullify();
00283     return;
00284   }
00285 
00286   GEOM::GeomObjPtr aSelectedObject = getSelected( TopAbs_VERTEX );
00287   TopoDS_Shape aShape;
00288   if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
00289     QString aName = GEOMBase::GetName( aSelectedObject.get() );
00290     myEditCurrentArgument->setText(aName);
00291     if (myEditCurrentArgument == GroupPoints->LineEdit1) {
00292       myPoint1 = aSelectedObject;
00293       if (myPoint1 && !myPoint2)
00294         GroupPoints->PushButton2->click();
00295     }
00296     else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
00297       myPoint2 = aSelectedObject;
00298       if (myPoint2 && !myPoint1)
00299         GroupPoints->PushButton1->click();
00300     }
00301   }
00302 
00303   displayPreview(true);
00304 }
00305 
00306 //=================================================================================
00307 // function : SetEditCurrentArgument()
00308 // purpose  :
00309 //=================================================================================
00310 void BasicGUI_VectorDlg::SetEditCurrentArgument()
00311 {
00312   QPushButton* send = (QPushButton*)sender();
00313   if      ( send == GroupPoints->PushButton1 ) {
00314     myEditCurrentArgument = GroupPoints->LineEdit1;
00315     GroupPoints->PushButton2->setDown(false);
00316     GroupPoints->LineEdit1->setEnabled(true);
00317     GroupPoints->LineEdit2->setEnabled(false);
00318   }
00319   else if ( send == GroupPoints->PushButton2 ) {
00320     myEditCurrentArgument = GroupPoints->LineEdit2;
00321     GroupPoints->PushButton1->setDown(false);
00322     GroupPoints->LineEdit1->setEnabled(false);
00323     GroupPoints->LineEdit2->setEnabled(true);
00324   }
00325   myEditCurrentArgument->setFocus();
00326   //  SelectionIntoArgument();
00327   globalSelection(); // close local selection to clear it
00328   localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
00329   send->setDown(true);
00330   displayPreview(true);
00331 }
00332 
00333 
00334 //=================================================================================
00335 // function : ActivateThisDialog()
00336 // purpose  :
00337 //=================================================================================
00338 void BasicGUI_VectorDlg::ActivateThisDialog()
00339 {
00340   GEOMBase_Skeleton::ActivateThisDialog();
00341   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
00342            this, SLOT( SelectionIntoArgument() ) );
00343         
00344   ConstructorsClicked( getConstructorId() );
00345 }
00346 
00347 //=================================================================================
00348 // function : DeactivateActiveDialog()
00349 // purpose  : public slot to deactivate if active
00350 //=================================================================================
00351 void BasicGUI_VectorDlg::DeactivateActiveDialog()
00352 {
00353   GEOMBase_Skeleton::DeactivateActiveDialog();
00354 }
00355 
00356 //=================================================================================
00357 // function : enterEvent()
00358 // purpose  :
00359 //=================================================================================
00360 void BasicGUI_VectorDlg::enterEvent( QEvent* )
00361 {
00362   if ( !mainFrame()->GroupConstructors->isEnabled() )
00363     ActivateThisDialog();
00364 }
00365 
00366 //=================================================================================
00367 // function : ValueChangedInSpinBox()
00368 // purpose  :
00369 //=================================================================================
00370 void BasicGUI_VectorDlg::ValueChangedInSpinBox( double newValue )
00371 {
00372   displayPreview(true);
00373 }
00374 
00375 //=================================================================================
00376 // function : ReverseVector()
00377 // purpose  : 'state' not used here
00378 //=================================================================================
00379 void BasicGUI_VectorDlg::ReverseVector( int state )
00380 {
00381   double dx = -GroupDimensions->SpinBox_DX->value();
00382   double dy = -GroupDimensions->SpinBox_DY->value();
00383   double dz = -GroupDimensions->SpinBox_DZ->value();
00384 
00385   GroupDimensions->SpinBox_DX->setValue( dx );
00386   GroupDimensions->SpinBox_DY->setValue( dy );
00387   GroupDimensions->SpinBox_DZ->setValue( dz );
00388 
00389   displayPreview(true);
00390 }
00391 
00392 //=================================================================================
00393 // function : createOperation
00394 // purpose  :
00395 //=================================================================================
00396 GEOM::GEOM_IOperations_ptr BasicGUI_VectorDlg::createOperation()
00397 {
00398   return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
00399 }
00400 
00401 //=================================================================================
00402 // function : isValid
00403 // purpose  :
00404 //=================================================================================
00405 bool BasicGUI_VectorDlg::isValid( QString& msg )
00406 {
00407   bool ok = false;
00408   if(getConstructorId() == 0) 
00409     ok = myPoint1 && myPoint2;
00410   else if(getConstructorId() == 1)
00411   {
00412     ok = GroupDimensions->SpinBox_DX->isValid( msg, !IsPreview() ) &&
00413          GroupDimensions->SpinBox_DY->isValid( msg, !IsPreview() ) &&
00414          GroupDimensions->SpinBox_DZ->isValid( msg, !IsPreview() );
00415   }
00416   return ok;
00417 }
00418 
00419 //=================================================================================
00420 // function : execute
00421 // purpose  :
00422 //=================================================================================
00423 bool BasicGUI_VectorDlg::execute( ObjectList& objects )
00424 {
00425   bool res = false;
00426 
00427   GEOM::GEOM_Object_var anObj;
00428 
00429   GEOM::GEOM_IBasicOperations_var anOper = GEOM::GEOM_IBasicOperations::_narrow( getOperation() );
00430 
00431   switch ( getConstructorId() ) {
00432   case 0 :
00433     {
00434       anObj = anOper->MakeVectorTwoPnt( myPoint1.get(), myPoint2.get() );
00435       res = true;
00436       break;
00437     }
00438   case 1 :
00439     {
00440       double dx = GroupDimensions->SpinBox_DX->value();
00441       double dy = GroupDimensions->SpinBox_DY->value();
00442       double dz = GroupDimensions->SpinBox_DZ->value();
00443       
00444       QStringList aParameters;
00445       aParameters << GroupDimensions->SpinBox_DX->text();
00446       aParameters << GroupDimensions->SpinBox_DY->text();
00447       aParameters << GroupDimensions->SpinBox_DZ->text();
00448       anObj = anOper->MakeVectorDXDYDZ( dx, dy, dz );
00449 
00450       if ( !anObj->_is_nil() && !IsPreview() )
00451         anObj->SetParameters(aParameters.join(":").toLatin1().constData());
00452       
00453       res = true;
00454       break;
00455     }
00456   }
00457 
00458   if ( !anObj->_is_nil() )
00459     objects.push_back( anObj._retn() );
00460 
00461   return res;
00462 }
00463 
00464 //=================================================================================
00465 // function : addSubshapeToStudy
00466 // purpose  : virtual method to add new SubObjects if local selection
00467 //=================================================================================
00468 void BasicGUI_VectorDlg::addSubshapesToStudy()
00469 {
00470   if ( getConstructorId() == 0 ) {
00471     GEOMBase::PublishSubObject( myPoint1.get() );
00472     GEOMBase::PublishSubObject( myPoint2.get() );
00473   }
00474 }