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