Back to index

salome-geom  6.5.0
BasicGUI_MarkerDlg.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_MarkerDlg.cxx
00025 // Author : Sergey LITONIN, Open CASCADE S.A.S. (sergey.litonin@opencascade.com)
00026 //
00027 #include "BasicGUI_MarkerDlg.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 <QLabel>
00039 
00040 #include <GEOMImpl_Types.hxx>
00041 
00042 // OCCT Includes
00043 #include <BRep_Tool.hxx>
00044 #include <TopExp.hxx>
00045 #include <TopAbs.hxx>
00046 #include <TopoDS.hxx>
00047 #include <TopoDS_Vertex.hxx>
00048 #include <TopoDS_Face.hxx>
00049 #include <Geom_Plane.hxx>
00050 #include <TopTools_IndexedMapOfShape.hxx>
00051 #include <TColStd_IndexedMapOfInteger.hxx>
00052 #include <gp_Pnt.hxx>
00053 #include <gp_Pln.hxx>
00054 
00055 //=================================================================================
00056 // class    : BasicGUI_MarkerDlg()
00057 // purpose  : Constructor
00058 //=================================================================================
00059 BasicGUI_MarkerDlg::BasicGUI_MarkerDlg( GeometryGUI* theGeometryGUI, QWidget* theParent )
00060   : GEOMBase_Skeleton( theGeometryGUI, theParent, false,
00061                        Qt::WindowTitleHint | Qt::WindowSystemMenuHint )
00062 {
00063   QPixmap iconCS1   ( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_MARKER" ) ) );
00064   QPixmap iconCS2   ( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_MARKER2" ) ) );
00065   QPixmap iconCS3   ( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_MARKER3" ) ) );
00066   QPixmap iconSelect( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
00067 
00068   setWindowTitle( tr( "CAPTION" ) );
00069 
00070   mainFrame()->GroupConstructors->setTitle( tr( "LOCALCS" ) );
00071   mainFrame()->RadioButton1->setIcon( iconCS1 );
00072   mainFrame()->RadioButton2->setIcon( iconCS2 );
00073   mainFrame()->RadioButton3->setIcon( iconCS3 );
00074 
00075   Group1 = new DlgRef_1Sel( centralWidget() );
00076 
00077   Group1->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
00078   Group1->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
00079   Group1->PushButton1->setIcon( iconSelect );
00080   Group1->PushButton1->setDown( true );
00081 
00082   Group2 = new DlgRef_3Sel( centralWidget() );
00083 
00084   Group2->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
00085   Group2->TextLabel1->setText( tr( "GEOM_POINT" ) );
00086   Group2->TextLabel2->setText( tr( "XDIR" ) );
00087   Group2->TextLabel3->setText( tr( "YDIR" ) );
00088   Group2->PushButton1->setIcon( iconSelect );
00089   Group2->PushButton2->setIcon( iconSelect );
00090   Group2->PushButton3->setIcon( iconSelect );
00091   Group2->PushButton1->setDown( true );
00092 
00093   aMainGrp = new QFrame( centralWidget() );
00094   aMainGrp->setFrameStyle( QFrame::NoFrame | QFrame::Plain );
00095   aMainGrp->setContentsMargins( 0, 0, 0, 0 );
00096   QHBoxLayout* aMainGrpLayout = new QHBoxLayout( aMainGrp );
00097   aMainGrpLayout->setMargin( 0 );
00098   
00099   QGroupBox* anOriGrp = new QGroupBox( tr( "ORIGIN" ), aMainGrp );
00100   QVBoxLayout* anOriGrpLayout = new QVBoxLayout( anOriGrp );
00101 
00102   anOriGrpLayout->addWidget( new QLabel( tr( "GEOM_X" ), anOriGrp ) );
00103   myData[ X ] = new SalomeApp_DoubleSpinBox( anOriGrp );
00104   anOriGrpLayout->addWidget( myData[ X ] );
00105   anOriGrpLayout->addWidget( new QLabel( tr( "GEOM_Y" ), anOriGrp ) );
00106   myData[ Y ] = new SalomeApp_DoubleSpinBox( anOriGrp );
00107   anOriGrpLayout->addWidget( myData[ Y ] );
00108   anOriGrpLayout->addWidget( new QLabel( tr( "GEOM_Z" ), anOriGrp ) );
00109   myData[ Z ] = new SalomeApp_DoubleSpinBox( anOriGrp );
00110   anOriGrpLayout->addWidget( myData[ Z ] );
00111 
00112   aMainGrpLayout->addWidget( anOriGrp );
00113 
00114   QGroupBox* aXAxisGrp = new QGroupBox( tr( "XDIR" ), aMainGrp );
00115   QVBoxLayout* aXAxisGrpLayout = new QVBoxLayout( aXAxisGrp );
00116 
00117   aXAxisGrpLayout->addWidget( new QLabel( tr( "DX" ), aXAxisGrp ) );
00118   myData[ DX1 ] = new SalomeApp_DoubleSpinBox( aXAxisGrp );
00119   aXAxisGrpLayout->addWidget( myData[ DX1 ] );
00120   aXAxisGrpLayout->addWidget( new QLabel( tr( "DY" ), aXAxisGrp ) );
00121   myData[ DY1 ] = new SalomeApp_DoubleSpinBox( aXAxisGrp );
00122   aXAxisGrpLayout->addWidget( myData[ DY1 ] );
00123   aXAxisGrpLayout->addWidget( new QLabel( tr( "DZ" ), aXAxisGrp ) );
00124   myData[ DZ1 ] = new SalomeApp_DoubleSpinBox( aXAxisGrp );
00125   aXAxisGrpLayout->addWidget( myData[ DZ1 ] );
00126 
00127   aMainGrpLayout->addWidget( aXAxisGrp );
00128 
00129   QGroupBox* anYAxisGrp = new QGroupBox( tr( "YDIR" ), aMainGrp );
00130   QVBoxLayout* anYAxisGrpLayout = new QVBoxLayout( anYAxisGrp );
00131 
00132   anYAxisGrpLayout->addWidget( new QLabel( tr( "DX" ), anYAxisGrp ) );
00133   myData[ DX2 ] = new SalomeApp_DoubleSpinBox( anYAxisGrp );
00134   anYAxisGrpLayout->addWidget( myData[ DX2 ] );
00135   anYAxisGrpLayout->addWidget( new QLabel( tr( "DY" ), anYAxisGrp ) );
00136   myData[ DY2 ] = new SalomeApp_DoubleSpinBox( anYAxisGrp );
00137   anYAxisGrpLayout->addWidget( myData[ DY2 ] );
00138   anYAxisGrpLayout->addWidget( new QLabel( tr( "DZ" ), anYAxisGrp ) );
00139   myData[ DZ2 ] = new SalomeApp_DoubleSpinBox( anYAxisGrp );
00140   anYAxisGrpLayout->addWidget( myData[ DZ2 ] );
00141 
00142   aMainGrpLayout->addWidget( anYAxisGrp );
00143 
00144   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
00145   layout->setMargin( 0 ); layout->setSpacing( 6 );
00146   layout->addWidget( aMainGrp );
00147   layout->addWidget( Group1 );
00148   layout->addWidget( Group2 );
00149 
00150   setHelpFileName( "create_lcs_page.html" );
00151 
00152   Init();
00153 }
00154 
00155 
00156 //=================================================================================
00157 // function : ~BasicGUI_MarkerDlg()
00158 // purpose  : Destroys the object and frees any allocated resources
00159 //=================================================================================
00160 BasicGUI_MarkerDlg::~BasicGUI_MarkerDlg()
00161 {
00162 }
00163 
00164 
00165 //=================================================================================
00166 // function : Init()
00167 // purpose  :
00168 //=================================================================================
00169 void BasicGUI_MarkerDlg::Init()
00170 {
00171   myShape.nullify();
00172   myPoint.nullify();
00173   myVectorX.nullify();
00174   myVectorY.nullify();
00175   myBlockPreview = false;
00176   myConstructorId = -1;
00177   myEditCurrentArgument = Group1->LineEdit1;
00178   Group1->LineEdit1->setReadOnly( true );
00179   Group2->LineEdit1->setReadOnly( true );
00180   Group2->LineEdit2->setReadOnly( true );
00181   Group2->LineEdit3->setReadOnly( true );
00182   Group2->LineEdit1->setEnabled( true );
00183   Group2->LineEdit2->setEnabled( false );
00184   Group2->LineEdit3->setEnabled( false );
00185 
00186   connect( this,                SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
00187 
00188   connect( Group1->PushButton1, SIGNAL( clicked() ),      this, SLOT( SetEditCurrentArgument() ) );
00189   connect( Group2->PushButton1, SIGNAL( clicked() ),      this, SLOT( SetEditCurrentArgument() ) );
00190   connect( Group2->PushButton2, SIGNAL( clicked() ),      this, SLOT( SetEditCurrentArgument() ) );
00191   connect( Group2->PushButton3, SIGNAL( clicked() ),      this, SLOT( SetEditCurrentArgument() ) );
00192 
00193   connect( myGeomGUI,           SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( onDeactivate() ) );
00194   connect( myGeomGUI,           SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
00195 
00196   connect( buttonOk(),          SIGNAL( clicked() ), this, SLOT( onOk() ) );
00197   connect( buttonApply(),       SIGNAL( clicked() ), this, SLOT( onApply() ) );
00198 
00199   connect( myGeomGUI->getApp()->selectionMgr(),
00200            SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionDone() ) );
00201 
00202   initName( tr( "LCS_NAME" ) );
00203 
00204   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00205   double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
00206 
00207   for ( DataMap::iterator anIter = myData.begin(); anIter != myData.end(); ++anIter ) {
00208     initSpinBox( anIter.value(), COORD_MIN, COORD_MAX, step, "length_precision" );
00209     connect( anIter.value(), SIGNAL( valueChanged( double ) ),
00210              this, SLOT( onValueChanged( double ) ) );
00211   }
00212   
00213   myBlockPreview = true;
00214   for ( DataMap::iterator anIter = myData.begin(); anIter != myData.end(); ++anIter )
00215     anIter.value()->setValue( 0 );
00216   myData[ DX1 ]->setValue( 1 );
00217   myData[ DY2 ]->setValue( 1 );
00218   myBlockPreview = false;
00219 
00220   ConstructorsClicked( 0 );
00221 }
00222 
00223 //=================================================================================
00224 // function : ConstructorsClicked()
00225 // purpose  : Radio button management
00226 //=================================================================================
00227 void BasicGUI_MarkerDlg::ConstructorsClicked( int constructorId )
00228 {
00229   if ( myConstructorId == constructorId && myConstructorId == 0 ) {
00230     globalSelection(); // close local contexts, if any
00231     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
00232     activate( GEOM_MARKER );
00233     return;
00234   }
00235 
00236   myConstructorId = constructorId;
00237 
00238   disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
00239 
00240   switch ( constructorId ) {
00241   case 0:
00242     {
00243       Group1->hide();
00244       Group2->hide();
00245       aMainGrp->show();
00246       globalSelection(); // close local contexts, if any
00247       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
00248       activate( GEOM_MARKER );
00249       break;
00250     }
00251   case 1:
00252     {
00253       aMainGrp->hide();
00254       Group2->hide();
00255       Group1->show();
00256       Group1->PushButton1->setDown( true );
00257       globalSelection( GEOM_ALLGEOM );
00258       myEditCurrentArgument = Group1->LineEdit1;
00259       Group1->LineEdit1->setText( "" );
00260       myShape.nullify();
00261       break;
00262     }
00263   case 2:
00264     {
00265       aMainGrp->hide();
00266       Group1->hide();
00267       Group2->show();
00268       Group2->PushButton1->setDown( true );
00269       Group2->PushButton2->setDown( false );
00270       Group2->PushButton3->setDown( false );
00271       globalSelection(); // close local contexts, if any
00272       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
00273       myEditCurrentArgument = Group2->LineEdit1;
00274       Group2->LineEdit1->setText( "" );
00275       Group2->LineEdit2->setText( "" );
00276       Group2->LineEdit3->setText( "" );
00277       Group2->LineEdit1->setEnabled( true );
00278       Group2->LineEdit2->setEnabled( false );
00279       Group2->LineEdit3->setEnabled( false );
00280       myPoint.nullify();
00281       myVectorX.nullify();
00282       myVectorY.nullify();
00283       break;
00284     }
00285   }
00286 
00287   displayPreview();
00288 
00289   qApp->processEvents();
00290   updateGeometry();
00291   resize( minimumSizeHint() );
00292   
00293   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
00294            this, SLOT( onSelectionDone() ) );
00295   onSelectionDone();
00296 }
00297 
00298 //=================================================================================
00299 // function : onOk()
00300 // purpose  :
00301 //=================================================================================
00302 void BasicGUI_MarkerDlg::onOk()
00303 {
00304   setIsApplyAndClose( true );
00305   if ( onApply() )
00306     ClickOnCancel();
00307 }
00308 
00309 //=================================================================================
00310 // function : onApply()
00311 // purpose  :
00312 //=================================================================================
00313 bool BasicGUI_MarkerDlg::onApply()
00314 {
00315   if ( !onAccept() )
00316     return false;
00317 
00318   initName();
00319   ConstructorsClicked( getConstructorId() );
00320 
00321   return true;
00322 }
00323 
00324 //=================================================================================
00325 // function : onSelectionDone0()
00326 // purpose  : Reaction on selection when first method of creation is current one
00327 //=================================================================================
00328 void BasicGUI_MarkerDlg::onSelectionDone0()
00329 {
00330   GEOM::GeomObjPtr aSelectedObject = getSelected( TopAbs_FACE );
00331   TopoDS_Shape aShape;
00332   if ( aSelectedObject && aSelectedObject->GetType() == GEOM_MARKER && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
00333     // Existing LCS selected
00334     TopoDS_Face aFace = TopoDS::Face( aShape );
00335     Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
00336     
00337     if ( !aPlane.IsNull() ) {
00338       gp_Ax3 anAx3 = aPlane->Pln().Position();
00339       gp_Pnt aLoc = anAx3.Location();
00340       gp_Dir aXDir = anAx3.XDirection();
00341       gp_Dir aYDir = anAx3.YDirection();
00342       
00343       myData[ X ]->setValue( aLoc.X() );
00344       myData[ Y ]->setValue( aLoc.Y() );
00345       myData[ Z ]->setValue( aLoc.Z() );
00346       
00347       myData[ DX1 ]->setValue( aXDir.X() );
00348       myData[ DY1 ]->setValue( aXDir.Y() );
00349       myData[ DZ1 ]->setValue( aXDir.Z() );
00350       
00351       myData[ DX2 ]->setValue( aYDir.X() );
00352       myData[ DY2 ]->setValue( aYDir.Y() );
00353       myData[ DZ2 ]->setValue( aYDir.Z() );
00354     }
00355     displayPreview();
00356     return;
00357   }
00358   aSelectedObject = getSelected( TopAbs_VERTEX );
00359   if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
00360     gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
00361     myData[ X ]->setValue( aPnt.X() );
00362     myData[ Y ]->setValue( aPnt.Y() );
00363     myData[ Z ]->setValue( aPnt.Z() );
00364     displayPreview();
00365     return;
00366   }
00367 }
00368 
00369 
00370 //=================================================================================
00371 // function : onSelectionDone()
00372 // purpose  : Called when selection as changed or other case
00373 //=================================================================================
00374 void BasicGUI_MarkerDlg::onSelectionDone()
00375 {
00376   if ( getConstructorId() == 0 ) {
00377     onSelectionDone0();
00378     return;
00379   }
00380 
00381   TopAbs_ShapeEnum aNeedType;
00382   if ( getConstructorId() == 1 ) // by shape position
00383     aNeedType = TopAbs_SHAPE;
00384   else if ( getConstructorId() == 2 ) // by point and two vectors
00385     aNeedType = myEditCurrentArgument == Group2->LineEdit1 ? TopAbs_VERTEX : TopAbs_EDGE;
00386   
00387   GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
00388   TopoDS_Shape aShape;
00389   if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
00390     QString aName = GEOMBase::GetName( aSelectedObject.get() );
00391     myEditCurrentArgument->setText( aName );
00392     if ( getConstructorId() == 1 ) { // by shape position
00393       myShape = aSelectedObject;
00394     }
00395     else if ( getConstructorId() == 2 ) { // by point and two vectors
00396       if ( myEditCurrentArgument == Group2->LineEdit1 ) {
00397        myPoint = aSelectedObject;
00398        if (myPoint && !myVectorX)
00399          Group2->PushButton2->click();
00400       }
00401       else if (myEditCurrentArgument == Group2->LineEdit2) {
00402        myVectorX = aSelectedObject;
00403        if (myVectorX && !myVectorY)
00404          Group2->PushButton3->click();
00405       }
00406       else if ( myEditCurrentArgument == Group2->LineEdit3 ) {
00407        myVectorY = aSelectedObject;
00408        if (myVectorY && !myPoint)
00409          Group2->PushButton1->click();
00410       }
00411     }
00412   }
00413   else {
00414     if ( getConstructorId() == 1 ) {
00415       myShape.nullify();
00416     }
00417     else if ( getConstructorId() == 2 ) {
00418       if ( myEditCurrentArgument == Group2->LineEdit1 )
00419         myPoint.nullify();
00420       else if ( myEditCurrentArgument == Group2->LineEdit2 )
00421         myVectorX.nullify();
00422       else if ( myEditCurrentArgument == Group2->LineEdit3 )
00423         myVectorY.nullify();
00424     }
00425   }
00426 
00427   displayPreview();
00428 }
00429 
00430 //=================================================================================
00431 // function : SetEditCurrentArgument()
00432 // purpose  :
00433 //=================================================================================
00434 void BasicGUI_MarkerDlg::SetEditCurrentArgument()
00435 {
00436   QPushButton* send = (QPushButton*)sender();
00437   globalSelection(); // close local contexts, if any
00438 
00439   if ( send == Group1->PushButton1 ) {
00440     myEditCurrentArgument = Group1->LineEdit1;
00441     globalSelection( GEOM_ALLGEOM );
00442   }
00443   else if ( send == Group2->PushButton1 ) {
00444     myEditCurrentArgument = Group2->LineEdit1;
00445     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
00446     Group2->PushButton2->setDown( false );
00447     Group2->PushButton3->setDown( false );
00448     Group2->LineEdit1->setEnabled( true );
00449     Group2->LineEdit2->setEnabled( false );
00450     Group2->LineEdit3->setEnabled( false );
00451   }
00452   else if ( send == Group2->PushButton2 ) {
00453     myEditCurrentArgument = Group2->LineEdit2;
00454     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
00455     Group2->PushButton1->setDown( false );
00456     Group2->PushButton3->setDown( false );
00457     Group2->LineEdit1->setEnabled( false );
00458     Group2->LineEdit2->setEnabled( true );
00459     Group2->LineEdit3->setEnabled( false );
00460   }
00461   else if ( send == Group2->PushButton3 ) {
00462     myEditCurrentArgument = Group2->LineEdit3;
00463     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
00464     Group2->PushButton1->setDown( false );
00465     Group2->PushButton2->setDown( false );
00466     Group2->LineEdit1->setEnabled( false );
00467     Group2->LineEdit2->setEnabled( false );
00468     Group2->LineEdit3->setEnabled( true );
00469   }
00470   
00471   myEditCurrentArgument->setFocus();
00472   send->setDown(true);
00473   onSelectionDone();
00474 }
00475 
00476 //=================================================================================
00477 // function : onActivate()
00478 // purpose  :
00479 //=================================================================================
00480 void BasicGUI_MarkerDlg::onActivate()
00481 {
00482   GEOMBase_Skeleton::ActivateThisDialog();
00483   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
00484            this, SLOT( onSelectionDone() ) );
00485 
00486   ConstructorsClicked( getConstructorId() );
00487 }
00488 
00489 //=================================================================================
00490 // function : onDeactivate()
00491 // purpose  : public slot to deactivate if active
00492 //=================================================================================
00493 void BasicGUI_MarkerDlg::onDeactivate()
00494 {
00495   GEOMBase_Skeleton::DeactivateActiveDialog();
00496 }
00497 
00498 //=================================================================================
00499 // function : enterEvent()
00500 // purpose  :
00501 //=================================================================================
00502 void BasicGUI_MarkerDlg::enterEvent( QEvent* )
00503 {
00504   if ( !mainFrame()->GroupConstructors->isEnabled() )
00505     onActivate();
00506 }
00507 
00508 //=================================================================================
00509 // function : createOperation
00510 // purpose  :
00511 //=================================================================================
00512 GEOM::GEOM_IOperations_ptr BasicGUI_MarkerDlg::createOperation()
00513 {
00514   return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
00515 }
00516 
00517 //=================================================================================
00518 // function : isValid
00519 // purpose  :
00520 //=================================================================================
00521 bool BasicGUI_MarkerDlg::isValid( QString& msg )
00522 {
00523   bool ok = false;
00524   switch ( getConstructorId() ) {
00525   case 0: {
00526     gp_Vec v1( myData[ DX1 ]->value(), myData[ DY1 ]->value(), myData[ DZ1 ]->value() ),
00527       v2( myData[ DX2 ]->value(), myData[ DY2 ]->value(), myData[ DZ2 ]->value() );
00528       
00529     // we will got exception if the magnitude of any of the 2 vectors <= gp::Resolution()
00530     // Vectors shouldn't be checked for being orthogonal here!
00531     if ( v1.Magnitude() > gp::Resolution() && v2.Magnitude() > gp::Resolution() ) {
00532       ok = !v1.IsParallel( v2, Precision::Angular() );
00533       if ( !ok )
00534        msg += tr( "VEC_PARALLEL" );
00535     }
00536     for ( DataMap::iterator anIter = myData.begin(); anIter != myData.end() && ok; ++anIter )
00537       ok = anIter.value()->isValid( msg, !IsPreview()) && ok;
00538     break;
00539   }
00540   case 1:
00541     ok = myShape;
00542     break;
00543   case 2:
00544     ok = myPoint && myVectorX && myVectorY;
00545     break;
00546   default:
00547     break;
00548   }
00549   return ok;
00550 }
00551 
00552 //=================================================================================
00553 // function : execute
00554 // purpose  :
00555 //=================================================================================
00556 bool BasicGUI_MarkerDlg::execute( ObjectList& objects )
00557 {
00558   GEOM::GEOM_IBasicOperations_var anOper = GEOM::GEOM_IBasicOperations::_narrow( getOperation() );
00559   GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_nil();
00560   QStringList aParameters;
00561   const int id = getConstructorId();
00562   if (id == 0) {
00563     anObj = anOper->MakeMarker( myData[ X   ]->value(), myData[ Y   ]->value(), 
00564                                 myData[ Z   ]->value(), myData[ DX1 ]->value(),
00565                                 myData[ DY1 ]->value(), myData[ DZ1 ]->value(),
00566                                 myData[ DX2 ]->value(), myData[ DY2 ]->value(),
00567                                 myData[ DZ2 ]->value() );
00568     aParameters<<myData[X]->text();
00569     aParameters<<myData[Y]->text();
00570     aParameters<<myData[Z]->text();
00571     aParameters<<myData[ DX1 ]->text(); 
00572     aParameters<<myData[ DY1 ]->text(); 
00573     aParameters<<myData[ DZ1 ]->text();
00574     aParameters<<myData[ DX2 ]->text();
00575     aParameters<<myData[ DY2 ]->text();
00576     aParameters<<myData[ DZ2 ]->text();
00577   } else if (id == 1) {
00578     anObj = anOper->MakeMarkerFromShape( myShape.get() ); 
00579   } else if (id == 2) {
00580     anObj = anOper->MakeMarkerPntTwoVec( myPoint.get(), myVectorX.get(), myVectorY.get() ); 
00581   }
00582   
00583   if ( !anObj->_is_nil() ) {
00584     if ( !IsPreview() && id == 0)
00585       anObj->SetParameters(aParameters.join(":").toLatin1().constData());
00586     objects.push_back( anObj._retn() );
00587   }
00588 
00589   return true;
00590 }
00591 
00592 //=================================================================================
00593 // function : addSubshapeToStudy
00594 // purpose  : virtual method to add new SubObjects if local selection
00595 //=================================================================================
00596 void BasicGUI_MarkerDlg::addSubshapesToStudy()
00597 {
00598   switch ( getConstructorId() ) {
00599   case 0 :
00600     break;
00601   case 1 :
00602     GEOMBase::PublishSubObject( myShape.get() );
00603     break;
00604   case 2:
00605     GEOMBase::PublishSubObject( myPoint.get() );
00606     GEOMBase::PublishSubObject( myVectorX.get() );
00607     GEOMBase::PublishSubObject( myVectorY.get() );
00608     break;
00609   default:
00610     break;
00611   }
00612 
00613 }
00614 
00615 //=================================================================================
00616 // function : onValueChanged
00617 // purpose  :
00618 //=================================================================================
00619 void BasicGUI_MarkerDlg::onValueChanged( double )
00620 {
00621   displayPreview();
00622 }
00623 
00624 //=================================================================================
00625 // function : displayPreview
00626 // purpose  :
00627 //=================================================================================
00628 void BasicGUI_MarkerDlg::displayPreview ( const bool   activate,
00629                                           const bool   update,
00630                                           const bool   toRemoveFromEngine,
00631                                           const double lineWidth )
00632 {
00633   if ( !myBlockPreview ) {
00634     GEOMBase_Skeleton::displayPreview( true, activate, update, toRemoveFromEngine, lineWidth );
00635     if ( myConstructorId == 0 )
00636       GEOMBase_Skeleton::activate( GEOM_MARKER );
00637   }
00638 }