Salome HOME
0021209: Bug GetInPlace with faces. Integrate self-intersections checker.
[modules/geom.git] / src / EntityGUI / EntityGUI_SketcherDlg.cxx
index fc948361659a1d3787abeade3a2bf0b781476099..e3ec23f224823ad4dc1eac56f1284259edb9cdc7 100644 (file)
@@ -1,23 +1,23 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 // GEOM GEOMGUI : GUI for Geometry component
@@ -28,6 +28,9 @@
 #include "EntityGUI_Widgets.h"
 #include <SalomeApp_DoubleSpinBox.h>
 
+#include <OCCViewer_ViewPort3d.h>
+#include <OCCViewer_ViewWindow.h>
+
 #include <GEOMBase.h>
 #include <GeometryGUI.h>
 #include <GEOMImpl_Types.hxx>
@@ -51,6 +54,7 @@
 #include <TopoDS.hxx>
 #include <BRepBuilderAPI_Transform.hxx>
 #include <BRepBuilderAPI_MakeWire.hxx>
+#include <BRepBuilderAPI_MakeVertex.hxx>
 #include <Sketcher_Profile.hxx>
 
 #include <SalomeApp_Study.h>
@@ -76,6 +80,7 @@ EntityGUI_SketcherDlg::EntityGUI_SketcherDlg( GeometryGUI* GUI, QWidget* parent,
     myGeometryGUI( GUI ),
     myLineWidth( lineWidth )
 {
+  SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
   setModal( modal );
   setAttribute( Qt::WA_DeleteOnClose );
 
@@ -86,19 +91,23 @@ EntityGUI_SketcherDlg::EntityGUI_SketcherDlg( GeometryGUI* GUI, QWidget* parent,
   topLayout->setMargin( 9 ); topLayout->setSpacing( 6 );
 
   MainWidget->buttonCancel->setText( tr( "GEOM_BUT_CANCEL" ) );
-  MainWidget->buttonEnd->setText( tr( "GEOM_BUT_END_SKETCH" ) );
+  MainWidget->buttonEnd->setText( tr( "GEOM_BUT_CLOSE" ) );
   MainWidget->buttonClose->setText( tr( "GEOM_BUT_CLOSE_SKETCH" ) );
   MainWidget->buttonHelp->setText( tr( "GEOM_BUT_HELP" ) );
 
-  QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
-  QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_UNDO" ) ) );
-  QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_REDO" ) ) );
+  QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT"      ) ) );
+  QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_UNDO"    ) ) );
+  QPixmap image2( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_REDO"    ) ) );
+  QPixmap image3( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_LINE_2P" ) ) );
+  QPixmap image4( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_ARC"     ) ) );
 
   setWindowTitle( tr( "GEOM_SKETCHER_TITLE" ) );
 
   MainWidget->GroupConstructors->setTitle( tr( "GEOM_SKETCHER_EL" ) );
-  MainWidget->RadioButton1->setText( tr( "GEOM_SKETCHER_SEGMENT" ) );
-  MainWidget->RadioButton2->setText( tr( "GEOM_SKETCHER_ARC" ) );
+  MainWidget->RadioButton1->setText( "" );
+  MainWidget->RadioButton1->setIcon( image3 );
+  MainWidget->RadioButton2->setText( "" );
+  MainWidget->RadioButton2->setIcon( image4 );
   MainWidget->GroupDest->setTitle( tr( "GEOM_SKETCHER_DEST" ) );
   MainWidget->GroupDest1->setTitle( tr( "GEOM_SKETCHER_TYPE" ) );
   MainWidget->RB_Dest1->setText( tr( "GEOM_SKETCHER_POINT" ) );
@@ -122,6 +131,7 @@ EntityGUI_SketcherDlg::EntityGUI_SketcherDlg( GeometryGUI* GUI, QWidget* parent,
 
   topLayout->addWidget(GroupBox1);
   topLayout->addWidget( MainWidget );
+  topLayout->setStretch( 1, 1);
 
   GroupPt = new EntityGUI_Point( MainWidget->DestCnt );
 
@@ -147,7 +157,7 @@ EntityGUI_SketcherDlg::EntityGUI_SketcherDlg( GeometryGUI* GUI, QWidget* parent,
 
   GroupD2 = new EntityGUI_Dir2( MainWidget->DestCnt );
 
-  GroupD2->GroupDir2->setTitle( tr( "GEOM_SKETCHER_DIR" ) );
+  GroupD2->GroupDir2->setTitle( tr( "GEOM_SKETCHER_DIST" ) );
   GroupD2->RB_Dir21->setText( tr( "GEOM_SKETCHER_LENGTH" ) );
   GroupD2->RB_Dir22->setText( tr( "GEOM_SKETCHER_X" ) );
   GroupD2->RB_Dir23->setText( tr( "GEOM_SKETCHER_Y" ) );
@@ -231,6 +241,7 @@ EntityGUI_SketcherDlg::EntityGUI_SketcherDlg( GeometryGUI* GUI, QWidget* parent,
   SkeletonCntlayout->addWidget( Group2Spin, 0, 0 );
   SkeletonCntlayout->addWidget( Group3Spin, 0, 0 );
   SkeletonCntlayout->addWidget( Group4Spin, 0, 0 );
+  //SkeletonCntlayout->setStretch( 0, 1);
   /***************************************************************/
 
   QButtonGroup* ButtonGroup = new QButtonGroup( this );
@@ -238,75 +249,75 @@ EntityGUI_SketcherDlg::EntityGUI_SketcherDlg( GeometryGUI* GUI, QWidget* parent,
   ButtonGroup->addButton( MainWidget->RB_Dest2, 0 );
 
   /* signals and slots connections */
-  connect( MainWidget->buttonEnd,    SIGNAL( clicked() ), this, SLOT( ClickOnEnd() ) );
-  connect( MainWidget->buttonClose,  SIGNAL( clicked() ), this, SLOT( ClickOnEnd() ) );
-  connect( MainWidget->buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
-  connect( MainWidget->buttonHelp,   SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
-
-  connect( Group1Sel->buttonApply,   SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
-  connect( Group1Sel->buttonUndo,    SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
-  connect( Group1Sel->buttonRedo,    SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
-  connect( Group2Sel->buttonApply,   SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
-  connect( Group2Sel->buttonUndo,    SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
-  connect( Group2Sel->buttonRedo,    SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
-  connect( Group1Sel1Spin->buttonApply,   SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
-  connect( Group1Sel1Spin->buttonUndo,    SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
-  connect( Group1Sel1Spin->buttonRedo,    SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
-  connect( Group1Spin->buttonApply,  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
-  connect( Group1Spin->buttonUndo,   SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
-  connect( Group1Spin->buttonRedo,   SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
-  connect( Group2Spin->buttonApply,  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
-  connect( Group2Spin->buttonUndo,   SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
-  connect( Group2Spin->buttonRedo,   SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
-  connect( Group3Spin->buttonApply,  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
-  connect( Group3Spin->buttonUndo,   SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
-  connect( Group3Spin->buttonRedo,   SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) ) ;
-  connect( Group4Spin->buttonApply,  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
-  connect( Group4Spin->buttonUndo,   SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
-  connect( Group4Spin->buttonRedo,   SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
-
-  connect( MainWidget->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( TypeClicked( int ) ) );
-  connect( ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( DestClicked( int ) ) );
-  connect( GroupPt->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( PointClicked( int ) ) );
-  connect( GroupPt2->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( Point2Clicked( int ) ) );
-  connect( GroupD1->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( Dir1Clicked( int ) ) );
-  connect( GroupD2->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( Dir2Clicked( int ) ));
-
-  connect( Group1Sel->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
-  connect( Group1Sel->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
-
-  connect( Group2Sel->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
-  connect( Group2Sel->LineEdit2,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
-  connect( Group2Sel->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
-  connect( Group2Sel->PushButton2, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
-
-  connect( Group1Sel1Spin->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
-  connect( Group1Sel1Spin->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
-  connect( Group1Sel1Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
-
-  connect( Group1Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
-  connect( Group2Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
-  connect( Group2Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
-  connect( Group3Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
-  connect( Group3Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
-  connect( Group3Spin->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
-  connect( Group4Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
-  connect( Group4Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
-  connect( Group4Spin->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
-  connect( Group4Spin->SpinBox_DS, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
-
-  connect( Group3Spin->checkBox, SIGNAL( stateChanged( int ) ), this, SLOT( CheckBoxClicked( int ) ) );
-  connect( Group4Spin->checkBox, SIGNAL( stateChanged( int ) ), this, SLOT( CheckBoxClicked( int ) ) );
-  connect( Group2Sel->checkBox, SIGNAL( stateChanged( int ) ), this, SLOT( CheckBoxClicked( int ) ) );
-  connect( Group1Sel1Spin->checkBox, SIGNAL( stateChanged( int ) ), this, SLOT( CheckBoxClicked( int ) ) );
-
-  connect( ComboBox1, SIGNAL( activated( int ) ), this, SLOT( SelectionIntoArgument() ) );
-  connect( planeButton, SIGNAL( clicked() ), this, SLOT( ActivateLocalCS() ) );
-
-  connect( myGeometryGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
-
-  connect( myGeometryGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
-  connect( myGeometryGUI, SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
+  connect( MainWidget->buttonEnd,    SIGNAL( clicked() ),              this, SLOT( ClickOnEnd() ) );
+  connect( MainWidget->buttonClose,  SIGNAL( clicked() ),              this, SLOT( ClickOnEnd() ) );
+  connect( MainWidget->buttonCancel, SIGNAL( clicked() ),              this, SLOT( ClickOnCancel() ) );
+  connect( MainWidget->buttonHelp,   SIGNAL( clicked() ),              this, SLOT( ClickOnHelp() ) );
+
+  connect( Group1Sel->buttonApply,   SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
+  connect( Group1Sel->buttonUndo,    SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
+  connect( Group1Sel->buttonRedo,    SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) );
+  connect( Group2Sel->buttonApply,   SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
+  connect( Group2Sel->buttonUndo,    SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
+  connect( Group2Sel->buttonRedo,    SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) );
+  connect( Group1Sel1Spin->buttonApply,SIGNAL( clicked() ),            this, SLOT( ClickOnApply() ) );
+  connect( Group1Sel1Spin->buttonUndo, SIGNAL( clicked() ),            this, SLOT( ClickOnUndo() ) );
+  connect( Group1Sel1Spin->buttonRedo, SIGNAL( clicked() ),            this, SLOT( ClickOnRedo() ) );
+  connect( Group1Spin->buttonApply,  SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
+  connect( Group1Spin->buttonUndo,   SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
+  connect( Group1Spin->buttonRedo,   SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) );
+  connect( Group2Spin->buttonApply,  SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
+  connect( Group2Spin->buttonUndo,   SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
+  connect( Group2Spin->buttonRedo,   SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) );
+  connect( Group3Spin->buttonApply,  SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
+  connect( Group3Spin->buttonUndo,   SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
+  connect( Group3Spin->buttonRedo,   SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) ) ;
+  connect( Group4Spin->buttonApply,  SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
+  connect( Group4Spin->buttonUndo,   SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
+  connect( Group4Spin->buttonRedo,   SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) );
+
+  connect( MainWidget->ButtonGroup,  SIGNAL( buttonClicked( int ) ),   this, SLOT( TypeClicked( int ) ) );
+  connect( ButtonGroup,              SIGNAL( buttonClicked( int ) ),   this, SLOT( DestClicked( int ) ) );
+  connect( GroupPt->ButtonGroup,     SIGNAL( buttonClicked( int ) ),   this, SLOT( PointClicked( int ) ) );
+  connect( GroupPt2->ButtonGroup,    SIGNAL( buttonClicked( int ) ),   this, SLOT( Point2Clicked( int ) ) );
+  connect( GroupD1->ButtonGroup,     SIGNAL( buttonClicked( int ) ),   this, SLOT( Dir1Clicked( int ) ) );
+  connect( GroupD2->ButtonGroup,     SIGNAL( buttonClicked( int ) ),   this, SLOT( Dir2Clicked( int ) ));
+
+  connect( Group1Sel->LineEdit1,     SIGNAL( returnPressed() ),        this, SLOT( LineEditReturnPressed() ) );
+  connect( Group1Sel->PushButton1,   SIGNAL( clicked() ),              this, SLOT( SetEditCurrentArgument() ) );
+
+  connect( Group2Sel->LineEdit1,     SIGNAL( returnPressed() ),        this, SLOT( LineEditReturnPressed() ) );
+  connect( Group2Sel->LineEdit2,     SIGNAL( returnPressed() ),        this, SLOT( LineEditReturnPressed() ) );
+  connect( Group2Sel->PushButton1,   SIGNAL( clicked() ),              this, SLOT( SetEditCurrentArgument() ) );
+  connect( Group2Sel->PushButton2,   SIGNAL( clicked() ),              this, SLOT( SetEditCurrentArgument() ) );
+
+  connect( Group1Sel1Spin->LineEdit1,SIGNAL( returnPressed() ),        this, SLOT( LineEditReturnPressed() ) );
+  connect( Group1Sel1Spin->PushButton1,SIGNAL( clicked() ),            this, SLOT( SetEditCurrentArgument() ) );
+  connect( Group1Sel1Spin->SpinBox_DX,SIGNAL( valueChanged( double ) ),this, SLOT( ValueChangedInSpinBox( double ) ) );
+
+  connect( Group1Spin->SpinBox_DX,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
+  connect( Group2Spin->SpinBox_DX,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
+  connect( Group2Spin->SpinBox_DY,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
+  connect( Group3Spin->SpinBox_DX,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
+  connect( Group3Spin->SpinBox_DY,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
+  connect( Group3Spin->SpinBox_DZ,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
+  connect( Group4Spin->SpinBox_DX,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
+  connect( Group4Spin->SpinBox_DY,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
+  connect( Group4Spin->SpinBox_DZ,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
+  connect( Group4Spin->SpinBox_DS,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
+
+  connect( Group3Spin->checkBox,     SIGNAL( stateChanged( int ) ),    this, SLOT( CheckBoxClicked( int ) ) );
+  connect( Group4Spin->checkBox,     SIGNAL( stateChanged( int ) ),    this, SLOT( CheckBoxClicked( int ) ) );
+  connect( Group2Sel->checkBox,      SIGNAL( stateChanged( int ) ),    this, SLOT( CheckBoxClicked( int ) ) );
+  connect( Group1Sel1Spin->checkBox, SIGNAL( stateChanged( int ) ),    this, SLOT( CheckBoxClicked( int ) ) );
+
+  connect( ComboBox1,                SIGNAL( activated( int ) ),       this, SLOT( SelectionIntoArgument() ) );
+  connect( planeButton,              SIGNAL( clicked() ),              this, SLOT( ActivateLocalCS() ) );
+
+  connect( myGeometryGUI,            SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
+
+  connect( myGeometryGUI,            SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
+  connect( myGeometryGUI,            SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
   
   // install event filter on spin-boxes to provide Apply action on Return pressed
   Group1Spin->SpinBox_DX->installEventFilter(this);
@@ -343,27 +354,27 @@ bool EntityGUI_SketcherDlg::eventFilter (QObject* object, QEvent* event)
 {
   if (event->type() == QEvent::KeyPress) {
     QKeyEvent* ke = (QKeyEvent*)event;
-    if (ke->key() == Qt::Key_Return) {
+    if ( ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter ) {
       if (object == Group1Spin->SpinBox_DX) {
-        Group1Spin->buttonApply->animateClick();
+        Group1Spin->buttonApply->click();
         return true;
       } else if (object == Group1Sel1Spin->SpinBox_DX) {
-        Group1Sel1Spin->buttonApply->animateClick();
+        Group1Sel1Spin->buttonApply->click();
         return true;
       } else if (object == Group2Spin->SpinBox_DX ||
                  object == Group2Spin->SpinBox_DY) {
-        Group2Spin->buttonApply->animateClick();
+        Group2Spin->buttonApply->click();
         return true;
       } else if (object == Group3Spin->SpinBox_DX ||
                  object == Group3Spin->SpinBox_DY ||
                  object == Group3Spin->SpinBox_DZ) {
-        Group3Spin->buttonApply->animateClick();
+        Group3Spin->buttonApply->click();
         return true;
       } else if (object == Group4Spin->SpinBox_DX ||
                  object == Group4Spin->SpinBox_DY ||
                  object == Group4Spin->SpinBox_DZ ||
                  object == Group4Spin->SpinBox_DS) {
-        Group4Spin->buttonApply->animateClick();
+        Group4Spin->buttonApply->click();
         return true;
       }
     }
@@ -382,6 +393,7 @@ bool EntityGUI_SketcherDlg::eventFilter (QObject* object, QEvent* event)
 void EntityGUI_SketcherDlg::Init()
 {
   /* init variables */
+  autoApply = false;
   myEditCurrentArgument = Group1Sel->LineEdit1;
   myCommand.append( "Sketcher" );
   myUndoCommand.append( "Sketcher" );
@@ -429,7 +441,7 @@ void EntityGUI_SketcherDlg::Init()
   resize(100,100);
 
   ActivateLocalCS();
-  GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
+  GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
 }
 
 
@@ -449,6 +461,8 @@ void EntityGUI_SketcherDlg::InitClick()
   Group2Spin->hide();
   Group3Spin->hide();
   Group4Spin->hide();
+  globalSelection(); // close local selection to clear it
+  localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
 }
 
 
@@ -460,6 +474,7 @@ void EntityGUI_SketcherDlg::TypeClicked( int constructorId )
 {
   myConstructorId = constructorId;
   if ( myConstructorId == 0 ) {    // SEGMENT
+    GroupPt2->RB_Point1->setChecked( true );
     GroupPt2->setEnabled( false );
     GroupD2->setEnabled( true );
     MainWidget->RB_Dest1->setEnabled( true );
@@ -468,6 +483,7 @@ void EntityGUI_SketcherDlg::TypeClicked( int constructorId )
   }
   else if (  myConstructorId == 1 ) { // ARC
     GroupPt2->setEnabled( true );
+    GroupD2->RB_Dir21->setChecked( true );
     GroupD2->setEnabled( false );
     MainWidget->RB_Dest1->setEnabled( true ); 
     MainWidget->RB_Dest1->setChecked( true );
@@ -505,6 +521,7 @@ void EntityGUI_SketcherDlg::DestClicked( int constructorId )
     Group4Spin->checkBox->hide();
     Dir1Clicked( 2 );  // Angle
   }
+  resize( minimumSizeHint() );
 }
 
 //=================================================================================
@@ -513,10 +530,18 @@ void EntityGUI_SketcherDlg::DestClicked( int constructorId )
 //=================================================================================
 void EntityGUI_SketcherDlg::PointClicked( int constructorId )
 {
+  MESSAGE("PointClicked")
   myConstructorPntId = constructorId;  
-  GroupPt2->RB_Point1->setChecked( true );
-  GroupPt->RB_Point3->setEnabled( true ); 
-  Point2Clicked( 1 );
+  GroupPt->RB_Point3->setEnabled( true );
+  int buttonId = GroupPt2->ButtonGroup->checkedId();
+  MESSAGE("checkedId ="<< buttonId)
+  if (buttonId >= 0){           // = If a button is checked
+    Point2Clicked(buttonId);
+  }
+  else{ 
+    GroupPt2->RB_Point1->setChecked( true );
+    Point2Clicked( 1 ); 
+  }
 }
 
 //=================================================================================
@@ -525,6 +550,7 @@ void EntityGUI_SketcherDlg::PointClicked( int constructorId )
 //=================================================================================
 void EntityGUI_SketcherDlg::Point2Clicked( int constructorId )
 {
+  MESSAGE("Point2Clicked")
   InitClick();
 
   // Get setting of step value from file configuration
@@ -544,7 +570,7 @@ void EntityGUI_SketcherDlg::Point2Clicked( int constructorId )
       Group2Spin->show();
       Group2Spin->buttonApply->setFocus();
 
-      GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
+      GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
     }
     else if ( constructorId == 0 ){   // Point + radius
       mySketchType = PT_ABS_RADIUS;
@@ -554,16 +580,16 @@ void EntityGUI_SketcherDlg::Point2Clicked( int constructorId )
       Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X2" ) );
       Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y2" ) );
       Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_RADIUS2" ) ); 
-      myDX = 0.0;
-      Group3Spin->SpinBox_DX->setValue( myDX );
-      myDY = 0.0;
-      Group3Spin->SpinBox_DY->setValue( myDY );
+      myX = 0.0;
+      Group3Spin->SpinBox_DX->setValue( myX );
+      myY = 0.0;
+      Group3Spin->SpinBox_DY->setValue( myY );
       myRadius=0.0;
       Group3Spin->SpinBox_DZ->setValue( myRadius ); 
       Group3Spin->show();
       Group3Spin->buttonApply->setFocus();
 
-      GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
+      GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
     }
     else if ( constructorId == 2 ){   // Point + center
       mySketchType = PT_ABS_CENTER;
@@ -571,22 +597,22 @@ void EntityGUI_SketcherDlg::Point2Clicked( int constructorId )
       initSpinBox( Group4Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
       initSpinBox( Group4Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
       initSpinBox( Group4Spin->SpinBox_DS, COORD_MIN, COORD_MAX, step, "length_precision" );
-      Group4Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X2" ) );
-      Group4Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y2" ) );
-      Group4Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_CENTER_X" ) );
-      Group4Spin->TextLabel4->setText( tr( "GEOM_SKETCHER_CENTER_Y" ) ); 
-      myDX = 0.0;
-      Group4Spin->SpinBox_DX->setValue( myDX );
-      myDY = 0.0;
-      Group4Spin->SpinBox_DY->setValue( myDY );
+      Group4Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_X2" ) );
+      Group4Spin->TextLabel4->setText( tr( "GEOM_SKETCHER_Y2" ) );
+      Group4Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_CENTER_X" ) );
+      Group4Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_CENTER_Y" ) ); 
       myXc = 0.0;
-      Group4Spin->SpinBox_DZ->setValue( myXc ); 
+      Group4Spin->SpinBox_DX->setValue( myXc );
       myYc = 0.0;
-      Group4Spin->SpinBox_DS->setValue( myYc );
+      Group4Spin->SpinBox_DY->setValue( myYc );
+      myX = 0.0;
+      Group4Spin->SpinBox_DZ->setValue( myX ); 
+      myY = 0.0;
+      Group4Spin->SpinBox_DS->setValue( myY );
       Group4Spin->show();
       Group4Spin->buttonApply->setFocus();
 
-      GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
+      GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
     }
 
   }
@@ -604,7 +630,7 @@ void EntityGUI_SketcherDlg::Point2Clicked( int constructorId )
       Group2Spin->show();
       Group2Spin->buttonApply->setFocus();
 
-      GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
+      GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
     }
     else if ( constructorId == 0 ){   // Point + radius 
       mySketchType = PT_REL_RADIUS;
@@ -623,7 +649,7 @@ void EntityGUI_SketcherDlg::Point2Clicked( int constructorId )
       Group3Spin->show();
       Group3Spin->buttonApply->setFocus();
 
-      GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
+      GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
     }
     else if ( constructorId == 2 ){   // Point + center
       mySketchType = PT_REL_CENTER;
@@ -631,22 +657,22 @@ void EntityGUI_SketcherDlg::Point2Clicked( int constructorId )
       initSpinBox( Group4Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
       initSpinBox( Group4Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
       initSpinBox( Group4Spin->SpinBox_DS, COORD_MIN, COORD_MAX, step, "length_precision" );
-      Group4Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_DX2" ) );
-      Group4Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_DY2" ) );
-      Group4Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_CENTER_DX" ) );
-      Group4Spin->TextLabel4->setText( tr( "GEOM_SKETCHER_CENTER_DY" ) ); 
-      myDX = 0.0;
-      Group4Spin->SpinBox_DX->setValue( myDX );
-      myDY = 0.0;
-      Group4Spin->SpinBox_DY->setValue( myDY );
+      Group4Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_DX2" ) );
+      Group4Spin->TextLabel4->setText( tr( "GEOM_SKETCHER_DY2" ) );
+      Group4Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_CENTER_DX" ) );
+      Group4Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_CENTER_DY" ) ); 
       myDXc = 0.0;
-      Group4Spin->SpinBox_DZ->setValue( myDXc ); 
+      Group4Spin->SpinBox_DX->setValue( myDXc );
       myDYc = 0.0;
-      Group4Spin->SpinBox_DS->setValue( myDYc );
+      Group4Spin->SpinBox_DY->setValue( myDYc );
+      myDX = 0.0;
+      Group4Spin->SpinBox_DZ->setValue( myDX ); 
+      myDY = 0.0;
+      Group4Spin->SpinBox_DS->setValue( myDY );
       Group4Spin->show();
       Group4Spin->buttonApply->setFocus();
 
-      GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
+      GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
     }
 
   }
@@ -675,8 +701,8 @@ void EntityGUI_SketcherDlg::Point2Clicked( int constructorId )
     else if ( constructorId == 2 ){   // Point + center 
       mySketchType = PT_SEL_CENTER;
       myEditCurrentArgument = Group2Sel->LineEdit1;
-      Group2Sel->TextLabel1->setText( tr( "GEOM_SKETCHER_END_POINT2" ) );  
-      Group2Sel->TextLabel2->setText( tr( "GEOM_SKETCHER_CENTER2" ) );
+      Group2Sel->TextLabel2->setText( tr( "GEOM_SKETCHER_END_POINT2" ) );  
+      Group2Sel->TextLabel1->setText( tr( "GEOM_SKETCHER_CENTER2" ) );
       Group2Sel->LineEdit1->setEnabled(true);
       Group2Sel->PushButton1->setDown(true);
       Group2Sel->LineEdit2->setEnabled(false);
@@ -687,6 +713,7 @@ void EntityGUI_SketcherDlg::Point2Clicked( int constructorId )
     }
 
   }
+  resize( minimumSizeHint() );
   connect( myGeometryGUI->getApp()->selectionMgr(),
           SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
   
@@ -700,8 +727,15 @@ void EntityGUI_SketcherDlg::Point2Clicked( int constructorId )
 void EntityGUI_SketcherDlg::Dir1Clicked( int constructorId )
 {
   myConstructorDirId = constructorId;
-  GroupD2->RB_Dir21->setChecked( true );
-  Dir2Clicked( 2 );
+  int dirButtonId = GroupD2->ButtonGroup->checkedId();
+  MESSAGE("checkedId ="<< dirButtonId)
+  if (dirButtonId >= 0){           // = If a button is checked
+    Dir2Clicked(dirButtonId);
+  }
+  else{ 
+    GroupD2->RB_Dir21->setChecked( true );
+    Dir2Clicked( 2 ); 
+  }
 }
 
 
@@ -890,8 +924,8 @@ void EntityGUI_SketcherDlg::Dir2Clicked( int constructorId )
       }
     }
   }
-
-  GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
+  resize( minimumSizeHint() );
+  GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
 }
 
 //=================================================================================
@@ -902,7 +936,7 @@ void EntityGUI_SketcherDlg::CheckBoxClicked(int State)
 {
   myCheckFlag = State;
 
-  GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
+  GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
 }
 
 
@@ -944,16 +978,16 @@ void EntityGUI_SketcherDlg::ClickOnEnd()
       myCommand.append( ":WW" );
   }
   else {
-    // PAL16008 (Sketcher Validation should be equal to Apply&Close)
-    if ( Group1Spin->buttonApply->isEnabled() && Group1Spin->isVisible() ||
-         Group2Spin->buttonApply->isEnabled() && Group2Spin->isVisible() ||
-         Group3Spin->buttonApply->isEnabled() && Group3Spin->isVisible() ||
-         Group4Spin->buttonApply->isEnabled() && Group4Spin->isVisible() ||
-         Group1Sel->buttonApply->isEnabled() && Group1Sel->isVisible()  ||
-        Group2Sel->buttonApply->isEnabled() && Group2Sel->isVisible()  ||
-         Group1Sel1Spin->buttonApply->isEnabled() && Group1Sel1Spin->isVisible() )  {     
+    /*// PAL16008 (Sketcher Validation should be equal to Apply&Close)
+    if ( ( Group1Spin->buttonApply->isEnabled() && Group1Spin->isVisible() ) ||
+         ( Group2Spin->buttonApply->isEnabled() && Group2Spin->isVisible() ) ||
+         ( Group3Spin->buttonApply->isEnabled() && Group3Spin->isVisible() ) ||
+         ( Group4Spin->buttonApply->isEnabled() && Group4Spin->isVisible() ) ||
+         ( Group1Sel->buttonApply->isEnabled()  && Group1Sel->isVisible()  ) ||
+         ( Group2Sel->buttonApply->isEnabled()  && Group2Sel->isVisible()  ) ||
+         ( Group1Sel1Spin->buttonApply->isEnabled() && Group1Sel1Spin->isVisible() ) )  {     
       ClickOnApply();
-    }
+    }*/
     myIsAllAdded = true;
   }
 
@@ -989,7 +1023,7 @@ bool EntityGUI_SketcherDlg::ClickOnApply()
   setEnabledRedo( false );
 
   myIsApply = true;
-  GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
+  GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
   myIsApply = false;
 
   // Set focus to SpinBox_DX
@@ -1013,7 +1047,7 @@ bool EntityGUI_SketcherDlg::ClickOnApply()
     (Group4Spin->SpinBox_DX)->setFocus();
     (Group4Spin->SpinBox_DX)->selectAll();
   }
-
+  
   return true;
 }
 
@@ -1069,7 +1103,7 @@ void EntityGUI_SketcherDlg::ClickOnUndo()
 
   setEnabledRedo( true );
 
-  GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
+  GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
 }
 
 //=================================================================================
@@ -1093,7 +1127,7 @@ void EntityGUI_SketcherDlg::ClickOnRedo()
   if ( myUndoCommand.count() == 1 )
     setEnabledRedo( false );
 
-  GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
+  GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
 }
 
 //=================================================================================
@@ -1132,6 +1166,7 @@ void EntityGUI_SketcherDlg::setEnabledRedo( bool value )
 //=================================================================================
 void EntityGUI_SketcherDlg::SelectionIntoArgument()
 {
+  MESSAGE("EntityGUI_SketcherDlg::SelectionIntoArgument")
   myEditCurrentArgument->setText( "" );
   double tmpX = myX;
   double tmpY = myY;
@@ -1149,6 +1184,7 @@ void EntityGUI_SketcherDlg::SelectionIntoArgument()
   aSelMgr->selectedObjects(aSelList);
 
   int nbSel = aSelList.Extent();
+  MESSAGE("NbSel = "<<nbSel)
   if (nbSel == 1 && myEditCurrentArgument == Group1Sel->LineEdit1) {
     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
     if ( !CORBA::is_nil(aSelectedObject) ) {
@@ -1249,27 +1285,27 @@ void EntityGUI_SketcherDlg::SelectionIntoArgument()
 
         gp_Pnt aPnt;
         if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) {
-          myX = aPnt.X();
-          myY = aPnt.Y();
+          myXc = aPnt.X();
+          myYc = aPnt.Y();
           Group2Sel->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
           if( Group4Spin->isVisible() && mySketchType == PT_ABS ) {
             disconnect( Group4Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
             disconnect( Group4Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
-            Group4Spin->SpinBox_DX->setValue(myX);
-            Group4Spin->SpinBox_DY->setValue(myY);
+            Group4Spin->SpinBox_DX->setValue(myXc);
+            Group4Spin->SpinBox_DY->setValue(myYc);
             connect( Group4Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
             connect( Group4Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
           } else if ( Group4Spin->isVisible() && mySketchType == PT_RELATIVE ) {
             if ( myLastX1 && myLastY1 ) {
-              Group4Spin->SpinBox_DX->setValue(myX - myLastX1);
-              Group4Spin->SpinBox_DY->setValue(myY - myLastY1);
+              Group4Spin->SpinBox_DX->setValue(myXc - myLastX1);
+              Group4Spin->SpinBox_DY->setValue(myYc - myLastY1);
             } else {
               if ( mySketchState != FIRST_POINT ) {
-                Group4Spin->SpinBox_DX->setValue(myX - tmpX);
-                Group4Spin->SpinBox_DY->setValue(myY - tmpY);
+                Group4Spin->SpinBox_DX->setValue(myXc - tmpX);
+                Group4Spin->SpinBox_DY->setValue(myYc - tmpY);
               } else {
-                Group4Spin->SpinBox_DX->setValue(myX);
-                Group4Spin->SpinBox_DY->setValue(myY);
+                Group4Spin->SpinBox_DX->setValue(myXc);
+                Group4Spin->SpinBox_DY->setValue(myYc);
               }
             }
           }
@@ -1296,27 +1332,27 @@ void EntityGUI_SketcherDlg::SelectionIntoArgument()
 
         gp_Pnt aPnt;
         if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) {
-          myXc = aPnt.X();
-          myYc = aPnt.Y();
+          myX = aPnt.X();
+          myY = aPnt.Y();
           Group2Sel->LineEdit2->setText( GEOMBase::GetName( aSelectedObject ) );
           if( Group4Spin->isVisible() && mySketchType == PT_ABS ) {
             disconnect( Group4Spin->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
             disconnect( Group4Spin->SpinBox_DS, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
-            Group4Spin->SpinBox_DZ->setValue(myXc);
-            Group4Spin->SpinBox_DS->setValue(myYc);
+            Group4Spin->SpinBox_DZ->setValue(myX);
+            Group4Spin->SpinBox_DS->setValue(myY);
             connect( Group4Spin->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
             connect( Group4Spin->SpinBox_DS, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
           } else if ( Group4Spin->isVisible() && mySketchType == PT_RELATIVE ) {
             if ( myLastX1 && myLastY1 ) {
-              Group4Spin->SpinBox_DZ->setValue(myXc - myLastX1);
-              Group4Spin->SpinBox_DS->setValue(myYc - myLastY1);
+              Group4Spin->SpinBox_DZ->setValue(myX - myLastX1);
+              Group4Spin->SpinBox_DS->setValue(myY - myLastY1);
             } else {
               if ( mySketchState != FIRST_POINT ) {
-                Group4Spin->SpinBox_DZ->setValue(myXc - tmpX);
-                Group4Spin->SpinBox_DS->setValue(myYc - tmpY);
+                Group4Spin->SpinBox_DZ->setValue(myX - tmpX);
+                Group4Spin->SpinBox_DS->setValue(myY - tmpY);
               } else {
-                Group4Spin->SpinBox_DZ->setValue(myXc);
-                Group4Spin->SpinBox_DS->setValue(myYc);
+                Group4Spin->SpinBox_DZ->setValue(myX);
+                Group4Spin->SpinBox_DS->setValue(myY);
               }
             }
           }
@@ -1324,10 +1360,19 @@ void EntityGUI_SketcherDlg::SelectionIntoArgument()
       }
     }
   }
-
-
-
-  GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
+  if (nbSel == 0){                 // If no object selected
+    myX=tmpX;                      // Don't change the point coordinates
+    myY=tmpY;                      // and don't redisplay the preview
+  }
+  else if(!autoApply){
+    GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
+  }
+  if ( autoApply ){    
+    ClickOnApply();
+    autoApply = false;
+  }
+  this->activateWindow();
+  
 }
 
 
@@ -1416,6 +1461,7 @@ void EntityGUI_SketcherDlg::DeactivateActiveDialog()
 //=================================================================================
 void EntityGUI_SketcherDlg::ActivateThisDialog()
 {
+  MESSAGE("EntityGUI_SketcherDlg::ActivateThisDialog()")
   myGeometryGUI->EmitSignalDeactivateDialog();
   setEnabled( true );
   myGeometryGUI->SetActiveDialogBox( this );
@@ -1445,8 +1491,8 @@ void EntityGUI_SketcherDlg::ActivateThisDialog()
      myEditCurrentArgument = Group2Sel->LineEdit2;
      myEditCurrentArgument->setFocus();
    }
-
-  GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
+   
+  GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
 }
 
 
@@ -1467,12 +1513,77 @@ void EntityGUI_SketcherDlg::enterEvent( QEvent* )
 //=================================================================================
 void EntityGUI_SketcherDlg::closeEvent( QCloseEvent* e )
 {
+  MESSAGE("EntityGUI_SketcherDlg::closeEvent")
   //myGeometryGUI->SetState( -1 );
   disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
   myGeometryGUI->getApp()->updateActions();
   QDialog::closeEvent( e );
 }
 
+//=================================================================================
+// function : OnPointSelected
+// purpose  :
+//=================================================================================
+void EntityGUI_SketcherDlg::OnPointSelected(Qt::KeyboardModifiers modifiers, const gp_Pnt& thePnt)
+{
+  MESSAGE("EntityGUI_SketcherDlg::OnPointSelected")
+  
+  SUIT_ViewWindow*       theViewWindow  = getDesktop()->activeWindow();
+  OCCViewer_ViewPort3d*  vp             = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
+  QString                theImgFileName = vp->backgroundImageFilename();
+  
+  double x, y;
+  x = y = 0;
+  
+  BRepBuilderAPI_MakeVertex mkVertex (thePnt);
+  TopoDS_Shape aShape = mkVertex.Shape();
+  
+  // Taking into account LocalCS
+  gp_Ax3 aWPlane = GetActiveLocalCS();
+  gp_Trsf aTrans;
+
+  aTrans.SetTransformation(aWPlane);
+  BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
+  aShape = aTransformation.Shape();
+  
+  gp_Pnt aTrsfPnt; 
+  GEOMBase::VertexToPoint( aShape, aTrsfPnt );
+  
+  autoApply = ( (getPnt2ConstructorId() == 1) && (!theImgFileName.isEmpty()) );  // If no additional argument needed after selection and there is a backgroundimage
+                                                                                 // -> apply automatically 
+  
+  if ( getPnt1ConstructorId() == 0 ){                    // Relative selection mode
+    x = aTrsfPnt.X() - myLastX1;
+    y = aTrsfPnt.Y() - myLastY1;
+  }
+  else {
+    x = aTrsfPnt.X();
+    y = aTrsfPnt.Y();
+  }
+  switch (getPnt2ConstructorId()){
+    case 1:
+      Group2Spin->SpinBox_DX->setValue( x );
+      Group2Spin->SpinBox_DY->setValue( y );
+      Group2Spin->buttonApply->setFocus();               // Previous setFocus (during preview) may have been inoperative if it was disabled 
+      break;
+    case 0:
+      Group3Spin->SpinBox_DX->setValue( x );
+      Group3Spin->SpinBox_DY->setValue( y );
+      Group3Spin->buttonApply->setFocus(); 
+      break;
+    case 2:
+      if (modifiers == Qt::MetaModifier){                // Select center with Meta key
+        Group4Spin->SpinBox_DX->setValue( x );
+        Group4Spin->SpinBox_DY->setValue( y );
+      }
+      else{                                              // Select end point
+        Group4Spin->SpinBox_DZ->setValue( x );
+        Group4Spin->SpinBox_DS->setValue( y );
+      }
+      Group4Spin->buttonApply->setFocus(); 
+      break;
+  }
+}
 
 //=================================================================================
 // function : ValueChangedInSpinBox()
@@ -1480,9 +1591,10 @@ void EntityGUI_SketcherDlg::closeEvent( QCloseEvent* e )
 //=================================================================================
 void EntityGUI_SketcherDlg::ValueChangedInSpinBox( double newValue )
 {
+  MESSAGE("EntityGUI_SketcherDlg::ValueChangedInSpinBox")
   QObject* send = (QObject*)sender();
-  Standard_Real vx, vy, vz, vs, minRad;
-  vx = vy = vz = vs = minRad =0.0;
+  Standard_Real vx, vy, vz, vs, minRad, dx, dy;
+  vx = vy = vz = vs = minRad = dx = dy = 0.0;
 
   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
   int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
@@ -1513,17 +1625,25 @@ void EntityGUI_SketcherDlg::ValueChangedInSpinBox( double newValue )
     vy = Group3Spin->SpinBox_DY->value(); vyStr = Group3Spin->SpinBox_DY->text();
     vz = Group3Spin->SpinBox_DZ->value();
     if ( (mySketchType == PT_REL_RADIUS || mySketchType == PT_ABS_RADIUS) && (vx != 0 || vy != 0) ) {  
-      minRad = 0.5 * Sqrt(vx * vx + vy * vy);                             //Computation of the minimum acceptable radius for the arc calculation
+      if (mySketchType == PT_ABS_RADIUS){
+        dx = vx - myLastX1;
+        dy = vy - myLastY1;
+      }
+      else{
+        dx = vx;
+        dy = vy;
+      }
+      minRad = 0.5 * Sqrt(dx * dx + dy * dy);                             //Computation of the minimum acceptable radius for the arc calculation
       if (aPrecision >= 0)    // 'f' format in the QString             
-       LastDecimal = aPrecision;
+        LastDecimal = aPrecision;
       else                    // 'g' format in the Qstring
-       LastDecimal = qAbs( aPrecision ) - ceil( log10(minRad) ); 
+        LastDecimal = qAbs( aPrecision ) - ceil( log10(minRad) ); 
       minRad = ceil(pow(10,LastDecimal) * minRad) / pow(10,LastDecimal);  // Rounded up at the last allowed decimal place
       if ( Abs(vz) < minRad){
-       if (vz < 0.0)
-         Group3Spin->SpinBox_DZ->setValue( - minRad );
-       else 
-          Group3Spin->SpinBox_DZ->setValue( minRad );
+        if (vz < 0.0)
+          Group3Spin->SpinBox_DZ->setValue( - minRad );
+        else 
+          Group3Spin->SpinBox_DZ->setValue( minRad );
       }
     }
     vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
@@ -1532,18 +1652,26 @@ void EntityGUI_SketcherDlg::ValueChangedInSpinBox( double newValue )
     vx = Group3Spin->SpinBox_DX->value(); vxStr = Group3Spin->SpinBox_DX->text();
     vy = newValue;                        vyStr = newValueStr;
     vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
-    if ( (mySketchType == PT_REL_RADIUS || mySketchType == PT_ABS_RADIUS) && (vx != 0 || vy != 0)){  
-      minRad = 0.5 * Sqrt(vx * vx + vy * vy);                            //Computation of the minimum acceptable radius for the arc calculation
+    if ( (mySketchType == PT_REL_RADIUS || mySketchType == PT_ABS_RADIUS) && (vx != 0 || vy != 0)){
+      if (mySketchType == PT_ABS_RADIUS){
+        dx = vx - myLastX1;
+        dy = vy - myLastY1;
+      }
+      else{
+        dx = vx;
+        dy = vy;
+      }    
+      minRad = 0.5 * Sqrt(dx * dx + dy * dy);                            //Computation of the minimum acceptable radius for the arc calculation
       if (aPrecision >= 0)    // 'f' format in the QString 
-       LastDecimal = aPrecision;
+        LastDecimal = aPrecision;
       else                    // 'g' format in the QString 
-       LastDecimal = qAbs( aPrecision ) - ceil( log10(minRad) ); 
-      minRad = ceil(pow(10,LastDecimal) * minRad) / pow(10,LastDecimal); // Rounded up at the last allowed decimal place
+        LastDecimal = qAbs( aPrecision ) - ceil( log10(minRad) ); 
+        minRad = ceil(pow(10,LastDecimal) * minRad) / pow(10,LastDecimal); // Rounded up at the last allowed decimal place
       if ( Abs(vz) < minRad){
-       if (vz < 0.0)
-         Group3Spin->SpinBox_DZ->setValue( - minRad );
-       else 
-          Group3Spin->SpinBox_DZ->setValue( minRad );
+        if (vz < 0.0)
+          Group3Spin->SpinBox_DZ->setValue( - minRad );
+        else 
+          Group3Spin->SpinBox_DZ->setValue( minRad );
       }
     }
     vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
@@ -1693,24 +1821,24 @@ void EntityGUI_SketcherDlg::ValueChangedInSpinBox( double newValue )
       myRadiusStr = vxStr;
     }
     if ( mySketchType == PT_ABS_CENTER ) {  
-      myX = vx;
-      myY = vy;
-      myXc = vz;
-      myYc = vs;
-      myXStr = vxStr;
-      myYStr = vyStr;
-      myXcStr = vzStr;
-      myYcStr = vsStr;
+      myXc = vx;
+      myYc = vy;
+      myX = vz;
+      myY = vs;
+      myXcStr = vxStr;
+      myYcStr = vyStr;
+      myXStr = vzStr;
+      myYStr = vsStr;
     }
     else if ( mySketchType == PT_REL_CENTER ) {
-      myDX = vx;
-      myDY = vy;
-      myDXc = vz;
-      myDYc = vs;
-      myDXStr = vxStr;
-      myDYStr = vyStr;
-      myDXcStr = vzStr;
-      myDYcStr = vsStr;
+      myDXc = vx;
+      myDYc = vy;
+      myDX = vz;
+      myDY = vs;
+      myDXcStr = vxStr;
+      myDYcStr = vyStr;
+      myDXStr = vzStr;
+      myDYStr = vsStr;
     }
     if ( mySketchType == DIR_ANGLE_LENGTH ) {
       myAngle = vx;
@@ -1743,8 +1871,29 @@ void EntityGUI_SketcherDlg::ValueChangedInSpinBox( double newValue )
       myLengthStr = vsStr;
     }
   }
-
-  GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
+  
+  if (!autoApply) 
+    GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
+  
+  double x, y, xc, yc;
+  x = y = xc = yc = 0.0;
+  if ( mySketchType == PT_ABS_CENTER || mySketchType == PT_REL_CENTER )
+  {
+    if ( mySketchType == PT_REL_CENTER ){
+      x  = myDX  + myLastX1;
+      y  = myDY  + myLastY1;
+      xc = myDXc + myLastX1;
+      yc = myDYc + myLastY1;
+    }
+    else {
+      x  = myX ;
+      y  = myY ;
+      xc = myXc;
+      yc = myYc;
+    }
+    displayPntPreview(xc,yc);
+    displayPntPreview(x,y);
+  }
 }
 
 
@@ -1942,8 +2091,15 @@ bool EntityGUI_SketcherDlg::isValid( QString& msg )
 //=================================================================================
 bool EntityGUI_SketcherDlg::execute( ObjectList& objects )
 {
+  SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
+  int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
+  int DigNum = qAbs(aPrecision);                   // options for the format of numbers in  myNewCommand
+  char Format = 'f';
+  if ( aPrecision < 0 )                            // f --> DigNum is the number of digits after the decimal point
+    Format = 'g';                                  // g --> DigNum is the maximum number of significant digits 
+    
   QString aParameters;
-
+  
   if ( mySketchState == FIRST_POINT ) {
     myLastX2 = myX;
     myLastY2 = myY;
@@ -1966,16 +2122,25 @@ bool EntityGUI_SketcherDlg::execute( ObjectList& objects )
     Sketcher_Profile aProfile2( Command2.toAscii() );
 
     //Error Message
-    if ( mySketchType == PT_ABS_CENTER || 
-        mySketchType == PT_REL_CENTER  ){
-      Group4Spin->label->show();
-      Group4Spin->label->setText(QString(aProfile2.ErrMsg().c_str()));
+    if ( mySketchType == PT_ABS_CENTER || mySketchType == PT_REL_CENTER  ){
+      if (aProfile2.Error() > Precision::Confusion()){
+        Group4Spin->label->show();
+        Group4Spin->label->setText( tr("GEOM_SKETCHER_WARNING") + QString::number( aProfile2.Error(), Format, DigNum));
+      }
+      else{
+        Group4Spin->label->hide();
+      } 
     }
     else 
       Group4Spin->label->hide();
     if ( mySketchType == PT_SEL_CENTER ){
-      Group2Sel->label->show();
-      Group2Sel->label->setText(QString(aProfile2.ErrMsg().c_str()));  
+      if (aProfile2.Error() > Precision::Confusion()){
+        Group2Sel->label->show();
+        Group2Sel->label->setText( tr("GEOM_SKETCHER_WARNING") + QString::number( aProfile2.Error(), Format, DigNum));
+      }
+      else{
+        Group2Sel->label->hide();
+      } 
     }
     else 
       Group2Sel->label->hide();
@@ -2048,31 +2213,24 @@ bool EntityGUI_SketcherDlg::execute( ObjectList& objects )
 
     if ( Group1Sel->isVisible() ) {
       Group1Sel->buttonApply->setEnabled( true );
-      //Group1Sel->buttonApply->setFocus();
     }
     if ( Group2Sel->isVisible() ) {
       Group2Sel->buttonApply->setEnabled( true );
-      //Group2Sel->buttonApply->setFocus();
     }
     if ( Group1Sel1Spin->isVisible() ) {
-      Group1Sel1Spin->buttonApply->setEnabled( true );
-      //Group1Sel1Spin->buttonApply->setFocus();
+      Group1Sel1Spin->buttonApply->setEnabled( true );;
     }
     if ( Group1Spin->isVisible() ) {
       Group1Spin->buttonApply->setEnabled( true );
-      //Group1Spin->buttonApply->setFocus();
     }
     if ( Group2Spin->isVisible() ) {
       Group2Spin->buttonApply->setEnabled( true );
-      //Group2Spin->buttonApply->setFocus();
     }
     if ( Group3Spin->isVisible() ) {
       Group3Spin->buttonApply->setEnabled( true );
-      //Group3Spin->buttonApply->setFocus();
     }
     if ( Group4Spin->isVisible() ) {
       Group4Spin->buttonApply->setEnabled( true );
-      //Group4Spin->buttonApply->setFocus();
     }
   }
 
@@ -2120,7 +2278,7 @@ void EntityGUI_SketcherDlg::displayPreview( GEOM::GEOM_Object_ptr object,
                                             const double          lineWidth,
                                             const int             displayMode,
                                             const int             color )
-{
+{ 
   // Set color for preview shape
   getDisplayer()->SetColor( Quantity_NOC_RED );
 
@@ -2155,6 +2313,41 @@ void EntityGUI_SketcherDlg::displayPreview( GEOM::GEOM_Object_ptr object,
   getDisplayer()->SetToActivate( true );
 }
 
+//================================================================
+// Function : displayPntPreview
+// Purpose  : creates a TopoDS_VERTEX and display a preview of it
+//================================================================
+void EntityGUI_SketcherDlg::displayPntPreview(const double x,
+                                              const double y,
+                                              bool append,
+                                              bool update
+                                             )
+{
+  // Get globalCS and working plane
+  gp_Ax3 globalCS = myLCSList.first(); //gp_Ax3(aOrigin, aDirZ, aDirX);
+  gp_Ax3 aWPlane  = GetActiveLocalCS();
+  
+  // Build point in localCS
+  gp_Pnt aPnt = gp_Pnt(x,y,0.0);
+  
+  // Get transfomation from local to global CS
+  gp_Trsf aTrans;
+  aTrans.SetTransformation(aWPlane, globalCS);
+  
+  BRepBuilderAPI_MakeVertex mkVertex (aPnt);
+  TopoDS_Shape aLocalVertex = mkVertex.Shape();
+  
+  // Perform transformation
+  BRepBuilderAPI_Transform aTransformation (aLocalVertex, aTrans, Standard_False);
+  TopoDS_Shape aGlobalVertex = aTransformation.Shape();
+  
+  // Build prs with vertex in globalCS
+  SALOME_Prs* aPrs = getDisplayer()->BuildPrs( aGlobalVertex );
+  if ( aPrs != 0 && !aPrs->IsNull() )
+    GEOMBase_Helper::displayPreview( aPrs, append, update );
+  
+}
+
 //================================================================
 // Function : createShapes
 // Purpose  : Create applyed wire, and last segment from entry object
@@ -2164,17 +2357,17 @@ bool EntityGUI_SketcherDlg::createShapes( GEOM::GEOM_Object_ptr theObject,
                                           TopoDS_Shape&         theLastSegment )
 {
   TopoDS_Shape aShape;
-  if ( !GEOMBase::GetShape( theObject, aShape ) ||
-       aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX )
+  if (  !GEOMBase::GetShape( theObject, aShape ) ||
+       ( aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX ) )
     return false;
 
-  if ( Group1Sel->isVisible()  && !Group1Sel->buttonApply->isEnabled()  ||
-       Group2Sel->isVisible()  && !Group2Sel->buttonApply->isEnabled()  ||
-       Group1Sel1Spin->isVisible()  && !Group1Sel1Spin->buttonApply->isEnabled()  ||
-       Group1Spin->isVisible() && !Group1Spin->buttonApply->isEnabled() ||
-       Group2Spin->isVisible() && !Group2Spin->buttonApply->isEnabled() ||
-       Group3Spin->isVisible() && !Group3Spin->buttonApply->isEnabled() ||
-       Group4Spin->isVisible() && !Group4Spin->buttonApply->isEnabled() ) {
+  if ( ( Group1Sel->isVisible()  && !Group1Sel->buttonApply->isEnabled() )||
+       ( Group2Sel->isVisible()  && !Group2Sel->buttonApply->isEnabled() ) ||
+       ( Group1Sel1Spin->isVisible()  && !Group1Sel1Spin->buttonApply->isEnabled() ) ||
+       ( Group1Spin->isVisible() && !Group1Spin->buttonApply->isEnabled() ) ||
+       ( Group2Spin->isVisible() && !Group2Spin->buttonApply->isEnabled() ) ||
+       ( Group3Spin->isVisible() && !Group3Spin->buttonApply->isEnabled() ) ||
+       ( Group4Spin->isVisible() && !Group4Spin->buttonApply->isEnabled() ) ) {
      theApplyedWire = aShape;
      return true;
   }
@@ -2328,6 +2521,28 @@ void EntityGUI_SketcherDlg::FindLocalCS()
   }
 }
 
+//=================================================================================
+// function : getPnt1ConstructorId()
+// purpose  :
+//=================================================================================
+int EntityGUI_SketcherDlg::getPnt1ConstructorId() const
+{ 
+  int buttonId = GroupPt->ButtonGroup->checkedId(); 
+//   MESSAGE("buttonId = "<<buttonId)
+  return buttonId;
+}
+
+//=================================================================================
+// function : getPnt2ConstructorId()
+// purpose  :
+//=================================================================================
+int EntityGUI_SketcherDlg::getPnt2ConstructorId() const
+{ 
+  int buttonId = GroupPt2->ButtonGroup->checkedId(); 
+//   MESSAGE("buttonId = "<<buttonId)
+  return buttonId;
+}
+
 //=================================================================================
 // function : GetActiveLocalCS()
 // purpose  : Get Working plane