]> SALOME platform Git repositories - modules/geom.git/blob - src/EntityGUI/EntityGUI_SketcherDlg.cxx
Salome HOME
Mantis issues 0020939(GetSharedShapes) and 0020842(AllSorted meaning).
[modules/geom.git] / src / EntityGUI / EntityGUI_SketcherDlg.cxx
1 //  Copyright (C) 2007-2010  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 <GEOMBase.h>
32 #include <GeometryGUI.h>
33 #include <GEOMImpl_Types.hxx>
34 #include <Geom_Surface.hxx>
35 #include <Geom_Plane.hxx>
36
37 #include <SUIT_Desktop.h>
38 #include <SUIT_Session.h>
39 #include <SUIT_MessageBox.h>
40 #include <SUIT_ResourceMgr.h>
41 #include <SalomeApp_Application.h>
42 #include <LightApp_Application.h>
43 #include <LightApp_SelectionMgr.h>
44
45 #include <QKeyEvent>
46
47 #include <BRep_Tool.hxx>
48 #include <TopExp.hxx>
49 #include <TopExp_Explorer.hxx>
50 #include <TopoDS_Vertex.hxx>
51 #include <TopoDS.hxx>
52 #include <BRepBuilderAPI_Transform.hxx>
53 #include <BRepBuilderAPI_MakeWire.hxx>
54 #include <Sketcher_Profile.hxx>
55
56 #include <SalomeApp_Study.h>
57
58 #include <gp_Pln.hxx>
59
60 #include <Basics_Utils.hxx>
61
62 //=================================================================================
63 // class    : EntityGUI_SketcherDlg()
64 // purpose  : Constructs a EntityGUI_SketcherDlg which is a child of 'parent', with the
65 //            name 'name' and widget flags set to 'f'.
66 //            The dialog will by default be modeless, unless you set 'modal' to
67 //            TRUE to construct a modal dialog.
68 //=================================================================================
69 EntityGUI_SketcherDlg::EntityGUI_SketcherDlg( GeometryGUI* GUI, QWidget* parent,
70                                               bool modal, Qt::WindowFlags fl,
71                                               const double lineWidth )
72   : QDialog( parent, fl ),
73     myIsAllAdded( false ),
74     myIsApply( false ),
75     GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
76     myGeometryGUI( GUI ),
77     myLineWidth( lineWidth )
78 {
79   setModal( modal );
80   setAttribute( Qt::WA_DeleteOnClose );
81
82   myGeometryGUI->SetActiveDialogBox(this);
83
84   MainWidget = new EntityGUI_Skeleton( this );
85   QVBoxLayout* topLayout = new QVBoxLayout( this );
86   topLayout->setMargin( 9 ); topLayout->setSpacing( 6 );
87
88   MainWidget->buttonCancel->setText( tr( "GEOM_BUT_CANCEL" ) );
89   MainWidget->buttonEnd->setText( tr( "GEOM_BUT_END_SKETCH" ) );
90   MainWidget->buttonClose->setText( tr( "GEOM_BUT_CLOSE_SKETCH" ) );
91   MainWidget->buttonHelp->setText( tr( "GEOM_BUT_HELP" ) );
92
93   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
94   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_UNDO" ) ) );
95   QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_REDO" ) ) );
96
97   setWindowTitle( tr( "GEOM_SKETCHER_TITLE" ) );
98
99   MainWidget->GroupConstructors->setTitle( tr( "GEOM_SKETCHER_EL" ) );
100   MainWidget->RadioButton1->setText( tr( "GEOM_SKETCHER_SEGMENT" ) );
101   MainWidget->RadioButton2->setText( tr( "GEOM_SKETCHER_ARC" ) );
102   MainWidget->GroupDest->setTitle( tr( "GEOM_SKETCHER_DEST" ) );
103   MainWidget->GroupDest1->setTitle( tr( "GEOM_SKETCHER_TYPE" ) );
104   MainWidget->RB_Dest1->setText( tr( "GEOM_SKETCHER_POINT" ) );
105   MainWidget->RB_Dest2->setText( tr( "GEOM_SKETCHER_DIR" ) );
106
107   /***************************************************************/
108
109   GroupBox1 = new QGroupBox(tr("GEOM_CS"), this);
110   QHBoxLayout* planeLayout = new QHBoxLayout(GroupBox1);
111   planeLayout->setSpacing(6);
112   planeLayout->setMargin(11);
113
114   ComboBox1 = new QComboBox(GroupBox1);
115   ComboBox1->setSizePolicy( QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed) );
116   planeLayout->addWidget(ComboBox1);
117
118   planeButton = new QPushButton (GroupBox1);
119   planeButton->setText( tr( "GEOM_SKETCHER_RESTORE" ) );
120   planeLayout->addWidget(planeButton);
121
122   topLayout->addWidget(GroupBox1);
123   topLayout->addWidget( MainWidget );
124
125   GroupPt = new EntityGUI_Point( MainWidget->DestCnt );
126
127   GroupPt->GroupPoint->setTitle( tr( "GEOM_SKETCHER_POINT" ) );
128   GroupPt->RB_Point1->setText( tr( "GEOM_SKETCHER_ABS" ) );
129   GroupPt->RB_Point2->setText( tr( "GEOM_SKETCHER_REL" ) );
130   GroupPt->RB_Point3->setText( tr( "GEOM_SKETCHER_SEL" ) );
131
132   GroupD1 = new EntityGUI_Dir1( MainWidget->DestCnt );
133
134   GroupD1->GroupDir1->setTitle( tr( "GEOM_SKETCHER_DIR" ) );
135   GroupD1->RB_Dir11->setText( tr( "GEOM_SKETCHER_ANGLE" ) );
136   GroupD1->RB_Dir12->setText( tr( "GEOM_SKETCHER_PER" ) );
137   GroupD1->RB_Dir13->setText( tr( "GEOM_SKETCHER_TAN" ) );
138   GroupD1->RB_Dir14->setText( tr( "GEOM_SKETCHER_VXVY" ) );
139
140   GroupD2 = new EntityGUI_Dir2( MainWidget->DestCnt );
141
142   GroupD2->GroupDir2->setTitle( tr( "GEOM_SKETCHER_DIR" ) );
143   GroupD2->RB_Dir21->setText( tr( "GEOM_SKETCHER_LENGTH" ) );
144   GroupD2->RB_Dir22->setText( tr( "GEOM_SKETCHER_X" ) );
145   GroupD2->RB_Dir23->setText( tr( "GEOM_SKETCHER_Y" ) );
146
147   Group1Sel = new EntityGUI_1Sel( MainWidget->SkeletonCnt );
148
149   Group1Sel->TextLabel1->setText( tr( "GEOM_SKETCHER_POINT2" ) );
150   Group1Sel->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
151   Group1Sel->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
152   Group1Sel->PushButton1->setIcon( image0 );
153   Group1Sel->buttonUndo->setIcon( image1 );
154   Group1Sel->buttonRedo->setIcon( image2 );
155   Group1Sel->LineEdit1->setReadOnly( true );
156
157   Group1Spin = new EntityGUI_1Spin( MainWidget->SkeletonCnt );
158   Group1Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
159   Group1Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
160   Group1Spin->buttonUndo->setIcon( image1 );
161   Group1Spin->buttonRedo->setIcon( image2 );
162
163   Group2Spin = new EntityGUI_2Spin( MainWidget->SkeletonCnt );
164   Group2Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
165   Group2Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
166   Group2Spin->buttonUndo->setIcon( image1 );
167   Group2Spin->buttonRedo->setIcon( image2 );
168
169   Group3Spin = new EntityGUI_3Spin( MainWidget->SkeletonCnt );
170   Group3Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
171   Group3Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
172   Group3Spin->buttonUndo->setIcon( image1 );
173   Group3Spin->buttonRedo->setIcon( image2 );
174
175   Group4Spin = new EntityGUI_4Spin( MainWidget->SkeletonCnt );
176   Group4Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
177   Group4Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
178   Group4Spin->buttonUndo->setIcon( image1 );
179   Group4Spin->buttonRedo->setIcon( image2 );
180
181   QGridLayout* DestCntLayout = new QGridLayout( MainWidget->DestCnt );
182   DestCntLayout->setMargin( 0 ); DestCntLayout->setSpacing( 6 );
183   DestCntLayout->addWidget( GroupPt, 0, 0, 1, 2 );
184   DestCntLayout->addWidget( GroupD1, 1, 0 );
185   DestCntLayout->addWidget( GroupD2, 1, 1 );
186
187   QVBoxLayout* SkeletonCntlayout = new QVBoxLayout( MainWidget->SkeletonCnt );
188   SkeletonCntlayout->setMargin( 0 ); SkeletonCntlayout->setSpacing( 6 );
189   SkeletonCntlayout->addWidget( Group1Sel,  0, 0 );
190   SkeletonCntlayout->addWidget( Group1Spin, 0, 0 );
191   SkeletonCntlayout->addWidget( Group2Spin, 0, 0 );
192   SkeletonCntlayout->addWidget( Group3Spin, 0, 0 );
193   SkeletonCntlayout->addWidget( Group4Spin, 0, 0 );
194   /***************************************************************/
195
196   QButtonGroup* ButtonGroup = new QButtonGroup( this );
197   ButtonGroup->addButton( MainWidget->RB_Dest1, 1 );
198   ButtonGroup->addButton( MainWidget->RB_Dest2, 0 );
199
200   /* signals and slots connections */
201   connect( MainWidget->buttonEnd,    SIGNAL( clicked() ), this, SLOT( ClickOnEnd() ) );
202   connect( MainWidget->buttonClose,  SIGNAL( clicked() ), this, SLOT( ClickOnEnd() ) );
203   connect( MainWidget->buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
204   connect( MainWidget->buttonHelp,   SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
205
206   connect( Group1Sel->buttonApply,   SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
207   connect( Group1Sel->buttonUndo,    SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
208   connect( Group1Sel->buttonRedo,    SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
209   connect( Group1Spin->buttonApply,  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
210   connect( Group1Spin->buttonUndo,   SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
211   connect( Group1Spin->buttonRedo,   SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
212   connect( Group2Spin->buttonApply,  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
213   connect( Group2Spin->buttonUndo,   SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
214   connect( Group2Spin->buttonRedo,   SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
215   connect( Group3Spin->buttonApply,  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
216   connect( Group3Spin->buttonUndo,   SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
217   connect( Group3Spin->buttonRedo,   SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) ) ;
218   connect( Group4Spin->buttonApply,  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
219   connect( Group4Spin->buttonUndo,   SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
220   connect( Group4Spin->buttonRedo,   SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
221
222   connect( MainWidget->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( TypeClicked( int ) ) );
223   connect( ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( DestClicked( int ) ) );
224   connect( GroupPt->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( PointClicked( int ) ) );
225   connect( GroupD1->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( Dir1Clicked( int ) ) );
226   connect( GroupD2->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( Dir2Clicked( int ) ));
227
228   connect( Group1Sel->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
229   connect( Group1Sel->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
230
231   connect( Group1Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
232   connect( Group2Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
233   connect( Group2Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
234   connect( Group3Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
235   connect( Group3Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
236   connect( Group3Spin->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
237   connect( Group4Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
238   connect( Group4Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
239   connect( Group4Spin->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
240   connect( Group4Spin->SpinBox_DS, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
241
242   connect( ComboBox1, SIGNAL( activated( int ) ), this, SLOT( SelectionIntoArgument() ) );
243   connect( planeButton, SIGNAL( clicked() ), this, SLOT( ActivateLocalCS() ) );
244
245   connect( myGeometryGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
246
247   connect( myGeometryGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
248   connect( myGeometryGUI, SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
249   
250   // install event filter on spin-boxes to provide Apply action on Return pressed
251   Group1Spin->SpinBox_DX->installEventFilter(this);
252   Group2Spin->SpinBox_DX->installEventFilter(this);
253   Group2Spin->SpinBox_DY->installEventFilter(this);
254   Group3Spin->SpinBox_DX->installEventFilter(this);
255   Group3Spin->SpinBox_DY->installEventFilter(this);
256   Group3Spin->SpinBox_DZ->installEventFilter(this);
257   Group4Spin->SpinBox_DX->installEventFilter(this);
258   Group4Spin->SpinBox_DY->installEventFilter(this);
259   Group4Spin->SpinBox_DZ->installEventFilter(this);
260   Group4Spin->SpinBox_DS->installEventFilter(this);
261
262   Init();
263 }
264
265
266 //=================================================================================
267 // function : ~EntityGUI_SketcherDlg()
268 // purpose  : Destroys the object and frees any allocated resources
269 //=================================================================================
270 EntityGUI_SketcherDlg::~EntityGUI_SketcherDlg()
271 {
272   myGeometryGUI->SetActiveDialogBox( 0 );
273 }
274
275
276 //=================================================================================
277 // function : eventFilter()
278 // purpose  : event filter for spin-boxes to provide Apply action on Return pressed
279 //=================================================================================
280 bool EntityGUI_SketcherDlg::eventFilter (QObject* object, QEvent* event)
281 {
282   if (event->type() == QEvent::KeyPress) {
283     QKeyEvent* ke = (QKeyEvent*)event;
284     if (ke->key() == Qt::Key_Return) {
285       if (object == Group1Spin->SpinBox_DX) {
286         Group1Spin->buttonApply->animateClick();
287         return true;
288       } else if (object == Group2Spin->SpinBox_DX ||
289                  object == Group2Spin->SpinBox_DY) {
290         Group2Spin->buttonApply->animateClick();
291         return true;
292       } else if (object == Group3Spin->SpinBox_DX ||
293                  object == Group3Spin->SpinBox_DY ||
294                  object == Group3Spin->SpinBox_DZ) {
295         Group3Spin->buttonApply->animateClick();
296         return true;
297       } else if (object == Group4Spin->SpinBox_DX ||
298                  object == Group4Spin->SpinBox_DY ||
299                  object == Group4Spin->SpinBox_DZ ||
300                  object == Group4Spin->SpinBox_DS) {
301         Group4Spin->buttonApply->animateClick();
302         return true;
303       }
304     }
305   }
306
307   // Fix of the NPAL16010 bug is removed, because it's not actual with the Qt-4.x
308
309   return QDialog::eventFilter(object, event);
310 }
311
312
313 //=================================================================================
314 // function : Init()
315 // purpose  :
316 //=================================================================================
317 void EntityGUI_SketcherDlg::Init()
318 {
319   /* init variables */
320   myEditCurrentArgument = Group1Sel->LineEdit1;
321   myCommand.append( "Sketcher" );
322   myUndoCommand.append( "Sketcher" );
323
324   mySketchState = FIRST_POINT;
325   globalSelection( GEOM_POINT );
326
327   myLastX1 = 0.0;
328   myLastY1 = 0.0;
329   myLastX2 = 0.0;
330   myLastY2 = 0.0;
331
332   myHelpFileName = "create_sketcher_page.html";
333
334   /* Get setting of step value from file configuration */
335   double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
336
337   /* min, max, step and decimals for spin boxes */
338   initSpinBox( Group1Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
339   initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
340   initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
341   initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
342   initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
343   initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
344   initSpinBox( Group4Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
345   // san: Note specific step values below!
346   initSpinBox( Group4Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
347   initSpinBox( Group4Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
348   initSpinBox( Group4Spin->SpinBox_DS, COORD_MIN, COORD_MAX, 5., "length_precision" );
349
350   /* displays Dialog */
351   MainWidget->GroupConstructors->setEnabled( false );
352   MainWidget->GroupDest1->setEnabled( false );
353   setEnabledUndo( false );
354   setEnabledRedo( false );
355
356   MainWidget->RadioButton1->setChecked( true );
357
358   TypeClicked( 0 );
359
360   FindLocalCS();
361   resize(100,100);
362
363   ActivateLocalCS();
364   GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
365 }
366
367
368 //=================================================================================
369 // function : InitClick()
370 // purpose  :
371 //=================================================================================
372 void EntityGUI_SketcherDlg::InitClick()
373 {
374   disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
375
376   Group1Sel->hide();
377   Group1Spin->hide();
378   Group2Spin->hide();
379   Group3Spin->hide();
380   Group4Spin->hide();
381 }
382
383
384 //=================================================================================
385 // function : TypeClicked()
386 // purpose  : Radio button management
387 //=================================================================================
388 void EntityGUI_SketcherDlg::TypeClicked( int constructorId )
389 {
390   myConstructorId = constructorId;
391   if ( myConstructorId == 0 ) {    // SEGMENT
392     GroupD2->setEnabled( true );
393     MainWidget->RB_Dest1->setEnabled( true );
394     MainWidget->RB_Dest1->setChecked( true );
395     DestClicked( 1 );
396   }
397   else if (  myConstructorId == 1 ) { // ARC
398     GroupD2->setEnabled( false );
399     MainWidget->RB_Dest1->setEnabled( true ); 
400     MainWidget->RB_Dest2->setChecked( true );
401     DestClicked( 0 );
402   }
403 }
404
405
406 //=================================================================================
407 // function : DestClicked()
408 // purpose  : Radio button management
409 //=================================================================================
410 void EntityGUI_SketcherDlg::DestClicked( int constructorId )
411 {
412   GroupPt->hide();
413   GroupD1->hide();
414   GroupD2->hide();
415
416   if ( constructorId == 1 ) {
417     // Point
418     GroupPt->RB_Point1->setChecked( true );
419     GroupPt->show();
420     PointClicked( 1 );  // XY
421   }
422   else if (  constructorId == 0 ) {
423     // Direction
424     GroupD1->RB_Dir11->setChecked( true );
425     GroupD1->show();
426     GroupD2->show();
427     Dir1Clicked( 2 );  // Angle
428   }
429 }
430
431
432 //=================================================================================
433 // function : PointClicked()
434 // purpose  : Radio button management
435 //=================================================================================
436 void EntityGUI_SketcherDlg::PointClicked( int constructorId )
437 {
438   InitClick();
439
440   // Get setting of step value from file configuration
441   double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
442
443   if ( (myConstructorId == 0) || (myConstructorId == 1) ) {  // SEGMENT OR ARC
444     if ( constructorId == 1 ) {  // XY
445       mySketchType = PT_ABS;
446       initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
447       initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
448       Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X2" ) );
449       Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y2" ) );
450       myX = 0.0;
451       Group2Spin->SpinBox_DX->setValue( myX );
452       myY = 0.0;
453       Group2Spin->SpinBox_DY->setValue( myY );
454       Group2Spin->show();
455       Group2Spin->buttonApply->setFocus();
456
457       GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
458     }
459     else if ( constructorId == 0 ) {  // DXDY
460       mySketchType = PT_RELATIVE;
461       initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
462       initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
463       Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_DX2" ) );
464       Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_DY2" ) );
465       myDX = 0.0;
466       Group2Spin->SpinBox_DX->setValue( myDX );
467       myDY = 0.0;
468       Group2Spin->SpinBox_DY->setValue( myDY );
469       Group2Spin->show();
470       Group2Spin->buttonApply->setFocus();
471
472       GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
473     }
474     else if ( constructorId == 2 ) {  // Selection
475       mySketchType = PT_SEL;
476       myEditCurrentArgument = Group1Sel->LineEdit1;
477       Group1Sel->show();
478       Group1Sel->buttonApply->setFocus();
479       SelectionIntoArgument();
480     }
481
482     connect( myGeometryGUI->getApp()->selectionMgr(),
483              SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
484   }
485 }
486
487
488 //=================================================================================
489 // function : Dir1Clicked()
490 // purpose  : Radio button management
491 //=================================================================================
492 void EntityGUI_SketcherDlg::Dir1Clicked( int constructorId )
493 {
494   myConstructorDirId = constructorId;
495   GroupD2->RB_Dir21->setChecked( true );
496   Dir2Clicked( 2 );
497 }
498
499
500 //=================================================================================
501 // function : Dir2Clicked()
502 // purpose  : Radio button management
503 //=================================================================================
504 void EntityGUI_SketcherDlg::Dir2Clicked( int constructorId )
505 {
506   InitClick();
507   myAngle = 0.0;
508
509   // Get setting of step value from file configuration
510   double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
511
512   if ( myConstructorId == 0 ) {  // SEGMENT
513     myX = 0.0;
514     myY = 0.0;
515     myLength = 100.0;
516     if ( myConstructorDirId == 2 ) {  // Angle
517       initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 5., "length_precision" );
518       Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
519       Group2Spin->SpinBox_DX->setValue( myAngle );
520       Group2Spin->buttonApply->setFocus();
521       Group2Spin->show();
522
523       if ( constructorId == 2 ) {  // Length
524         mySketchType = DIR_ANGLE_LENGTH;
525         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
526         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
527         Group2Spin->SpinBox_DY->setValue( myLength );
528       }
529       else if ( constructorId == 0 ) {  // X
530         mySketchType = DIR_ANGLE_X;
531         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "angle_precision" );
532         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_X3" ) );
533         Group2Spin->SpinBox_DY->setValue( myX );
534       }
535       else if ( constructorId == 1 ) {  // Y
536         mySketchType = DIR_ANGLE_Y;
537         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "angle_precision" );        
538         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y3" ) );
539         Group2Spin->SpinBox_DY->setValue( myY );
540       }
541     }
542     else if ( myConstructorDirId == 0 ) {  // Perpendicular
543       Group1Spin->show();
544       Group1Spin->buttonApply->setFocus();
545
546       if ( constructorId == 2 ) {  // Length
547         mySketchType = DIR_PER_LENGTH;
548         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
549         Group1Spin->SpinBox_DX->setValue( myLength );
550       }
551       else if ( constructorId == 0 ) {  // X
552         mySketchType = DIR_PER_X;
553         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X3" ) );
554         Group1Spin->SpinBox_DX->setValue( myX );
555       }
556       else if ( constructorId == 1 ) {  // Y
557         mySketchType = DIR_PER_Y;
558         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_Y3" ) );
559         Group1Spin->SpinBox_DX->setValue( myY );
560       }
561     }
562     else if ( myConstructorDirId == 1 ) {  // Tangent
563       Group1Spin->show();
564       Group1Spin->buttonApply->setFocus();
565
566       if ( constructorId == 2 ) {  // Length
567         mySketchType = DIR_TAN_LENGTH;
568         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
569         Group1Spin->SpinBox_DX->setValue( myLength );
570       }
571       else if ( constructorId == 0 ) {  // X
572         mySketchType = DIR_TAN_X;
573         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X3" ) );
574         Group1Spin->SpinBox_DX->setValue( myX );
575       }
576       else if ( constructorId == 1 ) {  // Y
577         mySketchType = DIR_TAN_Y;
578         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_Y3" ) );
579         Group1Spin->SpinBox_DX->setValue( myY );
580       }
581     }
582     else if ( myConstructorDirId == 3 ) {  // DXDY
583       initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
584       initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
585       initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
586       Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_VX2" ) );
587       Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_VY2" ) );
588       myDX = 0.0;
589       Group3Spin->SpinBox_DX->setValue( myDX );
590       myDY = 0.0;
591       Group3Spin->SpinBox_DY->setValue( myDY );
592       Group3Spin->show();
593       Group3Spin->buttonApply->setFocus();
594
595       if ( constructorId == 2 ) {  // Length
596         mySketchType = DIR_DXDY_LENGTH;
597         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
598         Group3Spin->SpinBox_DZ->setValue( myLength );
599       }
600       else if ( constructorId == 0 ) { // X
601         mySketchType = DIR_DXDY_X;
602         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_X3" ) );
603         Group3Spin->SpinBox_DZ->setValue( myX );
604       }
605       else if ( constructorId == 1 ) {  // Y
606         mySketchType = DIR_DXDY_Y;
607         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_Y3" ) );
608         Group3Spin->SpinBox_DZ->setValue( myY );
609       }
610     }
611   }
612   else if ( myConstructorId == 1 ) {  // ARC
613     if ( myConstructorDirId == 2 ) {  // Angle
614       if ( constructorId == 2 ) {  // Length
615         mySketchType = DIR_ANGLE_LENGTH;
616         initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 5., "angle_precision" );
617         initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
618         initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, 5., "angle_precision" );
619         Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
620         Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
621         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_ANGLE2" ));
622         Group3Spin->SpinBox_DX->setValue( myAngle );
623         myRadius = 100.0;
624         Group3Spin->SpinBox_DY->setValue( myRadius );
625         myLength = 30.0;
626         Group3Spin->SpinBox_DZ->setValue( myLength );
627         Group3Spin->show();
628         Group3Spin->buttonApply->setFocus();
629       }
630     }
631     else if ( myConstructorDirId == 0 ) {  // Perpendicular
632       if ( constructorId == 2 ) {  // Length
633         mySketchType = DIR_PER_LENGTH;
634         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
635         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 5., "angle_precision" );
636         Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
637         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
638         myRadius = 100.0;
639         Group2Spin->SpinBox_DX->setValue( myRadius );
640         myLength = 30.0;
641         Group2Spin->SpinBox_DY->setValue( myLength );
642         Group2Spin->show();
643         Group2Spin->buttonApply->setFocus();
644       }
645     }
646     else if ( myConstructorDirId == 1 ) {  // Tangent
647       if ( constructorId == 2 ) {  // Length
648         mySketchType = DIR_TAN_LENGTH;
649         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
650         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 5., "angle_precision" );
651         Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
652         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
653         myRadius = 100.0;
654         Group2Spin->SpinBox_DX->setValue( myRadius );
655         myLength = 30.0;
656         Group2Spin->SpinBox_DY->setValue( myLength );
657         Group2Spin->show();
658         Group2Spin->buttonApply->setFocus();
659       }
660     }
661     else if ( myConstructorDirId == 3 ) {  // DXDY
662       if ( constructorId == 2 ) {  // Length
663         mySketchType = DIR_DXDY_LENGTH;
664         Group4Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_VX2" ) );
665         Group4Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_VY2" ) );
666         Group4Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
667         Group4Spin->TextLabel4->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
668         myDX = 0.0;
669         Group4Spin->SpinBox_DX->setValue( myDX );
670         myDY = 0.0;
671         Group4Spin->SpinBox_DY->setValue( myDY );
672         myRadius = 100.0;
673         Group4Spin->SpinBox_DZ->setValue( myRadius );
674         myLength = 30.0;
675         Group4Spin->SpinBox_DS->setValue( myLength );
676         Group4Spin->show();
677         Group4Spin->buttonApply->setFocus();
678       }
679     }
680   }
681
682   GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
683 }
684
685
686 //=================================================================================
687 // function : ClickOnCancel()
688 // purpose  :
689 //=================================================================================
690 void EntityGUI_SketcherDlg::ClickOnCancel()
691 {
692   close();
693 }
694
695
696 //=================================================================================
697 // function : ClickOnEnd()
698 // purpose  : connected to buttonEnd AND buttonClose
699 //=================================================================================
700 void EntityGUI_SketcherDlg::ClickOnEnd()
701 {
702   if ( sender() == MainWidget->buttonClose ) {
703     // Verify validity of commands
704     if ( myCommand.count() <= 2 ) {
705       SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
706                                  tr( "GEOM_ERROR_STATUS" ), tr( "CANNOT_CLOSE" ), tr( "BUT_OK" ) );
707       return;
708     }
709
710     QString Parameters;
711     QString Command = myCommand.join( "" ) + GetNewCommand( Parameters );
712     Sketcher_Profile aProfile( Command.toAscii() );
713
714     Command = myCommand.join( "" );
715     aProfile = Sketcher_Profile( Command.toAscii() );
716     TopoDS_Shape myShape;
717     if ( aProfile.IsDone() )
718       myShape = aProfile.GetShape();
719
720     if ( myShape.ShapeType() != TopAbs_VERTEX )
721       myCommand.append( ":WW" );
722   }
723   else {
724     // PAL16008 (Sketcher Validation should be equal to Apply&Close)
725     if ( Group1Spin->buttonApply->isEnabled() && Group1Spin->isVisible() ||
726          Group2Spin->buttonApply->isEnabled() && Group2Spin->isVisible() ||
727          Group3Spin->buttonApply->isEnabled() && Group3Spin->isVisible() ||
728          Group4Spin->buttonApply->isEnabled() && Group4Spin->isVisible() ||
729          Group1Sel ->buttonApply->isEnabled() && Group1Sel->isVisible() ) {
730       ClickOnApply();
731     }
732     myIsAllAdded = true;
733   }
734
735   if ( myCommand.size() > 2 )
736     if ( !onAccept() )
737       return;
738
739   close();
740 }
741
742 //=================================================================================
743 // function : ClickOnApply()
744 // purpose  :
745 //=================================================================================
746 bool EntityGUI_SketcherDlg::ClickOnApply()
747 {
748   if ( sender() && sender()->inherits( "QPushButton" ) )
749     ( (QPushButton*)sender() )->setFocus(); // to update value of currently edited spin-box (PAL11948)
750
751   QString aParameters;
752   myCommand.append( GetNewCommand( aParameters ) );
753   mySketchState = NEXT_POINT;
754
755   myUndoCommand.clear();
756   myUndoCommand.append( "Sketcher" );
757
758   myParameters.append( aParameters );
759   myUndoParameters.clear();
760
761   MainWidget->GroupConstructors->setEnabled( true );
762   MainWidget->GroupDest1->setEnabled( true );
763   setEnabledUndo( true );
764   setEnabledRedo( false );
765
766   myIsApply = true;
767   GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
768   myIsApply = false;
769
770   // Set focus to SpinBox_DX
771   if ( sender() == Group1Spin->buttonApply ) {
772     (Group1Spin->SpinBox_DX)->setFocus();
773     (Group1Spin->SpinBox_DX)->selectAll();
774   }
775   else if ( sender() == Group2Spin->buttonApply ) {
776     (Group2Spin->SpinBox_DX)->setFocus();
777     (Group2Spin->SpinBox_DX)->selectAll();
778   }
779   else if ( sender() == Group3Spin->buttonApply ) {
780     (Group3Spin->SpinBox_DX)->setFocus();
781     (Group3Spin->SpinBox_DX)->selectAll();
782   }
783   else if ( sender() == Group4Spin->buttonApply ) {
784     (Group4Spin->SpinBox_DX)->setFocus();
785     (Group4Spin->SpinBox_DX)->selectAll();
786   }
787
788   return true;
789 }
790
791 //=================================================================================
792 // function : ClickOnHelp()
793 // purpose  :
794 //=================================================================================
795 void EntityGUI_SketcherDlg::ClickOnHelp()
796 {
797   LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
798   if ( app )
799     app->onHelpContextModule( myGeometryGUI ? app->moduleName( myGeometryGUI->moduleName() ) : QString( "" ), myHelpFileName );
800   else {
801     QString platform;
802 #ifdef WIN32
803     platform = "winapplication";
804 #else
805     platform = "application";
806 #endif
807
808     SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
809                               QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
810                               arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
811                               QObject::tr( "BUT_OK" ) );
812   }
813 }
814
815 //=================================================================================
816 // function : ClickOnUndo()
817 // purpose  :
818 //=================================================================================
819 void EntityGUI_SketcherDlg::ClickOnUndo()
820 {
821   myUndoCommand.append( myCommand.last() );
822   myCommand.pop_back();
823
824   myUndoParameters.append( myParameters.last() );
825   myParameters.pop_back();
826
827   if ( myCommand.count() == 1 ) {
828     mySketchState = FIRST_POINT;
829
830     MainWidget->RadioButton1->setChecked( true );
831     TypeClicked( 0 );
832
833     connect( myGeometryGUI->getApp()->selectionMgr(),
834              SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
835
836     MainWidget->GroupConstructors->setEnabled( false );
837     MainWidget->GroupDest1->setEnabled( false );
838     setEnabledUndo( false );
839   }
840
841   setEnabledRedo( true );
842
843   GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
844 }
845
846 //=================================================================================
847 // function : ClickOnRedo()
848 // purpose  :
849 //=================================================================================
850 void EntityGUI_SketcherDlg::ClickOnRedo()
851 {
852   myCommand.append( myUndoCommand.last() );
853   myUndoCommand.pop_back();
854
855   myParameters.append( myUndoParameters.last() );
856   myUndoParameters.pop_back();
857
858   mySketchState = NEXT_POINT;
859
860   MainWidget->GroupConstructors->setEnabled( true );
861   MainWidget->GroupDest1->setEnabled( true );
862   setEnabledUndo( true );
863
864   if ( myUndoCommand.count() == 1 )
865     setEnabledRedo( false );
866
867   GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
868 }
869
870 //=================================================================================
871 // function : setEnabledUndo()
872 // purpose  :
873 //=================================================================================
874 void EntityGUI_SketcherDlg::setEnabledUndo( bool value )
875 {
876   Group1Sel->buttonUndo->setEnabled( value );
877   Group1Spin->buttonUndo->setEnabled( value );
878   Group2Spin->buttonUndo->setEnabled( value );
879   Group3Spin->buttonUndo->setEnabled( value );
880   Group4Spin->buttonUndo->setEnabled( value );
881 }
882
883 //=================================================================================
884 // function : setEnabledRedo()
885 // purpose  :
886 //=================================================================================
887 void EntityGUI_SketcherDlg::setEnabledRedo( bool value )
888 {
889   Group1Sel->buttonRedo->setEnabled( value );
890   Group1Spin->buttonRedo->setEnabled( value );
891   Group2Spin->buttonRedo->setEnabled( value );
892   Group3Spin->buttonRedo->setEnabled( value );
893   Group4Spin->buttonRedo->setEnabled( value );
894 }
895
896 //=================================================================================
897 // function : SelectionIntoArgument()
898 // purpose  : Called when selection as changed
899 //=================================================================================
900 void EntityGUI_SketcherDlg::SelectionIntoArgument()
901 {
902   myEditCurrentArgument->setText( "" );
903   double tmpX = myX;
904   double tmpY = myY;
905   myX = myLastX1;
906   myY = myLastY1;
907   //  printf ("\nmyX = %f         myY = %f", myX, myY);
908   //  printf ("\nmyLastX1 = %f    myLastY1 = %f", myLastX1, myLastY1);
909   //  printf ("\nmyLastX2 = %f    myLastY2 = %f", myLastX2, myLastY2);
910
911   if ( sender() == ComboBox1 )
912       ActivateLocalCS();
913
914   LightApp_SelectionMgr* aSelMgr = myGeometryGUI->getApp()->selectionMgr();
915   SALOME_ListIO aSelList;
916   aSelMgr->selectedObjects(aSelList);
917
918   int nbSel = aSelList.Extent();
919   if (nbSel == 1 && myEditCurrentArgument == Group1Sel->LineEdit1) {
920     Standard_Boolean aRes = Standard_False;
921     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aRes);
922     if (!CORBA::is_nil(aSelectedObject) && aRes) {
923       TopoDS_Shape aShape;
924       if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_VERTEX)) {
925         gp_Trsf aTrans;
926         gp_Ax3 aWPlane = GetActiveLocalCS();
927
928         aTrans.SetTransformation(aWPlane);
929         BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
930         aShape = aTransformation.Shape();
931
932         gp_Pnt aPnt;
933         if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) {
934           myX = aPnt.X();
935           myY = aPnt.Y();
936           Group1Sel->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
937           if( Group2Spin->isVisible() && mySketchType == PT_ABS ) {
938             disconnect( Group2Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
939             disconnect( Group2Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
940             Group2Spin->SpinBox_DX->setValue(myX);
941             Group2Spin->SpinBox_DY->setValue(myY);
942             connect( Group2Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
943             connect( Group2Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
944           } else if ( Group2Spin->isVisible() && mySketchType == PT_RELATIVE ) {
945             if ( myLastX1 && myLastY1 ) {
946               Group2Spin->SpinBox_DX->setValue(myX - myLastX1);
947               Group2Spin->SpinBox_DY->setValue(myY - myLastY1);
948             } else {
949               if ( mySketchState != FIRST_POINT ) {
950                 Group2Spin->SpinBox_DX->setValue(myX - tmpX);
951                 Group2Spin->SpinBox_DY->setValue(myY - tmpY);
952               } else {
953                 Group2Spin->SpinBox_DX->setValue(myX);
954                 Group2Spin->SpinBox_DY->setValue(myY);
955               }
956             }
957           }
958         }
959       }
960     }
961   }
962
963   GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
964 }
965
966
967 //=================================================================================
968 // function : SetEditCurrentArgument()
969 // purpose  :
970 //=================================================================================
971 void EntityGUI_SketcherDlg::SetEditCurrentArgument()
972 {
973   if ( sender() == Group1Sel->PushButton1 ) {
974     myEditCurrentArgument = Group1Sel->LineEdit1;
975     myEditCurrentArgument->setFocus();
976   }
977   SelectionIntoArgument();
978 }
979
980
981 //=================================================================================
982 // function : LineEditReturnPressed()
983 // purpose  :
984 //=================================================================================
985 void EntityGUI_SketcherDlg::LineEditReturnPressed()
986 {
987   if ( sender() == Group1Sel->LineEdit1 ) {
988     myEditCurrentArgument = Group1Sel->LineEdit1;
989
990     /* User name of object input management                          */
991     /* If successfull the selection is changed and signal emitted... */
992     /* so SelectionIntoArgument() is automatically called.           */
993     const QString objectUserName = myEditCurrentArgument->text();
994     QWidget* thisWidget = (QWidget*)this;
995
996     LightApp_SelectionMgr* aSelMgr = myGeometryGUI->getApp()->selectionMgr();
997     SALOME_ListIO aSelList;
998     aSelMgr->selectedObjects(aSelList);
999
1000     if (GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, aSelList))
1001       myEditCurrentArgument->setText( objectUserName );
1002   }
1003 }
1004
1005
1006 //=================================================================================
1007 // function : DeactivateActiveDialog()
1008 // purpose  :
1009 //=================================================================================
1010 void EntityGUI_SketcherDlg::DeactivateActiveDialog()
1011 {
1012   //myGeometryGUI->SetState( -1 );
1013
1014   setEnabled( false );
1015   globalSelection();
1016   disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
1017   myGeometryGUI->SetActiveDialogBox( 0 );
1018 }
1019
1020
1021 //=================================================================================
1022 // function : ActivateThisDialog()
1023 // purpose  :
1024 //=================================================================================
1025 void EntityGUI_SketcherDlg::ActivateThisDialog()
1026 {
1027   myGeometryGUI->EmitSignalDeactivateDialog();
1028   setEnabled( true );
1029   myGeometryGUI->SetActiveDialogBox( this );
1030
1031   connect( myGeometryGUI->getApp()->selectionMgr(),
1032           SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
1033
1034   //myGeometryGUI->SetState( 0 );
1035   globalSelection( GEOM_POINT );
1036
1037   myEditCurrentArgument = Group1Sel->LineEdit1;
1038   myEditCurrentArgument->setFocus();
1039
1040   GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
1041 }
1042
1043
1044 //=================================================================================
1045 // function : enterEvent [REDEFINED]
1046 // purpose  :
1047 //=================================================================================
1048 void EntityGUI_SketcherDlg::enterEvent( QEvent* )
1049 {
1050   if ( !MainWidget->GroupConstructors->isEnabled() )
1051     ActivateThisDialog();
1052 }
1053
1054
1055 //=================================================================================
1056 // function : closeEvent()
1057 // purpose  :
1058 //=================================================================================
1059 void EntityGUI_SketcherDlg::closeEvent( QCloseEvent* e )
1060 {
1061   //myGeometryGUI->SetState( -1 );
1062   disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
1063   myGeometryGUI->getApp()->updateActions();
1064   QDialog::closeEvent( e );
1065 }
1066
1067
1068 //=================================================================================
1069 // function : ValueChangedInSpinBox()
1070 // purpose  :
1071 //=================================================================================
1072 void EntityGUI_SketcherDlg::ValueChangedInSpinBox( double newValue )
1073 {
1074   QObject* send = (QObject*)sender();
1075   Standard_Real vx, vy, vz, vs;
1076   vx = vy = vz = vs = 0.0;
1077
1078   QString vxStr, vyStr, vzStr, vsStr;
1079
1080   QString newValueStr;
1081   if( SalomeApp_DoubleSpinBox* aDoubleSpinBox = (SalomeApp_DoubleSpinBox*)send )
1082     newValueStr = aDoubleSpinBox->text();
1083
1084   if ( send == Group1Spin->SpinBox_DX ) {
1085     vx = newValue;                        vxStr = newValueStr;
1086   }
1087   else if ( send == Group2Spin->SpinBox_DX ) {
1088     vx = newValue;                        vxStr = newValueStr;
1089     vy = Group2Spin->SpinBox_DY->value(); vyStr = Group2Spin->SpinBox_DY->text();
1090   }
1091   else if ( send == Group2Spin->SpinBox_DY ) {
1092     vx = Group2Spin->SpinBox_DX->value(); vxStr = Group2Spin->SpinBox_DX->text();
1093     vy = newValue;                        vyStr = newValueStr;
1094   }
1095   else if ( send == Group3Spin->SpinBox_DX ) {
1096     vx = newValue;                        vxStr = newValueStr;
1097     vy = Group3Spin->SpinBox_DY->value(); vyStr = Group3Spin->SpinBox_DY->text();
1098     vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
1099   }
1100   else if ( send == Group3Spin->SpinBox_DY ) {
1101     vx = Group3Spin->SpinBox_DX->value(); vxStr = Group3Spin->SpinBox_DX->text();
1102     vy = newValue;                        vyStr = newValueStr;
1103     vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
1104   }
1105   else if ( send == Group3Spin->SpinBox_DZ ) {
1106     vx = Group3Spin->SpinBox_DX->value(); vxStr = Group3Spin->SpinBox_DX->text();
1107     vy = Group3Spin->SpinBox_DY->value(); vyStr = Group3Spin->SpinBox_DY->text();
1108     vz = newValue;                        vzStr = newValueStr;
1109   }
1110   else if ( send == Group4Spin->SpinBox_DX ) {
1111     vx = newValue;                        vxStr = newValueStr;
1112     vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1113     vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1114     vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1115   }
1116   else if ( send == Group4Spin->SpinBox_DY ) {
1117     vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1118     vy = newValue;                        vyStr = newValueStr;
1119     vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1120     vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1121   }
1122   else if ( send == Group4Spin->SpinBox_DZ ) {
1123     vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1124     vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1125     vz = newValue;                        vzStr = newValueStr;
1126     vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1127   }
1128   else if ( send == Group4Spin->SpinBox_DS ) {
1129     vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1130     vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1131     vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1132     vs = newValue;                        vsStr = newValueStr;
1133   }
1134   // Fix of the NPAL16010 bug is removed, because it's not actual with the Qt-4.x
1135
1136   if ( myConstructorId == 0 ) {  // SEGMENT
1137     if ( mySketchType == PT_ABS ) {
1138       myX = vx;
1139       myY = vy;
1140       myXStr = vxStr;
1141       myYStr = vyStr;
1142     }
1143     else if ( mySketchType == PT_RELATIVE ) {
1144       myDX = vx;
1145       myDY = vy;
1146       myDXStr = vxStr;
1147       myDYStr = vyStr;
1148     }
1149     else if ( mySketchType == DIR_ANGLE_LENGTH ) {
1150       myAngle = vx;
1151       myLength = vy;
1152       myAngleStr = vxStr;
1153       myLengthStr = vyStr;
1154     }
1155     else if ( mySketchType == DIR_ANGLE_X ) {
1156       myAngle = vx;
1157       myX = vy;
1158       myAngleStr = vxStr;
1159       myXStr = vyStr;
1160     }
1161     else if ( mySketchType == DIR_ANGLE_Y ) {
1162       myAngle = vx;
1163       myY = vy;
1164       myAngleStr = vxStr;
1165       myYStr = vyStr;
1166     }
1167     else if ( mySketchType == DIR_PER_LENGTH ) {
1168       myLength = vx;
1169       myLengthStr = vxStr;
1170     }
1171     else if ( mySketchType == DIR_PER_X ) {
1172       myX = vx;
1173       myXStr = vxStr;
1174     }
1175     else if ( mySketchType == DIR_PER_Y ) {
1176       myY = vx;
1177       myYStr = vxStr;
1178     }
1179     else if ( mySketchType == DIR_TAN_LENGTH ) {
1180       myLength = vx;
1181       myLengthStr = vxStr;
1182     }
1183     else if ( mySketchType == DIR_TAN_X ) {
1184       myX = vx;
1185       myXStr = vxStr;
1186     }
1187     else if ( mySketchType == DIR_TAN_Y ) {
1188       myY = vx;
1189       myYStr = vxStr;
1190     }
1191     else if ( mySketchType == DIR_DXDY_LENGTH ) {
1192       myDX = vx;
1193       myDY = vy;
1194       myLength = vz;
1195       myDXStr = vxStr;
1196       myDYStr = vyStr;
1197       myLengthStr = vzStr;
1198     }
1199     else if ( mySketchType == DIR_DXDY_X ) {
1200       myDX = vx;
1201       myDY = vy;
1202       myX = vz;
1203       myDXStr = vxStr;
1204       myDYStr = vyStr;
1205       myXStr = vzStr;
1206     }
1207     else if ( mySketchType == DIR_DXDY_Y ) {
1208       myDX = vx;
1209       myDY = vy;
1210       myY = vz;
1211       myDXStr = vxStr;
1212       myDYStr = vyStr;
1213       myYStr = vzStr;
1214     }
1215   }
1216   else if ( myConstructorId == 1 ) {  // ARC
1217     if ( mySketchType == PT_ABS ) {  
1218       myX = vx;
1219       myY = vy;
1220       myXStr = vxStr;
1221       myYStr = vyStr;
1222     }
1223     else if ( mySketchType == PT_RELATIVE ) {
1224       myDX = vx;
1225       myDY = vy;
1226       myDXStr = vxStr;
1227       myDYStr = vyStr;
1228     } 
1229     if ( mySketchType == DIR_ANGLE_LENGTH ) {
1230       myAngle = vx;
1231       myRadius = vy;
1232       myLength = vz;
1233       myAngleStr = vxStr;
1234       myRadiusStr = vyStr;
1235       myLengthStr = vzStr;
1236     }
1237     else if ( mySketchType == DIR_PER_LENGTH ) {
1238       myRadius = vx;
1239       myLength = vy;
1240       myRadiusStr = vxStr;
1241       myLengthStr = vyStr;
1242     }
1243     else if ( mySketchType == DIR_TAN_LENGTH ) {
1244       myRadius = vx;
1245       myLength = vy;
1246       myRadiusStr = vxStr;
1247       myLengthStr = vyStr;
1248     }
1249     else if ( mySketchType == DIR_DXDY_LENGTH ) {
1250       myDX = vx;
1251       myDY = vy;
1252       myRadius = vz;
1253       myLength = vs;
1254       myDXStr = vxStr;
1255       myDYStr = vyStr;
1256       myRadiusStr = vzStr;
1257       myLengthStr = vsStr;
1258     }
1259   }
1260
1261   GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
1262 }
1263
1264
1265 //=================================================================================
1266 // function : GetNewCommand()
1267 // purpose  : Build the new command with context
1268 //=================================================================================
1269 QString EntityGUI_SketcherDlg::GetNewCommand( QString& theParameters )
1270 {
1271   theParameters.clear();
1272   QString myNewCommand = ":";
1273   if ( mySketchState == FIRST_POINT ) {
1274     if ( mySketchType == PT_ABS || mySketchType == PT_SEL ) {
1275       myNewCommand = myNewCommand + "F " + QString::number( myX ) + " " + QString::number( myY );
1276       theParameters = myXStr + ":" + myYStr;
1277     }
1278     if ( mySketchType == PT_RELATIVE) {
1279       myNewCommand = myNewCommand + "F " + QString::number( myDX ) + " " + QString::number( myDY );
1280       theParameters = myDXStr + ":" + myDYStr;
1281     }
1282     return myNewCommand;
1283   }
1284
1285   if ( myConstructorId == 0  ) {  // SEGMENT
1286     if ( mySketchType == PT_ABS || mySketchType == PT_SEL ) {
1287       myNewCommand = myNewCommand + "TT " + QString::number( myX ) + " " + QString::number( myY );
1288       theParameters = myXStr + ":" + myYStr;
1289     }
1290     if ( mySketchType == PT_RELATIVE) {
1291       myNewCommand = myNewCommand + "T " + QString::number( myDX ) + " " + QString::number( myDY );
1292       theParameters = myDXStr + ":" + myDYStr;
1293     }
1294     if ( mySketchType == DIR_ANGLE_LENGTH ) {
1295       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1296       myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength );
1297       theParameters = myAngleStr + ":" + myLengthStr;
1298     }
1299     if ( mySketchType == DIR_ANGLE_X ) {
1300       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1301       myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX );
1302       theParameters = myAngleStr + ":" + myXStr;
1303     }
1304     if ( mySketchType == DIR_ANGLE_Y ) {
1305       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1306       myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY );
1307       theParameters = myAngleStr + ":" + myYStr;
1308     }
1309     if ( mySketchType == DIR_PER_LENGTH ) {
1310       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1311       myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength );
1312       theParameters = QString::number( 90.0 ) + ":" + myLengthStr;
1313     }
1314     if ( mySketchType == DIR_PER_X ) {
1315       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1316       myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX );
1317       theParameters = QString::number( 90.0 ) + ":" + myXStr;
1318     }
1319     if ( mySketchType == DIR_PER_Y ) {
1320       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1321       myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY );
1322       theParameters = QString::number( 90.0 ) + ":" + myYStr;
1323     }
1324     if ( mySketchType == DIR_TAN_LENGTH ) {
1325       myNewCommand = myNewCommand + "L " + QString::number( myLength );
1326       theParameters = myLengthStr;
1327     }
1328     if ( mySketchType == DIR_TAN_X ) {
1329       myNewCommand = myNewCommand + "IX " + QString::number( myX );
1330       theParameters = myXStr;
1331     }
1332     if ( mySketchType == DIR_TAN_Y) {
1333       myNewCommand = myNewCommand + "IY " + QString::number(myY);
1334       theParameters = myYStr;
1335     }
1336     if ( mySketchType == DIR_DXDY_LENGTH ) {
1337       myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1338       myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength );
1339       theParameters = myDXStr + ":" + myDYStr + ":" + myLengthStr;
1340     }
1341     if ( mySketchType == DIR_DXDY_X ) {
1342       myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1343       myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX );
1344       theParameters = myDXStr + ":" + myDYStr + ":" + myXStr;
1345     }
1346     if ( mySketchType == DIR_DXDY_Y ) {
1347       myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1348       myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY );
1349       theParameters = myDXStr + ":" + myDYStr + ":" + myYStr;
1350     }
1351   }
1352   else if ( myConstructorId == 1 ) {  // ARC
1353     if ( mySketchType == PT_ABS || mySketchType == PT_SEL ) {
1354       myNewCommand = myNewCommand + "AA " + QString::number( myX ) + " " + QString::number( myY );
1355       theParameters = myXStr + ":" + myYStr;
1356     }
1357     if ( mySketchType == PT_RELATIVE) {
1358       myNewCommand = myNewCommand + "A " + QString::number( myDX ) + " " + QString::number( myDY );
1359       theParameters = myDXStr + ":" + myDYStr;
1360     } 
1361     if ( mySketchType == DIR_ANGLE_LENGTH ) {
1362       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1363       myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1364       theParameters = myAngleStr + ":" + myRadiusStr + ":" + myLengthStr;
1365     }
1366     if ( mySketchType == DIR_PER_LENGTH ) {
1367       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1368       myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1369       theParameters = QString::number( 90.0 ) + ":" + myRadiusStr + ":" + myLengthStr;
1370     }
1371     if ( mySketchType == DIR_TAN_LENGTH ) {
1372       myNewCommand = myNewCommand + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1373       theParameters = myRadiusStr + ":" + myLengthStr;
1374     }
1375     if ( mySketchType == DIR_DXDY_LENGTH ) {
1376       myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1377       myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1378       theParameters = myDXStr + ":" + myDYStr + ":" + myRadiusStr + ":" + myLengthStr;
1379     }
1380   }
1381   return myNewCommand;
1382 }
1383
1384 //=================================================================================
1385 // function : createOperation
1386 // purpose  :
1387 //=================================================================================
1388 GEOM::GEOM_IOperations_ptr EntityGUI_SketcherDlg::createOperation()
1389 {
1390   return getGeomEngine()->GetICurvesOperations( getStudyId() );
1391 }
1392
1393 //=================================================================================
1394 // function : isValid
1395 // purpose  :
1396 //=================================================================================
1397 bool EntityGUI_SketcherDlg::isValid( QString& msg )
1398 {
1399   bool ok = true;
1400   bool toCorrect = !IsPreview() || myIsApply;
1401
1402   if( Group1Spin->isVisible() ) {
1403     ok = Group1Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1404   }
1405   else if( Group2Spin->isVisible() ) {
1406     ok = Group2Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1407     ok = Group2Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
1408   }
1409   else if( Group3Spin->isVisible() ) {
1410     ok = Group3Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1411     ok = Group3Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
1412     ok = Group3Spin->SpinBox_DZ->isValid( msg, toCorrect ) && ok;
1413   }
1414   else if( Group4Spin->isVisible() ) {
1415     ok = Group4Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1416     ok = Group4Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
1417     ok = Group4Spin->SpinBox_DZ->isValid( msg, toCorrect ) && ok;
1418     ok = Group4Spin->SpinBox_DS->isValid( msg, toCorrect ) && ok;
1419   }
1420
1421   if( myIsApply && !ok )
1422     showError( msg );
1423
1424   return ok;
1425 }
1426
1427 //=================================================================================
1428 // function : execute
1429 // purpose  :
1430 //=================================================================================
1431 bool EntityGUI_SketcherDlg::execute( ObjectList& objects )
1432 {
1433   QString aParameters;
1434
1435   if ( mySketchState == FIRST_POINT ) {
1436     myLastX2 = myX;
1437     myLastY2 = myY;
1438   }
1439   else {
1440     //Test if the current point is the same as the last one
1441     TopoDS_Shape myShape1, myShape2;
1442
1443     // Set "C" numeric locale
1444     Kernel_Utils::Localizer loc;
1445
1446     //Last Shape
1447     QString Command1 = myCommand.join( "" );
1448     Sketcher_Profile aProfile1( Command1.toAscii() );
1449     if ( aProfile1.IsDone() )
1450       myShape1 = aProfile1.GetShape();
1451
1452     //Current Shape
1453     QString Command2 = Command1 + GetNewCommand( aParameters );
1454     Sketcher_Profile aProfile2( Command2.toAscii() );
1455     if ( aProfile2.IsDone() )
1456       myShape2 = aProfile2.GetShape();
1457
1458     if ( myShape2.IsNull() ) {
1459       //the current point is the same as the last one
1460       myLastX2 = myLastX1;
1461       myLastY2 = myLastY1;
1462     }
1463     else {
1464       TopoDS_Vertex V1, V2;
1465       gp_Pnt pt;
1466       if ( myShape1.ShapeType() == TopAbs_VERTEX ) {
1467         //the last shape is the first point
1468         pt = BRep_Tool::Pnt( TopoDS::Vertex( myShape1 ) );
1469         myLastX1 = pt.X();
1470         myLastY1 = pt.Y();
1471       }
1472       else {
1473         TopExp::Vertices( TopoDS::Wire( myShape1 ), V1, V2 );
1474         pt = BRep_Tool::Pnt( V2 );
1475         myLastX1 = pt.X();
1476         myLastY1 = pt.Y();
1477       }
1478       TopExp::Vertices( TopoDS::Wire( myShape2 ), V1, V2 );
1479       pt = BRep_Tool::Pnt( V2 );
1480       myLastX2 = pt.X();
1481       myLastY2 = pt.Y();
1482     }
1483   }
1484
1485   QString cmd;
1486   if ( ( mySketchState != FIRST_POINT &&
1487          myLastX1 == myLastX2 && myLastY1 == myLastY2 ) || myIsAllAdded ) {
1488     cmd = myCommand.join( "" );
1489
1490     if ( Group1Sel->isVisible() ) {
1491       Group1Sel->buttonApply->setEnabled( false );
1492       //Group1Sel->buttonApply->setFocus();
1493     }
1494     if ( Group1Spin->isVisible() ) {
1495       Group1Spin->buttonApply->setEnabled( false );
1496       //Group1Spin->buttonApply->setFocus();
1497     }
1498     if ( Group2Spin->isVisible() ) {
1499       Group2Spin->buttonApply->setEnabled( false );
1500       //Group2Spin->buttonApply->setFocus();
1501     }
1502     if ( Group3Spin->isVisible() ) {
1503       Group3Spin->buttonApply->setEnabled( false );
1504       //Group3Spin->buttonApply->setFocus();
1505     }
1506     if ( Group4Spin->isVisible() ) {
1507       Group4Spin->buttonApply->setEnabled( false );
1508       //Group4Spin->buttonApply->setFocus();
1509     }
1510   }
1511   else {
1512     cmd = myCommand.join( "" ) + GetNewCommand( aParameters );
1513
1514     if ( Group1Sel->isVisible() ) {
1515       Group1Sel->buttonApply->setEnabled( true );
1516       //Group1Sel->buttonApply->setFocus();
1517     }
1518     if ( Group1Spin->isVisible() ) {
1519       Group1Spin->buttonApply->setEnabled( true );
1520       //Group1Spin->buttonApply->setFocus();
1521     }
1522     if ( Group2Spin->isVisible() ) {
1523       Group2Spin->buttonApply->setEnabled( true );
1524       //Group2Spin->buttonApply->setFocus();
1525     }
1526     if ( Group3Spin->isVisible() ) {
1527       Group3Spin->buttonApply->setEnabled( true );
1528       //Group3Spin->buttonApply->setFocus();
1529     }
1530     if ( Group4Spin->isVisible() ) {
1531       Group4Spin->buttonApply->setEnabled( true );
1532       //Group4Spin->buttonApply->setFocus();
1533     }
1534   }
1535
1536   gp_Ax3 myWPlane = GetActiveLocalCS();
1537   GEOM::ListOfDouble_var WPlane = new GEOM::ListOfDouble;
1538   WPlane->length( 9 );
1539   WPlane[0] = myWPlane.Location().X();
1540   WPlane[1] = myWPlane.Location().Y();
1541   WPlane[2] = myWPlane.Location().Z();
1542
1543   WPlane[3] = myWPlane.Direction().X();
1544   WPlane[4] = myWPlane.Direction().Y();
1545   WPlane[5] = myWPlane.Direction().Z();
1546
1547   WPlane[6] = myWPlane.XDirection().X();
1548   WPlane[7] = myWPlane.XDirection().Y();
1549   WPlane[8] = myWPlane.XDirection().Z();
1550
1551   GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow(getOperation());
1552   GEOM::GEOM_Object_var anObj = anOper->MakeSketcher( cmd.toLatin1().constData(), WPlane );
1553
1554   if ( !anObj->_is_nil() )
1555   {
1556     if( !IsPreview() ) {
1557       QStringList aCurrentParameters = myParameters;
1558       aCurrentParameters << aParameters;
1559       anObj->SetParameters(aCurrentParameters.join(":").toLatin1().constData());
1560     }
1561
1562     objects.push_back( anObj._retn() );
1563   }
1564
1565   return true;
1566 }
1567
1568 //================================================================
1569 // Function : displayPreview
1570 // Purpose  : Method for displaying preview of resulting shape
1571 //            Redefined from GEOMBase_Helper.
1572 //================================================================
1573 void EntityGUI_SketcherDlg::displayPreview( GEOM::GEOM_Object_ptr object,
1574                                             const bool            append,
1575                                             const bool            activate,
1576                                             const bool            update,
1577                                             const double          lineWidth,
1578                                             const int             displayMode,
1579                                             const int             color )
1580 {
1581   // Set color for preview shape
1582   getDisplayer()->SetColor( Quantity_NOC_RED );
1583
1584   // set width of displayed shape
1585   getDisplayer()->SetWidth( (lineWidth == -1)?myLineWidth:lineWidth );
1586
1587   // Disable activation of selection
1588   getDisplayer()->SetToActivate( activate );
1589
1590   // Make a reference to GEOM_Object
1591   CORBA::String_var objStr = myGeometryGUI->getApp()->orb()->object_to_string( object );
1592   getDisplayer()->SetName( objStr.in() );
1593
1594   // Create wire from applayed object
1595   TopoDS_Shape anApplyedWire, aLastSegment;
1596   if ( !createShapes( object, anApplyedWire, aLastSegment ) )
1597     return;
1598
1599   // Build prs
1600   SALOME_Prs* aPrs = getDisplayer()->BuildPrs( anApplyedWire );
1601   if ( aPrs != 0 && !aPrs->IsNull() )
1602     GEOMBase_Helper::displayPreview( aPrs, append, update );
1603
1604   getDisplayer()->SetColor( Quantity_NOC_VIOLET );
1605   aPrs = getDisplayer()->BuildPrs( aLastSegment );
1606   if ( aPrs != 0 && !aPrs->IsNull() )
1607     GEOMBase_Helper::displayPreview( aPrs, append, update );
1608
1609   getDisplayer()->UnsetName();
1610
1611   // Enable activation of displayed objects
1612   getDisplayer()->SetToActivate( true );
1613 }
1614
1615 //================================================================
1616 // Function : createShapes
1617 // Purpose  : Create applyed wire, and last segment from entry object
1618 //================================================================
1619 bool EntityGUI_SketcherDlg::createShapes( GEOM::GEOM_Object_ptr theObject,
1620                                           TopoDS_Shape&         theApplyedWire,
1621                                           TopoDS_Shape&         theLastSegment )
1622 {
1623   TopoDS_Shape aShape;
1624   if ( !GEOMBase::GetShape( theObject, aShape ) ||
1625        aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX )
1626     return false;
1627
1628   if ( Group1Sel->isVisible()  && !Group1Sel->buttonApply->isEnabled()  ||
1629        Group1Spin->isVisible() && !Group1Spin->buttonApply->isEnabled() ||
1630        Group2Spin->isVisible() && !Group2Spin->buttonApply->isEnabled() ||
1631        Group3Spin->isVisible() && !Group3Spin->buttonApply->isEnabled() ||
1632        Group4Spin->isVisible() && !Group4Spin->buttonApply->isEnabled() ) {
1633      theApplyedWire = aShape;
1634      return true;
1635   }
1636
1637   BRepBuilderAPI_MakeWire aBuilder;
1638   TopExp_Explorer anExp( aShape, TopAbs_EDGE );
1639   while ( 1 ) {
1640     TopoDS_Shape anEdge = anExp.Current();
1641     anExp.Next();
1642     if ( anExp.More() ) // i.e. non-last edge
1643       aBuilder.Add( TopoDS::Edge( anEdge ) );
1644     else {
1645       theLastSegment = anEdge;
1646       break;
1647     }
1648   }
1649
1650   if ( aBuilder.IsDone() )
1651     theApplyedWire = aBuilder.Shape();
1652
1653   return true;
1654 }
1655
1656 //=================================================================================
1657 // function : keyPressEvent()
1658 // purpose  :
1659 //=================================================================================
1660 void  EntityGUI_SketcherDlg::keyPressEvent( QKeyEvent* e )
1661 {
1662   QDialog::keyPressEvent( e );
1663   if ( e->isAccepted() )
1664     return;
1665
1666   if ( e->key() == Qt::Key_F1 ) {
1667     e->accept();
1668     ClickOnHelp();
1669   }
1670 }
1671
1672 //=================================================================================
1673 // function : initSpinBox()
1674 // purpose  :
1675 //=================================================================================
1676 void EntityGUI_SketcherDlg::initSpinBox( SalomeApp_DoubleSpinBox* spinBox,
1677                                          double min,  double max,
1678                                          double step, const char* quantity )
1679 {
1680   // The same stuff as in GEOMBase_Skeleton::initSpinBox()!
1681   // TODO: Think how to keep the single piece of code...
1682
1683   // Obtain precision from preferences
1684   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1685   int aPrecision = resMgr->integerValue( "Geometry", quantity, 6 );
1686   
1687   spinBox->setPrecision( aPrecision );
1688   spinBox->setDecimals( qAbs( aPrecision ) ); // it's necessary to set decimals before the range setting,
1689                                               // by default Qt rounds boundaries to 2 decimals at setRange
1690   spinBox->setRange( min, max );
1691   spinBox->setSingleStep( step );
1692   
1693   // Add a hint for the user saying how to tune precision
1694   QString userPropName = QObject::tr( QString( "GEOM_PREF_%1" ).arg( quantity ).toLatin1().constData() );
1695   spinBox->setProperty( "validity_tune_hint", 
1696                         QVariant( QObject::tr( "GEOM_PRECISION_HINT" ).arg( userPropName ) ) );
1697 }
1698
1699 //=================================================================================
1700 // function : SetDoubleSpinBoxStep()
1701 // purpose  : Double spin box management
1702 //=================================================================================
1703 void EntityGUI_SketcherDlg::SetDoubleSpinBoxStep( double step )
1704 {
1705   Group1Spin->SpinBox_DX->setSingleStep(step);
1706   Group2Spin->SpinBox_DX->setSingleStep(step);
1707   Group2Spin->SpinBox_DY->setSingleStep(step);
1708   Group3Spin->SpinBox_DX->setSingleStep(step);
1709   Group3Spin->SpinBox_DY->setSingleStep(step);
1710   Group3Spin->SpinBox_DZ->setSingleStep(step);
1711   Group4Spin->SpinBox_DZ->setSingleStep(step);
1712
1713   // san: Do NOT override the step when a speicifc step value is used
1714   // in some input fields!
1715   //Group4Spin->SpinBox_DX->setSingleStep(step);
1716   //Group4Spin->SpinBox_DY->setSingleStep(step);
1717   //Group4Spin->SpinBox_DS->setSingleStep(step);
1718 }
1719
1720 //=================================================================================
1721 // function : FindLocalCS()
1722 // purpose  : Find All Coordinates systems in study
1723 //=================================================================================
1724 void EntityGUI_SketcherDlg::FindLocalCS()
1725 {
1726   ComboBox1->clear();
1727   myLCSList.clear();
1728   SalomeApp_Application* app =
1729     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1730   if ( !app )
1731     return;
1732
1733   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1734   if ( !appStudy )
1735     return;
1736
1737   _PTR(Study) aStudy = appStudy->studyDS();
1738
1739   //add Global CS
1740   ComboBox1->addItem(tr("GEOM_GCS"));
1741   gp_Pnt aOrigin = gp_Pnt(0, 0, 0);
1742   gp_Dir aDirZ = gp_Dir(0, 0, 1);
1743   gp_Dir aDirX = gp_Dir(1, 0, 0);
1744   gp_Ax3 globalCS = gp_Ax3(aOrigin, aDirZ, aDirX);
1745   myLCSList.push_back(globalCS);
1746
1747   // get GEOM component
1748   CORBA::String_var geomIOR = app->orb()->object_to_string( GeometryGUI::GetGeomGen() );
1749   _PTR(SObject) obj = aStudy->FindObjectIOR( geomIOR.in() );
1750   if (!obj)
1751     return;
1752   _PTR(SComponent) fc = obj->GetFatherComponent();
1753   QString geomComp = fc->GetID().c_str();
1754   _PTR(SObject) comp = aStudy->FindObjectID( geomComp.toLatin1().data() );
1755   if ( !comp )
1756     return;
1757
1758   // browse through all GEOM data tree
1759   _PTR(ChildIterator) it ( aStudy->NewChildIterator( comp ) );
1760   for ( it->InitEx( true ); it->More(); it->Next() ) {
1761     _PTR(SObject) child( it->Value() );
1762     CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( child );
1763     GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
1764     if( CORBA::is_nil( geomObj ) ) 
1765       continue;
1766     if (geomObj->GetType() == GEOM_MARKER) {
1767       ComboBox1->addItem(geomObj->GetName());
1768       TopoDS_Shape aShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), geomObj);
1769       
1770       gp_Ax3 aLCS;
1771       aLCS.Transform(aShape.Location().Transformation());
1772       if (aShape.ShapeType() == TopAbs_FACE) {
1773         Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(aShape));
1774         if (!aGS.IsNull() && aGS->IsKind(STANDARD_TYPE(Geom_Plane))) {
1775           Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast(aGS);
1776           gp_Pln aPln = aGPlane->Pln();
1777           aLCS = aPln.Position();
1778         }
1779       }
1780       myLCSList.push_back(aLCS);
1781     }
1782   }
1783 }
1784
1785 //=================================================================================
1786 // function : GetActiveLocalCS()
1787 // purpose  : Get Working plane
1788 //=================================================================================
1789 gp_Ax3 EntityGUI_SketcherDlg::GetActiveLocalCS()
1790 {
1791   int ind = ComboBox1->currentIndex();
1792   if (ind == -1)
1793     return myGeometryGUI->GetWorkingPlane();
1794
1795   gp_Ax3 aLCS = myLCSList.at(ind);
1796
1797   return aLCS;
1798 }
1799
1800 //=================================================================================
1801 // function : ActivateLocalCS()
1802 // purpose  : Activate & Fit Working plane
1803 //=================================================================================
1804 void EntityGUI_SketcherDlg::ActivateLocalCS()
1805 {
1806     myGeometryGUI->SetWorkingPlane( GetActiveLocalCS() );
1807     myGeometryGUI->ActiveWorkingPlane();
1808 }