Back to index

salome-geom  6.5.0
EntityGUI_SketcherDlg.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   : EntityGUI_SketcherDlg.cxx
00025 // Author : Damien COQUERET, Open CASCADE S.A.S.
00026 //
00027 #include "EntityGUI_SketcherDlg.h"
00028 #include "EntityGUI_Widgets.h"
00029 #include <SalomeApp_DoubleSpinBox.h>
00030 
00031 #include <OCCViewer_ViewPort3d.h>
00032 #include <OCCViewer_ViewWindow.h>
00033 #include <OCCViewer_ViewSketcher.h>
00034 
00035 #include <GEOMBase.h>
00036 #include <GeometryGUI.h>
00037 #include <GEOMImpl_Types.hxx>
00038 #include <Geom_Surface.hxx>
00039 #include <Geom_Plane.hxx>
00040 
00041 #include <GeomLib_IsPlanarSurface.hxx>
00042 
00043 #include <SUIT_Desktop.h>
00044 #include <SUIT_Session.h>
00045 #include <SUIT_MessageBox.h>
00046 #include <SUIT_ResourceMgr.h>
00047 #include <SalomeApp_Application.h>
00048 #include <LightApp_Application.h>
00049 #include <LightApp_SelectionMgr.h>
00050 
00051 #include <DlgRef.h>
00052 
00053 #include <QKeyEvent>
00054 
00055 #include <BRep_Tool.hxx>
00056 #include <TopExp.hxx>
00057 #include <TopExp_Explorer.hxx>
00058 #include <TopoDS_Vertex.hxx>
00059 #include <TopoDS.hxx>
00060 #include <BRepBuilderAPI_Transform.hxx>
00061 #include <BRepBuilderAPI_MakeWire.hxx>
00062 #include <BRepBuilderAPI_MakeVertex.hxx>
00063 #include <Sketcher_Profile.hxx>
00064 
00065 #include <SalomeApp_Study.h>
00066 #include <SalomeApp_Tools.h>
00067 
00068 #include <gp_Pln.hxx>
00069 
00070 #include <Basics_Utils.hxx>
00071 
00072 //=================================================================================
00073 // class    : EntityGUI_SketcherDlg()
00074 // purpose  : Constructs a EntityGUI_SketcherDlg which is a child of 'parent', with the
00075 //            name 'name' and widget flags set to 'f'.
00076 //            The dialog will by default be modeless, unless you set 'modal' to
00077 //            TRUE to construct a modal dialog.
00078 //=================================================================================
00079 EntityGUI_SketcherDlg::EntityGUI_SketcherDlg( GeometryGUI* GUI, QWidget* parent,
00080                                               bool modal, Qt::WindowFlags fl,
00081                                               const double lineWidth )
00082   : QDialog( parent, fl ),
00083     myIsAllAdded( false ),
00084     myIsApply( false ),
00085     GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
00086     myGeometryGUI( GUI ),
00087     myLineWidth( lineWidth )
00088 {
00089   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
00090   setModal( modal );
00091   setAttribute( Qt::WA_DeleteOnClose );
00092   
00093   // Disable rectangular selection
00094 //   SUIT_ViewWindow*      theViewWindow  = getDesktop()->activeWindow();
00095 //   ((OCCViewer_ViewWindow*)theViewWindow)->setEnabledDrawMode( false );
00096 //   MESSAGE("((OCCViewer_ViewWindow*)theViewWindow)->isEnabledDrawMode();"<<((OCCViewer_ViewWindow*)theViewWindow)->isEnabledDrawMode())
00097 //   OCCViewer_ViewPort3d* vp             = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
00098 //   vp->setSketchingEnabled( false );
00099 //   MESSAGE("vp->isSketchingEnabled()"<<vp->isSketchingEnabled())
00100 //   ((OCCViewer_ViewWindow*)theViewWindow)->setSketcherStyle(true);
00101 //   OCCViewer_ViewSketcher* aViewSketcher = ((OCCViewer_ViewWindow*)theViewWindow)->getSketcher( OCCViewer_ViewWindow::Rect );
00102 //   aViewSketcher->deactivate()
00103 //   aViewSketcher->setVisible(false);
00104   
00105 //   this->setMouseTracking(false);
00106   
00107   myGeometryGUI->SetActiveDialogBox(this);
00108 
00109   MainWidget = new EntityGUI_Skeleton( this );
00110   QVBoxLayout* topLayout = new QVBoxLayout( this );
00111   topLayout->setMargin( 9 ); topLayout->setSpacing( 6 );
00112 
00113   MainWidget->buttonCancel->setText( tr( "GEOM_BUT_CANCEL" ) );
00114   MainWidget->buttonEnd->setText( tr( "GEOM_BUT_CLOSE" ) );
00115   MainWidget->buttonClose->setText( tr( "GEOM_BUT_CLOSE_SKETCH" ) );
00116   MainWidget->buttonHelp->setText( tr( "GEOM_BUT_HELP" ) );
00117 
00118   QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT"        ) ) );
00119   QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_UNDO"      ) ) );
00120   QPixmap image2( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_REDO"      ) ) );
00121   QPixmap image3( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_LINE_2P"   ) ) );
00122   QPixmap image4( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_ARC"       ) ) );
00123   QPixmap image5 (aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT"        ) ) );
00124   QPixmap image6 (aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_RECTANGLE" ) ) );
00125 
00126   setWindowTitle( tr( "GEOM_SKETCHER_TITLE" ) );
00127 
00128   MainWidget->GroupConstructors->setTitle( tr( "GEOM_SKETCHER_EL" ) );
00129   MainWidget->RadioButton1->setText( "" );
00130   MainWidget->RadioButton1->setIcon( image3 );
00131   MainWidget->RadioButton2->setText( "" );
00132   MainWidget->RadioButton2->setIcon( image4 );
00133   MainWidget->RadioButton3->setText( "" );
00134   MainWidget->RadioButton3->setIcon( image6 );
00135   MainWidget->GroupDest->setTitle( tr( "GEOM_SKETCHER_DEST" ) );
00136   MainWidget->GroupDest1->setTitle( tr( "GEOM_SKETCHER_TYPE" ) );
00137   MainWidget->RB_Dest1->setText( tr( "GEOM_SKETCHER_POINT" ) );
00138   MainWidget->RB_Dest2->setText( tr( "GEOM_SKETCHER_DIR" ) );
00139 
00140   /***************************************************************/
00141 
00142   GroupBox1 = new QGroupBox(tr("GEOM_CS"), this);
00143   QGridLayout* planeLayout = new QGridLayout(GroupBox1);
00144   planeLayout->setSpacing(6);
00145   planeLayout->setMargin(11);
00146 
00147   ComboBox1 = new QComboBox(GroupBox1);
00148   planeLayout->addWidget(ComboBox1,0,0,1,2);
00149 
00150   planeButton = new QPushButton (GroupBox1);
00151   planeButton->setText( tr( "GEOM_SKETCHER_RESTORE" ) );
00152   planeLayout->addWidget(planeButton,0,2);
00153   
00154   selButton = new QPushButton (GroupBox1);
00155   selButton->setIcon(image5);
00156   planeLayout->addWidget(selButton,1,0);
00157   
00158   WPlaneLineEdit = new QLineEdit (GroupBox1);
00159   WPlaneLineEdit->setReadOnly(true);
00160   planeLayout->addWidget(WPlaneLineEdit,1,1,1,2);
00161   
00162   planeLayout->setColumnStretch(1,1);
00163   
00164   topLayout->addWidget(GroupBox1);
00165   topLayout->addWidget( MainWidget );
00166   topLayout->setStretch( 1, 1);
00167 
00168   GroupPt = new EntityGUI_Point( MainWidget->DestCnt );
00169 
00170   GroupPt->GroupPoint->setTitle( tr( "GEOM_SKETCHER_POINT" ) );
00171   GroupPt->RB_Point1->setText( tr( "GEOM_SKETCHER_ABS" ) );
00172   GroupPt->RB_Point2->setText( tr( "GEOM_SKETCHER_REL" ) );
00173   GroupPt->RB_Point3->setText( tr( "GEOM_SKETCHER_SEL" ) );
00174 
00175   GroupPt2 = new EntityGUI_Point( MainWidget->DestCnt );
00176 
00177   GroupPt2->GroupPoint->setTitle( tr( "GEOM_SKETCHER_ADD_PARAMS" ) ); 
00178   GroupPt2->RB_Point1->setText( tr( "GEOM_SKETCHER_NONE" ) );
00179   GroupPt2->RB_Point2->setText( tr( "GEOM_SKETCHER_RADIUS" ) );
00180   GroupPt2->RB_Point3->setText( tr( "GEOM_SKETCHER_CENTER" ) ); 
00181 
00182   GroupD1 = new EntityGUI_Dir1( MainWidget->DestCnt );
00183 
00184   GroupD1->GroupDir1->setTitle( tr( "GEOM_SKETCHER_DIR" ) );
00185   GroupD1->RB_Dir11->setText( tr( "GEOM_SKETCHER_ANGLE" ) );
00186   GroupD1->RB_Dir12->setText( tr( "GEOM_SKETCHER_PER" ) );
00187   GroupD1->RB_Dir13->setText( tr( "GEOM_SKETCHER_TAN" ) );
00188   GroupD1->RB_Dir14->setText( tr( "GEOM_SKETCHER_VXVY" ) );
00189 
00190   GroupD2 = new EntityGUI_Dir2( MainWidget->DestCnt );
00191 
00192   GroupD2->GroupDir2->setTitle( tr( "GEOM_SKETCHER_DIST" ) );
00193   GroupD2->RB_Dir21->setText( tr( "GEOM_SKETCHER_LENGTH" ) );
00194   GroupD2->RB_Dir22->setText( tr( "GEOM_SKETCHER_X" ) );
00195   GroupD2->RB_Dir23->setText( tr( "GEOM_SKETCHER_Y" ) );
00196 
00197   Group1Sel = new EntityGUI_1Sel( MainWidget->SkeletonCnt );
00198   Group1Sel->TextLabel1->setText( tr( "GEOM_SKETCHER_POINT2" ) );
00199   Group1Sel->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
00200   Group1Sel->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
00201   Group1Sel->PushButton1->setIcon( image0 );
00202   Group1Sel->buttonUndo->setIcon( image1 );
00203   Group1Sel->buttonRedo->setIcon( image2 );
00204   Group1Sel->LineEdit1->setReadOnly( true );
00205 
00206   Group2Sel = new EntityGUI_2Sel1Check( MainWidget->SkeletonCnt );
00207   Group2Sel->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
00208   Group2Sel->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
00209   Group2Sel->checkBox->setText( tr( "GEOM_REVERSE" ) );
00210   Group2Sel->PushButton1->setIcon( image0 );
00211   Group2Sel->PushButton2->setIcon( image0 );
00212   Group2Sel->buttonUndo->setIcon( image1 );
00213   Group2Sel->buttonRedo->setIcon( image2 );
00214   Group2Sel->LineEdit1->setReadOnly( true );
00215   Group2Sel->LineEdit2->setReadOnly( true );
00216 
00217   Group1Sel1Spin = new EntityGUI_1Sel1Spin1Check( MainWidget->SkeletonCnt );
00218   Group1Sel1Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
00219   Group1Sel1Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
00220   Group1Sel1Spin->checkBox->setText( tr( "GEOM_REVERSE" ) );
00221   Group1Sel1Spin->PushButton1->setIcon( image0 );
00222   Group1Sel1Spin->buttonUndo->setIcon( image1 );
00223   Group1Sel1Spin->buttonRedo->setIcon( image2 );
00224   Group1Sel1Spin->LineEdit1->setReadOnly( true );
00225 
00226   Group1Spin = new EntityGUI_1Spin( MainWidget->SkeletonCnt );
00227   Group1Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
00228   Group1Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
00229   Group1Spin->buttonUndo->setIcon( image1 );
00230   Group1Spin->buttonRedo->setIcon( image2 );
00231 
00232   Group2Spin = new EntityGUI_2Spin( MainWidget->SkeletonCnt );
00233   Group2Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
00234   Group2Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
00235   Group2Spin->buttonUndo->setIcon( image1 );
00236   Group2Spin->buttonRedo->setIcon( image2 );
00237 
00238   Group3Spin = new EntityGUI_3Spin1Check( MainWidget->SkeletonCnt );
00239   Group3Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
00240   Group3Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
00241   Group3Spin->checkBox->setText( tr( "GEOM_REVERSE" ) );
00242   Group3Spin->buttonUndo->setIcon( image1 );
00243   Group3Spin->buttonRedo->setIcon( image2 );
00244 
00245   Group4Spin = new EntityGUI_4Spin1Check( MainWidget->SkeletonCnt );
00246   Group4Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
00247   Group4Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
00248   Group4Spin->checkBox->setText( tr( "GEOM_REVERSE" ) );
00249   Group4Spin->buttonUndo->setIcon( image1 );
00250   Group4Spin->buttonRedo->setIcon( image2 );
00251   
00252   GroupRect = new DlgRef_4Spin( MainWidget->SkeletonCnt );
00253   GroupRect->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
00254   GroupRect->TextLabel1->setText("X1:");
00255   GroupRect->TextLabel2->setText("Y1:");
00256   GroupRect->TextLabel3->setText("X2:");
00257   GroupRect->TextLabel4->setText("Y2:");
00258 
00259   // Defines a palette for the error message on Group4Spin and Group2Sel 
00260   QPalette palette;
00261   QColor color("red");
00262   palette.setColor(Group4Spin->label->foregroundRole(), color);
00263   Group4Spin->label->setPalette(palette);
00264   palette.setColor(Group2Sel->label->foregroundRole(), color);
00265   Group2Sel->label->setPalette(palette);
00266 
00267   QGridLayout* DestCntLayout = new QGridLayout( MainWidget->DestCnt );
00268   DestCntLayout->setMargin( 0 ); DestCntLayout->setSpacing( 6 );
00269   DestCntLayout->addWidget( GroupPt, 0, 0 );
00270   DestCntLayout->addWidget( GroupPt2, 0, 1 );
00271   DestCntLayout->addWidget( GroupD1, 0, 0 );
00272   DestCntLayout->addWidget( GroupD2, 0, 1 );
00273 
00274   QVBoxLayout* SkeletonCntlayout = new QVBoxLayout( MainWidget->SkeletonCnt );
00275   SkeletonCntlayout->setMargin( 0 ); SkeletonCntlayout->setSpacing( 6 );
00276   SkeletonCntlayout->addWidget( Group1Sel,  0, 0 );
00277   SkeletonCntlayout->addWidget( Group2Sel,  0, 0 );
00278   SkeletonCntlayout->addWidget( Group1Sel1Spin,  0, 0 );
00279   SkeletonCntlayout->addWidget( Group1Spin, 0, 0 );
00280   SkeletonCntlayout->addWidget( Group2Spin, 0, 0 );
00281   SkeletonCntlayout->addWidget( Group3Spin, 0, 0 );
00282   SkeletonCntlayout->addWidget( Group4Spin, 0, 0 );
00283   SkeletonCntlayout->addWidget( GroupRect, 0, 0 );
00284   //SkeletonCntlayout->setStretch( 0, 1);
00285   /***************************************************************/
00286 
00287   QButtonGroup* ButtonGroup = new QButtonGroup( this );
00288   ButtonGroup->addButton( MainWidget->RB_Dest1, 1 );
00289   ButtonGroup->addButton( MainWidget->RB_Dest2, 0 );
00290 
00291   /* signals and slots connections */
00292   connect( MainWidget->buttonEnd,    SIGNAL( clicked() ),              this, SLOT( ClickOnEnd() ) );
00293   connect( MainWidget->buttonClose,  SIGNAL( clicked() ),              this, SLOT( ClickOnEnd() ) );
00294   connect( MainWidget->buttonCancel, SIGNAL( clicked() ),              this, SLOT( ClickOnCancel() ) );
00295   connect( MainWidget->buttonHelp,   SIGNAL( clicked() ),              this, SLOT( ClickOnHelp() ) );
00296 
00297   connect( Group1Sel->buttonApply,   SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
00298   connect( Group1Sel->buttonUndo,    SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
00299   connect( Group1Sel->buttonRedo,    SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) );
00300   connect( Group2Sel->buttonApply,   SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
00301   connect( Group2Sel->buttonUndo,    SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
00302   connect( Group2Sel->buttonRedo,    SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) );
00303   connect( Group1Sel1Spin->buttonApply,SIGNAL( clicked() ),            this, SLOT( ClickOnApply() ) );
00304   connect( Group1Sel1Spin->buttonUndo, SIGNAL( clicked() ),            this, SLOT( ClickOnUndo() ) );
00305   connect( Group1Sel1Spin->buttonRedo, SIGNAL( clicked() ),            this, SLOT( ClickOnRedo() ) );
00306   connect( Group1Spin->buttonApply,  SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
00307   connect( Group1Spin->buttonUndo,   SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
00308   connect( Group1Spin->buttonRedo,   SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) );
00309   connect( Group2Spin->buttonApply,  SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
00310   connect( Group2Spin->buttonUndo,   SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
00311   connect( Group2Spin->buttonRedo,   SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) );
00312   connect( Group3Spin->buttonApply,  SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
00313   connect( Group3Spin->buttonUndo,   SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
00314   connect( Group3Spin->buttonRedo,   SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) ) ;
00315   connect( Group4Spin->buttonApply,  SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
00316   connect( Group4Spin->buttonUndo,   SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
00317   connect( Group4Spin->buttonRedo,   SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) );
00318 
00319   connect( MainWidget->ButtonGroup,  SIGNAL( buttonClicked( int ) ),   this, SLOT( TypeClicked( int ) ) );
00320   connect( ButtonGroup,              SIGNAL( buttonClicked( int ) ),   this, SLOT( DestClicked( int ) ) );
00321   connect( GroupPt->ButtonGroup,     SIGNAL( buttonClicked( int ) ),   this, SLOT( PointClicked( int ) ) );
00322   connect( GroupPt2->ButtonGroup,    SIGNAL( buttonClicked( int ) ),   this, SLOT( Point2Clicked( int ) ) );
00323   connect( GroupD1->ButtonGroup,     SIGNAL( buttonClicked( int ) ),   this, SLOT( Dir1Clicked( int ) ) );
00324   connect( GroupD2->ButtonGroup,     SIGNAL( buttonClicked( int ) ),   this, SLOT( Dir2Clicked( int ) ));
00325 
00326   connect( Group1Sel->LineEdit1,     SIGNAL( returnPressed() ),        this, SLOT( LineEditReturnPressed() ) );
00327   connect( Group1Sel->PushButton1,   SIGNAL( clicked() ),              this, SLOT( SetEditCurrentArgument() ) );
00328 
00329   connect( Group2Sel->LineEdit1,     SIGNAL( returnPressed() ),        this, SLOT( LineEditReturnPressed() ) );
00330   connect( Group2Sel->LineEdit2,     SIGNAL( returnPressed() ),        this, SLOT( LineEditReturnPressed() ) );
00331   connect( Group2Sel->PushButton1,   SIGNAL( clicked() ),              this, SLOT( SetEditCurrentArgument() ) );
00332   connect( Group2Sel->PushButton2,   SIGNAL( clicked() ),              this, SLOT( SetEditCurrentArgument() ) );
00333 
00334   connect( Group1Sel1Spin->LineEdit1,SIGNAL( returnPressed() ),        this, SLOT( LineEditReturnPressed() ) );
00335   connect( Group1Sel1Spin->PushButton1,SIGNAL( clicked() ),            this, SLOT( SetEditCurrentArgument() ) );
00336   connect( Group1Sel1Spin->SpinBox_DX,SIGNAL( valueChanged( double ) ),this, SLOT( ValueChangedInSpinBox( double ) ) );
00337 
00338   connect( Group1Spin->SpinBox_DX,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00339   connect( Group2Spin->SpinBox_DX,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00340   connect( Group2Spin->SpinBox_DY,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00341   connect( Group3Spin->SpinBox_DX,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00342   connect( Group3Spin->SpinBox_DY,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00343   connect( Group3Spin->SpinBox_DZ,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00344   connect( Group4Spin->SpinBox_DX,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00345   connect( Group4Spin->SpinBox_DY,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00346   connect( Group4Spin->SpinBox_DZ,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00347   connect( Group4Spin->SpinBox_DS,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00348   connect( GroupRect->SpinBox_DX1,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00349   connect( GroupRect->SpinBox_DX2,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00350   connect( GroupRect->SpinBox_DY1,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00351   connect( GroupRect->SpinBox_DY2,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00352 
00353   connect( Group3Spin->checkBox,     SIGNAL( stateChanged( int ) ),    this, SLOT( CheckBoxClicked( int ) ) );
00354   connect( Group4Spin->checkBox,     SIGNAL( stateChanged( int ) ),    this, SLOT( CheckBoxClicked( int ) ) );
00355   connect( Group2Sel->checkBox,      SIGNAL( stateChanged( int ) ),    this, SLOT( CheckBoxClicked( int ) ) );
00356   connect( Group1Sel1Spin->checkBox, SIGNAL( stateChanged( int ) ),    this, SLOT( CheckBoxClicked( int ) ) );
00357 
00358   connect( ComboBox1,                SIGNAL( activated( int ) ),       this, SLOT( ActivateLocalCS() ) );
00359   connect( planeButton,              SIGNAL( clicked() ),              this, SLOT( ActivateLocalCS() ) );
00360   connect( selButton,                SIGNAL( clicked() ),              this, SLOT( SetEditCurrentArgument() ) );
00361 
00362   connect( myGeometryGUI,            SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
00363 
00364   connect( myGeometryGUI,            SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
00365   connect( myGeometryGUI,            SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
00366   
00367   // install event filter on spin-boxes to provide Apply action on Return pressed
00368   Group1Spin->SpinBox_DX->installEventFilter(this);
00369   Group1Sel1Spin->SpinBox_DX->installEventFilter(this);
00370   Group2Spin->SpinBox_DX->installEventFilter(this);
00371   Group2Spin->SpinBox_DY->installEventFilter(this);
00372   Group3Spin->SpinBox_DX->installEventFilter(this);
00373   Group3Spin->SpinBox_DY->installEventFilter(this);
00374   Group3Spin->SpinBox_DZ->installEventFilter(this);
00375   Group4Spin->SpinBox_DX->installEventFilter(this);
00376   Group4Spin->SpinBox_DY->installEventFilter(this);
00377   Group4Spin->SpinBox_DZ->installEventFilter(this);
00378   Group4Spin->SpinBox_DS->installEventFilter(this);
00379 
00380   Init();
00381 }
00382 
00383 
00384 //=================================================================================
00385 // function : ~EntityGUI_SketcherDlg()
00386 // purpose  : Destroys the object and frees any allocated resources
00387 //=================================================================================
00388 EntityGUI_SketcherDlg::~EntityGUI_SketcherDlg()
00389 {
00390 //   SUIT_ViewWindow*      theViewWindow  = getDesktop()->activeWindow();
00391   
00392   myGeometryGUI->SetActiveDialogBox( 0 );
00393 //   ((OCCViewer_ViewWindow*)theViewWindow)->setSketcherStyle(false);
00394 }
00395 
00396 
00397 //=================================================================================
00398 // function : eventFilter()
00399 // purpose  : event filter for spin-boxes to provide Apply action on Return pressed
00400 //=================================================================================
00401 bool EntityGUI_SketcherDlg::eventFilter (QObject* object, QEvent* event)
00402 {
00403   if (event->type() == QEvent::KeyPress) {
00404     QKeyEvent* ke = (QKeyEvent*)event;
00405     if ( ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter ) {
00406       if (object == Group1Spin->SpinBox_DX) {
00407         Group1Spin->buttonApply->click();
00408         return true;
00409       } else if (object == Group1Sel1Spin->SpinBox_DX) {
00410         Group1Sel1Spin->buttonApply->click();
00411         return true;
00412       } else if (object == Group2Spin->SpinBox_DX ||
00413                  object == Group2Spin->SpinBox_DY) {
00414         Group2Spin->buttonApply->click();
00415         return true;
00416       } else if (object == Group3Spin->SpinBox_DX ||
00417                  object == Group3Spin->SpinBox_DY ||
00418                  object == Group3Spin->SpinBox_DZ) {
00419         Group3Spin->buttonApply->click();
00420         return true;
00421       } else if (object == Group4Spin->SpinBox_DX ||
00422                  object == Group4Spin->SpinBox_DY ||
00423                  object == Group4Spin->SpinBox_DZ ||
00424                  object == Group4Spin->SpinBox_DS) {
00425         Group4Spin->buttonApply->click();
00426         return true;
00427       }
00428     }
00429   }
00430 
00431   // Fix of the NPAL16010 bug is removed, because it's not actual with the Qt-4.x
00432 
00433   return QDialog::eventFilter(object, event);
00434 }
00435 
00436 
00437 //=================================================================================
00438 // function : Init()
00439 // purpose  :
00440 //=================================================================================
00441 void EntityGUI_SketcherDlg::Init()
00442 {
00443   /* init variables */
00444   autoApply = false;
00445   
00446   myEditCurrentArgument = WPlaneLineEdit; // Initiate the parameters selection with the first WPlaneLineEdit
00447   
00448   myCommand.append( "Sketcher" );
00449   myUndoCommand.append( "Sketcher" );
00450 
00451   mySketchState = FIRST_POINT;
00452   globalSelection( GEOM_FACE );
00453 
00454   myCheckFlag = 0;
00455 
00456   myLastX1 = 0.0;
00457   myLastY1 = 0.0;
00458   myLastX2 = 0.0;
00459   myLastY2 = 0.0;
00460 
00461   myHelpFileName = "create_sketcher_page.html";
00462   
00463   GEOM::GEOM_IBasicOperations_var aBasicOp = getGeomEngine()->GetIBasicOperations( getStudyId() );
00464   myGlobalCS = aBasicOp->MakeMarker( 0,0,0,
00465                                      1,0,0,
00466                                      0,1,0 ); 
00467   myWPlane = myGlobalCS;
00468   myLCSList.push_back( WPlaneToLCS(myGlobalCS) );
00469 
00470   /* Get setting of step value from file configuration */
00471   double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
00472 
00473   /* min, max, step and decimals for spin boxes */
00474   initSpinBox( Group1Sel1Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
00475   initSpinBox( Group1Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
00476   initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
00477   initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
00478   initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
00479   initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
00480   initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
00481   initSpinBox( Group4Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
00482   // san: Note specific step values below!
00483   initSpinBox( Group4Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
00484   initSpinBox( Group4Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
00485   initSpinBox( Group4Spin->SpinBox_DS, COORD_MIN, COORD_MAX, 5., "length_precision" );
00486   
00487   initSpinBox( GroupRect->SpinBox_DX1, COORD_MIN, COORD_MAX, step, "length_precision" ); 
00488   initSpinBox( GroupRect->SpinBox_DY1, COORD_MIN, COORD_MAX, step, "length_precision" );
00489   initSpinBox( GroupRect->SpinBox_DX2, COORD_MIN, COORD_MAX, step, "length_precision" );
00490   initSpinBox( GroupRect->SpinBox_DY2, COORD_MIN, COORD_MAX, step, "length_precision" );
00491     
00492   /* displays Dialog */
00493 
00494 //   MainWidget->RadioButton1->setEnabled( false );
00495 //   MainWidget->RadioButton2->setEnabled( false );
00496 //   MainWidget->RadioButton3->setEnabled( true );
00497 //   MainWidget->GroupDest1->setEnabled( false );
00498   setEnabledUndo( false );
00499   setEnabledRedo( false );
00500 
00501   MainWidget->RadioButton1->setChecked( true );
00502 
00503   FindLocalCS();
00504   TypeClicked( 0 );
00505   // If a face has already been selected use it. Placed after FindLocalCS to avoid clearing the combobox
00506   // that should be filled with the possibly selected face
00507   
00508   OnFirstPoint();
00509   
00510   SelectionIntoArgument();     
00511   
00512   resize(100,100);
00513   
00514   setPrefix(tr("GEOM_SKETCH"));
00515 
00516   ActivateLocalCS();
00517   
00518   setIsWaitCursorEnabled( false );
00519   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
00520 }
00521 
00522 
00523 //=================================================================================
00524 // function : InitClick()
00525 // purpose  :
00526 //=================================================================================
00527 void EntityGUI_SketcherDlg::InitClick()
00528 {
00529   MESSAGE("EntityGUI_SketcherDlg::InitClick()")
00530   disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
00531   myCheckFlag = 0;
00532 
00533   Group1Sel->hide();
00534   Group2Sel->hide();
00535   Group1Sel1Spin->hide();
00536   Group1Spin->hide();
00537   Group2Spin->hide();
00538   Group3Spin->hide();
00539   Group4Spin->hide();
00540   GroupRect->hide();
00541   globalSelection(); // close local selection to clear it
00542   localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
00543 }
00544 
00545 
00546 //=================================================================================
00547 // function : TypeClicked()
00548 // purpose  : Radio button management
00549 //=================================================================================
00550 void EntityGUI_SketcherDlg::TypeClicked( int constructorId )
00551 {
00552   myConstructorId = constructorId;
00553   MainWidget->buttonEnd->setText(tr("GEOM_BUT_CLOSE"));
00554   MainWidget->buttonClose->setEnabled(true);
00555   
00556   if ( myConstructorId == 0 ) {    // SEGMENT
00557     GroupPt2->RB_Point1->setChecked( true );
00558     GroupPt ->setEnabled( true );
00559     GroupPt2->setEnabled( false );
00560     GroupD1->setEnabled( true );
00561     GroupD2->setEnabled( true );
00562     MainWidget->RB_Dest1->setEnabled( true );
00563     MainWidget->RB_Dest1->setChecked( true );
00564     
00565     MainWidget->GroupDest ->setEnabled( true );
00566     MainWidget->GroupDest1->setEnabled( true );
00567     MainWidget->GroupDest ->show();
00568     MainWidget->GroupDest1->show();
00569     DestClicked( 1 );
00570     if (mySketchState == FIRST_POINT)
00571     {
00572       OnFirstPoint();
00573     }
00574   }
00575   else if (  myConstructorId == 1 ) { // ARC
00576     GroupPt ->setEnabled( true );
00577     GroupPt2->setEnabled( true );
00578     GroupD2->RB_Dir21->setChecked( true );
00579     GroupD1->setEnabled( true );
00580     GroupD2->setEnabled( false );
00581     MainWidget->RB_Dest1->setEnabled( true ); 
00582     MainWidget->RB_Dest1->setChecked( true );
00583     
00584     MainWidget->GroupDest ->setEnabled( true );
00585     MainWidget->GroupDest1->setEnabled( true );
00586     MainWidget->GroupDest ->show();
00587     MainWidget->GroupDest1->show();
00588     DestClicked( 1 );
00589     if (mySketchState == FIRST_POINT)
00590     {
00591       OnFirstPoint();
00592     }
00593   }
00594   else if (  myConstructorId == 2 ) { // RECTANGLE
00595     GroupPt ->setEnabled( false );
00596     GroupPt2->setEnabled( false );
00597     GroupD1 ->setEnabled( false );
00598     GroupD2 ->setEnabled( false );
00599     MainWidget->GroupDest ->setEnabled( false );
00600     MainWidget->GroupDest1->setEnabled( false );
00601 
00602     GroupPt ->hide();
00603     GroupPt2->hide();
00604     GroupD1 ->hide();
00605     GroupD2 ->hide();
00606     MainWidget->GroupDest ->hide();
00607     MainWidget->GroupDest1->hide();
00608     
00609     MainWidget->buttonEnd->setText(tr("Apply and Close"));
00610     MainWidget->buttonClose->setEnabled(false);
00611     
00612     GroupRect->setEnabled( true );
00613     MainWidget->RadioButton1->setEnabled( true );
00614     MainWidget->RadioButton2->setEnabled( true );
00615     
00616     RectClicked();
00617   }
00618 }
00619 
00620 //=================================================================================
00621 // function : RectClicked()
00622 // purpose  : Radio button management
00623 //=================================================================================
00624 void EntityGUI_SketcherDlg::RectClicked()
00625 {
00626   InitClick();
00627   
00628   // Connect the selction manager (disconnected in InitClick())
00629   connect( myGeometryGUI->getApp()->selectionMgr(),
00630        SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00631   
00632   GroupRect->show();
00633   
00634   myX1=0;
00635   myX2=10;
00636   myY1=0;
00637   myY2=10;
00638 
00639   GroupRect->SpinBox_DX1->setValue(myX1); 
00640   GroupRect->SpinBox_DY1->setValue(myY1);
00641   GroupRect->SpinBox_DX2->setValue(myX2);
00642   GroupRect->SpinBox_DY2->setValue(myY2);
00643   
00644   resize( minimumSizeHint() );
00645   
00646   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
00647 }
00648 
00649 
00650 //=================================================================================
00651 // function : DestClicked()
00652 // purpose  : Radio button management
00653 //=================================================================================
00654 void EntityGUI_SketcherDlg::DestClicked( int constructorId )
00655 {
00656   GroupPt->hide();
00657   GroupPt2->hide();
00658   GroupD1->hide();
00659   GroupD2->hide();
00660 
00661   if ( constructorId == 1 ) {
00662     // Point
00663     GroupPt->RB_Point1->setChecked( true );
00664     GroupPt->show();
00665     GroupPt2->show();
00666     Group3Spin->checkBox->show();
00667     Group4Spin->checkBox->show();
00668     PointClicked( 1 );  // XY
00669   }
00670   else if (  constructorId == 0 ) {
00671     // Direction
00672     GroupD1->RB_Dir11->setChecked( true );
00673     GroupD1->show();
00674     GroupD2->show();
00675     Group3Spin->checkBox->hide();
00676     Group4Spin->checkBox->hide();
00677     Dir1Clicked( 2 );  // Angle
00678   }
00679   resize( minimumSizeHint() );
00680 }
00681 
00682 //=================================================================================
00683 // function : PointClicked()
00684 // purpose  : Radio button management
00685 //=================================================================================
00686 void EntityGUI_SketcherDlg::PointClicked( int constructorId )
00687 {
00688   MESSAGE("PointClicked")
00689   myConstructorPntId = constructorId;  
00690   GroupPt->RB_Point3->setEnabled( true );
00691   int buttonId = GroupPt2->ButtonGroup->checkedId();
00692   if (buttonId >= 0){           // = If a button is checked
00693     Point2Clicked(buttonId);
00694   }
00695   else{ 
00696     GroupPt2->RB_Point1->setChecked( true );
00697     Point2Clicked( 1 ); 
00698   }
00699 }
00700 
00701 //=================================================================================
00702 // function : Point2Clicked()
00703 // purpose  : Radio button management
00704 //=================================================================================
00705 void EntityGUI_SketcherDlg::Point2Clicked( int constructorId )
00706 {
00707   MESSAGE("Point2Clicked")
00708   InitClick();
00709 
00710   // Get setting of step value from file configuration
00711   double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
00712 
00713   if ( myConstructorPntId == 1 ) {  // XY
00714     if ( constructorId == 1 ){      // No additional parameter
00715       mySketchType = PT_ABS;
00716       initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
00717       initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
00718       Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X2" ) );
00719       Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y2" ) );
00720       myX = 0.0;
00721       Group2Spin->SpinBox_DX->setValue( myX );
00722       myY = 0.0;
00723       Group2Spin->SpinBox_DY->setValue( myY );
00724       Group2Spin->show();
00725       Group2Spin->buttonApply->setFocus();
00726 
00727       GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
00728     }
00729     else if ( constructorId == 0 ){   // Point + radius
00730       mySketchType = PT_ABS_RADIUS;
00731       initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" ); 
00732       initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
00733       initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step/10.0, "length_precision" );
00734       Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X2" ) );
00735       Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y2" ) );
00736       Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_RADIUS2" ) ); 
00737       myX = 0.0;
00738       Group3Spin->SpinBox_DX->setValue( myX );
00739       myY = 0.0;
00740       Group3Spin->SpinBox_DY->setValue( myY );
00741       myRadius=0.0;
00742       Group3Spin->SpinBox_DZ->setValue( myRadius ); 
00743       Group3Spin->show();
00744       Group3Spin->buttonApply->setFocus();
00745 
00746       GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
00747     }
00748     else if ( constructorId == 2 ){   // Point + center
00749       mySketchType = PT_ABS_CENTER;
00750       initSpinBox( Group4Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" ); 
00751       initSpinBox( Group4Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
00752       initSpinBox( Group4Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
00753       initSpinBox( Group4Spin->SpinBox_DS, COORD_MIN, COORD_MAX, step, "length_precision" );
00754       Group4Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_X2" ) );
00755       Group4Spin->TextLabel4->setText( tr( "GEOM_SKETCHER_Y2" ) );
00756       Group4Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_CENTER_X" ) );
00757       Group4Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_CENTER_Y" ) ); 
00758       myXc = 0.0;
00759       Group4Spin->SpinBox_DX->setValue( myXc );
00760       myYc = 0.0;
00761       Group4Spin->SpinBox_DY->setValue( myYc );
00762       myX = 0.0;
00763       Group4Spin->SpinBox_DZ->setValue( myX ); 
00764       myY = 0.0;
00765       Group4Spin->SpinBox_DS->setValue( myY );
00766       Group4Spin->show();
00767       Group4Spin->buttonApply->setFocus();
00768 
00769       GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
00770     }
00771 
00772   }
00773   else if ( myConstructorPntId == 0 ) {  // DXDY
00774     if ( constructorId == 1 ){    // No additional parameter
00775       mySketchType = PT_RELATIVE;
00776       initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
00777       initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
00778       Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_DX2" ) );
00779       Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_DY2" ) );
00780       myDX = 0.0;
00781       Group2Spin->SpinBox_DX->setValue( myDX );
00782       myDY = 0.0;
00783       Group2Spin->SpinBox_DY->setValue( myDY );
00784       Group2Spin->show();
00785       Group2Spin->buttonApply->setFocus();
00786 
00787       GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
00788     }
00789     else if ( constructorId == 0 ){   // Point + radius 
00790       mySketchType = PT_REL_RADIUS;
00791       initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" ); 
00792       initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
00793       initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step/10.0, "length_precision" );
00794       Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_DX2" ) );
00795       Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_DY2" ) );
00796       Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_RADIUS2" ) ); 
00797       myDX = 10.0;
00798       Group3Spin->SpinBox_DX->setValue( myDX );
00799       myDY = 0.0;
00800       Group3Spin->SpinBox_DY->setValue( myDY );
00801       myRadius=5.0;
00802       Group3Spin->SpinBox_DZ->setValue( myRadius );
00803       Group3Spin->show();
00804       Group3Spin->buttonApply->setFocus();
00805 
00806       GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
00807     }
00808     else if ( constructorId == 2 ){   // Point + center
00809       mySketchType = PT_REL_CENTER;
00810       initSpinBox( Group4Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" ); 
00811       initSpinBox( Group4Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
00812       initSpinBox( Group4Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
00813       initSpinBox( Group4Spin->SpinBox_DS, COORD_MIN, COORD_MAX, step, "length_precision" );
00814       Group4Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_DX2" ) );
00815       Group4Spin->TextLabel4->setText( tr( "GEOM_SKETCHER_DY2" ) );
00816       Group4Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_CENTER_DX" ) );
00817       Group4Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_CENTER_DY" ) ); 
00818       myDXc = 0.0;
00819       Group4Spin->SpinBox_DX->setValue( myDXc );
00820       myDYc = 0.0;
00821       Group4Spin->SpinBox_DY->setValue( myDYc );
00822       myDX = 0.0;
00823       Group4Spin->SpinBox_DZ->setValue( myDX ); 
00824       myDY = 0.0;
00825       Group4Spin->SpinBox_DS->setValue( myDY );
00826       Group4Spin->show();
00827       Group4Spin->buttonApply->setFocus();
00828 
00829       GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
00830     }
00831 
00832   }
00833   else if ( myConstructorPntId == 2 ) {  // Selection
00834     if ( constructorId == 1 ){    // No additional parameter
00835       mySketchType = PT_SEL;
00836       myEditCurrentArgument = Group1Sel->LineEdit1;
00837       Group1Sel->TextLabel1->setText( tr( "GEOM_SKETCHER_END_POINT2" ) ); 
00838       Group1Sel->show();
00839       Group1Sel->buttonApply->setFocus();
00840       SelectionIntoArgument();
00841     }
00842     else if ( constructorId == 0 ){   // Point + radius 
00843       mySketchType = PT_SEL_RADIUS;
00844       myEditCurrentArgument = Group1Sel1Spin->LineEdit1;
00845       initSpinBox( Group1Sel1Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step/10.0, "length_precision" );
00846       Group1Sel1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_END_POINT2" ) ); 
00847       Group1Sel1Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_RADIUS2" ) ); 
00848       myRadius=0.0;
00849       Group1Sel1Spin->SpinBox_DX->setValue( myRadius );
00850 
00851       Group1Sel1Spin->show();
00852       Group1Sel1Spin->buttonApply->setFocus();
00853       SelectionIntoArgument();
00854     }
00855     else if ( constructorId == 2 ){   // Point + center 
00856       mySketchType = PT_SEL_CENTER;
00857       myEditCurrentArgument = Group2Sel->LineEdit1;
00858       Group2Sel->TextLabel2->setText( tr( "GEOM_SKETCHER_END_POINT2" ) );  
00859       Group2Sel->TextLabel1->setText( tr( "GEOM_SKETCHER_CENTER2" ) );
00860       Group2Sel->LineEdit1->setEnabled(true);
00861       Group2Sel->PushButton1->setDown(true);
00862       Group2Sel->LineEdit2->setEnabled(false);
00863       Group2Sel->PushButton2->setDown(false);
00864       Group2Sel->show();
00865       Group2Sel->buttonApply->setFocus();
00866       SelectionIntoArgument();
00867     }
00868 
00869   }
00870   resize( minimumSizeHint() );
00871   connect( myGeometryGUI->getApp()->selectionMgr(),
00872       SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00873   
00874 }
00875 
00876 
00877 //=================================================================================
00878 // function : Dir1Clicked()
00879 // purpose  : Radio button management
00880 //=================================================================================
00881 void EntityGUI_SketcherDlg::Dir1Clicked( int constructorId )
00882 {
00883   myConstructorDirId = constructorId;
00884   int dirButtonId = GroupD2->ButtonGroup->checkedId();
00885   if (dirButtonId >= 0){           // = If a button is checked
00886     Dir2Clicked(dirButtonId);
00887   }
00888   else{ 
00889     GroupD2->RB_Dir21->setChecked( true );
00890     Dir2Clicked( 2 ); 
00891   }
00892 }
00893 
00894 
00895 //=================================================================================
00896 // function : Dir2Clicked()
00897 // purpose  : Radio button management
00898 //=================================================================================
00899 void EntityGUI_SketcherDlg::Dir2Clicked( int constructorId )
00900 {
00901   InitClick();
00902   myAngle = 0.0;
00903 
00904   // Get setting of step value from file configuration
00905   double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
00906 
00907   if ( myConstructorId == 0 ) {  // SEGMENT
00908     myX = 0.0;
00909     myY = 0.0;
00910     myLength = 100.0;
00911     if ( myConstructorDirId == 2 ) {  // Angle
00912       initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 5., "length_precision" );
00913       Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
00914       Group2Spin->SpinBox_DX->setValue( myAngle );
00915       Group2Spin->buttonApply->setFocus();
00916       Group2Spin->show();
00917 
00918       if ( constructorId == 2 ) {  // Length
00919         mySketchType = DIR_ANGLE_LENGTH;
00920         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
00921         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
00922         Group2Spin->SpinBox_DY->setValue( myLength );
00923       }
00924       else if ( constructorId == 0 ) {  // X
00925         mySketchType = DIR_ANGLE_X;
00926         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "angle_precision" );
00927         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_X3" ) );
00928         Group2Spin->SpinBox_DY->setValue( myX );
00929       }
00930       else if ( constructorId == 1 ) {  // Y
00931         mySketchType = DIR_ANGLE_Y;
00932         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "angle_precision" );        
00933         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y3" ) );
00934         Group2Spin->SpinBox_DY->setValue( myY );
00935       }
00936     }
00937     else if ( myConstructorDirId == 0 ) {  // Perpendicular
00938       Group1Spin->show();
00939       Group1Spin->buttonApply->setFocus();
00940 
00941       if ( constructorId == 2 ) {  // Length
00942         mySketchType = DIR_PER_LENGTH;
00943         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
00944         Group1Spin->SpinBox_DX->setValue( myLength );
00945       }
00946       else if ( constructorId == 0 ) {  // X
00947         mySketchType = DIR_PER_X;
00948         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X3" ) );
00949         Group1Spin->SpinBox_DX->setValue( myX );
00950       }
00951       else if ( constructorId == 1 ) {  // Y
00952         mySketchType = DIR_PER_Y;
00953         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_Y3" ) );
00954         Group1Spin->SpinBox_DX->setValue( myY );
00955       }
00956     }
00957     else if ( myConstructorDirId == 1 ) {  // Tangent
00958       Group1Spin->show();
00959       Group1Spin->buttonApply->setFocus();
00960 
00961       if ( constructorId == 2 ) {  // Length
00962         mySketchType = DIR_TAN_LENGTH;
00963         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
00964         Group1Spin->SpinBox_DX->setValue( myLength );
00965       }
00966       else if ( constructorId == 0 ) {  // X
00967         mySketchType = DIR_TAN_X;
00968         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X3" ) );
00969         Group1Spin->SpinBox_DX->setValue( myX );
00970       }
00971       else if ( constructorId == 1 ) {  // Y
00972         mySketchType = DIR_TAN_Y;
00973         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_Y3" ) );
00974         Group1Spin->SpinBox_DX->setValue( myY );
00975       }
00976     }
00977     else if ( myConstructorDirId == 3 ) {  // DXDY
00978       initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
00979       initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
00980       initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
00981       Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_VX2" ) );
00982       Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_VY2" ) );
00983       myDX = 0.0;
00984       Group3Spin->SpinBox_DX->setValue( myDX );
00985       myDY = 0.0;
00986       Group3Spin->SpinBox_DY->setValue( myDY );
00987       Group3Spin->show();
00988       Group3Spin->buttonApply->setFocus();
00989 
00990       if ( constructorId == 2 ) {  // Length
00991         mySketchType = DIR_DXDY_LENGTH;
00992         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
00993         Group3Spin->SpinBox_DZ->setValue( myLength );
00994       }
00995       else if ( constructorId == 0 ) { // X
00996         mySketchType = DIR_DXDY_X;
00997         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_X3" ) );
00998         Group3Spin->SpinBox_DZ->setValue( myX );
00999       }
01000       else if ( constructorId == 1 ) {  // Y
01001         mySketchType = DIR_DXDY_Y;
01002         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_Y3" ) );
01003         Group3Spin->SpinBox_DZ->setValue( myY );
01004       }
01005     }
01006   }
01007   else if ( myConstructorId == 1 ) {  // ARC
01008     if ( myConstructorDirId == 2 ) {  // Angle
01009       if ( constructorId == 2 ) {  // Length
01010         mySketchType = DIR_ANGLE_LENGTH;
01011         initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 5., "angle_precision" );
01012         initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
01013         initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, 5., "angle_precision" );
01014         Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
01015         Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
01016         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_ANGLE2" ));
01017         Group3Spin->SpinBox_DX->setValue( myAngle );
01018         myRadius = 100.0;
01019         Group3Spin->SpinBox_DY->setValue( myRadius );
01020         myLength = 30.0;
01021         Group3Spin->SpinBox_DZ->setValue( myLength );
01022         Group3Spin->show();
01023         Group3Spin->buttonApply->setFocus();
01024       }
01025     }
01026     else if ( myConstructorDirId == 0 ) {  // Perpendicular
01027       if ( constructorId == 2 ) {  // Length
01028         mySketchType = DIR_PER_LENGTH;
01029         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
01030         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 5., "angle_precision" );
01031         Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
01032         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
01033         myRadius = 100.0;
01034         Group2Spin->SpinBox_DX->setValue( myRadius );
01035         myLength = 30.0;
01036         Group2Spin->SpinBox_DY->setValue( myLength );
01037         Group2Spin->show();
01038         Group2Spin->buttonApply->setFocus();
01039       }
01040     }
01041     else if ( myConstructorDirId == 1 ) {  // Tangent
01042       if ( constructorId == 2 ) {  // Length
01043         mySketchType = DIR_TAN_LENGTH;
01044         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
01045         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 5., "angle_precision" );
01046         Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
01047         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
01048         myRadius = 100.0;
01049         Group2Spin->SpinBox_DX->setValue( myRadius );
01050         myLength = 30.0;
01051         Group2Spin->SpinBox_DY->setValue( myLength );
01052         Group2Spin->show();
01053         Group2Spin->buttonApply->setFocus();
01054       }
01055     }
01056     else if ( myConstructorDirId == 3 ) {  // DXDY
01057       if ( constructorId == 2 ) {  // Length
01058         mySketchType = DIR_DXDY_LENGTH;
01059         Group4Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_VX2" ) );
01060         Group4Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_VY2" ) );
01061         Group4Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
01062         Group4Spin->TextLabel4->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
01063        initSpinBox( Group4Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
01064        initSpinBox( Group4Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
01065        initSpinBox( Group4Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
01066        initSpinBox( Group4Spin->SpinBox_DS, COORD_MIN, COORD_MAX, 5., "length_precision" );
01067         myDX = 0.0;
01068         Group4Spin->SpinBox_DX->setValue( myDX );
01069         myDY = 0.0;
01070         Group4Spin->SpinBox_DY->setValue( myDY );
01071         myRadius = 100.0;
01072         Group4Spin->SpinBox_DZ->setValue( myRadius );
01073         myLength = 30.0;
01074         Group4Spin->SpinBox_DS->setValue( myLength );
01075         Group4Spin->show();
01076         Group4Spin->buttonApply->setFocus();
01077       }
01078     }
01079   }
01080   resize( minimumSizeHint() );
01081   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
01082 }
01083 
01084 //=================================================================================
01085 // function : CheckBoxClicked()
01086 // purpose  : CheckBox  management
01087 //=================================================================================
01088 void EntityGUI_SketcherDlg::CheckBoxClicked(int State)
01089 {
01090   myCheckFlag = State;
01091 
01092   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
01093 }
01094 
01095 
01096 //=================================================================================
01097 // function : ClickOnCancel()
01098 // purpose  :
01099 //=================================================================================
01100 void EntityGUI_SketcherDlg::ClickOnCancel()
01101 {
01102   close();
01103 }
01104 
01105 
01106 //=================================================================================
01107 // function : ClickOnEnd()
01108 // purpose  : connected to buttonEnd AND buttonClose
01109 //=================================================================================
01110 void EntityGUI_SketcherDlg::ClickOnEnd()
01111 {
01112   MESSAGE("EntityGUI_SketcherDlg::ClickOnEnd()")
01113   if ( sender() == MainWidget->buttonClose ) {
01114     // Verify validity of commands
01115     if ( myCommand.count() <= 2 ) {
01116       SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
01117                                  tr( "GEOM_ERROR_STATUS" ), tr( "CANNOT_CLOSE" ), tr( "BUT_OK" ) );
01118       return;
01119     }
01120 
01121     QString Parameters;
01122     QString Command = myCommand.join( "" ) + GetNewCommand( Parameters );
01123     Sketcher_Profile aProfile( Command.toAscii() );
01124 
01125     Command = myCommand.join( "" );
01126     aProfile = Sketcher_Profile( Command.toAscii() );
01127     TopoDS_Shape myShape;
01128     if ( aProfile.IsDone() )
01129       myShape = aProfile.GetShape();
01130 
01131     if ( myShape.ShapeType() != TopAbs_VERTEX )
01132       myCommand.append( ":WW" );
01133   }
01134   else {
01135     /*// PAL16008 (Sketcher Validation should be equal to Apply&Close)
01136     if ( ( Group1Spin->buttonApply->isEnabled() && Group1Spin->isVisible() ) ||
01137          ( Group2Spin->buttonApply->isEnabled() && Group2Spin->isVisible() ) ||
01138          ( Group3Spin->buttonApply->isEnabled() && Group3Spin->isVisible() ) ||
01139          ( Group4Spin->buttonApply->isEnabled() && Group4Spin->isVisible() ) ||
01140          ( Group1Sel->buttonApply->isEnabled()  && Group1Sel->isVisible()  ) ||
01141          ( Group2Sel->buttonApply->isEnabled()  && Group2Sel->isVisible()  ) ||
01142          ( Group1Sel1Spin->buttonApply->isEnabled() && Group1Sel1Spin->isVisible() ) )  {     
01143       ClickOnApply();
01144     }*/
01145 //     ClickOnApply(); // TEST remove then
01146     myIsAllAdded = true;
01147   }
01148 
01149   if (myConstructorId == 2)
01150   {
01151     QString aParameters;
01152     myCommand.append( GetNewCommand( aParameters ) );
01153     mySketchState = NEXT_POINT;
01154     if ( onAccept() )
01155       ClickOnCancel();
01156   }
01157   if ( myCommand.size() > 2 )
01158   {
01159     if ( !onAccept() )
01160       return;
01161   }
01162 
01163   close();
01164 }
01165 
01166 //=================================================================================
01167 // function : ClickOnApply()
01168 // purpose  :
01169 //=================================================================================
01170 bool EntityGUI_SketcherDlg::ClickOnApply()
01171 {
01172   MESSAGE("EntityGUI_SketcherDlg::ClickOnApply()")
01173   if ( sender() && sender()->inherits( "QPushButton" ) )
01174     ( (QPushButton*)sender() )->setFocus(); // to update value of currently edited spin-box (PAL11948)
01175 
01176 //   addSubshapesToStudy();
01177 
01178   QString aParameters;
01179   myCommand.append( GetNewCommand( aParameters ) );
01180   if (mySketchState == FIRST_POINT)
01181   {
01182     mySketchState = NEXT_POINT;
01183     OnNextPoint();
01184   }
01185 
01186   myUndoCommand.clear();
01187   myUndoCommand.append( "Sketcher" );
01188 
01189   myParameters.append( aParameters );
01190   myUndoParameters.clear();
01191 
01192   setEnabledUndo( true );
01193   setEnabledRedo( false );
01194 
01195   myIsApply = true;
01196   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
01197   myIsApply = false;
01198 
01199   // Set focus to SpinBox_DX
01200   if ( sender() == Group1Spin->buttonApply ) {
01201     (Group1Spin->SpinBox_DX)->setFocus();
01202     (Group1Spin->SpinBox_DX)->selectAll();
01203   }
01204   else if ( sender() == Group1Sel1Spin->buttonApply ) {
01205     (Group1Sel1Spin->SpinBox_DX)->setFocus();
01206     (Group1Sel1Spin->SpinBox_DX)->selectAll();
01207   }
01208   else if ( sender() == Group2Spin->buttonApply ) {
01209     (Group2Spin->SpinBox_DX)->setFocus();
01210     (Group2Spin->SpinBox_DX)->selectAll();
01211   }
01212   else if ( sender() == Group3Spin->buttonApply ) {
01213     (Group3Spin->SpinBox_DX)->setFocus();
01214     (Group3Spin->SpinBox_DX)->selectAll();
01215   }
01216   else if ( sender() == Group4Spin->buttonApply ) {
01217     (Group4Spin->SpinBox_DX)->setFocus();
01218     (Group4Spin->SpinBox_DX)->selectAll();
01219   }
01220   
01221   return true;
01222 }
01223 
01224 //=================================================================================
01225 // function : ClickOnHelp()
01226 // purpose  :
01227 //=================================================================================
01228 void EntityGUI_SketcherDlg::ClickOnHelp()
01229 {
01230   LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
01231   if ( app )
01232     app->onHelpContextModule( myGeometryGUI ? app->moduleName( myGeometryGUI->moduleName() ) : QString( "" ), myHelpFileName );
01233   else {
01234     QString platform;
01235 #ifdef WIN32
01236     platform = "winapplication";
01237 #else
01238     platform = "application";
01239 #endif
01240 
01241     SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
01242                               QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
01243                               arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
01244                               QObject::tr( "BUT_OK" ) );
01245   }
01246 }
01247 
01248 //=================================================================================
01249 // function : ClickOnUndo()
01250 // purpose  :
01251 //=================================================================================
01252 void EntityGUI_SketcherDlg::ClickOnUndo()
01253 {
01254   myUndoCommand.append( myCommand.last() );
01255   myCommand.pop_back();
01256 
01257   myUndoParameters.append( myParameters.last() );
01258   myParameters.pop_back();
01259 
01260   if ( myCommand.count() == 1 ) {
01261     mySketchState = FIRST_POINT;
01262 
01263     MainWidget->RadioButton1->setChecked( true );
01264     TypeClicked( 0 );
01265 
01266     connect( myGeometryGUI->getApp()->selectionMgr(),
01267              SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
01268 
01269     OnFirstPoint();
01270 
01271     setEnabledUndo( false );
01272   }
01273 
01274   setEnabledRedo( true );
01275 
01276   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
01277 }
01278 
01279 //=================================================================================
01280 // function : ClickOnRedo()
01281 // purpose  :
01282 //=================================================================================
01283 void EntityGUI_SketcherDlg::ClickOnRedo()
01284 {
01285   myCommand.append( myUndoCommand.last() );
01286   myUndoCommand.pop_back();
01287 
01288   myParameters.append( myUndoParameters.last() );
01289   myUndoParameters.pop_back();
01290 
01291   mySketchState = NEXT_POINT;
01292   
01293   OnNextPoint();
01294   
01295   setEnabledUndo( true );
01296 
01297   if ( myUndoCommand.count() == 1 )
01298     setEnabledRedo( false );
01299 
01300   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
01301 }
01302 
01303 //=================================================================================
01304 // function : setEnabledUndo()
01305 // purpose  :
01306 //=================================================================================
01307 void EntityGUI_SketcherDlg::setEnabledUndo( bool value )
01308 {
01309   Group1Sel->buttonUndo->setEnabled( value );
01310   Group2Sel->buttonUndo->setEnabled( value );
01311   Group1Sel1Spin->buttonUndo->setEnabled( value );
01312   Group1Spin->buttonUndo->setEnabled( value );
01313   Group2Spin->buttonUndo->setEnabled( value );
01314   Group3Spin->buttonUndo->setEnabled( value );
01315   Group4Spin->buttonUndo->setEnabled( value );
01316 }
01317 
01318 //=================================================================================
01319 // function : setEnabledRedo()
01320 // purpose  :
01321 //=================================================================================
01322 void EntityGUI_SketcherDlg::setEnabledRedo( bool value )
01323 {
01324   Group1Sel->buttonRedo->setEnabled( value );
01325   Group2Sel->buttonRedo->setEnabled( value );
01326   Group1Sel1Spin->buttonRedo->setEnabled( value );
01327   Group1Spin->buttonRedo->setEnabled( value );
01328   Group2Spin->buttonRedo->setEnabled( value );
01329   Group3Spin->buttonRedo->setEnabled( value );
01330   Group4Spin->buttonRedo->setEnabled( value );
01331 }
01332 
01333 //=================================================================================
01334 // function : SelectionIntoArgument()
01335 // purpose  : Called when selection as changed
01336 //=================================================================================
01337 void EntityGUI_SketcherDlg::SelectionIntoArgument()
01338 {
01339   MESSAGE("EntityGUI_SketcherDlg::SelectionIntoArgument")
01340   myEditCurrentArgument->setText( "" );
01341 
01342   LightApp_SelectionMgr* aSelMgr = myGeometryGUI->getApp()->selectionMgr();
01343   SALOME_ListIO aSelList;
01344   aSelMgr->selectedObjects(aSelList);
01345   
01346   this->activateWindow();
01347   
01348   if (aSelList.Extent() == 0)
01349   {
01350     selButton->setDown(false);
01351     WPlaneLineEdit->setEnabled(false);
01352     WPlaneLineEdit->setText(tr("GEOM_SKETCHER_WPLANE"));
01353     return;
01354   }
01355   else if (aSelList.Extent() != 1)                                
01356     return;
01357   
01358   double tmpX = myX;
01359   double tmpY = myY;
01360   myX = myLastX1;
01361   myY = myLastY1;
01362   
01363   TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
01364   if (myEditCurrentArgument == WPlaneLineEdit)
01365     aNeedType = TopAbs_FACE;
01366   
01367  
01368   GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
01369   TopoDS_Shape aShape;
01370   
01371   if(aSelectedObject && GEOMBase::GetShape(aSelectedObject.get(), aShape) 
01372                      && !aShape.IsNull())
01373   { 
01374     QString aName = GEOMBase::GetName( aSelectedObject.get() ); 
01375     if (myEditCurrentArgument==WPlaneLineEdit)  
01376     { 
01377       // Check if the face is planar
01378       Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aShape));
01379       GeomLib_IsPlanarSurface aPlanarCheck(aSurf, Precision::Confusion());
01380       
01381       if (aPlanarCheck.IsPlanar())
01382       {
01383         myEditCurrentArgument->setText(aName);
01384         AddLocalCS(aSelectedObject.get());
01385         selButton->setDown(false);
01386         WPlaneLineEdit->setEnabled(false);
01387         TypeClicked( myConstructorId );
01388       }
01389       else
01390       {
01391         myEditCurrentArgument->setText(tr("GEOM_SKETCHER_WPLANE"));
01392         // The following leads to crash TODO : find a way to return a warning
01393 //         Standard_Failure::Raise(tr("GEOM_SKETCHER_NOT_PLANAR").toStdString().c_str()); 
01394       }
01395     }           
01396     else
01397     {
01398       gp_Trsf aTrans;
01399       gp_Ax3 aWPlane = GetActiveLocalCS();
01400 
01401       aTrans.SetTransformation(aWPlane);
01402       BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
01403       aShape = aTransformation.Shape();
01404 
01405       gp_Pnt aPnt;
01406       if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) 
01407       {
01408         myEditCurrentArgument->setText(aName);
01409         myX = aPnt.X();
01410         myY = aPnt.Y();       
01411         double Xcoord = myX;
01412         double Ycoord = myY;
01413         
01414         switch (mySketchType)
01415         {
01416           case PT_ABS:
01417           disconnect( Group2Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
01418           disconnect( Group2Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
01419           
01420           Group2Spin->SpinBox_DX->setValue(Xcoord);
01421           Group2Spin->SpinBox_DY->setValue(Ycoord);
01422       
01423           connect( Group2Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
01424           connect( Group2Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
01425             break;
01426             
01427           case PT_RELATIVE:
01428             if (myLastX1 && myLastY1)
01429             {
01430               Xcoord = myX - myLastX1;
01431               Ycoord = myY - myLastY1;
01432             }
01433             else if (mySketchState != FIRST_POINT)
01434             {
01435               Xcoord = myX - tmpX;
01436               Ycoord = myY - tmpY;
01437             }          
01438             Group2Spin->SpinBox_DX->setValue(Xcoord);
01439             Group2Spin->SpinBox_DY->setValue(Ycoord);      
01440             break; 
01441             
01442           case PT_ABS_RADIUS:
01443             disconnect( Group3Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
01444             disconnect( Group3Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
01445             
01446             Group3Spin->SpinBox_DX->setValue(Xcoord);
01447             Group3Spin->SpinBox_DY->setValue(Ycoord);
01448       
01449             connect( Group3Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
01450             connect( Group3Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
01451             break;
01452             
01453           case PT_REL_RADIUS:
01454             if (myLastX1 && myLastY1)
01455             {
01456               Xcoord = myX - myLastX1;
01457               Ycoord = myY - myLastY1;
01458             }
01459             else if (mySketchState != FIRST_POINT)
01460             {
01461               Xcoord = myX - tmpX;
01462               Ycoord = myY - tmpY;
01463             }             
01464             Group3Spin->SpinBox_DX->setValue(Xcoord);
01465             Group3Spin->SpinBox_DY->setValue(Ycoord);
01466             break; 
01467             
01468           case PT_ABS_CENTER:
01469             disconnect( Group4Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
01470             disconnect( Group4Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
01471             
01472             Group4Spin->SpinBox_DX->setValue(Xcoord);
01473             Group4Spin->SpinBox_DY->setValue(Ycoord);
01474       
01475             connect( Group4Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
01476             connect( Group4Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );        
01477             break;
01478             
01479           case PT_REL_CENTER:
01480             if (myLastX1 && myLastY1)
01481             {
01482               Xcoord = myXc - myLastX1;
01483               Ycoord = myYc - myLastY1;
01484             }
01485             else if (mySketchState != FIRST_POINT)
01486             {
01487               Xcoord = myXc - tmpX;
01488               Ycoord = myYc - tmpY;
01489             } 
01490             else
01491             {
01492               Xcoord = myXc;
01493               Ycoord = myYc;
01494             }
01495             
01496             Group4Spin->SpinBox_DX->setValue(Xcoord);
01497             Group4Spin->SpinBox_DY->setValue(Ycoord);            
01498             break; 
01499             
01500         }
01501       }
01502     }
01503   }
01504 
01505   if(!autoApply){
01506     GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
01507   }
01508   else {    
01509     ClickOnApply();
01510     autoApply = false;
01511   }
01512   
01513 }
01514 
01515 
01516 //=================================================================================
01517 // function : SetEditCurrentArgument()
01518 // purpose  :
01519 //=================================================================================
01520 void EntityGUI_SketcherDlg::SetEditCurrentArgument()
01521 {
01522   TopAbs_ShapeEnum myNeedType = TopAbs_VERTEX;
01523   if ( sender() == Group1Sel->PushButton1 ) {
01524     myEditCurrentArgument = Group1Sel->LineEdit1;
01525     myEditCurrentArgument->setFocus();
01526   }
01527   else if ( sender() == Group1Sel1Spin->PushButton1 ) {
01528     myEditCurrentArgument = Group1Sel1Spin->LineEdit1;
01529     myEditCurrentArgument->setFocus();
01530   }
01531   else if ( sender() == Group2Sel->PushButton1 ) {
01532     myEditCurrentArgument = Group2Sel->LineEdit1;
01533     Group2Sel->PushButton2->setDown(false);
01534     Group2Sel->PushButton1->setDown(true);
01535     Group2Sel->LineEdit2->setEnabled(false);
01536     Group2Sel->LineEdit1->setEnabled(true);
01537    // myEditCurrentArgument->setFocus();
01538   }
01539    else if ( sender() == Group2Sel->PushButton2 ) {
01540     myEditCurrentArgument = Group2Sel->LineEdit2;
01541     Group2Sel->PushButton1->setDown(false);
01542     Group2Sel->PushButton2->setDown(true);
01543     Group2Sel->LineEdit1->setEnabled(false);
01544     Group2Sel->LineEdit2->setEnabled(true);
01545    // myEditCurrentArgument->setFocus();
01546   }
01547   else if ( sender() == selButton ) {
01548     myNeedType = TopAbs_FACE;
01549     myEditCurrentArgument = WPlaneLineEdit;
01550     WPlaneLineEdit->setEnabled(true);
01551     selButton->setDown(true);
01552   }
01553   globalSelection(); // close local selection to clear it
01554   localSelection(GEOM::GEOM_Object::_nil(), myNeedType);
01555 }
01556 
01557 
01558 //=================================================================================
01559 // function : LineEditReturnPressed()
01560 // purpose  :
01561 //=================================================================================
01562 void EntityGUI_SketcherDlg::LineEditReturnPressed()
01563 {
01564   if ( sender() == Group1Sel->LineEdit1 ) 
01565     myEditCurrentArgument = Group1Sel->LineEdit1;
01566   else if ( sender() == Group1Sel1Spin->LineEdit1 ) 
01567      myEditCurrentArgument = Group1Sel1Spin->LineEdit1;
01568   else if ( sender() == Group2Sel->LineEdit1 ) 
01569      myEditCurrentArgument = Group2Sel->LineEdit1;
01570   else if ( sender() == Group2Sel->LineEdit2 )
01571      myEditCurrentArgument = Group2Sel->LineEdit2;
01572 
01573   /* User name of object input management                          */
01574   /* If successfull the selection is changed and signal emitted... */
01575   /* so SelectionIntoArgument() is automatically called.           */
01576   const QString objectUserName = myEditCurrentArgument->text();
01577   QWidget* thisWidget = (QWidget*)this;
01578 
01579   LightApp_SelectionMgr* aSelMgr = myGeometryGUI->getApp()->selectionMgr();
01580   SALOME_ListIO aSelList;
01581   aSelMgr->selectedObjects(aSelList);
01582 
01583   if (GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, aSelList))
01584     myEditCurrentArgument->setText( objectUserName );
01585 }
01586 
01587 
01588 //=================================================================================
01589 // function : DeactivateActiveDialog()
01590 // purpose  :
01591 //=================================================================================
01592 void EntityGUI_SketcherDlg::DeactivateActiveDialog()
01593 {
01594   //myGeometryGUI->SetState( -1 );
01595 
01596   setEnabled( false );
01597   globalSelection();
01598   disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
01599   myGeometryGUI->SetActiveDialogBox( 0 );
01600 }
01601 
01602 
01603 //=================================================================================
01604 // function : ActivateThisDialog()
01605 // purpose  :
01606 //=================================================================================
01607 void EntityGUI_SketcherDlg::ActivateThisDialog()
01608 {
01609   MESSAGE("EntityGUI_SketcherDlg::ActivateThisDialog()")
01610   myGeometryGUI->EmitSignalDeactivateDialog();
01611   setEnabled( true );
01612   myGeometryGUI->SetActiveDialogBox( this );
01613 
01614   connect( myGeometryGUI->getApp()->selectionMgr(),
01615           SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
01616 
01617   //myGeometryGUI->SetState( 0 );
01618 //   globalSelection( GEOM_POINT );
01619   
01620   myEditCurrentArgument = WPlaneLineEdit;
01621   myEditCurrentArgument->setFocus();
01622   
01623    if ( sender() == Group1Sel->LineEdit1 ) {
01624      myEditCurrentArgument = Group1Sel->LineEdit1;
01625      myEditCurrentArgument->setFocus();
01626    }
01627    else if ( sender() == Group1Sel1Spin->LineEdit1 ) {
01628      myEditCurrentArgument = Group1Sel1Spin->LineEdit1;
01629      myEditCurrentArgument->setFocus();
01630    }
01631    else if ( sender() == Group2Sel->LineEdit1 ) {
01632      myEditCurrentArgument = Group2Sel->LineEdit1;
01633      myEditCurrentArgument->setFocus();
01634    }
01635     else if ( sender() == Group2Sel->LineEdit2 ) {
01636      myEditCurrentArgument = Group2Sel->LineEdit2;
01637      myEditCurrentArgument->setFocus();
01638    }
01639    
01640   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
01641 }
01642 
01643 
01644 //=================================================================================
01645 // function : enterEvent [REDEFINED]
01646 // purpose  :
01647 //=================================================================================
01648 void EntityGUI_SketcherDlg::enterEvent( QEvent* )
01649 {
01650   if ( !isEnabled() )
01651     ActivateThisDialog();
01652 }
01653 
01654 
01655 //=================================================================================
01656 // function : closeEvent()
01657 // purpose  :
01658 //=================================================================================
01659 void EntityGUI_SketcherDlg::closeEvent( QCloseEvent* e )
01660 {
01661   MESSAGE("EntityGUI_SketcherDlg::closeEvent")
01662   //myGeometryGUI->SetState( -1 );
01663   disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
01664   myGeometryGUI->getApp()->updateActions();
01665   QDialog::closeEvent( e );
01666 }
01667 
01668 //=================================================================================
01669 // function : OnPointSelected
01670 // purpose  :
01671 //=================================================================================
01672 void EntityGUI_SketcherDlg::OnPointSelected(Qt::KeyboardModifiers modifiers, const gp_Pnt& thePnt,
01673                                             bool isStart )
01674 {
01675   // NOTE Basing the autoapply functionnality on the background picture has no sense anymore
01676   // The import picture functionnality is now used for drawing on top of a picture
01677   
01678 //   SUIT_ViewWindow*      theViewWindow  = getDesktop()->activeWindow();
01679 //   OCCViewer_ViewPort3d* vp             = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
01680 //   
01681 //   QString                theImgFileName;
01682 //   vp->background().texture( theImgFileName ); ////////////// VSR: temporarily
01683   
01684   double x, y;
01685   x = y = 0;
01686   
01687   BRepBuilderAPI_MakeVertex mkVertex (thePnt);
01688   TopoDS_Shape aShape = mkVertex.Shape();
01689   
01690   // Taking into account LocalCS
01691   gp_Ax3 aWPlane = GetActiveLocalCS();
01692   gp_Trsf aTrans;
01693 
01694   aTrans.SetTransformation(aWPlane);
01695   BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
01696   aShape = aTransformation.Shape();
01697   
01698   gp_Pnt aTrsfPnt; 
01699   GEOMBase::VertexToPoint( aShape, aTrsfPnt );
01700   
01701   // NOTE autoapply disabled : doesn't seem useful anymore
01702 //   autoApply = ( (getPnt2ConstructorId() == 1) && (!theImgFileName.isEmpty()) );  // If no additional argument needed after selection and there is a backgroundimage
01703                                                                                  // -> apply automatically 
01704   
01705   if ( getPnt1ConstructorId() == 0 ){                    // Relative selection mode
01706     x = aTrsfPnt.X() - myLastX1;
01707     y = aTrsfPnt.Y() - myLastY1;
01708   }
01709   else {
01710     x = aTrsfPnt.X();
01711     y = aTrsfPnt.Y();
01712   }
01713   switch (getPnt2ConstructorId()){
01714     case 1:
01715       Group2Spin->SpinBox_DX->setValue( x );
01716       Group2Spin->SpinBox_DY->setValue( y );
01717       Group2Spin->buttonApply->setFocus();               // Previous setFocus (during preview) may have been inoperative if it was disabled 
01718       break;
01719     case 0:
01720       Group3Spin->SpinBox_DX->setValue( x );
01721       Group3Spin->SpinBox_DY->setValue( y );
01722       Group3Spin->buttonApply->setFocus(); 
01723       break;
01724     case 2:
01725       if (modifiers == Qt::MetaModifier){                // Select center with Meta key
01726         Group4Spin->SpinBox_DX->setValue( x );
01727         Group4Spin->SpinBox_DY->setValue( y );
01728       }
01729       else{                                              // Select end point
01730         Group4Spin->SpinBox_DZ->setValue( x );
01731         Group4Spin->SpinBox_DS->setValue( y );
01732       }
01733       Group4Spin->buttonApply->setFocus(); 
01734       break;
01735   }
01736   if ( myConstructorId == 2 ) //RECTANGLE
01737   {
01738     if (isStart)
01739     {
01740       GroupRect->SpinBox_DX1->setValue( aTrsfPnt.X() );
01741       GroupRect->SpinBox_DY1->setValue( aTrsfPnt.Y() );
01742       GroupRect->SpinBox_DX2->setValue( aTrsfPnt.X() );
01743       GroupRect->SpinBox_DY2->setValue( aTrsfPnt.Y() );
01744     }
01745     else
01746     {
01747       GroupRect->SpinBox_DX2->setValue( aTrsfPnt.X() );
01748       GroupRect->SpinBox_DY2->setValue( aTrsfPnt.Y() );
01749     }
01750   }
01751 }
01752 
01753 //=================================================================================
01754 // function : OnFirstPoint
01755 // purpose  :
01756 //=================================================================================
01757 void EntityGUI_SketcherDlg::OnFirstPoint()
01758 {
01759   MainWidget->RadioButton3->setEnabled( true );
01760   MainWidget->GroupDest1->setEnabled( false );
01761   GroupPt2->setEnabled( false );
01762 }
01763 
01764 //=================================================================================
01765 // function : OnNextPoint
01766 // purpose  :
01767 //=================================================================================
01768 void EntityGUI_SketcherDlg::OnNextPoint()
01769 {
01770   MainWidget->RadioButton3->setEnabled( false );
01771   MainWidget->GroupDest1->setEnabled( true );
01772   TypeClicked(myConstructorId);
01773 }
01774 
01775 //=================================================================================
01776 // function : ValueChangedInSpinBox()
01777 // purpose  :
01778 //=================================================================================
01779 void EntityGUI_SketcherDlg::ValueChangedInSpinBox( double newValue )
01780 {
01781   QObject* send = (QObject*)sender();
01782   Standard_Real vx, vy, vz, vs, minRad, dx, dy;
01783   vx = vy = vz = vs = minRad = dx = dy = 0.0;
01784 
01785   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
01786   int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
01787   double LastDecimal = 0.0;
01788 
01789   QString vxStr, vyStr, vzStr, vsStr;
01790 
01791   QString newValueStr;
01792   if( SalomeApp_DoubleSpinBox* aDoubleSpinBox = (SalomeApp_DoubleSpinBox*)send )
01793     newValueStr = aDoubleSpinBox->text();
01794 
01795   if ( send == Group1Spin->SpinBox_DX ) {
01796     vx = newValue;                        vxStr = newValueStr;
01797   }
01798   else if ( send == Group1Sel1Spin->SpinBox_DX ) {
01799     vx = newValue;                        vxStr = newValueStr;
01800   }
01801   else if ( send == Group2Spin->SpinBox_DX ) {
01802     vx = newValue;                        vxStr = newValueStr;
01803     vy = Group2Spin->SpinBox_DY->value(); vyStr = Group2Spin->SpinBox_DY->text();
01804   }
01805   else if ( send == Group2Spin->SpinBox_DY ) {
01806     vx = Group2Spin->SpinBox_DX->value(); vxStr = Group2Spin->SpinBox_DX->text();
01807     vy = newValue;                        vyStr = newValueStr;
01808   }
01809   else if ( send == Group3Spin->SpinBox_DX ) {
01810     vx = newValue;                        vxStr = newValueStr;
01811     vy = Group3Spin->SpinBox_DY->value(); vyStr = Group3Spin->SpinBox_DY->text();
01812     vz = Group3Spin->SpinBox_DZ->value();
01813     if ( (mySketchType == PT_REL_RADIUS || mySketchType == PT_ABS_RADIUS) && (vx != 0 || vy != 0) ) {  
01814       if (mySketchType == PT_ABS_RADIUS){
01815         dx = vx - myLastX1;
01816         dy = vy - myLastY1;
01817       }
01818       else{
01819         dx = vx;
01820         dy = vy;
01821       }
01822       minRad = 0.5 * Sqrt(dx * dx + dy * dy);                             //Computation of the minimum acceptable radius for the arc calculation
01823       if (aPrecision >= 0)    // 'f' format in the QString             
01824         LastDecimal = aPrecision;
01825       else                    // 'g' format in the Qstring
01826         LastDecimal = qAbs( aPrecision ) - ceil( log10(minRad) ); 
01827       minRad = ceil(pow(10,LastDecimal) * minRad) / pow(10,LastDecimal);  // Rounded up at the last allowed decimal place
01828       if ( Abs(vz) < minRad){
01829         if (vz < 0.0)
01830           Group3Spin->SpinBox_DZ->setValue( - minRad );
01831         else 
01832           Group3Spin->SpinBox_DZ->setValue( minRad );
01833       }
01834     }
01835     vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
01836   }
01837   else if ( send == Group3Spin->SpinBox_DY ) {
01838     vx = Group3Spin->SpinBox_DX->value(); vxStr = Group3Spin->SpinBox_DX->text();
01839     vy = newValue;                        vyStr = newValueStr;
01840     vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
01841     if ( (mySketchType == PT_REL_RADIUS || mySketchType == PT_ABS_RADIUS) && (vx != 0 || vy != 0)){
01842       if (mySketchType == PT_ABS_RADIUS){
01843         dx = vx - myLastX1;
01844         dy = vy - myLastY1;
01845       }
01846       else{
01847         dx = vx;
01848         dy = vy;
01849       }    
01850       minRad = 0.5 * Sqrt(dx * dx + dy * dy);                            //Computation of the minimum acceptable radius for the arc calculation
01851       if (aPrecision >= 0)    // 'f' format in the QString 
01852         LastDecimal = aPrecision;
01853       else                    // 'g' format in the QString 
01854         LastDecimal = qAbs( aPrecision ) - ceil( log10(minRad) ); 
01855         minRad = ceil(pow(10,LastDecimal) * minRad) / pow(10,LastDecimal); // Rounded up at the last allowed decimal place
01856       if ( Abs(vz) < minRad){
01857         if (vz < 0.0)
01858           Group3Spin->SpinBox_DZ->setValue( - minRad );
01859         else 
01860           Group3Spin->SpinBox_DZ->setValue( minRad );
01861       }
01862     }
01863     vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
01864   }
01865   else if ( send == Group3Spin->SpinBox_DZ ) {
01866     vx = Group3Spin->SpinBox_DX->value(); vxStr = Group3Spin->SpinBox_DX->text();
01867     vy = Group3Spin->SpinBox_DY->value(); vyStr = Group3Spin->SpinBox_DY->text();
01868     vz = newValue;                        vzStr = newValueStr;
01869   }
01870   else if ( send == Group4Spin->SpinBox_DX ) {
01871     vx = newValue;                        vxStr = newValueStr;
01872     vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
01873     vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
01874     vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
01875   }
01876   else if ( send == Group4Spin->SpinBox_DY ) {
01877     vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
01878     vy = newValue;                        vyStr = newValueStr;
01879     vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
01880     vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
01881   }
01882   else if ( send == Group4Spin->SpinBox_DZ ) {
01883     vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
01884     vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
01885     vz = newValue;                        vzStr = newValueStr;
01886     vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
01887   }
01888   else if ( send == Group4Spin->SpinBox_DS ) {
01889     vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
01890     vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
01891     vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
01892     vs = newValue;                        vsStr = newValueStr;
01893   }
01894   // Fix of the NPAL16010 bug is removed, because it's not actual with the Qt-4.x
01895 
01896   if ( myConstructorId == 0 ) {  // SEGMENT
01897     if ( mySketchType == PT_ABS ) {
01898       myX = vx;
01899       myY = vy;
01900       myXStr = vxStr;
01901       myYStr = vyStr;
01902     }
01903     else if ( mySketchType == PT_RELATIVE ) {
01904       myDX = vx;
01905       myDY = vy;
01906       myDXStr = vxStr;
01907       myDYStr = vyStr;
01908     }
01909     else if ( mySketchType == DIR_ANGLE_LENGTH ) {
01910       myAngle = vx;
01911       myLength = vy;
01912       myAngleStr = vxStr;
01913       myLengthStr = vyStr;
01914     }
01915     else if ( mySketchType == DIR_ANGLE_X ) {
01916       myAngle = vx;
01917       myX = vy;
01918       myAngleStr = vxStr;
01919       myXStr = vyStr;
01920     }
01921     else if ( mySketchType == DIR_ANGLE_Y ) {
01922       myAngle = vx;
01923       myY = vy;
01924       myAngleStr = vxStr;
01925       myYStr = vyStr;
01926     }
01927     else if ( mySketchType == DIR_PER_LENGTH ) {
01928       myLength = vx;
01929       myLengthStr = vxStr;
01930     }
01931     else if ( mySketchType == DIR_PER_X ) {
01932       myX = vx;
01933       myXStr = vxStr;
01934     }
01935     else if ( mySketchType == DIR_PER_Y ) {
01936       myY = vx;
01937       myYStr = vxStr;
01938     }
01939     else if ( mySketchType == DIR_TAN_LENGTH ) {
01940       myLength = vx;
01941       myLengthStr = vxStr;
01942     }
01943     else if ( mySketchType == DIR_TAN_X ) {
01944       myX = vx;
01945       myXStr = vxStr;
01946     }
01947     else if ( mySketchType == DIR_TAN_Y ) {
01948       myY = vx;
01949       myYStr = vxStr;
01950     }
01951     else if ( mySketchType == DIR_DXDY_LENGTH ) {
01952       myDX = vx;
01953       myDY = vy;
01954       myLength = vz;
01955       myDXStr = vxStr;
01956       myDYStr = vyStr;
01957       myLengthStr = vzStr;
01958     }
01959     else if ( mySketchType == DIR_DXDY_X ) {
01960       myDX = vx;
01961       myDY = vy;
01962       myX = vz;
01963       myDXStr = vxStr;
01964       myDYStr = vyStr;
01965       myXStr = vzStr;
01966     }
01967     else if ( mySketchType == DIR_DXDY_Y ) {
01968       myDX = vx;
01969       myDY = vy;
01970       myY = vz;
01971       myDXStr = vxStr;
01972       myDYStr = vyStr;
01973       myYStr = vzStr;
01974     }
01975   }
01976   else if ( myConstructorId == 1 ) {  // ARC
01977     if ( mySketchType == PT_ABS ) {  
01978       myX = vx;
01979       myY = vy;
01980       myXStr = vxStr;
01981       myYStr = vyStr;
01982     }
01983     else if ( mySketchType == PT_RELATIVE ) {
01984       myDX = vx;
01985       myDY = vy;
01986       myDXStr = vxStr;
01987       myDYStr = vyStr;
01988     }
01989     if ( mySketchType == PT_ABS_RADIUS ) {  
01990       myX = vx;
01991       myY = vy;
01992       myRadius=vz;
01993       myXStr = vxStr;
01994       myYStr = vyStr;
01995       myRadiusStr = vzStr;
01996     }
01997     else if ( mySketchType == PT_REL_RADIUS ) {
01998       myDX = vx;
01999       myDY = vy;
02000       myRadius=vz;
02001       myDXStr = vxStr;
02002       myDYStr = vyStr;
02003       myRadiusStr = vzStr;
02004     }
02005     else if ( mySketchType == PT_SEL_RADIUS ) {
02006       myRadius = vx;
02007       myRadiusStr = vxStr;
02008     }
02009     if ( mySketchType == PT_ABS_CENTER ) {  
02010       myXc = vx;
02011       myYc = vy;
02012       myX = vz;
02013       myY = vs;
02014       myXcStr = vxStr;
02015       myYcStr = vyStr;
02016       myXStr = vzStr;
02017       myYStr = vsStr;
02018     }
02019     else if ( mySketchType == PT_REL_CENTER ) {
02020       myDXc = vx;
02021       myDYc = vy;
02022       myDX = vz;
02023       myDY = vs;
02024       myDXcStr = vxStr;
02025       myDYcStr = vyStr;
02026       myDXStr = vzStr;
02027       myDYStr = vsStr;
02028     }
02029     if ( mySketchType == DIR_ANGLE_LENGTH ) {
02030       myAngle = vx;
02031       myRadius = vy;
02032       myLength = vz;
02033       myAngleStr = vxStr;
02034       myRadiusStr = vyStr;
02035       myLengthStr = vzStr;
02036     }
02037     else if ( mySketchType == DIR_PER_LENGTH ) {
02038       myRadius = vx;
02039       myLength = vy;
02040       myRadiusStr = vxStr;
02041       myLengthStr = vyStr;
02042     }
02043     else if ( mySketchType == DIR_TAN_LENGTH ) {
02044       myRadius = vx;
02045       myLength = vy;
02046       myRadiusStr = vxStr;
02047       myLengthStr = vyStr;
02048     }
02049     else if ( mySketchType == DIR_DXDY_LENGTH ) {
02050       myDX = vx;
02051       myDY = vy;
02052       myRadius = vz;
02053       myLength = vs;
02054       myDXStr = vxStr;
02055       myDYStr = vyStr;
02056       myRadiusStr = vzStr;
02057       myLengthStr = vsStr;
02058     }
02059   }
02060   else if ( myConstructorId == 2 ) {  // RECTANGLE
02061     myX1 = GroupRect->SpinBox_DX1->value(); myX1Str = GroupRect->SpinBox_DX1->text();
02062     myX2 = GroupRect->SpinBox_DX2->value(); myX2Str = GroupRect->SpinBox_DX2->text();
02063     myY1 = GroupRect->SpinBox_DY1->value(); myY1Str = GroupRect->SpinBox_DY1->text();
02064     myY2 = GroupRect->SpinBox_DY2->value(); myY2Str = GroupRect->SpinBox_DY2->text();
02065   }
02066 
02067   
02068   if (!autoApply) 
02069     GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
02070   
02071   double x, y, xc, yc;
02072   x = y = xc = yc = 0.0;
02073   if ( mySketchType == PT_ABS_CENTER || mySketchType == PT_REL_CENTER )
02074   {
02075     if ( mySketchType == PT_REL_CENTER ){
02076       x  = myDX  + myLastX1;
02077       y  = myDY  + myLastY1;
02078       xc = myDXc + myLastX1;
02079       yc = myDYc + myLastY1;
02080     }
02081     else {
02082       x  = myX ;
02083       y  = myY ;
02084       xc = myXc;
02085       yc = myYc;
02086     }
02087     displayPntPreview(xc,yc);
02088     displayPntPreview(x,y);
02089   }
02090 }
02091 
02092 
02093 //=================================================================================
02094 // function : GetNewCommand()
02095 // purpose  : Build the new command with context
02096 //=================================================================================
02097 QString EntityGUI_SketcherDlg::GetNewCommand( QString& theParameters )
02098 {
02099   theParameters.clear();
02100   QString myNewCommand = ":";
02101   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
02102   int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
02103   int DigNum = qAbs(aPrecision);                   // options for the format of numbers in  myNewCommand
02104   char Format = 'f';
02105   if ( aPrecision < 0 )                            // f --> DigNum is the number of digits after the decimal point
02106     Format = 'g';                                  // g --> DigNum is the maximum number of significant digits 
02107 
02108   if ( mySketchState == FIRST_POINT ) {
02109     if ( mySketchType == PT_ABS || mySketchType == PT_SEL ) {
02110       myNewCommand = myNewCommand + "F " + QString::number( myX, Format, DigNum) + " " + QString::number( myY, Format, DigNum);
02111       theParameters = myXStr + ":" + myYStr;
02112     }
02113     if ( mySketchType == PT_RELATIVE) {
02114       myNewCommand = myNewCommand + "F " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
02115       theParameters = myDXStr + ":" + myDYStr;
02116     }
02117     if (myConstructorId == 2 )
02118       myNewCommand = ":";
02119     else
02120       return myNewCommand;
02121   }
02122 
02123   if ( myConstructorId == 0  ) {  // SEGMENT
02124     if ( mySketchType == PT_ABS || mySketchType == PT_SEL ) {
02125       myNewCommand = myNewCommand + "TT " + QString::number( myX, Format, DigNum) + " " + QString::number( myY, Format, DigNum);
02126       theParameters = myXStr + ":" + myYStr;
02127     }
02128     if ( mySketchType == PT_RELATIVE) {
02129       myNewCommand = myNewCommand + "T " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
02130       theParameters = myDXStr + ":" + myDYStr;
02131     }
02132     if ( mySketchType == DIR_ANGLE_LENGTH ) {
02133       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
02134       myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength, Format, DigNum );
02135       theParameters = myAngleStr + ":" + myLengthStr;
02136     }
02137     if ( mySketchType == DIR_ANGLE_X ) {
02138       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
02139       myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX, Format, DigNum);
02140       theParameters = myAngleStr + ":" + myXStr;
02141     }
02142     if ( mySketchType == DIR_ANGLE_Y ) {
02143       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
02144       myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY, Format, DigNum);
02145       theParameters = myAngleStr + ":" + myYStr;
02146     }
02147     if ( mySketchType == DIR_PER_LENGTH ) {
02148       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
02149       myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength, Format, DigNum );
02150       theParameters = QString::number( 90.0 ) + ":" + myLengthStr;
02151     }
02152     if ( mySketchType == DIR_PER_X ) {
02153       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
02154       myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX, Format, DigNum);
02155       theParameters = QString::number( 90.0 ) + ":" + myXStr;
02156     }
02157     if ( mySketchType == DIR_PER_Y ) {
02158       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
02159       myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY, Format, DigNum);
02160       theParameters = QString::number( 90.0 ) + ":" + myYStr;
02161     }
02162     if ( mySketchType == DIR_TAN_LENGTH ) {
02163       myNewCommand = myNewCommand + "L " + QString::number( myLength, Format, DigNum );
02164       theParameters = myLengthStr;
02165     }
02166     if ( mySketchType == DIR_TAN_X ) {
02167       myNewCommand = myNewCommand + "IX " + QString::number( myX, Format, DigNum);
02168       theParameters = myXStr;
02169     }
02170     if ( mySketchType == DIR_TAN_Y) {
02171       myNewCommand = myNewCommand + "IY " + QString::number(myY, Format, DigNum);
02172       theParameters = myYStr;
02173     }
02174     if ( mySketchType == DIR_DXDY_LENGTH ) {
02175       myNewCommand = myNewCommand + "D " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
02176       myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength, Format, DigNum );
02177       theParameters = myDXStr + ":" + myDYStr + ":" + myLengthStr;
02178     }
02179     if ( mySketchType == DIR_DXDY_X ) {
02180       myNewCommand = myNewCommand + "D " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
02181       myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX, Format, DigNum);
02182       theParameters = myDXStr + ":" + myDYStr + ":" + myXStr;
02183     }
02184     if ( mySketchType == DIR_DXDY_Y ) {
02185       myNewCommand = myNewCommand + "D " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
02186       myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY, Format, DigNum);
02187       theParameters = myDXStr + ":" + myDYStr + ":" + myYStr;
02188     }
02189   }
02190   else if ( myConstructorId == 1 ) {  // ARC
02191     if ( mySketchType == PT_ABS || mySketchType == PT_SEL ) {
02192       myNewCommand = myNewCommand + "AA " + QString::number( myX, Format, DigNum) + " " + QString::number( myY, Format, DigNum);
02193       theParameters = myXStr + ":" + myYStr;
02194     }
02195     if ( mySketchType == PT_RELATIVE) {
02196       myNewCommand = myNewCommand + "A " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
02197       theParameters = myDXStr + ":" + myDYStr;
02198     }
02199     if ( mySketchType == PT_ABS_RADIUS || mySketchType == PT_SEL_RADIUS ) {
02200       myNewCommand = myNewCommand + "UU " + QString::number( myX, Format, DigNum) + " " + QString::number( myY, Format, DigNum ) + " " + QString::number( myRadius , Format,  DigNum)+ " " + QString::number( myCheckFlag );
02201       theParameters = myXStr + ":" + myYStr + ":" + myRadiusStr; 
02202     }
02203     if ( mySketchType == PT_REL_RADIUS) {
02204       myNewCommand = myNewCommand + "U " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum ) + " " + QString::number( myRadius, Format, DigNum )+ " " + QString::number( myCheckFlag );
02205       theParameters = myDXStr + ":" + myDYStr + ":" + myRadiusStr;  
02206     }
02207     if ( mySketchType == PT_ABS_CENTER || mySketchType == PT_SEL_CENTER ) {
02208       myNewCommand = myNewCommand + "EE " + QString::number( myX, Format, DigNum) + " " + QString::number( myY, Format, DigNum ) + " " + QString::number( myXc , Format,  DigNum) + " " + QString::number( myYc , Format,  DigNum)+ " " + QString::number( myCheckFlag ) + " " + QString::number( 0 );
02209       theParameters = myXStr + ":" + myYStr + ":" + myXcStr+ ":" + myYcStr; 
02210     }
02211     if ( mySketchType == PT_REL_CENTER) {
02212       myNewCommand = myNewCommand + "E " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum ) + " " + QString::number( myDXc, Format, DigNum )+ " " + QString::number( myDYc, Format, DigNum )+ " " + QString::number( myCheckFlag )+ " " + QString::number( 0 );
02213       theParameters = myDXStr + ":" + myDYStr + ":" +  myDXcStr + ":" + myDYcStr ;  
02214     }
02215     if ( mySketchType == DIR_ANGLE_LENGTH ) {
02216       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
02217       myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius, Format, DigNum ) + " " + QString::number( myLength, Format, DigNum );
02218       theParameters = myAngleStr + ":" + myRadiusStr + ":" + myLengthStr;
02219     }
02220     if ( mySketchType == DIR_PER_LENGTH ) {
02221       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
02222       myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius, Format, DigNum ) + " " + QString::number( myLength, Format, DigNum );
02223       theParameters = QString::number( 90.0 ) + ":" + myRadiusStr + ":" + myLengthStr;
02224     }
02225     if ( mySketchType == DIR_TAN_LENGTH ) {
02226       myNewCommand = myNewCommand + "C " + QString::number( myRadius, Format, DigNum ) + " " + QString::number( myLength, Format, DigNum );
02227       theParameters = myRadiusStr + ":" + myLengthStr;
02228     }
02229     if ( mySketchType == DIR_DXDY_LENGTH ) {
02230       myNewCommand = myNewCommand + "D " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
02231       myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius, Format, DigNum ) + " " + QString::number( myLength, Format, DigNum );
02232       theParameters = myDXStr + ":" + myDYStr + ":" + myRadiusStr + ":" + myLengthStr;
02233     }
02234   }
02235   else if ( myConstructorId == 2 ) {  // RECTANGLE
02236       myNewCommand = myNewCommand + "F " + QString::number( myX1, Format, DigNum) + " " + QString::number( myY1, Format, DigNum)
02237                                   + ":TT " + QString::number( myX1, Format, DigNum) + " " + QString::number( myY2, Format, DigNum)
02238                                   + ":TT " + QString::number( myX2, Format, DigNum) + " " + QString::number( myY2, Format, DigNum)
02239                                   + ":TT " + QString::number( myX2, Format, DigNum) + " " + QString::number( myY1, Format, DigNum)
02240                                   + ":WW";
02241                           
02242       theParameters = myX1Str + ":" + myY1Str + ":" + myX2Str + ":" + myY2Str ;
02243     }
02244   return myNewCommand;
02245 }
02246 
02247 //=================================================================================
02248 // function : createOperation
02249 // purpose  :
02250 //=================================================================================
02251 GEOM::GEOM_IOperations_ptr EntityGUI_SketcherDlg::createOperation()
02252 {
02253   return getGeomEngine()->GetICurvesOperations( getStudyId() );
02254 }
02255 
02256 //=================================================================================
02257 // function : isValid
02258 // purpose  :
02259 //=================================================================================
02260 bool EntityGUI_SketcherDlg::isValid( QString& msg )
02261 {
02262   bool ok = true;
02263   bool toCorrect = !IsPreview() || myIsApply;
02264 
02265   if( Group1Spin->isVisible() ) {
02266     ok = Group1Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
02267   }
02268   else if( Group1Sel1Spin->isVisible() ) {
02269     ok = Group1Sel1Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
02270   }
02271   else if( Group2Spin->isVisible() ) {
02272     ok = Group2Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
02273     ok = Group2Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
02274   }
02275   else if( Group3Spin->isVisible() ) {
02276     ok = Group3Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
02277     ok = Group3Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
02278     ok = Group3Spin->SpinBox_DZ->isValid( msg, toCorrect ) && ok;
02279   }
02280   else if( Group4Spin->isVisible() ) {
02281     ok = Group4Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
02282     ok = Group4Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
02283     ok = Group4Spin->SpinBox_DZ->isValid( msg, toCorrect ) && ok;
02284     ok = Group4Spin->SpinBox_DS->isValid( msg, toCorrect ) && ok;
02285   }
02286 
02287   if( myIsApply && !ok )
02288     showError( msg );
02289 
02290   return ok;
02291 }
02292 
02293 //=================================================================================
02294 // function : execute
02295 // purpose  :
02296 //=================================================================================
02297 bool EntityGUI_SketcherDlg::execute( ObjectList& objects )
02298 {
02299   MESSAGE("EntityGUI_SketcherDlg::execute")
02300   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
02301   int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
02302   int DigNum = qAbs(aPrecision);                   // options for the format of numbers in  myNewCommand
02303   char Format = 'f';
02304   if ( aPrecision < 0 )                            // f --> DigNum is the number of digits after the decimal point
02305     Format = 'g';                                  // g --> DigNum is the maximum number of significant digits 
02306     
02307   QString aParameters;
02308   
02309   if ( mySketchState == FIRST_POINT ) {
02310     myLastX2 = myX;
02311     myLastY2 = myY;
02312   }
02313   else {
02314     //Test if the current point is the same as the last one
02315     TopoDS_Shape myShape1, myShape2;
02316 
02317     // Set "C" numeric locale
02318     Kernel_Utils::Localizer loc;
02319 
02320     //Last Shape
02321     QString Command1 = myCommand.join( "" );
02322     Sketcher_Profile aProfile1( Command1.toAscii() );
02323     if ( aProfile1.IsDone() )
02324       myShape1 = aProfile1.GetShape();
02325 
02326     //Current Shape
02327     QString Command2 = Command1 + GetNewCommand( aParameters );
02328     Sketcher_Profile aProfile2( Command2.toAscii() );
02329 
02330     //Error Message
02331     if ( mySketchType == PT_ABS_CENTER || mySketchType == PT_REL_CENTER  ){
02332       if (aProfile2.Error() > Precision::Confusion()){
02333         Group4Spin->label->show();
02334         Group4Spin->label->setText( tr("GEOM_SKETCHER_WARNING") + QString::number( aProfile2.Error(), Format, DigNum));
02335       }
02336       else{
02337         Group4Spin->label->hide();
02338       } 
02339     }
02340     else 
02341       Group4Spin->label->hide();
02342     if ( mySketchType == PT_SEL_CENTER ){
02343       if (aProfile2.Error() > Precision::Confusion()){
02344         Group2Sel->label->show();
02345         Group2Sel->label->setText( tr("GEOM_SKETCHER_WARNING") + QString::number( aProfile2.Error(), Format, DigNum));
02346       }
02347       else{
02348         Group2Sel->label->hide();
02349       } 
02350     }
02351     else 
02352       Group2Sel->label->hide();
02353 
02354     if ( aProfile2.IsDone() )
02355       myShape2 = aProfile2.GetShape();
02356 
02357     if ( myShape2.IsNull() ) {
02358       //the current point is the same as the last one
02359       myLastX2 = myLastX1;
02360       myLastY2 = myLastY1;
02361     }
02362     else {
02363       TopoDS_Vertex V1, V2;
02364       gp_Pnt pt;
02365       if ( myShape1.ShapeType() == TopAbs_VERTEX ) {
02366         //the last shape is the first point
02367         pt = BRep_Tool::Pnt( TopoDS::Vertex( myShape1 ) );
02368         myLastX1 = pt.X();
02369         myLastY1 = pt.Y();
02370       }
02371       else {
02372         TopExp::Vertices( TopoDS::Wire( myShape1 ), V1, V2 );
02373         pt = BRep_Tool::Pnt( V2 );
02374         myLastX1 = pt.X();
02375         myLastY1 = pt.Y();
02376       }
02377       TopExp::Vertices( TopoDS::Wire( myShape2 ), V1, V2 );
02378       pt = BRep_Tool::Pnt( V2 );
02379       myLastX2 = pt.X();
02380       myLastY2 = pt.Y();
02381     }
02382   }
02383 
02384   QString cmd;
02385   if ( ( mySketchState != FIRST_POINT &&
02386          myLastX1 == myLastX2 && myLastY1 == myLastY2 ) || myIsAllAdded ) {
02387     cmd = myCommand.join( "" );
02388     if ( Group1Sel->isVisible() ) {
02389       Group1Sel->buttonApply->setEnabled( false );
02390       //Group1Sel->buttonApply->setFocus();
02391     }
02392     if ( Group2Sel->isVisible() ) {
02393       Group2Sel->buttonApply->setEnabled( false );
02394       //Group2Sel->buttonApply->setFocus();
02395     }
02396     if ( Group1Sel1Spin->isVisible() ) {
02397       Group1Sel1Spin->buttonApply->setEnabled( false );
02398       //Group1Sel1Spin->buttonApply->setFocus();
02399     }
02400     if ( Group1Spin->isVisible() ) {
02401       Group1Spin->buttonApply->setEnabled( false );
02402       //Group1Spin->buttonApply->setFocus();
02403     }
02404     if ( Group2Spin->isVisible() ) {
02405       Group2Spin->buttonApply->setEnabled( false );
02406       //Group2Spin->buttonApply->setFocus();
02407     }
02408     if ( Group3Spin->isVisible() ) {
02409       Group3Spin->buttonApply->setEnabled( false );
02410       //Group3Spin->buttonApply->setFocus();
02411     }
02412     if ( Group4Spin->isVisible() ) {
02413       Group4Spin->buttonApply->setEnabled( false );
02414       //Group4Spin->buttonApply->setFocus();
02415     }
02416   }
02417   else {
02418     cmd = myCommand.join( "" ) + GetNewCommand( aParameters );
02419 
02420     if ( Group1Sel->isVisible() ) {
02421       Group1Sel->buttonApply->setEnabled( true );
02422     }
02423     if ( Group2Sel->isVisible() ) {
02424       Group2Sel->buttonApply->setEnabled( true );
02425     }
02426     if ( Group1Sel1Spin->isVisible() ) {
02427       Group1Sel1Spin->buttonApply->setEnabled( true );;
02428     }
02429     if ( Group1Spin->isVisible() ) {
02430       Group1Spin->buttonApply->setEnabled( true );
02431     }
02432     if ( Group2Spin->isVisible() ) {
02433       Group2Spin->buttonApply->setEnabled( true );
02434     }
02435     if ( Group3Spin->isVisible() ) {
02436       Group3Spin->buttonApply->setEnabled( true );
02437     }
02438     if ( Group4Spin->isVisible() ) {
02439       Group4Spin->buttonApply->setEnabled( true );
02440     }
02441   }
02442 
02443   GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow(getOperation());
02444   GEOM::GEOM_Object_var anObj = NULL;
02445   
02446   int index = ComboBox1->currentIndex();
02447   if(index != -1 && !myWPlane->_is_nil()) // The combobox is not empty
02448   {
02449     anObj = anOper->MakeSketcherOnPlane( cmd.toLatin1().constData(), myWPlane );
02450   }
02451   if ( !anObj->_is_nil() )
02452   {
02453     if( !IsPreview() ) {
02454       QStringList aCurrentParameters = myParameters;
02455       aCurrentParameters << aParameters;
02456       anObj->SetParameters(aCurrentParameters.join(":").toLatin1().constData());
02457     }
02458 
02459     objects.push_back( anObj._retn() );
02460   }
02461 
02462   return true;
02463 }
02464 
02465 //================================================================
02466 // Function : displayPreview
02467 // Purpose  : Method for displaying preview of resulting shape
02468 //            Redefined from GEOMBase_Helper.
02469 //================================================================
02470 void EntityGUI_SketcherDlg::displayPreview( GEOM::GEOM_Object_ptr object,
02471                                             const bool            append,
02472                                             const bool            activate,
02473                                             const bool            update,
02474                                             const double          lineWidth,
02475                                             const int             displayMode,
02476                                             const int             color )
02477 { 
02478   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); 
02479   
02480   QColor aColor = resMgr->colorValue("Geometry","line_color",QColor(255,0,0));
02481   Quantity_NameOfColor line_color = SalomeApp_Tools::color( aColor ).Name();
02482   
02483   // set width of displayed shape
02484   int lw = lineWidth;
02485   if(lw == -1) { 
02486     lw = resMgr->integerValue("Geometry", "preview_edge_width", -1);
02487   }
02488   getDisplayer()->SetWidth( lw );
02489 
02490   // Disable activation of selection
02491   getDisplayer()->SetToActivate( activate );
02492 
02493   // Make a reference to GEOM_Object
02494   CORBA::String_var objStr = myGeometryGUI->getApp()->orb()->object_to_string( object );
02495   getDisplayer()->SetName( objStr.in() );
02496 
02497   // Create wire from applayed object
02498   TopoDS_Shape anApplyedWire, aLastSegment;
02499   if ( !createShapes( object, anApplyedWire, aLastSegment ) )
02500     return;
02501 
02502   // Build prs
02503   if( myConstructorId != 2)
02504     getDisplayer()->SetColor( line_color );
02505   else
02506     getDisplayer()->SetColor( Quantity_NOC_VIOLET );
02507   
02508   SALOME_Prs* aPrs = getDisplayer()->BuildPrs( anApplyedWire );
02509   if ( aPrs != 0 && !aPrs->IsNull() )
02510     GEOMBase_Helper::displayPreview( aPrs, append, update );
02511 
02512   getDisplayer()->SetColor( Quantity_NOC_VIOLET );
02513   
02514   aPrs = getDisplayer()->BuildPrs( aLastSegment );
02515   if ( aPrs != 0 && !aPrs->IsNull() )
02516     GEOMBase_Helper::displayPreview( aPrs, append, update );
02517 
02518   getDisplayer()->SetColor( line_color );
02519   
02520   getDisplayer()->UnsetName();
02521 
02522   // Enable activation of displayed objects
02523   getDisplayer()->SetToActivate( true );
02524 }
02525 
02526 //================================================================
02527 // Function : displayPntPreview
02528 // Purpose  : creates a TopoDS_VERTEX and display a preview of it
02529 //================================================================
02530 void EntityGUI_SketcherDlg::displayPntPreview(const double x,
02531                                               const double y,
02532                                               bool append,
02533                                               bool update
02534                                              )
02535 {
02536   // Get globalCS and working plane
02537   gp_Ax3 globalCS = WPlaneToLCS( myGlobalCS );
02538   gp_Ax3 aWPlane  = GetActiveLocalCS();
02539   
02540   // Build point in localCS
02541   gp_Pnt aPnt = gp_Pnt(x,y,0.0);
02542   
02543   // Get transfomation from local to global CS
02544   gp_Trsf aTrans;
02545   aTrans.SetTransformation(aWPlane, globalCS);
02546   
02547   BRepBuilderAPI_MakeVertex mkVertex (aPnt);
02548   TopoDS_Shape aLocalVertex = mkVertex.Shape();
02549   
02550   // Perform transformation
02551   BRepBuilderAPI_Transform aTransformation (aLocalVertex, aTrans, Standard_False);
02552   TopoDS_Shape aGlobalVertex = aTransformation.Shape();
02553   
02554   // Build prs with vertex in globalCS
02555   SALOME_Prs* aPrs = getDisplayer()->BuildPrs( aGlobalVertex );
02556   if ( aPrs != 0 && !aPrs->IsNull() )
02557     GEOMBase_Helper::displayPreview( aPrs, append, update );
02558   
02559 }
02560 
02561 //================================================================
02562 // Function : createShapes
02563 // Purpose  : Create applyed wire, and last segment from entry object
02564 //================================================================
02565 bool EntityGUI_SketcherDlg::createShapes( GEOM::GEOM_Object_ptr theObject,
02566                                           TopoDS_Shape&         theApplyedWire,
02567                                           TopoDS_Shape&         theLastSegment )
02568 {
02569   TopoDS_Shape aShape;
02570   if (  !GEOMBase::GetShape( theObject, aShape ) ||
02571        ( aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX ) )
02572     return false;
02573 
02574   if ( ( Group1Sel->isVisible()  && !Group1Sel->buttonApply->isEnabled() )||
02575        ( Group2Sel->isVisible()  && !Group2Sel->buttonApply->isEnabled() ) ||
02576        ( Group1Sel1Spin->isVisible()  && !Group1Sel1Spin->buttonApply->isEnabled() ) ||
02577        ( Group1Spin->isVisible() && !Group1Spin->buttonApply->isEnabled() ) ||
02578        ( Group2Spin->isVisible() && !Group2Spin->buttonApply->isEnabled() ) ||
02579        ( Group3Spin->isVisible() && !Group3Spin->buttonApply->isEnabled() ) ||
02580        ( Group4Spin->isVisible() && !Group4Spin->buttonApply->isEnabled() ) ) {
02581      theApplyedWire = aShape;
02582      return true;
02583   }
02584 
02585   BRepBuilderAPI_MakeWire aBuilder;
02586   TopExp_Explorer anExp( aShape, TopAbs_EDGE );
02587   while ( 1 ) {
02588     TopoDS_Shape anEdge = anExp.Current();
02589     anExp.Next();
02590     if ( anExp.More() ) // i.e. non-last edge
02591       aBuilder.Add( TopoDS::Edge( anEdge ) );
02592     else {
02593       theLastSegment = anEdge;
02594       break;
02595     }
02596   }
02597 
02598   if ( aBuilder.IsDone() )
02599     theApplyedWire = aBuilder.Shape();
02600 
02601   return true;
02602 }
02603 
02604 //=================================================================================
02605 // function : acceptMouseEvent()
02606 // purpose  :
02607 //=================================================================================
02608 bool EntityGUI_SketcherDlg::acceptMouseEvent() const 
02609 {
02610   return ( (getPnt1ConstructorId() == 1 
02611             || getPnt1ConstructorId() == 0
02612             || myConstructorId == 2)                       //accept mouse event only on absolute and relative selection mode                                                        
02613             && !WPlaneLineEdit->isEnabled());              //or when the constructor is rectangle
02614                                                            //called by EntityGUI::OnMousePress()        
02615 }  
02616 
02617 //=================================================================================
02618 // function : keyPressEvent()
02619 // purpose  :
02620 //=================================================================================
02621 void  EntityGUI_SketcherDlg::keyPressEvent( QKeyEvent* e )
02622 {
02623   QDialog::keyPressEvent( e );
02624   if ( e->isAccepted() )
02625     return;
02626 
02627   if ( e->key() == Qt::Key_F1 ) {
02628     e->accept();
02629     ClickOnHelp();
02630   }
02631 }
02632 
02633 //=================================================================================
02634 // function : initSpinBox()
02635 // purpose  :
02636 //=================================================================================
02637 void EntityGUI_SketcherDlg::initSpinBox( SalomeApp_DoubleSpinBox* spinBox,
02638                                          double min,  double max,
02639                                          double step, const char* quantity )
02640 {
02641   // The same stuff as in GEOMBase_Skeleton::initSpinBox()!
02642   // TODO: Think how to keep the single piece of code...
02643 
02644   // Obtain precision from preferences
02645   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
02646   int aPrecision = resMgr->integerValue( "Geometry", quantity, 6 );
02647   
02648   spinBox->setPrecision( aPrecision );
02649   spinBox->setDecimals( qAbs( aPrecision ) ); // it's necessary to set decimals before the range setting,
02650                                               // by default Qt rounds boundaries to 2 decimals at setRange
02651   spinBox->setRange( min, max );
02652   spinBox->setSingleStep( step );
02653   
02654   // Add a hint for the user saying how to tune precision
02655   QString userPropName = QObject::tr( QString( "GEOM_PREF_%1" ).arg( quantity ).toLatin1().constData() );
02656   spinBox->setProperty( "validity_tune_hint", 
02657                         QVariant( QObject::tr( "GEOM_PRECISION_HINT" ).arg( userPropName ) ) );
02658 }
02659 
02660 //=================================================================================
02661 // function : SetDoubleSpinBoxStep()
02662 // purpose  : Double spin box management
02663 //=================================================================================
02664 void EntityGUI_SketcherDlg::SetDoubleSpinBoxStep( double step )
02665 {
02666   Group1Spin->SpinBox_DX->setSingleStep(step);
02667   Group1Sel1Spin->SpinBox_DX->setSingleStep(step);
02668   Group2Spin->SpinBox_DX->setSingleStep(step);
02669   Group2Spin->SpinBox_DY->setSingleStep(step);
02670   Group3Spin->SpinBox_DX->setSingleStep(step);
02671   Group3Spin->SpinBox_DY->setSingleStep(step);
02672   Group3Spin->SpinBox_DZ->setSingleStep(step);
02673   Group4Spin->SpinBox_DZ->setSingleStep(step);
02674 
02675   // san: Do NOT override the step when a speicifc step value is used
02676   // in some input fields!
02677   //Group4Spin->SpinBox_DX->setSingleStep(step);
02678   //Group4Spin->SpinBox_DY->setSingleStep(step);
02679   //Group4Spin->SpinBox_DS->setSingleStep(step);
02680 }
02681 
02682 //=================================================================================
02683 // function : AddLocalCS()
02684 // purpose  : Add All Coordinates systems in study
02685 //=================================================================================
02686 void EntityGUI_SketcherDlg::AddLocalCS(GEOM::GEOM_Object_var aSelectedObject)
02687 {
02688   QString aName = GEOMBase::GetName( aSelectedObject );
02689   
02690   int index = ComboBox1->findText(aName, Qt::MatchExactly);
02691   
02692   if (index==-1)  // If the working plane hasn't been added yet
02693   {   
02694     myWPlaneList.push_back(aSelectedObject);
02695     myWPlane = aSelectedObject;
02696     addSubshapesToStudy();
02697     myLCSList.push_back(WPlaneToLCS(aSelectedObject));
02698     ComboBox1->addItem(aName); 
02699     index = ComboBox1->count();
02700     ComboBox1->setCurrentIndex(index-1);    
02701   }
02702   else
02703   {
02704     ComboBox1->setCurrentIndex(index);
02705   }
02706   ActivateLocalCS();   
02707 }
02708 
02709 //=================================================================================
02710 // function : FindLocalCS()
02711 // purpose  : Find All Coordinates systems in study
02712 //=================================================================================
02713 void EntityGUI_SketcherDlg::FindLocalCS()
02714 {
02715   ComboBox1->clear();
02716   myWPlaneList.clear();
02717   SalomeApp_Application* app =
02718     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
02719   if ( !app )
02720     return;
02721 
02722   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
02723   if ( !appStudy )
02724     return;
02725 
02726   _PTR(Study) aStudy = appStudy->studyDS();
02727 
02728   //add Global CS
02729   ComboBox1->addItem(tr("GEOM_GCS"));
02730   myWPlaneList.push_back(myGlobalCS);
02731 
02732   // get GEOM component
02733   CORBA::String_var geomIOR = app->orb()->object_to_string( GeometryGUI::GetGeomGen() );
02734   _PTR(SObject) obj = aStudy->FindObjectIOR( geomIOR.in() );
02735   if (!obj)
02736     return;
02737   _PTR(SComponent) fc = obj->GetFatherComponent();
02738   QString geomComp = fc->GetID().c_str();
02739   _PTR(SObject) comp = aStudy->FindObjectID( geomComp.toLatin1().data() );
02740   if ( !comp )
02741     return;
02742 
02743   // browse through all GEOM data tree
02744   _PTR(ChildIterator) it ( aStudy->NewChildIterator( comp ) );
02745   for ( it->InitEx( true ); it->More(); it->Next() ) 
02746   {
02747     _PTR(SObject) child( it->Value() );
02748     CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( child );
02749     GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
02750     if( CORBA::is_nil( geomObj ) ) 
02751       continue;
02752     if (geomObj->GetType() == GEOM_MARKER) 
02753     {
02754       myWPlaneList.push_back(geomObj);
02755       myLCSList.push_back(WPlaneToLCS(geomObj));
02756       ComboBox1->addItem(geomObj->GetName());
02757     }
02758   }
02759 }
02760 
02761 //=================================================================================
02762 // function : WPlaneToLCS ( aWPlane )
02763 // purpose  : 
02764 //=================================================================================
02765 gp_Ax3 EntityGUI_SketcherDlg::WPlaneToLCS( GEOM::GEOM_Object_var geomObj )
02766 {
02767   TopoDS_Shape aShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), geomObj);
02768   
02769   gp_Ax3 aLCS;
02770   if (CORBA::is_nil( geomObj ) || aShape.IsNull())
02771   {
02772     MESSAGE("CORBA::is_nil( geomObj ) || aShape.IsNull()")
02773   }
02774   aLCS.Transform(aShape.Location().Transformation());
02775   if (aShape.ShapeType() == TopAbs_FACE) 
02776   {
02777     GEOM::GEOM_IMeasureOperations_ptr aMeasureOp =
02778     myGeometryGUI->GetGeomGen()->GetIMeasureOperations( getStudyId() );
02779     double Ox, Oy, Oz, Zx, Zy, Zz, Xx, Xy, Xz;
02780     aMeasureOp->GetPosition( geomObj, Ox, Oy, Oz, Zx, Zy, Zz, Xx, Xy, Xz);
02781     if ( aMeasureOp->IsDone() )
02782     {  
02783       gp_Pnt aPnt ( Ox, Oy, Oz );
02784       gp_Dir aDirN ( Zx, Zy, Zz );
02785       gp_Dir aDirX ( Xx, Xy, Xz );
02786       aLCS = gp_Ax3( aPnt, aDirN, aDirX );
02787     }
02788   }
02789   return aLCS;
02790 }
02791 
02792 
02793 //=================================================================================
02794 // function : getPnt1ConstructorId()
02795 // purpose  :
02796 //=================================================================================
02797 int EntityGUI_SketcherDlg::getPnt1ConstructorId() const
02798 { 
02799   int buttonId = GroupPt->ButtonGroup->checkedId(); 
02800 //   MESSAGE("buttonId = "<<buttonId)
02801   return buttonId;
02802 }
02803 
02804 //=================================================================================
02805 // function : getPnt2ConstructorId()
02806 // purpose  :
02807 //=================================================================================
02808 int EntityGUI_SketcherDlg::getPnt2ConstructorId() const
02809 { 
02810   int buttonId = GroupPt2->ButtonGroup->checkedId(); 
02811 //   MESSAGE("buttonId = "<<buttonId)
02812   return buttonId;
02813 }
02814 
02815 //=================================================================================
02816 // function : GetActiveLocalCS()
02817 // purpose  : Get Working plane
02818 //=================================================================================
02819 gp_Ax3 EntityGUI_SketcherDlg::GetActiveLocalCS()
02820 {
02821   int ind = ComboBox1->currentIndex();
02822   if (ind == -1)
02823     return myGeometryGUI->GetWorkingPlane();
02824   
02825   gp_Ax3 aLCS = myLCSList.at(ind);
02826   myWPlane = myWPlaneList.at(ind);
02827 
02828   return aLCS;
02829 }
02830 
02831 //=================================================================================
02832 // function : ActivateLocalCS()
02833 // purpose  : Activate & Fit Working plane
02834 //=================================================================================
02835 void EntityGUI_SketcherDlg::ActivateLocalCS()
02836 {
02837   myGeometryGUI->SetWorkingPlane( GetActiveLocalCS() );
02838   myGeometryGUI->ActiveWorkingPlane();
02839 }
02840 
02841 //=================================================================================
02842 // function : addSubshapeToStudy
02843 // purpose  : virtual method to add new SubObjects if local selection
02844 //=================================================================================
02845 void EntityGUI_SketcherDlg::addSubshapesToStudy()
02846 {
02847   GEOMBase::PublishSubObject(myWPlane);
02848 }