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