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