Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/geom.git] / src / EntityGUI / EntityGUI_SketcherDlg.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : EntityGUI_SketcherDlg.cxx
25 // Author : Damien COQUERET, Open CASCADE S.A.S.
26 //
27 #include "EntityGUI_SketcherDlg.h"
28 #include "EntityGUI_Widgets.h"
29 #include <SalomeApp_DoubleSpinBox.h>
30
31 #include <OCCViewer_ViewPort3d.h>
32 #include <OCCViewer_ViewWindow.h>
33 #include <OCCViewer_ViewSketcher.h>
34
35 #include <GEOMBase.h>
36 #include <GeometryGUI.h>
37 #include <GEOMImpl_Types.hxx>
38 #include <Geom_Surface.hxx>
39 #include <Geom_Plane.hxx>
40
41 #include <GeomLib_IsPlanarSurface.hxx>
42
43 #include <SUIT_Desktop.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_ResourceMgr.h>
47 #include <SalomeApp_Application.h>
48 #include <LightApp_Application.h>
49 #include <LightApp_SelectionMgr.h>
50
51 #include <DlgRef.h>
52
53 #include <QKeyEvent>
54
55 #include <BRep_Tool.hxx>
56 #include <TopExp.hxx>
57 #include <TopExp_Explorer.hxx>
58 #include <TopoDS_Vertex.hxx>
59 #include <TopoDS.hxx>
60 #include <BRepBuilderAPI_Transform.hxx>
61 #include <BRepBuilderAPI_MakeWire.hxx>
62 #include <BRepBuilderAPI_MakeVertex.hxx>
63 #include <Sketcher_Profile.hxx>
64
65 #include <SalomeApp_Study.h>
66 #include <SalomeApp_Tools.h>
67
68 #include <gp_Pln.hxx>
69
70 #include <Basics_Utils.hxx>
71
72 //=================================================================================
73 // class    : EntityGUI_SketcherDlg()
74 // purpose  : Constructs a EntityGUI_SketcherDlg which is a child of 'parent', with the
75 //            name 'name' and widget flags set to 'f'.
76 //            The dialog will by default be modeless, unless you set 'modal' to
77 //            TRUE to construct a modal dialog.
78 //=================================================================================
79 EntityGUI_SketcherDlg::EntityGUI_SketcherDlg( GeometryGUI* GUI, QWidget* parent,
80                                               bool modal, Qt::WindowFlags fl,
81                                               const double lineWidth )
82   : QDialog( parent, fl ),
83     myIsAllAdded( false ),
84     myIsApply( false ),
85     GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
86     myGeometryGUI( GUI ),
87     myLineWidth( lineWidth )
88 {
89   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
90   setModal( modal );
91   setAttribute( Qt::WA_DeleteOnClose );
92   
93   // Disable rectangular selection
94 //   SUIT_ViewWindow*      theViewWindow  = getDesktop()->activeWindow();
95 //   ((OCCViewer_ViewWindow*)theViewWindow)->setEnabledDrawMode( false );
96 //   MESSAGE("((OCCViewer_ViewWindow*)theViewWindow)->isEnabledDrawMode();"<<((OCCViewer_ViewWindow*)theViewWindow)->isEnabledDrawMode())
97 //   OCCViewer_ViewPort3d* vp             = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
98 //   vp->setSketchingEnabled( false );
99 //   MESSAGE("vp->isSketchingEnabled()"<<vp->isSketchingEnabled())
100 //   ((OCCViewer_ViewWindow*)theViewWindow)->setSketcherStyle(true);
101 //   OCCViewer_ViewSketcher* aViewSketcher = ((OCCViewer_ViewWindow*)theViewWindow)->getSketcher( OCCViewer_ViewWindow::Rect );
102 //   aViewSketcher->deactivate()
103 //   aViewSketcher->setVisible(false);
104   
105 //   this->setMouseTracking(false);
106   
107   myGeometryGUI->SetActiveDialogBox(this);
108
109   MainWidget = new EntityGUI_Skeleton( this );
110   QVBoxLayout* topLayout = new QVBoxLayout( this );
111   topLayout->setMargin( 9 ); topLayout->setSpacing( 6 );
112
113   MainWidget->buttonCancel->setText( tr( "GEOM_BUT_CANCEL" ) );
114   MainWidget->buttonEnd->setText( tr( "GEOM_BUT_CLOSE" ) );
115   MainWidget->buttonClose->setText( tr( "GEOM_BUT_CLOSE_SKETCH" ) );
116   MainWidget->buttonHelp->setText( tr( "GEOM_BUT_HELP" ) );
117
118   QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT"        ) ) );
119   QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_UNDO"      ) ) );
120   QPixmap image2( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_REDO"      ) ) );
121   QPixmap image3( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_LINE_2P"   ) ) );
122   QPixmap image4( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_ARC"       ) ) );
123   QPixmap image5 (aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT"        ) ) );
124   QPixmap image6 (aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_RECTANGLE" ) ) );
125
126   setWindowTitle( tr( "GEOM_SKETCHER_TITLE" ) );
127
128   MainWidget->GroupConstructors->setTitle( tr( "GEOM_SKETCHER_EL" ) );
129   MainWidget->RadioButton1->setText( "" );
130   MainWidget->RadioButton1->setIcon( image3 );
131   MainWidget->RadioButton2->setText( "" );
132   MainWidget->RadioButton2->setIcon( image4 );
133   MainWidget->RadioButton3->setText( "" );
134   MainWidget->RadioButton3->setIcon( image6 );
135   MainWidget->GroupDest->setTitle( tr( "GEOM_SKETCHER_DEST" ) );
136   MainWidget->GroupDest1->setTitle( tr( "GEOM_SKETCHER_TYPE" ) );
137   MainWidget->RB_Dest1->setText( tr( "GEOM_SKETCHER_POINT" ) );
138   MainWidget->RB_Dest2->setText( tr( "GEOM_SKETCHER_DIR" ) );
139
140   /***************************************************************/
141
142   GroupBox1 = new QGroupBox(tr("GEOM_CS"), this);
143   QGridLayout* planeLayout = new QGridLayout(GroupBox1);
144   planeLayout->setSpacing(6);
145   planeLayout->setMargin(11);
146
147   ComboBox1 = new QComboBox(GroupBox1);
148   planeLayout->addWidget(ComboBox1,0,0,1,2);
149
150   planeButton = new QPushButton (GroupBox1);
151   planeButton->setText( tr( "GEOM_SKETCHER_RESTORE" ) );
152   planeLayout->addWidget(planeButton,0,2);
153   
154   selButton = new QPushButton (GroupBox1);
155   selButton->setIcon(image5);
156   planeLayout->addWidget(selButton,1,0);
157   
158   WPlaneLineEdit = new QLineEdit (GroupBox1);
159   WPlaneLineEdit->setReadOnly(true);
160   planeLayout->addWidget(WPlaneLineEdit,1,1,1,2);
161   
162   planeLayout->setColumnStretch(1,1);
163   
164   topLayout->addWidget(GroupBox1);
165   topLayout->addWidget( MainWidget );
166   topLayout->setStretch( 1, 1);
167
168   GroupPt = new EntityGUI_Point( MainWidget->DestCnt );
169
170   GroupPt->GroupPoint->setTitle( tr( "GEOM_SKETCHER_POINT" ) );
171   GroupPt->RB_Point1->setText( tr( "GEOM_SKETCHER_ABS" ) );
172   GroupPt->RB_Point2->setText( tr( "GEOM_SKETCHER_REL" ) );
173   GroupPt->RB_Point3->setText( tr( "GEOM_SKETCHER_SEL" ) );
174
175   GroupPt2 = new EntityGUI_Point( MainWidget->DestCnt );
176
177   GroupPt2->GroupPoint->setTitle( tr( "GEOM_SKETCHER_ADD_PARAMS" ) ); 
178   GroupPt2->RB_Point1->setText( tr( "GEOM_SKETCHER_NONE" ) );
179   GroupPt2->RB_Point2->setText( tr( "GEOM_SKETCHER_RADIUS" ) );
180   GroupPt2->RB_Point3->setText( tr( "GEOM_SKETCHER_CENTER" ) ); 
181
182   GroupD1 = new EntityGUI_Dir1( MainWidget->DestCnt );
183
184   GroupD1->GroupDir1->setTitle( tr( "GEOM_SKETCHER_DIR" ) );
185   GroupD1->RB_Dir11->setText( tr( "GEOM_SKETCHER_ANGLE" ) );
186   GroupD1->RB_Dir12->setText( tr( "GEOM_SKETCHER_PER" ) );
187   GroupD1->RB_Dir13->setText( tr( "GEOM_SKETCHER_TAN" ) );
188   GroupD1->RB_Dir14->setText( tr( "GEOM_SKETCHER_VXVY" ) );
189
190   GroupD2 = new EntityGUI_Dir2( MainWidget->DestCnt );
191
192   GroupD2->GroupDir2->setTitle( tr( "GEOM_SKETCHER_DIST" ) );
193   GroupD2->RB_Dir21->setText( tr( "GEOM_SKETCHER_LENGTH" ) );
194   GroupD2->RB_Dir22->setText( tr( "GEOM_SKETCHER_X" ) );
195   GroupD2->RB_Dir23->setText( tr( "GEOM_SKETCHER_Y" ) );
196
197   Group1Sel = new EntityGUI_1Sel( MainWidget->SkeletonCnt );
198   Group1Sel->TextLabel1->setText( tr( "GEOM_SKETCHER_POINT2" ) );
199   Group1Sel->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
200   Group1Sel->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
201   Group1Sel->PushButton1->setIcon( image0 );
202   Group1Sel->buttonUndo->setIcon( image1 );
203   Group1Sel->buttonRedo->setIcon( image2 );
204   Group1Sel->LineEdit1->setReadOnly( true );
205
206   Group2Sel = new EntityGUI_2Sel1Check( MainWidget->SkeletonCnt );
207   Group2Sel->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
208   Group2Sel->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
209   Group2Sel->checkBox->setText( tr( "GEOM_REVERSE" ) );
210   Group2Sel->PushButton1->setIcon( image0 );
211   Group2Sel->PushButton2->setIcon( image0 );
212   Group2Sel->buttonUndo->setIcon( image1 );
213   Group2Sel->buttonRedo->setIcon( image2 );
214   Group2Sel->LineEdit1->setReadOnly( true );
215   Group2Sel->LineEdit2->setReadOnly( true );
216
217   Group1Sel1Spin = new EntityGUI_1Sel1Spin1Check( MainWidget->SkeletonCnt );
218   Group1Sel1Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
219   Group1Sel1Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
220   Group1Sel1Spin->checkBox->setText( tr( "GEOM_REVERSE" ) );
221   Group1Sel1Spin->PushButton1->setIcon( image0 );
222   Group1Sel1Spin->buttonUndo->setIcon( image1 );
223   Group1Sel1Spin->buttonRedo->setIcon( image2 );
224   Group1Sel1Spin->LineEdit1->setReadOnly( true );
225
226   Group1Spin = new EntityGUI_1Spin( MainWidget->SkeletonCnt );
227   Group1Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
228   Group1Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
229   Group1Spin->buttonUndo->setIcon( image1 );
230   Group1Spin->buttonRedo->setIcon( image2 );
231
232   Group2Spin = new EntityGUI_2Spin( MainWidget->SkeletonCnt );
233   Group2Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
234   Group2Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
235   Group2Spin->buttonUndo->setIcon( image1 );
236   Group2Spin->buttonRedo->setIcon( image2 );
237
238   Group3Spin = new EntityGUI_3Spin1Check( MainWidget->SkeletonCnt );
239   Group3Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
240   Group3Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
241   Group3Spin->checkBox->setText( tr( "GEOM_REVERSE" ) );
242   Group3Spin->buttonUndo->setIcon( image1 );
243   Group3Spin->buttonRedo->setIcon( image2 );
244
245   Group4Spin = new EntityGUI_4Spin1Check( MainWidget->SkeletonCnt );
246   Group4Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
247   Group4Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
248   Group4Spin->checkBox->setText( tr( "GEOM_REVERSE" ) );
249   Group4Spin->buttonUndo->setIcon( image1 );
250   Group4Spin->buttonRedo->setIcon( image2 );
251   
252   GroupRect = new DlgRef_4Spin( MainWidget->SkeletonCnt );
253   GroupRect->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
254   GroupRect->TextLabel1->setText("X1:");
255   GroupRect->TextLabel2->setText("Y1:");
256   GroupRect->TextLabel3->setText("X2:");
257   GroupRect->TextLabel4->setText("Y2:");
258
259   // Defines a palette for the error message on Group4Spin and Group2Sel 
260   QPalette palette;
261   QColor color("red");
262   palette.setColor(Group4Spin->label->foregroundRole(), color);
263   Group4Spin->label->setPalette(palette);
264   palette.setColor(Group2Sel->label->foregroundRole(), color);
265   Group2Sel->label->setPalette(palette);
266
267   QGridLayout* DestCntLayout = new QGridLayout( MainWidget->DestCnt );
268   DestCntLayout->setMargin( 0 ); DestCntLayout->setSpacing( 6 );
269   DestCntLayout->addWidget( GroupPt, 0, 0 );
270   DestCntLayout->addWidget( GroupPt2, 0, 1 );
271   DestCntLayout->addWidget( GroupD1, 0, 0 );
272   DestCntLayout->addWidget( GroupD2, 0, 1 );
273
274   QVBoxLayout* SkeletonCntlayout = new QVBoxLayout( MainWidget->SkeletonCnt );
275   SkeletonCntlayout->setMargin( 0 ); SkeletonCntlayout->setSpacing( 6 );
276   SkeletonCntlayout->addWidget( Group1Sel,  0, 0 );
277   SkeletonCntlayout->addWidget( Group2Sel,  0, 0 );
278   SkeletonCntlayout->addWidget( Group1Sel1Spin,  0, 0 );
279   SkeletonCntlayout->addWidget( Group1Spin, 0, 0 );
280   SkeletonCntlayout->addWidget( Group2Spin, 0, 0 );
281   SkeletonCntlayout->addWidget( Group3Spin, 0, 0 );
282   SkeletonCntlayout->addWidget( Group4Spin, 0, 0 );
283   SkeletonCntlayout->addWidget( GroupRect, 0, 0 );
284   //SkeletonCntlayout->setStretch( 0, 1);
285   /***************************************************************/
286
287   QButtonGroup* ButtonGroup = new QButtonGroup( this );
288   ButtonGroup->addButton( MainWidget->RB_Dest1, 1 );
289   ButtonGroup->addButton( MainWidget->RB_Dest2, 0 );
290
291   /* signals and slots connections */
292   connect( MainWidget->buttonEnd,    SIGNAL( clicked() ),              this, SLOT( ClickOnEnd() ) );
293   connect( MainWidget->buttonClose,  SIGNAL( clicked() ),              this, SLOT( ClickOnEnd() ) );
294   connect( MainWidget->buttonCancel, SIGNAL( clicked() ),              this, SLOT( ClickOnCancel() ) );
295   connect( MainWidget->buttonHelp,   SIGNAL( clicked() ),              this, SLOT( ClickOnHelp() ) );
296
297   connect( Group1Sel->buttonApply,   SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
298   connect( Group1Sel->buttonUndo,    SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
299   connect( Group1Sel->buttonRedo,    SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) );
300   connect( Group2Sel->buttonApply,   SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
301   connect( Group2Sel->buttonUndo,    SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
302   connect( Group2Sel->buttonRedo,    SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) );
303   connect( Group1Sel1Spin->buttonApply,SIGNAL( clicked() ),            this, SLOT( ClickOnApply() ) );
304   connect( Group1Sel1Spin->buttonUndo, SIGNAL( clicked() ),            this, SLOT( ClickOnUndo() ) );
305   connect( Group1Sel1Spin->buttonRedo, SIGNAL( clicked() ),            this, SLOT( ClickOnRedo() ) );
306   connect( Group1Spin->buttonApply,  SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
307   connect( Group1Spin->buttonUndo,   SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
308   connect( Group1Spin->buttonRedo,   SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) );
309   connect( Group2Spin->buttonApply,  SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
310   connect( Group2Spin->buttonUndo,   SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
311   connect( Group2Spin->buttonRedo,   SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) );
312   connect( Group3Spin->buttonApply,  SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
313   connect( Group3Spin->buttonUndo,   SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
314   connect( Group3Spin->buttonRedo,   SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) ) ;
315   connect( Group4Spin->buttonApply,  SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
316   connect( Group4Spin->buttonUndo,   SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
317   connect( Group4Spin->buttonRedo,   SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) );
318
319   connect( MainWidget->ButtonGroup,  SIGNAL( buttonClicked( int ) ),   this, SLOT( TypeClicked( int ) ) );
320   connect( ButtonGroup,              SIGNAL( buttonClicked( int ) ),   this, SLOT( DestClicked( int ) ) );
321   connect( GroupPt->ButtonGroup,     SIGNAL( buttonClicked( int ) ),   this, SLOT( PointClicked( int ) ) );
322   connect( GroupPt2->ButtonGroup,    SIGNAL( buttonClicked( int ) ),   this, SLOT( Point2Clicked( int ) ) );
323   connect( GroupD1->ButtonGroup,     SIGNAL( buttonClicked( int ) ),   this, SLOT( Dir1Clicked( int ) ) );
324   connect( GroupD2->ButtonGroup,     SIGNAL( buttonClicked( int ) ),   this, SLOT( Dir2Clicked( int ) ));
325
326   connect( Group1Sel->LineEdit1,     SIGNAL( returnPressed() ),        this, SLOT( LineEditReturnPressed() ) );
327   connect( Group1Sel->PushButton1,   SIGNAL( clicked() ),              this, SLOT( SetEditCurrentArgument() ) );
328
329   connect( Group2Sel->LineEdit1,     SIGNAL( returnPressed() ),        this, SLOT( LineEditReturnPressed() ) );
330   connect( Group2Sel->LineEdit2,     SIGNAL( returnPressed() ),        this, SLOT( LineEditReturnPressed() ) );
331   connect( Group2Sel->PushButton1,   SIGNAL( clicked() ),              this, SLOT( SetEditCurrentArgument() ) );
332   connect( Group2Sel->PushButton2,   SIGNAL( clicked() ),              this, SLOT( SetEditCurrentArgument() ) );
333
334   connect( Group1Sel1Spin->LineEdit1,SIGNAL( returnPressed() ),        this, SLOT( LineEditReturnPressed() ) );
335   connect( Group1Sel1Spin->PushButton1,SIGNAL( clicked() ),            this, SLOT( SetEditCurrentArgument() ) );
336   connect( Group1Sel1Spin->SpinBox_DX,SIGNAL( valueChanged( double ) ),this, SLOT( ValueChangedInSpinBox( double ) ) );
337
338   connect( Group1Spin->SpinBox_DX,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
339   connect( Group2Spin->SpinBox_DX,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
340   connect( Group2Spin->SpinBox_DY,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
341   connect( Group3Spin->SpinBox_DX,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
342   connect( Group3Spin->SpinBox_DY,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
343   connect( Group3Spin->SpinBox_DZ,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
344   connect( Group4Spin->SpinBox_DX,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
345   connect( Group4Spin->SpinBox_DY,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
346   connect( Group4Spin->SpinBox_DZ,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
347   connect( Group4Spin->SpinBox_DS,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
348   connect( GroupRect->SpinBox_DX1,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
349   connect( GroupRect->SpinBox_DX2,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
350   connect( GroupRect->SpinBox_DY1,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
351   connect( GroupRect->SpinBox_DY2,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
352
353   connect( Group3Spin->checkBox,     SIGNAL( stateChanged( int ) ),    this, SLOT( CheckBoxClicked( int ) ) );
354   connect( Group4Spin->checkBox,     SIGNAL( stateChanged( int ) ),    this, SLOT( CheckBoxClicked( int ) ) );
355   connect( Group2Sel->checkBox,      SIGNAL( stateChanged( int ) ),    this, SLOT( CheckBoxClicked( int ) ) );
356   connect( Group1Sel1Spin->checkBox, SIGNAL( stateChanged( int ) ),    this, SLOT( CheckBoxClicked( int ) ) );
357
358   connect( ComboBox1,                SIGNAL( activated( int ) ),       this, SLOT( ActivateLocalCS() ) );
359   connect( planeButton,              SIGNAL( clicked() ),              this, SLOT( ActivateLocalCS() ) );
360   connect( selButton,                SIGNAL( clicked() ),              this, SLOT( SetEditCurrentArgument() ) );
361
362   connect( myGeometryGUI,            SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
363
364   connect( myGeometryGUI,            SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
365   connect( myGeometryGUI,            SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
366   
367   // install event filter on spin-boxes to provide Apply action on Return pressed
368   Group1Spin->SpinBox_DX->installEventFilter(this);
369   Group1Sel1Spin->SpinBox_DX->installEventFilter(this);
370   Group2Spin->SpinBox_DX->installEventFilter(this);
371   Group2Spin->SpinBox_DY->installEventFilter(this);
372   Group3Spin->SpinBox_DX->installEventFilter(this);
373   Group3Spin->SpinBox_DY->installEventFilter(this);
374   Group3Spin->SpinBox_DZ->installEventFilter(this);
375   Group4Spin->SpinBox_DX->installEventFilter(this);
376   Group4Spin->SpinBox_DY->installEventFilter(this);
377   Group4Spin->SpinBox_DZ->installEventFilter(this);
378   Group4Spin->SpinBox_DS->installEventFilter(this);
379
380   Init();
381 }
382
383
384 //=================================================================================
385 // function : ~EntityGUI_SketcherDlg()
386 // purpose  : Destroys the object and frees any allocated resources
387 //=================================================================================
388 EntityGUI_SketcherDlg::~EntityGUI_SketcherDlg()
389 {
390 //   SUIT_ViewWindow*      theViewWindow  = getDesktop()->activeWindow();
391   
392   myGeometryGUI->SetActiveDialogBox( 0 );
393 //   ((OCCViewer_ViewWindow*)theViewWindow)->setSketcherStyle(false);
394 }
395
396
397 //=================================================================================
398 // function : eventFilter()
399 // purpose  : event filter for spin-boxes to provide Apply action on Return pressed
400 //=================================================================================
401 bool EntityGUI_SketcherDlg::eventFilter (QObject* object, QEvent* event)
402 {
403   if (event->type() == QEvent::KeyPress) {
404     QKeyEvent* ke = (QKeyEvent*)event;
405     if ( ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter ) {
406       if (object == Group1Spin->SpinBox_DX) {
407         Group1Spin->buttonApply->click();
408         return true;
409       } else if (object == Group1Sel1Spin->SpinBox_DX) {
410         Group1Sel1Spin->buttonApply->click();
411         return true;
412       } else if (object == Group2Spin->SpinBox_DX ||
413                  object == Group2Spin->SpinBox_DY) {
414         Group2Spin->buttonApply->click();
415         return true;
416       } else if (object == Group3Spin->SpinBox_DX ||
417                  object == Group3Spin->SpinBox_DY ||
418                  object == Group3Spin->SpinBox_DZ) {
419         Group3Spin->buttonApply->click();
420         return true;
421       } else if (object == Group4Spin->SpinBox_DX ||
422                  object == Group4Spin->SpinBox_DY ||
423                  object == Group4Spin->SpinBox_DZ ||
424                  object == Group4Spin->SpinBox_DS) {
425         Group4Spin->buttonApply->click();
426         return true;
427       }
428     }
429   }
430
431   // Fix of the NPAL16010 bug is removed, because it's not actual with the Qt-4.x
432
433   return QDialog::eventFilter(object, event);
434 }
435
436
437 //=================================================================================
438 // function : Init()
439 // purpose  :
440 //=================================================================================
441 void EntityGUI_SketcherDlg::Init()
442 {
443   /* init variables */
444   autoApply = false;
445   
446   myEditCurrentArgument = WPlaneLineEdit; // Initiate the parameters selection with the first WPlaneLineEdit
447   
448   myCommand.append( "Sketcher" );
449   myUndoCommand.append( "Sketcher" );
450
451   mySketchState = FIRST_POINT;
452   globalSelection( GEOM_FACE );
453
454   myCheckFlag = 0;
455
456   myLastX1 = 0.0;
457   myLastY1 = 0.0;
458   myLastX2 = 0.0;
459   myLastY2 = 0.0;
460
461   myHelpFileName = "create_sketcher_page.html";
462   
463   GEOM::GEOM_IBasicOperations_var aBasicOp = getGeomEngine()->GetIBasicOperations( getStudyId() );
464   myGlobalCS = aBasicOp->MakeMarker( 0,0,0,
465                                      1,0,0,
466                                      0,1,0 ); 
467   myWPlane = myGlobalCS;
468   myLCSList.push_back( WPlaneToLCS(myGlobalCS) );
469
470   /* Get setting of step value from file configuration */
471   double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
472
473   /* min, max, step and decimals for spin boxes */
474   initSpinBox( Group1Sel1Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
475   initSpinBox( Group1Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
476   initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
477   initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
478   initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
479   initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
480   initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
481   initSpinBox( Group4Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
482   // san: Note specific step values below!
483   initSpinBox( Group4Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
484   initSpinBox( Group4Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
485   initSpinBox( Group4Spin->SpinBox_DS, COORD_MIN, COORD_MAX, 5., "length_precision" );
486   
487   initSpinBox( GroupRect->SpinBox_DX1, COORD_MIN, COORD_MAX, step, "length_precision" ); 
488   initSpinBox( GroupRect->SpinBox_DY1, COORD_MIN, COORD_MAX, step, "length_precision" );
489   initSpinBox( GroupRect->SpinBox_DX2, COORD_MIN, COORD_MAX, step, "length_precision" );
490   initSpinBox( GroupRect->SpinBox_DY2, COORD_MIN, COORD_MAX, step, "length_precision" );
491     
492   /* displays Dialog */
493
494 //   MainWidget->RadioButton1->setEnabled( false );
495 //   MainWidget->RadioButton2->setEnabled( false );
496 //   MainWidget->RadioButton3->setEnabled( true );
497 //   MainWidget->GroupDest1->setEnabled( false );
498   setEnabledUndo( false );
499   setEnabledRedo( false );
500
501   MainWidget->RadioButton1->setChecked( true );
502
503   FindLocalCS();
504   TypeClicked( 0 );
505   // If a face has already been selected use it. Placed after FindLocalCS to avoid clearing the combobox
506   // that should be filled with the possibly selected face
507   
508   OnFirstPoint();
509   
510   SelectionIntoArgument();     
511   
512   resize(100,100);
513   
514   setPrefix(tr("GEOM_SKETCH"));
515
516   ActivateLocalCS();
517   
518   setIsWaitCursorEnabled( false );
519   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
520 }
521
522
523 //=================================================================================
524 // function : InitClick()
525 // purpose  :
526 //=================================================================================
527 void EntityGUI_SketcherDlg::InitClick()
528 {
529   MESSAGE("EntityGUI_SketcherDlg::InitClick()")
530   disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
531   myCheckFlag = 0;
532
533   Group1Sel->hide();
534   Group2Sel->hide();
535   Group1Sel1Spin->hide();
536   Group1Spin->hide();
537   Group2Spin->hide();
538   Group3Spin->hide();
539   Group4Spin->hide();
540   GroupRect->hide();
541   globalSelection(); // close local selection to clear it
542   localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
543 }
544
545
546 //=================================================================================
547 // function : TypeClicked()
548 // purpose  : Radio button management
549 //=================================================================================
550 void EntityGUI_SketcherDlg::TypeClicked( int constructorId )
551 {
552   myConstructorId = constructorId;
553   MainWidget->buttonEnd->setText(tr("GEOM_BUT_CLOSE"));
554   MainWidget->buttonClose->setEnabled(true);
555   
556   if ( myConstructorId == 0 ) {    // SEGMENT
557     GroupPt2->RB_Point1->setChecked( true );
558     GroupPt ->setEnabled( true );
559     GroupPt2->setEnabled( false );
560     GroupD1->setEnabled( true );
561     GroupD2->setEnabled( true );
562     MainWidget->RB_Dest1->setEnabled( true );
563     MainWidget->RB_Dest1->setChecked( true );
564     
565     MainWidget->GroupDest ->setEnabled( true );
566     MainWidget->GroupDest1->setEnabled( true );
567     MainWidget->GroupDest ->show();
568     MainWidget->GroupDest1->show();
569     DestClicked( 1 );
570     if (mySketchState == FIRST_POINT)
571     {
572       OnFirstPoint();
573     }
574   }
575   else if (  myConstructorId == 1 ) { // ARC
576     GroupPt ->setEnabled( true );
577     GroupPt2->setEnabled( true );
578     GroupD2->RB_Dir21->setChecked( true );
579     GroupD1->setEnabled( true );
580     GroupD2->setEnabled( false );
581     MainWidget->RB_Dest1->setEnabled( true ); 
582     MainWidget->RB_Dest1->setChecked( true );
583     
584     MainWidget->GroupDest ->setEnabled( true );
585     MainWidget->GroupDest1->setEnabled( true );
586     MainWidget->GroupDest ->show();
587     MainWidget->GroupDest1->show();
588     DestClicked( 1 );
589     if (mySketchState == FIRST_POINT)
590     {
591       OnFirstPoint();
592     }
593   }
594   else if (  myConstructorId == 2 ) { // RECTANGLE
595     GroupPt ->setEnabled( false );
596     GroupPt2->setEnabled( false );
597     GroupD1 ->setEnabled( false );
598     GroupD2 ->setEnabled( false );
599     MainWidget->GroupDest ->setEnabled( false );
600     MainWidget->GroupDest1->setEnabled( false );
601
602     GroupPt ->hide();
603     GroupPt2->hide();
604     GroupD1 ->hide();
605     GroupD2 ->hide();
606     MainWidget->GroupDest ->hide();
607     MainWidget->GroupDest1->hide();
608     
609     MainWidget->buttonEnd->setText(tr("Apply and Close"));
610     MainWidget->buttonClose->setEnabled(false);
611     
612     GroupRect->setEnabled( true );
613     MainWidget->RadioButton1->setEnabled( true );
614     MainWidget->RadioButton2->setEnabled( true );
615     
616     RectClicked();
617   }
618 }
619
620 //=================================================================================
621 // function : RectClicked()
622 // purpose  : Radio button management
623 //=================================================================================
624 void EntityGUI_SketcherDlg::RectClicked()
625 {
626   InitClick();
627   
628   // Connect the selction manager (disconnected in InitClick())
629   connect( myGeometryGUI->getApp()->selectionMgr(),
630        SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
631   
632   GroupRect->show();
633   
634   myX1=0;
635   myX2=10;
636   myY1=0;
637   myY2=10;
638
639   GroupRect->SpinBox_DX1->setValue(myX1); 
640   GroupRect->SpinBox_DY1->setValue(myY1);
641   GroupRect->SpinBox_DX2->setValue(myX2);
642   GroupRect->SpinBox_DY2->setValue(myY2);
643   
644   resize( minimumSizeHint() );
645   
646   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
647 }
648
649
650 //=================================================================================
651 // function : DestClicked()
652 // purpose  : Radio button management
653 //=================================================================================
654 void EntityGUI_SketcherDlg::DestClicked( int constructorId )
655 {
656   GroupPt->hide();
657   GroupPt2->hide();
658   GroupD1->hide();
659   GroupD2->hide();
660
661   if ( constructorId == 1 ) {
662     // Point
663     GroupPt->RB_Point1->setChecked( true );
664     GroupPt->show();
665     GroupPt2->show();
666     Group3Spin->checkBox->show();
667     Group4Spin->checkBox->show();
668     PointClicked( 1 );  // XY
669   }
670   else if (  constructorId == 0 ) {
671     // Direction
672     GroupD1->RB_Dir11->setChecked( true );
673     GroupD1->show();
674     GroupD2->show();
675     Group3Spin->checkBox->hide();
676     Group4Spin->checkBox->hide();
677     Dir1Clicked( 2 );  // Angle
678   }
679   resize( minimumSizeHint() );
680 }
681
682 //=================================================================================
683 // function : PointClicked()
684 // purpose  : Radio button management
685 //=================================================================================
686 void EntityGUI_SketcherDlg::PointClicked( int constructorId )
687 {
688   MESSAGE("PointClicked")
689   myConstructorPntId = constructorId;  
690   GroupPt->RB_Point3->setEnabled( true );
691   int buttonId = GroupPt2->ButtonGroup->checkedId();
692   if (buttonId >= 0){           // = If a button is checked
693     Point2Clicked(buttonId);
694   }
695   else{ 
696     GroupPt2->RB_Point1->setChecked( true );
697     Point2Clicked( 1 ); 
698   }
699 }
700
701 //=================================================================================
702 // function : Point2Clicked()
703 // purpose  : Radio button management
704 //=================================================================================
705 void EntityGUI_SketcherDlg::Point2Clicked( int constructorId )
706 {
707   MESSAGE("Point2Clicked")
708   InitClick();
709
710   // Get setting of step value from file configuration
711   double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
712
713   if ( myConstructorPntId == 1 ) {  // XY
714     if ( constructorId == 1 ){      // No additional parameter
715       mySketchType = PT_ABS;
716       initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
717       initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
718       Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X2" ) );
719       Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y2" ) );
720       myX = 0.0;
721       Group2Spin->SpinBox_DX->setValue( myX );
722       myY = 0.0;
723       Group2Spin->SpinBox_DY->setValue( myY );
724       Group2Spin->show();
725       Group2Spin->buttonApply->setFocus();
726
727       GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
728     }
729     else if ( constructorId == 0 ){   // Point + radius
730       mySketchType = PT_ABS_RADIUS;
731       initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" ); 
732       initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
733       initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step/10.0, "length_precision" );
734       Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X2" ) );
735       Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y2" ) );
736       Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_RADIUS2" ) ); 
737       myX = 0.0;
738       Group3Spin->SpinBox_DX->setValue( myX );
739       myY = 0.0;
740       Group3Spin->SpinBox_DY->setValue( myY );
741       myRadius=0.0;
742       Group3Spin->SpinBox_DZ->setValue( myRadius ); 
743       Group3Spin->show();
744       Group3Spin->buttonApply->setFocus();
745
746       GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
747     }
748     else if ( constructorId == 2 ){   // Point + center
749       mySketchType = PT_ABS_CENTER;
750       initSpinBox( Group4Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" ); 
751       initSpinBox( Group4Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
752       initSpinBox( Group4Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
753       initSpinBox( Group4Spin->SpinBox_DS, COORD_MIN, COORD_MAX, step, "length_precision" );
754       Group4Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_X2" ) );
755       Group4Spin->TextLabel4->setText( tr( "GEOM_SKETCHER_Y2" ) );
756       Group4Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_CENTER_X" ) );
757       Group4Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_CENTER_Y" ) ); 
758       myXc = 0.0;
759       Group4Spin->SpinBox_DX->setValue( myXc );
760       myYc = 0.0;
761       Group4Spin->SpinBox_DY->setValue( myYc );
762       myX = 0.0;
763       Group4Spin->SpinBox_DZ->setValue( myX ); 
764       myY = 0.0;
765       Group4Spin->SpinBox_DS->setValue( myY );
766       Group4Spin->show();
767       Group4Spin->buttonApply->setFocus();
768
769       GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
770     }
771
772   }
773   else if ( myConstructorPntId == 0 ) {  // DXDY
774     if ( constructorId == 1 ){    // No additional parameter
775       mySketchType = PT_RELATIVE;
776       initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
777       initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
778       Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_DX2" ) );
779       Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_DY2" ) );
780       myDX = 0.0;
781       Group2Spin->SpinBox_DX->setValue( myDX );
782       myDY = 0.0;
783       Group2Spin->SpinBox_DY->setValue( myDY );
784       Group2Spin->show();
785       Group2Spin->buttonApply->setFocus();
786
787       GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
788     }
789     else if ( constructorId == 0 ){   // Point + radius 
790       mySketchType = PT_REL_RADIUS;
791       initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" ); 
792       initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
793       initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step/10.0, "length_precision" );
794       Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_DX2" ) );
795       Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_DY2" ) );
796       Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_RADIUS2" ) ); 
797       myDX = 10.0;
798       Group3Spin->SpinBox_DX->setValue( myDX );
799       myDY = 0.0;
800       Group3Spin->SpinBox_DY->setValue( myDY );
801       myRadius=5.0;
802       Group3Spin->SpinBox_DZ->setValue( myRadius );
803       Group3Spin->show();
804       Group3Spin->buttonApply->setFocus();
805
806       GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
807     }
808     else if ( constructorId == 2 ){   // Point + center
809       mySketchType = PT_REL_CENTER;
810       initSpinBox( Group4Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" ); 
811       initSpinBox( Group4Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
812       initSpinBox( Group4Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
813       initSpinBox( Group4Spin->SpinBox_DS, COORD_MIN, COORD_MAX, step, "length_precision" );
814       Group4Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_DX2" ) );
815       Group4Spin->TextLabel4->setText( tr( "GEOM_SKETCHER_DY2" ) );
816       Group4Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_CENTER_DX" ) );
817       Group4Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_CENTER_DY" ) ); 
818       myDXc = 0.0;
819       Group4Spin->SpinBox_DX->setValue( myDXc );
820       myDYc = 0.0;
821       Group4Spin->SpinBox_DY->setValue( myDYc );
822       myDX = 0.0;
823       Group4Spin->SpinBox_DZ->setValue( myDX ); 
824       myDY = 0.0;
825       Group4Spin->SpinBox_DS->setValue( myDY );
826       Group4Spin->show();
827       Group4Spin->buttonApply->setFocus();
828
829       GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
830     }
831
832   }
833   else if ( myConstructorPntId == 2 ) {  // Selection
834     if ( constructorId == 1 ){    // No additional parameter
835       mySketchType = PT_SEL;
836       myEditCurrentArgument = Group1Sel->LineEdit1;
837       Group1Sel->TextLabel1->setText( tr( "GEOM_SKETCHER_END_POINT2" ) ); 
838       Group1Sel->show();
839       Group1Sel->buttonApply->setFocus();
840       SelectionIntoArgument();
841     }
842     else if ( constructorId == 0 ){   // Point + radius 
843       mySketchType = PT_SEL_RADIUS;
844       myEditCurrentArgument = Group1Sel1Spin->LineEdit1;
845       initSpinBox( Group1Sel1Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step/10.0, "length_precision" );
846       Group1Sel1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_END_POINT2" ) ); 
847       Group1Sel1Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_RADIUS2" ) ); 
848       myRadius=0.0;
849       Group1Sel1Spin->SpinBox_DX->setValue( myRadius );
850
851       Group1Sel1Spin->show();
852       Group1Sel1Spin->buttonApply->setFocus();
853       SelectionIntoArgument();
854     }
855     else if ( constructorId == 2 ){   // Point + center 
856       mySketchType = PT_SEL_CENTER;
857       myEditCurrentArgument = Group2Sel->LineEdit1;
858       Group2Sel->TextLabel2->setText( tr( "GEOM_SKETCHER_END_POINT2" ) );  
859       Group2Sel->TextLabel1->setText( tr( "GEOM_SKETCHER_CENTER2" ) );
860       Group2Sel->LineEdit1->setEnabled(true);
861       Group2Sel->PushButton1->setDown(true);
862       Group2Sel->LineEdit2->setEnabled(false);
863       Group2Sel->PushButton2->setDown(false);
864       Group2Sel->show();
865       Group2Sel->buttonApply->setFocus();
866       SelectionIntoArgument();
867     }
868
869   }
870   resize( minimumSizeHint() );
871   connect( myGeometryGUI->getApp()->selectionMgr(),
872       SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
873   
874 }
875
876
877 //=================================================================================
878 // function : Dir1Clicked()
879 // purpose  : Radio button management
880 //=================================================================================
881 void EntityGUI_SketcherDlg::Dir1Clicked( int constructorId )
882 {
883   myConstructorDirId = constructorId;
884   int dirButtonId = GroupD2->ButtonGroup->checkedId();
885   if (dirButtonId >= 0){           // = If a button is checked
886     Dir2Clicked(dirButtonId);
887   }
888   else{ 
889     GroupD2->RB_Dir21->setChecked( true );
890     Dir2Clicked( 2 ); 
891   }
892 }
893
894
895 //=================================================================================
896 // function : Dir2Clicked()
897 // purpose  : Radio button management
898 //=================================================================================
899 void EntityGUI_SketcherDlg::Dir2Clicked( int constructorId )
900 {
901   InitClick();
902   myAngle = 0.0;
903
904   // Get setting of step value from file configuration
905   double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
906
907   if ( myConstructorId == 0 ) {  // SEGMENT
908     myX = 0.0;
909     myY = 0.0;
910     myLength = 100.0;
911     if ( myConstructorDirId == 2 ) {  // Angle
912       initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 5., "length_precision" );
913       Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
914       Group2Spin->SpinBox_DX->setValue( myAngle );
915       Group2Spin->buttonApply->setFocus();
916       Group2Spin->show();
917
918       if ( constructorId == 2 ) {  // Length
919         mySketchType = DIR_ANGLE_LENGTH;
920         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
921         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
922         Group2Spin->SpinBox_DY->setValue( myLength );
923       }
924       else if ( constructorId == 0 ) {  // X
925         mySketchType = DIR_ANGLE_X;
926         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "angle_precision" );
927         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_X3" ) );
928         Group2Spin->SpinBox_DY->setValue( myX );
929       }
930       else if ( constructorId == 1 ) {  // Y
931         mySketchType = DIR_ANGLE_Y;
932         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "angle_precision" );        
933         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y3" ) );
934         Group2Spin->SpinBox_DY->setValue( myY );
935       }
936     }
937     else if ( myConstructorDirId == 0 ) {  // Perpendicular
938       Group1Spin->show();
939       Group1Spin->buttonApply->setFocus();
940
941       if ( constructorId == 2 ) {  // Length
942         mySketchType = DIR_PER_LENGTH;
943         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
944         Group1Spin->SpinBox_DX->setValue( myLength );
945       }
946       else if ( constructorId == 0 ) {  // X
947         mySketchType = DIR_PER_X;
948         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X3" ) );
949         Group1Spin->SpinBox_DX->setValue( myX );
950       }
951       else if ( constructorId == 1 ) {  // Y
952         mySketchType = DIR_PER_Y;
953         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_Y3" ) );
954         Group1Spin->SpinBox_DX->setValue( myY );
955       }
956     }
957     else if ( myConstructorDirId == 1 ) {  // Tangent
958       Group1Spin->show();
959       Group1Spin->buttonApply->setFocus();
960
961       if ( constructorId == 2 ) {  // Length
962         mySketchType = DIR_TAN_LENGTH;
963         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
964         Group1Spin->SpinBox_DX->setValue( myLength );
965       }
966       else if ( constructorId == 0 ) {  // X
967         mySketchType = DIR_TAN_X;
968         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X3" ) );
969         Group1Spin->SpinBox_DX->setValue( myX );
970       }
971       else if ( constructorId == 1 ) {  // Y
972         mySketchType = DIR_TAN_Y;
973         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_Y3" ) );
974         Group1Spin->SpinBox_DX->setValue( myY );
975       }
976     }
977     else if ( myConstructorDirId == 3 ) {  // DXDY
978       initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
979       initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
980       initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
981       Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_VX2" ) );
982       Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_VY2" ) );
983       myDX = 0.0;
984       Group3Spin->SpinBox_DX->setValue( myDX );
985       myDY = 0.0;
986       Group3Spin->SpinBox_DY->setValue( myDY );
987       Group3Spin->show();
988       Group3Spin->buttonApply->setFocus();
989
990       if ( constructorId == 2 ) {  // Length
991         mySketchType = DIR_DXDY_LENGTH;
992         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
993         Group3Spin->SpinBox_DZ->setValue( myLength );
994       }
995       else if ( constructorId == 0 ) { // X
996         mySketchType = DIR_DXDY_X;
997         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_X3" ) );
998         Group3Spin->SpinBox_DZ->setValue( myX );
999       }
1000       else if ( constructorId == 1 ) {  // Y
1001         mySketchType = DIR_DXDY_Y;
1002         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_Y3" ) );
1003         Group3Spin->SpinBox_DZ->setValue( myY );
1004       }
1005     }
1006   }
1007   else if ( myConstructorId == 1 ) {  // ARC
1008     if ( myConstructorDirId == 2 ) {  // Angle
1009       if ( constructorId == 2 ) {  // Length
1010         mySketchType = DIR_ANGLE_LENGTH;
1011         initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 5., "angle_precision" );
1012         initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
1013         initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, 5., "angle_precision" );
1014         Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
1015         Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
1016         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_ANGLE2" ));
1017         Group3Spin->SpinBox_DX->setValue( myAngle );
1018         myRadius = 100.0;
1019         Group3Spin->SpinBox_DY->setValue( myRadius );
1020         myLength = 30.0;
1021         Group3Spin->SpinBox_DZ->setValue( myLength );
1022         Group3Spin->show();
1023         Group3Spin->buttonApply->setFocus();
1024       }
1025     }
1026     else if ( myConstructorDirId == 0 ) {  // Perpendicular
1027       if ( constructorId == 2 ) {  // Length
1028         mySketchType = DIR_PER_LENGTH;
1029         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
1030         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 5., "angle_precision" );
1031         Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
1032         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
1033         myRadius = 100.0;
1034         Group2Spin->SpinBox_DX->setValue( myRadius );
1035         myLength = 30.0;
1036         Group2Spin->SpinBox_DY->setValue( myLength );
1037         Group2Spin->show();
1038         Group2Spin->buttonApply->setFocus();
1039       }
1040     }
1041     else if ( myConstructorDirId == 1 ) {  // Tangent
1042       if ( constructorId == 2 ) {  // Length
1043         mySketchType = DIR_TAN_LENGTH;
1044         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
1045         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 5., "angle_precision" );
1046         Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
1047         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
1048         myRadius = 100.0;
1049         Group2Spin->SpinBox_DX->setValue( myRadius );
1050         myLength = 30.0;
1051         Group2Spin->SpinBox_DY->setValue( myLength );
1052         Group2Spin->show();
1053         Group2Spin->buttonApply->setFocus();
1054       }
1055     }
1056     else if ( myConstructorDirId == 3 ) {  // DXDY
1057       if ( constructorId == 2 ) {  // Length
1058         mySketchType = DIR_DXDY_LENGTH;
1059         Group4Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_VX2" ) );
1060         Group4Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_VY2" ) );
1061         Group4Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
1062         Group4Spin->TextLabel4->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
1063         initSpinBox( Group4Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
1064         initSpinBox( Group4Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
1065         initSpinBox( Group4Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
1066         initSpinBox( Group4Spin->SpinBox_DS, COORD_MIN, COORD_MAX, 5., "length_precision" );
1067         myDX = 0.0;
1068         Group4Spin->SpinBox_DX->setValue( myDX );
1069         myDY = 0.0;
1070         Group4Spin->SpinBox_DY->setValue( myDY );
1071         myRadius = 100.0;
1072         Group4Spin->SpinBox_DZ->setValue( myRadius );
1073         myLength = 30.0;
1074         Group4Spin->SpinBox_DS->setValue( myLength );
1075         Group4Spin->show();
1076         Group4Spin->buttonApply->setFocus();
1077       }
1078     }
1079   }
1080   resize( minimumSizeHint() );
1081   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
1082 }
1083
1084 //=================================================================================
1085 // function : CheckBoxClicked()
1086 // purpose  : CheckBox  management
1087 //=================================================================================
1088 void EntityGUI_SketcherDlg::CheckBoxClicked(int State)
1089 {
1090   myCheckFlag = State;
1091
1092   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
1093 }
1094
1095
1096 //=================================================================================
1097 // function : ClickOnCancel()
1098 // purpose  :
1099 //=================================================================================
1100 void EntityGUI_SketcherDlg::ClickOnCancel()
1101 {
1102   close();
1103 }
1104
1105
1106 //=================================================================================
1107 // function : ClickOnEnd()
1108 // purpose  : connected to buttonEnd AND buttonClose
1109 //=================================================================================
1110 void EntityGUI_SketcherDlg::ClickOnEnd()
1111 {
1112   MESSAGE("EntityGUI_SketcherDlg::ClickOnEnd()")
1113   if ( sender() == MainWidget->buttonClose ) {
1114     // Verify validity of commands
1115     if ( myCommand.count() <= 2 ) {
1116       SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
1117                                  tr( "GEOM_ERROR_STATUS" ), tr( "CANNOT_CLOSE" ), tr( "BUT_OK" ) );
1118       return;
1119     }
1120
1121     QString Parameters;
1122     QString Command = myCommand.join( "" ) + GetNewCommand( Parameters );
1123     Sketcher_Profile aProfile( Command.toAscii() );
1124
1125     Command = myCommand.join( "" );
1126     aProfile = Sketcher_Profile( Command.toAscii() );
1127     TopoDS_Shape myShape;
1128     if ( aProfile.IsDone() )
1129       myShape = aProfile.GetShape();
1130
1131     if ( myShape.ShapeType() != TopAbs_VERTEX )
1132       myCommand.append( ":WW" );
1133   }
1134   else {
1135     /*// PAL16008 (Sketcher Validation should be equal to Apply&Close)
1136     if ( ( Group1Spin->buttonApply->isEnabled() && Group1Spin->isVisible() ) ||
1137          ( Group2Spin->buttonApply->isEnabled() && Group2Spin->isVisible() ) ||
1138          ( Group3Spin->buttonApply->isEnabled() && Group3Spin->isVisible() ) ||
1139          ( Group4Spin->buttonApply->isEnabled() && Group4Spin->isVisible() ) ||
1140          ( Group1Sel->buttonApply->isEnabled()  && Group1Sel->isVisible()  ) ||
1141          ( Group2Sel->buttonApply->isEnabled()  && Group2Sel->isVisible()  ) ||
1142          ( Group1Sel1Spin->buttonApply->isEnabled() && Group1Sel1Spin->isVisible() ) )  {     
1143       ClickOnApply();
1144     }*/
1145 //     ClickOnApply(); // TEST remove then
1146     myIsAllAdded = true;
1147   }
1148
1149   if (myConstructorId == 2)
1150   {
1151     QString aParameters;
1152     myCommand.append( GetNewCommand( aParameters ) );
1153     mySketchState = NEXT_POINT;
1154     if ( onAccept() )
1155       ClickOnCancel();
1156   }
1157   if ( myCommand.size() > 2 )
1158   {
1159     if ( !onAccept() )
1160       return;
1161   }
1162
1163   close();
1164 }
1165
1166 //=================================================================================
1167 // function : ClickOnApply()
1168 // purpose  :
1169 //=================================================================================
1170 bool EntityGUI_SketcherDlg::ClickOnApply()
1171 {
1172   MESSAGE("EntityGUI_SketcherDlg::ClickOnApply()")
1173   if ( sender() && sender()->inherits( "QPushButton" ) )
1174     ( (QPushButton*)sender() )->setFocus(); // to update value of currently edited spin-box (PAL11948)
1175
1176 //   addSubshapesToStudy();
1177
1178   QString aParameters;
1179   myCommand.append( GetNewCommand( aParameters ) );
1180   if (mySketchState == FIRST_POINT)
1181   {
1182     mySketchState = NEXT_POINT;
1183     OnNextPoint();
1184   }
1185
1186   myUndoCommand.clear();
1187   myUndoCommand.append( "Sketcher" );
1188
1189   myParameters.append( aParameters );
1190   myUndoParameters.clear();
1191
1192   setEnabledUndo( true );
1193   setEnabledRedo( false );
1194
1195   myIsApply = true;
1196   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
1197   myIsApply = false;
1198
1199   // Set focus to SpinBox_DX
1200   if ( sender() == Group1Spin->buttonApply ) {
1201     (Group1Spin->SpinBox_DX)->setFocus();
1202     (Group1Spin->SpinBox_DX)->selectAll();
1203   }
1204   else if ( sender() == Group1Sel1Spin->buttonApply ) {
1205     (Group1Sel1Spin->SpinBox_DX)->setFocus();
1206     (Group1Sel1Spin->SpinBox_DX)->selectAll();
1207   }
1208   else if ( sender() == Group2Spin->buttonApply ) {
1209     (Group2Spin->SpinBox_DX)->setFocus();
1210     (Group2Spin->SpinBox_DX)->selectAll();
1211   }
1212   else if ( sender() == Group3Spin->buttonApply ) {
1213     (Group3Spin->SpinBox_DX)->setFocus();
1214     (Group3Spin->SpinBox_DX)->selectAll();
1215   }
1216   else if ( sender() == Group4Spin->buttonApply ) {
1217     (Group4Spin->SpinBox_DX)->setFocus();
1218     (Group4Spin->SpinBox_DX)->selectAll();
1219   }
1220   
1221   return true;
1222 }
1223
1224 //=================================================================================
1225 // function : ClickOnHelp()
1226 // purpose  :
1227 //=================================================================================
1228 void EntityGUI_SketcherDlg::ClickOnHelp()
1229 {
1230   LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
1231   if ( app )
1232     app->onHelpContextModule( myGeometryGUI ? app->moduleName( myGeometryGUI->moduleName() ) : QString( "" ), myHelpFileName );
1233   else {
1234     QString platform;
1235 #ifdef WIN32
1236     platform = "winapplication";
1237 #else
1238     platform = "application";
1239 #endif
1240
1241     SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
1242                               QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
1243                               arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
1244                               QObject::tr( "BUT_OK" ) );
1245   }
1246 }
1247
1248 //=================================================================================
1249 // function : ClickOnUndo()
1250 // purpose  :
1251 //=================================================================================
1252 void EntityGUI_SketcherDlg::ClickOnUndo()
1253 {
1254   myUndoCommand.append( myCommand.last() );
1255   myCommand.pop_back();
1256
1257   myUndoParameters.append( myParameters.last() );
1258   myParameters.pop_back();
1259
1260   if ( myCommand.count() == 1 ) {
1261     mySketchState = FIRST_POINT;
1262
1263     MainWidget->RadioButton1->setChecked( true );
1264     TypeClicked( 0 );
1265
1266     connect( myGeometryGUI->getApp()->selectionMgr(),
1267              SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
1268
1269     OnFirstPoint();
1270
1271     setEnabledUndo( false );
1272   }
1273
1274   setEnabledRedo( true );
1275
1276   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
1277 }
1278
1279 //=================================================================================
1280 // function : ClickOnRedo()
1281 // purpose  :
1282 //=================================================================================
1283 void EntityGUI_SketcherDlg::ClickOnRedo()
1284 {
1285   myCommand.append( myUndoCommand.last() );
1286   myUndoCommand.pop_back();
1287
1288   myParameters.append( myUndoParameters.last() );
1289   myUndoParameters.pop_back();
1290
1291   mySketchState = NEXT_POINT;
1292   
1293   OnNextPoint();
1294   
1295   setEnabledUndo( true );
1296
1297   if ( myUndoCommand.count() == 1 )
1298     setEnabledRedo( false );
1299
1300   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
1301 }
1302
1303 //=================================================================================
1304 // function : setEnabledUndo()
1305 // purpose  :
1306 //=================================================================================
1307 void EntityGUI_SketcherDlg::setEnabledUndo( bool value )
1308 {
1309   Group1Sel->buttonUndo->setEnabled( value );
1310   Group2Sel->buttonUndo->setEnabled( value );
1311   Group1Sel1Spin->buttonUndo->setEnabled( value );
1312   Group1Spin->buttonUndo->setEnabled( value );
1313   Group2Spin->buttonUndo->setEnabled( value );
1314   Group3Spin->buttonUndo->setEnabled( value );
1315   Group4Spin->buttonUndo->setEnabled( value );
1316 }
1317
1318 //=================================================================================
1319 // function : setEnabledRedo()
1320 // purpose  :
1321 //=================================================================================
1322 void EntityGUI_SketcherDlg::setEnabledRedo( bool value )
1323 {
1324   Group1Sel->buttonRedo->setEnabled( value );
1325   Group2Sel->buttonRedo->setEnabled( value );
1326   Group1Sel1Spin->buttonRedo->setEnabled( value );
1327   Group1Spin->buttonRedo->setEnabled( value );
1328   Group2Spin->buttonRedo->setEnabled( value );
1329   Group3Spin->buttonRedo->setEnabled( value );
1330   Group4Spin->buttonRedo->setEnabled( value );
1331 }
1332
1333 //=================================================================================
1334 // function : SelectionIntoArgument()
1335 // purpose  : Called when selection as changed
1336 //=================================================================================
1337 void EntityGUI_SketcherDlg::SelectionIntoArgument()
1338 {
1339   MESSAGE("EntityGUI_SketcherDlg::SelectionIntoArgument")
1340   myEditCurrentArgument->setText( "" );
1341
1342   LightApp_SelectionMgr* aSelMgr = myGeometryGUI->getApp()->selectionMgr();
1343   SALOME_ListIO aSelList;
1344   aSelMgr->selectedObjects(aSelList);
1345   
1346   this->activateWindow();
1347   
1348   if (aSelList.Extent() == 0)
1349   {
1350     selButton->setDown(false);
1351     WPlaneLineEdit->setEnabled(false);
1352     WPlaneLineEdit->setText(tr("GEOM_SKETCHER_WPLANE"));
1353     return;
1354   }
1355   else if (aSelList.Extent() != 1)                                
1356     return;
1357   
1358   double tmpX = myX;
1359   double tmpY = myY;
1360   myX = myLastX1;
1361   myY = myLastY1;
1362   
1363   TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
1364   if (myEditCurrentArgument == WPlaneLineEdit)
1365     aNeedType = TopAbs_FACE;
1366   
1367  
1368   GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
1369   TopoDS_Shape aShape;
1370   
1371   if(aSelectedObject && GEOMBase::GetShape(aSelectedObject.get(), aShape) 
1372                      && !aShape.IsNull())
1373   { 
1374     QString aName = GEOMBase::GetName( aSelectedObject.get() ); 
1375     if (myEditCurrentArgument==WPlaneLineEdit)  
1376     { 
1377       // Check if the face is planar
1378       Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aShape));
1379       GeomLib_IsPlanarSurface aPlanarCheck(aSurf, Precision::Confusion());
1380       
1381       if (aPlanarCheck.IsPlanar())
1382       {
1383         myEditCurrentArgument->setText(aName);
1384         AddLocalCS(aSelectedObject.get());
1385         selButton->setDown(false);
1386         WPlaneLineEdit->setEnabled(false);
1387         TypeClicked( myConstructorId );
1388       }
1389       else
1390       {
1391         myEditCurrentArgument->setText(tr("GEOM_SKETCHER_WPLANE"));
1392         // The following leads to crash TODO : find a way to return a warning
1393 //         Standard_Failure::Raise(tr("GEOM_SKETCHER_NOT_PLANAR").toStdString().c_str()); 
1394       }
1395     }           
1396     else
1397     {
1398       gp_Trsf aTrans;
1399       gp_Ax3 aWPlane = GetActiveLocalCS();
1400
1401       aTrans.SetTransformation(aWPlane);
1402       BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
1403       aShape = aTransformation.Shape();
1404
1405       gp_Pnt aPnt;
1406       if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) 
1407       {
1408         myEditCurrentArgument->setText(aName);
1409         myX = aPnt.X();
1410         myY = aPnt.Y();       
1411         double Xcoord = myX;
1412         double Ycoord = myY;
1413         
1414         switch (mySketchType)
1415         {
1416           case PT_ABS:
1417           disconnect( Group2Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1418           disconnect( Group2Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1419           
1420           Group2Spin->SpinBox_DX->setValue(Xcoord);
1421           Group2Spin->SpinBox_DY->setValue(Ycoord);
1422       
1423           connect( Group2Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1424           connect( Group2Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1425             break;
1426             
1427           case PT_RELATIVE:
1428             if (myLastX1 && myLastY1)
1429             {
1430               Xcoord = myX - myLastX1;
1431               Ycoord = myY - myLastY1;
1432             }
1433             else if (mySketchState != FIRST_POINT)
1434             {
1435               Xcoord = myX - tmpX;
1436               Ycoord = myY - tmpY;
1437             }          
1438             Group2Spin->SpinBox_DX->setValue(Xcoord);
1439             Group2Spin->SpinBox_DY->setValue(Ycoord);      
1440             break; 
1441             
1442           case PT_ABS_RADIUS:
1443             disconnect( Group3Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1444             disconnect( Group3Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1445             
1446             Group3Spin->SpinBox_DX->setValue(Xcoord);
1447             Group3Spin->SpinBox_DY->setValue(Ycoord);
1448       
1449             connect( Group3Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1450             connect( Group3Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1451             break;
1452             
1453           case PT_REL_RADIUS:
1454             if (myLastX1 && myLastY1)
1455             {
1456               Xcoord = myX - myLastX1;
1457               Ycoord = myY - myLastY1;
1458             }
1459             else if (mySketchState != FIRST_POINT)
1460             {
1461               Xcoord = myX - tmpX;
1462               Ycoord = myY - tmpY;
1463             }             
1464             Group3Spin->SpinBox_DX->setValue(Xcoord);
1465             Group3Spin->SpinBox_DY->setValue(Ycoord);
1466             break; 
1467             
1468           case PT_ABS_CENTER:
1469             disconnect( Group4Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1470             disconnect( Group4Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1471             
1472             Group4Spin->SpinBox_DX->setValue(Xcoord);
1473             Group4Spin->SpinBox_DY->setValue(Ycoord);
1474       
1475             connect( Group4Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1476             connect( Group4Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );        
1477             break;
1478             
1479           case PT_REL_CENTER:
1480             if (myLastX1 && myLastY1)
1481             {
1482               Xcoord = myXc - myLastX1;
1483               Ycoord = myYc - myLastY1;
1484             }
1485             else if (mySketchState != FIRST_POINT)
1486             {
1487               Xcoord = myXc - tmpX;
1488               Ycoord = myYc - tmpY;
1489             } 
1490             else
1491             {
1492               Xcoord = myXc;
1493               Ycoord = myYc;
1494             }
1495             
1496             Group4Spin->SpinBox_DX->setValue(Xcoord);
1497             Group4Spin->SpinBox_DY->setValue(Ycoord);            
1498             break; 
1499             
1500         }
1501       }
1502     }
1503   }
1504
1505   if(!autoApply){
1506     GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
1507   }
1508   else {    
1509     ClickOnApply();
1510     autoApply = false;
1511   }
1512   
1513 }
1514
1515
1516 //=================================================================================
1517 // function : SetEditCurrentArgument()
1518 // purpose  :
1519 //=================================================================================
1520 void EntityGUI_SketcherDlg::SetEditCurrentArgument()
1521 {
1522   TopAbs_ShapeEnum myNeedType = TopAbs_VERTEX;
1523   if ( sender() == Group1Sel->PushButton1 ) {
1524     myEditCurrentArgument = Group1Sel->LineEdit1;
1525     myEditCurrentArgument->setFocus();
1526   }
1527   else if ( sender() == Group1Sel1Spin->PushButton1 ) {
1528     myEditCurrentArgument = Group1Sel1Spin->LineEdit1;
1529     myEditCurrentArgument->setFocus();
1530   }
1531   else if ( sender() == Group2Sel->PushButton1 ) {
1532     myEditCurrentArgument = Group2Sel->LineEdit1;
1533     Group2Sel->PushButton2->setDown(false);
1534     Group2Sel->PushButton1->setDown(true);
1535     Group2Sel->LineEdit2->setEnabled(false);
1536     Group2Sel->LineEdit1->setEnabled(true);
1537    // myEditCurrentArgument->setFocus();
1538   }
1539    else if ( sender() == Group2Sel->PushButton2 ) {
1540     myEditCurrentArgument = Group2Sel->LineEdit2;
1541     Group2Sel->PushButton1->setDown(false);
1542     Group2Sel->PushButton2->setDown(true);
1543     Group2Sel->LineEdit1->setEnabled(false);
1544     Group2Sel->LineEdit2->setEnabled(true);
1545    // myEditCurrentArgument->setFocus();
1546   }
1547   else if ( sender() == selButton ) {
1548     myNeedType = TopAbs_FACE;
1549     myEditCurrentArgument = WPlaneLineEdit;
1550     WPlaneLineEdit->setEnabled(true);
1551     selButton->setDown(true);
1552   }
1553   globalSelection(); // close local selection to clear it
1554   localSelection(GEOM::GEOM_Object::_nil(), myNeedType);
1555 }
1556
1557
1558 //=================================================================================
1559 // function : LineEditReturnPressed()
1560 // purpose  :
1561 //=================================================================================
1562 void EntityGUI_SketcherDlg::LineEditReturnPressed()
1563 {
1564   if ( sender() == Group1Sel->LineEdit1 ) 
1565     myEditCurrentArgument = Group1Sel->LineEdit1;
1566   else if ( sender() == Group1Sel1Spin->LineEdit1 ) 
1567      myEditCurrentArgument = Group1Sel1Spin->LineEdit1;
1568   else if ( sender() == Group2Sel->LineEdit1 ) 
1569      myEditCurrentArgument = Group2Sel->LineEdit1;
1570   else if ( sender() == Group2Sel->LineEdit2 )
1571      myEditCurrentArgument = Group2Sel->LineEdit2;
1572
1573   /* User name of object input management                          */
1574   /* If successfull the selection is changed and signal emitted... */
1575   /* so SelectionIntoArgument() is automatically called.           */
1576   const QString objectUserName = myEditCurrentArgument->text();
1577   QWidget* thisWidget = (QWidget*)this;
1578
1579   LightApp_SelectionMgr* aSelMgr = myGeometryGUI->getApp()->selectionMgr();
1580   SALOME_ListIO aSelList;
1581   aSelMgr->selectedObjects(aSelList);
1582
1583   if (GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, aSelList))
1584     myEditCurrentArgument->setText( objectUserName );
1585 }
1586
1587
1588 //=================================================================================
1589 // function : DeactivateActiveDialog()
1590 // purpose  :
1591 //=================================================================================
1592 void EntityGUI_SketcherDlg::DeactivateActiveDialog()
1593 {
1594   //myGeometryGUI->SetState( -1 );
1595
1596   setEnabled( false );
1597   globalSelection();
1598   disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
1599   myGeometryGUI->SetActiveDialogBox( 0 );
1600 }
1601
1602
1603 //=================================================================================
1604 // function : ActivateThisDialog()
1605 // purpose  :
1606 //=================================================================================
1607 void EntityGUI_SketcherDlg::ActivateThisDialog()
1608 {
1609   MESSAGE("EntityGUI_SketcherDlg::ActivateThisDialog()")
1610   myGeometryGUI->EmitSignalDeactivateDialog();
1611   setEnabled( true );
1612   myGeometryGUI->SetActiveDialogBox( this );
1613
1614   connect( myGeometryGUI->getApp()->selectionMgr(),
1615           SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
1616
1617   //myGeometryGUI->SetState( 0 );
1618 //   globalSelection( GEOM_POINT );
1619   
1620   myEditCurrentArgument = WPlaneLineEdit;
1621   myEditCurrentArgument->setFocus();
1622   
1623    if ( sender() == Group1Sel->LineEdit1 ) {
1624      myEditCurrentArgument = Group1Sel->LineEdit1;
1625      myEditCurrentArgument->setFocus();
1626    }
1627    else if ( sender() == Group1Sel1Spin->LineEdit1 ) {
1628      myEditCurrentArgument = Group1Sel1Spin->LineEdit1;
1629      myEditCurrentArgument->setFocus();
1630    }
1631    else if ( sender() == Group2Sel->LineEdit1 ) {
1632      myEditCurrentArgument = Group2Sel->LineEdit1;
1633      myEditCurrentArgument->setFocus();
1634    }
1635     else if ( sender() == Group2Sel->LineEdit2 ) {
1636      myEditCurrentArgument = Group2Sel->LineEdit2;
1637      myEditCurrentArgument->setFocus();
1638    }
1639    
1640   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
1641 }
1642
1643
1644 //=================================================================================
1645 // function : enterEvent [REDEFINED]
1646 // purpose  :
1647 //=================================================================================
1648 void EntityGUI_SketcherDlg::enterEvent( QEvent* )
1649 {
1650   if ( !isEnabled() )
1651     ActivateThisDialog();
1652 }
1653
1654
1655 //=================================================================================
1656 // function : closeEvent()
1657 // purpose  :
1658 //=================================================================================
1659 void EntityGUI_SketcherDlg::closeEvent( QCloseEvent* e )
1660 {
1661   MESSAGE("EntityGUI_SketcherDlg::closeEvent")
1662   //myGeometryGUI->SetState( -1 );
1663   disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
1664   myGeometryGUI->getApp()->updateActions();
1665   QDialog::closeEvent( e );
1666 }
1667
1668 //=================================================================================
1669 // function : OnPointSelected
1670 // purpose  :
1671 //=================================================================================
1672 void EntityGUI_SketcherDlg::OnPointSelected(Qt::KeyboardModifiers modifiers, const gp_Pnt& thePnt,
1673                                             bool isStart )
1674 {
1675   // NOTE Basing the autoapply functionnality on the background picture has no sense anymore
1676   // The import picture functionnality is now used for drawing on top of a picture
1677   
1678 //   SUIT_ViewWindow*      theViewWindow  = getDesktop()->activeWindow();
1679 //   OCCViewer_ViewPort3d* vp             = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
1680 //   
1681 //   QString                theImgFileName;
1682 //   vp->background().texture( theImgFileName ); ////////////// VSR: temporarily
1683   
1684   double x, y;
1685   x = y = 0;
1686   
1687   BRepBuilderAPI_MakeVertex mkVertex (thePnt);
1688   TopoDS_Shape aShape = mkVertex.Shape();
1689   
1690   // Taking into account LocalCS
1691   gp_Ax3 aWPlane = GetActiveLocalCS();
1692   gp_Trsf aTrans;
1693
1694   aTrans.SetTransformation(aWPlane);
1695   BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
1696   aShape = aTransformation.Shape();
1697   
1698   gp_Pnt aTrsfPnt; 
1699   GEOMBase::VertexToPoint( aShape, aTrsfPnt );
1700   
1701   // NOTE autoapply disabled : doesn't seem useful anymore
1702 //   autoApply = ( (getPnt2ConstructorId() == 1) && (!theImgFileName.isEmpty()) );  // If no additional argument needed after selection and there is a backgroundimage
1703                                                                                  // -> apply automatically 
1704   
1705   if ( getPnt1ConstructorId() == 0 ){                    // Relative selection mode
1706     x = aTrsfPnt.X() - myLastX1;
1707     y = aTrsfPnt.Y() - myLastY1;
1708   }
1709   else {
1710     x = aTrsfPnt.X();
1711     y = aTrsfPnt.Y();
1712   }
1713   switch (getPnt2ConstructorId()){
1714     case 1:
1715       Group2Spin->SpinBox_DX->setValue( x );
1716       Group2Spin->SpinBox_DY->setValue( y );
1717       Group2Spin->buttonApply->setFocus();               // Previous setFocus (during preview) may have been inoperative if it was disabled 
1718       break;
1719     case 0:
1720       Group3Spin->SpinBox_DX->setValue( x );
1721       Group3Spin->SpinBox_DY->setValue( y );
1722       Group3Spin->buttonApply->setFocus(); 
1723       break;
1724     case 2:
1725       if (modifiers == Qt::MetaModifier){                // Select center with Meta key
1726         Group4Spin->SpinBox_DX->setValue( x );
1727         Group4Spin->SpinBox_DY->setValue( y );
1728       }
1729       else{                                              // Select end point
1730         Group4Spin->SpinBox_DZ->setValue( x );
1731         Group4Spin->SpinBox_DS->setValue( y );
1732       }
1733       Group4Spin->buttonApply->setFocus(); 
1734       break;
1735   }
1736   if ( myConstructorId == 2 ) //RECTANGLE
1737   {
1738     if (isStart)
1739     {
1740       GroupRect->SpinBox_DX1->setValue( aTrsfPnt.X() );
1741       GroupRect->SpinBox_DY1->setValue( aTrsfPnt.Y() );
1742       GroupRect->SpinBox_DX2->setValue( aTrsfPnt.X() );
1743       GroupRect->SpinBox_DY2->setValue( aTrsfPnt.Y() );
1744     }
1745     else
1746     {
1747       GroupRect->SpinBox_DX2->setValue( aTrsfPnt.X() );
1748       GroupRect->SpinBox_DY2->setValue( aTrsfPnt.Y() );
1749     }
1750   }
1751 }
1752
1753 //=================================================================================
1754 // function : OnFirstPoint
1755 // purpose  :
1756 //=================================================================================
1757 void EntityGUI_SketcherDlg::OnFirstPoint()
1758 {
1759   MainWidget->RadioButton3->setEnabled( true );
1760   MainWidget->GroupDest1->setEnabled( false );
1761   GroupPt2->setEnabled( false );
1762 }
1763
1764 //=================================================================================
1765 // function : OnNextPoint
1766 // purpose  :
1767 //=================================================================================
1768 void EntityGUI_SketcherDlg::OnNextPoint()
1769 {
1770   MainWidget->RadioButton3->setEnabled( false );
1771   MainWidget->GroupDest1->setEnabled( true );
1772   TypeClicked(myConstructorId);
1773 }
1774
1775 //=================================================================================
1776 // function : ValueChangedInSpinBox()
1777 // purpose  :
1778 //=================================================================================
1779 void EntityGUI_SketcherDlg::ValueChangedInSpinBox( double newValue )
1780 {
1781   QObject* send = (QObject*)sender();
1782   Standard_Real vx, vy, vz, vs, minRad, dx, dy;
1783   vx = vy = vz = vs = minRad = dx = dy = 0.0;
1784
1785   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1786   int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
1787   double LastDecimal = 0.0;
1788
1789   QString vxStr, vyStr, vzStr, vsStr;
1790
1791   QString newValueStr;
1792   if( SalomeApp_DoubleSpinBox* aDoubleSpinBox = (SalomeApp_DoubleSpinBox*)send )
1793     newValueStr = aDoubleSpinBox->text();
1794
1795   if ( send == Group1Spin->SpinBox_DX ) {
1796     vx = newValue;                        vxStr = newValueStr;
1797   }
1798   else if ( send == Group1Sel1Spin->SpinBox_DX ) {
1799     vx = newValue;                        vxStr = newValueStr;
1800   }
1801   else if ( send == Group2Spin->SpinBox_DX ) {
1802     vx = newValue;                        vxStr = newValueStr;
1803     vy = Group2Spin->SpinBox_DY->value(); vyStr = Group2Spin->SpinBox_DY->text();
1804   }
1805   else if ( send == Group2Spin->SpinBox_DY ) {
1806     vx = Group2Spin->SpinBox_DX->value(); vxStr = Group2Spin->SpinBox_DX->text();
1807     vy = newValue;                        vyStr = newValueStr;
1808   }
1809   else if ( send == Group3Spin->SpinBox_DX ) {
1810     vx = newValue;                        vxStr = newValueStr;
1811     vy = Group3Spin->SpinBox_DY->value(); vyStr = Group3Spin->SpinBox_DY->text();
1812     vz = Group3Spin->SpinBox_DZ->value();
1813     if ( (mySketchType == PT_REL_RADIUS || mySketchType == PT_ABS_RADIUS) && (vx != 0 || vy != 0) ) {  
1814       if (mySketchType == PT_ABS_RADIUS){
1815         dx = vx - myLastX1;
1816         dy = vy - myLastY1;
1817       }
1818       else{
1819         dx = vx;
1820         dy = vy;
1821       }
1822       minRad = 0.5 * Sqrt(dx * dx + dy * dy);                             //Computation of the minimum acceptable radius for the arc calculation
1823       if (aPrecision >= 0)    // 'f' format in the QString             
1824         LastDecimal = aPrecision;
1825       else                    // 'g' format in the Qstring
1826         LastDecimal = qAbs( aPrecision ) - ceil( log10(minRad) ); 
1827       minRad = ceil(pow(10,LastDecimal) * minRad) / pow(10,LastDecimal);  // Rounded up at the last allowed decimal place
1828       if ( Abs(vz) < minRad){
1829         if (vz < 0.0)
1830           Group3Spin->SpinBox_DZ->setValue( - minRad );
1831         else 
1832           Group3Spin->SpinBox_DZ->setValue( minRad );
1833       }
1834     }
1835     vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
1836   }
1837   else if ( send == Group3Spin->SpinBox_DY ) {
1838     vx = Group3Spin->SpinBox_DX->value(); vxStr = Group3Spin->SpinBox_DX->text();
1839     vy = newValue;                        vyStr = newValueStr;
1840     vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
1841     if ( (mySketchType == PT_REL_RADIUS || mySketchType == PT_ABS_RADIUS) && (vx != 0 || vy != 0)){
1842       if (mySketchType == PT_ABS_RADIUS){
1843         dx = vx - myLastX1;
1844         dy = vy - myLastY1;
1845       }
1846       else{
1847         dx = vx;
1848         dy = vy;
1849       }    
1850       minRad = 0.5 * Sqrt(dx * dx + dy * dy);                            //Computation of the minimum acceptable radius for the arc calculation
1851       if (aPrecision >= 0)    // 'f' format in the QString 
1852         LastDecimal = aPrecision;
1853       else                    // 'g' format in the QString 
1854         LastDecimal = qAbs( aPrecision ) - ceil( log10(minRad) ); 
1855         minRad = ceil(pow(10,LastDecimal) * minRad) / pow(10,LastDecimal); // Rounded up at the last allowed decimal place
1856       if ( Abs(vz) < minRad){
1857         if (vz < 0.0)
1858           Group3Spin->SpinBox_DZ->setValue( - minRad );
1859         else 
1860           Group3Spin->SpinBox_DZ->setValue( minRad );
1861       }
1862     }
1863     vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
1864   }
1865   else if ( send == Group3Spin->SpinBox_DZ ) {
1866     vx = Group3Spin->SpinBox_DX->value(); vxStr = Group3Spin->SpinBox_DX->text();
1867     vy = Group3Spin->SpinBox_DY->value(); vyStr = Group3Spin->SpinBox_DY->text();
1868     vz = newValue;                        vzStr = newValueStr;
1869   }
1870   else if ( send == Group4Spin->SpinBox_DX ) {
1871     vx = newValue;                        vxStr = newValueStr;
1872     vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1873     vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1874     vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1875   }
1876   else if ( send == Group4Spin->SpinBox_DY ) {
1877     vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1878     vy = newValue;                        vyStr = newValueStr;
1879     vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1880     vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1881   }
1882   else if ( send == Group4Spin->SpinBox_DZ ) {
1883     vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1884     vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1885     vz = newValue;                        vzStr = newValueStr;
1886     vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1887   }
1888   else if ( send == Group4Spin->SpinBox_DS ) {
1889     vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1890     vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1891     vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1892     vs = newValue;                        vsStr = newValueStr;
1893   }
1894   // Fix of the NPAL16010 bug is removed, because it's not actual with the Qt-4.x
1895
1896   if ( myConstructorId == 0 ) {  // SEGMENT
1897     if ( mySketchType == PT_ABS ) {
1898       myX = vx;
1899       myY = vy;
1900       myXStr = vxStr;
1901       myYStr = vyStr;
1902     }
1903     else if ( mySketchType == PT_RELATIVE ) {
1904       myDX = vx;
1905       myDY = vy;
1906       myDXStr = vxStr;
1907       myDYStr = vyStr;
1908     }
1909     else if ( mySketchType == DIR_ANGLE_LENGTH ) {
1910       myAngle = vx;
1911       myLength = vy;
1912       myAngleStr = vxStr;
1913       myLengthStr = vyStr;
1914     }
1915     else if ( mySketchType == DIR_ANGLE_X ) {
1916       myAngle = vx;
1917       myX = vy;
1918       myAngleStr = vxStr;
1919       myXStr = vyStr;
1920     }
1921     else if ( mySketchType == DIR_ANGLE_Y ) {
1922       myAngle = vx;
1923       myY = vy;
1924       myAngleStr = vxStr;
1925       myYStr = vyStr;
1926     }
1927     else if ( mySketchType == DIR_PER_LENGTH ) {
1928       myLength = vx;
1929       myLengthStr = vxStr;
1930     }
1931     else if ( mySketchType == DIR_PER_X ) {
1932       myX = vx;
1933       myXStr = vxStr;
1934     }
1935     else if ( mySketchType == DIR_PER_Y ) {
1936       myY = vx;
1937       myYStr = vxStr;
1938     }
1939     else if ( mySketchType == DIR_TAN_LENGTH ) {
1940       myLength = vx;
1941       myLengthStr = vxStr;
1942     }
1943     else if ( mySketchType == DIR_TAN_X ) {
1944       myX = vx;
1945       myXStr = vxStr;
1946     }
1947     else if ( mySketchType == DIR_TAN_Y ) {
1948       myY = vx;
1949       myYStr = vxStr;
1950     }
1951     else if ( mySketchType == DIR_DXDY_LENGTH ) {
1952       myDX = vx;
1953       myDY = vy;
1954       myLength = vz;
1955       myDXStr = vxStr;
1956       myDYStr = vyStr;
1957       myLengthStr = vzStr;
1958     }
1959     else if ( mySketchType == DIR_DXDY_X ) {
1960       myDX = vx;
1961       myDY = vy;
1962       myX = vz;
1963       myDXStr = vxStr;
1964       myDYStr = vyStr;
1965       myXStr = vzStr;
1966     }
1967     else if ( mySketchType == DIR_DXDY_Y ) {
1968       myDX = vx;
1969       myDY = vy;
1970       myY = vz;
1971       myDXStr = vxStr;
1972       myDYStr = vyStr;
1973       myYStr = vzStr;
1974     }
1975   }
1976   else if ( myConstructorId == 1 ) {  // ARC
1977     if ( mySketchType == PT_ABS ) {  
1978       myX = vx;
1979       myY = vy;
1980       myXStr = vxStr;
1981       myYStr = vyStr;
1982     }
1983     else if ( mySketchType == PT_RELATIVE ) {
1984       myDX = vx;
1985       myDY = vy;
1986       myDXStr = vxStr;
1987       myDYStr = vyStr;
1988     }
1989     if ( mySketchType == PT_ABS_RADIUS ) {  
1990       myX = vx;
1991       myY = vy;
1992       myRadius=vz;
1993       myXStr = vxStr;
1994       myYStr = vyStr;
1995       myRadiusStr = vzStr;
1996     }
1997     else if ( mySketchType == PT_REL_RADIUS ) {
1998       myDX = vx;
1999       myDY = vy;
2000       myRadius=vz;
2001       myDXStr = vxStr;
2002       myDYStr = vyStr;
2003       myRadiusStr = vzStr;
2004     }
2005     else if ( mySketchType == PT_SEL_RADIUS ) {
2006       myRadius = vx;
2007       myRadiusStr = vxStr;
2008     }
2009     if ( mySketchType == PT_ABS_CENTER ) {  
2010       myXc = vx;
2011       myYc = vy;
2012       myX = vz;
2013       myY = vs;
2014       myXcStr = vxStr;
2015       myYcStr = vyStr;
2016       myXStr = vzStr;
2017       myYStr = vsStr;
2018     }
2019     else if ( mySketchType == PT_REL_CENTER ) {
2020       myDXc = vx;
2021       myDYc = vy;
2022       myDX = vz;
2023       myDY = vs;
2024       myDXcStr = vxStr;
2025       myDYcStr = vyStr;
2026       myDXStr = vzStr;
2027       myDYStr = vsStr;
2028     }
2029     if ( mySketchType == DIR_ANGLE_LENGTH ) {
2030       myAngle = vx;
2031       myRadius = vy;
2032       myLength = vz;
2033       myAngleStr = vxStr;
2034       myRadiusStr = vyStr;
2035       myLengthStr = vzStr;
2036     }
2037     else if ( mySketchType == DIR_PER_LENGTH ) {
2038       myRadius = vx;
2039       myLength = vy;
2040       myRadiusStr = vxStr;
2041       myLengthStr = vyStr;
2042     }
2043     else if ( mySketchType == DIR_TAN_LENGTH ) {
2044       myRadius = vx;
2045       myLength = vy;
2046       myRadiusStr = vxStr;
2047       myLengthStr = vyStr;
2048     }
2049     else if ( mySketchType == DIR_DXDY_LENGTH ) {
2050       myDX = vx;
2051       myDY = vy;
2052       myRadius = vz;
2053       myLength = vs;
2054       myDXStr = vxStr;
2055       myDYStr = vyStr;
2056       myRadiusStr = vzStr;
2057       myLengthStr = vsStr;
2058     }
2059   }
2060   else if ( myConstructorId == 2 ) {  // RECTANGLE
2061     myX1 = GroupRect->SpinBox_DX1->value(); myX1Str = GroupRect->SpinBox_DX1->text();
2062     myX2 = GroupRect->SpinBox_DX2->value(); myX2Str = GroupRect->SpinBox_DX2->text();
2063     myY1 = GroupRect->SpinBox_DY1->value(); myY1Str = GroupRect->SpinBox_DY1->text();
2064     myY2 = GroupRect->SpinBox_DY2->value(); myY2Str = GroupRect->SpinBox_DY2->text();
2065   }
2066
2067   
2068   if (!autoApply) 
2069     GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
2070   
2071   double x, y, xc, yc;
2072   x = y = xc = yc = 0.0;
2073   if ( mySketchType == PT_ABS_CENTER || mySketchType == PT_REL_CENTER )
2074   {
2075     if ( mySketchType == PT_REL_CENTER ){
2076       x  = myDX  + myLastX1;
2077       y  = myDY  + myLastY1;
2078       xc = myDXc + myLastX1;
2079       yc = myDYc + myLastY1;
2080     }
2081     else {
2082       x  = myX ;
2083       y  = myY ;
2084       xc = myXc;
2085       yc = myYc;
2086     }
2087     displayPntPreview(xc,yc);
2088     displayPntPreview(x,y);
2089   }
2090 }
2091
2092
2093 //=================================================================================
2094 // function : GetNewCommand()
2095 // purpose  : Build the new command with context
2096 //=================================================================================
2097 QString EntityGUI_SketcherDlg::GetNewCommand( QString& theParameters )
2098 {
2099   theParameters.clear();
2100   QString myNewCommand = ":";
2101   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2102   int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
2103   int DigNum = qAbs(aPrecision);                   // options for the format of numbers in  myNewCommand
2104   char Format = 'f';
2105   if ( aPrecision < 0 )                            // f --> DigNum is the number of digits after the decimal point
2106     Format = 'g';                                  // g --> DigNum is the maximum number of significant digits 
2107
2108   if ( mySketchState == FIRST_POINT ) {
2109     if ( mySketchType == PT_ABS || mySketchType == PT_SEL ) {
2110       myNewCommand = myNewCommand + "F " + QString::number( myX, Format, DigNum) + " " + QString::number( myY, Format, DigNum);
2111       theParameters = myXStr + ":" + myYStr;
2112     }
2113     if ( mySketchType == PT_RELATIVE) {
2114       myNewCommand = myNewCommand + "F " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
2115       theParameters = myDXStr + ":" + myDYStr;
2116     }
2117     if (myConstructorId == 2 )
2118       myNewCommand = ":";
2119     else
2120       return myNewCommand;
2121   }
2122
2123   if ( myConstructorId == 0  ) {  // SEGMENT
2124     if ( mySketchType == PT_ABS || mySketchType == PT_SEL ) {
2125       myNewCommand = myNewCommand + "TT " + QString::number( myX, Format, DigNum) + " " + QString::number( myY, Format, DigNum);
2126       theParameters = myXStr + ":" + myYStr;
2127     }
2128     if ( mySketchType == PT_RELATIVE) {
2129       myNewCommand = myNewCommand + "T " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
2130       theParameters = myDXStr + ":" + myDYStr;
2131     }
2132     if ( mySketchType == DIR_ANGLE_LENGTH ) {
2133       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
2134       myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength, Format, DigNum );
2135       theParameters = myAngleStr + ":" + myLengthStr;
2136     }
2137     if ( mySketchType == DIR_ANGLE_X ) {
2138       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
2139       myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX, Format, DigNum);
2140       theParameters = myAngleStr + ":" + myXStr;
2141     }
2142     if ( mySketchType == DIR_ANGLE_Y ) {
2143       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
2144       myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY, Format, DigNum);
2145       theParameters = myAngleStr + ":" + myYStr;
2146     }
2147     if ( mySketchType == DIR_PER_LENGTH ) {
2148       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
2149       myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength, Format, DigNum );
2150       theParameters = QString::number( 90.0 ) + ":" + myLengthStr;
2151     }
2152     if ( mySketchType == DIR_PER_X ) {
2153       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
2154       myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX, Format, DigNum);
2155       theParameters = QString::number( 90.0 ) + ":" + myXStr;
2156     }
2157     if ( mySketchType == DIR_PER_Y ) {
2158       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
2159       myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY, Format, DigNum);
2160       theParameters = QString::number( 90.0 ) + ":" + myYStr;
2161     }
2162     if ( mySketchType == DIR_TAN_LENGTH ) {
2163       myNewCommand = myNewCommand + "L " + QString::number( myLength, Format, DigNum );
2164       theParameters = myLengthStr;
2165     }
2166     if ( mySketchType == DIR_TAN_X ) {
2167       myNewCommand = myNewCommand + "IX " + QString::number( myX, Format, DigNum);
2168       theParameters = myXStr;
2169     }
2170     if ( mySketchType == DIR_TAN_Y) {
2171       myNewCommand = myNewCommand + "IY " + QString::number(myY, Format, DigNum);
2172       theParameters = myYStr;
2173     }
2174     if ( mySketchType == DIR_DXDY_LENGTH ) {
2175       myNewCommand = myNewCommand + "D " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
2176       myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength, Format, DigNum );
2177       theParameters = myDXStr + ":" + myDYStr + ":" + myLengthStr;
2178     }
2179     if ( mySketchType == DIR_DXDY_X ) {
2180       myNewCommand = myNewCommand + "D " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
2181       myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX, Format, DigNum);
2182       theParameters = myDXStr + ":" + myDYStr + ":" + myXStr;
2183     }
2184     if ( mySketchType == DIR_DXDY_Y ) {
2185       myNewCommand = myNewCommand + "D " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
2186       myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY, Format, DigNum);
2187       theParameters = myDXStr + ":" + myDYStr + ":" + myYStr;
2188     }
2189   }
2190   else if ( myConstructorId == 1 ) {  // ARC
2191     if ( mySketchType == PT_ABS || mySketchType == PT_SEL ) {
2192       myNewCommand = myNewCommand + "AA " + QString::number( myX, Format, DigNum) + " " + QString::number( myY, Format, DigNum);
2193       theParameters = myXStr + ":" + myYStr;
2194     }
2195     if ( mySketchType == PT_RELATIVE) {
2196       myNewCommand = myNewCommand + "A " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
2197       theParameters = myDXStr + ":" + myDYStr;
2198     }
2199     if ( mySketchType == PT_ABS_RADIUS || mySketchType == PT_SEL_RADIUS ) {
2200       myNewCommand = myNewCommand + "UU " + QString::number( myX, Format, DigNum) + " " + QString::number( myY, Format, DigNum ) + " " + QString::number( myRadius , Format,  DigNum)+ " " + QString::number( myCheckFlag );
2201       theParameters = myXStr + ":" + myYStr + ":" + myRadiusStr; 
2202     }
2203     if ( mySketchType == PT_REL_RADIUS) {
2204       myNewCommand = myNewCommand + "U " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum ) + " " + QString::number( myRadius, Format, DigNum )+ " " + QString::number( myCheckFlag );
2205       theParameters = myDXStr + ":" + myDYStr + ":" + myRadiusStr;  
2206     }
2207     if ( mySketchType == PT_ABS_CENTER || mySketchType == PT_SEL_CENTER ) {
2208       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 );
2209       theParameters = myXStr + ":" + myYStr + ":" + myXcStr+ ":" + myYcStr; 
2210     }
2211     if ( mySketchType == PT_REL_CENTER) {
2212       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 );
2213       theParameters = myDXStr + ":" + myDYStr + ":" +  myDXcStr + ":" + myDYcStr ;  
2214     }
2215     if ( mySketchType == DIR_ANGLE_LENGTH ) {
2216       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
2217       myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius, Format, DigNum ) + " " + QString::number( myLength, Format, DigNum );
2218       theParameters = myAngleStr + ":" + myRadiusStr + ":" + myLengthStr;
2219     }
2220     if ( mySketchType == DIR_PER_LENGTH ) {
2221       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
2222       myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius, Format, DigNum ) + " " + QString::number( myLength, Format, DigNum );
2223       theParameters = QString::number( 90.0 ) + ":" + myRadiusStr + ":" + myLengthStr;
2224     }
2225     if ( mySketchType == DIR_TAN_LENGTH ) {
2226       myNewCommand = myNewCommand + "C " + QString::number( myRadius, Format, DigNum ) + " " + QString::number( myLength, Format, DigNum );
2227       theParameters = myRadiusStr + ":" + myLengthStr;
2228     }
2229     if ( mySketchType == DIR_DXDY_LENGTH ) {
2230       myNewCommand = myNewCommand + "D " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
2231       myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius, Format, DigNum ) + " " + QString::number( myLength, Format, DigNum );
2232       theParameters = myDXStr + ":" + myDYStr + ":" + myRadiusStr + ":" + myLengthStr;
2233     }
2234   }
2235   else if ( myConstructorId == 2 ) {  // RECTANGLE
2236       myNewCommand = myNewCommand + "F " + QString::number( myX1, Format, DigNum) + " " + QString::number( myY1, Format, DigNum)
2237                                   + ":TT " + QString::number( myX1, Format, DigNum) + " " + QString::number( myY2, Format, DigNum)
2238                                   + ":TT " + QString::number( myX2, Format, DigNum) + " " + QString::number( myY2, Format, DigNum)
2239                                   + ":TT " + QString::number( myX2, Format, DigNum) + " " + QString::number( myY1, Format, DigNum)
2240                                   + ":WW";
2241                           
2242       theParameters = myX1Str + ":" + myY1Str + ":" + myX2Str + ":" + myY2Str ;
2243     }
2244   return myNewCommand;
2245 }
2246
2247 //=================================================================================
2248 // function : createOperation
2249 // purpose  :
2250 //=================================================================================
2251 GEOM::GEOM_IOperations_ptr EntityGUI_SketcherDlg::createOperation()
2252 {
2253   return getGeomEngine()->GetICurvesOperations( getStudyId() );
2254 }
2255
2256 //=================================================================================
2257 // function : isValid
2258 // purpose  :
2259 //=================================================================================
2260 bool EntityGUI_SketcherDlg::isValid( QString& msg )
2261 {
2262   bool ok = true;
2263   bool toCorrect = !IsPreview() || myIsApply;
2264
2265   if( Group1Spin->isVisible() ) {
2266     ok = Group1Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
2267   }
2268   else if( Group1Sel1Spin->isVisible() ) {
2269     ok = Group1Sel1Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
2270   }
2271   else if( Group2Spin->isVisible() ) {
2272     ok = Group2Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
2273     ok = Group2Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
2274   }
2275   else if( Group3Spin->isVisible() ) {
2276     ok = Group3Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
2277     ok = Group3Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
2278     ok = Group3Spin->SpinBox_DZ->isValid( msg, toCorrect ) && ok;
2279   }
2280   else if( Group4Spin->isVisible() ) {
2281     ok = Group4Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
2282     ok = Group4Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
2283     ok = Group4Spin->SpinBox_DZ->isValid( msg, toCorrect ) && ok;
2284     ok = Group4Spin->SpinBox_DS->isValid( msg, toCorrect ) && ok;
2285   }
2286
2287   if( myIsApply && !ok )
2288     showError( msg );
2289
2290   return ok;
2291 }
2292
2293 //=================================================================================
2294 // function : execute
2295 // purpose  :
2296 //=================================================================================
2297 bool EntityGUI_SketcherDlg::execute( ObjectList& objects )
2298 {
2299   MESSAGE("EntityGUI_SketcherDlg::execute")
2300   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2301   int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
2302   int DigNum = qAbs(aPrecision);                   // options for the format of numbers in  myNewCommand
2303   char Format = 'f';
2304   if ( aPrecision < 0 )                            // f --> DigNum is the number of digits after the decimal point
2305     Format = 'g';                                  // g --> DigNum is the maximum number of significant digits 
2306     
2307   QString aParameters;
2308   
2309   if ( mySketchState == FIRST_POINT ) {
2310     myLastX2 = myX;
2311     myLastY2 = myY;
2312   }
2313   else {
2314     //Test if the current point is the same as the last one
2315     TopoDS_Shape myShape1, myShape2;
2316
2317     // Set "C" numeric locale
2318     Kernel_Utils::Localizer loc;
2319
2320     //Last Shape
2321     QString Command1 = myCommand.join( "" );
2322     Sketcher_Profile aProfile1( Command1.toAscii() );
2323     if ( aProfile1.IsDone() )
2324       myShape1 = aProfile1.GetShape();
2325
2326     //Current Shape
2327     QString Command2 = Command1 + GetNewCommand( aParameters );
2328     Sketcher_Profile aProfile2( Command2.toAscii() );
2329
2330     //Error Message
2331     if ( mySketchType == PT_ABS_CENTER || mySketchType == PT_REL_CENTER  ){
2332       if (aProfile2.Error() > Precision::Confusion()){
2333         Group4Spin->label->show();
2334         Group4Spin->label->setText( tr("GEOM_SKETCHER_WARNING") + QString::number( aProfile2.Error(), Format, DigNum));
2335       }
2336       else{
2337         Group4Spin->label->hide();
2338       } 
2339     }
2340     else 
2341       Group4Spin->label->hide();
2342     if ( mySketchType == PT_SEL_CENTER ){
2343       if (aProfile2.Error() > Precision::Confusion()){
2344         Group2Sel->label->show();
2345         Group2Sel->label->setText( tr("GEOM_SKETCHER_WARNING") + QString::number( aProfile2.Error(), Format, DigNum));
2346       }
2347       else{
2348         Group2Sel->label->hide();
2349       } 
2350     }
2351     else 
2352       Group2Sel->label->hide();
2353
2354     if ( aProfile2.IsDone() )
2355       myShape2 = aProfile2.GetShape();
2356
2357     if ( myShape2.IsNull() ) {
2358       //the current point is the same as the last one
2359       myLastX2 = myLastX1;
2360       myLastY2 = myLastY1;
2361     }
2362     else {
2363       TopoDS_Vertex V1, V2;
2364       gp_Pnt pt;
2365       if ( myShape1.ShapeType() == TopAbs_VERTEX ) {
2366         //the last shape is the first point
2367         pt = BRep_Tool::Pnt( TopoDS::Vertex( myShape1 ) );
2368         myLastX1 = pt.X();
2369         myLastY1 = pt.Y();
2370       }
2371       else {
2372         TopExp::Vertices( TopoDS::Wire( myShape1 ), V1, V2 );
2373         pt = BRep_Tool::Pnt( V2 );
2374         myLastX1 = pt.X();
2375         myLastY1 = pt.Y();
2376       }
2377       TopExp::Vertices( TopoDS::Wire( myShape2 ), V1, V2 );
2378       pt = BRep_Tool::Pnt( V2 );
2379       myLastX2 = pt.X();
2380       myLastY2 = pt.Y();
2381     }
2382   }
2383
2384   QString cmd;
2385   if ( ( mySketchState != FIRST_POINT &&
2386          myLastX1 == myLastX2 && myLastY1 == myLastY2 ) || myIsAllAdded ) {
2387     cmd = myCommand.join( "" );
2388     if ( Group1Sel->isVisible() ) {
2389       Group1Sel->buttonApply->setEnabled( false );
2390       //Group1Sel->buttonApply->setFocus();
2391     }
2392     if ( Group2Sel->isVisible() ) {
2393       Group2Sel->buttonApply->setEnabled( false );
2394       //Group2Sel->buttonApply->setFocus();
2395     }
2396     if ( Group1Sel1Spin->isVisible() ) {
2397       Group1Sel1Spin->buttonApply->setEnabled( false );
2398       //Group1Sel1Spin->buttonApply->setFocus();
2399     }
2400     if ( Group1Spin->isVisible() ) {
2401       Group1Spin->buttonApply->setEnabled( false );
2402       //Group1Spin->buttonApply->setFocus();
2403     }
2404     if ( Group2Spin->isVisible() ) {
2405       Group2Spin->buttonApply->setEnabled( false );
2406       //Group2Spin->buttonApply->setFocus();
2407     }
2408     if ( Group3Spin->isVisible() ) {
2409       Group3Spin->buttonApply->setEnabled( false );
2410       //Group3Spin->buttonApply->setFocus();
2411     }
2412     if ( Group4Spin->isVisible() ) {
2413       Group4Spin->buttonApply->setEnabled( false );
2414       //Group4Spin->buttonApply->setFocus();
2415     }
2416   }
2417   else {
2418     cmd = myCommand.join( "" ) + GetNewCommand( aParameters );
2419
2420     if ( Group1Sel->isVisible() ) {
2421       Group1Sel->buttonApply->setEnabled( true );
2422     }
2423     if ( Group2Sel->isVisible() ) {
2424       Group2Sel->buttonApply->setEnabled( true );
2425     }
2426     if ( Group1Sel1Spin->isVisible() ) {
2427       Group1Sel1Spin->buttonApply->setEnabled( true );;
2428     }
2429     if ( Group1Spin->isVisible() ) {
2430       Group1Spin->buttonApply->setEnabled( true );
2431     }
2432     if ( Group2Spin->isVisible() ) {
2433       Group2Spin->buttonApply->setEnabled( true );
2434     }
2435     if ( Group3Spin->isVisible() ) {
2436       Group3Spin->buttonApply->setEnabled( true );
2437     }
2438     if ( Group4Spin->isVisible() ) {
2439       Group4Spin->buttonApply->setEnabled( true );
2440     }
2441   }
2442
2443   GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow(getOperation());
2444   GEOM::GEOM_Object_var anObj = NULL;
2445   
2446   int index = ComboBox1->currentIndex();
2447   if(index != -1 && !myWPlane->_is_nil()) // The combobox is not empty
2448   {
2449     anObj = anOper->MakeSketcherOnPlane( cmd.toLatin1().constData(), myWPlane );
2450   }
2451   if ( !anObj->_is_nil() )
2452   {
2453     if( !IsPreview() ) {
2454       QStringList aCurrentParameters = myParameters;
2455       aCurrentParameters << aParameters;
2456       anObj->SetParameters(aCurrentParameters.join(":").toLatin1().constData());
2457     }
2458
2459     objects.push_back( anObj._retn() );
2460   }
2461
2462   return true;
2463 }
2464
2465 //================================================================
2466 // Function : displayPreview
2467 // Purpose  : Method for displaying preview of resulting shape
2468 //            Redefined from GEOMBase_Helper.
2469 //================================================================
2470 void EntityGUI_SketcherDlg::displayPreview( GEOM::GEOM_Object_ptr object,
2471                                             const bool            append,
2472                                             const bool            activate,
2473                                             const bool            update,
2474                                             const double          lineWidth,
2475                                             const int             displayMode,
2476                                             const int             color )
2477
2478   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); 
2479   
2480   QColor aColor = resMgr->colorValue("Geometry","line_color",QColor(255,0,0));
2481   Quantity_NameOfColor line_color = SalomeApp_Tools::color( aColor ).Name();
2482   
2483   // set width of displayed shape
2484   int lw = lineWidth;
2485   if(lw == -1) { 
2486     lw = resMgr->integerValue("Geometry", "preview_edge_width", -1);
2487   }
2488   getDisplayer()->SetWidth( lw );
2489
2490   // Disable activation of selection
2491   getDisplayer()->SetToActivate( activate );
2492
2493   // Make a reference to GEOM_Object
2494   CORBA::String_var objStr = myGeometryGUI->getApp()->orb()->object_to_string( object );
2495   getDisplayer()->SetName( objStr.in() );
2496
2497   // Create wire from applied object
2498   TopoDS_Shape anApplyedWire, aLastSegment;
2499   if ( !createShapes( object, anApplyedWire, aLastSegment ) )
2500     return;
2501
2502   // Build prs
2503   if( myConstructorId != 2)
2504     getDisplayer()->SetColor( line_color );
2505   else
2506     getDisplayer()->SetColor( Quantity_NOC_VIOLET );
2507   
2508   SALOME_Prs* aPrs = getDisplayer()->BuildPrs( anApplyedWire );
2509   if ( aPrs != 0 && !aPrs->IsNull() )
2510     GEOMBase_Helper::displayPreview( aPrs, append, update );
2511
2512   getDisplayer()->SetColor( Quantity_NOC_VIOLET ); 
2513   aPrs = getDisplayer()->BuildPrs( aLastSegment );
2514   
2515   if ( aPrs != 0 && !aPrs->IsNull() )
2516     GEOMBase_Helper::displayPreview( aPrs, append, update );
2517
2518   getDisplayer()->SetColor( line_color );
2519   
2520   getDisplayer()->UnsetName();
2521
2522   // Enable activation of displayed objects
2523   getDisplayer()->SetToActivate( true );
2524 }
2525
2526 //================================================================
2527 // Function : displayPntPreview
2528 // Purpose  : creates a TopoDS_VERTEX and display a preview of it
2529 //================================================================
2530 void EntityGUI_SketcherDlg::displayPntPreview(const double x,
2531                                               const double y,
2532                                               bool append,
2533                                               bool update
2534                                              )
2535 {
2536   // Get globalCS and working plane
2537   gp_Ax3 globalCS = WPlaneToLCS( myGlobalCS );
2538   gp_Ax3 aWPlane  = GetActiveLocalCS();
2539   
2540   // Build point in localCS
2541   gp_Pnt aPnt = gp_Pnt(x,y,0.0);
2542   
2543   // Get transfomation from local to global CS
2544   gp_Trsf aTrans;
2545   aTrans.SetTransformation(aWPlane, globalCS);
2546   
2547   BRepBuilderAPI_MakeVertex mkVertex (aPnt);
2548   TopoDS_Shape aLocalVertex = mkVertex.Shape();
2549   
2550   // Perform transformation
2551   BRepBuilderAPI_Transform aTransformation (aLocalVertex, aTrans, Standard_False);
2552   TopoDS_Shape aGlobalVertex = aTransformation.Shape();
2553   
2554   // Build prs with vertex in globalCS
2555   SALOME_Prs* aPrs = getDisplayer()->BuildPrs( aGlobalVertex );
2556   if ( aPrs != 0 && !aPrs->IsNull() )
2557     GEOMBase_Helper::displayPreview( aPrs, append, update );
2558   
2559 }
2560
2561 //================================================================
2562 // Function : createShapes
2563 // Purpose  : Create applyed wire, and last segment from entry object
2564 //================================================================
2565 bool EntityGUI_SketcherDlg::createShapes( GEOM::GEOM_Object_ptr theObject,
2566                                           TopoDS_Shape&         theApplyedWire,
2567                                           TopoDS_Shape&         theLastSegment )
2568 {
2569   TopoDS_Shape aShape;
2570   if (  !GEOMBase::GetShape( theObject, aShape ) ||
2571        ( aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX ) )
2572     return false;
2573
2574   if ( ( Group1Sel->isVisible()  && !Group1Sel->buttonApply->isEnabled() )||
2575        ( Group2Sel->isVisible()  && !Group2Sel->buttonApply->isEnabled() ) ||
2576        ( Group1Sel1Spin->isVisible()  && !Group1Sel1Spin->buttonApply->isEnabled() ) ||
2577        ( Group1Spin->isVisible() && !Group1Spin->buttonApply->isEnabled() ) ||
2578        ( Group2Spin->isVisible() && !Group2Spin->buttonApply->isEnabled() ) ||
2579        ( Group3Spin->isVisible() && !Group3Spin->buttonApply->isEnabled() ) ||
2580        ( Group4Spin->isVisible() && !Group4Spin->buttonApply->isEnabled() ) ) {
2581      theApplyedWire = aShape;
2582      return true;
2583   }
2584
2585   BRepBuilderAPI_MakeWire aBuilder;
2586   TopExp_Explorer anExp( aShape, TopAbs_EDGE );
2587   while ( 1 ) {
2588     TopoDS_Shape anEdge = anExp.Current();
2589     anExp.Next();
2590     if ( anExp.More() ) // i.e. non-last edge
2591       aBuilder.Add( TopoDS::Edge( anEdge ) );
2592     else {
2593       theLastSegment = anEdge;
2594       break;
2595     }
2596   }
2597
2598   if ( aBuilder.IsDone() )
2599     theApplyedWire = aBuilder.Shape();
2600
2601   return true;
2602 }
2603
2604 //=================================================================================
2605 // function : acceptMouseEvent()
2606 // purpose  :
2607 //=================================================================================
2608 bool EntityGUI_SketcherDlg::acceptMouseEvent() const 
2609 {
2610   return ( (getPnt1ConstructorId() == 1 
2611             || getPnt1ConstructorId() == 0
2612             || myConstructorId == 2)                       //accept mouse event only on absolute and relative selection mode                                                        
2613             && !WPlaneLineEdit->isEnabled());              //or when the constructor is rectangle
2614                                                            //called by EntityGUI::OnMousePress()        
2615 }  
2616
2617 //=================================================================================
2618 // function : keyPressEvent()
2619 // purpose  :
2620 //=================================================================================
2621 void  EntityGUI_SketcherDlg::keyPressEvent( QKeyEvent* e )
2622 {
2623   QDialog::keyPressEvent( e );
2624   if ( e->isAccepted() )
2625     return;
2626
2627   if ( e->key() == Qt::Key_F1 ) {
2628     e->accept();
2629     ClickOnHelp();
2630   }
2631 }
2632
2633 //=================================================================================
2634 // function : initSpinBox()
2635 // purpose  :
2636 //=================================================================================
2637 void EntityGUI_SketcherDlg::initSpinBox( SalomeApp_DoubleSpinBox* spinBox,
2638                                          double min,  double max,
2639                                          double step, const char* quantity )
2640 {
2641   // The same stuff as in GEOMBase_Skeleton::initSpinBox()!
2642   // TODO: Think how to keep the single piece of code...
2643
2644   // Obtain precision from preferences
2645   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2646   int aPrecision = resMgr->integerValue( "Geometry", quantity, 6 );
2647   
2648   spinBox->setPrecision( aPrecision );
2649   spinBox->setDecimals( qAbs( aPrecision ) ); // it's necessary to set decimals before the range setting,
2650                                               // by default Qt rounds boundaries to 2 decimals at setRange
2651   spinBox->setRange( min, max );
2652   spinBox->setSingleStep( step );
2653   
2654   // Add a hint for the user saying how to tune precision
2655   QString userPropName = QObject::tr( QString( "GEOM_PREF_%1" ).arg( quantity ).toLatin1().constData() );
2656   spinBox->setProperty( "validity_tune_hint", 
2657                         QVariant( QObject::tr( "GEOM_PRECISION_HINT" ).arg( userPropName ) ) );
2658 }
2659
2660 //=================================================================================
2661 // function : SetDoubleSpinBoxStep()
2662 // purpose  : Double spin box management
2663 //=================================================================================
2664 void EntityGUI_SketcherDlg::SetDoubleSpinBoxStep( double step )
2665 {
2666   Group1Spin->SpinBox_DX->setSingleStep(step);
2667   Group1Sel1Spin->SpinBox_DX->setSingleStep(step);
2668   Group2Spin->SpinBox_DX->setSingleStep(step);
2669   Group2Spin->SpinBox_DY->setSingleStep(step);
2670   Group3Spin->SpinBox_DX->setSingleStep(step);
2671   Group3Spin->SpinBox_DY->setSingleStep(step);
2672   Group3Spin->SpinBox_DZ->setSingleStep(step);
2673   Group4Spin->SpinBox_DZ->setSingleStep(step);
2674
2675   // san: Do NOT override the step when a speicifc step value is used
2676   // in some input fields!
2677   //Group4Spin->SpinBox_DX->setSingleStep(step);
2678   //Group4Spin->SpinBox_DY->setSingleStep(step);
2679   //Group4Spin->SpinBox_DS->setSingleStep(step);
2680 }
2681
2682 //=================================================================================
2683 // function : AddLocalCS()
2684 // purpose  : Add All Coordinates systems in study
2685 //=================================================================================
2686 void EntityGUI_SketcherDlg::AddLocalCS(GEOM::GEOM_Object_var aSelectedObject)
2687 {
2688   QString aName = GEOMBase::GetName( aSelectedObject );
2689   
2690   int index = ComboBox1->findText(aName, Qt::MatchExactly);
2691   
2692   if (index==-1)  // If the working plane hasn't been added yet
2693   {   
2694     myWPlaneList.push_back(aSelectedObject);
2695     myWPlane = aSelectedObject;
2696     addSubshapesToStudy();
2697     myLCSList.push_back(WPlaneToLCS(aSelectedObject));
2698     ComboBox1->addItem(aName); 
2699     index = ComboBox1->count();
2700     ComboBox1->setCurrentIndex(index-1);    
2701   }
2702   else
2703   {
2704     ComboBox1->setCurrentIndex(index);
2705   }
2706   ActivateLocalCS();   
2707 }
2708
2709 //=================================================================================
2710 // function : FindLocalCS()
2711 // purpose  : Find All Coordinates systems in study
2712 //=================================================================================
2713 void EntityGUI_SketcherDlg::FindLocalCS()
2714 {
2715   ComboBox1->clear();
2716   myWPlaneList.clear();
2717   SalomeApp_Application* app =
2718     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2719   if ( !app )
2720     return;
2721
2722   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2723   if ( !appStudy )
2724     return;
2725
2726   _PTR(Study) aStudy = appStudy->studyDS();
2727
2728   //add Global CS
2729   ComboBox1->addItem(tr("GEOM_GCS"));
2730   myWPlaneList.push_back(myGlobalCS);
2731
2732   // get GEOM component
2733   CORBA::String_var geomIOR = app->orb()->object_to_string( GeometryGUI::GetGeomGen() );
2734   _PTR(SObject) obj = aStudy->FindObjectIOR( geomIOR.in() );
2735   if (!obj)
2736     return;
2737   _PTR(SComponent) fc = obj->GetFatherComponent();
2738   QString geomComp = fc->GetID().c_str();
2739   _PTR(SObject) comp = aStudy->FindObjectID( geomComp.toLatin1().data() );
2740   if ( !comp )
2741     return;
2742
2743   // browse through all GEOM data tree
2744   _PTR(ChildIterator) it ( aStudy->NewChildIterator( comp ) );
2745   for ( it->InitEx( true ); it->More(); it->Next() ) 
2746   {
2747     _PTR(SObject) child( it->Value() );
2748     CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( child );
2749     GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
2750     if( CORBA::is_nil( geomObj ) ) 
2751       continue;
2752     if (geomObj->GetType() == GEOM_MARKER) 
2753     {
2754       myWPlaneList.push_back(geomObj);
2755       myLCSList.push_back(WPlaneToLCS(geomObj));
2756       ComboBox1->addItem(geomObj->GetName());
2757     }
2758   }
2759 }
2760
2761 //=================================================================================
2762 // function : WPlaneToLCS ( aWPlane )
2763 // purpose  : 
2764 //=================================================================================
2765 gp_Ax3 EntityGUI_SketcherDlg::WPlaneToLCS( GEOM::GEOM_Object_var geomObj )
2766 {
2767   TopoDS_Shape aShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), geomObj);
2768   
2769   gp_Ax3 aLCS;
2770   if (CORBA::is_nil( geomObj ) || aShape.IsNull())
2771   {
2772     MESSAGE("CORBA::is_nil( geomObj ) || aShape.IsNull()")
2773   }
2774   aLCS.Transform(aShape.Location().Transformation());
2775   if (aShape.ShapeType() == TopAbs_FACE) 
2776   {
2777     GEOM::GEOM_IMeasureOperations_ptr aMeasureOp =
2778     myGeometryGUI->GetGeomGen()->GetIMeasureOperations( getStudyId() );
2779     double Ox, Oy, Oz, Zx, Zy, Zz, Xx, Xy, Xz;
2780     aMeasureOp->GetPosition( geomObj, Ox, Oy, Oz, Zx, Zy, Zz, Xx, Xy, Xz);
2781     if ( aMeasureOp->IsDone() )
2782     {  
2783       gp_Pnt aPnt ( Ox, Oy, Oz );
2784       gp_Dir aDirN ( Zx, Zy, Zz );
2785       gp_Dir aDirX ( Xx, Xy, Xz );
2786       aLCS = gp_Ax3( aPnt, aDirN, aDirX );
2787     }
2788   }
2789   return aLCS;
2790 }
2791
2792
2793 //=================================================================================
2794 // function : getPnt1ConstructorId()
2795 // purpose  :
2796 //=================================================================================
2797 int EntityGUI_SketcherDlg::getPnt1ConstructorId() const
2798
2799   int buttonId = GroupPt->ButtonGroup->checkedId(); 
2800 //   MESSAGE("buttonId = "<<buttonId)
2801   return buttonId;
2802 }
2803
2804 //=================================================================================
2805 // function : getPnt2ConstructorId()
2806 // purpose  :
2807 //=================================================================================
2808 int EntityGUI_SketcherDlg::getPnt2ConstructorId() const
2809
2810   int buttonId = GroupPt2->ButtonGroup->checkedId(); 
2811 //   MESSAGE("buttonId = "<<buttonId)
2812   return buttonId;
2813 }
2814
2815 //=================================================================================
2816 // function : GetActiveLocalCS()
2817 // purpose  : Get Working plane
2818 //=================================================================================
2819 gp_Ax3 EntityGUI_SketcherDlg::GetActiveLocalCS()
2820 {
2821   int ind = ComboBox1->currentIndex();
2822   if (ind == -1)
2823     return myGeometryGUI->GetWorkingPlane();
2824   
2825   gp_Ax3 aLCS = myLCSList.at(ind);
2826   myWPlane = myWPlaneList.at(ind);
2827
2828   return aLCS;
2829 }
2830
2831 //=================================================================================
2832 // function : ActivateLocalCS()
2833 // purpose  : Activate & Fit Working plane
2834 //=================================================================================
2835 void EntityGUI_SketcherDlg::ActivateLocalCS()
2836 {
2837   myGeometryGUI->SetWorkingPlane( GetActiveLocalCS() );
2838   myGeometryGUI->ActiveWorkingPlane();
2839 }
2840
2841 //=================================================================================
2842 // function : addSubshapeToStudy
2843 // purpose  : virtual method to add new SubObjects if local selection
2844 //=================================================================================
2845 void EntityGUI_SketcherDlg::addSubshapesToStudy()
2846 {
2847   GEOMBase::PublishSubObject(myWPlane);
2848 }