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