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