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