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