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