]> SALOME platform Git repositories - modules/geom.git/blob - src/EntityGUI/EntityGUI_SketcherDlg.cxx
Salome HOME
d1a4ff9e8ef76aa952068266c5347d210737500f
[modules/geom.git] / src / EntityGUI / EntityGUI_SketcherDlg.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : EntityGUI_SketcherDlg.cxx
25 // Author : Damien COQUERET, Open CASCADE S.A.S.
26 //
27 #include "EntityGUI_SketcherDlg.h"
28 #include "EntityGUI_Widgets.h"
29 #include <SalomeApp_DoubleSpinBox.h>
30
31 #include <GEOMBase.h>
32 #include <GeometryGUI.h>
33 #include <GEOMImpl_Types.hxx>
34 #include <Geom_Surface.hxx>
35 #include <Geom_Plane.hxx>
36
37 #include <SUIT_Desktop.h>
38 #include <SUIT_Session.h>
39 #include <SUIT_MessageBox.h>
40 #include <SUIT_ResourceMgr.h>
41 #include <SalomeApp_Application.h>
42 #include <LightApp_Application.h>
43 #include <LightApp_SelectionMgr.h>
44
45 #include <QKeyEvent>
46
47 #include <BRep_Tool.hxx>
48 #include <TopExp.hxx>
49 #include <TopExp_Explorer.hxx>
50 #include <TopoDS_Vertex.hxx>
51 #include <TopoDS.hxx>
52 #include <BRepBuilderAPI_Transform.hxx>
53 #include <BRepBuilderAPI_MakeWire.hxx>
54 #include <Sketcher_Profile.hxx>
55
56 #include <SalomeApp_Study.h>
57
58 #include <gp_Pln.hxx>
59
60 //=================================================================================
61 // class    : EntityGUI_SketcherDlg()
62 // purpose  : Constructs a EntityGUI_SketcherDlg which is a child of 'parent', with the
63 //            name 'name' and widget flags set to 'f'.
64 //            The dialog will by default be modeless, unless you set 'modal' to
65 //            TRUE to construct a modal dialog.
66 //=================================================================================
67 EntityGUI_SketcherDlg::EntityGUI_SketcherDlg( GeometryGUI* GUI, QWidget* parent,
68                                               bool modal, Qt::WindowFlags fl,
69                                               const double lineWidth )
70   : QDialog( parent, fl ),
71     myIsAllAdded( false ),
72     myIsApply( false ),
73     GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
74     myGeometryGUI( GUI ),
75     myLineWidth( lineWidth )
76 {
77   setModal( modal );
78   setAttribute( Qt::WA_DeleteOnClose );
79
80   myGeometryGUI->SetActiveDialogBox(this);
81
82   MainWidget = new EntityGUI_Skeleton( this );
83   QVBoxLayout* topLayout = new QVBoxLayout( this );
84   topLayout->setMargin( 9 ); topLayout->setSpacing( 6 );
85
86   MainWidget->buttonCancel->setText( tr( "GEOM_BUT_CANCEL" ) );
87   MainWidget->buttonEnd->setText( tr( "GEOM_BUT_END_SKETCH" ) );
88   MainWidget->buttonClose->setText( tr( "GEOM_BUT_CLOSE_SKETCH" ) );
89   MainWidget->buttonHelp->setText( tr( "GEOM_BUT_HELP" ) );
90
91   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
92   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_UNDO" ) ) );
93   QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_REDO" ) ) );
94
95   setWindowTitle( tr( "GEOM_SKETCHER_TITLE" ) );
96
97   MainWidget->GroupConstructors->setTitle( tr( "GEOM_SKETCHER_EL" ) );
98   MainWidget->RadioButton1->setText( tr( "GEOM_SKETCHER_SEGMENT" ) );
99   MainWidget->RadioButton2->setText( tr( "GEOM_SKETCHER_ARC" ) );
100   MainWidget->GroupDest->setTitle( tr( "GEOM_SKETCHER_DEST" ) );
101   MainWidget->GroupDest1->setTitle( tr( "GEOM_SKETCHER_TYPE" ) );
102   MainWidget->RB_Dest1->setText( tr( "GEOM_SKETCHER_POINT" ) );
103   MainWidget->RB_Dest2->setText( tr( "GEOM_SKETCHER_DIR" ) );
104
105   /***************************************************************/
106
107   GroupBox1 = new QGroupBox(tr("GEOM_CS"), this);
108   QGridLayout* OwnLayout = new QGridLayout(GroupBox1);
109   OwnLayout->setSpacing(6);
110   OwnLayout->setMargin(11);
111
112   ComboBox1 = new QComboBox(GroupBox1);
113   OwnLayout->addWidget(ComboBox1);
114
115   topLayout->addWidget(GroupBox1);
116   topLayout->addWidget( MainWidget );
117
118   GroupPt = new EntityGUI_Point( MainWidget->DestCnt );
119
120   GroupPt->GroupPoint->setTitle( tr( "GEOM_SKETCHER_POINT" ) );
121   GroupPt->RB_Point1->setText( tr( "GEOM_SKETCHER_ABS" ) );
122   GroupPt->RB_Point2->setText( tr( "GEOM_SKETCHER_REL" ) );
123   GroupPt->RB_Point3->setText( tr( "GEOM_SKETCHER_SEL" ) );
124
125   GroupD1 = new EntityGUI_Dir1( MainWidget->DestCnt );
126
127   GroupD1->GroupDir1->setTitle( tr( "GEOM_SKETCHER_DIR" ) );
128   GroupD1->RB_Dir11->setText( tr( "GEOM_SKETCHER_ANGLE" ) );
129   GroupD1->RB_Dir12->setText( tr( "GEOM_SKETCHER_PER" ) );
130   GroupD1->RB_Dir13->setText( tr( "GEOM_SKETCHER_TAN" ) );
131   GroupD1->RB_Dir14->setText( tr( "GEOM_SKETCHER_VXVY" ) );
132
133   GroupD2 = new EntityGUI_Dir2( MainWidget->DestCnt );
134
135   GroupD2->GroupDir2->setTitle( tr( "GEOM_SKETCHER_DIR" ) );
136   GroupD2->RB_Dir21->setText( tr( "GEOM_SKETCHER_LENGTH" ) );
137   GroupD2->RB_Dir22->setText( tr( "GEOM_SKETCHER_X" ) );
138   GroupD2->RB_Dir23->setText( tr( "GEOM_SKETCHER_Y" ) );
139
140   Group1Sel = new EntityGUI_1Sel( MainWidget->SkeletonCnt );
141
142   Group1Sel->TextLabel1->setText( tr( "GEOM_SKETCHER_POINT2" ) );
143   Group1Sel->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
144   Group1Sel->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
145   Group1Sel->PushButton1->setIcon( image0 );
146   Group1Sel->buttonUndo->setIcon( image1 );
147   Group1Sel->buttonRedo->setIcon( image2 );
148   Group1Sel->LineEdit1->setReadOnly( true );
149
150   Group1Spin = new EntityGUI_1Spin( MainWidget->SkeletonCnt );
151   Group1Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
152   Group1Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
153   Group1Spin->buttonUndo->setIcon( image1 );
154   Group1Spin->buttonRedo->setIcon( image2 );
155
156   Group2Spin = new EntityGUI_2Spin( MainWidget->SkeletonCnt );
157   Group2Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
158   Group2Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
159   Group2Spin->buttonUndo->setIcon( image1 );
160   Group2Spin->buttonRedo->setIcon( image2 );
161
162   Group3Spin = new EntityGUI_3Spin( MainWidget->SkeletonCnt );
163   Group3Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
164   Group3Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
165   Group3Spin->buttonUndo->setIcon( image1 );
166   Group3Spin->buttonRedo->setIcon( image2 );
167
168   Group4Spin = new EntityGUI_4Spin( MainWidget->SkeletonCnt );
169   Group4Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
170   Group4Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
171   Group4Spin->buttonUndo->setIcon( image1 );
172   Group4Spin->buttonRedo->setIcon( image2 );
173
174   QGridLayout* DestCntLayout = new QGridLayout( MainWidget->DestCnt );
175   DestCntLayout->setMargin( 0 ); DestCntLayout->setSpacing( 6 );
176   DestCntLayout->addWidget( GroupPt, 0, 0, 1, 2 );
177   DestCntLayout->addWidget( GroupD1, 1, 0 );
178   DestCntLayout->addWidget( GroupD2, 1, 1 );
179
180   QVBoxLayout* SkeletonCntlayout = new QVBoxLayout( MainWidget->SkeletonCnt );
181   SkeletonCntlayout->setMargin( 0 ); SkeletonCntlayout->setSpacing( 6 );
182   SkeletonCntlayout->addWidget( Group1Sel,  0, 0 );
183   SkeletonCntlayout->addWidget( Group1Spin, 0, 0 );
184   SkeletonCntlayout->addWidget( Group2Spin, 0, 0 );
185   SkeletonCntlayout->addWidget( Group3Spin, 0, 0 );
186   SkeletonCntlayout->addWidget( Group4Spin, 0, 0 );
187   /***************************************************************/
188
189   QButtonGroup* ButtonGroup = new QButtonGroup( this );
190   ButtonGroup->addButton( MainWidget->RB_Dest1, 1 );
191   ButtonGroup->addButton( MainWidget->RB_Dest2, 0 );
192
193   /* signals and slots connections */
194   connect( MainWidget->buttonEnd,    SIGNAL( clicked() ), this, SLOT( ClickOnEnd() ) );
195   connect( MainWidget->buttonClose,  SIGNAL( clicked() ), this, SLOT( ClickOnEnd() ) );
196   connect( MainWidget->buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
197   connect( MainWidget->buttonHelp,   SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
198
199   connect( Group1Sel->buttonApply,   SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
200   connect( Group1Sel->buttonUndo,    SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
201   connect( Group1Sel->buttonRedo,    SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
202   connect( Group1Spin->buttonApply,  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
203   connect( Group1Spin->buttonUndo,   SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
204   connect( Group1Spin->buttonRedo,   SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
205   connect( Group2Spin->buttonApply,  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
206   connect( Group2Spin->buttonUndo,   SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
207   connect( Group2Spin->buttonRedo,   SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
208   connect( Group3Spin->buttonApply,  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
209   connect( Group3Spin->buttonUndo,   SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
210   connect( Group3Spin->buttonRedo,   SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) ) ;
211   connect( Group4Spin->buttonApply,  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
212   connect( Group4Spin->buttonUndo,   SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
213   connect( Group4Spin->buttonRedo,   SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
214
215   connect( MainWidget->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( TypeClicked( int ) ) );
216   connect( ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( DestClicked( int ) ) );
217   connect( GroupPt->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( PointClicked( int ) ) );
218   connect( GroupD1->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( Dir1Clicked( int ) ) );
219   connect( GroupD2->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( Dir2Clicked( int ) ));
220
221   connect( Group1Sel->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
222   connect( Group1Sel->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
223
224   connect( Group1Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
225   connect( Group2Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
226   connect( Group2Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
227   connect( Group3Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
228   connect( Group3Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
229   connect( Group3Spin->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
230   connect( Group4Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
231   connect( Group4Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
232   connect( Group4Spin->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
233   connect( Group4Spin->SpinBox_DS, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
234
235   connect( ComboBox1, SIGNAL( activated( int ) ), this, SLOT( SelectionIntoArgument() ) );
236
237   connect( myGeometryGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
238
239   connect( myGeometryGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
240   connect( myGeometryGUI, SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
241   
242   // install event filter on spin-boxes to provide Apply action on Return pressed
243   Group1Spin->SpinBox_DX->installEventFilter(this);
244   Group2Spin->SpinBox_DX->installEventFilter(this);
245   Group2Spin->SpinBox_DY->installEventFilter(this);
246   Group3Spin->SpinBox_DX->installEventFilter(this);
247   Group3Spin->SpinBox_DY->installEventFilter(this);
248   Group3Spin->SpinBox_DZ->installEventFilter(this);
249   Group4Spin->SpinBox_DX->installEventFilter(this);
250   Group4Spin->SpinBox_DY->installEventFilter(this);
251   Group4Spin->SpinBox_DZ->installEventFilter(this);
252   Group4Spin->SpinBox_DS->installEventFilter(this);
253
254   Init();
255 }
256
257
258 //=================================================================================
259 // function : ~EntityGUI_SketcherDlg()
260 // purpose  : Destroys the object and frees any allocated resources
261 //=================================================================================
262 EntityGUI_SketcherDlg::~EntityGUI_SketcherDlg()
263 {
264   myGeometryGUI->SetActiveDialogBox( 0 );
265 }
266
267
268 //=================================================================================
269 // function : eventFilter()
270 // purpose  : event filter for spin-boxes to provide Apply action on Return pressed
271 //=================================================================================
272 bool EntityGUI_SketcherDlg::eventFilter (QObject* object, QEvent* event)
273 {
274   if (event->type() == QEvent::KeyPress) {
275     QKeyEvent* ke = (QKeyEvent*)event;
276     if (ke->key() == Qt::Key_Return) {
277       if (object == Group1Spin->SpinBox_DX) {
278         Group1Spin->buttonApply->animateClick();
279         return true;
280       } else if (object == Group2Spin->SpinBox_DX ||
281                  object == Group2Spin->SpinBox_DY) {
282         Group2Spin->buttonApply->animateClick();
283         return true;
284       } else if (object == Group3Spin->SpinBox_DX ||
285                  object == Group3Spin->SpinBox_DY ||
286                  object == Group3Spin->SpinBox_DZ) {
287         Group3Spin->buttonApply->animateClick();
288         return true;
289       } else if (object == Group4Spin->SpinBox_DX ||
290                  object == Group4Spin->SpinBox_DY ||
291                  object == Group4Spin->SpinBox_DZ ||
292                  object == Group4Spin->SpinBox_DS) {
293         Group4Spin->buttonApply->animateClick();
294         return true;
295       }
296     }
297   }
298
299   // Fix of the NPAL16010 bug is removed, because it's not actual with the Qt-4.x
300
301   return QDialog::eventFilter(object, event);
302 }
303
304
305 //=================================================================================
306 // function : Init()
307 // purpose  :
308 //=================================================================================
309 void EntityGUI_SketcherDlg::Init()
310 {
311   /* init variables */
312   myEditCurrentArgument = Group1Sel->LineEdit1;
313   myCommand.append( "Sketcher" );
314   myUndoCommand.append( "Sketcher" );
315
316   mySketchState = FIRST_POINT;
317   globalSelection( GEOM_POINT );
318
319   myLastX1 = 0.0;
320   myLastY1 = 0.0;
321   myLastX2 = 0.0;
322   myLastY2 = 0.0;
323
324   myHelpFileName = "create_sketcher_page.html";
325
326   /* Get setting of step value from file configuration */
327   double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
328
329   /* min, max, step and decimals for spin boxes */
330   initSpinBox( Group1Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
331   initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
332   initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
333   initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
334   initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
335   initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
336   initSpinBox( Group4Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
337   // san: Note specific step values below!
338   initSpinBox( Group4Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
339   initSpinBox( Group4Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
340   initSpinBox( Group4Spin->SpinBox_DS, COORD_MIN, COORD_MAX, 5., "length_precision" );
341
342   /* displays Dialog */
343   MainWidget->GroupConstructors->setEnabled( false );
344   MainWidget->GroupDest1->setEnabled( false );
345   setEnabledUndo( false );
346   setEnabledRedo( false );
347
348   MainWidget->RadioButton1->setChecked( true );
349
350   TypeClicked( 0 );
351
352   FindLocalCS();
353   resize(100,100);
354
355
356   GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
357 }
358
359
360 //=================================================================================
361 // function : InitClick()
362 // purpose  :
363 //=================================================================================
364 void EntityGUI_SketcherDlg::InitClick()
365 {
366   disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
367
368   Group1Sel->hide();
369   Group1Spin->hide();
370   Group2Spin->hide();
371   Group3Spin->hide();
372   Group4Spin->hide();
373 }
374
375
376 //=================================================================================
377 // function : TypeClicked()
378 // purpose  : Radio button management
379 //=================================================================================
380 void EntityGUI_SketcherDlg::TypeClicked( int constructorId )
381 {
382   myConstructorId = constructorId;
383   if ( myConstructorId == 0 ) {    // SEGMENT
384     GroupD2->setEnabled( true );
385     MainWidget->RB_Dest1->setEnabled( true );
386     MainWidget->RB_Dest1->setChecked( true );
387     DestClicked( 1 );
388   }
389   else if (  myConstructorId == 1 ) { // ARC
390     GroupD2->setEnabled( false );
391     MainWidget->RB_Dest1->setEnabled( false );
392     MainWidget->RB_Dest2->setChecked( true );
393     DestClicked( 0 );
394   }
395 }
396
397
398 //=================================================================================
399 // function : DestClicked()
400 // purpose  : Radio button management
401 //=================================================================================
402 void EntityGUI_SketcherDlg::DestClicked( int constructorId )
403 {
404   GroupPt->hide();
405   GroupD1->hide();
406   GroupD2->hide();
407
408   if ( constructorId == 1 ) {
409     // Point
410     GroupPt->RB_Point1->setChecked( true );
411     GroupPt->show();
412     PointClicked( 1 );  // XY
413   }
414   else if (  constructorId == 0 ) {
415     // Direction
416     GroupD1->RB_Dir11->setChecked( true );
417     GroupD1->show();
418     GroupD2->show();
419     Dir1Clicked( 2 );  // Angle
420   }
421 }
422
423
424 //=================================================================================
425 // function : PointClicked()
426 // purpose  : Radio button management
427 //=================================================================================
428 void EntityGUI_SketcherDlg::PointClicked( int constructorId )
429 {
430   InitClick();
431
432   // Get setting of step value from file configuration
433   double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
434
435   if ( myConstructorId == 0 ) {  // SEGMENT
436     if ( constructorId == 1 ) {  // XY
437       mySketchType = PT_ABS;
438       initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
439       initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
440       Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X2" ) );
441       Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y2" ) );
442       myX = 0.0;
443       Group2Spin->SpinBox_DX->setValue( myX );
444       myY = 0.0;
445       Group2Spin->SpinBox_DY->setValue( myY );
446       Group2Spin->show();
447       Group2Spin->buttonApply->setFocus();
448
449       GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
450     }
451     else if ( constructorId == 0 ) {  // DXDY
452       mySketchType = PT_RELATIVE;
453       initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
454       initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
455       Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_DX2" ) );
456       Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_DY2" ) );
457       myDX = 0.0;
458       Group2Spin->SpinBox_DX->setValue( myDX );
459       myDY = 0.0;
460       Group2Spin->SpinBox_DY->setValue( myDY );
461       Group2Spin->show();
462       Group2Spin->buttonApply->setFocus();
463
464       GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
465     }
466     else if ( constructorId == 2 ) {  // Selection
467       mySketchType = PT_SEL;
468       myEditCurrentArgument = Group1Sel->LineEdit1;
469       Group1Sel->show();
470       Group1Sel->buttonApply->setFocus();
471       SelectionIntoArgument();
472     }
473
474     connect( myGeometryGUI->getApp()->selectionMgr(),
475              SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
476   }
477 }
478
479
480 //=================================================================================
481 // function : Dir1Clicked()
482 // purpose  : Radio button management
483 //=================================================================================
484 void EntityGUI_SketcherDlg::Dir1Clicked( int constructorId )
485 {
486   myConstructorDirId = constructorId;
487   GroupD2->RB_Dir21->setChecked( true );
488   Dir2Clicked( 2 );
489 }
490
491
492 //=================================================================================
493 // function : Dir2Clicked()
494 // purpose  : Radio button management
495 //=================================================================================
496 void EntityGUI_SketcherDlg::Dir2Clicked( int constructorId )
497 {
498   InitClick();
499   myAngle = 0.0;
500
501   // Get setting of step value from file configuration
502   double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
503
504   if ( myConstructorId == 0 ) {  // SEGMENT
505     myX = 0.0;
506     myY = 0.0;
507     myLength = 100.0;
508     if ( myConstructorDirId == 2 ) {  // Angle
509       initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 5., "length_precision" );
510       Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
511       Group2Spin->SpinBox_DX->setValue( myAngle );
512       Group2Spin->buttonApply->setFocus();
513       Group2Spin->show();
514
515       if ( constructorId == 2 ) {  // Length
516         mySketchType = DIR_ANGLE_LENGTH;
517         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
518         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
519         Group2Spin->SpinBox_DY->setValue( myLength );
520       }
521       else if ( constructorId == 0 ) {  // X
522         mySketchType = DIR_ANGLE_X;
523         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "angle_precision" );
524         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_X3" ) );
525         Group2Spin->SpinBox_DY->setValue( myX );
526       }
527       else if ( constructorId == 1 ) {  // Y
528         mySketchType = DIR_ANGLE_Y;
529         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "angle_precision" );        
530         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y3" ) );
531         Group2Spin->SpinBox_DY->setValue( myY );
532       }
533     }
534     else if ( myConstructorDirId == 0 ) {  // Perpendicular
535       Group1Spin->show();
536       Group1Spin->buttonApply->setFocus();
537
538       if ( constructorId == 2 ) {  // Length
539         mySketchType = DIR_PER_LENGTH;
540         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
541         Group1Spin->SpinBox_DX->setValue( myLength );
542       }
543       else if ( constructorId == 0 ) {  // X
544         mySketchType = DIR_PER_X;
545         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X3" ) );
546         Group1Spin->SpinBox_DX->setValue( myX );
547       }
548       else if ( constructorId == 1 ) {  // Y
549         mySketchType = DIR_PER_Y;
550         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_Y3" ) );
551         Group1Spin->SpinBox_DX->setValue( myY );
552       }
553     }
554     else if ( myConstructorDirId == 1 ) {  // Tangent
555       Group1Spin->show();
556       Group1Spin->buttonApply->setFocus();
557
558       if ( constructorId == 2 ) {  // Length
559         mySketchType = DIR_TAN_LENGTH;
560         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
561         Group1Spin->SpinBox_DX->setValue( myLength );
562       }
563       else if ( constructorId == 0 ) {  // X
564         mySketchType = DIR_TAN_X;
565         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X3" ) );
566         Group1Spin->SpinBox_DX->setValue( myX );
567       }
568       else if ( constructorId == 1 ) {  // Y
569         mySketchType = DIR_TAN_Y;
570         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_Y3" ) );
571         Group1Spin->SpinBox_DX->setValue( myY );
572       }
573     }
574     else if ( myConstructorDirId == 3 ) {  // DXDY
575       initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
576       initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
577       initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
578       Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_VX2" ) );
579       Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_VY2" ) );
580       myDX = 0.0;
581       Group3Spin->SpinBox_DX->setValue( myDX );
582       myDY = 0.0;
583       Group3Spin->SpinBox_DY->setValue( myDY );
584       Group3Spin->show();
585       Group3Spin->buttonApply->setFocus();
586
587       if ( constructorId == 2 ) {  // Length
588         mySketchType = DIR_DXDY_LENGTH;
589         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
590         Group3Spin->SpinBox_DZ->setValue( myLength );
591       }
592       else if ( constructorId == 0 ) { // X
593         mySketchType = DIR_DXDY_X;
594         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_X3" ) );
595         Group3Spin->SpinBox_DZ->setValue( myX );
596       }
597       else if ( constructorId == 1 ) {  // Y
598         mySketchType = DIR_DXDY_Y;
599         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_Y3" ) );
600         Group3Spin->SpinBox_DZ->setValue( myY );
601       }
602     }
603   }
604   else if ( myConstructorId == 1 ) {  // ARC
605     if ( myConstructorDirId == 2 ) {  // Angle
606       if ( constructorId == 2 ) {  // Length
607         mySketchType = DIR_ANGLE_LENGTH;
608         initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 5., "angle_precision" );
609         initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
610         initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, 5., "angle_precision" );
611         Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
612         Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
613         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_ANGLE2" ));
614         Group3Spin->SpinBox_DX->setValue( myAngle );
615         myRadius = 100.0;
616         Group3Spin->SpinBox_DY->setValue( myRadius );
617         myLength = 30.0;
618         Group3Spin->SpinBox_DZ->setValue( myLength );
619         Group3Spin->show();
620         Group3Spin->buttonApply->setFocus();
621       }
622     }
623     else if ( myConstructorDirId == 0 ) {  // Perpendicular
624       if ( constructorId == 2 ) {  // Length
625         mySketchType = DIR_PER_LENGTH;
626         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
627         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 5., "angle_precision" );
628         Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
629         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
630         myRadius = 100.0;
631         Group2Spin->SpinBox_DX->setValue( myRadius );
632         myLength = 30.0;
633         Group2Spin->SpinBox_DY->setValue( myLength );
634         Group2Spin->show();
635         Group2Spin->buttonApply->setFocus();
636       }
637     }
638     else if ( myConstructorDirId == 1 ) {  // Tangent
639       if ( constructorId == 2 ) {  // Length
640         mySketchType = DIR_TAN_LENGTH;
641         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
642         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 5., "angle_precision" );
643         Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
644         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
645         myRadius = 100.0;
646         Group2Spin->SpinBox_DX->setValue( myRadius );
647         myLength = 30.0;
648         Group2Spin->SpinBox_DY->setValue( myLength );
649         Group2Spin->show();
650         Group2Spin->buttonApply->setFocus();
651       }
652     }
653     else if ( myConstructorDirId == 3 ) {  // DXDY
654       if ( constructorId == 2 ) {  // Length
655         mySketchType = DIR_DXDY_LENGTH;
656         Group4Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_VX2" ) );
657         Group4Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_VY2" ) );
658         Group4Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
659         Group4Spin->TextLabel4->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
660         myDX = 0.0;
661         Group4Spin->SpinBox_DX->setValue( myDX );
662         myDY = 0.0;
663         Group4Spin->SpinBox_DY->setValue( myDY );
664         myRadius = 100.0;
665         Group4Spin->SpinBox_DZ->setValue( myRadius );
666         myLength = 30.0;
667         Group4Spin->SpinBox_DS->setValue( myLength );
668         Group4Spin->show();
669         Group4Spin->buttonApply->setFocus();
670       }
671     }
672   }
673
674   GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
675 }
676
677
678 //=================================================================================
679 // function : ClickOnCancel()
680 // purpose  :
681 //=================================================================================
682 void EntityGUI_SketcherDlg::ClickOnCancel()
683 {
684   close();
685 }
686
687
688 //=================================================================================
689 // function : ClickOnEnd()
690 // purpose  : connected to buttonEnd AND buttonClose
691 //=================================================================================
692 void EntityGUI_SketcherDlg::ClickOnEnd()
693 {
694   if ( sender() == MainWidget->buttonClose ) {
695     // Verify validity of commands
696     if ( myCommand.count() <= 2 ) {
697       SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
698                                  tr( "GEOM_ERROR_STATUS" ), tr( "CANNOT_CLOSE" ), tr( "BUT_OK" ) );
699       return;
700     }
701
702     QString Parameters;
703     QString Command = myCommand.join( "" ) + GetNewCommand( Parameters );
704     Sketcher_Profile aProfile( Command.toAscii() );
705
706     Command = myCommand.join( "" );
707     aProfile = Sketcher_Profile( Command.toAscii() );
708     TopoDS_Shape myShape;
709     if ( aProfile.IsDone() )
710       myShape = aProfile.GetShape();
711
712     if ( myShape.ShapeType() != TopAbs_VERTEX )
713       myCommand.append( ":WW" );
714   }
715   else {
716     // PAL16008 (Sketcher Validation should be equal to Apply&Close)
717     if ( Group1Spin->buttonApply->isEnabled() && Group1Spin->isVisible() ||
718          Group2Spin->buttonApply->isEnabled() && Group2Spin->isVisible() ||
719          Group3Spin->buttonApply->isEnabled() && Group3Spin->isVisible() ||
720          Group4Spin->buttonApply->isEnabled() && Group4Spin->isVisible() ||
721          Group1Sel ->buttonApply->isEnabled() && Group1Sel->isVisible() ) {
722       ClickOnApply();
723     }
724     myIsAllAdded = true;
725   }
726
727   if ( myCommand.size() > 2 )
728     if ( !onAccept() )
729       return;
730
731   close();
732 }
733
734 //=================================================================================
735 // function : ClickOnApply()
736 // purpose  :
737 //=================================================================================
738 bool EntityGUI_SketcherDlg::ClickOnApply()
739 {
740   if ( sender() && sender()->inherits( "QPushButton" ) )
741     ( (QPushButton*)sender() )->setFocus(); // to update value of currently edited spin-box (PAL11948)
742
743   QString aParameters;
744   myCommand.append( GetNewCommand( aParameters ) );
745   mySketchState = NEXT_POINT;
746
747   myUndoCommand.clear();
748   myUndoCommand.append( "Sketcher" );
749
750   myParameters.append( aParameters );
751   myUndoParameters.clear();
752
753   MainWidget->GroupConstructors->setEnabled( true );
754   MainWidget->GroupDest1->setEnabled( true );
755   setEnabledUndo( true );
756   setEnabledRedo( false );
757
758   myIsApply = true;
759   GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
760   myIsApply = false;
761
762   // Set focus to SpinBox_DX
763   if ( sender() == Group1Spin->buttonApply ) {
764     (Group1Spin->SpinBox_DX)->setFocus();
765     (Group1Spin->SpinBox_DX)->selectAll();
766   }
767   else if ( sender() == Group2Spin->buttonApply ) {
768     (Group2Spin->SpinBox_DX)->setFocus();
769     (Group2Spin->SpinBox_DX)->selectAll();
770   }
771   else if ( sender() == Group3Spin->buttonApply ) {
772     (Group3Spin->SpinBox_DX)->setFocus();
773     (Group3Spin->SpinBox_DX)->selectAll();
774   }
775   else if ( sender() == Group4Spin->buttonApply ) {
776     (Group4Spin->SpinBox_DX)->setFocus();
777     (Group4Spin->SpinBox_DX)->selectAll();
778   }
779
780   return true;
781 }
782
783 //=================================================================================
784 // function : ClickOnHelp()
785 // purpose  :
786 //=================================================================================
787 void EntityGUI_SketcherDlg::ClickOnHelp()
788 {
789   LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
790   if ( app )
791     app->onHelpContextModule( myGeometryGUI ? app->moduleName( myGeometryGUI->moduleName() ) : QString( "" ), myHelpFileName );
792   else {
793     QString platform;
794 #ifdef WIN32
795     platform = "winapplication";
796 #else
797     platform = "application";
798 #endif
799
800     SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
801                               QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
802                               arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
803                               QObject::tr( "BUT_OK" ) );
804   }
805 }
806
807 //=================================================================================
808 // function : ClickOnUndo()
809 // purpose  :
810 //=================================================================================
811 void EntityGUI_SketcherDlg::ClickOnUndo()
812 {
813   myUndoCommand.append( myCommand.last() );
814   myCommand.pop_back();
815
816   myUndoParameters.append( myParameters.last() );
817   myParameters.pop_back();
818
819   if ( myCommand.count() == 1 ) {
820     mySketchState = FIRST_POINT;
821
822     MainWidget->RadioButton1->setChecked( true );
823     TypeClicked( 0 );
824
825     connect( myGeometryGUI->getApp()->selectionMgr(),
826              SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
827
828     MainWidget->GroupConstructors->setEnabled( false );
829     MainWidget->GroupDest1->setEnabled( false );
830     setEnabledUndo( false );
831   }
832
833   setEnabledRedo( true );
834
835   GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
836 }
837
838 //=================================================================================
839 // function : ClickOnRedo()
840 // purpose  :
841 //=================================================================================
842 void EntityGUI_SketcherDlg::ClickOnRedo()
843 {
844   myCommand.append( myUndoCommand.last() );
845   myUndoCommand.pop_back();
846
847   myParameters.append( myUndoParameters.last() );
848   myUndoParameters.pop_back();
849
850   mySketchState = NEXT_POINT;
851
852   MainWidget->GroupConstructors->setEnabled( true );
853   MainWidget->GroupDest1->setEnabled( true );
854   setEnabledUndo( true );
855
856   if ( myUndoCommand.count() == 1 )
857     setEnabledRedo( false );
858
859   GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
860 }
861
862 //=================================================================================
863 // function : setEnabledUndo()
864 // purpose  :
865 //=================================================================================
866 void EntityGUI_SketcherDlg::setEnabledUndo( bool value )
867 {
868   Group1Sel->buttonUndo->setEnabled( value );
869   Group1Spin->buttonUndo->setEnabled( value );
870   Group2Spin->buttonUndo->setEnabled( value );
871   Group3Spin->buttonUndo->setEnabled( value );
872   Group4Spin->buttonUndo->setEnabled( value );
873 }
874
875 //=================================================================================
876 // function : setEnabledRedo()
877 // purpose  :
878 //=================================================================================
879 void EntityGUI_SketcherDlg::setEnabledRedo( bool value )
880 {
881   Group1Sel->buttonRedo->setEnabled( value );
882   Group1Spin->buttonRedo->setEnabled( value );
883   Group2Spin->buttonRedo->setEnabled( value );
884   Group3Spin->buttonRedo->setEnabled( value );
885   Group4Spin->buttonRedo->setEnabled( value );
886 }
887
888 //=================================================================================
889 // function : SelectionIntoArgument()
890 // purpose  : Called when selection as changed
891 //=================================================================================
892 void EntityGUI_SketcherDlg::SelectionIntoArgument()
893 {
894   myEditCurrentArgument->setText( "" );
895   double tmpX = myX;
896   double tmpY = myY;
897   myX = myLastX1;
898   myY = myLastY1;
899
900   LightApp_SelectionMgr* aSelMgr = myGeometryGUI->getApp()->selectionMgr();
901   SALOME_ListIO aSelList;
902   aSelMgr->selectedObjects(aSelList);
903
904   int nbSel = aSelList.Extent();
905   if (nbSel == 1 && myEditCurrentArgument == Group1Sel->LineEdit1) {
906     Standard_Boolean aRes = Standard_False;
907     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aRes);
908     if (!CORBA::is_nil(aSelectedObject) && aRes) {
909       TopoDS_Shape aShape;
910       if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_VERTEX)) {
911         gp_Trsf aTrans;
912         gp_Ax3 aWPlane = GetActiveLocalCS();
913
914         aTrans.SetTransformation(aWPlane);
915         BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
916         aShape = aTransformation.Shape();
917
918         gp_Pnt aPnt;
919         if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) {
920           myX = aPnt.X();
921           myY = aPnt.Y();
922           Group1Sel->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
923           if( Group2Spin->isVisible() && mySketchType == PT_ABS ) {
924             disconnect( Group2Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
925             disconnect( Group2Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
926             Group2Spin->SpinBox_DX->setValue(myX);
927             Group2Spin->SpinBox_DY->setValue(myY);
928             connect( Group2Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
929             connect( Group2Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
930           } else if ( Group2Spin->isVisible() && mySketchType == PT_RELATIVE ) {
931             if ( myLastX1 && myLastY1 ) {
932               Group2Spin->SpinBox_DX->setValue(myX - myLastX1);
933               Group2Spin->SpinBox_DY->setValue(myY - myLastY1);
934             } else {
935               if ( mySketchState != FIRST_POINT ) {
936                 Group2Spin->SpinBox_DX->setValue(myX - tmpX);
937                 Group2Spin->SpinBox_DY->setValue(myY - tmpY);
938               } else {
939                 Group2Spin->SpinBox_DX->setValue(myX);
940                 Group2Spin->SpinBox_DY->setValue(myY);
941               }
942             }
943           }
944         }
945       }
946     }
947   }
948
949   GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
950 }
951
952
953 //=================================================================================
954 // function : SetEditCurrentArgument()
955 // purpose  :
956 //=================================================================================
957 void EntityGUI_SketcherDlg::SetEditCurrentArgument()
958 {
959   if ( sender() == Group1Sel->PushButton1 ) {
960     myEditCurrentArgument = Group1Sel->LineEdit1;
961     myEditCurrentArgument->setFocus();
962   }
963   SelectionIntoArgument();
964 }
965
966
967 //=================================================================================
968 // function : LineEditReturnPressed()
969 // purpose  :
970 //=================================================================================
971 void EntityGUI_SketcherDlg::LineEditReturnPressed()
972 {
973   if ( sender() == Group1Sel->LineEdit1 ) {
974     myEditCurrentArgument = Group1Sel->LineEdit1;
975
976     /* User name of object input management                          */
977     /* If successfull the selection is changed and signal emitted... */
978     /* so SelectionIntoArgument() is automatically called.           */
979     const QString objectUserName = myEditCurrentArgument->text();
980     QWidget* thisWidget = (QWidget*)this;
981
982     LightApp_SelectionMgr* aSelMgr = myGeometryGUI->getApp()->selectionMgr();
983     SALOME_ListIO aSelList;
984     aSelMgr->selectedObjects(aSelList);
985
986     if (GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, aSelList))
987       myEditCurrentArgument->setText( objectUserName );
988   }
989 }
990
991
992 //=================================================================================
993 // function : DeactivateActiveDialog()
994 // purpose  :
995 //=================================================================================
996 void EntityGUI_SketcherDlg::DeactivateActiveDialog()
997 {
998   //myGeometryGUI->SetState( -1 );
999
1000   setEnabled( false );
1001   globalSelection();
1002   disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
1003   myGeometryGUI->SetActiveDialogBox( 0 );
1004 }
1005
1006
1007 //=================================================================================
1008 // function : ActivateThisDialog()
1009 // purpose  :
1010 //=================================================================================
1011 void EntityGUI_SketcherDlg::ActivateThisDialog()
1012 {
1013   myGeometryGUI->EmitSignalDeactivateDialog();
1014   setEnabled( true );
1015   myGeometryGUI->SetActiveDialogBox( this );
1016
1017   connect( myGeometryGUI->getApp()->selectionMgr(),
1018           SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
1019
1020   //myGeometryGUI->SetState( 0 );
1021   globalSelection( GEOM_POINT );
1022
1023   myEditCurrentArgument = Group1Sel->LineEdit1;
1024   myEditCurrentArgument->setFocus();
1025
1026   GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
1027 }
1028
1029
1030 //=================================================================================
1031 // function : enterEvent [REDEFINED]
1032 // purpose  :
1033 //=================================================================================
1034 void EntityGUI_SketcherDlg::enterEvent( QEvent* )
1035 {
1036   if ( !MainWidget->GroupConstructors->isEnabled() )
1037     ActivateThisDialog();
1038 }
1039
1040
1041 //=================================================================================
1042 // function : closeEvent()
1043 // purpose  :
1044 //=================================================================================
1045 void EntityGUI_SketcherDlg::closeEvent( QCloseEvent* e )
1046 {
1047   //myGeometryGUI->SetState( -1 );
1048   disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
1049   myGeometryGUI->getApp()->updateActions();
1050   QDialog::closeEvent( e );
1051 }
1052
1053
1054 //=================================================================================
1055 // function : ValueChangedInSpinBox()
1056 // purpose  :
1057 //=================================================================================
1058 void EntityGUI_SketcherDlg::ValueChangedInSpinBox( double newValue )
1059 {
1060   QObject* send = (QObject*)sender();
1061   Standard_Real vx, vy, vz, vs;
1062   vx = vy = vz = vs = 0.0;
1063
1064   QString vxStr, vyStr, vzStr, vsStr;
1065
1066   QString newValueStr;
1067   if( SalomeApp_DoubleSpinBox* aDoubleSpinBox = (SalomeApp_DoubleSpinBox*)send )
1068     newValueStr = aDoubleSpinBox->text();
1069
1070   if ( send == Group1Spin->SpinBox_DX ) {
1071     vx = newValue;                        vxStr = newValueStr;
1072   }
1073   else if ( send == Group2Spin->SpinBox_DX ) {
1074     vx = newValue;                        vxStr = newValueStr;
1075     vy = Group2Spin->SpinBox_DY->value(); vyStr = Group2Spin->SpinBox_DY->text();
1076   }
1077   else if ( send == Group2Spin->SpinBox_DY ) {
1078     vx = Group2Spin->SpinBox_DX->value(); vxStr = Group2Spin->SpinBox_DX->text();
1079     vy = newValue;                        vyStr = newValueStr;
1080   }
1081   else if ( send == Group3Spin->SpinBox_DX ) {
1082     vx = newValue;                        vxStr = newValueStr;
1083     vy = Group3Spin->SpinBox_DY->value(); vyStr = Group3Spin->SpinBox_DY->text();
1084     vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
1085   }
1086   else if ( send == Group3Spin->SpinBox_DY ) {
1087     vx = Group3Spin->SpinBox_DX->value(); vxStr = Group3Spin->SpinBox_DX->text();
1088     vy = newValue;                        vyStr = newValueStr;
1089     vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
1090   }
1091   else if ( send == Group3Spin->SpinBox_DZ ) {
1092     vx = Group3Spin->SpinBox_DX->value(); vxStr = Group3Spin->SpinBox_DX->text();
1093     vy = Group3Spin->SpinBox_DY->value(); vyStr = Group3Spin->SpinBox_DY->text();
1094     vz = newValue;                        vzStr = newValueStr;
1095   }
1096   else if ( send == Group4Spin->SpinBox_DX ) {
1097     vx = newValue;                        vxStr = newValueStr;
1098     vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1099     vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1100     vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1101   }
1102   else if ( send == Group4Spin->SpinBox_DY ) {
1103     vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1104     vy = newValue;                        vyStr = newValueStr;
1105     vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1106     vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1107   }
1108   else if ( send == Group4Spin->SpinBox_DZ ) {
1109     vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1110     vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1111     vz = newValue;                        vzStr = newValueStr;
1112     vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1113   }
1114   else if ( send == Group4Spin->SpinBox_DS ) {
1115     vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1116     vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1117     vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1118     vs = newValue;                        vsStr = newValueStr;
1119   }
1120   // Fix of the NPAL16010 bug is removed, because it's not actual with the Qt-4.x
1121
1122   if ( myConstructorId == 0 ) {  // SEGMENT
1123     if ( mySketchType == PT_ABS ) {
1124       myX = vx;
1125       myY = vy;
1126       myXStr = vxStr;
1127       myYStr = vyStr;
1128     }
1129     else if ( mySketchType == PT_RELATIVE ) {
1130       myDX = vx;
1131       myDY = vy;
1132       myDXStr = vxStr;
1133       myDYStr = vyStr;
1134     }
1135     else if ( mySketchType == DIR_ANGLE_LENGTH ) {
1136       myAngle = vx;
1137       myLength = vy;
1138       myAngleStr = vxStr;
1139       myLengthStr = vyStr;
1140     }
1141     else if ( mySketchType == DIR_ANGLE_X ) {
1142       myAngle = vx;
1143       myX = vy;
1144       myAngleStr = vxStr;
1145       myXStr = vyStr;
1146     }
1147     else if ( mySketchType == DIR_ANGLE_Y ) {
1148       myAngle = vx;
1149       myY = vy;
1150       myAngleStr = vxStr;
1151       myYStr = vyStr;
1152     }
1153     else if ( mySketchType == DIR_PER_LENGTH ) {
1154       myLength = vx;
1155       myLengthStr = vxStr;
1156     }
1157     else if ( mySketchType == DIR_PER_X ) {
1158       myX = vx;
1159       myXStr = vxStr;
1160     }
1161     else if ( mySketchType == DIR_PER_Y ) {
1162       myY = vx;
1163       myYStr = vxStr;
1164     }
1165     else if ( mySketchType == DIR_TAN_LENGTH ) {
1166       myLength = vx;
1167       myLengthStr = vxStr;
1168     }
1169     else if ( mySketchType == DIR_TAN_X ) {
1170       myX = vx;
1171       myXStr = vxStr;
1172     }
1173     else if ( mySketchType == DIR_TAN_Y ) {
1174       myY = vx;
1175       myYStr = vxStr;
1176     }
1177     else if ( mySketchType == DIR_DXDY_LENGTH ) {
1178       myDX = vx;
1179       myDY = vy;
1180       myLength = vz;
1181       myDXStr = vxStr;
1182       myDYStr = vyStr;
1183       myLengthStr = vzStr;
1184     }
1185     else if ( mySketchType == DIR_DXDY_X ) {
1186       myDX = vx;
1187       myDY = vy;
1188       myX = vz;
1189       myDXStr = vxStr;
1190       myDYStr = vyStr;
1191       myXStr = vzStr;
1192     }
1193     else if ( mySketchType == DIR_DXDY_Y ) {
1194       myDX = vx;
1195       myDY = vy;
1196       myY = vz;
1197       myDXStr = vxStr;
1198       myDYStr = vyStr;
1199       myYStr = vzStr;
1200     }
1201   }
1202   else if ( myConstructorId == 1 ) {  // ARC
1203     if ( mySketchType == DIR_ANGLE_LENGTH ) {
1204       myAngle = vx;
1205       myRadius = vy;
1206       myLength = vz;
1207       myAngleStr = vxStr;
1208       myRadiusStr = vyStr;
1209       myLengthStr = vzStr;
1210     }
1211     else if ( mySketchType == DIR_PER_LENGTH ) {
1212       myRadius = vx;
1213       myLength = vy;
1214       myRadiusStr = vxStr;
1215       myLengthStr = vyStr;
1216     }
1217     else if ( mySketchType == DIR_TAN_LENGTH ) {
1218       myRadius = vx;
1219       myLength = vy;
1220       myRadiusStr = vxStr;
1221       myLengthStr = vyStr;
1222     }
1223     else if ( mySketchType == DIR_DXDY_LENGTH ) {
1224       myDX = vx;
1225       myDY = vy;
1226       myRadius = vz;
1227       myLength = vs;
1228       myDXStr = vxStr;
1229       myDYStr = vyStr;
1230       myRadiusStr = vzStr;
1231       myLengthStr = vsStr;
1232     }
1233   }
1234
1235   GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
1236 }
1237
1238
1239 //=================================================================================
1240 // function : GetNewCommand()
1241 // purpose  : Build the new command with context
1242 //=================================================================================
1243 QString EntityGUI_SketcherDlg::GetNewCommand( QString& theParameters )
1244 {
1245   theParameters.clear();
1246   QString myNewCommand = ":";
1247   if ( mySketchState == FIRST_POINT ) {
1248     if ( mySketchType == PT_ABS || mySketchType == PT_SEL ) {
1249       myNewCommand = myNewCommand + "F " + QString::number( myX ) + " " + QString::number( myY );
1250       theParameters = myXStr + ":" + myYStr;
1251     }
1252     if ( mySketchType == PT_RELATIVE) {
1253       myNewCommand = myNewCommand + "F " + QString::number( myDX ) + " " + QString::number( myDY );
1254       theParameters = myDXStr + ":" + myDYStr;
1255     }
1256     return myNewCommand;
1257   }
1258
1259   if ( myConstructorId == 0  ) {  // SEGMENT
1260     if ( mySketchType == PT_ABS || mySketchType == PT_SEL ) {
1261       myNewCommand = myNewCommand + "TT " + QString::number( myX ) + " " + QString::number( myY );
1262       theParameters = myXStr + ":" + myYStr;
1263     }
1264     if ( mySketchType == PT_RELATIVE) {
1265       myNewCommand = myNewCommand + "T " + QString::number( myDX ) + " " + QString::number( myDY );
1266       theParameters = myDXStr + ":" + myDYStr;
1267     }
1268     if ( mySketchType == DIR_ANGLE_LENGTH ) {
1269       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1270       myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength );
1271       theParameters = myAngleStr + ":" + myLengthStr;
1272     }
1273     if ( mySketchType == DIR_ANGLE_X ) {
1274       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1275       myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX );
1276       theParameters = myAngleStr + ":" + myXStr;
1277     }
1278     if ( mySketchType == DIR_ANGLE_Y ) {
1279       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1280       myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY );
1281       theParameters = myAngleStr + ":" + myYStr;
1282     }
1283     if ( mySketchType == DIR_PER_LENGTH ) {
1284       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1285       myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength );
1286       theParameters = QString::number( 90.0 ) + ":" + myLengthStr;
1287     }
1288     if ( mySketchType == DIR_PER_X ) {
1289       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1290       myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX );
1291       theParameters = QString::number( 90.0 ) + ":" + myXStr;
1292     }
1293     if ( mySketchType == DIR_PER_Y ) {
1294       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1295       myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY );
1296       theParameters = QString::number( 90.0 ) + ":" + myYStr;
1297     }
1298     if ( mySketchType == DIR_TAN_LENGTH ) {
1299       myNewCommand = myNewCommand + "L " + QString::number( myLength );
1300       theParameters = myLengthStr;
1301     }
1302     if ( mySketchType == DIR_TAN_X ) {
1303       myNewCommand = myNewCommand + "IX " + QString::number( myX );
1304       theParameters = myXStr;
1305     }
1306     if ( mySketchType == DIR_TAN_Y) {
1307       myNewCommand = myNewCommand + "IY " + QString::number(myY);
1308       theParameters = myYStr;
1309     }
1310     if ( mySketchType == DIR_DXDY_LENGTH ) {
1311       myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1312       myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength );
1313       theParameters = myDXStr + ":" + myDYStr + ":" + myLengthStr;
1314     }
1315     if ( mySketchType == DIR_DXDY_X ) {
1316       myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1317       myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX );
1318       theParameters = myDXStr + ":" + myDYStr + ":" + myXStr;
1319     }
1320     if ( mySketchType == DIR_DXDY_Y ) {
1321       myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1322       myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY );
1323       theParameters = myDXStr + ":" + myDYStr + ":" + myYStr;
1324     }
1325   }
1326   else if ( myConstructorId == 1 ) {  // ARC
1327     if ( mySketchType == DIR_ANGLE_LENGTH ) {
1328       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1329       myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1330       theParameters = myAngleStr + ":" + myRadiusStr + ":" + myLengthStr;
1331     }
1332     if ( mySketchType == DIR_PER_LENGTH ) {
1333       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1334       myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1335       theParameters = QString::number( 90.0 ) + ":" + myRadiusStr + ":" + myLengthStr;
1336     }
1337     if ( mySketchType == DIR_TAN_LENGTH ) {
1338       myNewCommand = myNewCommand + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1339       theParameters = myRadiusStr + ":" + myLengthStr;
1340     }
1341     if ( mySketchType == DIR_DXDY_LENGTH ) {
1342       myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1343       myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1344       theParameters = myDXStr + ":" + myDYStr + ":" + myRadiusStr + ":" + myLengthStr;
1345     }
1346   }
1347   return myNewCommand;
1348 }
1349
1350 //=================================================================================
1351 // function : createOperation
1352 // purpose  :
1353 //=================================================================================
1354 GEOM::GEOM_IOperations_ptr EntityGUI_SketcherDlg::createOperation()
1355 {
1356   return getGeomEngine()->GetICurvesOperations( getStudyId() );
1357 }
1358
1359 //=================================================================================
1360 // function : isValid
1361 // purpose  :
1362 //=================================================================================
1363 bool EntityGUI_SketcherDlg::isValid( QString& msg )
1364 {
1365   bool ok = true;
1366   bool toCorrect = !IsPreview() || myIsApply;
1367
1368   if( Group1Spin->isVisible() ) {
1369     ok = Group1Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1370   }
1371   else if( Group2Spin->isVisible() ) {
1372     ok = Group2Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1373     ok = Group2Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
1374   }
1375   else if( Group3Spin->isVisible() ) {
1376     ok = Group3Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1377     ok = Group3Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
1378     ok = Group3Spin->SpinBox_DZ->isValid( msg, toCorrect ) && ok;
1379   }
1380   else if( Group4Spin->isVisible() ) {
1381     ok = Group4Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1382     ok = Group4Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
1383     ok = Group4Spin->SpinBox_DZ->isValid( msg, toCorrect ) && ok;
1384     ok = Group4Spin->SpinBox_DS->isValid( msg, toCorrect ) && ok;
1385   }
1386
1387   if( myIsApply && !ok )
1388     showError( msg );
1389
1390   return ok;
1391 }
1392
1393 //=================================================================================
1394 // function : execute
1395 // purpose  :
1396 //=================================================================================
1397 bool EntityGUI_SketcherDlg::execute( ObjectList& objects )
1398 {
1399   QString aParameters;
1400
1401   if ( mySketchState == FIRST_POINT ) {
1402     myLastX2 = myX;
1403     myLastY2 = myY;
1404   }
1405   else {
1406     //Test if the current point is the same as the last one
1407     TopoDS_Shape myShape1, myShape2;
1408
1409     //Last Shape
1410     QString Command1 = myCommand.join( "" );
1411     Sketcher_Profile aProfile1( Command1.toAscii() );
1412     if ( aProfile1.IsDone() )
1413       myShape1 = aProfile1.GetShape();
1414
1415     //Current Shape
1416     QString Command2 = Command1 + GetNewCommand( aParameters );
1417     Sketcher_Profile aProfile2( Command2.toAscii() );
1418     if ( aProfile2.IsDone() )
1419       myShape2 = aProfile2.GetShape();
1420
1421     if ( myShape2.IsNull() ) {
1422       //the current point is the same as the last one
1423       myLastX2 = myLastX1;
1424       myLastY2 = myLastY1;
1425     }
1426     else {
1427       TopoDS_Vertex V1, V2;
1428       gp_Pnt pt;
1429       if ( myShape1.ShapeType() == TopAbs_VERTEX ) {
1430         //the last shape is the first point
1431         pt = BRep_Tool::Pnt( TopoDS::Vertex( myShape1 ) );
1432         myLastX1 = pt.X();
1433         myLastY1 = pt.Y();
1434       }
1435       else {
1436         TopExp::Vertices( TopoDS::Wire( myShape1 ), V1, V2 );
1437         pt = BRep_Tool::Pnt( V2 );
1438         myLastX1 = pt.X();
1439         myLastY1 = pt.Y();
1440       }
1441       TopExp::Vertices( TopoDS::Wire( myShape2 ), V1, V2 );
1442       pt = BRep_Tool::Pnt( V2 );
1443       myLastX2 = pt.X();
1444       myLastY2 = pt.Y();
1445     }
1446   }
1447
1448   QString cmd;
1449   if ( ( mySketchState != FIRST_POINT &&
1450          myLastX1 == myLastX2 && myLastY1 == myLastY2 ) || myIsAllAdded ) {
1451     cmd = myCommand.join( "" );
1452
1453     if ( Group1Sel->isVisible() ) {
1454       Group1Sel->buttonApply->setEnabled( false );
1455       //Group1Sel->buttonApply->setFocus();
1456     }
1457     if ( Group1Spin->isVisible() ) {
1458       Group1Spin->buttonApply->setEnabled( false );
1459       //Group1Spin->buttonApply->setFocus();
1460     }
1461     if ( Group2Spin->isVisible() ) {
1462       Group2Spin->buttonApply->setEnabled( false );
1463       //Group2Spin->buttonApply->setFocus();
1464     }
1465     if ( Group3Spin->isVisible() ) {
1466       Group3Spin->buttonApply->setEnabled( false );
1467       //Group3Spin->buttonApply->setFocus();
1468     }
1469     if ( Group4Spin->isVisible() ) {
1470       Group4Spin->buttonApply->setEnabled( false );
1471       //Group4Spin->buttonApply->setFocus();
1472     }
1473   }
1474   else {
1475     cmd = myCommand.join( "" ) + GetNewCommand( aParameters );
1476
1477     if ( Group1Sel->isVisible() ) {
1478       Group1Sel->buttonApply->setEnabled( true );
1479       //Group1Sel->buttonApply->setFocus();
1480     }
1481     if ( Group1Spin->isVisible() ) {
1482       Group1Spin->buttonApply->setEnabled( true );
1483       //Group1Spin->buttonApply->setFocus();
1484     }
1485     if ( Group2Spin->isVisible() ) {
1486       Group2Spin->buttonApply->setEnabled( true );
1487       //Group2Spin->buttonApply->setFocus();
1488     }
1489     if ( Group3Spin->isVisible() ) {
1490       Group3Spin->buttonApply->setEnabled( true );
1491       //Group3Spin->buttonApply->setFocus();
1492     }
1493     if ( Group4Spin->isVisible() ) {
1494       Group4Spin->buttonApply->setEnabled( true );
1495       //Group4Spin->buttonApply->setFocus();
1496     }
1497   }
1498
1499   gp_Ax3 myWPlane = GetActiveLocalCS();
1500   GEOM::ListOfDouble_var WPlane = new GEOM::ListOfDouble;
1501   WPlane->length( 9 );
1502   WPlane[0] = myWPlane.Location().X();
1503   WPlane[1] = myWPlane.Location().Y();
1504   WPlane[2] = myWPlane.Location().Z();
1505
1506   WPlane[3] = myWPlane.Direction().X();
1507   WPlane[4] = myWPlane.Direction().Y();
1508   WPlane[5] = myWPlane.Direction().Z();
1509
1510   WPlane[6] = myWPlane.XDirection().X();
1511   WPlane[7] = myWPlane.XDirection().Y();
1512   WPlane[8] = myWPlane.XDirection().Z();
1513
1514   GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow(getOperation());
1515   GEOM::GEOM_Object_var anObj = anOper->MakeSketcher( cmd.toLatin1().constData(), WPlane );
1516
1517   if ( !anObj->_is_nil() )
1518   {
1519     if( !IsPreview() ) {
1520       QStringList aCurrentParameters = myParameters;
1521       aCurrentParameters << aParameters;
1522       anObj->SetParameters(aCurrentParameters.join(":").toLatin1().constData());
1523     }
1524
1525     objects.push_back( anObj._retn() );
1526   }
1527
1528   return true;
1529 }
1530
1531 //================================================================
1532 // Function : displayPreview
1533 // Purpose  : Method for displaying preview of resulting shape
1534 //            Redefined from GEOMBase_Helper.
1535 //================================================================
1536 void EntityGUI_SketcherDlg::displayPreview( GEOM::GEOM_Object_ptr object,
1537                                             const bool            append,
1538                                             const bool            activate,
1539                                             const bool            update,
1540                                             const double          lineWidth,
1541                                             const int             displayMode,
1542                                             const int             color )
1543 {
1544   // Set color for preview shape
1545   getDisplayer()->SetColor( Quantity_NOC_RED );
1546
1547   // set width of displayed shape
1548   getDisplayer()->SetWidth( (lineWidth == -1)?myLineWidth:lineWidth );
1549
1550   // Disable activation of selection
1551   getDisplayer()->SetToActivate( activate );
1552
1553   // Make a reference to GEOM_Object
1554   CORBA::String_var objStr = myGeometryGUI->getApp()->orb()->object_to_string( object );
1555   getDisplayer()->SetName( objStr.in() );
1556
1557   // Create wire from applayed object
1558   TopoDS_Shape anApplyedWire, aLastSegment;
1559   if ( !createShapes( object, anApplyedWire, aLastSegment ) )
1560     return;
1561
1562   // Build prs
1563   SALOME_Prs* aPrs = getDisplayer()->BuildPrs( anApplyedWire );
1564   if ( aPrs != 0 && !aPrs->IsNull() )
1565     GEOMBase_Helper::displayPreview( aPrs, append, update );
1566
1567   getDisplayer()->SetColor( Quantity_NOC_VIOLET );
1568   aPrs = getDisplayer()->BuildPrs( aLastSegment );
1569   if ( aPrs != 0 && !aPrs->IsNull() )
1570     GEOMBase_Helper::displayPreview( aPrs, append, update );
1571
1572   getDisplayer()->UnsetName();
1573
1574   // Enable activation of displayed objects
1575   getDisplayer()->SetToActivate( true );
1576 }
1577
1578 //================================================================
1579 // Function : createShapes
1580 // Purpose  : Create applyed wire, and last segment from entry object
1581 //================================================================
1582 bool EntityGUI_SketcherDlg::createShapes( GEOM::GEOM_Object_ptr theObject,
1583                                           TopoDS_Shape&         theApplyedWire,
1584                                           TopoDS_Shape&         theLastSegment )
1585 {
1586   TopoDS_Shape aShape;
1587   if ( !GEOMBase::GetShape( theObject, aShape ) ||
1588        aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX )
1589     return false;
1590
1591   if ( Group1Sel->isVisible()  && !Group1Sel->buttonApply->isEnabled()  ||
1592        Group1Spin->isVisible() && !Group1Spin->buttonApply->isEnabled() ||
1593        Group2Spin->isVisible() && !Group2Spin->buttonApply->isEnabled() ||
1594        Group3Spin->isVisible() && !Group3Spin->buttonApply->isEnabled() ||
1595        Group4Spin->isVisible() && !Group4Spin->buttonApply->isEnabled() ) {
1596      theApplyedWire = aShape;
1597      return true;
1598   }
1599
1600   BRepBuilderAPI_MakeWire aBuilder;
1601   TopExp_Explorer anExp( aShape, TopAbs_EDGE );
1602   while ( 1 ) {
1603     TopoDS_Shape anEdge = anExp.Current();
1604     anExp.Next();
1605     if ( anExp.More() ) // i.e. non-last edge
1606       aBuilder.Add( TopoDS::Edge( anEdge ) );
1607     else {
1608       theLastSegment = anEdge;
1609       break;
1610     }
1611   }
1612
1613   if ( aBuilder.IsDone() )
1614     theApplyedWire = aBuilder.Shape();
1615
1616   return true;
1617 }
1618
1619 //=================================================================================
1620 // function : keyPressEvent()
1621 // purpose  :
1622 //=================================================================================
1623 void  EntityGUI_SketcherDlg::keyPressEvent( QKeyEvent* e )
1624 {
1625   QDialog::keyPressEvent( e );
1626   if ( e->isAccepted() )
1627     return;
1628
1629   if ( e->key() == Qt::Key_F1 ) {
1630     e->accept();
1631     ClickOnHelp();
1632   }
1633 }
1634
1635 //=================================================================================
1636 // function : initSpinBox()
1637 // purpose  :
1638 //=================================================================================
1639 void EntityGUI_SketcherDlg::initSpinBox( SalomeApp_DoubleSpinBox* spinBox,
1640                                          double min,  double max,
1641                                          double step, const char* quantity )
1642 {
1643   // The same stuff as in GEOMBase_Skeleton::initSpinBox()!
1644   // TODO: Think how to keep the single piece of code...
1645
1646   // Obtain precision from preferences
1647   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1648   int aPrecision = resMgr->integerValue( "Geometry", quantity, 6 );
1649   
1650   spinBox->setPrecision( aPrecision );
1651   spinBox->setDecimals( aPrecision ); // it's necessary to set decimals before the range setting,
1652                                     // by default Qt rounds boundaries to 2 decimals at setRange
1653   spinBox->setRange( min, max );
1654   spinBox->setSingleStep( step );
1655   
1656   // Add a hint for the user saying how to tune precision
1657   QString userPropName = QObject::tr( QString( "PREF_%1" ).arg( quantity ).toLatin1().constData() );
1658   spinBox->setProperty( "validity_tune_hint", 
1659                         QVariant( QObject::tr( "PRECISION_HINT" ).arg( userPropName ) ) );  
1660 }
1661
1662 //=================================================================================
1663 // function : SetDoubleSpinBoxStep()
1664 // purpose  : Double spin box management
1665 //=================================================================================
1666 void EntityGUI_SketcherDlg::SetDoubleSpinBoxStep( double step )
1667 {
1668   Group1Spin->SpinBox_DX->setSingleStep(step);
1669   Group2Spin->SpinBox_DX->setSingleStep(step);
1670   Group2Spin->SpinBox_DY->setSingleStep(step);
1671   Group3Spin->SpinBox_DX->setSingleStep(step);
1672   Group3Spin->SpinBox_DY->setSingleStep(step);
1673   Group3Spin->SpinBox_DZ->setSingleStep(step);
1674   Group4Spin->SpinBox_DZ->setSingleStep(step);
1675
1676   // san: Do NOT override the step when a speicifc step value is used
1677   // in some input fields!
1678   //Group4Spin->SpinBox_DX->setSingleStep(step);
1679   //Group4Spin->SpinBox_DY->setSingleStep(step);
1680   //Group4Spin->SpinBox_DS->setSingleStep(step);
1681 }
1682
1683 //=================================================================================
1684 // function : FindLocalCS()
1685 // purpose  : Find All Coordinates systems in study
1686 //=================================================================================
1687 void EntityGUI_SketcherDlg::FindLocalCS()
1688 {
1689   ComboBox1->clear();
1690   myLCSList.clear();
1691   SalomeApp_Application* app =
1692     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1693   if ( !app )
1694     return;
1695
1696   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1697   if ( !appStudy )
1698     return;
1699
1700   _PTR(Study) aStudy = appStudy->studyDS();
1701
1702   //add Global CS
1703   ComboBox1->addItem(tr("GEOM_GCS"));
1704   gp_Pnt aOrigin = gp_Pnt(0, 0, 0);
1705   gp_Dir aDirZ = gp_Dir(0, 0, 1);
1706   gp_Dir aDirX = gp_Dir(1, 0, 0);
1707   gp_Ax3 globalCS = gp_Ax3(aOrigin, aDirZ, aDirX);
1708   myLCSList.push_back(globalCS);
1709
1710   // get GEOM component
1711   CORBA::String_var geomIOR = app->orb()->object_to_string( GeometryGUI::GetGeomGen() );
1712   _PTR(SObject) obj = aStudy->FindObjectIOR( geomIOR.in() );
1713   if (!obj)
1714     return;
1715   _PTR(SComponent) fc = obj->GetFatherComponent();
1716   QString geomComp = fc->GetID().c_str();
1717   _PTR(SObject) comp = aStudy->FindObjectID( geomComp.toLatin1().data() );
1718   if ( !comp )
1719     return;
1720
1721   // browse through all GEOM data tree
1722   _PTR(ChildIterator) it ( aStudy->NewChildIterator( comp ) );
1723   for ( it->InitEx( true ); it->More(); it->Next() ) {
1724     _PTR(SObject) child( it->Value() );
1725     CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( child );
1726     GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
1727     if( CORBA::is_nil( geomObj ) ) 
1728       continue;
1729     if (geomObj->GetType() == GEOM_MARKER) {
1730       ComboBox1->addItem(geomObj->GetName());
1731       TopoDS_Shape aShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), geomObj);
1732       
1733       gp_Ax3 aLCS;
1734       aLCS.Transform(aShape.Location().Transformation());
1735       if (aShape.ShapeType() == TopAbs_FACE) {
1736         Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(aShape));
1737         if (!aGS.IsNull() && aGS->IsKind(STANDARD_TYPE(Geom_Plane))) {
1738           Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast(aGS);
1739           gp_Pln aPln = aGPlane->Pln();
1740           aLCS = aPln.Position();
1741         }
1742       }
1743       myLCSList.push_back(aLCS);
1744     }
1745   }
1746 }
1747
1748 //=================================================================================
1749 // function : GetActiveLocalCS()
1750 // purpose  : Find All Coordinates systems in study
1751 //=================================================================================
1752 gp_Ax3 EntityGUI_SketcherDlg::GetActiveLocalCS()
1753 {
1754   int ind = ComboBox1->currentIndex();
1755   if (ind == -1)
1756     return myGeometryGUI->GetWorkingPlane();
1757
1758   gp_Ax3 aLCS = myLCSList.at(ind);
1759
1760   myGeometryGUI->SetWorkingPlane( aLCS );
1761   myGeometryGUI->ActiveWorkingPlane();
1762   return aLCS;
1763 }