Salome HOME
Merge from V6_main 01/04/2013
[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 Parameters;
1145     QString Command = myCommand.join( "" ) + GetNewCommand( Parameters );
1146     Sketcher_Profile aProfile( Command.toAscii() );
1147
1148     Command = myCommand.join( "" );
1149     aProfile = Sketcher_Profile( Command.toAscii() );
1150     TopoDS_Shape myShape;
1151     if ( aProfile.IsDone() )
1152       myShape = aProfile.GetShape();
1153
1154     if ( myShape.ShapeType() != TopAbs_VERTEX )
1155       myCommand.append( ":WW" );
1156   }
1157   else {
1158     /*// PAL16008 (Sketcher Validation should be equal to Apply&Close)
1159     if ( ( Group1Spin->buttonApply->isEnabled() && Group1Spin->isVisible() ) ||
1160          ( Group2Spin->buttonApply->isEnabled() && Group2Spin->isVisible() ) ||
1161          ( Group3Spin->buttonApply->isEnabled() && Group3Spin->isVisible() ) ||
1162          ( Group4Spin->buttonApply->isEnabled() && Group4Spin->isVisible() ) ||
1163          ( Group1Sel->buttonApply->isEnabled()  && Group1Sel->isVisible()  ) ||
1164          ( Group2Sel->buttonApply->isEnabled()  && Group2Sel->isVisible()  ) ||
1165          ( Group1Sel1Spin->buttonApply->isEnabled() && Group1Sel1Spin->isVisible() ) )  {     
1166       ClickOnApply();
1167     }*/
1168 //     ClickOnApply(); // TEST remove then
1169     myIsAllAdded = true;
1170   }
1171
1172   if (myConstructorId == 2)
1173   {
1174     QString aParameters;
1175     myCommand.append( GetNewCommand( aParameters ) );
1176     mySketchState = NEXT_POINT;
1177     if ( onAccept() )
1178       ClickOnCancel();
1179   }
1180   if ( myCommand.size() > 2 )
1181   {
1182     if ( !onAccept() )
1183       return;
1184   }
1185
1186   close();
1187 }
1188
1189 //=================================================================================
1190 // function : ClickOnApply()
1191 // purpose  :
1192 //=================================================================================
1193 bool EntityGUI_SketcherDlg::ClickOnApply()
1194 {
1195   MESSAGE("EntityGUI_SketcherDlg::ClickOnApply()")
1196   if ( sender() && sender()->inherits( "QPushButton" ) )
1197     ( (QPushButton*)sender() )->setFocus(); // to update value of currently edited spin-box (PAL11948)
1198
1199 //   addSubshapesToStudy();
1200
1201   QString aParameters;
1202   myCommand.append( GetNewCommand( aParameters ) );
1203   if (mySketchState == FIRST_POINT)
1204   {
1205     mySketchState = NEXT_POINT;
1206     OnNextPoint();
1207   }
1208
1209   myUndoCommand.clear();
1210   myUndoCommand.append( "Sketcher" );
1211
1212   myParameters.append( aParameters );
1213   myUndoParameters.clear();
1214
1215   setEnabledUndo( true );
1216   setEnabledRedo( false );
1217
1218   myIsApply = true;
1219   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
1220   myIsApply = false;
1221
1222   // Set focus to SpinBox_DX
1223   if ( sender() == Group1Spin->buttonApply ) {
1224     (Group1Spin->SpinBox_DX)->setFocus();
1225     (Group1Spin->SpinBox_DX)->selectAll();
1226   }
1227   else if ( sender() == Group1Sel1Spin->buttonApply ) {
1228     (Group1Sel1Spin->SpinBox_DX)->setFocus();
1229     (Group1Sel1Spin->SpinBox_DX)->selectAll();
1230   }
1231   else if ( sender() == Group2Spin->buttonApply ) {
1232     (Group2Spin->SpinBox_DX)->setFocus();
1233     (Group2Spin->SpinBox_DX)->selectAll();
1234   }
1235   else if ( sender() == Group3Spin->buttonApply ) {
1236     (Group3Spin->SpinBox_DX)->setFocus();
1237     (Group3Spin->SpinBox_DX)->selectAll();
1238   }
1239   else if ( sender() == Group4Spin->buttonApply ) {
1240     (Group4Spin->SpinBox_DX)->setFocus();
1241     (Group4Spin->SpinBox_DX)->selectAll();
1242   }
1243   
1244   return true;
1245 }
1246
1247 //=================================================================================
1248 // function : ClickOnHelp()
1249 // purpose  :
1250 //=================================================================================
1251 void EntityGUI_SketcherDlg::ClickOnHelp()
1252 {
1253   LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
1254   if ( app )
1255     app->onHelpContextModule( myGeometryGUI ? app->moduleName( myGeometryGUI->moduleName() ) : QString( "" ), myHelpFileName );
1256   else {
1257     QString platform;
1258 #ifdef WIN32
1259     platform = "winapplication";
1260 #else
1261     platform = "application";
1262 #endif
1263
1264     SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
1265                               QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
1266                               arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
1267                               QObject::tr( "BUT_OK" ) );
1268   }
1269 }
1270
1271 //=================================================================================
1272 // function : ClickOnUndo()
1273 // purpose  :
1274 //=================================================================================
1275 void EntityGUI_SketcherDlg::ClickOnUndo()
1276 {
1277   myUndoCommand.append( myCommand.last() );
1278   myCommand.pop_back();
1279
1280   myUndoParameters.append( myParameters.last() );
1281   myParameters.pop_back();
1282
1283   if ( myCommand.count() == 1 ) {
1284     mySketchState = FIRST_POINT;
1285
1286     MainWidget->RadioButton1->setChecked( true );
1287     TypeClicked( 0 );
1288
1289     connect( myGeometryGUI->getApp()->selectionMgr(),
1290              SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
1291
1292     OnFirstPoint();
1293
1294     setEnabledUndo( false );
1295   }
1296
1297   setEnabledRedo( true );
1298
1299   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
1300 }
1301
1302 //=================================================================================
1303 // function : ClickOnRedo()
1304 // purpose  :
1305 //=================================================================================
1306 void EntityGUI_SketcherDlg::ClickOnRedo()
1307 {
1308   myCommand.append( myUndoCommand.last() );
1309   myUndoCommand.pop_back();
1310
1311   myParameters.append( myUndoParameters.last() );
1312   myUndoParameters.pop_back();
1313
1314   mySketchState = NEXT_POINT;
1315   
1316   OnNextPoint();
1317   
1318   setEnabledUndo( true );
1319
1320   if ( myUndoCommand.count() == 1 )
1321     setEnabledRedo( false );
1322
1323   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
1324 }
1325
1326 //=================================================================================
1327 // function : setEnabledUndo()
1328 // purpose  :
1329 //=================================================================================
1330 void EntityGUI_SketcherDlg::setEnabledUndo( bool value )
1331 {
1332   Group1Sel->buttonUndo->setEnabled( value );
1333   Group2Sel->buttonUndo->setEnabled( value );
1334   Group1Sel1Spin->buttonUndo->setEnabled( value );
1335   Group1Spin->buttonUndo->setEnabled( value );
1336   Group2Spin->buttonUndo->setEnabled( value );
1337   Group3Spin->buttonUndo->setEnabled( value );
1338   Group4Spin->buttonUndo->setEnabled( value );
1339 }
1340
1341 //=================================================================================
1342 // function : setEnabledRedo()
1343 // purpose  :
1344 //=================================================================================
1345 void EntityGUI_SketcherDlg::setEnabledRedo( bool value )
1346 {
1347   Group1Sel->buttonRedo->setEnabled( value );
1348   Group2Sel->buttonRedo->setEnabled( value );
1349   Group1Sel1Spin->buttonRedo->setEnabled( value );
1350   Group1Spin->buttonRedo->setEnabled( value );
1351   Group2Spin->buttonRedo->setEnabled( value );
1352   Group3Spin->buttonRedo->setEnabled( value );
1353   Group4Spin->buttonRedo->setEnabled( value );
1354 }
1355
1356 //=================================================================================
1357 // function : SelectionIntoArgument()
1358 // purpose  : Called when selection as changed
1359 //=================================================================================
1360 void EntityGUI_SketcherDlg::SelectionIntoArgument()
1361 {
1362   MESSAGE("EntityGUI_SketcherDlg::SelectionIntoArgument")
1363   myEditCurrentArgument->setText( "" );
1364
1365   LightApp_SelectionMgr* aSelMgr = myGeometryGUI->getApp()->selectionMgr();
1366   SALOME_ListIO aSelList;
1367   aSelMgr->selectedObjects(aSelList);
1368   
1369   this->activateWindow();
1370   
1371   if (aSelList.Extent() == 0)
1372   {
1373     selButton->setDown(false);
1374     WPlaneLineEdit->setEnabled(false);
1375     WPlaneLineEdit->setText(tr("GEOM_SKETCHER_WPLANE"));
1376     return;
1377   }
1378   else if (aSelList.Extent() != 1)                                
1379     return;
1380   
1381   double tmpX = myX;
1382   double tmpY = myY;
1383   myX = myLastX1;
1384   myY = myLastY1;
1385   
1386   TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
1387   if (myEditCurrentArgument == WPlaneLineEdit)
1388     aNeedType = TopAbs_FACE;
1389   
1390  
1391   GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
1392   TopoDS_Shape aShape;
1393   
1394   if(aSelectedObject && GEOMBase::GetShape(aSelectedObject.get(), aShape) 
1395                      && !aShape.IsNull())
1396   { 
1397     QString aName = GEOMBase::GetName( aSelectedObject.get() ); 
1398     if (myEditCurrentArgument==WPlaneLineEdit)  
1399     { 
1400       // Check if the face is planar
1401       Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aShape));
1402       GeomLib_IsPlanarSurface aPlanarCheck(aSurf, Precision::Confusion());
1403       
1404       if (aPlanarCheck.IsPlanar())
1405       {
1406         myEditCurrentArgument->setText(aName);
1407         AddLocalCS(aSelectedObject.get());
1408         selButton->setDown(false);
1409         WPlaneLineEdit->setEnabled(false);
1410         TypeClicked( myConstructorId );
1411       }
1412       else
1413       {
1414         myEditCurrentArgument->setText(tr("GEOM_SKETCHER_WPLANE"));
1415         // The following leads to crash TODO : find a way to return a warning
1416 //         Standard_Failure::Raise(tr("GEOM_SKETCHER_NOT_PLANAR").toStdString().c_str()); 
1417       }
1418     }           
1419     else
1420     {
1421       gp_Trsf aTrans;
1422       gp_Ax3 aWPlane = GetActiveLocalCS();
1423
1424       aTrans.SetTransformation(aWPlane);
1425       BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
1426       aShape = aTransformation.Shape();
1427
1428       gp_Pnt aPnt;
1429       if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) 
1430       {
1431         myEditCurrentArgument->setText(aName);
1432         myX = aPnt.X();
1433         myY = aPnt.Y();       
1434         double Xcoord = myX;
1435         double Ycoord = myY;
1436         
1437         switch (mySketchType)
1438         {
1439           case PT_ABS:
1440           disconnect( Group2Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1441           disconnect( Group2Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1442           
1443           Group2Spin->SpinBox_DX->setValue(Xcoord);
1444           Group2Spin->SpinBox_DY->setValue(Ycoord);
1445       
1446           connect( Group2Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1447           connect( Group2Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1448             break;
1449             
1450           case PT_RELATIVE:
1451             if (myLastX1 && myLastY1)
1452             {
1453               Xcoord = myX - myLastX1;
1454               Ycoord = myY - myLastY1;
1455             }
1456             else if (mySketchState != FIRST_POINT)
1457             {
1458               Xcoord = myX - tmpX;
1459               Ycoord = myY - tmpY;
1460             }          
1461             Group2Spin->SpinBox_DX->setValue(Xcoord);
1462             Group2Spin->SpinBox_DY->setValue(Ycoord);      
1463             break; 
1464             
1465           case PT_ABS_RADIUS:
1466             disconnect( Group3Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1467             disconnect( Group3Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1468             
1469             Group3Spin->SpinBox_DX->setValue(Xcoord);
1470             Group3Spin->SpinBox_DY->setValue(Ycoord);
1471       
1472             connect( Group3Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1473             connect( Group3Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1474             break;
1475             
1476           case PT_REL_RADIUS:
1477             if (myLastX1 && myLastY1)
1478             {
1479               Xcoord = myX - myLastX1;
1480               Ycoord = myY - myLastY1;
1481             }
1482             else if (mySketchState != FIRST_POINT)
1483             {
1484               Xcoord = myX - tmpX;
1485               Ycoord = myY - tmpY;
1486             }             
1487             Group3Spin->SpinBox_DX->setValue(Xcoord);
1488             Group3Spin->SpinBox_DY->setValue(Ycoord);
1489             break; 
1490             
1491           case PT_ABS_CENTER:
1492             disconnect( Group4Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1493             disconnect( Group4Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1494             
1495             Group4Spin->SpinBox_DX->setValue(Xcoord);
1496             Group4Spin->SpinBox_DY->setValue(Ycoord);
1497       
1498             connect( Group4Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1499             connect( Group4Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );        
1500             break;
1501             
1502           case PT_REL_CENTER:
1503             if (myLastX1 && myLastY1)
1504             {
1505               Xcoord = myXc - myLastX1;
1506               Ycoord = myYc - myLastY1;
1507             }
1508             else if (mySketchState != FIRST_POINT)
1509             {
1510               Xcoord = myXc - tmpX;
1511               Ycoord = myYc - tmpY;
1512             } 
1513             else
1514             {
1515               Xcoord = myXc;
1516               Ycoord = myYc;
1517             }
1518             
1519             Group4Spin->SpinBox_DX->setValue(Xcoord);
1520             Group4Spin->SpinBox_DY->setValue(Ycoord);            
1521             break; 
1522             
1523         }
1524       }
1525     }
1526   }
1527
1528   if(!autoApply){
1529     GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
1530   }
1531   else {    
1532     ClickOnApply();
1533     autoApply = false;
1534   }
1535   
1536 }
1537
1538
1539 //=================================================================================
1540 // function : SetEditCurrentArgument()
1541 // purpose  :
1542 //=================================================================================
1543 void EntityGUI_SketcherDlg::SetEditCurrentArgument()
1544 {
1545   TopAbs_ShapeEnum myNeedType = TopAbs_VERTEX;
1546   if ( sender() == Group1Sel->PushButton1 ) {
1547     myEditCurrentArgument = Group1Sel->LineEdit1;
1548     myEditCurrentArgument->setFocus();
1549   }
1550   else if ( sender() == Group1Sel1Spin->PushButton1 ) {
1551     myEditCurrentArgument = Group1Sel1Spin->LineEdit1;
1552     myEditCurrentArgument->setFocus();
1553   }
1554   else if ( sender() == Group2Sel->PushButton1 ) {
1555     myEditCurrentArgument = Group2Sel->LineEdit1;
1556     Group2Sel->PushButton2->setDown(false);
1557     Group2Sel->PushButton1->setDown(true);
1558     Group2Sel->LineEdit2->setEnabled(false);
1559     Group2Sel->LineEdit1->setEnabled(true);
1560    // myEditCurrentArgument->setFocus();
1561   }
1562    else if ( sender() == Group2Sel->PushButton2 ) {
1563     myEditCurrentArgument = Group2Sel->LineEdit2;
1564     Group2Sel->PushButton1->setDown(false);
1565     Group2Sel->PushButton2->setDown(true);
1566     Group2Sel->LineEdit1->setEnabled(false);
1567     Group2Sel->LineEdit2->setEnabled(true);
1568    // myEditCurrentArgument->setFocus();
1569   }
1570   else if ( sender() == selButton ) {
1571     myNeedType = TopAbs_FACE;
1572     myEditCurrentArgument = WPlaneLineEdit;
1573     WPlaneLineEdit->setEnabled(true);
1574     selButton->setDown(true);
1575   }
1576   globalSelection(); // close local selection to clear it
1577   localSelection(GEOM::GEOM_Object::_nil(), myNeedType);
1578 }
1579
1580
1581 //=================================================================================
1582 // function : LineEditReturnPressed()
1583 // purpose  :
1584 //=================================================================================
1585 void EntityGUI_SketcherDlg::LineEditReturnPressed()
1586 {
1587   if ( sender() == Group1Sel->LineEdit1 ) 
1588     myEditCurrentArgument = Group1Sel->LineEdit1;
1589   else if ( sender() == Group1Sel1Spin->LineEdit1 ) 
1590      myEditCurrentArgument = Group1Sel1Spin->LineEdit1;
1591   else if ( sender() == Group2Sel->LineEdit1 ) 
1592      myEditCurrentArgument = Group2Sel->LineEdit1;
1593   else if ( sender() == Group2Sel->LineEdit2 )
1594      myEditCurrentArgument = Group2Sel->LineEdit2;
1595
1596   /* User name of object input management                          */
1597   /* If successfull the selection is changed and signal emitted... */
1598   /* so SelectionIntoArgument() is automatically called.           */
1599   const QString objectUserName = myEditCurrentArgument->text();
1600   QWidget* thisWidget = (QWidget*)this;
1601
1602   LightApp_SelectionMgr* aSelMgr = myGeometryGUI->getApp()->selectionMgr();
1603   SALOME_ListIO aSelList;
1604   aSelMgr->selectedObjects(aSelList);
1605
1606   if (GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, aSelList))
1607     myEditCurrentArgument->setText( objectUserName );
1608 }
1609
1610
1611 //=================================================================================
1612 // function : DeactivateActiveDialog()
1613 // purpose  :
1614 //=================================================================================
1615 void EntityGUI_SketcherDlg::DeactivateActiveDialog()
1616 {
1617   //myGeometryGUI->SetState( -1 );
1618
1619   setEnabled( false );
1620   globalSelection();
1621   disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
1622   myGeometryGUI->SetActiveDialogBox( 0 );
1623 }
1624
1625
1626 //=================================================================================
1627 // function : ActivateThisDialog()
1628 // purpose  :
1629 //=================================================================================
1630 void EntityGUI_SketcherDlg::ActivateThisDialog()
1631 {
1632   MESSAGE("EntityGUI_SketcherDlg::ActivateThisDialog()")
1633   myGeometryGUI->EmitSignalDeactivateDialog();
1634   setEnabled( true );
1635   myGeometryGUI->SetActiveDialogBox( this );
1636
1637   connect( myGeometryGUI->getApp()->selectionMgr(),
1638           SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
1639
1640   //myGeometryGUI->SetState( 0 );
1641 //   globalSelection( GEOM_POINT );
1642   
1643   myEditCurrentArgument = WPlaneLineEdit;
1644   myEditCurrentArgument->setFocus();
1645   
1646    if ( sender() == Group1Sel->LineEdit1 ) {
1647      myEditCurrentArgument = Group1Sel->LineEdit1;
1648      myEditCurrentArgument->setFocus();
1649    }
1650    else if ( sender() == Group1Sel1Spin->LineEdit1 ) {
1651      myEditCurrentArgument = Group1Sel1Spin->LineEdit1;
1652      myEditCurrentArgument->setFocus();
1653    }
1654    else if ( sender() == Group2Sel->LineEdit1 ) {
1655      myEditCurrentArgument = Group2Sel->LineEdit1;
1656      myEditCurrentArgument->setFocus();
1657    }
1658     else if ( sender() == Group2Sel->LineEdit2 ) {
1659      myEditCurrentArgument = Group2Sel->LineEdit2;
1660      myEditCurrentArgument->setFocus();
1661    }
1662    
1663   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
1664 }
1665
1666
1667 //=================================================================================
1668 // function : enterEvent [REDEFINED]
1669 // purpose  :
1670 //=================================================================================
1671 void EntityGUI_SketcherDlg::enterEvent( QEvent* )
1672 {
1673   if ( !isEnabled() )
1674     ActivateThisDialog();
1675 }
1676
1677
1678 //=================================================================================
1679 // function : closeEvent()
1680 // purpose  :
1681 //=================================================================================
1682 void EntityGUI_SketcherDlg::closeEvent( QCloseEvent* e )
1683 {
1684   MESSAGE("EntityGUI_SketcherDlg::closeEvent")
1685   //myGeometryGUI->SetState( -1 );
1686   disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
1687   myGeometryGUI->getApp()->updateActions();
1688   QDialog::closeEvent( e );
1689 }
1690
1691 //=================================================================================
1692 // function : OnPointSelected
1693 // purpose  :
1694 //=================================================================================
1695 void EntityGUI_SketcherDlg::OnPointSelected(Qt::KeyboardModifiers modifiers, const gp_Pnt& thePnt,
1696                                             bool isStart )
1697 {
1698   // NOTE Basing the autoapply functionnality on the background picture has no sense anymore
1699   // The import picture functionnality is now used for drawing on top of a picture
1700   
1701 //   SUIT_ViewWindow*      theViewWindow  = getDesktop()->activeWindow();
1702 //   OCCViewer_ViewPort3d* vp             = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
1703 //   
1704 //   QString                theImgFileName;
1705 //   vp->background().texture( theImgFileName ); ////////////// VSR: temporarily
1706   
1707   double x, y;
1708   x = y = 0;
1709   
1710   BRepBuilderAPI_MakeVertex mkVertex (thePnt);
1711   TopoDS_Shape aShape = mkVertex.Shape();
1712   
1713   // Taking into account LocalCS
1714   gp_Ax3 aWPlane = GetActiveLocalCS();
1715   gp_Trsf aTrans;
1716
1717   aTrans.SetTransformation(aWPlane);
1718   BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
1719   aShape = aTransformation.Shape();
1720   
1721   gp_Pnt aTrsfPnt; 
1722   GEOMBase::VertexToPoint( aShape, aTrsfPnt );
1723   
1724   // NOTE autoapply disabled : doesn't seem useful anymore
1725 //   autoApply = ( (getPnt2ConstructorId() == 1) && (!theImgFileName.isEmpty()) );  // If no additional argument needed after selection and there is a backgroundimage
1726                                                                                  // -> apply automatically 
1727   
1728   if ( getPnt1ConstructorId() == 0 ){                    // Relative selection mode
1729     x = aTrsfPnt.X() - myLastX1;
1730     y = aTrsfPnt.Y() - myLastY1;
1731   }
1732   else {
1733     x = aTrsfPnt.X();
1734     y = aTrsfPnt.Y();
1735   }
1736   switch (getPnt2ConstructorId()){
1737     case 1:
1738       Group2Spin->SpinBox_DX->setValue( x );
1739       Group2Spin->SpinBox_DY->setValue( y );
1740       Group2Spin->buttonApply->setFocus();               // Previous setFocus (during preview) may have been inoperative if it was disabled 
1741       break;
1742     case 0:
1743       Group3Spin->SpinBox_DX->setValue( x );
1744       Group3Spin->SpinBox_DY->setValue( y );
1745       Group3Spin->buttonApply->setFocus(); 
1746       break;
1747     case 2:
1748       if (modifiers == Qt::MetaModifier){                // Select center with Meta key
1749         Group4Spin->SpinBox_DX->setValue( x );
1750         Group4Spin->SpinBox_DY->setValue( y );
1751       }
1752       else{                                              // Select end point
1753         Group4Spin->SpinBox_DZ->setValue( x );
1754         Group4Spin->SpinBox_DS->setValue( y );
1755       }
1756       Group4Spin->buttonApply->setFocus(); 
1757       break;
1758   }
1759   if ( myConstructorId == 2 ) //RECTANGLE
1760   {
1761     if (isStart)
1762     {
1763       GroupRect->SpinBox_DX1->setValue( aTrsfPnt.X() );
1764       GroupRect->SpinBox_DY1->setValue( aTrsfPnt.Y() );
1765       GroupRect->SpinBox_DX2->setValue( aTrsfPnt.X() );
1766       GroupRect->SpinBox_DY2->setValue( aTrsfPnt.Y() );
1767     }
1768     else
1769     {
1770       GroupRect->SpinBox_DX2->setValue( aTrsfPnt.X() );
1771       GroupRect->SpinBox_DY2->setValue( aTrsfPnt.Y() );
1772     }
1773   }
1774 }
1775
1776 //=================================================================================
1777 // function : OnFirstPoint
1778 // purpose  :
1779 //=================================================================================
1780 void EntityGUI_SketcherDlg::OnFirstPoint()
1781 {
1782   MainWidget->RadioButton3->setEnabled( true );
1783   MainWidget->GroupDest1->setEnabled( false );
1784   GroupPt2->setEnabled( false );
1785 }
1786
1787 //=================================================================================
1788 // function : OnNextPoint
1789 // purpose  :
1790 //=================================================================================
1791 void EntityGUI_SketcherDlg::OnNextPoint()
1792 {
1793   MainWidget->RadioButton3->setEnabled( false );
1794   MainWidget->GroupDest1->setEnabled( true );
1795   TypeClicked(myConstructorId);
1796 }
1797
1798 //=================================================================================
1799 // function : ValueChangedInSpinBox()
1800 // purpose  :
1801 //=================================================================================
1802 void EntityGUI_SketcherDlg::ValueChangedInSpinBox( double newValue )
1803 {
1804   QObject* send = (QObject*)sender();
1805   Standard_Real vx, vy, vz, vs, minRad, dx, dy;
1806   vx = vy = vz = vs = minRad = dx = dy = 0.0;
1807
1808   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1809   int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
1810   double LastDecimal = 0.0;
1811
1812   QString vxStr, vyStr, vzStr, vsStr;
1813
1814   QString newValueStr;
1815   if( SalomeApp_DoubleSpinBox* aDoubleSpinBox = (SalomeApp_DoubleSpinBox*)send )
1816     newValueStr = aDoubleSpinBox->text();
1817
1818   if ( send == Group1Spin->SpinBox_DX ) {
1819     vx = newValue;                        vxStr = newValueStr;
1820   }
1821   else if ( send == Group1Sel1Spin->SpinBox_DX ) {
1822     vx = newValue;                        vxStr = newValueStr;
1823   }
1824   else if ( send == Group2Spin->SpinBox_DX ) {
1825     vx = newValue;                        vxStr = newValueStr;
1826     vy = Group2Spin->SpinBox_DY->value(); vyStr = Group2Spin->SpinBox_DY->text();
1827   }
1828   else if ( send == Group2Spin->SpinBox_DY ) {
1829     vx = Group2Spin->SpinBox_DX->value(); vxStr = Group2Spin->SpinBox_DX->text();
1830     vy = newValue;                        vyStr = newValueStr;
1831   }
1832   else if ( send == Group3Spin->SpinBox_DX ) {
1833     vx = newValue;                        vxStr = newValueStr;
1834     vy = Group3Spin->SpinBox_DY->value(); vyStr = Group3Spin->SpinBox_DY->text();
1835     vz = Group3Spin->SpinBox_DZ->value();
1836     if ( (mySketchType == PT_REL_RADIUS || mySketchType == PT_ABS_RADIUS) && (vx != 0 || vy != 0) ) {  
1837       if (mySketchType == PT_ABS_RADIUS){
1838         dx = vx - myLastX1;
1839         dy = vy - myLastY1;
1840       }
1841       else{
1842         dx = vx;
1843         dy = vy;
1844       }
1845       minRad = 0.5 * Sqrt(dx * dx + dy * dy);                             //Computation of the minimum acceptable radius for the arc calculation
1846       if (aPrecision >= 0)    // 'f' format in the QString             
1847         LastDecimal = aPrecision;
1848       else                    // 'g' format in the Qstring
1849         LastDecimal = qAbs( aPrecision ) - ceil( log10(minRad) ); 
1850       minRad = ceil(pow(10,LastDecimal) * minRad) / pow(10,LastDecimal);  // Rounded up at the last allowed decimal place
1851       if ( Abs(vz) < minRad){
1852         if (vz < 0.0)
1853           Group3Spin->SpinBox_DZ->setValue( - minRad );
1854         else 
1855           Group3Spin->SpinBox_DZ->setValue( minRad );
1856       }
1857     }
1858     vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
1859   }
1860   else if ( send == Group3Spin->SpinBox_DY ) {
1861     vx = Group3Spin->SpinBox_DX->value(); vxStr = Group3Spin->SpinBox_DX->text();
1862     vy = newValue;                        vyStr = newValueStr;
1863     vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
1864     if ( (mySketchType == PT_REL_RADIUS || mySketchType == PT_ABS_RADIUS) && (vx != 0 || vy != 0)){
1865       if (mySketchType == PT_ABS_RADIUS){
1866         dx = vx - myLastX1;
1867         dy = vy - myLastY1;
1868       }
1869       else{
1870         dx = vx;
1871         dy = vy;
1872       }    
1873       minRad = 0.5 * Sqrt(dx * dx + dy * dy);                            //Computation of the minimum acceptable radius for the arc calculation
1874       if (aPrecision >= 0)    // 'f' format in the QString 
1875         LastDecimal = aPrecision;
1876       else                    // 'g' format in the QString 
1877         LastDecimal = qAbs( aPrecision ) - ceil( log10(minRad) ); 
1878         minRad = ceil(pow(10,LastDecimal) * minRad) / pow(10,LastDecimal); // Rounded up at the last allowed decimal place
1879       if ( Abs(vz) < minRad){
1880         if (vz < 0.0)
1881           Group3Spin->SpinBox_DZ->setValue( - minRad );
1882         else 
1883           Group3Spin->SpinBox_DZ->setValue( minRad );
1884       }
1885     }
1886     vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
1887   }
1888   else if ( send == Group3Spin->SpinBox_DZ ) {
1889     vx = Group3Spin->SpinBox_DX->value(); vxStr = Group3Spin->SpinBox_DX->text();
1890     vy = Group3Spin->SpinBox_DY->value(); vyStr = Group3Spin->SpinBox_DY->text();
1891     vz = newValue;                        vzStr = newValueStr;
1892   }
1893   else if ( send == Group4Spin->SpinBox_DX ) {
1894     vx = newValue;                        vxStr = newValueStr;
1895     vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1896     vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1897     vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1898   }
1899   else if ( send == Group4Spin->SpinBox_DY ) {
1900     vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1901     vy = newValue;                        vyStr = newValueStr;
1902     vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1903     vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1904   }
1905   else if ( send == Group4Spin->SpinBox_DZ ) {
1906     vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1907     vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1908     vz = newValue;                        vzStr = newValueStr;
1909     vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1910   }
1911   else if ( send == Group4Spin->SpinBox_DS ) {
1912     vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1913     vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1914     vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1915     vs = newValue;                        vsStr = newValueStr;
1916   }
1917   // Fix of the NPAL16010 bug is removed, because it's not actual with the Qt-4.x
1918
1919   if ( myConstructorId == 0 ) {  // SEGMENT
1920     if ( mySketchType == PT_ABS ) {
1921       myX = vx;
1922       myY = vy;
1923       myXStr = vxStr;
1924       myYStr = vyStr;
1925     }
1926     else if ( mySketchType == PT_RELATIVE ) {
1927       myDX = vx;
1928       myDY = vy;
1929       myDXStr = vxStr;
1930       myDYStr = vyStr;
1931     }
1932     else if ( mySketchType == DIR_ANGLE_LENGTH ) {
1933       myAngle = vx;
1934       myLength = vy;
1935       myAngleStr = vxStr;
1936       myLengthStr = vyStr;
1937     }
1938     else if ( mySketchType == DIR_ANGLE_X ) {
1939       myAngle = vx;
1940       myX = vy;
1941       myAngleStr = vxStr;
1942       myXStr = vyStr;
1943     }
1944     else if ( mySketchType == DIR_ANGLE_Y ) {
1945       myAngle = vx;
1946       myY = vy;
1947       myAngleStr = vxStr;
1948       myYStr = vyStr;
1949     }
1950     else if ( mySketchType == DIR_PER_LENGTH ) {
1951       myLength = vx;
1952       myLengthStr = vxStr;
1953     }
1954     else if ( mySketchType == DIR_PER_X ) {
1955       myX = vx;
1956       myXStr = vxStr;
1957     }
1958     else if ( mySketchType == DIR_PER_Y ) {
1959       myY = vx;
1960       myYStr = vxStr;
1961     }
1962     else if ( mySketchType == DIR_TAN_LENGTH ) {
1963       myLength = vx;
1964       myLengthStr = vxStr;
1965     }
1966     else if ( mySketchType == DIR_TAN_X ) {
1967       myX = vx;
1968       myXStr = vxStr;
1969     }
1970     else if ( mySketchType == DIR_TAN_Y ) {
1971       myY = vx;
1972       myYStr = vxStr;
1973     }
1974     else if ( mySketchType == DIR_DXDY_LENGTH ) {
1975       myDX = vx;
1976       myDY = vy;
1977       myLength = vz;
1978       myDXStr = vxStr;
1979       myDYStr = vyStr;
1980       myLengthStr = vzStr;
1981     }
1982     else if ( mySketchType == DIR_DXDY_X ) {
1983       myDX = vx;
1984       myDY = vy;
1985       myX = vz;
1986       myDXStr = vxStr;
1987       myDYStr = vyStr;
1988       myXStr = vzStr;
1989     }
1990     else if ( mySketchType == DIR_DXDY_Y ) {
1991       myDX = vx;
1992       myDY = vy;
1993       myY = vz;
1994       myDXStr = vxStr;
1995       myDYStr = vyStr;
1996       myYStr = vzStr;
1997     }
1998   }
1999   else if ( myConstructorId == 1 ) {  // ARC
2000     if ( mySketchType == PT_ABS ) {  
2001       myX = vx;
2002       myY = vy;
2003       myXStr = vxStr;
2004       myYStr = vyStr;
2005     }
2006     else if ( mySketchType == PT_RELATIVE ) {
2007       myDX = vx;
2008       myDY = vy;
2009       myDXStr = vxStr;
2010       myDYStr = vyStr;
2011     }
2012     if ( mySketchType == PT_ABS_RADIUS ) {  
2013       myX = vx;
2014       myY = vy;
2015       myRadius=vz;
2016       myXStr = vxStr;
2017       myYStr = vyStr;
2018       myRadiusStr = vzStr;
2019     }
2020     else if ( mySketchType == PT_REL_RADIUS ) {
2021       myDX = vx;
2022       myDY = vy;
2023       myRadius=vz;
2024       myDXStr = vxStr;
2025       myDYStr = vyStr;
2026       myRadiusStr = vzStr;
2027     }
2028     else if ( mySketchType == PT_SEL_RADIUS ) {
2029       myRadius = vx;
2030       myRadiusStr = vxStr;
2031     }
2032     if ( mySketchType == PT_ABS_CENTER ) {  
2033       myXc = vx;
2034       myYc = vy;
2035       myX = vz;
2036       myY = vs;
2037       myXcStr = vxStr;
2038       myYcStr = vyStr;
2039       myXStr = vzStr;
2040       myYStr = vsStr;
2041     }
2042     else if ( mySketchType == PT_REL_CENTER ) {
2043       myDXc = vx;
2044       myDYc = vy;
2045       myDX = vz;
2046       myDY = vs;
2047       myDXcStr = vxStr;
2048       myDYcStr = vyStr;
2049       myDXStr = vzStr;
2050       myDYStr = vsStr;
2051     }
2052     if ( mySketchType == DIR_ANGLE_LENGTH ) {
2053       myAngle = vx;
2054       myRadius = vy;
2055       myLength = vz;
2056       myAngleStr = vxStr;
2057       myRadiusStr = vyStr;
2058       myLengthStr = vzStr;
2059     }
2060     else if ( mySketchType == DIR_PER_LENGTH ) {
2061       myRadius = vx;
2062       myLength = vy;
2063       myRadiusStr = vxStr;
2064       myLengthStr = vyStr;
2065     }
2066     else if ( mySketchType == DIR_TAN_LENGTH ) {
2067       myRadius = vx;
2068       myLength = vy;
2069       myRadiusStr = vxStr;
2070       myLengthStr = vyStr;
2071     }
2072     else if ( mySketchType == DIR_DXDY_LENGTH ) {
2073       myDX = vx;
2074       myDY = vy;
2075       myRadius = vz;
2076       myLength = vs;
2077       myDXStr = vxStr;
2078       myDYStr = vyStr;
2079       myRadiusStr = vzStr;
2080       myLengthStr = vsStr;
2081     }
2082   }
2083   else if ( myConstructorId == 2 ) {  // RECTANGLE
2084     myX1 = GroupRect->SpinBox_DX1->value(); myX1Str = GroupRect->SpinBox_DX1->text();
2085     myX2 = GroupRect->SpinBox_DX2->value(); myX2Str = GroupRect->SpinBox_DX2->text();
2086     myY1 = GroupRect->SpinBox_DY1->value(); myY1Str = GroupRect->SpinBox_DY1->text();
2087     myY2 = GroupRect->SpinBox_DY2->value(); myY2Str = GroupRect->SpinBox_DY2->text();
2088   }
2089
2090   
2091   if (!autoApply) 
2092     GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
2093   
2094   double x, y, xc, yc;
2095   x = y = xc = yc = 0.0;
2096   if ( mySketchType == PT_ABS_CENTER || mySketchType == PT_REL_CENTER )
2097   {
2098     if ( mySketchType == PT_REL_CENTER ){
2099       x  = myDX  + myLastX1;
2100       y  = myDY  + myLastY1;
2101       xc = myDXc + myLastX1;
2102       yc = myDYc + myLastY1;
2103     }
2104     else {
2105       x  = myX ;
2106       y  = myY ;
2107       xc = myXc;
2108       yc = myYc;
2109     }
2110     displayPntPreview(xc,yc);
2111     displayPntPreview(x,y);
2112   }
2113 }
2114
2115
2116 //=================================================================================
2117 // function : GetNewCommand()
2118 // purpose  : Build the new command with context
2119 //=================================================================================
2120 QString EntityGUI_SketcherDlg::GetNewCommand( QString& theParameters )
2121 {
2122   theParameters.clear();
2123   QString myNewCommand = ":";
2124   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2125   int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
2126   int DigNum = qAbs(aPrecision);                   // options for the format of numbers in  myNewCommand
2127   char Format = 'f';
2128   if ( aPrecision < 0 )                            // f --> DigNum is the number of digits after the decimal point
2129     Format = 'g';                                  // g --> DigNum is the maximum number of significant digits 
2130
2131   if ( mySketchState == FIRST_POINT ) {
2132     if ( mySketchType == PT_ABS || mySketchType == PT_SEL ) {
2133       myNewCommand = myNewCommand + "F " + QString::number( myX, Format, DigNum) + " " + QString::number( myY, Format, DigNum);
2134       theParameters = myXStr + ":" + myYStr;
2135     }
2136     if ( mySketchType == PT_RELATIVE) {
2137       myNewCommand = myNewCommand + "F " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
2138       theParameters = myDXStr + ":" + myDYStr;
2139     }
2140     if (myConstructorId == 2 )
2141       myNewCommand = ":";
2142     else
2143       return myNewCommand;
2144   }
2145
2146   if ( myConstructorId == 0  ) {  // SEGMENT
2147     if ( mySketchType == PT_ABS || mySketchType == PT_SEL ) {
2148       myNewCommand = myNewCommand + "TT " + QString::number( myX, Format, DigNum) + " " + QString::number( myY, Format, DigNum);
2149       theParameters = myXStr + ":" + myYStr;
2150     }
2151     if ( mySketchType == PT_RELATIVE) {
2152       myNewCommand = myNewCommand + "T " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
2153       theParameters = myDXStr + ":" + myDYStr;
2154     }
2155     if ( mySketchType == DIR_ANGLE_LENGTH ) {
2156       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
2157       myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength, Format, DigNum );
2158       theParameters = myAngleStr + ":" + myLengthStr;
2159     }
2160     if ( mySketchType == DIR_ANGLE_X ) {
2161       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
2162       myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX, Format, DigNum);
2163       theParameters = myAngleStr + ":" + myXStr;
2164     }
2165     if ( mySketchType == DIR_ANGLE_Y ) {
2166       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
2167       myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY, Format, DigNum);
2168       theParameters = myAngleStr + ":" + myYStr;
2169     }
2170     if ( mySketchType == DIR_PER_LENGTH ) {
2171       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
2172       myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength, Format, DigNum );
2173       theParameters = QString::number( 90.0 ) + ":" + myLengthStr;
2174     }
2175     if ( mySketchType == DIR_PER_X ) {
2176       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
2177       myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX, Format, DigNum);
2178       theParameters = QString::number( 90.0 ) + ":" + myXStr;
2179     }
2180     if ( mySketchType == DIR_PER_Y ) {
2181       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
2182       myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY, Format, DigNum);
2183       theParameters = QString::number( 90.0 ) + ":" + myYStr;
2184     }
2185     if ( mySketchType == DIR_TAN_LENGTH ) {
2186       myNewCommand = myNewCommand + "L " + QString::number( myLength, Format, DigNum );
2187       theParameters = myLengthStr;
2188     }
2189     if ( mySketchType == DIR_TAN_X ) {
2190       myNewCommand = myNewCommand + "IX " + QString::number( myX, Format, DigNum);
2191       theParameters = myXStr;
2192     }
2193     if ( mySketchType == DIR_TAN_Y) {
2194       myNewCommand = myNewCommand + "IY " + QString::number(myY, Format, DigNum);
2195       theParameters = myYStr;
2196     }
2197     if ( mySketchType == DIR_DXDY_LENGTH ) {
2198       myNewCommand = myNewCommand + "D " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
2199       myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength, Format, DigNum );
2200       theParameters = myDXStr + ":" + myDYStr + ":" + myLengthStr;
2201     }
2202     if ( mySketchType == DIR_DXDY_X ) {
2203       myNewCommand = myNewCommand + "D " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
2204       myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX, Format, DigNum);
2205       theParameters = myDXStr + ":" + myDYStr + ":" + myXStr;
2206     }
2207     if ( mySketchType == DIR_DXDY_Y ) {
2208       myNewCommand = myNewCommand + "D " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
2209       myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY, Format, DigNum);
2210       theParameters = myDXStr + ":" + myDYStr + ":" + myYStr;
2211     }
2212   }
2213   else if ( myConstructorId == 1 ) {  // ARC
2214     if ( mySketchType == PT_ABS || mySketchType == PT_SEL ) {
2215       myNewCommand = myNewCommand + "AA " + QString::number( myX, Format, DigNum) + " " + QString::number( myY, Format, DigNum);
2216       theParameters = myXStr + ":" + myYStr;
2217     }
2218     if ( mySketchType == PT_RELATIVE) {
2219       myNewCommand = myNewCommand + "A " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
2220       theParameters = myDXStr + ":" + myDYStr;
2221     }
2222     if ( mySketchType == PT_ABS_RADIUS || mySketchType == PT_SEL_RADIUS ) {
2223       myNewCommand = myNewCommand + "UU " + QString::number( myX, Format, DigNum) + " " + QString::number( myY, Format, DigNum ) + " " + QString::number( myRadius , Format,  DigNum)+ " " + QString::number( myCheckFlag );
2224       theParameters = myXStr + ":" + myYStr + ":" + myRadiusStr; 
2225     }
2226     if ( mySketchType == PT_REL_RADIUS) {
2227       myNewCommand = myNewCommand + "U " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum ) + " " + QString::number( myRadius, Format, DigNum )+ " " + QString::number( myCheckFlag );
2228       theParameters = myDXStr + ":" + myDYStr + ":" + myRadiusStr;  
2229     }
2230     if ( mySketchType == PT_ABS_CENTER || mySketchType == PT_SEL_CENTER ) {
2231       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 );
2232       theParameters = myXStr + ":" + myYStr + ":" + myXcStr+ ":" + myYcStr; 
2233     }
2234     if ( mySketchType == PT_REL_CENTER) {
2235       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 );
2236       theParameters = myDXStr + ":" + myDYStr + ":" +  myDXcStr + ":" + myDYcStr ;  
2237     }
2238     if ( mySketchType == DIR_ANGLE_LENGTH ) {
2239       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
2240       myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius, Format, DigNum ) + " " + QString::number( myLength, Format, DigNum );
2241       theParameters = myAngleStr + ":" + myRadiusStr + ":" + myLengthStr;
2242     }
2243     if ( mySketchType == DIR_PER_LENGTH ) {
2244       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
2245       myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius, Format, DigNum ) + " " + QString::number( myLength, Format, DigNum );
2246       theParameters = QString::number( 90.0 ) + ":" + myRadiusStr + ":" + myLengthStr;
2247     }
2248     if ( mySketchType == DIR_TAN_LENGTH ) {
2249       myNewCommand = myNewCommand + "C " + QString::number( myRadius, Format, DigNum ) + " " + QString::number( myLength, Format, DigNum );
2250       theParameters = myRadiusStr + ":" + myLengthStr;
2251     }
2252     if ( mySketchType == DIR_DXDY_LENGTH ) {
2253       myNewCommand = myNewCommand + "D " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
2254       myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius, Format, DigNum ) + " " + QString::number( myLength, Format, DigNum );
2255       theParameters = myDXStr + ":" + myDYStr + ":" + myRadiusStr + ":" + myLengthStr;
2256     }
2257   }
2258   else if ( myConstructorId == 2 ) {  // RECTANGLE
2259       myNewCommand = myNewCommand + "F " + QString::number( myX1, Format, DigNum) + " " + QString::number( myY1, Format, DigNum)
2260                                   + ":TT " + QString::number( myX1, Format, DigNum) + " " + QString::number( myY2, Format, DigNum)
2261                                   + ":TT " + QString::number( myX2, Format, DigNum) + " " + QString::number( myY2, Format, DigNum)
2262                                   + ":TT " + QString::number( myX2, Format, DigNum) + " " + QString::number( myY1, Format, DigNum)
2263                                   + ":WW";
2264                           
2265       theParameters = myX1Str + ":" + myY1Str + ":" + myX2Str + ":" + myY2Str ;
2266     }
2267   return myNewCommand;
2268 }
2269
2270 //=================================================================================
2271 // function : createOperation
2272 // purpose  :
2273 //=================================================================================
2274 GEOM::GEOM_IOperations_ptr EntityGUI_SketcherDlg::createOperation()
2275 {
2276   return getGeomEngine()->GetICurvesOperations( getStudyId() );
2277 }
2278
2279 //=================================================================================
2280 // function : isValid
2281 // purpose  :
2282 //=================================================================================
2283 bool EntityGUI_SketcherDlg::isValid( QString& msg )
2284 {
2285   bool ok = true;
2286   bool toCorrect = !IsPreview() || myIsApply;
2287
2288   if( Group1Spin->isVisible() ) {
2289     ok = Group1Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
2290   }
2291   else if( Group1Sel1Spin->isVisible() ) {
2292     ok = Group1Sel1Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
2293   }
2294   else if( Group2Spin->isVisible() ) {
2295     ok = Group2Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
2296     ok = Group2Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
2297   }
2298   else if( Group3Spin->isVisible() ) {
2299     ok = Group3Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
2300     ok = Group3Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
2301     ok = Group3Spin->SpinBox_DZ->isValid( msg, toCorrect ) && ok;
2302   }
2303   else if( Group4Spin->isVisible() ) {
2304     ok = Group4Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
2305     ok = Group4Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
2306     ok = Group4Spin->SpinBox_DZ->isValid( msg, toCorrect ) && ok;
2307     ok = Group4Spin->SpinBox_DS->isValid( msg, toCorrect ) && ok;
2308   }
2309
2310   if( myIsApply && !ok )
2311     showError( msg );
2312
2313   return ok;
2314 }
2315
2316 //=================================================================================
2317 // function : execute
2318 // purpose  :
2319 //=================================================================================
2320 bool EntityGUI_SketcherDlg::execute( ObjectList& objects )
2321 {
2322   MESSAGE("EntityGUI_SketcherDlg::execute")
2323   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2324   int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
2325   int DigNum = qAbs(aPrecision);                   // options for the format of numbers in  myNewCommand
2326   char Format = 'f';
2327   if ( aPrecision < 0 )                            // f --> DigNum is the number of digits after the decimal point
2328     Format = 'g';                                  // g --> DigNum is the maximum number of significant digits 
2329     
2330   QString aParameters;
2331   
2332   if ( mySketchState == FIRST_POINT ) {
2333     myLastX2 = myX;
2334     myLastY2 = myY;
2335   }
2336   else {
2337     //Test if the current point is the same as the last one
2338     TopoDS_Shape myShape1, myShape2;
2339
2340     // Set "C" numeric locale
2341     Kernel_Utils::Localizer loc;
2342
2343     //Last Shape
2344     QString Command1 = myCommand.join( "" );
2345     Sketcher_Profile aProfile1( Command1.toAscii() );
2346     if ( aProfile1.IsDone() )
2347       myShape1 = aProfile1.GetShape();
2348
2349     //Current Shape
2350     QString Command2 = Command1 + GetNewCommand( aParameters );
2351     Sketcher_Profile aProfile2( Command2.toAscii() );
2352
2353     //Error Message
2354     if ( mySketchType == PT_ABS_CENTER || mySketchType == PT_REL_CENTER  ){
2355       if (aProfile2.Error() > Precision::Confusion()){
2356         Group4Spin->label->show();
2357         Group4Spin->label->setText( tr("GEOM_SKETCHER_WARNING") + QString::number( aProfile2.Error(), Format, DigNum));
2358       }
2359       else{
2360         Group4Spin->label->hide();
2361       } 
2362     }
2363     else 
2364       Group4Spin->label->hide();
2365     if ( mySketchType == PT_SEL_CENTER ){
2366       if (aProfile2.Error() > Precision::Confusion()){
2367         Group2Sel->label->show();
2368         Group2Sel->label->setText( tr("GEOM_SKETCHER_WARNING") + QString::number( aProfile2.Error(), Format, DigNum));
2369       }
2370       else{
2371         Group2Sel->label->hide();
2372       } 
2373     }
2374     else 
2375       Group2Sel->label->hide();
2376
2377     if ( aProfile2.IsDone() )
2378       myShape2 = aProfile2.GetShape();
2379
2380     if ( myShape2.IsNull() ) {
2381       //the current point is the same as the last one
2382       myLastX2 = myLastX1;
2383       myLastY2 = myLastY1;
2384     }
2385     else {
2386       TopoDS_Vertex V1, V2;
2387       gp_Pnt pt;
2388       if ( myShape1.ShapeType() == TopAbs_VERTEX ) {
2389         //the last shape is the first point
2390         pt = BRep_Tool::Pnt( TopoDS::Vertex( myShape1 ) );
2391         myLastX1 = pt.X();
2392         myLastY1 = pt.Y();
2393       }
2394       else {
2395         TopExp::Vertices( TopoDS::Wire( myShape1 ), V1, V2 );
2396         pt = BRep_Tool::Pnt( V2 );
2397         myLastX1 = pt.X();
2398         myLastY1 = pt.Y();
2399       }
2400       TopExp::Vertices( TopoDS::Wire( myShape2 ), V1, V2 );
2401       pt = BRep_Tool::Pnt( V2 );
2402       myLastX2 = pt.X();
2403       myLastY2 = pt.Y();
2404     }
2405   }
2406
2407   QString cmd;
2408   if ( ( mySketchState != FIRST_POINT &&
2409          myLastX1 == myLastX2 && myLastY1 == myLastY2 ) || myIsAllAdded ) {
2410     cmd = myCommand.join( "" );
2411     if ( Group1Sel->isVisible() ) {
2412       Group1Sel->buttonApply->setEnabled( false );
2413       //Group1Sel->buttonApply->setFocus();
2414     }
2415     if ( Group2Sel->isVisible() ) {
2416       Group2Sel->buttonApply->setEnabled( false );
2417       //Group2Sel->buttonApply->setFocus();
2418     }
2419     if ( Group1Sel1Spin->isVisible() ) {
2420       Group1Sel1Spin->buttonApply->setEnabled( false );
2421       //Group1Sel1Spin->buttonApply->setFocus();
2422     }
2423     if ( Group1Spin->isVisible() ) {
2424       Group1Spin->buttonApply->setEnabled( false );
2425       //Group1Spin->buttonApply->setFocus();
2426     }
2427     if ( Group2Spin->isVisible() ) {
2428       Group2Spin->buttonApply->setEnabled( false );
2429       //Group2Spin->buttonApply->setFocus();
2430     }
2431     if ( Group3Spin->isVisible() ) {
2432       Group3Spin->buttonApply->setEnabled( false );
2433       //Group3Spin->buttonApply->setFocus();
2434     }
2435     if ( Group4Spin->isVisible() ) {
2436       Group4Spin->buttonApply->setEnabled( false );
2437       //Group4Spin->buttonApply->setFocus();
2438     }
2439   }
2440   else {
2441     cmd = myCommand.join( "" ) + GetNewCommand( aParameters );
2442
2443     if ( Group1Sel->isVisible() ) {
2444       Group1Sel->buttonApply->setEnabled( true );
2445     }
2446     if ( Group2Sel->isVisible() ) {
2447       Group2Sel->buttonApply->setEnabled( true );
2448     }
2449     if ( Group1Sel1Spin->isVisible() ) {
2450       Group1Sel1Spin->buttonApply->setEnabled( true );;
2451     }
2452     if ( Group1Spin->isVisible() ) {
2453       Group1Spin->buttonApply->setEnabled( true );
2454     }
2455     if ( Group2Spin->isVisible() ) {
2456       Group2Spin->buttonApply->setEnabled( true );
2457     }
2458     if ( Group3Spin->isVisible() ) {
2459       Group3Spin->buttonApply->setEnabled( true );
2460     }
2461     if ( Group4Spin->isVisible() ) {
2462       Group4Spin->buttonApply->setEnabled( true );
2463     }
2464   }
2465
2466   GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow(getOperation());
2467   GEOM::GEOM_Object_var anObj = NULL;
2468   
2469   int index = ComboBox1->currentIndex();
2470   if(index != -1 && !myWPlane->_is_nil()) // The combobox is not empty
2471   {
2472     anObj = anOper->MakeSketcherOnPlane( cmd.toLatin1().constData(), myWPlane );
2473   }
2474   if ( !anObj->_is_nil() )
2475   {
2476     if( !IsPreview() ) {
2477       QStringList aCurrentParameters = myParameters;
2478       aCurrentParameters << aParameters;
2479       anObj->SetParameters(aCurrentParameters.join(":").toLatin1().constData());
2480     }
2481
2482     objects.push_back( anObj._retn() );
2483   }
2484
2485   return true;
2486 }
2487
2488 //================================================================
2489 // Function : displayPreview
2490 // Purpose  : Method for displaying preview of resulting shape
2491 //            Redefined from GEOMBase_Helper.
2492 //================================================================
2493 void EntityGUI_SketcherDlg::displayPreview( GEOM::GEOM_Object_ptr object,
2494                                             const bool            append,
2495                                             const bool            activate,
2496                                             const bool            update,
2497                                             const double          lineWidth,
2498                                             const int             displayMode,
2499                                             const int             color )
2500
2501   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); 
2502   
2503   QColor aColor = resMgr->colorValue("Geometry","line_color",QColor(255,0,0));
2504   Quantity_NameOfColor line_color = SalomeApp_Tools::color( aColor ).Name();
2505   
2506   // set width of displayed shape
2507   int lw = lineWidth;
2508   if(lw == -1) { 
2509     lw = resMgr->integerValue("Geometry", "preview_edge_width", -1);
2510   }
2511   getDisplayer()->SetWidth( lw );
2512
2513   // Disable activation of selection
2514   getDisplayer()->SetToActivate( activate );
2515
2516   // Make a reference to GEOM_Object
2517   CORBA::String_var objStr = myGeometryGUI->getApp()->orb()->object_to_string( object );
2518   getDisplayer()->SetName( objStr.in() );
2519
2520   // Create wire from applied object
2521   TopoDS_Shape anApplyedWire, aLastSegment;
2522   if ( !createShapes( object, anApplyedWire, aLastSegment ) )
2523     return;
2524
2525   // Build prs
2526   if( myConstructorId != 2)
2527     getDisplayer()->SetColor( line_color );
2528   else
2529     getDisplayer()->SetColor( Quantity_NOC_VIOLET );
2530   
2531   SALOME_Prs* aPrs = getDisplayer()->BuildPrs( anApplyedWire );
2532   if ( aPrs != 0 && !aPrs->IsNull() )
2533     GEOMBase_Helper::displayPreview( aPrs, append, update );
2534
2535   getDisplayer()->SetColor( Quantity_NOC_VIOLET ); 
2536   aPrs = getDisplayer()->BuildPrs( aLastSegment );
2537   
2538   if ( aPrs != 0 && !aPrs->IsNull() )
2539     GEOMBase_Helper::displayPreview( aPrs, append, update );
2540
2541   getDisplayer()->SetColor( line_color );
2542   
2543   getDisplayer()->UnsetName();
2544
2545   // Enable activation of displayed objects
2546   getDisplayer()->SetToActivate( true );
2547 }
2548
2549 //================================================================
2550 // Function : displayPntPreview
2551 // Purpose  : creates a TopoDS_VERTEX and display a preview of it
2552 //================================================================
2553 void EntityGUI_SketcherDlg::displayPntPreview(const double x,
2554                                               const double y,
2555                                               bool append,
2556                                               bool update
2557                                              )
2558 {
2559   // Get globalCS and working plane
2560   gp_Ax3 globalCS = WPlaneToLCS( myGlobalCS );
2561   gp_Ax3 aWPlane  = GetActiveLocalCS();
2562   
2563   // Build point in localCS
2564   gp_Pnt aPnt = gp_Pnt(x,y,0.0);
2565   
2566   // Get transfomation from local to global CS
2567   gp_Trsf aTrans;
2568   aTrans.SetTransformation(aWPlane, globalCS);
2569   
2570   BRepBuilderAPI_MakeVertex mkVertex (aPnt);
2571   TopoDS_Shape aLocalVertex = mkVertex.Shape();
2572   
2573   // Perform transformation
2574   BRepBuilderAPI_Transform aTransformation (aLocalVertex, aTrans, Standard_False);
2575   TopoDS_Shape aGlobalVertex = aTransformation.Shape();
2576   
2577   // Build prs with vertex in globalCS
2578   SALOME_Prs* aPrs = getDisplayer()->BuildPrs( aGlobalVertex );
2579   if ( aPrs != 0 && !aPrs->IsNull() )
2580     GEOMBase_Helper::displayPreview( aPrs, append, update );
2581   
2582 }
2583
2584 //================================================================
2585 // Function : createShapes
2586 // Purpose  : Create applyed wire, and last segment from entry object
2587 //================================================================
2588 bool EntityGUI_SketcherDlg::createShapes( GEOM::GEOM_Object_ptr theObject,
2589                                           TopoDS_Shape&         theApplyedWire,
2590                                           TopoDS_Shape&         theLastSegment )
2591 {
2592   TopoDS_Shape aShape;
2593   if (  !GEOMBase::GetShape( theObject, aShape ) ||
2594        ( aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX ) )
2595     return false;
2596
2597   if ( ( Group1Sel->isVisible()  && !Group1Sel->buttonApply->isEnabled() )||
2598        ( Group2Sel->isVisible()  && !Group2Sel->buttonApply->isEnabled() ) ||
2599        ( Group1Sel1Spin->isVisible()  && !Group1Sel1Spin->buttonApply->isEnabled() ) ||
2600        ( Group1Spin->isVisible() && !Group1Spin->buttonApply->isEnabled() ) ||
2601        ( Group2Spin->isVisible() && !Group2Spin->buttonApply->isEnabled() ) ||
2602        ( Group3Spin->isVisible() && !Group3Spin->buttonApply->isEnabled() ) ||
2603        ( Group4Spin->isVisible() && !Group4Spin->buttonApply->isEnabled() ) ) {
2604      theApplyedWire = aShape;
2605      return true;
2606   }
2607
2608   BRepBuilderAPI_MakeWire aBuilder;
2609   TopExp_Explorer anExp( aShape, TopAbs_EDGE );
2610   while ( 1 ) {
2611     TopoDS_Shape anEdge = anExp.Current();
2612     anExp.Next();
2613     if ( anExp.More() ) // i.e. non-last edge
2614       aBuilder.Add( TopoDS::Edge( anEdge ) );
2615     else {
2616       theLastSegment = anEdge;
2617       break;
2618     }
2619   }
2620
2621   if ( aBuilder.IsDone() )
2622     theApplyedWire = aBuilder.Shape();
2623
2624   return true;
2625 }
2626
2627 //=================================================================================
2628 // function : acceptMouseEvent()
2629 // purpose  :
2630 //=================================================================================
2631 bool EntityGUI_SketcherDlg::acceptMouseEvent() const 
2632 {
2633   return ( (getPnt1ConstructorId() == 1 
2634             || getPnt1ConstructorId() == 0
2635             || myConstructorId == 2)                       //accept mouse event only on absolute and relative selection mode                                                        
2636             && !WPlaneLineEdit->isEnabled());              //or when the constructor is rectangle
2637                                                            //called by EntityGUI::OnMousePress()        
2638 }  
2639
2640 //=================================================================================
2641 // function : keyPressEvent()
2642 // purpose  :
2643 //=================================================================================
2644 void  EntityGUI_SketcherDlg::keyPressEvent( QKeyEvent* e )
2645 {
2646   QDialog::keyPressEvent( e );
2647   if ( e->isAccepted() )
2648     return;
2649
2650   if ( e->key() == Qt::Key_F1 ) {
2651     e->accept();
2652     ClickOnHelp();
2653   }
2654 }
2655
2656 //=================================================================================
2657 // function : initSpinBox()
2658 // purpose  :
2659 //=================================================================================
2660 void EntityGUI_SketcherDlg::initSpinBox( SalomeApp_DoubleSpinBox* spinBox,
2661                                          double min,  double max,
2662                                          double step, const char* quantity )
2663 {
2664   // The same stuff as in GEOMBase_Skeleton::initSpinBox()!
2665   // TODO: Think how to keep the single piece of code...
2666
2667   // Obtain precision from preferences
2668   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2669   int aPrecision = resMgr->integerValue( "Geometry", quantity, 6 );
2670   
2671   spinBox->setPrecision( aPrecision );
2672   spinBox->setDecimals( qAbs( aPrecision ) ); // it's necessary to set decimals before the range setting,
2673                                               // by default Qt rounds boundaries to 2 decimals at setRange
2674   spinBox->setRange( min, max );
2675   spinBox->setSingleStep( step );
2676   
2677   // Add a hint for the user saying how to tune precision
2678   QString userPropName = QObject::tr( QString( "GEOM_PREF_%1" ).arg( quantity ).toLatin1().constData() );
2679   spinBox->setProperty( "validity_tune_hint", 
2680                         QVariant( QObject::tr( "GEOM_PRECISION_HINT" ).arg( userPropName ) ) );
2681 }
2682
2683 //=================================================================================
2684 // function : SetDoubleSpinBoxStep()
2685 // purpose  : Double spin box management
2686 //=================================================================================
2687 void EntityGUI_SketcherDlg::SetDoubleSpinBoxStep( double step )
2688 {
2689   Group1Spin->SpinBox_DX->setSingleStep(step);
2690   Group1Sel1Spin->SpinBox_DX->setSingleStep(step);
2691   Group2Spin->SpinBox_DX->setSingleStep(step);
2692   Group2Spin->SpinBox_DY->setSingleStep(step);
2693   Group3Spin->SpinBox_DX->setSingleStep(step);
2694   Group3Spin->SpinBox_DY->setSingleStep(step);
2695   Group3Spin->SpinBox_DZ->setSingleStep(step);
2696   Group4Spin->SpinBox_DZ->setSingleStep(step);
2697
2698   // san: Do NOT override the step when a speicifc step value is used
2699   // in some input fields!
2700   //Group4Spin->SpinBox_DX->setSingleStep(step);
2701   //Group4Spin->SpinBox_DY->setSingleStep(step);
2702   //Group4Spin->SpinBox_DS->setSingleStep(step);
2703 }
2704
2705 //=================================================================================
2706 // function : AddLocalCS()
2707 // purpose  : Add All Coordinates systems in study
2708 //=================================================================================
2709 void EntityGUI_SketcherDlg::AddLocalCS(GEOM::GEOM_Object_var aSelectedObject)
2710 {
2711   QString aName = GEOMBase::GetName( aSelectedObject );
2712   
2713   int index = ComboBox1->findText(aName, Qt::MatchExactly);
2714   
2715   if (index==-1)  // If the working plane hasn't been added yet
2716   {   
2717     myWPlaneList.push_back(aSelectedObject);
2718     myWPlane = aSelectedObject;
2719     addSubshapesToStudy();
2720     myLCSList.push_back(WPlaneToLCS(aSelectedObject));
2721     ComboBox1->addItem(aName); 
2722     index = ComboBox1->count();
2723     ComboBox1->setCurrentIndex(index-1);    
2724   }
2725   else
2726   {
2727     ComboBox1->setCurrentIndex(index);
2728   }
2729   ActivateLocalCS();   
2730 }
2731
2732 //=================================================================================
2733 // function : FindLocalCS()
2734 // purpose  : Find All Coordinates systems in study
2735 //=================================================================================
2736 void EntityGUI_SketcherDlg::FindLocalCS()
2737 {
2738   ComboBox1->clear();
2739   myWPlaneList.clear();
2740   SalomeApp_Application* app =
2741     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2742   if ( !app )
2743     return;
2744
2745   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2746   if ( !appStudy )
2747     return;
2748
2749   _PTR(Study) aStudy = appStudy->studyDS();
2750
2751   //add Global CS
2752   ComboBox1->addItem(tr("GEOM_GCS"));
2753   myWPlaneList.push_back(myGlobalCS);
2754
2755   // get GEOM component
2756   CORBA::String_var geomIOR = app->orb()->object_to_string( GeometryGUI::GetGeomGen() );
2757   _PTR(SObject) obj = aStudy->FindObjectIOR( geomIOR.in() );
2758   if (!obj)
2759     return;
2760   _PTR(SComponent) fc = obj->GetFatherComponent();
2761   QString geomComp = fc->GetID().c_str();
2762   _PTR(SObject) comp = aStudy->FindObjectID( geomComp.toLatin1().data() );
2763   if ( !comp )
2764     return;
2765
2766   // browse through all GEOM data tree
2767   _PTR(ChildIterator) it ( aStudy->NewChildIterator( comp ) );
2768   for ( it->InitEx( true ); it->More(); it->Next() ) 
2769   {
2770     _PTR(SObject) child( it->Value() );
2771     CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( child );
2772     GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
2773     if( CORBA::is_nil( geomObj ) ) 
2774       continue;
2775     if (geomObj->GetType() == GEOM_MARKER) 
2776     {
2777       myWPlaneList.push_back(geomObj);
2778       myLCSList.push_back(WPlaneToLCS(geomObj));
2779       ComboBox1->addItem(geomObj->GetName());
2780     }
2781   }
2782 }
2783
2784 //=================================================================================
2785 // function : WPlaneToLCS ( aWPlane )
2786 // purpose  : 
2787 //=================================================================================
2788 gp_Ax3 EntityGUI_SketcherDlg::WPlaneToLCS( GEOM::GEOM_Object_var geomObj )
2789 {
2790   TopoDS_Shape aShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), geomObj);
2791   
2792   gp_Ax3 aLCS;
2793   if (CORBA::is_nil( geomObj ) || aShape.IsNull())
2794   {
2795     MESSAGE("CORBA::is_nil( geomObj ) || aShape.IsNull()")
2796   }
2797   aLCS.Transform(aShape.Location().Transformation());
2798   if (aShape.ShapeType() == TopAbs_FACE) 
2799   {
2800     GEOM::GEOM_IMeasureOperations_ptr aMeasureOp =
2801     myGeometryGUI->GetGeomGen()->GetIMeasureOperations( getStudyId() );
2802     double Ox, Oy, Oz, Zx, Zy, Zz, Xx, Xy, Xz;
2803     aMeasureOp->GetPosition( geomObj, Ox, Oy, Oz, Zx, Zy, Zz, Xx, Xy, Xz);
2804     if ( aMeasureOp->IsDone() )
2805     {  
2806       gp_Pnt aPnt ( Ox, Oy, Oz );
2807       gp_Dir aDirN ( Zx, Zy, Zz );
2808       gp_Dir aDirX ( Xx, Xy, Xz );
2809       aLCS = gp_Ax3( aPnt, aDirN, aDirX );
2810     }
2811   }
2812   return aLCS;
2813 }
2814
2815
2816 //=================================================================================
2817 // function : getPnt1ConstructorId()
2818 // purpose  :
2819 //=================================================================================
2820 int EntityGUI_SketcherDlg::getPnt1ConstructorId() const
2821
2822   int buttonId = GroupPt->ButtonGroup->checkedId(); 
2823 //   MESSAGE("buttonId = "<<buttonId)
2824   return buttonId;
2825 }
2826
2827 //=================================================================================
2828 // function : getPnt2ConstructorId()
2829 // purpose  :
2830 //=================================================================================
2831 int EntityGUI_SketcherDlg::getPnt2ConstructorId() const
2832
2833   int buttonId = GroupPt2->ButtonGroup->checkedId(); 
2834 //   MESSAGE("buttonId = "<<buttonId)
2835   return buttonId;
2836 }
2837
2838 //=================================================================================
2839 // function : GetActiveLocalCS()
2840 // purpose  : Get Working plane
2841 //=================================================================================
2842 gp_Ax3 EntityGUI_SketcherDlg::GetActiveLocalCS()
2843 {
2844   int ind = ComboBox1->currentIndex();
2845   if (ind == -1)
2846     return myGeometryGUI->GetWorkingPlane();
2847   
2848   gp_Ax3 aLCS = myLCSList.at(ind);
2849   myWPlane = myWPlaneList.at(ind);
2850
2851   return aLCS;
2852 }
2853
2854 //=================================================================================
2855 // function : ActivateLocalCS()
2856 // purpose  : Activate & Fit Working plane
2857 //=================================================================================
2858 void EntityGUI_SketcherDlg::ActivateLocalCS()
2859 {
2860   myGeometryGUI->SetWorkingPlane( GetActiveLocalCS() );
2861   myGeometryGUI->ActiveWorkingPlane();
2862 }
2863
2864 //=================================================================================
2865 // function : addSubshapeToStudy
2866 // purpose  : virtual method to add new SubObjects if local selection
2867 //=================================================================================
2868 void EntityGUI_SketcherDlg::addSubshapesToStudy()
2869 {
2870   GEOMBase::PublishSubObject(myWPlane);
2871 }