Salome HOME
923e5e973ce93300ea410fc2bf5385f06a4e3011
[modules/geom.git] / src / EntityGUI / EntityGUI_SketcherDlg.cxx
1 // Copyright (C) 2007-2011  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->setSizePolicy( QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed));
120   planeButton->setText( tr( "GEOM_SKETCHER_RESTORE" ) );
121   planeLayout->addWidget(planeButton);
122
123   topLayout->addWidget(GroupBox1);
124   topLayout->addWidget( MainWidget );
125   topLayout->setStretch( 1, 1);
126
127   GroupPt = new EntityGUI_Point( MainWidget->DestCnt );
128
129   GroupPt->GroupPoint->setTitle( tr( "GEOM_SKETCHER_POINT" ) );
130   GroupPt->RB_Point1->setText( tr( "GEOM_SKETCHER_ABS" ) );
131   GroupPt->RB_Point2->setText( tr( "GEOM_SKETCHER_REL" ) );
132   GroupPt->RB_Point3->setText( tr( "GEOM_SKETCHER_SEL" ) );
133
134   GroupPt2 = new EntityGUI_Point( MainWidget->DestCnt );
135
136   GroupPt2->GroupPoint->setTitle( tr( "GEOM_SKETCHER_ADD_PARAMS" ) ); 
137   GroupPt2->RB_Point1->setText( tr( "GEOM_SKETCHER_NONE" ) );
138   GroupPt2->RB_Point2->setText( tr( "GEOM_SKETCHER_RADIUS" ) );
139   GroupPt2->RB_Point3->setText( tr( "GEOM_SKETCHER_CENTER" ) ); 
140
141   GroupD1 = new EntityGUI_Dir1( MainWidget->DestCnt );
142
143   GroupD1->GroupDir1->setTitle( tr( "GEOM_SKETCHER_DIR" ) );
144   GroupD1->RB_Dir11->setText( tr( "GEOM_SKETCHER_ANGLE" ) );
145   GroupD1->RB_Dir12->setText( tr( "GEOM_SKETCHER_PER" ) );
146   GroupD1->RB_Dir13->setText( tr( "GEOM_SKETCHER_TAN" ) );
147   GroupD1->RB_Dir14->setText( tr( "GEOM_SKETCHER_VXVY" ) );
148
149   GroupD2 = new EntityGUI_Dir2( MainWidget->DestCnt );
150
151   GroupD2->GroupDir2->setTitle( tr( "GEOM_SKETCHER_DIR" ) );
152   GroupD2->RB_Dir21->setText( tr( "GEOM_SKETCHER_LENGTH" ) );
153   GroupD2->RB_Dir22->setText( tr( "GEOM_SKETCHER_X" ) );
154   GroupD2->RB_Dir23->setText( tr( "GEOM_SKETCHER_Y" ) );
155
156   Group1Sel = new EntityGUI_1Sel( MainWidget->SkeletonCnt );
157   Group1Sel->TextLabel1->setText( tr( "GEOM_SKETCHER_POINT2" ) );
158   Group1Sel->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
159   Group1Sel->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
160   Group1Sel->PushButton1->setIcon( image0 );
161   Group1Sel->buttonUndo->setIcon( image1 );
162   Group1Sel->buttonRedo->setIcon( image2 );
163   Group1Sel->LineEdit1->setReadOnly( true );
164
165   Group2Sel = new EntityGUI_2Sel1Check( MainWidget->SkeletonCnt );
166   Group2Sel->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
167   Group2Sel->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
168   Group2Sel->checkBox->setText( tr( "GEOM_REVERSE" ) );
169   Group2Sel->PushButton1->setIcon( image0 );
170   Group2Sel->PushButton2->setIcon( image0 );
171   Group2Sel->buttonUndo->setIcon( image1 );
172   Group2Sel->buttonRedo->setIcon( image2 );
173   Group2Sel->LineEdit1->setReadOnly( true );
174   Group2Sel->LineEdit2->setReadOnly( true );
175
176   Group1Sel1Spin = new EntityGUI_1Sel1Spin1Check( MainWidget->SkeletonCnt );
177   Group1Sel1Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
178   Group1Sel1Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
179   Group1Sel1Spin->checkBox->setText( tr( "GEOM_REVERSE" ) );
180   Group1Sel1Spin->PushButton1->setIcon( image0 );
181   Group1Sel1Spin->buttonUndo->setIcon( image1 );
182   Group1Sel1Spin->buttonRedo->setIcon( image2 );
183   Group1Sel1Spin->LineEdit1->setReadOnly( true );
184
185   Group1Spin = new EntityGUI_1Spin( MainWidget->SkeletonCnt );
186   Group1Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
187   Group1Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
188   Group1Spin->buttonUndo->setIcon( image1 );
189   Group1Spin->buttonRedo->setIcon( image2 );
190
191   Group2Spin = new EntityGUI_2Spin( MainWidget->SkeletonCnt );
192   Group2Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
193   Group2Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
194   Group2Spin->buttonUndo->setIcon( image1 );
195   Group2Spin->buttonRedo->setIcon( image2 );
196
197   Group3Spin = new EntityGUI_3Spin1Check( MainWidget->SkeletonCnt );
198   Group3Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
199   Group3Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
200   Group3Spin->checkBox->setText( tr( "GEOM_REVERSE" ) );
201   Group3Spin->buttonUndo->setIcon( image1 );
202   Group3Spin->buttonRedo->setIcon( image2 );
203
204   Group4Spin = new EntityGUI_4Spin1Check( MainWidget->SkeletonCnt );
205   Group4Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
206   Group4Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
207   Group4Spin->checkBox->setText( tr( "GEOM_REVERSE" ) );
208   Group4Spin->buttonUndo->setIcon( image1 );
209   Group4Spin->buttonRedo->setIcon( image2 );
210
211   // Defines a palette for the error message on Group4Spin and Group2Sel 
212   QPalette palette;
213   QColor color("red");
214   palette.setColor(Group4Spin->label->foregroundRole(), color);
215   Group4Spin->label->setPalette(palette);
216   palette.setColor(Group2Sel->label->foregroundRole(), color);
217   Group2Sel->label->setPalette(palette);
218
219   QGridLayout* DestCntLayout = new QGridLayout( MainWidget->DestCnt );
220   DestCntLayout->setMargin( 0 ); DestCntLayout->setSpacing( 6 );
221   DestCntLayout->addWidget( GroupPt, 0, 0 );
222   DestCntLayout->addWidget( GroupPt2, 0, 1 );
223   DestCntLayout->addWidget( GroupD1, 0, 0 );
224   DestCntLayout->addWidget( GroupD2, 0, 1 );
225
226   QVBoxLayout* SkeletonCntlayout = new QVBoxLayout( MainWidget->SkeletonCnt );
227   SkeletonCntlayout->setMargin( 0 ); SkeletonCntlayout->setSpacing( 6 );
228   SkeletonCntlayout->addWidget( Group1Sel,  0, 0 );
229   SkeletonCntlayout->addWidget( Group2Sel,  0, 0 );
230   SkeletonCntlayout->addWidget( Group1Sel1Spin,  0, 0 );
231   SkeletonCntlayout->addWidget( Group1Spin, 0, 0 );
232   SkeletonCntlayout->addWidget( Group2Spin, 0, 0 );
233   SkeletonCntlayout->addWidget( Group3Spin, 0, 0 );
234   SkeletonCntlayout->addWidget( Group4Spin, 0, 0 );
235   //SkeletonCntlayout->setStretch( 0, 1);
236   /***************************************************************/
237
238   QButtonGroup* ButtonGroup = new QButtonGroup( this );
239   ButtonGroup->addButton( MainWidget->RB_Dest1, 1 );
240   ButtonGroup->addButton( MainWidget->RB_Dest2, 0 );
241
242   /* signals and slots connections */
243   connect( MainWidget->buttonEnd,    SIGNAL( clicked() ),              this, SLOT( ClickOnEnd() ) );
244   connect( MainWidget->buttonClose,  SIGNAL( clicked() ),              this, SLOT( ClickOnEnd() ) );
245   connect( MainWidget->buttonCancel, SIGNAL( clicked() ),              this, SLOT( ClickOnCancel() ) );
246   connect( MainWidget->buttonHelp,   SIGNAL( clicked() ),              this, SLOT( ClickOnHelp() ) );
247
248   connect( Group1Sel->buttonApply,   SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
249   connect( Group1Sel->buttonUndo,    SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
250   connect( Group1Sel->buttonRedo,    SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) );
251   connect( Group2Sel->buttonApply,   SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
252   connect( Group2Sel->buttonUndo,    SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
253   connect( Group2Sel->buttonRedo,    SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) );
254   connect( Group1Sel1Spin->buttonApply,SIGNAL( clicked() ),            this, SLOT( ClickOnApply() ) );
255   connect( Group1Sel1Spin->buttonUndo, SIGNAL( clicked() ),            this, SLOT( ClickOnUndo() ) );
256   connect( Group1Sel1Spin->buttonRedo, SIGNAL( clicked() ),            this, SLOT( ClickOnRedo() ) );
257   connect( Group1Spin->buttonApply,  SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
258   connect( Group1Spin->buttonUndo,   SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
259   connect( Group1Spin->buttonRedo,   SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) );
260   connect( Group2Spin->buttonApply,  SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
261   connect( Group2Spin->buttonUndo,   SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
262   connect( Group2Spin->buttonRedo,   SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) );
263   connect( Group3Spin->buttonApply,  SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
264   connect( Group3Spin->buttonUndo,   SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
265   connect( Group3Spin->buttonRedo,   SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) ) ;
266   connect( Group4Spin->buttonApply,  SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
267   connect( Group4Spin->buttonUndo,   SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
268   connect( Group4Spin->buttonRedo,   SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) );
269
270   connect( MainWidget->ButtonGroup,  SIGNAL( buttonClicked( int ) ),   this, SLOT( TypeClicked( int ) ) );
271   connect( ButtonGroup,              SIGNAL( buttonClicked( int ) ),   this, SLOT( DestClicked( int ) ) );
272   connect( GroupPt->ButtonGroup,     SIGNAL( buttonClicked( int ) ),   this, SLOT( PointClicked( int ) ) );
273   connect( GroupPt2->ButtonGroup,    SIGNAL( buttonClicked( int ) ),   this, SLOT( Point2Clicked( int ) ) );
274   connect( GroupD1->ButtonGroup,     SIGNAL( buttonClicked( int ) ),   this, SLOT( Dir1Clicked( int ) ) );
275   connect( GroupD2->ButtonGroup,     SIGNAL( buttonClicked( int ) ),   this, SLOT( Dir2Clicked( int ) ));
276
277   connect( Group1Sel->LineEdit1,     SIGNAL( returnPressed() ),        this, SLOT( LineEditReturnPressed() ) );
278   connect( Group1Sel->PushButton1,   SIGNAL( clicked() ),              this, SLOT( SetEditCurrentArgument() ) );
279
280   connect( Group2Sel->LineEdit1,     SIGNAL( returnPressed() ),        this, SLOT( LineEditReturnPressed() ) );
281   connect( Group2Sel->LineEdit2,     SIGNAL( returnPressed() ),        this, SLOT( LineEditReturnPressed() ) );
282   connect( Group2Sel->PushButton1,   SIGNAL( clicked() ),              this, SLOT( SetEditCurrentArgument() ) );
283   connect( Group2Sel->PushButton2,   SIGNAL( clicked() ),              this, SLOT( SetEditCurrentArgument() ) );
284
285   connect( Group1Sel1Spin->LineEdit1,SIGNAL( returnPressed() ),        this, SLOT( LineEditReturnPressed() ) );
286   connect( Group1Sel1Spin->PushButton1,SIGNAL( clicked() ),            this, SLOT( SetEditCurrentArgument() ) );
287   connect( Group1Sel1Spin->SpinBox_DX,SIGNAL( valueChanged( double ) ),this, SLOT( ValueChangedInSpinBox( double ) ) );
288
289   connect( Group1Spin->SpinBox_DX,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
290   connect( Group2Spin->SpinBox_DX,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
291   connect( Group2Spin->SpinBox_DY,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
292   connect( Group3Spin->SpinBox_DX,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
293   connect( Group3Spin->SpinBox_DY,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
294   connect( Group3Spin->SpinBox_DZ,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
295   connect( Group4Spin->SpinBox_DX,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
296   connect( Group4Spin->SpinBox_DY,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
297   connect( Group4Spin->SpinBox_DZ,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
298   connect( Group4Spin->SpinBox_DS,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
299
300   connect( Group3Spin->checkBox,     SIGNAL( stateChanged( int ) ),    this, SLOT( CheckBoxClicked( int ) ) );
301   connect( Group4Spin->checkBox,     SIGNAL( stateChanged( int ) ),    this, SLOT( CheckBoxClicked( int ) ) );
302   connect( Group2Sel->checkBox,      SIGNAL( stateChanged( int ) ),    this, SLOT( CheckBoxClicked( int ) ) );
303   connect( Group1Sel1Spin->checkBox, SIGNAL( stateChanged( int ) ),    this, SLOT( CheckBoxClicked( int ) ) );
304
305   connect( ComboBox1,                SIGNAL( activated( int ) ),       this, SLOT( SelectionIntoArgument() ) );
306   connect( planeButton,              SIGNAL( clicked() ),              this, SLOT( ActivateLocalCS() ) );
307
308   connect( myGeometryGUI,            SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
309
310   connect( myGeometryGUI,            SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
311   connect( myGeometryGUI,            SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
312   
313   // install event filter on spin-boxes to provide Apply action on Return pressed
314   Group1Spin->SpinBox_DX->installEventFilter(this);
315   Group1Sel1Spin->SpinBox_DX->installEventFilter(this);
316   Group2Spin->SpinBox_DX->installEventFilter(this);
317   Group2Spin->SpinBox_DY->installEventFilter(this);
318   Group3Spin->SpinBox_DX->installEventFilter(this);
319   Group3Spin->SpinBox_DY->installEventFilter(this);
320   Group3Spin->SpinBox_DZ->installEventFilter(this);
321   Group4Spin->SpinBox_DX->installEventFilter(this);
322   Group4Spin->SpinBox_DY->installEventFilter(this);
323   Group4Spin->SpinBox_DZ->installEventFilter(this);
324   Group4Spin->SpinBox_DS->installEventFilter(this);
325
326   Init();
327 }
328
329
330 //=================================================================================
331 // function : ~EntityGUI_SketcherDlg()
332 // purpose  : Destroys the object and frees any allocated resources
333 //=================================================================================
334 EntityGUI_SketcherDlg::~EntityGUI_SketcherDlg()
335 {
336   myGeometryGUI->SetActiveDialogBox( 0 );
337 }
338
339
340 //=================================================================================
341 // function : eventFilter()
342 // purpose  : event filter for spin-boxes to provide Apply action on Return pressed
343 //=================================================================================
344 bool EntityGUI_SketcherDlg::eventFilter (QObject* object, QEvent* event)
345 {
346   if (event->type() == QEvent::KeyPress) {
347     QKeyEvent* ke = (QKeyEvent*)event;
348     if (ke->key() == Qt::Key_Return) {
349       if (object == Group1Spin->SpinBox_DX) {
350         Group1Spin->buttonApply->animateClick();
351         return true;
352       } else if (object == Group1Sel1Spin->SpinBox_DX) {
353         Group1Sel1Spin->buttonApply->animateClick();
354         return true;
355       } else if (object == Group2Spin->SpinBox_DX ||
356                  object == Group2Spin->SpinBox_DY) {
357         Group2Spin->buttonApply->animateClick();
358         return true;
359       } else if (object == Group3Spin->SpinBox_DX ||
360                  object == Group3Spin->SpinBox_DY ||
361                  object == Group3Spin->SpinBox_DZ) {
362         Group3Spin->buttonApply->animateClick();
363         return true;
364       } else if (object == Group4Spin->SpinBox_DX ||
365                  object == Group4Spin->SpinBox_DY ||
366                  object == Group4Spin->SpinBox_DZ ||
367                  object == Group4Spin->SpinBox_DS) {
368         Group4Spin->buttonApply->animateClick();
369         return true;
370       }
371     }
372   }
373
374   // Fix of the NPAL16010 bug is removed, because it's not actual with the Qt-4.x
375
376   return QDialog::eventFilter(object, event);
377 }
378
379
380 //=================================================================================
381 // function : Init()
382 // purpose  :
383 //=================================================================================
384 void EntityGUI_SketcherDlg::Init()
385 {
386   /* init variables */
387   myEditCurrentArgument = Group1Sel->LineEdit1;
388   myCommand.append( "Sketcher" );
389   myUndoCommand.append( "Sketcher" );
390
391   mySketchState = FIRST_POINT;
392   globalSelection( GEOM_POINT );
393
394   myCheckFlag = 0;
395
396   myLastX1 = 0.0;
397   myLastY1 = 0.0;
398   myLastX2 = 0.0;
399   myLastY2 = 0.0;
400
401   myHelpFileName = "create_sketcher_page.html";
402
403   /* Get setting of step value from file configuration */
404   double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
405
406   /* min, max, step and decimals for spin boxes */
407   initSpinBox( Group1Sel1Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
408   initSpinBox( Group1Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
409   initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
410   initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
411   initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
412   initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
413   initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
414   initSpinBox( Group4Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
415   // san: Note specific step values below!
416   initSpinBox( Group4Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
417   initSpinBox( Group4Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
418   initSpinBox( Group4Spin->SpinBox_DS, COORD_MIN, COORD_MAX, 5., "length_precision" );
419
420   /* displays Dialog */
421   MainWidget->GroupConstructors->setEnabled( false );
422   MainWidget->GroupDest1->setEnabled( false );
423   setEnabledUndo( false );
424   setEnabledRedo( false );
425
426   MainWidget->RadioButton1->setChecked( true );
427
428   TypeClicked( 0 );
429
430   FindLocalCS();
431   resize(100,100);
432
433   ActivateLocalCS();
434   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
435 }
436
437
438 //=================================================================================
439 // function : InitClick()
440 // purpose  :
441 //=================================================================================
442 void EntityGUI_SketcherDlg::InitClick()
443 {
444   disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
445   myCheckFlag = 0;
446
447   Group1Sel->hide();
448   Group2Sel->hide();
449   Group1Sel1Spin->hide();
450   Group1Spin->hide();
451   Group2Spin->hide();
452   Group3Spin->hide();
453   Group4Spin->hide();
454 }
455
456
457 //=================================================================================
458 // function : TypeClicked()
459 // purpose  : Radio button management
460 //=================================================================================
461 void EntityGUI_SketcherDlg::TypeClicked( int constructorId )
462 {
463   myConstructorId = constructorId;
464   if ( myConstructorId == 0 ) {    // SEGMENT
465     GroupPt2->RB_Point1->setChecked( true );
466     GroupPt2->setEnabled( false );
467     GroupD2->setEnabled( true );
468     MainWidget->RB_Dest1->setEnabled( true );
469     MainWidget->RB_Dest1->setChecked( true );
470     DestClicked( 1 );
471   }
472   else if (  myConstructorId == 1 ) { // ARC
473     GroupPt2->setEnabled( true );
474     GroupD2->RB_Dir21->setChecked( true );
475     GroupD2->setEnabled( false );
476     MainWidget->RB_Dest1->setEnabled( true ); 
477     MainWidget->RB_Dest1->setChecked( true );
478     DestClicked( 1 );
479   }
480 }
481
482
483 //=================================================================================
484 // function : DestClicked()
485 // purpose  : Radio button management
486 //=================================================================================
487 void EntityGUI_SketcherDlg::DestClicked( int constructorId )
488 {
489   GroupPt->hide();
490   GroupPt2->hide();
491   GroupD1->hide();
492   GroupD2->hide();
493
494   if ( constructorId == 1 ) {
495     // Point
496     GroupPt->RB_Point1->setChecked( true );
497     GroupPt->show();
498     GroupPt2->show();
499     Group3Spin->checkBox->show();
500     Group4Spin->checkBox->show();
501     PointClicked( 1 );  // XY
502   }
503   else if (  constructorId == 0 ) {
504     // Direction
505     GroupD1->RB_Dir11->setChecked( true );
506     GroupD1->show();
507     GroupD2->show();
508     Group3Spin->checkBox->hide();
509     Group4Spin->checkBox->hide();
510     Dir1Clicked( 2 );  // Angle
511   }
512   resize( minimumSizeHint() );
513 }
514
515 //=================================================================================
516 // function : PointClicked()
517 // purpose  : Radio button management
518 //=================================================================================
519 void EntityGUI_SketcherDlg::PointClicked( int constructorId )
520 {
521   MESSAGE("PointClicked")
522   myConstructorPntId = constructorId;  
523   GroupPt->RB_Point3->setEnabled( true );
524   int buttonId = GroupPt2->ButtonGroup->checkedId();
525   MESSAGE("checkedId ="<< buttonId)
526   if (buttonId >= 0){           // = If a button is checked
527     Point2Clicked(buttonId);
528   }
529   else{ 
530     GroupPt2->RB_Point1->setChecked( true );
531     Point2Clicked( 1 ); 
532   }
533 }
534
535 //=================================================================================
536 // function : Point2Clicked()
537 // purpose  : Radio button management
538 //=================================================================================
539 void EntityGUI_SketcherDlg::Point2Clicked( int constructorId )
540 {
541   MESSAGE("Point2Clicked")
542   InitClick();
543
544   // Get setting of step value from file configuration
545   double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
546
547   if ( myConstructorPntId == 1 ) {  // XY
548     if ( constructorId == 1 ){      // No additional parameter
549       mySketchType = PT_ABS;
550       initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
551       initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
552       Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X2" ) );
553       Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y2" ) );
554       myX = 0.0;
555       Group2Spin->SpinBox_DX->setValue( myX );
556       myY = 0.0;
557       Group2Spin->SpinBox_DY->setValue( myY );
558       Group2Spin->show();
559       Group2Spin->buttonApply->setFocus();
560
561       GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
562     }
563     else if ( constructorId == 0 ){   // Point + radius
564       mySketchType = PT_ABS_RADIUS;
565       initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" ); 
566       initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
567       initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step/10.0, "length_precision" );
568       Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X2" ) );
569       Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y2" ) );
570       Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_RADIUS2" ) ); 
571       myX = 0.0;
572       Group3Spin->SpinBox_DX->setValue( myX );
573       myY = 0.0;
574       Group3Spin->SpinBox_DY->setValue( myY );
575       myRadius=0.0;
576       Group3Spin->SpinBox_DZ->setValue( myRadius ); 
577       Group3Spin->show();
578       Group3Spin->buttonApply->setFocus();
579
580       GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
581     }
582     else if ( constructorId == 2 ){   // Point + center
583       mySketchType = PT_ABS_CENTER;
584       initSpinBox( Group4Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" ); 
585       initSpinBox( Group4Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
586       initSpinBox( Group4Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
587       initSpinBox( Group4Spin->SpinBox_DS, COORD_MIN, COORD_MAX, step, "length_precision" );
588       Group4Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_X2" ) );
589       Group4Spin->TextLabel4->setText( tr( "GEOM_SKETCHER_Y2" ) );
590       Group4Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_CENTER_X" ) );
591       Group4Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_CENTER_Y" ) ); 
592       myXc = 0.0;
593       Group4Spin->SpinBox_DX->setValue( myXc );
594       myYc = 0.0;
595       Group4Spin->SpinBox_DY->setValue( myYc );
596       myX = 0.0;
597       Group4Spin->SpinBox_DZ->setValue( myX ); 
598       myY = 0.0;
599       Group4Spin->SpinBox_DS->setValue( myY );
600       Group4Spin->show();
601       Group4Spin->buttonApply->setFocus();
602
603       GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
604     }
605
606   }
607   else if ( myConstructorPntId == 0 ) {  // DXDY
608     if ( constructorId == 1 ){    // No additional parameter
609       mySketchType = PT_RELATIVE;
610       initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
611       initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
612       Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_DX2" ) );
613       Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_DY2" ) );
614       myDX = 0.0;
615       Group2Spin->SpinBox_DX->setValue( myDX );
616       myDY = 0.0;
617       Group2Spin->SpinBox_DY->setValue( myDY );
618       Group2Spin->show();
619       Group2Spin->buttonApply->setFocus();
620
621       GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
622     }
623     else if ( constructorId == 0 ){   // Point + radius 
624       mySketchType = PT_REL_RADIUS;
625       initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" ); 
626       initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
627       initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step/10.0, "length_precision" );
628       Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_DX2" ) );
629       Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_DY2" ) );
630       Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_RADIUS2" ) ); 
631       myDX = 10.0;
632       Group3Spin->SpinBox_DX->setValue( myDX );
633       myDY = 0.0;
634       Group3Spin->SpinBox_DY->setValue( myDY );
635       myRadius=5.0;
636       Group3Spin->SpinBox_DZ->setValue( myRadius );
637       Group3Spin->show();
638       Group3Spin->buttonApply->setFocus();
639
640       GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
641     }
642     else if ( constructorId == 2 ){   // Point + center
643       mySketchType = PT_REL_CENTER;
644       initSpinBox( Group4Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" ); 
645       initSpinBox( Group4Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
646       initSpinBox( Group4Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
647       initSpinBox( Group4Spin->SpinBox_DS, COORD_MIN, COORD_MAX, step, "length_precision" );
648       Group4Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_DX2" ) );
649       Group4Spin->TextLabel4->setText( tr( "GEOM_SKETCHER_DY2" ) );
650       Group4Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_CENTER_DX" ) );
651       Group4Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_CENTER_DY" ) ); 
652       myDXc = 0.0;
653       Group4Spin->SpinBox_DX->setValue( myDXc );
654       myDYc = 0.0;
655       Group4Spin->SpinBox_DY->setValue( myDYc );
656       myDX = 0.0;
657       Group4Spin->SpinBox_DZ->setValue( myDX ); 
658       myDY = 0.0;
659       Group4Spin->SpinBox_DS->setValue( myDY );
660       Group4Spin->show();
661       Group4Spin->buttonApply->setFocus();
662
663       GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
664     }
665
666   }
667   else if ( myConstructorPntId == 2 ) {  // Selection
668     if ( constructorId == 1 ){    // No additional parameter
669       mySketchType = PT_SEL;
670       myEditCurrentArgument = Group1Sel->LineEdit1;
671       Group1Sel->TextLabel1->setText( tr( "GEOM_SKETCHER_END_POINT2" ) ); 
672       Group1Sel->show();
673       Group1Sel->buttonApply->setFocus();
674       SelectionIntoArgument();
675     }
676     else if ( constructorId == 0 ){   // Point + radius 
677       mySketchType = PT_SEL_RADIUS;
678       myEditCurrentArgument = Group1Sel1Spin->LineEdit1;
679       initSpinBox( Group1Sel1Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step/10.0, "length_precision" );
680       Group1Sel1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_END_POINT2" ) ); 
681       Group1Sel1Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_RADIUS2" ) ); 
682       myRadius=0.0;
683       Group1Sel1Spin->SpinBox_DX->setValue( myRadius );
684
685       Group1Sel1Spin->show();
686       Group1Sel1Spin->buttonApply->setFocus();
687       SelectionIntoArgument();
688     }
689     else if ( constructorId == 2 ){   // Point + center 
690       mySketchType = PT_SEL_CENTER;
691       myEditCurrentArgument = Group2Sel->LineEdit1;
692       Group2Sel->TextLabel2->setText( tr( "GEOM_SKETCHER_END_POINT2" ) );  
693       Group2Sel->TextLabel1->setText( tr( "GEOM_SKETCHER_CENTER2" ) );
694       Group2Sel->LineEdit1->setEnabled(true);
695       Group2Sel->PushButton1->setDown(true);
696       Group2Sel->LineEdit2->setEnabled(false);
697       Group2Sel->PushButton2->setDown(false);
698       Group2Sel->show();
699       Group2Sel->buttonApply->setFocus();
700       SelectionIntoArgument();
701     }
702
703   }
704   resize( minimumSizeHint() );
705   connect( myGeometryGUI->getApp()->selectionMgr(),
706            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
707   
708 }
709
710
711 //=================================================================================
712 // function : Dir1Clicked()
713 // purpose  : Radio button management
714 //=================================================================================
715 void EntityGUI_SketcherDlg::Dir1Clicked( int constructorId )
716 {
717   myConstructorDirId = constructorId;
718   int dirButtonId = GroupD2->ButtonGroup->checkedId();
719   MESSAGE("checkedId ="<< dirButtonId)
720   if (dirButtonId >= 0){           // = If a button is checked
721     Dir2Clicked(dirButtonId);
722   }
723   else{ 
724     GroupD2->RB_Dir21->setChecked( true );
725     Dir2Clicked( 2 ); 
726   }
727 }
728
729
730 //=================================================================================
731 // function : Dir2Clicked()
732 // purpose  : Radio button management
733 //=================================================================================
734 void EntityGUI_SketcherDlg::Dir2Clicked( int constructorId )
735 {
736   InitClick();
737   myAngle = 0.0;
738
739   // Get setting of step value from file configuration
740   double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
741
742   if ( myConstructorId == 0 ) {  // SEGMENT
743     myX = 0.0;
744     myY = 0.0;
745     myLength = 100.0;
746     if ( myConstructorDirId == 2 ) {  // Angle
747       initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 5., "length_precision" );
748       Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
749       Group2Spin->SpinBox_DX->setValue( myAngle );
750       Group2Spin->buttonApply->setFocus();
751       Group2Spin->show();
752
753       if ( constructorId == 2 ) {  // Length
754         mySketchType = DIR_ANGLE_LENGTH;
755         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
756         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
757         Group2Spin->SpinBox_DY->setValue( myLength );
758       }
759       else if ( constructorId == 0 ) {  // X
760         mySketchType = DIR_ANGLE_X;
761         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "angle_precision" );
762         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_X3" ) );
763         Group2Spin->SpinBox_DY->setValue( myX );
764       }
765       else if ( constructorId == 1 ) {  // Y
766         mySketchType = DIR_ANGLE_Y;
767         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "angle_precision" );        
768         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y3" ) );
769         Group2Spin->SpinBox_DY->setValue( myY );
770       }
771     }
772     else if ( myConstructorDirId == 0 ) {  // Perpendicular
773       Group1Spin->show();
774       Group1Spin->buttonApply->setFocus();
775
776       if ( constructorId == 2 ) {  // Length
777         mySketchType = DIR_PER_LENGTH;
778         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
779         Group1Spin->SpinBox_DX->setValue( myLength );
780       }
781       else if ( constructorId == 0 ) {  // X
782         mySketchType = DIR_PER_X;
783         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X3" ) );
784         Group1Spin->SpinBox_DX->setValue( myX );
785       }
786       else if ( constructorId == 1 ) {  // Y
787         mySketchType = DIR_PER_Y;
788         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_Y3" ) );
789         Group1Spin->SpinBox_DX->setValue( myY );
790       }
791     }
792     else if ( myConstructorDirId == 1 ) {  // Tangent
793       Group1Spin->show();
794       Group1Spin->buttonApply->setFocus();
795
796       if ( constructorId == 2 ) {  // Length
797         mySketchType = DIR_TAN_LENGTH;
798         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
799         Group1Spin->SpinBox_DX->setValue( myLength );
800       }
801       else if ( constructorId == 0 ) {  // X
802         mySketchType = DIR_TAN_X;
803         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X3" ) );
804         Group1Spin->SpinBox_DX->setValue( myX );
805       }
806       else if ( constructorId == 1 ) {  // Y
807         mySketchType = DIR_TAN_Y;
808         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_Y3" ) );
809         Group1Spin->SpinBox_DX->setValue( myY );
810       }
811     }
812     else if ( myConstructorDirId == 3 ) {  // DXDY
813       initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
814       initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
815       initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
816       Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_VX2" ) );
817       Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_VY2" ) );
818       myDX = 0.0;
819       Group3Spin->SpinBox_DX->setValue( myDX );
820       myDY = 0.0;
821       Group3Spin->SpinBox_DY->setValue( myDY );
822       Group3Spin->show();
823       Group3Spin->buttonApply->setFocus();
824
825       if ( constructorId == 2 ) {  // Length
826         mySketchType = DIR_DXDY_LENGTH;
827         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
828         Group3Spin->SpinBox_DZ->setValue( myLength );
829       }
830       else if ( constructorId == 0 ) { // X
831         mySketchType = DIR_DXDY_X;
832         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_X3" ) );
833         Group3Spin->SpinBox_DZ->setValue( myX );
834       }
835       else if ( constructorId == 1 ) {  // Y
836         mySketchType = DIR_DXDY_Y;
837         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_Y3" ) );
838         Group3Spin->SpinBox_DZ->setValue( myY );
839       }
840     }
841   }
842   else if ( myConstructorId == 1 ) {  // ARC
843     if ( myConstructorDirId == 2 ) {  // Angle
844       if ( constructorId == 2 ) {  // Length
845         mySketchType = DIR_ANGLE_LENGTH;
846         initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 5., "angle_precision" );
847         initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
848         initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, 5., "angle_precision" );
849         Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
850         Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
851         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_ANGLE2" ));
852         Group3Spin->SpinBox_DX->setValue( myAngle );
853         myRadius = 100.0;
854         Group3Spin->SpinBox_DY->setValue( myRadius );
855         myLength = 30.0;
856         Group3Spin->SpinBox_DZ->setValue( myLength );
857         Group3Spin->show();
858         Group3Spin->buttonApply->setFocus();
859       }
860     }
861     else if ( myConstructorDirId == 0 ) {  // Perpendicular
862       if ( constructorId == 2 ) {  // Length
863         mySketchType = DIR_PER_LENGTH;
864         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
865         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 5., "angle_precision" );
866         Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
867         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
868         myRadius = 100.0;
869         Group2Spin->SpinBox_DX->setValue( myRadius );
870         myLength = 30.0;
871         Group2Spin->SpinBox_DY->setValue( myLength );
872         Group2Spin->show();
873         Group2Spin->buttonApply->setFocus();
874       }
875     }
876     else if ( myConstructorDirId == 1 ) {  // Tangent
877       if ( constructorId == 2 ) {  // Length
878         mySketchType = DIR_TAN_LENGTH;
879         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
880         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 5., "angle_precision" );
881         Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
882         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
883         myRadius = 100.0;
884         Group2Spin->SpinBox_DX->setValue( myRadius );
885         myLength = 30.0;
886         Group2Spin->SpinBox_DY->setValue( myLength );
887         Group2Spin->show();
888         Group2Spin->buttonApply->setFocus();
889       }
890     }
891     else if ( myConstructorDirId == 3 ) {  // DXDY
892       if ( constructorId == 2 ) {  // Length
893         mySketchType = DIR_DXDY_LENGTH;
894         Group4Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_VX2" ) );
895         Group4Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_VY2" ) );
896         Group4Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
897         Group4Spin->TextLabel4->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
898         initSpinBox( Group4Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
899         initSpinBox( Group4Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
900         initSpinBox( Group4Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
901         initSpinBox( Group4Spin->SpinBox_DS, COORD_MIN, COORD_MAX, 5., "length_precision" );
902         myDX = 0.0;
903         Group4Spin->SpinBox_DX->setValue( myDX );
904         myDY = 0.0;
905         Group4Spin->SpinBox_DY->setValue( myDY );
906         myRadius = 100.0;
907         Group4Spin->SpinBox_DZ->setValue( myRadius );
908         myLength = 30.0;
909         Group4Spin->SpinBox_DS->setValue( myLength );
910         Group4Spin->show();
911         Group4Spin->buttonApply->setFocus();
912       }
913     }
914   }
915   resize( minimumSizeHint() );
916   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
917 }
918
919 //=================================================================================
920 // function : CheckBoxClicked()
921 // purpose  : CheckBox  management
922 //=================================================================================
923 void EntityGUI_SketcherDlg::CheckBoxClicked(int State)
924 {
925   myCheckFlag = State;
926
927   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
928 }
929
930
931 //=================================================================================
932 // function : ClickOnCancel()
933 // purpose  :
934 //=================================================================================
935 void EntityGUI_SketcherDlg::ClickOnCancel()
936 {
937   close();
938 }
939
940
941 //=================================================================================
942 // function : ClickOnEnd()
943 // purpose  : connected to buttonEnd AND buttonClose
944 //=================================================================================
945 void EntityGUI_SketcherDlg::ClickOnEnd()
946 {
947   if ( sender() == MainWidget->buttonClose ) {
948     // Verify validity of commands
949     if ( myCommand.count() <= 2 ) {
950       SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
951                                  tr( "GEOM_ERROR_STATUS" ), tr( "CANNOT_CLOSE" ), tr( "BUT_OK" ) );
952       return;
953     }
954
955     QString Parameters;
956     QString Command = myCommand.join( "" ) + GetNewCommand( Parameters );
957     Sketcher_Profile aProfile( Command.toAscii() );
958
959     Command = myCommand.join( "" );
960     aProfile = Sketcher_Profile( Command.toAscii() );
961     TopoDS_Shape myShape;
962     if ( aProfile.IsDone() )
963       myShape = aProfile.GetShape();
964
965     if ( myShape.ShapeType() != TopAbs_VERTEX )
966       myCommand.append( ":WW" );
967   }
968   else {
969     // PAL16008 (Sketcher Validation should be equal to Apply&Close)
970     if ( ( Group1Spin->buttonApply->isEnabled() && Group1Spin->isVisible() ) ||
971          ( Group2Spin->buttonApply->isEnabled() && Group2Spin->isVisible() ) ||
972          ( Group3Spin->buttonApply->isEnabled() && Group3Spin->isVisible() ) ||
973          ( Group4Spin->buttonApply->isEnabled() && Group4Spin->isVisible() ) ||
974          ( Group1Sel->buttonApply->isEnabled()  && Group1Sel->isVisible()  ) ||
975          ( Group2Sel->buttonApply->isEnabled()  && Group2Sel->isVisible()  ) ||
976          ( Group1Sel1Spin->buttonApply->isEnabled() && Group1Sel1Spin->isVisible() ) )  {     
977       ClickOnApply();
978     }
979     myIsAllAdded = true;
980   }
981
982   if ( myCommand.size() > 2 )
983     if ( !onAccept() )
984       return;
985
986   close();
987 }
988
989 //=================================================================================
990 // function : ClickOnApply()
991 // purpose  :
992 //=================================================================================
993 bool EntityGUI_SketcherDlg::ClickOnApply()
994 {
995   if ( sender() && sender()->inherits( "QPushButton" ) )
996     ( (QPushButton*)sender() )->setFocus(); // to update value of currently edited spin-box (PAL11948)
997
998   QString aParameters;
999   myCommand.append( GetNewCommand( aParameters ) );
1000   mySketchState = NEXT_POINT;
1001
1002   myUndoCommand.clear();
1003   myUndoCommand.append( "Sketcher" );
1004
1005   myParameters.append( aParameters );
1006   myUndoParameters.clear();
1007
1008   MainWidget->GroupConstructors->setEnabled( true );
1009   MainWidget->GroupDest1->setEnabled( true );
1010   setEnabledUndo( true );
1011   setEnabledRedo( false );
1012
1013   myIsApply = true;
1014   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
1015   myIsApply = false;
1016
1017   // Set focus to SpinBox_DX
1018   if ( sender() == Group1Spin->buttonApply ) {
1019     (Group1Spin->SpinBox_DX)->setFocus();
1020     (Group1Spin->SpinBox_DX)->selectAll();
1021   }
1022   else if ( sender() == Group1Sel1Spin->buttonApply ) {
1023     (Group1Sel1Spin->SpinBox_DX)->setFocus();
1024     (Group1Sel1Spin->SpinBox_DX)->selectAll();
1025   }
1026   else if ( sender() == Group2Spin->buttonApply ) {
1027     (Group2Spin->SpinBox_DX)->setFocus();
1028     (Group2Spin->SpinBox_DX)->selectAll();
1029   }
1030   else if ( sender() == Group3Spin->buttonApply ) {
1031     (Group3Spin->SpinBox_DX)->setFocus();
1032     (Group3Spin->SpinBox_DX)->selectAll();
1033   }
1034   else if ( sender() == Group4Spin->buttonApply ) {
1035     (Group4Spin->SpinBox_DX)->setFocus();
1036     (Group4Spin->SpinBox_DX)->selectAll();
1037   }
1038
1039   return true;
1040 }
1041
1042 //=================================================================================
1043 // function : ClickOnHelp()
1044 // purpose  :
1045 //=================================================================================
1046 void EntityGUI_SketcherDlg::ClickOnHelp()
1047 {
1048   LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
1049   if ( app )
1050     app->onHelpContextModule( myGeometryGUI ? app->moduleName( myGeometryGUI->moduleName() ) : QString( "" ), myHelpFileName );
1051   else {
1052     QString platform;
1053 #ifdef WIN32
1054     platform = "winapplication";
1055 #else
1056     platform = "application";
1057 #endif
1058
1059     SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
1060                               QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
1061                               arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
1062                               QObject::tr( "BUT_OK" ) );
1063   }
1064 }
1065
1066 //=================================================================================
1067 // function : ClickOnUndo()
1068 // purpose  :
1069 //=================================================================================
1070 void EntityGUI_SketcherDlg::ClickOnUndo()
1071 {
1072   myUndoCommand.append( myCommand.last() );
1073   myCommand.pop_back();
1074
1075   myUndoParameters.append( myParameters.last() );
1076   myParameters.pop_back();
1077
1078   if ( myCommand.count() == 1 ) {
1079     mySketchState = FIRST_POINT;
1080
1081     MainWidget->RadioButton1->setChecked( true );
1082     TypeClicked( 0 );
1083
1084     connect( myGeometryGUI->getApp()->selectionMgr(),
1085              SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
1086
1087     MainWidget->GroupConstructors->setEnabled( false );
1088     MainWidget->GroupDest1->setEnabled( false );
1089     setEnabledUndo( false );
1090   }
1091
1092   setEnabledRedo( true );
1093
1094   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
1095 }
1096
1097 //=================================================================================
1098 // function : ClickOnRedo()
1099 // purpose  :
1100 //=================================================================================
1101 void EntityGUI_SketcherDlg::ClickOnRedo()
1102 {
1103   myCommand.append( myUndoCommand.last() );
1104   myUndoCommand.pop_back();
1105
1106   myParameters.append( myUndoParameters.last() );
1107   myUndoParameters.pop_back();
1108
1109   mySketchState = NEXT_POINT;
1110
1111   MainWidget->GroupConstructors->setEnabled( true );
1112   MainWidget->GroupDest1->setEnabled( true );
1113   setEnabledUndo( true );
1114
1115   if ( myUndoCommand.count() == 1 )
1116     setEnabledRedo( false );
1117
1118   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
1119 }
1120
1121 //=================================================================================
1122 // function : setEnabledUndo()
1123 // purpose  :
1124 //=================================================================================
1125 void EntityGUI_SketcherDlg::setEnabledUndo( bool value )
1126 {
1127   Group1Sel->buttonUndo->setEnabled( value );
1128   Group2Sel->buttonUndo->setEnabled( value );
1129   Group1Sel1Spin->buttonUndo->setEnabled( value );
1130   Group1Spin->buttonUndo->setEnabled( value );
1131   Group2Spin->buttonUndo->setEnabled( value );
1132   Group3Spin->buttonUndo->setEnabled( value );
1133   Group4Spin->buttonUndo->setEnabled( value );
1134 }
1135
1136 //=================================================================================
1137 // function : setEnabledRedo()
1138 // purpose  :
1139 //=================================================================================
1140 void EntityGUI_SketcherDlg::setEnabledRedo( bool value )
1141 {
1142   Group1Sel->buttonRedo->setEnabled( value );
1143   Group2Sel->buttonRedo->setEnabled( value );
1144   Group1Sel1Spin->buttonRedo->setEnabled( value );
1145   Group1Spin->buttonRedo->setEnabled( value );
1146   Group2Spin->buttonRedo->setEnabled( value );
1147   Group3Spin->buttonRedo->setEnabled( value );
1148   Group4Spin->buttonRedo->setEnabled( value );
1149 }
1150
1151 //=================================================================================
1152 // function : SelectionIntoArgument()
1153 // purpose  : Called when selection as changed
1154 //=================================================================================
1155 void EntityGUI_SketcherDlg::SelectionIntoArgument()
1156 {
1157   MESSAGE("EntityGUI_SketcherDlg::SelectionIntoArgument")
1158   myEditCurrentArgument->setText( "" );
1159   double tmpX = myX;
1160   double tmpY = myY;
1161   myX = myLastX1;
1162   myY = myLastY1;
1163   //  printf ("\nmyX = %f         myY = %f", myX, myY);
1164   //  printf ("\nmyLastX1 = %f    myLastY1 = %f", myLastX1, myLastY1);
1165   //  printf ("\nmyLastX2 = %f    myLastY2 = %f", myLastX2, myLastY2);
1166
1167   if ( sender() == ComboBox1 )
1168       ActivateLocalCS();
1169
1170   LightApp_SelectionMgr* aSelMgr = myGeometryGUI->getApp()->selectionMgr();
1171   SALOME_ListIO aSelList;
1172   aSelMgr->selectedObjects(aSelList);
1173
1174   int nbSel = aSelList.Extent();
1175   MESSAGE("NbSel = "<<nbSel)
1176   if (nbSel == 0){
1177     myX=tmpX;
1178     myY=tmpY;
1179   }
1180   if (nbSel == 1 && myEditCurrentArgument == Group1Sel->LineEdit1) {
1181     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
1182     if ( !CORBA::is_nil(aSelectedObject) ) {
1183       TopoDS_Shape aShape;
1184       if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_VERTEX)) {
1185         gp_Trsf aTrans;
1186         gp_Ax3 aWPlane = GetActiveLocalCS();
1187
1188         aTrans.SetTransformation(aWPlane);
1189         BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
1190         aShape = aTransformation.Shape();
1191
1192         gp_Pnt aPnt;
1193         if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) {
1194           myX = aPnt.X();
1195           myY = aPnt.Y();
1196           Group1Sel->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
1197           if( Group2Spin->isVisible() && mySketchType == PT_ABS ) {
1198             disconnect( Group2Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1199             disconnect( Group2Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1200             Group2Spin->SpinBox_DX->setValue(myX);
1201             Group2Spin->SpinBox_DY->setValue(myY);
1202             connect( Group2Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1203             connect( Group2Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1204           } else if ( Group2Spin->isVisible() && mySketchType == PT_RELATIVE ) {
1205             if ( myLastX1 && myLastY1 ) {
1206               Group2Spin->SpinBox_DX->setValue(myX - myLastX1);
1207               Group2Spin->SpinBox_DY->setValue(myY - myLastY1);
1208             } else {
1209               if ( mySketchState != FIRST_POINT ) {
1210                 Group2Spin->SpinBox_DX->setValue(myX - tmpX);
1211                 Group2Spin->SpinBox_DY->setValue(myY - tmpY);
1212               } else {
1213                 Group2Spin->SpinBox_DX->setValue(myX);
1214                 Group2Spin->SpinBox_DY->setValue(myY);
1215               }
1216             }
1217           }
1218         }
1219       }
1220     }
1221   }
1222
1223   if (nbSel == 1 && myEditCurrentArgument == Group1Sel1Spin->LineEdit1) {
1224     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
1225     if ( !CORBA::is_nil(aSelectedObject) ) {
1226       TopoDS_Shape aShape;
1227       if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_VERTEX)) {
1228         gp_Trsf aTrans;
1229         gp_Ax3 aWPlane = GetActiveLocalCS();
1230
1231         aTrans.SetTransformation(aWPlane);
1232         BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
1233         aShape = aTransformation.Shape();
1234
1235         gp_Pnt aPnt;
1236         if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) {
1237           myX = aPnt.X();
1238           myY = aPnt.Y();
1239           Group1Sel1Spin->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
1240           if( Group3Spin->isVisible() && mySketchType == PT_ABS ) {
1241             disconnect( Group3Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1242             disconnect( Group3Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1243             Group3Spin->SpinBox_DX->setValue(myX);
1244             Group3Spin->SpinBox_DY->setValue(myY);
1245             connect( Group3Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1246             connect( Group3Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1247           } else if ( Group3Spin->isVisible() && mySketchType == PT_RELATIVE ) {
1248             if ( myLastX1 && myLastY1 ) {
1249               Group3Spin->SpinBox_DX->setValue(myX - myLastX1);
1250               Group3Spin->SpinBox_DY->setValue(myY - myLastY1);
1251             } else {
1252               if ( mySketchState != FIRST_POINT ) {
1253                 Group3Spin->SpinBox_DX->setValue(myX - tmpX);
1254                 Group3Spin->SpinBox_DY->setValue(myY - tmpY);
1255               } else {
1256                 Group3Spin->SpinBox_DX->setValue(myX);
1257                 Group3Spin->SpinBox_DY->setValue(myY);
1258               }
1259             }
1260           }
1261         }
1262       }
1263     }
1264   }
1265
1266   if (nbSel == 1 && myEditCurrentArgument == Group2Sel->LineEdit1) {
1267     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
1268     if ( !CORBA::is_nil(aSelectedObject) ) {
1269       TopoDS_Shape aShape;
1270       if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_VERTEX)) {
1271         gp_Trsf aTrans;
1272         gp_Ax3 aWPlane = GetActiveLocalCS();
1273
1274         aTrans.SetTransformation(aWPlane);
1275         BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
1276         aShape = aTransformation.Shape();
1277
1278         gp_Pnt aPnt;
1279         if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) {
1280           myXc = aPnt.X();
1281           myYc = aPnt.Y();
1282           Group2Sel->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
1283           if( Group4Spin->isVisible() && mySketchType == PT_ABS ) {
1284             disconnect( Group4Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1285             disconnect( Group4Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1286             Group4Spin->SpinBox_DX->setValue(myXc);
1287             Group4Spin->SpinBox_DY->setValue(myYc);
1288             connect( Group4Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1289             connect( Group4Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1290           } else if ( Group4Spin->isVisible() && mySketchType == PT_RELATIVE ) {
1291             if ( myLastX1 && myLastY1 ) {
1292               Group4Spin->SpinBox_DX->setValue(myXc - myLastX1);
1293               Group4Spin->SpinBox_DY->setValue(myYc - myLastY1);
1294             } else {
1295               if ( mySketchState != FIRST_POINT ) {
1296                 Group4Spin->SpinBox_DX->setValue(myXc - tmpX);
1297                 Group4Spin->SpinBox_DY->setValue(myYc - tmpY);
1298               } else {
1299                 Group4Spin->SpinBox_DX->setValue(myXc);
1300                 Group4Spin->SpinBox_DY->setValue(myYc);
1301               }
1302             }
1303           }
1304         }
1305       }
1306     }
1307   }
1308
1309   if (nbSel == 1 && myEditCurrentArgument == Group2Sel->LineEdit2) {
1310     if (!Group2Sel->LineEdit1->text().isEmpty()){    //Check wether or not Linedit2 has been modified
1311       myX=tmpX;                                      // If yes keep the old values of X and Y  
1312       myY=tmpY;
1313     }
1314     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
1315     if ( !CORBA::is_nil(aSelectedObject) ) {
1316       TopoDS_Shape aShape;
1317       if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_VERTEX)) {
1318         gp_Trsf aTrans;
1319         gp_Ax3 aWPlane = GetActiveLocalCS();
1320
1321         aTrans.SetTransformation(aWPlane);
1322         BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
1323         aShape = aTransformation.Shape();
1324
1325         gp_Pnt aPnt;
1326         if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) {
1327           myX = aPnt.X();
1328           myY = aPnt.Y();
1329           Group2Sel->LineEdit2->setText( GEOMBase::GetName( aSelectedObject ) );
1330           if( Group4Spin->isVisible() && mySketchType == PT_ABS ) {
1331             disconnect( Group4Spin->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1332             disconnect( Group4Spin->SpinBox_DS, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1333             Group4Spin->SpinBox_DZ->setValue(myX);
1334             Group4Spin->SpinBox_DS->setValue(myY);
1335             connect( Group4Spin->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1336             connect( Group4Spin->SpinBox_DS, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1337           } else if ( Group4Spin->isVisible() && mySketchType == PT_RELATIVE ) {
1338             if ( myLastX1 && myLastY1 ) {
1339               Group4Spin->SpinBox_DZ->setValue(myX - myLastX1);
1340               Group4Spin->SpinBox_DS->setValue(myY - myLastY1);
1341             } else {
1342               if ( mySketchState != FIRST_POINT ) {
1343                 Group4Spin->SpinBox_DZ->setValue(myX - tmpX);
1344                 Group4Spin->SpinBox_DS->setValue(myY - tmpY);
1345               } else {
1346                 Group4Spin->SpinBox_DZ->setValue(myX);
1347                 Group4Spin->SpinBox_DS->setValue(myY);
1348               }
1349             }
1350           }
1351         }
1352       }
1353     }
1354   }
1355   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
1356 }
1357
1358
1359 //=================================================================================
1360 // function : SetEditCurrentArgument()
1361 // purpose  :
1362 //=================================================================================
1363 void EntityGUI_SketcherDlg::SetEditCurrentArgument()
1364 {
1365   if ( sender() == Group1Sel->PushButton1 ) {
1366     myEditCurrentArgument = Group1Sel->LineEdit1;
1367     myEditCurrentArgument->setFocus();
1368   }
1369   else if ( sender() == Group1Sel1Spin->PushButton1 ) {
1370     myEditCurrentArgument = Group1Sel1Spin->LineEdit1;
1371     myEditCurrentArgument->setFocus();
1372   }
1373   else if ( sender() == Group2Sel->PushButton1 ) {
1374     myEditCurrentArgument = Group2Sel->LineEdit1;
1375     Group2Sel->PushButton2->setDown(false);
1376     Group2Sel->PushButton1->setDown(true);
1377     Group2Sel->LineEdit2->setEnabled(false);
1378     Group2Sel->LineEdit1->setEnabled(true);
1379    // myEditCurrentArgument->setFocus();
1380   }
1381    else if ( sender() == Group2Sel->PushButton2 ) {
1382     myEditCurrentArgument = Group2Sel->LineEdit2;
1383     Group2Sel->PushButton1->setDown(false);
1384     Group2Sel->PushButton2->setDown(true);
1385     Group2Sel->LineEdit1->setEnabled(false);
1386     Group2Sel->LineEdit2->setEnabled(true);
1387    // myEditCurrentArgument->setFocus();
1388   }
1389   SelectionIntoArgument();
1390 }
1391
1392
1393 //=================================================================================
1394 // function : LineEditReturnPressed()
1395 // purpose  :
1396 //=================================================================================
1397 void EntityGUI_SketcherDlg::LineEditReturnPressed()
1398 {
1399   if ( sender() == Group1Sel->LineEdit1 ) 
1400     myEditCurrentArgument = Group1Sel->LineEdit1;
1401   else if ( sender() == Group1Sel1Spin->LineEdit1 ) 
1402      myEditCurrentArgument = Group1Sel1Spin->LineEdit1;
1403   else if ( sender() == Group2Sel->LineEdit1 ) 
1404      myEditCurrentArgument = Group2Sel->LineEdit1;
1405   else if ( sender() == Group2Sel->LineEdit2 )
1406      myEditCurrentArgument = Group2Sel->LineEdit2;
1407
1408   /* User name of object input management                          */
1409   /* If successfull the selection is changed and signal emitted... */
1410   /* so SelectionIntoArgument() is automatically called.           */
1411   const QString objectUserName = myEditCurrentArgument->text();
1412   QWidget* thisWidget = (QWidget*)this;
1413
1414   LightApp_SelectionMgr* aSelMgr = myGeometryGUI->getApp()->selectionMgr();
1415   SALOME_ListIO aSelList;
1416   aSelMgr->selectedObjects(aSelList);
1417
1418   if (GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, aSelList))
1419     myEditCurrentArgument->setText( objectUserName );
1420 }
1421
1422
1423 //=================================================================================
1424 // function : DeactivateActiveDialog()
1425 // purpose  :
1426 //=================================================================================
1427 void EntityGUI_SketcherDlg::DeactivateActiveDialog()
1428 {
1429   //myGeometryGUI->SetState( -1 );
1430
1431   setEnabled( false );
1432   globalSelection();
1433   disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
1434   myGeometryGUI->SetActiveDialogBox( 0 );
1435 }
1436
1437
1438 //=================================================================================
1439 // function : ActivateThisDialog()
1440 // purpose  :
1441 //=================================================================================
1442 void EntityGUI_SketcherDlg::ActivateThisDialog()
1443 {
1444   myGeometryGUI->EmitSignalDeactivateDialog();
1445   setEnabled( true );
1446   myGeometryGUI->SetActiveDialogBox( this );
1447
1448   connect( myGeometryGUI->getApp()->selectionMgr(),
1449           SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
1450
1451   //myGeometryGUI->SetState( 0 );
1452   globalSelection( GEOM_POINT );
1453   
1454   myEditCurrentArgument = Group1Sel->LineEdit1;
1455   myEditCurrentArgument->setFocus();
1456   
1457    if ( sender() == Group1Sel->LineEdit1 ) {
1458      myEditCurrentArgument = Group1Sel->LineEdit1;
1459      myEditCurrentArgument->setFocus();
1460    }
1461    else if ( sender() == Group1Sel1Spin->LineEdit1 ) {
1462      myEditCurrentArgument = Group1Sel1Spin->LineEdit1;
1463      myEditCurrentArgument->setFocus();
1464    }
1465    else if ( sender() == Group2Sel->LineEdit1 ) {
1466      myEditCurrentArgument = Group2Sel->LineEdit1;
1467      myEditCurrentArgument->setFocus();
1468    }
1469     else if ( sender() == Group2Sel->LineEdit2 ) {
1470      myEditCurrentArgument = Group2Sel->LineEdit2;
1471      myEditCurrentArgument->setFocus();
1472    }
1473    
1474   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
1475 }
1476
1477
1478 //=================================================================================
1479 // function : enterEvent [REDEFINED]
1480 // purpose  :
1481 //=================================================================================
1482 void EntityGUI_SketcherDlg::enterEvent( QEvent* )
1483 {
1484   if ( !isEnabled() )
1485     ActivateThisDialog();
1486 }
1487
1488
1489 //=================================================================================
1490 // function : closeEvent()
1491 // purpose  :
1492 //=================================================================================
1493 void EntityGUI_SketcherDlg::closeEvent( QCloseEvent* e )
1494 {
1495   MESSAGE("EntityGUI_SketcherDlg::closeEvent")
1496   //myGeometryGUI->SetState( -1 );
1497   disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
1498   myGeometryGUI->getApp()->updateActions();
1499   QDialog::closeEvent( e );
1500 }
1501
1502 //=================================================================================
1503 // function : OnPointSelected
1504 // purpose  :
1505 //=================================================================================
1506 void EntityGUI_SketcherDlg::OnPointSelected(Qt::KeyboardModifiers modifiers, const gp_Pnt& thePnt)
1507 {
1508   MESSAGE("EntityGUI_SketcherDlg::OnPointSelected")
1509   switch (getPnt2ConstructorId()){
1510     case 1:
1511       Group2Spin->SpinBox_DX->setValue( thePnt.X() );
1512       Group2Spin->SpinBox_DY->setValue( thePnt.Y() );
1513       break;
1514     case 0:
1515       Group3Spin->SpinBox_DX->setValue( thePnt.X() );
1516       Group3Spin->SpinBox_DY->setValue( thePnt.Y() );
1517       break;
1518     case 2:
1519       if (modifiers == Qt::MetaModifier){                // Select center with Meta key
1520         Group4Spin->SpinBox_DX->setValue( thePnt.X() );
1521         Group4Spin->SpinBox_DY->setValue( thePnt.Y() );
1522       }
1523       else{                                              // The select end point
1524         Group4Spin->SpinBox_DZ->setValue( thePnt.X() );
1525         Group4Spin->SpinBox_DS->setValue( thePnt.Y() );
1526       }
1527       break;
1528   }
1529 }
1530
1531 //=================================================================================
1532 // function : ValueChangedInSpinBox()
1533 // purpose  :
1534 //=================================================================================
1535 void EntityGUI_SketcherDlg::ValueChangedInSpinBox( double newValue )
1536 {
1537   MESSAGE("EntityGUI_SketcherDlg::ValueChangedInSpinBox")
1538   QObject* send = (QObject*)sender();
1539   Standard_Real vx, vy, vz, vs, minRad, dx, dy;
1540   vx = vy = vz = vs = minRad = dx = dy = 0.0;
1541
1542   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1543   int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
1544   double LastDecimal = 0.0;
1545
1546   QString vxStr, vyStr, vzStr, vsStr;
1547
1548   QString newValueStr;
1549   if( SalomeApp_DoubleSpinBox* aDoubleSpinBox = (SalomeApp_DoubleSpinBox*)send )
1550     newValueStr = aDoubleSpinBox->text();
1551
1552   if ( send == Group1Spin->SpinBox_DX ) {
1553     vx = newValue;                        vxStr = newValueStr;
1554   }
1555   else if ( send == Group1Sel1Spin->SpinBox_DX ) {
1556     vx = newValue;                        vxStr = newValueStr;
1557   }
1558   else if ( send == Group2Spin->SpinBox_DX ) {
1559     vx = newValue;                        vxStr = newValueStr;
1560     vy = Group2Spin->SpinBox_DY->value(); vyStr = Group2Spin->SpinBox_DY->text();
1561   }
1562   else if ( send == Group2Spin->SpinBox_DY ) {
1563     vx = Group2Spin->SpinBox_DX->value(); vxStr = Group2Spin->SpinBox_DX->text();
1564     vy = newValue;                        vyStr = newValueStr;
1565   }
1566   else if ( send == Group3Spin->SpinBox_DX ) {
1567     vx = newValue;                        vxStr = newValueStr;
1568     vy = Group3Spin->SpinBox_DY->value(); vyStr = Group3Spin->SpinBox_DY->text();
1569     vz = Group3Spin->SpinBox_DZ->value();
1570     if ( (mySketchType == PT_REL_RADIUS || mySketchType == PT_ABS_RADIUS) && (vx != 0 || vy != 0) ) {  
1571       if (mySketchType == PT_ABS_RADIUS){
1572         dx = vx - myLastX1;
1573         dy = vy - myLastY1;
1574       }
1575       else{
1576         dx = vx;
1577         dy = vy;
1578       }
1579       minRad = 0.5 * Sqrt(dx * dx + dy * dy);                             //Computation of the minimum acceptable radius for the arc calculation
1580       if (aPrecision >= 0)    // 'f' format in the QString             
1581         LastDecimal = aPrecision;
1582       else                    // 'g' format in the Qstring
1583         LastDecimal = qAbs( aPrecision ) - ceil( log10(minRad) ); 
1584       minRad = ceil(pow(10,LastDecimal) * minRad) / pow(10,LastDecimal);  // Rounded up at the last allowed decimal place
1585       if ( Abs(vz) < minRad){
1586         if (vz < 0.0)
1587           Group3Spin->SpinBox_DZ->setValue( - minRad );
1588         else 
1589           Group3Spin->SpinBox_DZ->setValue( minRad );
1590       }
1591     }
1592     vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
1593   }
1594   else if ( send == Group3Spin->SpinBox_DY ) {
1595     vx = Group3Spin->SpinBox_DX->value(); vxStr = Group3Spin->SpinBox_DX->text();
1596     vy = newValue;                        vyStr = newValueStr;
1597     vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
1598     if ( (mySketchType == PT_REL_RADIUS || mySketchType == PT_ABS_RADIUS) && (vx != 0 || vy != 0)){
1599       if (mySketchType == PT_ABS_RADIUS){
1600         dx = vx - myLastX1;
1601         dy = vy - myLastY1;
1602       }
1603       else{
1604         dx = vx;
1605         dy = vy;
1606       }    
1607       minRad = 0.5 * Sqrt(dx * dx + dy * dy);                            //Computation of the minimum acceptable radius for the arc calculation
1608       if (aPrecision >= 0)    // 'f' format in the QString 
1609         LastDecimal = aPrecision;
1610       else                    // 'g' format in the QString 
1611         LastDecimal = qAbs( aPrecision ) - ceil( log10(minRad) ); 
1612         minRad = ceil(pow(10,LastDecimal) * minRad) / pow(10,LastDecimal); // Rounded up at the last allowed decimal place
1613       if ( Abs(vz) < minRad){
1614         if (vz < 0.0)
1615           Group3Spin->SpinBox_DZ->setValue( - minRad );
1616         else 
1617           Group3Spin->SpinBox_DZ->setValue( minRad );
1618       }
1619     }
1620     vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
1621   }
1622   else if ( send == Group3Spin->SpinBox_DZ ) {
1623     vx = Group3Spin->SpinBox_DX->value(); vxStr = Group3Spin->SpinBox_DX->text();
1624     vy = Group3Spin->SpinBox_DY->value(); vyStr = Group3Spin->SpinBox_DY->text();
1625     vz = newValue;                        vzStr = newValueStr;
1626   }
1627   else if ( send == Group4Spin->SpinBox_DX ) {
1628     vx = newValue;                        vxStr = newValueStr;
1629     vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1630     vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1631     vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1632   }
1633   else if ( send == Group4Spin->SpinBox_DY ) {
1634     vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1635     vy = newValue;                        vyStr = newValueStr;
1636     vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1637     vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1638   }
1639   else if ( send == Group4Spin->SpinBox_DZ ) {
1640     vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1641     vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1642     vz = newValue;                        vzStr = newValueStr;
1643     vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1644   }
1645   else if ( send == Group4Spin->SpinBox_DS ) {
1646     vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1647     vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1648     vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1649     vs = newValue;                        vsStr = newValueStr;
1650   }
1651   // Fix of the NPAL16010 bug is removed, because it's not actual with the Qt-4.x
1652
1653   if ( myConstructorId == 0 ) {  // SEGMENT
1654     if ( mySketchType == PT_ABS ) {
1655       myX = vx;
1656       myY = vy;
1657       myXStr = vxStr;
1658       myYStr = vyStr;
1659     }
1660     else if ( mySketchType == PT_RELATIVE ) {
1661       myDX = vx;
1662       myDY = vy;
1663       myDXStr = vxStr;
1664       myDYStr = vyStr;
1665     }
1666     else if ( mySketchType == DIR_ANGLE_LENGTH ) {
1667       myAngle = vx;
1668       myLength = vy;
1669       myAngleStr = vxStr;
1670       myLengthStr = vyStr;
1671     }
1672     else if ( mySketchType == DIR_ANGLE_X ) {
1673       myAngle = vx;
1674       myX = vy;
1675       myAngleStr = vxStr;
1676       myXStr = vyStr;
1677     }
1678     else if ( mySketchType == DIR_ANGLE_Y ) {
1679       myAngle = vx;
1680       myY = vy;
1681       myAngleStr = vxStr;
1682       myYStr = vyStr;
1683     }
1684     else if ( mySketchType == DIR_PER_LENGTH ) {
1685       myLength = vx;
1686       myLengthStr = vxStr;
1687     }
1688     else if ( mySketchType == DIR_PER_X ) {
1689       myX = vx;
1690       myXStr = vxStr;
1691     }
1692     else if ( mySketchType == DIR_PER_Y ) {
1693       myY = vx;
1694       myYStr = vxStr;
1695     }
1696     else if ( mySketchType == DIR_TAN_LENGTH ) {
1697       myLength = vx;
1698       myLengthStr = vxStr;
1699     }
1700     else if ( mySketchType == DIR_TAN_X ) {
1701       myX = vx;
1702       myXStr = vxStr;
1703     }
1704     else if ( mySketchType == DIR_TAN_Y ) {
1705       myY = vx;
1706       myYStr = vxStr;
1707     }
1708     else if ( mySketchType == DIR_DXDY_LENGTH ) {
1709       myDX = vx;
1710       myDY = vy;
1711       myLength = vz;
1712       myDXStr = vxStr;
1713       myDYStr = vyStr;
1714       myLengthStr = vzStr;
1715     }
1716     else if ( mySketchType == DIR_DXDY_X ) {
1717       myDX = vx;
1718       myDY = vy;
1719       myX = vz;
1720       myDXStr = vxStr;
1721       myDYStr = vyStr;
1722       myXStr = vzStr;
1723     }
1724     else if ( mySketchType == DIR_DXDY_Y ) {
1725       myDX = vx;
1726       myDY = vy;
1727       myY = vz;
1728       myDXStr = vxStr;
1729       myDYStr = vyStr;
1730       myYStr = vzStr;
1731     }
1732   }
1733   else if ( myConstructorId == 1 ) {  // ARC
1734     if ( mySketchType == PT_ABS ) {  
1735       myX = vx;
1736       myY = vy;
1737       myXStr = vxStr;
1738       myYStr = vyStr;
1739     }
1740     else if ( mySketchType == PT_RELATIVE ) {
1741       myDX = vx;
1742       myDY = vy;
1743       myDXStr = vxStr;
1744       myDYStr = vyStr;
1745     }
1746     if ( mySketchType == PT_ABS_RADIUS ) {  
1747       myX = vx;
1748       myY = vy;
1749       myRadius=vz;
1750       myXStr = vxStr;
1751       myYStr = vyStr;
1752       myRadiusStr = vzStr;
1753     }
1754     else if ( mySketchType == PT_REL_RADIUS ) {
1755       myDX = vx;
1756       myDY = vy;
1757       myRadius=vz;
1758       myDXStr = vxStr;
1759       myDYStr = vyStr;
1760       myRadiusStr = vzStr;
1761     }
1762     else if ( mySketchType == PT_SEL_RADIUS ) {
1763       myRadius = vx;
1764       myRadiusStr = vxStr;
1765     }
1766     if ( mySketchType == PT_ABS_CENTER ) {  
1767       myXc = vx;
1768       myYc = vy;
1769       myX = vz;
1770       myY = vs;
1771       myXcStr = vxStr;
1772       myYcStr = vyStr;
1773       myXStr = vzStr;
1774       myYStr = vsStr;
1775     }
1776     else if ( mySketchType == PT_REL_CENTER ) {
1777       myDXc = vx;
1778       myDYc = vy;
1779       myDX = vz;
1780       myDY = vs;
1781       myDXcStr = vxStr;
1782       myDYcStr = vyStr;
1783       myDXStr = vzStr;
1784       myDYStr = vsStr;
1785     }
1786     if ( mySketchType == DIR_ANGLE_LENGTH ) {
1787       myAngle = vx;
1788       myRadius = vy;
1789       myLength = vz;
1790       myAngleStr = vxStr;
1791       myRadiusStr = vyStr;
1792       myLengthStr = vzStr;
1793     }
1794     else if ( mySketchType == DIR_PER_LENGTH ) {
1795       myRadius = vx;
1796       myLength = vy;
1797       myRadiusStr = vxStr;
1798       myLengthStr = vyStr;
1799     }
1800     else if ( mySketchType == DIR_TAN_LENGTH ) {
1801       myRadius = vx;
1802       myLength = vy;
1803       myRadiusStr = vxStr;
1804       myLengthStr = vyStr;
1805     }
1806     else if ( mySketchType == DIR_DXDY_LENGTH ) {
1807       myDX = vx;
1808       myDY = vy;
1809       myRadius = vz;
1810       myLength = vs;
1811       myDXStr = vxStr;
1812       myDYStr = vyStr;
1813       myRadiusStr = vzStr;
1814       myLengthStr = vsStr;
1815     }
1816   }
1817
1818   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth ); 
1819 }
1820
1821
1822 //=================================================================================
1823 // function : GetNewCommand()
1824 // purpose  : Build the new command with context
1825 //=================================================================================
1826 QString EntityGUI_SketcherDlg::GetNewCommand( QString& theParameters )
1827 {
1828   theParameters.clear();
1829   QString myNewCommand = ":";
1830   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1831   int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
1832   int DigNum = qAbs(aPrecision);                   // options for the format of numbers in  myNewCommand
1833   char Format = 'f';
1834   if ( aPrecision < 0 )                            // f --> DigNum is the number of digits after the decimal point
1835     Format = 'g';                                  // g --> DigNum is the maximum number of significant digits 
1836
1837   if ( mySketchState == FIRST_POINT ) {
1838     if ( mySketchType == PT_ABS || mySketchType == PT_SEL ) {
1839       myNewCommand = myNewCommand + "F " + QString::number( myX, Format, DigNum) + " " + QString::number( myY, Format, DigNum);
1840       theParameters = myXStr + ":" + myYStr;
1841     }
1842     if ( mySketchType == PT_RELATIVE) {
1843       myNewCommand = myNewCommand + "F " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
1844       theParameters = myDXStr + ":" + myDYStr;
1845     }
1846     return myNewCommand;
1847   }
1848
1849   if ( myConstructorId == 0  ) {  // SEGMENT
1850     if ( mySketchType == PT_ABS || mySketchType == PT_SEL ) {
1851       myNewCommand = myNewCommand + "TT " + QString::number( myX, Format, DigNum) + " " + QString::number( myY, Format, DigNum);
1852       theParameters = myXStr + ":" + myYStr;
1853     }
1854     if ( mySketchType == PT_RELATIVE) {
1855       myNewCommand = myNewCommand + "T " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
1856       theParameters = myDXStr + ":" + myDYStr;
1857     }
1858     if ( mySketchType == DIR_ANGLE_LENGTH ) {
1859       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1860       myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength, Format, DigNum );
1861       theParameters = myAngleStr + ":" + myLengthStr;
1862     }
1863     if ( mySketchType == DIR_ANGLE_X ) {
1864       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1865       myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX, Format, DigNum);
1866       theParameters = myAngleStr + ":" + myXStr;
1867     }
1868     if ( mySketchType == DIR_ANGLE_Y ) {
1869       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1870       myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY, Format, DigNum);
1871       theParameters = myAngleStr + ":" + myYStr;
1872     }
1873     if ( mySketchType == DIR_PER_LENGTH ) {
1874       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1875       myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength, Format, DigNum );
1876       theParameters = QString::number( 90.0 ) + ":" + myLengthStr;
1877     }
1878     if ( mySketchType == DIR_PER_X ) {
1879       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1880       myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX, Format, DigNum);
1881       theParameters = QString::number( 90.0 ) + ":" + myXStr;
1882     }
1883     if ( mySketchType == DIR_PER_Y ) {
1884       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1885       myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY, Format, DigNum);
1886       theParameters = QString::number( 90.0 ) + ":" + myYStr;
1887     }
1888     if ( mySketchType == DIR_TAN_LENGTH ) {
1889       myNewCommand = myNewCommand + "L " + QString::number( myLength, Format, DigNum );
1890       theParameters = myLengthStr;
1891     }
1892     if ( mySketchType == DIR_TAN_X ) {
1893       myNewCommand = myNewCommand + "IX " + QString::number( myX, Format, DigNum);
1894       theParameters = myXStr;
1895     }
1896     if ( mySketchType == DIR_TAN_Y) {
1897       myNewCommand = myNewCommand + "IY " + QString::number(myY, Format, DigNum);
1898       theParameters = myYStr;
1899     }
1900     if ( mySketchType == DIR_DXDY_LENGTH ) {
1901       myNewCommand = myNewCommand + "D " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
1902       myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength, Format, DigNum );
1903       theParameters = myDXStr + ":" + myDYStr + ":" + myLengthStr;
1904     }
1905     if ( mySketchType == DIR_DXDY_X ) {
1906       myNewCommand = myNewCommand + "D " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
1907       myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX, Format, DigNum);
1908       theParameters = myDXStr + ":" + myDYStr + ":" + myXStr;
1909     }
1910     if ( mySketchType == DIR_DXDY_Y ) {
1911       myNewCommand = myNewCommand + "D " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
1912       myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY, Format, DigNum);
1913       theParameters = myDXStr + ":" + myDYStr + ":" + myYStr;
1914     }
1915   }
1916   else if ( myConstructorId == 1 ) {  // ARC
1917     if ( mySketchType == PT_ABS || mySketchType == PT_SEL ) {
1918       myNewCommand = myNewCommand + "AA " + QString::number( myX, Format, DigNum) + " " + QString::number( myY, Format, DigNum);
1919       theParameters = myXStr + ":" + myYStr;
1920     }
1921     if ( mySketchType == PT_RELATIVE) {
1922       myNewCommand = myNewCommand + "A " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
1923       theParameters = myDXStr + ":" + myDYStr;
1924     }
1925     if ( mySketchType == PT_ABS_RADIUS || mySketchType == PT_SEL_RADIUS ) {
1926       myNewCommand = myNewCommand + "UU " + QString::number( myX, Format, DigNum) + " " + QString::number( myY, Format, DigNum ) + " " + QString::number( myRadius , Format,  DigNum)+ " " + QString::number( myCheckFlag );
1927       theParameters = myXStr + ":" + myYStr + ":" + myRadiusStr; 
1928     }
1929     if ( mySketchType == PT_REL_RADIUS) {
1930       myNewCommand = myNewCommand + "U " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum ) + " " + QString::number( myRadius, Format, DigNum )+ " " + QString::number( myCheckFlag );
1931       theParameters = myDXStr + ":" + myDYStr + ":" + myRadiusStr;  
1932     }
1933     if ( mySketchType == PT_ABS_CENTER || mySketchType == PT_SEL_CENTER ) {
1934       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 );
1935       theParameters = myXStr + ":" + myYStr + ":" + myXcStr+ ":" + myYcStr; 
1936     }
1937     if ( mySketchType == PT_REL_CENTER) {
1938       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 );
1939       theParameters = myDXStr + ":" + myDYStr + ":" +  myDXcStr + ":" + myDYcStr ;  
1940     }
1941     if ( mySketchType == DIR_ANGLE_LENGTH ) {
1942       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1943       myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius, Format, DigNum ) + " " + QString::number( myLength, Format, DigNum );
1944       theParameters = myAngleStr + ":" + myRadiusStr + ":" + myLengthStr;
1945     }
1946     if ( mySketchType == DIR_PER_LENGTH ) {
1947       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1948       myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius, Format, DigNum ) + " " + QString::number( myLength, Format, DigNum );
1949       theParameters = QString::number( 90.0 ) + ":" + myRadiusStr + ":" + myLengthStr;
1950     }
1951     if ( mySketchType == DIR_TAN_LENGTH ) {
1952       myNewCommand = myNewCommand + "C " + QString::number( myRadius, Format, DigNum ) + " " + QString::number( myLength, Format, DigNum );
1953       theParameters = myRadiusStr + ":" + myLengthStr;
1954     }
1955     if ( mySketchType == DIR_DXDY_LENGTH ) {
1956       myNewCommand = myNewCommand + "D " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
1957       myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius, Format, DigNum ) + " " + QString::number( myLength, Format, DigNum );
1958       theParameters = myDXStr + ":" + myDYStr + ":" + myRadiusStr + ":" + myLengthStr;
1959     }
1960   }
1961   return myNewCommand;
1962 }
1963
1964 //=================================================================================
1965 // function : createOperation
1966 // purpose  :
1967 //=================================================================================
1968 GEOM::GEOM_IOperations_ptr EntityGUI_SketcherDlg::createOperation()
1969 {
1970   return getGeomEngine()->GetICurvesOperations( getStudyId() );
1971 }
1972
1973 //=================================================================================
1974 // function : isValid
1975 // purpose  :
1976 //=================================================================================
1977 bool EntityGUI_SketcherDlg::isValid( QString& msg )
1978 {
1979   bool ok = true;
1980   bool toCorrect = !IsPreview() || myIsApply;
1981
1982   if( Group1Spin->isVisible() ) {
1983     ok = Group1Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1984   }
1985   else if( Group1Sel1Spin->isVisible() ) {
1986     ok = Group1Sel1Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1987   }
1988   else if( Group2Spin->isVisible() ) {
1989     ok = Group2Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1990     ok = Group2Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
1991   }
1992   else if( Group3Spin->isVisible() ) {
1993     ok = Group3Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1994     ok = Group3Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
1995     ok = Group3Spin->SpinBox_DZ->isValid( msg, toCorrect ) && ok;
1996   }
1997   else if( Group4Spin->isVisible() ) {
1998     ok = Group4Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1999     ok = Group4Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
2000     ok = Group4Spin->SpinBox_DZ->isValid( msg, toCorrect ) && ok;
2001     ok = Group4Spin->SpinBox_DS->isValid( msg, toCorrect ) && ok;
2002   }
2003
2004   if( myIsApply && !ok )
2005     showError( msg );
2006
2007   return ok;
2008 }
2009
2010 //=================================================================================
2011 // function : execute
2012 // purpose  :
2013 //=================================================================================
2014 bool EntityGUI_SketcherDlg::execute( ObjectList& objects )
2015 {
2016   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2017   int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
2018   int DigNum = qAbs(aPrecision);                   // options for the format of numbers in  myNewCommand
2019   char Format = 'f';
2020   if ( aPrecision < 0 )                            // f --> DigNum is the number of digits after the decimal point
2021     Format = 'g';                                  // g --> DigNum is the maximum number of significant digits 
2022     
2023   QString aParameters;
2024
2025   if ( mySketchState == FIRST_POINT ) {
2026     myLastX2 = myX;
2027     myLastY2 = myY;
2028   }
2029   else {
2030     //Test if the current point is the same as the last one
2031     TopoDS_Shape myShape1, myShape2;
2032
2033     // Set "C" numeric locale
2034     Kernel_Utils::Localizer loc;
2035
2036     //Last Shape
2037     QString Command1 = myCommand.join( "" );
2038     Sketcher_Profile aProfile1( Command1.toAscii() );
2039     if ( aProfile1.IsDone() )
2040       myShape1 = aProfile1.GetShape();
2041
2042     //Current Shape
2043     QString Command2 = Command1 + GetNewCommand( aParameters );
2044     Sketcher_Profile aProfile2( Command2.toAscii() );
2045
2046     //Error Message
2047     if ( mySketchType == PT_ABS_CENTER || mySketchType == PT_REL_CENTER  ){
2048       if (aProfile2.Error() > Precision::Confusion()){
2049         Group4Spin->label->show();
2050         Group4Spin->label->setText( tr("GEOM_SKETCHER_WARNING") + QString::number( aProfile2.Error(), Format, DigNum));
2051       }
2052       else{
2053         Group4Spin->label->hide();
2054       } 
2055     }
2056     else 
2057       Group4Spin->label->hide();
2058     if ( mySketchType == PT_SEL_CENTER ){
2059       if (aProfile2.Error() > Precision::Confusion()){
2060         Group2Sel->label->show();
2061         Group2Sel->label->setText( tr("GEOM_SKETCHER_WARNING") + QString::number( aProfile2.Error(), Format, DigNum));
2062       }
2063       else{
2064         Group2Sel->label->hide();
2065       } 
2066     }
2067     else 
2068       Group2Sel->label->hide();
2069
2070     if ( aProfile2.IsDone() )
2071       myShape2 = aProfile2.GetShape();
2072
2073     if ( myShape2.IsNull() ) {
2074       //the current point is the same as the last one
2075       myLastX2 = myLastX1;
2076       myLastY2 = myLastY1;
2077     }
2078     else {
2079       TopoDS_Vertex V1, V2;
2080       gp_Pnt pt;
2081       if ( myShape1.ShapeType() == TopAbs_VERTEX ) {
2082         //the last shape is the first point
2083         pt = BRep_Tool::Pnt( TopoDS::Vertex( myShape1 ) );
2084         myLastX1 = pt.X();
2085         myLastY1 = pt.Y();
2086       }
2087       else {
2088         TopExp::Vertices( TopoDS::Wire( myShape1 ), V1, V2 );
2089         pt = BRep_Tool::Pnt( V2 );
2090         myLastX1 = pt.X();
2091         myLastY1 = pt.Y();
2092       }
2093       TopExp::Vertices( TopoDS::Wire( myShape2 ), V1, V2 );
2094       pt = BRep_Tool::Pnt( V2 );
2095       myLastX2 = pt.X();
2096       myLastY2 = pt.Y();
2097     }
2098   }
2099
2100   QString cmd;
2101   if ( ( mySketchState != FIRST_POINT &&
2102          myLastX1 == myLastX2 && myLastY1 == myLastY2 ) || myIsAllAdded ) {
2103     cmd = myCommand.join( "" );
2104     if ( Group1Sel->isVisible() ) {
2105       Group1Sel->buttonApply->setEnabled( false );
2106       //Group1Sel->buttonApply->setFocus();
2107     }
2108     if ( Group2Sel->isVisible() ) {
2109       Group2Sel->buttonApply->setEnabled( false );
2110       //Group2Sel->buttonApply->setFocus();
2111     }
2112     if ( Group1Sel1Spin->isVisible() ) {
2113       Group1Sel1Spin->buttonApply->setEnabled( false );
2114       //Group1Sel1Spin->buttonApply->setFocus();
2115     }
2116     if ( Group1Spin->isVisible() ) {
2117       Group1Spin->buttonApply->setEnabled( false );
2118       //Group1Spin->buttonApply->setFocus();
2119     }
2120     if ( Group2Spin->isVisible() ) {
2121       Group2Spin->buttonApply->setEnabled( false );
2122       //Group2Spin->buttonApply->setFocus();
2123     }
2124     if ( Group3Spin->isVisible() ) {
2125       Group3Spin->buttonApply->setEnabled( false );
2126       //Group3Spin->buttonApply->setFocus();
2127     }
2128     if ( Group4Spin->isVisible() ) {
2129       Group4Spin->buttonApply->setEnabled( false );
2130       //Group4Spin->buttonApply->setFocus();
2131     }
2132   }
2133   else {
2134     cmd = myCommand.join( "" ) + GetNewCommand( aParameters );
2135
2136     if ( Group1Sel->isVisible() ) {
2137       Group1Sel->buttonApply->setEnabled( true );
2138       this->activateWindow();
2139       Group1Sel->buttonApply->setFocus();
2140     }
2141     if ( Group2Sel->isVisible() ) {
2142       Group2Sel->buttonApply->setEnabled( true );
2143       this->activateWindow();
2144       Group2Sel->buttonApply->setFocus();
2145     }
2146     if ( Group1Sel1Spin->isVisible() ) {
2147       Group1Sel1Spin->buttonApply->setEnabled( true );
2148       this->activateWindow();
2149       Group1Sel1Spin->buttonApply->setFocus();
2150     }
2151     if ( Group1Spin->isVisible() ) {
2152       Group1Spin->buttonApply->setEnabled( true );
2153       this->activateWindow();
2154       Group1Spin->buttonApply->setFocus();
2155     }
2156     if ( Group2Spin->isVisible() ) {
2157       Group2Spin->buttonApply->setEnabled( true );
2158       this->activateWindow();
2159       Group2Spin->buttonApply->setFocus();
2160     }
2161     if ( Group3Spin->isVisible() ) {
2162       Group3Spin->buttonApply->setEnabled( true );
2163       this->activateWindow();
2164       Group3Spin->buttonApply->setFocus();
2165     }
2166     if ( Group4Spin->isVisible() ) {
2167       Group4Spin->buttonApply->setEnabled( true );
2168       this->activateWindow();
2169       Group4Spin->buttonApply->setFocus();
2170     }
2171   }
2172
2173   gp_Ax3 myWPlane = GetActiveLocalCS();
2174   GEOM::ListOfDouble_var WPlane = new GEOM::ListOfDouble;
2175   WPlane->length( 9 );
2176   WPlane[0] = myWPlane.Location().X();
2177   WPlane[1] = myWPlane.Location().Y();
2178   WPlane[2] = myWPlane.Location().Z();
2179
2180   WPlane[3] = myWPlane.Direction().X();
2181   WPlane[4] = myWPlane.Direction().Y();
2182   WPlane[5] = myWPlane.Direction().Z();
2183
2184   WPlane[6] = myWPlane.XDirection().X();
2185   WPlane[7] = myWPlane.XDirection().Y();
2186   WPlane[8] = myWPlane.XDirection().Z();
2187
2188   GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow(getOperation());
2189   GEOM::GEOM_Object_var anObj = anOper->MakeSketcher( cmd.toLatin1().constData(), WPlane );
2190
2191   if ( !anObj->_is_nil() )
2192   {
2193     if( !IsPreview() ) {
2194       QStringList aCurrentParameters = myParameters;
2195       aCurrentParameters << aParameters;
2196       anObj->SetParameters(aCurrentParameters.join(":").toLatin1().constData());
2197     }
2198
2199     objects.push_back( anObj._retn() );
2200   }
2201
2202   return true;
2203 }
2204
2205 //================================================================
2206 // Function : displayPreview
2207 // Purpose  : Method for displaying preview of resulting shape
2208 //            Redefined from GEOMBase_Helper.
2209 //================================================================
2210 void EntityGUI_SketcherDlg::displayPreview( GEOM::GEOM_Object_ptr object,
2211                                             const bool            append,
2212                                             const bool            activate,
2213                                             const bool            update,
2214                                             const double          lineWidth,
2215                                             const int             displayMode,
2216                                             const int             color )
2217
2218   // Set color for preview shape
2219   getDisplayer()->SetColor( Quantity_NOC_RED );
2220
2221   // set width of displayed shape
2222   getDisplayer()->SetWidth( (lineWidth == -1)?myLineWidth:lineWidth );
2223
2224   // Disable activation of selection
2225   getDisplayer()->SetToActivate( activate );
2226
2227   // Make a reference to GEOM_Object
2228   CORBA::String_var objStr = myGeometryGUI->getApp()->orb()->object_to_string( object );
2229   getDisplayer()->SetName( objStr.in() );
2230
2231   // Create wire from applayed object
2232   TopoDS_Shape anApplyedWire, aLastSegment;
2233   if ( !createShapes( object, anApplyedWire, aLastSegment ) )
2234     return;
2235
2236   // Build prs
2237   SALOME_Prs* aPrs = getDisplayer()->BuildPrs( anApplyedWire );
2238   if ( aPrs != 0 && !aPrs->IsNull() )
2239     GEOMBase_Helper::displayPreview( aPrs, append, update );
2240
2241   getDisplayer()->SetColor( Quantity_NOC_VIOLET );
2242   aPrs = getDisplayer()->BuildPrs( aLastSegment );
2243   if ( aPrs != 0 && !aPrs->IsNull() )
2244     GEOMBase_Helper::displayPreview( aPrs, append, update );
2245
2246   getDisplayer()->UnsetName();
2247
2248   // Enable activation of displayed objects
2249   getDisplayer()->SetToActivate( true );
2250 }
2251
2252 //================================================================
2253 // Function : createShapes
2254 // Purpose  : Create applyed wire, and last segment from entry object
2255 //================================================================
2256 bool EntityGUI_SketcherDlg::createShapes( GEOM::GEOM_Object_ptr theObject,
2257                                           TopoDS_Shape&         theApplyedWire,
2258                                           TopoDS_Shape&         theLastSegment )
2259 {
2260   TopoDS_Shape aShape;
2261   if (  !GEOMBase::GetShape( theObject, aShape ) ||
2262        ( aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX ) )
2263     return false;
2264
2265   if ( ( Group1Sel->isVisible()  && !Group1Sel->buttonApply->isEnabled() )||
2266        ( Group2Sel->isVisible()  && !Group2Sel->buttonApply->isEnabled() ) ||
2267        ( Group1Sel1Spin->isVisible()  && !Group1Sel1Spin->buttonApply->isEnabled() ) ||
2268        ( Group1Spin->isVisible() && !Group1Spin->buttonApply->isEnabled() ) ||
2269        ( Group2Spin->isVisible() && !Group2Spin->buttonApply->isEnabled() ) ||
2270        ( Group3Spin->isVisible() && !Group3Spin->buttonApply->isEnabled() ) ||
2271        ( Group4Spin->isVisible() && !Group4Spin->buttonApply->isEnabled() ) ) {
2272      theApplyedWire = aShape;
2273      return true;
2274   }
2275
2276   BRepBuilderAPI_MakeWire aBuilder;
2277   TopExp_Explorer anExp( aShape, TopAbs_EDGE );
2278   while ( 1 ) {
2279     TopoDS_Shape anEdge = anExp.Current();
2280     anExp.Next();
2281     if ( anExp.More() ) // i.e. non-last edge
2282       aBuilder.Add( TopoDS::Edge( anEdge ) );
2283     else {
2284       theLastSegment = anEdge;
2285       break;
2286     }
2287   }
2288
2289   if ( aBuilder.IsDone() )
2290     theApplyedWire = aBuilder.Shape();
2291
2292   return true;
2293 }
2294
2295 //=================================================================================
2296 // function : keyPressEvent()
2297 // purpose  :
2298 //=================================================================================
2299 void  EntityGUI_SketcherDlg::keyPressEvent( QKeyEvent* e )
2300 {
2301   QDialog::keyPressEvent( e );
2302   if ( e->isAccepted() )
2303     return;
2304
2305   if ( e->key() == Qt::Key_F1 ) {
2306     e->accept();
2307     ClickOnHelp();
2308   }
2309 }
2310
2311 //=================================================================================
2312 // function : initSpinBox()
2313 // purpose  :
2314 //=================================================================================
2315 void EntityGUI_SketcherDlg::initSpinBox( SalomeApp_DoubleSpinBox* spinBox,
2316                                          double min,  double max,
2317                                          double step, const char* quantity )
2318 {
2319   // The same stuff as in GEOMBase_Skeleton::initSpinBox()!
2320   // TODO: Think how to keep the single piece of code...
2321
2322   // Obtain precision from preferences
2323   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2324   int aPrecision = resMgr->integerValue( "Geometry", quantity, 6 );
2325   
2326   spinBox->setPrecision( aPrecision );
2327   spinBox->setDecimals( qAbs( aPrecision ) ); // it's necessary to set decimals before the range setting,
2328                                               // by default Qt rounds boundaries to 2 decimals at setRange
2329   spinBox->setRange( min, max );
2330   spinBox->setSingleStep( step );
2331   
2332   // Add a hint for the user saying how to tune precision
2333   QString userPropName = QObject::tr( QString( "GEOM_PREF_%1" ).arg( quantity ).toLatin1().constData() );
2334   spinBox->setProperty( "validity_tune_hint", 
2335                         QVariant( QObject::tr( "GEOM_PRECISION_HINT" ).arg( userPropName ) ) );
2336 }
2337
2338 //=================================================================================
2339 // function : SetDoubleSpinBoxStep()
2340 // purpose  : Double spin box management
2341 //=================================================================================
2342 void EntityGUI_SketcherDlg::SetDoubleSpinBoxStep( double step )
2343 {
2344   Group1Spin->SpinBox_DX->setSingleStep(step);
2345   Group1Sel1Spin->SpinBox_DX->setSingleStep(step);
2346   Group2Spin->SpinBox_DX->setSingleStep(step);
2347   Group2Spin->SpinBox_DY->setSingleStep(step);
2348   Group3Spin->SpinBox_DX->setSingleStep(step);
2349   Group3Spin->SpinBox_DY->setSingleStep(step);
2350   Group3Spin->SpinBox_DZ->setSingleStep(step);
2351   Group4Spin->SpinBox_DZ->setSingleStep(step);
2352
2353   // san: Do NOT override the step when a speicifc step value is used
2354   // in some input fields!
2355   //Group4Spin->SpinBox_DX->setSingleStep(step);
2356   //Group4Spin->SpinBox_DY->setSingleStep(step);
2357   //Group4Spin->SpinBox_DS->setSingleStep(step);
2358 }
2359
2360 //=================================================================================
2361 // function : FindLocalCS()
2362 // purpose  : Find All Coordinates systems in study
2363 //=================================================================================
2364 void EntityGUI_SketcherDlg::FindLocalCS()
2365 {
2366   ComboBox1->clear();
2367   myLCSList.clear();
2368   SalomeApp_Application* app =
2369     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2370   if ( !app )
2371     return;
2372
2373   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2374   if ( !appStudy )
2375     return;
2376
2377   _PTR(Study) aStudy = appStudy->studyDS();
2378
2379   //add Global CS
2380   ComboBox1->addItem(tr("GEOM_GCS"));
2381   gp_Pnt aOrigin = gp_Pnt(0, 0, 0);
2382   gp_Dir aDirZ = gp_Dir(0, 0, 1);
2383   gp_Dir aDirX = gp_Dir(1, 0, 0);
2384   gp_Ax3 globalCS = gp_Ax3(aOrigin, aDirZ, aDirX);
2385   myLCSList.push_back(globalCS);
2386
2387   // get GEOM component
2388   CORBA::String_var geomIOR = app->orb()->object_to_string( GeometryGUI::GetGeomGen() );
2389   _PTR(SObject) obj = aStudy->FindObjectIOR( geomIOR.in() );
2390   if (!obj)
2391     return;
2392   _PTR(SComponent) fc = obj->GetFatherComponent();
2393   QString geomComp = fc->GetID().c_str();
2394   _PTR(SObject) comp = aStudy->FindObjectID( geomComp.toLatin1().data() );
2395   if ( !comp )
2396     return;
2397
2398   // browse through all GEOM data tree
2399   _PTR(ChildIterator) it ( aStudy->NewChildIterator( comp ) );
2400   for ( it->InitEx( true ); it->More(); it->Next() ) {
2401     _PTR(SObject) child( it->Value() );
2402     CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( child );
2403     GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
2404     if( CORBA::is_nil( geomObj ) ) 
2405       continue;
2406     if (geomObj->GetType() == GEOM_MARKER) {
2407       ComboBox1->addItem(geomObj->GetName());
2408       TopoDS_Shape aShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), geomObj);
2409       
2410       gp_Ax3 aLCS;
2411       aLCS.Transform(aShape.Location().Transformation());
2412       if (aShape.ShapeType() == TopAbs_FACE) {
2413         Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(aShape));
2414         if (!aGS.IsNull() && aGS->IsKind(STANDARD_TYPE(Geom_Plane))) {
2415           Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast(aGS);
2416           gp_Pln aPln = aGPlane->Pln();
2417           aLCS = aPln.Position();
2418         }
2419       }
2420       myLCSList.push_back(aLCS);
2421     }
2422   }
2423 }
2424
2425 //rnc TODO
2426 //=================================================================================
2427 // function : getPnt1ConstructorId()
2428 // purpose  :
2429 //=================================================================================
2430 int EntityGUI_SketcherDlg::getPnt1ConstructorId() const
2431
2432   int buttonId = GroupPt->ButtonGroup->checkedId(); 
2433   MESSAGE("buttonId = "<<buttonId)
2434   return buttonId;
2435 }
2436
2437 //=================================================================================
2438 // function : getPnt2ConstructorId()
2439 // purpose  :
2440 //=================================================================================
2441 int EntityGUI_SketcherDlg::getPnt2ConstructorId() const
2442
2443   int buttonId = GroupPt2->ButtonGroup->checkedId(); 
2444   MESSAGE("buttonId = "<<buttonId)
2445   return buttonId;
2446 }
2447
2448 //=================================================================================
2449 // function : GetActiveLocalCS()
2450 // purpose  : Get Working plane
2451 //=================================================================================
2452 gp_Ax3 EntityGUI_SketcherDlg::GetActiveLocalCS()
2453 {
2454   int ind = ComboBox1->currentIndex();
2455   if (ind == -1)
2456     return myGeometryGUI->GetWorkingPlane();
2457
2458   gp_Ax3 aLCS = myLCSList.at(ind);
2459
2460   return aLCS;
2461 }
2462
2463 //=================================================================================
2464 // function : ActivateLocalCS()
2465 // purpose  : Activate & Fit Working plane
2466 //=================================================================================
2467 void EntityGUI_SketcherDlg::ActivateLocalCS()
2468 {
2469     myGeometryGUI->SetWorkingPlane( GetActiveLocalCS() );
2470     myGeometryGUI->ActiveWorkingPlane();
2471 }