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