Salome HOME
Preparation of intermediate revision
[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 <QtxDoubleSpinBox.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 <SalomeApp_Notebook.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, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
331   initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
332   initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
333   initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
334   initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
335   initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
336   initSpinBox( Group4Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
337   initSpinBox( Group4Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
338   initSpinBox( Group4Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
339   initSpinBox( Group4Spin->SpinBox_DS, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
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   resize(100,100);
350   TypeClicked( 0 );
351
352   FindLocalCS();
353
354   GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
355 }
356
357
358 //=================================================================================
359 // function : InitClick()
360 // purpose  :
361 //=================================================================================
362 void EntityGUI_SketcherDlg::InitClick()
363 {
364   disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
365
366   Group1Sel->hide();
367   Group1Spin->hide();
368   Group2Spin->hide();
369   Group3Spin->hide();
370   Group4Spin->hide();
371
372   resize(100,100);
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, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
439       initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
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, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
454       initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
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       connect( myGeometryGUI->getApp()->selectionMgr(),
470                SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
471       Group1Sel->show();
472       Group1Sel->buttonApply->setFocus();
473       SelectionIntoArgument();
474     }
475   }
476 }
477
478
479 //=================================================================================
480 // function : Dir1Clicked()
481 // purpose  : Radio button management
482 //=================================================================================
483 void EntityGUI_SketcherDlg::Dir1Clicked( int constructorId )
484 {
485   myConstructorDirId = constructorId;
486   GroupD2->RB_Dir21->setChecked( true );
487   Dir2Clicked( 2 );
488 }
489
490
491 //=================================================================================
492 // function : Dir2Clicked()
493 // purpose  : Radio button management
494 //=================================================================================
495 void EntityGUI_SketcherDlg::Dir2Clicked( int constructorId )
496 {
497   InitClick();
498   myAngle = 0.0;
499
500   // Get setting of step value from file configuration
501   double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
502
503   if ( myConstructorId == 0 ) {  // SEGMENT
504     myX = 0.0;
505     myY = 0.0;
506     myLength = 100.0;
507     if ( myConstructorDirId == 2 ) {  // Angle
508       initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
509       initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
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         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
518         Group2Spin->SpinBox_DY->setValue( myLength );
519       }
520       else if ( constructorId == 0 ) {  // X
521         mySketchType = DIR_ANGLE_X;
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         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y3" ) );
528         Group2Spin->SpinBox_DY->setValue( myY );
529       }
530     }
531     else if ( myConstructorDirId == 0 ) {  // Perpendicular
532       Group1Spin->show();
533       Group1Spin->buttonApply->setFocus();
534
535       if ( constructorId == 2 ) {  // Length
536         mySketchType = DIR_PER_LENGTH;
537         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
538         Group1Spin->SpinBox_DX->setValue( myLength );
539       }
540       else if ( constructorId == 0 ) {  // X
541         mySketchType = DIR_PER_X;
542         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X3" ) );
543         Group1Spin->SpinBox_DX->setValue( myX );
544       }
545       else if ( constructorId == 1 ) {  // Y
546         mySketchType = DIR_PER_Y;
547         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_Y3" ) );
548         Group1Spin->SpinBox_DX->setValue( myY );
549       }
550     }
551     else if ( myConstructorDirId == 1 ) {  // Tangent
552       Group1Spin->show();
553       Group1Spin->buttonApply->setFocus();
554
555       if ( constructorId == 2 ) {  // Length
556         mySketchType = DIR_TAN_LENGTH;
557         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
558         Group1Spin->SpinBox_DX->setValue( myLength );
559       }
560       else if ( constructorId == 0 ) {  // X
561         mySketchType = DIR_TAN_X;
562         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X3" ) );
563         Group1Spin->SpinBox_DX->setValue( myX );
564       }
565       else if ( constructorId == 1 ) {  // Y
566         mySketchType = DIR_TAN_Y;
567         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_Y3" ) );
568         Group1Spin->SpinBox_DX->setValue( myY );
569       }
570     }
571     else if ( myConstructorDirId == 3 ) {  // DXDY
572       initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
573       initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
574       initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
575       Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_VX2" ) );
576       Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_VY2" ) );
577       myDX = 0.0;
578       Group3Spin->SpinBox_DX->setValue( myDX );
579       myDY = 0.0;
580       Group3Spin->SpinBox_DY->setValue( myDY );
581       Group3Spin->show();
582       Group3Spin->buttonApply->setFocus();
583
584       if ( constructorId == 2 ) {  // Length
585         mySketchType = DIR_DXDY_LENGTH;
586         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
587         Group3Spin->SpinBox_DZ->setValue( myLength );
588       }
589       else if ( constructorId == 0 ) { // X
590         mySketchType = DIR_DXDY_X;
591         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_X3" ) );
592         Group3Spin->SpinBox_DZ->setValue( myX );
593       }
594       else if ( constructorId == 1 ) {  // Y
595         mySketchType = DIR_DXDY_Y;
596         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_Y3" ) );
597         Group3Spin->SpinBox_DZ->setValue( myY );
598       }
599     }
600   }
601   else if ( myConstructorId == 1 ) {  // ARC
602     if ( myConstructorDirId == 2 ) {  // Angle
603       if ( constructorId == 2 ) {  // Length
604         mySketchType = DIR_ANGLE_LENGTH;
605         initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
606         initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
607         initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
608         Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
609         Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
610         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_ANGLE2" ));
611         Group3Spin->SpinBox_DX->setValue( myAngle );
612         myRadius = 100.0;
613         Group3Spin->SpinBox_DY->setValue( myRadius );
614         myLength = 30.0;
615         Group3Spin->SpinBox_DZ->setValue( myLength );
616         Group3Spin->show();
617         Group3Spin->buttonApply->setFocus();
618       }
619     }
620     else if ( myConstructorDirId == 0 ) {  // Perpendicular
621       if ( constructorId == 2 ) {  // Length
622         mySketchType = DIR_PER_LENGTH;
623         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
624         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
625         Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
626         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
627         myRadius = 100.0;
628         Group2Spin->SpinBox_DX->setValue( myRadius );
629         myLength = 30.0;
630         Group2Spin->SpinBox_DY->setValue( myLength );
631         Group2Spin->show();
632         Group2Spin->buttonApply->setFocus();
633       }
634     }
635     else if ( myConstructorDirId == 1 ) {  // Tangent
636       if ( constructorId == 2 ) {  // Length
637         mySketchType = DIR_TAN_LENGTH;
638         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
639         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
640         Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
641         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
642         myRadius = 100.0;
643         Group2Spin->SpinBox_DX->setValue( myRadius );
644         myLength = 30.0;
645         Group2Spin->SpinBox_DY->setValue( myLength );
646         Group2Spin->show();
647         Group2Spin->buttonApply->setFocus();
648       }
649     }
650     else if ( myConstructorDirId == 3 ) {  // DXDY
651       if ( constructorId == 2 ) {  // Length
652         mySketchType = DIR_DXDY_LENGTH;
653         Group4Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_VX2" ) );
654         Group4Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_VY2" ) );
655         Group4Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
656         Group4Spin->TextLabel4->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
657         myDX = 0.0;
658         Group4Spin->SpinBox_DX->setValue( myDX );
659         myDY = 0.0;
660         Group4Spin->SpinBox_DY->setValue( myDY );
661         myRadius = 100.0;
662         Group4Spin->SpinBox_DZ->setValue( myRadius );
663         myLength = 30.0;
664         Group4Spin->SpinBox_DS->setValue( myLength );
665         Group4Spin->show();
666         Group4Spin->buttonApply->setFocus();
667       }
668     }
669   }
670
671   GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
672 }
673
674
675 //=================================================================================
676 // function : ClickOnCancel()
677 // purpose  :
678 //=================================================================================
679 void EntityGUI_SketcherDlg::ClickOnCancel()
680 {
681   close();
682 }
683
684
685 //=================================================================================
686 // function : ClickOnEnd()
687 // purpose  : connected to buttonEnd AND buttonClose
688 //=================================================================================
689 void EntityGUI_SketcherDlg::ClickOnEnd()
690 {
691   if ( sender() == MainWidget->buttonClose ) {
692     // Verify validity of commands
693     if ( myCommand.count() <= 2 ) {
694       SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
695                                  tr( "GEOM_ERROR_STATUS" ), tr( "CANNOT_CLOSE" ), tr( "BUT_OK" ) );
696       return;
697     }
698
699     QString Parameters;
700     QString Command = myCommand.join( "" ) + GetNewCommand( Parameters );
701     Sketcher_Profile aProfile( Command.toAscii() );
702
703     Command = myCommand.join( "" );
704     aProfile = Sketcher_Profile( Command.toAscii() );
705     TopoDS_Shape myShape;
706     if ( aProfile.IsDone() )
707       myShape = aProfile.GetShape();
708
709     if ( myShape.ShapeType() != TopAbs_VERTEX )
710       myCommand.append( ":WW" );
711   }
712   else {
713     // PAL16008 (Sketcher Validation should be equal to Apply&Close)
714     if ( Group1Spin->buttonApply->isEnabled() && Group1Spin->isVisible() ||
715          Group2Spin->buttonApply->isEnabled() && Group2Spin->isVisible() ||
716          Group3Spin->buttonApply->isEnabled() && Group3Spin->isVisible() ||
717          Group4Spin->buttonApply->isEnabled() && Group4Spin->isVisible() ||
718          Group1Sel ->buttonApply->isEnabled() && Group1Sel->isVisible() ) {
719       ClickOnApply();
720     }
721     myIsAllAdded = true;
722   }
723
724   if ( myCommand.size() > 2 )
725     if ( !onAccept() )
726       return;
727
728   close();
729 }
730
731 //=================================================================================
732 // function : ClickOnApply()
733 // purpose  :
734 //=================================================================================
735 bool EntityGUI_SketcherDlg::ClickOnApply()
736 {
737   if ( sender() && sender()->inherits( "QPushButton" ) )
738     ( (QPushButton*)sender() )->setFocus(); // to update value of currently edited spin-box (PAL11948)
739
740   QString aParameters;
741   myCommand.append( GetNewCommand( aParameters ) );
742   mySketchState = NEXT_POINT;
743
744   myUndoCommand.clear();
745   myUndoCommand.append( "Sketcher" );
746
747   myParameters.append( aParameters );
748   myUndoParameters.clear();
749
750   MainWidget->GroupConstructors->setEnabled( true );
751   MainWidget->GroupDest1->setEnabled( true );
752   setEnabledUndo( true );
753   setEnabledRedo( false );
754
755   myIsApply = true;
756   GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
757   myIsApply = false;
758
759   // Set focus to SpinBox_DX
760   if ( sender() == Group1Spin->buttonApply ) {
761     (Group1Spin->SpinBox_DX)->setFocus();
762     (Group1Spin->SpinBox_DX)->selectAll();
763   }
764   else if ( sender() == Group2Spin->buttonApply ) {
765     (Group2Spin->SpinBox_DX)->setFocus();
766     (Group2Spin->SpinBox_DX)->selectAll();
767   }
768   else if ( sender() == Group3Spin->buttonApply ) {
769     (Group3Spin->SpinBox_DX)->setFocus();
770     (Group3Spin->SpinBox_DX)->selectAll();
771   }
772   else if ( sender() == Group4Spin->buttonApply ) {
773     (Group4Spin->SpinBox_DX)->setFocus();
774     (Group4Spin->SpinBox_DX)->selectAll();
775   }
776
777   return true;
778 }
779
780 //=================================================================================
781 // function : ClickOnHelp()
782 // purpose  :
783 //=================================================================================
784 void EntityGUI_SketcherDlg::ClickOnHelp()
785 {
786   LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
787   if ( app )
788     app->onHelpContextModule( myGeometryGUI ? app->moduleName( myGeometryGUI->moduleName() ) : QString( "" ), myHelpFileName );
789   else {
790     QString platform;
791 #ifdef WIN32
792     platform = "winapplication";
793 #else
794     platform = "application";
795 #endif
796
797     SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
798                               QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
799                               arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
800                               QObject::tr( "BUT_OK" ) );
801   }
802 }
803
804 //=================================================================================
805 // function : ClickOnUndo()
806 // purpose  :
807 //=================================================================================
808 void EntityGUI_SketcherDlg::ClickOnUndo()
809 {
810   myUndoCommand.append( myCommand.last() );
811   myCommand.pop_back();
812
813   myUndoParameters.append( myParameters.last() );
814   myParameters.pop_back();
815
816   if ( myCommand.count() == 1 ) {
817     mySketchState = FIRST_POINT;
818
819     MainWidget->RadioButton1->setChecked( true );
820     TypeClicked( 0 );
821
822     MainWidget->GroupConstructors->setEnabled( false );
823     MainWidget->GroupDest1->setEnabled( false );
824     setEnabledUndo( false );
825   }
826
827   setEnabledRedo( true );
828
829   GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
830 }
831
832 //=================================================================================
833 // function : ClickOnRedo()
834 // purpose  :
835 //=================================================================================
836 void EntityGUI_SketcherDlg::ClickOnRedo()
837 {
838   myCommand.append( myUndoCommand.last() );
839   myUndoCommand.pop_back();
840
841   myParameters.append( myUndoParameters.last() );
842   myUndoParameters.pop_back();
843
844   mySketchState = NEXT_POINT;
845
846   MainWidget->GroupConstructors->setEnabled( true );
847   MainWidget->GroupDest1->setEnabled( true );
848   setEnabledUndo( true );
849
850   if ( myUndoCommand.count() == 1 )
851     setEnabledRedo( false );
852
853   GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
854 }
855
856 //=================================================================================
857 // function : setEnabledUndo()
858 // purpose  :
859 //=================================================================================
860 void EntityGUI_SketcherDlg::setEnabledUndo( bool value )
861 {
862   Group1Sel->buttonUndo->setEnabled( value );
863   Group1Spin->buttonUndo->setEnabled( value );
864   Group2Spin->buttonUndo->setEnabled( value );
865   Group3Spin->buttonUndo->setEnabled( value );
866   Group4Spin->buttonUndo->setEnabled( value );
867 }
868
869 //=================================================================================
870 // function : setEnabledRedo()
871 // purpose  :
872 //=================================================================================
873 void EntityGUI_SketcherDlg::setEnabledRedo( bool value )
874 {
875   Group1Sel->buttonRedo->setEnabled( value );
876   Group1Spin->buttonRedo->setEnabled( value );
877   Group2Spin->buttonRedo->setEnabled( value );
878   Group3Spin->buttonRedo->setEnabled( value );
879   Group4Spin->buttonRedo->setEnabled( value );
880 }
881
882 //=================================================================================
883 // function : SelectionIntoArgument()
884 // purpose  : Called when selection as changed
885 //=================================================================================
886 void EntityGUI_SketcherDlg::SelectionIntoArgument()
887 {
888   myEditCurrentArgument->setText( "" );
889   myX = myLastX1;
890   myY = myLastY1;
891
892   LightApp_SelectionMgr* aSelMgr = myGeometryGUI->getApp()->selectionMgr();
893   SALOME_ListIO aSelList;
894   aSelMgr->selectedObjects(aSelList);
895
896   int nbSel = aSelList.Extent();
897   if (nbSel == 1 && myEditCurrentArgument == Group1Sel->LineEdit1) {
898     Standard_Boolean aRes = Standard_False;
899     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aRes);
900     if (!CORBA::is_nil(aSelectedObject) && aRes) {
901       TopoDS_Shape aShape;
902       if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_VERTEX)) {
903         gp_Trsf aTrans;
904         gp_Ax3 aWPlane = GetActiveLocalCS();
905
906         aTrans.SetTransformation(aWPlane);
907         BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
908         aShape = aTransformation.Shape();
909
910         gp_Pnt aPnt;
911         if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) {
912           myX = aPnt.X();
913           myY = aPnt.Y();
914           Group1Sel->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
915         }
916       }
917     }
918   }
919
920   GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
921 }
922
923
924 //=================================================================================
925 // function : SetEditCurrentArgument()
926 // purpose  :
927 //=================================================================================
928 void EntityGUI_SketcherDlg::SetEditCurrentArgument()
929 {
930   if ( sender() == Group1Sel->PushButton1 ) {
931     myEditCurrentArgument = Group1Sel->LineEdit1;
932     myEditCurrentArgument->setFocus();
933   }
934   SelectionIntoArgument();
935 }
936
937
938 //=================================================================================
939 // function : LineEditReturnPressed()
940 // purpose  :
941 //=================================================================================
942 void EntityGUI_SketcherDlg::LineEditReturnPressed()
943 {
944   if ( sender() == Group1Sel->LineEdit1 ) {
945     myEditCurrentArgument = Group1Sel->LineEdit1;
946
947     /* User name of object input management                          */
948     /* If successfull the selection is changed and signal emitted... */
949     /* so SelectionIntoArgument() is automatically called.           */
950     const QString objectUserName = myEditCurrentArgument->text();
951     QWidget* thisWidget = (QWidget*)this;
952
953     LightApp_SelectionMgr* aSelMgr = myGeometryGUI->getApp()->selectionMgr();
954     SALOME_ListIO aSelList;
955     aSelMgr->selectedObjects(aSelList);
956
957     if (GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, aSelList))
958       myEditCurrentArgument->setText( objectUserName );
959   }
960 }
961
962
963 //=================================================================================
964 // function : DeactivateActiveDialog()
965 // purpose  :
966 //=================================================================================
967 void EntityGUI_SketcherDlg::DeactivateActiveDialog()
968 {
969   //myGeometryGUI->SetState( -1 );
970
971   setEnabled( false );
972   globalSelection();
973   disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
974   myGeometryGUI->SetActiveDialogBox( 0 );
975 }
976
977
978 //=================================================================================
979 // function : ActivateThisDialog()
980 // purpose  :
981 //=================================================================================
982 void EntityGUI_SketcherDlg::ActivateThisDialog()
983 {
984   myGeometryGUI->EmitSignalDeactivateDialog();
985   setEnabled( true );
986   myGeometryGUI->SetActiveDialogBox( this );
987
988   connect( myGeometryGUI->getApp()->selectionMgr(),
989           SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
990
991   //myGeometryGUI->SetState( 0 );
992   globalSelection( GEOM_POINT );
993
994   myEditCurrentArgument = Group1Sel->LineEdit1;
995   myEditCurrentArgument->setFocus();
996
997   GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
998 }
999
1000
1001 //=================================================================================
1002 // function : enterEvent [REDEFINED]
1003 // purpose  :
1004 //=================================================================================
1005 void EntityGUI_SketcherDlg::enterEvent( QEvent* )
1006 {
1007   if ( !MainWidget->GroupConstructors->isEnabled() )
1008     ActivateThisDialog();
1009 }
1010
1011
1012 //=================================================================================
1013 // function : closeEvent()
1014 // purpose  :
1015 //=================================================================================
1016 void EntityGUI_SketcherDlg::closeEvent( QCloseEvent* e )
1017 {
1018   //myGeometryGUI->SetState( -1 );
1019   disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
1020   myGeometryGUI->getApp()->updateActions();
1021   QDialog::closeEvent( e );
1022 }
1023
1024
1025 //=================================================================================
1026 // function : ValueChangedInSpinBox()
1027 // purpose  :
1028 //=================================================================================
1029 void EntityGUI_SketcherDlg::ValueChangedInSpinBox( double newValue )
1030 {
1031   QObject* send = (QObject*)sender();
1032   Standard_Real vx, vy, vz, vs;
1033   vx = vy = vz = vs = 0.0;
1034
1035   QString vxStr, vyStr, vzStr, vsStr;
1036
1037   QString newValueStr;
1038   if( SalomeApp_DoubleSpinBox* aDoubleSpinBox = (SalomeApp_DoubleSpinBox*)send )
1039     newValueStr = aDoubleSpinBox->text();
1040
1041   if ( send == Group1Spin->SpinBox_DX ) {
1042     vx = newValue;                        vxStr = newValueStr;
1043   }
1044   else if ( send == Group2Spin->SpinBox_DX ) {
1045     vx = newValue;                        vxStr = newValueStr;
1046     vy = Group2Spin->SpinBox_DY->value(); vyStr = Group2Spin->SpinBox_DY->text();
1047   }
1048   else if ( send == Group2Spin->SpinBox_DY ) {
1049     vx = Group2Spin->SpinBox_DX->value(); vxStr = Group2Spin->SpinBox_DX->text();
1050     vy = newValue;                        vyStr = newValueStr;
1051   }
1052   else if ( send == Group3Spin->SpinBox_DX ) {
1053     vx = newValue;                        vxStr = newValueStr;
1054     vy = Group3Spin->SpinBox_DY->value(); vyStr = Group3Spin->SpinBox_DY->text();
1055     vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
1056   }
1057   else if ( send == Group3Spin->SpinBox_DY ) {
1058     vx = Group3Spin->SpinBox_DX->value(); vxStr = Group3Spin->SpinBox_DX->text();
1059     vy = newValue;                        vyStr = newValueStr;
1060     vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
1061   }
1062   else if ( send == Group3Spin->SpinBox_DZ ) {
1063     vx = Group3Spin->SpinBox_DX->value(); vxStr = Group3Spin->SpinBox_DX->text();
1064     vy = Group3Spin->SpinBox_DY->value(); vyStr = Group3Spin->SpinBox_DY->text();
1065     vz = newValue;                        vzStr = newValueStr;
1066   }
1067   else if ( send == Group4Spin->SpinBox_DX ) {
1068     vx = newValue;                        vxStr = newValueStr;
1069     vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1070     vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1071     vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1072   }
1073   else if ( send == Group4Spin->SpinBox_DY ) {
1074     vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1075     vy = newValue;                        vyStr = newValueStr;
1076     vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1077     vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1078   }
1079   else if ( send == Group4Spin->SpinBox_DZ ) {
1080     vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1081     vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1082     vz = newValue;                        vzStr = newValueStr;
1083     vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1084   }
1085   else if ( send == Group4Spin->SpinBox_DS ) {
1086     vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1087     vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1088     vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1089     vs = newValue;                        vsStr = newValueStr;
1090   }
1091   // Fix of the NPAL16010 bug is removed, because it's not actual with the Qt-4.x
1092
1093   if ( myConstructorId == 0 ) {  // SEGMENT
1094     if ( mySketchType == PT_ABS ) {
1095       myX = vx;
1096       myY = vy;
1097       myXStr = vxStr;
1098       myYStr = vyStr;
1099     }
1100     else if ( mySketchType == PT_RELATIVE ) {
1101       myDX = vx;
1102       myDY = vy;
1103       myDXStr = vxStr;
1104       myDYStr = vyStr;
1105     }
1106     else if ( mySketchType == DIR_ANGLE_LENGTH ) {
1107       myAngle = vx;
1108       myLength = vy;
1109       myAngleStr = vxStr;
1110       myLengthStr = vyStr;
1111     }
1112     else if ( mySketchType == DIR_ANGLE_X ) {
1113       myAngle = vx;
1114       myX = vy;
1115       myAngleStr = vxStr;
1116       myXStr = vyStr;
1117     }
1118     else if ( mySketchType == DIR_ANGLE_Y ) {
1119       myAngle = vx;
1120       myY = vy;
1121       myAngleStr = vxStr;
1122       myYStr = vyStr;
1123     }
1124     else if ( mySketchType == DIR_PER_LENGTH ) {
1125       myLength = vx;
1126       myLengthStr = vxStr;
1127     }
1128     else if ( mySketchType == DIR_PER_X ) {
1129       myX = vx;
1130       myXStr = vxStr;
1131     }
1132     else if ( mySketchType == DIR_PER_Y ) {
1133       myY = vx;
1134       myYStr = vxStr;
1135     }
1136     else if ( mySketchType == DIR_TAN_LENGTH ) {
1137       myLength = vx;
1138       myLengthStr = vxStr;
1139     }
1140     else if ( mySketchType == DIR_TAN_X ) {
1141       myX = vx;
1142       myXStr = vxStr;
1143     }
1144     else if ( mySketchType == DIR_TAN_Y ) {
1145       myY = vx;
1146       myYStr = vxStr;
1147     }
1148     else if ( mySketchType == DIR_DXDY_LENGTH ) {
1149       myDX = vx;
1150       myDY = vy;
1151       myLength = vz;
1152       myDXStr = vxStr;
1153       myDYStr = vyStr;
1154       myLengthStr = vzStr;
1155     }
1156     else if ( mySketchType == DIR_DXDY_X ) {
1157       myDX = vx;
1158       myDY = vy;
1159       myX = vz;
1160       myDXStr = vxStr;
1161       myDYStr = vyStr;
1162       myXStr = vzStr;
1163     }
1164     else if ( mySketchType == DIR_DXDY_Y ) {
1165       myDX = vx;
1166       myDY = vy;
1167       myY = vz;
1168       myDXStr = vxStr;
1169       myDYStr = vyStr;
1170       myYStr = vzStr;
1171     }
1172   }
1173   else if ( myConstructorId == 1 ) {  // ARC
1174     if ( mySketchType == DIR_ANGLE_LENGTH ) {
1175       myAngle = vx;
1176       myRadius = vy;
1177       myLength = vz;
1178       myAngleStr = vxStr;
1179       myRadiusStr = vyStr;
1180       myLengthStr = vzStr;
1181     }
1182     else if ( mySketchType == DIR_PER_LENGTH ) {
1183       myRadius = vx;
1184       myLength = vy;
1185       myRadiusStr = vxStr;
1186       myLengthStr = vyStr;
1187     }
1188     else if ( mySketchType == DIR_TAN_LENGTH ) {
1189       myRadius = vx;
1190       myLength = vy;
1191       myRadiusStr = vxStr;
1192       myLengthStr = vyStr;
1193     }
1194     else if ( mySketchType == DIR_DXDY_LENGTH ) {
1195       myDX = vx;
1196       myDY = vy;
1197       myRadius = vz;
1198       myLength = vs;
1199       myDXStr = vxStr;
1200       myDYStr = vyStr;
1201       myRadiusStr = vzStr;
1202       myLengthStr = vsStr;
1203     }
1204   }
1205
1206   GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
1207 }
1208
1209
1210 //=================================================================================
1211 // function : GetNewCommand()
1212 // purpose  : Build the new command with context
1213 //=================================================================================
1214 QString EntityGUI_SketcherDlg::GetNewCommand( QString& theParameters )
1215 {
1216   theParameters.clear();
1217   QString myNewCommand = ":";
1218   if ( mySketchState == FIRST_POINT ) {
1219     if ( mySketchType == PT_ABS || mySketchType == PT_SEL ) {
1220       myNewCommand = myNewCommand + "F " + QString::number( myX ) + " " + QString::number( myY );
1221       theParameters = myXStr + ":" + myYStr;
1222     }
1223     if ( mySketchType == PT_RELATIVE) {
1224       myNewCommand = myNewCommand + "F " + QString::number( myDX ) + " " + QString::number( myDY );
1225       theParameters = myDXStr + ":" + myDYStr;
1226     }
1227     return myNewCommand;
1228   }
1229
1230   if ( myConstructorId == 0  ) {  // SEGMENT
1231     if ( mySketchType == PT_ABS || mySketchType == PT_SEL ) {
1232       myNewCommand = myNewCommand + "TT " + QString::number( myX ) + " " + QString::number( myY );
1233       theParameters = myXStr + ":" + myYStr;
1234     }
1235     if ( mySketchType == PT_RELATIVE) {
1236       myNewCommand = myNewCommand + "T " + QString::number( myDX ) + " " + QString::number( myDY );
1237       theParameters = myDXStr + ":" + myDYStr;
1238     }
1239     if ( mySketchType == DIR_ANGLE_LENGTH ) {
1240       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1241       myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength );
1242       theParameters = myAngleStr + ":" + myLengthStr;
1243     }
1244     if ( mySketchType == DIR_ANGLE_X ) {
1245       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1246       myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX );
1247       theParameters = myAngleStr + ":" + myXStr;
1248     }
1249     if ( mySketchType == DIR_ANGLE_Y ) {
1250       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1251       myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY );
1252       theParameters = myAngleStr + ":" + myYStr;
1253     }
1254     if ( mySketchType == DIR_PER_LENGTH ) {
1255       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1256       myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength );
1257       theParameters = QString::number( 90.0 ) + ":" + myLengthStr;
1258     }
1259     if ( mySketchType == DIR_PER_X ) {
1260       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1261       myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX );
1262       theParameters = QString::number( 90.0 ) + ":" + myXStr;
1263     }
1264     if ( mySketchType == DIR_PER_Y ) {
1265       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1266       myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY );
1267       theParameters = QString::number( 90.0 ) + ":" + myYStr;
1268     }
1269     if ( mySketchType == DIR_TAN_LENGTH ) {
1270       myNewCommand = myNewCommand + "L " + QString::number( myLength );
1271       theParameters = myLengthStr;
1272     }
1273     if ( mySketchType == DIR_TAN_X ) {
1274       myNewCommand = myNewCommand + "IX " + QString::number( myX );
1275       theParameters = myXStr;
1276     }
1277     if ( mySketchType == DIR_TAN_Y) {
1278       myNewCommand = myNewCommand + "IY " + QString::number(myY);
1279       theParameters = myYStr;
1280     }
1281     if ( mySketchType == DIR_DXDY_LENGTH ) {
1282       myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1283       myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength );
1284       theParameters = myDXStr + ":" + myDYStr + ":" + myLengthStr;
1285     }
1286     if ( mySketchType == DIR_DXDY_X ) {
1287       myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1288       myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX );
1289       theParameters = myDXStr + ":" + myDYStr + ":" + myXStr;
1290     }
1291     if ( mySketchType == DIR_DXDY_Y ) {
1292       myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1293       myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY );
1294       theParameters = myDXStr + ":" + myDYStr + ":" + myYStr;
1295     }
1296   }
1297   else if ( myConstructorId == 1 ) {  // ARC
1298     if ( mySketchType == DIR_ANGLE_LENGTH ) {
1299       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1300       myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1301       theParameters = myAngleStr + ":" + myRadiusStr + ":" + myLengthStr;
1302     }
1303     if ( mySketchType == DIR_PER_LENGTH ) {
1304       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1305       myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1306       theParameters = QString::number( 90.0 ) + ":" + myRadiusStr + ":" + myLengthStr;
1307     }
1308     if ( mySketchType == DIR_TAN_LENGTH ) {
1309       myNewCommand = myNewCommand + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1310       theParameters = myRadiusStr + ":" + myLengthStr;
1311     }
1312     if ( mySketchType == DIR_DXDY_LENGTH ) {
1313       myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1314       myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1315       theParameters = myDXStr + ":" + myDYStr + ":" + myRadiusStr + ":" + myLengthStr;
1316     }
1317   }
1318   return myNewCommand;
1319 }
1320
1321 //=================================================================================
1322 // function : createOperation
1323 // purpose  :
1324 //=================================================================================
1325 GEOM::GEOM_IOperations_ptr EntityGUI_SketcherDlg::createOperation()
1326 {
1327   return getGeomEngine()->GetICurvesOperations( getStudyId() );
1328 }
1329
1330 //=================================================================================
1331 // function : isValid
1332 // purpose  :
1333 //=================================================================================
1334 bool EntityGUI_SketcherDlg::isValid( QString& msg )
1335 {
1336   bool ok = true;
1337   bool toCorrect = !IsPreview() || myIsApply;
1338
1339   if( Group1Spin->isVisible() ) {
1340     ok = Group1Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1341   }
1342   else if( Group2Spin->isVisible() ) {
1343     ok = Group2Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1344     ok = Group2Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
1345   }
1346   else if( Group3Spin->isVisible() ) {
1347     ok = Group3Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1348     ok = Group3Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
1349     ok = Group3Spin->SpinBox_DZ->isValid( msg, toCorrect ) && ok;
1350   }
1351   else if( Group4Spin->isVisible() ) {
1352     ok = Group4Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1353     ok = Group4Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
1354     ok = Group4Spin->SpinBox_DZ->isValid( msg, toCorrect ) && ok;
1355     ok = Group4Spin->SpinBox_DS->isValid( msg, toCorrect ) && ok;
1356   }
1357
1358   if( myIsApply && !ok )
1359     showError( msg );
1360
1361   return ok;
1362 }
1363
1364 //=================================================================================
1365 // function : execute
1366 // purpose  :
1367 //=================================================================================
1368 bool EntityGUI_SketcherDlg::execute( ObjectList& objects )
1369 {
1370   QString aParameters;
1371
1372   if ( mySketchState == FIRST_POINT ) {
1373     myLastX2 = myX;
1374     myLastY2 = myY;
1375   }
1376   else {
1377     //Test if the current point is the same as the last one
1378     TopoDS_Shape myShape1, myShape2;
1379
1380     //Last Shape
1381     QString Command1 = myCommand.join( "" );
1382     Sketcher_Profile aProfile1( Command1.toAscii() );
1383     if ( aProfile1.IsDone() )
1384       myShape1 = aProfile1.GetShape();
1385
1386     //Current Shape
1387     QString Command2 = Command1 + GetNewCommand( aParameters );
1388     Sketcher_Profile aProfile2( Command2.toAscii() );
1389     if ( aProfile2.IsDone() )
1390       myShape2 = aProfile2.GetShape();
1391
1392     if ( myShape2.IsNull() ) {
1393       //the current point is the same as the last one
1394       myLastX2 = myLastX1;
1395       myLastY2 = myLastY1;
1396     }
1397     else {
1398       TopoDS_Vertex V1, V2;
1399       gp_Pnt pt;
1400       if ( myShape1.ShapeType() == TopAbs_VERTEX ) {
1401         //the last shape is the first point
1402         pt = BRep_Tool::Pnt( TopoDS::Vertex( myShape1 ) );
1403         myLastX1 = pt.X();
1404         myLastY1 = pt.Y();
1405       }
1406       else {
1407         TopExp::Vertices( TopoDS::Wire( myShape1 ), V1, V2 );
1408         pt = BRep_Tool::Pnt( V2 );
1409         myLastX1 = pt.X();
1410         myLastY1 = pt.Y();
1411       }
1412       TopExp::Vertices( TopoDS::Wire( myShape2 ), V1, V2 );
1413       pt = BRep_Tool::Pnt( V2 );
1414       myLastX2 = pt.X();
1415       myLastY2 = pt.Y();
1416     }
1417   }
1418
1419   QString cmd;
1420   if ( ( mySketchState != FIRST_POINT &&
1421          myLastX1 == myLastX2 && myLastY1 == myLastY2 ) || myIsAllAdded ) {
1422     cmd = myCommand.join( "" );
1423
1424     if ( Group1Sel->isVisible() ) {
1425       Group1Sel->buttonApply->setEnabled( false );
1426       //Group1Sel->buttonApply->setFocus();
1427     }
1428     if ( Group1Spin->isVisible() ) {
1429       Group1Spin->buttonApply->setEnabled( false );
1430       //Group1Spin->buttonApply->setFocus();
1431     }
1432     if ( Group2Spin->isVisible() ) {
1433       Group2Spin->buttonApply->setEnabled( false );
1434       //Group2Spin->buttonApply->setFocus();
1435     }
1436     if ( Group3Spin->isVisible() ) {
1437       Group3Spin->buttonApply->setEnabled( false );
1438       //Group3Spin->buttonApply->setFocus();
1439     }
1440     if ( Group4Spin->isVisible() ) {
1441       Group4Spin->buttonApply->setEnabled( false );
1442       //Group4Spin->buttonApply->setFocus();
1443     }
1444   }
1445   else {
1446     cmd = myCommand.join( "" ) + GetNewCommand( aParameters );
1447
1448     if ( Group1Sel->isVisible() ) {
1449       Group1Sel->buttonApply->setEnabled( true );
1450       //Group1Sel->buttonApply->setFocus();
1451     }
1452     if ( Group1Spin->isVisible() ) {
1453       Group1Spin->buttonApply->setEnabled( true );
1454       //Group1Spin->buttonApply->setFocus();
1455     }
1456     if ( Group2Spin->isVisible() ) {
1457       Group2Spin->buttonApply->setEnabled( true );
1458       //Group2Spin->buttonApply->setFocus();
1459     }
1460     if ( Group3Spin->isVisible() ) {
1461       Group3Spin->buttonApply->setEnabled( true );
1462       //Group3Spin->buttonApply->setFocus();
1463     }
1464     if ( Group4Spin->isVisible() ) {
1465       Group4Spin->buttonApply->setEnabled( true );
1466       //Group4Spin->buttonApply->setFocus();
1467     }
1468   }
1469
1470   gp_Ax3 myWPlane = GetActiveLocalCS();
1471   GEOM::ListOfDouble_var WPlane = new GEOM::ListOfDouble;
1472   WPlane->length( 9 );
1473   WPlane[0] = myWPlane.Location().X();
1474   WPlane[1] = myWPlane.Location().Y();
1475   WPlane[2] = myWPlane.Location().Z();
1476
1477   WPlane[3] = myWPlane.Direction().X();
1478   WPlane[4] = myWPlane.Direction().Y();
1479   WPlane[5] = myWPlane.Direction().Z();
1480
1481   WPlane[6] = myWPlane.XDirection().X();
1482   WPlane[7] = myWPlane.XDirection().Y();
1483   WPlane[8] = myWPlane.XDirection().Z();
1484
1485   GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow(getOperation());
1486   GEOM::GEOM_Object_var anObj = anOper->MakeSketcher( cmd.toLatin1().constData(), WPlane );
1487
1488   if ( !anObj->_is_nil() )
1489   {
1490     if( !IsPreview() ) {
1491       QStringList aCurrentParameters = myParameters;
1492       aCurrentParameters << aParameters;
1493       myNoteBook->setParameters(anObj, aCurrentParameters);
1494     }
1495
1496     objects.push_back( anObj._retn() );
1497   }
1498
1499   return true;
1500 }
1501
1502 //================================================================
1503 // Function : displayPreview
1504 // Purpose  : Method for displaying preview of resulting shape
1505 //            Redefined from GEOMBase_Helper.
1506 //================================================================
1507 void EntityGUI_SketcherDlg::displayPreview( GEOM::GEOM_Object_ptr object,
1508                                             const bool            append,
1509                                             const bool            activate,
1510                                             const bool            update,
1511                                             const double          lineWidth,
1512                                             const int             displayMode,
1513                                             const int             color )
1514 {
1515   // Set color for preview shape
1516   getDisplayer()->SetColor( Quantity_NOC_RED );
1517
1518   // set width of displayed shape
1519   getDisplayer()->SetWidth( (lineWidth == -1)?myLineWidth:lineWidth );
1520
1521   // Disable activation of selection
1522   getDisplayer()->SetToActivate( activate );
1523
1524   // Make a reference to GEOM_Object
1525   CORBA::String_var objStr = myGeometryGUI->getApp()->orb()->object_to_string( object );
1526   getDisplayer()->SetName( objStr.in() );
1527
1528   // Create wire from applayed object
1529   TopoDS_Shape anApplyedWire, aLastSegment;
1530   if ( !createShapes( object, anApplyedWire, aLastSegment ) )
1531     return;
1532
1533   // Build prs
1534   SALOME_Prs* aPrs = getDisplayer()->BuildPrs( anApplyedWire );
1535   if ( aPrs != 0 && !aPrs->IsNull() )
1536     GEOMBase_Helper::displayPreview( aPrs, append, update );
1537
1538   getDisplayer()->SetColor( Quantity_NOC_VIOLET );
1539   aPrs = getDisplayer()->BuildPrs( aLastSegment );
1540   if ( aPrs != 0 && !aPrs->IsNull() )
1541     GEOMBase_Helper::displayPreview( aPrs, append, update );
1542
1543   getDisplayer()->UnsetName();
1544
1545   // Enable activation of displayed objects
1546   getDisplayer()->SetToActivate( true );
1547 }
1548
1549 //================================================================
1550 // Function : createShapes
1551 // Purpose  : Create applyed wire, and last segment from entry object
1552 //================================================================
1553 bool EntityGUI_SketcherDlg::createShapes( GEOM::GEOM_Object_ptr theObject,
1554                                           TopoDS_Shape&         theApplyedWire,
1555                                           TopoDS_Shape&         theLastSegment )
1556 {
1557   TopoDS_Shape aShape;
1558   if ( !GEOMBase::GetShape( theObject, aShape ) ||
1559        aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX )
1560     return false;
1561
1562   if ( Group1Sel->isVisible()  && !Group1Sel->buttonApply->isEnabled()  ||
1563        Group1Spin->isVisible() && !Group1Spin->buttonApply->isEnabled() ||
1564        Group2Spin->isVisible() && !Group2Spin->buttonApply->isEnabled() ||
1565        Group3Spin->isVisible() && !Group3Spin->buttonApply->isEnabled() ||
1566        Group4Spin->isVisible() && !Group4Spin->buttonApply->isEnabled() ) {
1567      theApplyedWire = aShape;
1568      return true;
1569   }
1570
1571   BRepBuilderAPI_MakeWire aBuilder;
1572   TopExp_Explorer anExp( aShape, TopAbs_EDGE );
1573   while ( 1 ) {
1574     TopoDS_Shape anEdge = anExp.Current();
1575     anExp.Next();
1576     if ( anExp.More() ) // i.e. non-last edge
1577       aBuilder.Add( TopoDS::Edge( anEdge ) );
1578     else {
1579       theLastSegment = anEdge;
1580       break;
1581     }
1582   }
1583
1584   if ( aBuilder.IsDone() )
1585     theApplyedWire = aBuilder.Shape();
1586
1587   return true;
1588 }
1589
1590 //=================================================================================
1591 // function : keyPressEvent()
1592 // purpose  :
1593 //=================================================================================
1594 void  EntityGUI_SketcherDlg::keyPressEvent( QKeyEvent* e )
1595 {
1596   QDialog::keyPressEvent( e );
1597   if ( e->isAccepted() )
1598     return;
1599
1600   if ( e->key() == Qt::Key_F1 ) {
1601     e->accept();
1602     ClickOnHelp();
1603   }
1604 }
1605
1606 void EntityGUI_SketcherDlg::initSpinBox( SalomeApp_DoubleSpinBox* spinBox,
1607                                          double min,  double max,
1608                                          double step, int decimals )
1609 {
1610   spinBox->setDecimals( decimals );
1611   spinBox->setRange( min, max );
1612   spinBox->setSingleStep( step );
1613 }
1614
1615 //=================================================================================
1616 // function : SetDoubleSpinBoxStep()
1617 // purpose  : Double spin box management
1618 //=================================================================================
1619 void EntityGUI_SketcherDlg::SetDoubleSpinBoxStep( double step )
1620 {
1621   Group1Spin->SpinBox_DX->setSingleStep(step);
1622   Group2Spin->SpinBox_DX->setSingleStep(step);
1623   Group2Spin->SpinBox_DY->setSingleStep(step);
1624   Group3Spin->SpinBox_DX->setSingleStep(step);
1625   Group3Spin->SpinBox_DY->setSingleStep(step);
1626   Group3Spin->SpinBox_DZ->setSingleStep(step);
1627   Group4Spin->SpinBox_DX->setSingleStep(step);
1628   Group4Spin->SpinBox_DY->setSingleStep(step);
1629   Group4Spin->SpinBox_DZ->setSingleStep(step);
1630   Group4Spin->SpinBox_DS->setSingleStep(step);
1631 }
1632
1633 //=================================================================================
1634 // function : FindLocalCS()
1635 // purpose  : Find All Coordinates systems in study
1636 //=================================================================================
1637 void EntityGUI_SketcherDlg::FindLocalCS()
1638 {
1639   ComboBox1->clear();
1640   myLCSList.clear();
1641   SalomeApp_Application* app =
1642     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1643   if ( !app )
1644     return;
1645
1646   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1647   if ( !appStudy )
1648     return;
1649
1650   _PTR(Study) aStudy = appStudy->studyDS();
1651
1652   //add Global CS
1653   ComboBox1->addItem(tr("GEOM_GCS"));
1654   gp_Pnt aOrigin = gp_Pnt(0, 0, 0);
1655   gp_Dir aDirZ = gp_Dir(0, 0, 1);
1656   gp_Dir aDirX = gp_Dir(1, 0, 0);
1657   gp_Ax3 globalCS = gp_Ax3(aOrigin, aDirZ, aDirX);
1658   myLCSList.push_back(globalCS);
1659
1660   // get GEOM component
1661   CORBA::String_var geomIOR = app->orb()->object_to_string( GeometryGUI::GetGeomGen() );
1662   _PTR(SObject) obj = aStudy->FindObjectIOR( geomIOR.in() );
1663   if (!obj)
1664     return;
1665   _PTR(SComponent) fc = obj->GetFatherComponent();
1666   QString geomComp = fc->GetID().c_str();
1667   _PTR(SObject) comp = aStudy->FindObjectID( geomComp.toLatin1().data() );
1668   if ( !comp )
1669     return;
1670
1671   // browse through all GEOM data tree
1672   _PTR(ChildIterator) it ( aStudy->NewChildIterator( comp ) );
1673   for ( it->InitEx( true ); it->More(); it->Next() ) {
1674     _PTR(SObject) child( it->Value() );
1675     CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( child );
1676     GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
1677     if( CORBA::is_nil( geomObj ) ) 
1678       continue;
1679     if (geomObj->GetType() == GEOM_MARKER) {
1680       ComboBox1->addItem(geomObj->GetName());
1681       TopoDS_Shape aShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), geomObj);
1682       
1683       gp_Ax3 aLCS;
1684       aLCS.Transform(aShape.Location().Transformation());
1685       if (aShape.ShapeType() == TopAbs_FACE) {
1686         Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(aShape));
1687         if (!aGS.IsNull() && aGS->IsKind(STANDARD_TYPE(Geom_Plane))) {
1688           Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast(aGS);
1689           gp_Pln aPln = aGPlane->Pln();
1690           aLCS = aPln.Position();
1691         }
1692       }
1693       myLCSList.push_back(aLCS);
1694     }
1695   }
1696 }
1697
1698 //=================================================================================
1699 // function : GetActiveLocalCS()
1700 // purpose  : Find All Coordinates systems in study
1701 //=================================================================================
1702 gp_Ax3 EntityGUI_SketcherDlg::GetActiveLocalCS()
1703 {
1704   int ind = ComboBox1->currentIndex();
1705   if (ind == -1)
1706     return myGeometryGUI->GetWorkingPlane();
1707
1708   gp_Ax3 aLCS = myLCSList.at(ind);
1709
1710   myGeometryGUI->SetWorkingPlane( aLCS );
1711   myGeometryGUI->ActiveWorkingPlane();
1712   return aLCS;
1713 }