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