]> SALOME platform Git repositories - modules/geom.git/blob - src/EntityGUI/EntityGUI_SketcherDlg.cxx
Salome HOME
5e9b3b1775e63fc47692d9f3f33ffd9c306219a5
[modules/geom.git] / src / EntityGUI / EntityGUI_SketcherDlg.cxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : EntityGUI_SketcherDlg.cxx
25 // Author : Damien COQUERET, Open CASCADE S.A.S.
26 //
27 #include "EntityGUI_SketcherDlg.h"
28 #include "EntityGUI_Widgets.h"
29 #include <SalomeApp_DoubleSpinBox.h>
30
31 #include <GEOMBase.h>
32 #include <GeometryGUI.h>
33 #include <GEOMImpl_Types.hxx>
34 #include <Geom_Surface.hxx>
35 #include <Geom_Plane.hxx>
36
37 #include <SUIT_Desktop.h>
38 #include <SUIT_Session.h>
39 #include <SUIT_MessageBox.h>
40 #include <SUIT_ResourceMgr.h>
41 #include <SalomeApp_Application.h>
42 #include <LightApp_Application.h>
43 #include <LightApp_SelectionMgr.h>
44
45 #include <QKeyEvent>
46
47 #include <BRep_Tool.hxx>
48 #include <TopExp.hxx>
49 #include <TopExp_Explorer.hxx>
50 #include <TopoDS_Vertex.hxx>
51 #include <TopoDS.hxx>
52 #include <BRepBuilderAPI_Transform.hxx>
53 #include <BRepBuilderAPI_MakeWire.hxx>
54 #include <BRepBuilderAPI_MakeVertex.hxx>
55 #include <Sketcher_Profile.hxx>
56
57 #include <SalomeApp_Study.h>
58
59 #include <gp_Pln.hxx>
60
61 #include <Basics_Utils.hxx>
62
63 //=================================================================================
64 // class    : EntityGUI_SketcherDlg()
65 // purpose  : Constructs a EntityGUI_SketcherDlg which is a child of 'parent', with the
66 //            name 'name' and widget flags set to 'f'.
67 //            The dialog will by default be modeless, unless you set 'modal' to
68 //            TRUE to construct a modal dialog.
69 //=================================================================================
70 EntityGUI_SketcherDlg::EntityGUI_SketcherDlg( GeometryGUI* GUI, QWidget* parent,
71                                               bool modal, Qt::WindowFlags fl,
72                                               const double lineWidth )
73   : QDialog( parent, fl ),
74     myIsAllAdded( false ),
75     myIsApply( false ),
76     GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
77     myGeometryGUI( GUI ),
78     myLineWidth( lineWidth )
79 {
80   setModal( modal );
81   setAttribute( Qt::WA_DeleteOnClose );
82
83   myGeometryGUI->SetActiveDialogBox(this);
84
85   MainWidget = new EntityGUI_Skeleton( this );
86   QVBoxLayout* topLayout = new QVBoxLayout( this );
87   topLayout->setMargin( 9 ); topLayout->setSpacing( 6 );
88
89   MainWidget->buttonCancel->setText( tr( "GEOM_BUT_CANCEL" ) );
90   MainWidget->buttonEnd->setText( tr( "GEOM_BUT_END_SKETCH" ) );
91   MainWidget->buttonClose->setText( tr( "GEOM_BUT_CLOSE_SKETCH" ) );
92   MainWidget->buttonHelp->setText( tr( "GEOM_BUT_HELP" ) );
93
94   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
95   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_UNDO" ) ) );
96   QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_REDO" ) ) );
97
98   setWindowTitle( tr( "GEOM_SKETCHER_TITLE" ) );
99
100   MainWidget->GroupConstructors->setTitle( tr( "GEOM_SKETCHER_EL" ) );
101   MainWidget->RadioButton1->setText( tr( "GEOM_SKETCHER_SEGMENT" ) );
102   MainWidget->RadioButton2->setText( tr( "GEOM_SKETCHER_ARC" ) );
103   MainWidget->GroupDest->setTitle( tr( "GEOM_SKETCHER_DEST" ) );
104   MainWidget->GroupDest1->setTitle( tr( "GEOM_SKETCHER_TYPE" ) );
105   MainWidget->RB_Dest1->setText( tr( "GEOM_SKETCHER_POINT" ) );
106   MainWidget->RB_Dest2->setText( tr( "GEOM_SKETCHER_DIR" ) );
107
108   /***************************************************************/
109
110   GroupBox1 = new QGroupBox(tr("GEOM_CS"), this);
111   QHBoxLayout* planeLayout = new QHBoxLayout(GroupBox1);
112   planeLayout->setSpacing(6);
113   planeLayout->setMargin(11);
114
115   ComboBox1 = new QComboBox(GroupBox1);
116   ComboBox1->setSizePolicy( QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed) );
117   planeLayout->addWidget(ComboBox1);
118
119   planeButton = new QPushButton (GroupBox1);
120   planeButton->setSizePolicy( QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed));
121   planeButton->setText( tr( "GEOM_SKETCHER_RESTORE" ) );
122   planeLayout->addWidget(planeButton);
123
124   topLayout->addWidget(GroupBox1);
125   topLayout->addWidget( MainWidget );
126   topLayout->setStretch( 1, 1);
127
128   GroupPt = new EntityGUI_Point( MainWidget->DestCnt );
129
130   GroupPt->GroupPoint->setTitle( tr( "GEOM_SKETCHER_POINT" ) );
131   GroupPt->RB_Point1->setText( tr( "GEOM_SKETCHER_ABS" ) );
132   GroupPt->RB_Point2->setText( tr( "GEOM_SKETCHER_REL" ) );
133   GroupPt->RB_Point3->setText( tr( "GEOM_SKETCHER_SEL" ) );
134
135   GroupPt2 = new EntityGUI_Point( MainWidget->DestCnt );
136
137   GroupPt2->GroupPoint->setTitle( tr( "GEOM_SKETCHER_ADD_PARAMS" ) ); 
138   GroupPt2->RB_Point1->setText( tr( "GEOM_SKETCHER_NONE" ) );
139   GroupPt2->RB_Point2->setText( tr( "GEOM_SKETCHER_RADIUS" ) );
140   GroupPt2->RB_Point3->setText( tr( "GEOM_SKETCHER_CENTER" ) ); 
141
142   GroupD1 = new EntityGUI_Dir1( MainWidget->DestCnt );
143
144   GroupD1->GroupDir1->setTitle( tr( "GEOM_SKETCHER_DIR" ) );
145   GroupD1->RB_Dir11->setText( tr( "GEOM_SKETCHER_ANGLE" ) );
146   GroupD1->RB_Dir12->setText( tr( "GEOM_SKETCHER_PER" ) );
147   GroupD1->RB_Dir13->setText( tr( "GEOM_SKETCHER_TAN" ) );
148   GroupD1->RB_Dir14->setText( tr( "GEOM_SKETCHER_VXVY" ) );
149
150   GroupD2 = new EntityGUI_Dir2( MainWidget->DestCnt );
151
152   GroupD2->GroupDir2->setTitle( tr( "GEOM_SKETCHER_DIR" ) );
153   GroupD2->RB_Dir21->setText( tr( "GEOM_SKETCHER_LENGTH" ) );
154   GroupD2->RB_Dir22->setText( tr( "GEOM_SKETCHER_X" ) );
155   GroupD2->RB_Dir23->setText( tr( "GEOM_SKETCHER_Y" ) );
156
157   Group1Sel = new EntityGUI_1Sel( MainWidget->SkeletonCnt );
158   Group1Sel->TextLabel1->setText( tr( "GEOM_SKETCHER_POINT2" ) );
159   Group1Sel->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
160   Group1Sel->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
161   Group1Sel->PushButton1->setIcon( image0 );
162   Group1Sel->buttonUndo->setIcon( image1 );
163   Group1Sel->buttonRedo->setIcon( image2 );
164   Group1Sel->LineEdit1->setReadOnly( true );
165
166   Group2Sel = new EntityGUI_2Sel1Check( MainWidget->SkeletonCnt );
167   Group2Sel->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
168   Group2Sel->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
169   Group2Sel->checkBox->setText( tr( "GEOM_REVERSE" ) );
170   Group2Sel->PushButton1->setIcon( image0 );
171   Group2Sel->PushButton2->setIcon( image0 );
172   Group2Sel->buttonUndo->setIcon( image1 );
173   Group2Sel->buttonRedo->setIcon( image2 );
174   Group2Sel->LineEdit1->setReadOnly( true );
175   Group2Sel->LineEdit2->setReadOnly( true );
176
177   Group1Sel1Spin = new EntityGUI_1Sel1Spin1Check( MainWidget->SkeletonCnt );
178   Group1Sel1Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
179   Group1Sel1Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
180   Group1Sel1Spin->checkBox->setText( tr( "GEOM_REVERSE" ) );
181   Group1Sel1Spin->PushButton1->setIcon( image0 );
182   Group1Sel1Spin->buttonUndo->setIcon( image1 );
183   Group1Sel1Spin->buttonRedo->setIcon( image2 );
184   Group1Sel1Spin->LineEdit1->setReadOnly( true );
185
186   Group1Spin = new EntityGUI_1Spin( MainWidget->SkeletonCnt );
187   Group1Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
188   Group1Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
189   Group1Spin->buttonUndo->setIcon( image1 );
190   Group1Spin->buttonRedo->setIcon( image2 );
191
192   Group2Spin = new EntityGUI_2Spin( MainWidget->SkeletonCnt );
193   Group2Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
194   Group2Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
195   Group2Spin->buttonUndo->setIcon( image1 );
196   Group2Spin->buttonRedo->setIcon( image2 );
197
198   Group3Spin = new EntityGUI_3Spin1Check( MainWidget->SkeletonCnt );
199   Group3Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
200   Group3Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
201   Group3Spin->checkBox->setText( tr( "GEOM_REVERSE" ) );
202   Group3Spin->buttonUndo->setIcon( image1 );
203   Group3Spin->buttonRedo->setIcon( image2 );
204
205   Group4Spin = new EntityGUI_4Spin1Check( MainWidget->SkeletonCnt );
206   Group4Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
207   Group4Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
208   Group4Spin->checkBox->setText( tr( "GEOM_REVERSE" ) );
209   Group4Spin->buttonUndo->setIcon( image1 );
210   Group4Spin->buttonRedo->setIcon( image2 );
211
212   // Defines a palette for the error message on Group4Spin and Group2Sel 
213   QPalette palette;
214   QColor color("red");
215   palette.setColor(Group4Spin->label->foregroundRole(), color);
216   Group4Spin->label->setPalette(palette);
217   palette.setColor(Group2Sel->label->foregroundRole(), color);
218   Group2Sel->label->setPalette(palette);
219
220   QGridLayout* DestCntLayout = new QGridLayout( MainWidget->DestCnt );
221   DestCntLayout->setMargin( 0 ); DestCntLayout->setSpacing( 6 );
222   DestCntLayout->addWidget( GroupPt, 0, 0 );
223   DestCntLayout->addWidget( GroupPt2, 0, 1 );
224   DestCntLayout->addWidget( GroupD1, 0, 0 );
225   DestCntLayout->addWidget( GroupD2, 0, 1 );
226
227   QVBoxLayout* SkeletonCntlayout = new QVBoxLayout( MainWidget->SkeletonCnt );
228   SkeletonCntlayout->setMargin( 0 ); SkeletonCntlayout->setSpacing( 6 );
229   SkeletonCntlayout->addWidget( Group1Sel,  0, 0 );
230   SkeletonCntlayout->addWidget( Group2Sel,  0, 0 );
231   SkeletonCntlayout->addWidget( Group1Sel1Spin,  0, 0 );
232   SkeletonCntlayout->addWidget( Group1Spin, 0, 0 );
233   SkeletonCntlayout->addWidget( Group2Spin, 0, 0 );
234   SkeletonCntlayout->addWidget( Group3Spin, 0, 0 );
235   SkeletonCntlayout->addWidget( Group4Spin, 0, 0 );
236   //SkeletonCntlayout->setStretch( 0, 1);
237   /***************************************************************/
238
239   QButtonGroup* ButtonGroup = new QButtonGroup( this );
240   ButtonGroup->addButton( MainWidget->RB_Dest1, 1 );
241   ButtonGroup->addButton( MainWidget->RB_Dest2, 0 );
242
243   /* signals and slots connections */
244   connect( MainWidget->buttonEnd,    SIGNAL( clicked() ),              this, SLOT( ClickOnEnd() ) );
245   connect( MainWidget->buttonClose,  SIGNAL( clicked() ),              this, SLOT( ClickOnEnd() ) );
246   connect( MainWidget->buttonCancel, SIGNAL( clicked() ),              this, SLOT( ClickOnCancel() ) );
247   connect( MainWidget->buttonHelp,   SIGNAL( clicked() ),              this, SLOT( ClickOnHelp() ) );
248
249   connect( Group1Sel->buttonApply,   SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
250   connect( Group1Sel->buttonUndo,    SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
251   connect( Group1Sel->buttonRedo,    SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) );
252   connect( Group2Sel->buttonApply,   SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
253   connect( Group2Sel->buttonUndo,    SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
254   connect( Group2Sel->buttonRedo,    SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) );
255   connect( Group1Sel1Spin->buttonApply,SIGNAL( clicked() ),            this, SLOT( ClickOnApply() ) );
256   connect( Group1Sel1Spin->buttonUndo, SIGNAL( clicked() ),            this, SLOT( ClickOnUndo() ) );
257   connect( Group1Sel1Spin->buttonRedo, SIGNAL( clicked() ),            this, SLOT( ClickOnRedo() ) );
258   connect( Group1Spin->buttonApply,  SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
259   connect( Group1Spin->buttonUndo,   SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
260   connect( Group1Spin->buttonRedo,   SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) );
261   connect( Group2Spin->buttonApply,  SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
262   connect( Group2Spin->buttonUndo,   SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
263   connect( Group2Spin->buttonRedo,   SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) );
264   connect( Group3Spin->buttonApply,  SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
265   connect( Group3Spin->buttonUndo,   SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
266   connect( Group3Spin->buttonRedo,   SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) ) ;
267   connect( Group4Spin->buttonApply,  SIGNAL( clicked() ),              this, SLOT( ClickOnApply() ) );
268   connect( Group4Spin->buttonUndo,   SIGNAL( clicked() ),              this, SLOT( ClickOnUndo() ) );
269   connect( Group4Spin->buttonRedo,   SIGNAL( clicked() ),              this, SLOT( ClickOnRedo() ) );
270
271   connect( MainWidget->ButtonGroup,  SIGNAL( buttonClicked( int ) ),   this, SLOT( TypeClicked( int ) ) );
272   connect( ButtonGroup,              SIGNAL( buttonClicked( int ) ),   this, SLOT( DestClicked( int ) ) );
273   connect( GroupPt->ButtonGroup,     SIGNAL( buttonClicked( int ) ),   this, SLOT( PointClicked( int ) ) );
274   connect( GroupPt2->ButtonGroup,    SIGNAL( buttonClicked( int ) ),   this, SLOT( Point2Clicked( int ) ) );
275   connect( GroupD1->ButtonGroup,     SIGNAL( buttonClicked( int ) ),   this, SLOT( Dir1Clicked( int ) ) );
276   connect( GroupD2->ButtonGroup,     SIGNAL( buttonClicked( int ) ),   this, SLOT( Dir2Clicked( int ) ));
277
278   connect( Group1Sel->LineEdit1,     SIGNAL( returnPressed() ),        this, SLOT( LineEditReturnPressed() ) );
279   connect( Group1Sel->PushButton1,   SIGNAL( clicked() ),              this, SLOT( SetEditCurrentArgument() ) );
280
281   connect( Group2Sel->LineEdit1,     SIGNAL( returnPressed() ),        this, SLOT( LineEditReturnPressed() ) );
282   connect( Group2Sel->LineEdit2,     SIGNAL( returnPressed() ),        this, SLOT( LineEditReturnPressed() ) );
283   connect( Group2Sel->PushButton1,   SIGNAL( clicked() ),              this, SLOT( SetEditCurrentArgument() ) );
284   connect( Group2Sel->PushButton2,   SIGNAL( clicked() ),              this, SLOT( SetEditCurrentArgument() ) );
285
286   connect( Group1Sel1Spin->LineEdit1,SIGNAL( returnPressed() ),        this, SLOT( LineEditReturnPressed() ) );
287   connect( Group1Sel1Spin->PushButton1,SIGNAL( clicked() ),            this, SLOT( SetEditCurrentArgument() ) );
288   connect( Group1Sel1Spin->SpinBox_DX,SIGNAL( valueChanged( double ) ),this, SLOT( ValueChangedInSpinBox( double ) ) );
289
290   connect( Group1Spin->SpinBox_DX,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
291   connect( Group2Spin->SpinBox_DX,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
292   connect( Group2Spin->SpinBox_DY,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
293   connect( Group3Spin->SpinBox_DX,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
294   connect( Group3Spin->SpinBox_DY,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
295   connect( Group3Spin->SpinBox_DZ,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
296   connect( Group4Spin->SpinBox_DX,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
297   connect( Group4Spin->SpinBox_DY,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
298   connect( Group4Spin->SpinBox_DZ,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
299   connect( Group4Spin->SpinBox_DS,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
300
301   connect( Group3Spin->checkBox,     SIGNAL( stateChanged( int ) ),    this, SLOT( CheckBoxClicked( int ) ) );
302   connect( Group4Spin->checkBox,     SIGNAL( stateChanged( int ) ),    this, SLOT( CheckBoxClicked( int ) ) );
303   connect( Group2Sel->checkBox,      SIGNAL( stateChanged( int ) ),    this, SLOT( CheckBoxClicked( int ) ) );
304   connect( Group1Sel1Spin->checkBox, SIGNAL( stateChanged( int ) ),    this, SLOT( CheckBoxClicked( int ) ) );
305
306   connect( ComboBox1,                SIGNAL( activated( int ) ),       this, SLOT( SelectionIntoArgument() ) );
307   connect( planeButton,              SIGNAL( clicked() ),              this, SLOT( ActivateLocalCS() ) );
308
309   connect( myGeometryGUI,            SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
310
311   connect( myGeometryGUI,            SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
312   connect( myGeometryGUI,            SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
313   
314   // install event filter on spin-boxes to provide Apply action on Return pressed
315   Group1Spin->SpinBox_DX->installEventFilter(this);
316   Group1Sel1Spin->SpinBox_DX->installEventFilter(this);
317   Group2Spin->SpinBox_DX->installEventFilter(this);
318   Group2Spin->SpinBox_DY->installEventFilter(this);
319   Group3Spin->SpinBox_DX->installEventFilter(this);
320   Group3Spin->SpinBox_DY->installEventFilter(this);
321   Group3Spin->SpinBox_DZ->installEventFilter(this);
322   Group4Spin->SpinBox_DX->installEventFilter(this);
323   Group4Spin->SpinBox_DY->installEventFilter(this);
324   Group4Spin->SpinBox_DZ->installEventFilter(this);
325   Group4Spin->SpinBox_DS->installEventFilter(this);
326
327   Init();
328 }
329
330
331 //=================================================================================
332 // function : ~EntityGUI_SketcherDlg()
333 // purpose  : Destroys the object and frees any allocated resources
334 //=================================================================================
335 EntityGUI_SketcherDlg::~EntityGUI_SketcherDlg()
336 {
337   myGeometryGUI->SetActiveDialogBox( 0 );
338 }
339
340
341 //=================================================================================
342 // function : eventFilter()
343 // purpose  : event filter for spin-boxes to provide Apply action on Return pressed
344 //=================================================================================
345 bool EntityGUI_SketcherDlg::eventFilter (QObject* object, QEvent* event)
346 {
347   MESSAGE("EntityGUI_SketcherDlg::eventFilter")
348   if (event->type() == QEvent::KeyPress) {
349     QKeyEvent* ke = (QKeyEvent*)event;
350     if ( ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter ) {
351       if (object == Group1Spin->SpinBox_DX) {
352         Group1Spin->buttonApply->click();
353         return true;
354       } else if (object == Group1Sel1Spin->SpinBox_DX) {
355         Group1Sel1Spin->buttonApply->click();
356         return true;
357       } else if (object == Group2Spin->SpinBox_DX ||
358                  object == Group2Spin->SpinBox_DY) {
359         Group2Spin->buttonApply->click();
360         return true;
361       } else if (object == Group3Spin->SpinBox_DX ||
362                  object == Group3Spin->SpinBox_DY ||
363                  object == Group3Spin->SpinBox_DZ) {
364         Group3Spin->buttonApply->click();
365         return true;
366       } else if (object == Group4Spin->SpinBox_DX ||
367                  object == Group4Spin->SpinBox_DY ||
368                  object == Group4Spin->SpinBox_DZ ||
369                  object == Group4Spin->SpinBox_DS) {
370         Group4Spin->buttonApply->click();
371         return true;
372       }
373     }
374   }
375
376   // Fix of the NPAL16010 bug is removed, because it's not actual with the Qt-4.x
377
378   return QDialog::eventFilter(object, event);
379 }
380
381
382 //=================================================================================
383 // function : Init()
384 // purpose  :
385 //=================================================================================
386 void EntityGUI_SketcherDlg::Init()
387 {
388   /* init variables */
389   autoApply = false;
390   myEditCurrentArgument = Group1Sel->LineEdit1;
391   myCommand.append( "Sketcher" );
392   myUndoCommand.append( "Sketcher" );
393
394   mySketchState = FIRST_POINT;
395   globalSelection( GEOM_POINT );
396
397   myCheckFlag = 0;
398
399   myLastX1 = 0.0;
400   myLastY1 = 0.0;
401   myLastX2 = 0.0;
402   myLastY2 = 0.0;
403
404   myHelpFileName = "create_sketcher_page.html";
405
406   /* Get setting of step value from file configuration */
407   double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
408
409   /* min, max, step and decimals for spin boxes */
410   initSpinBox( Group1Sel1Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
411   initSpinBox( Group1Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
412   initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
413   initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
414   initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
415   initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
416   initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
417   initSpinBox( Group4Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
418   // san: Note specific step values below!
419   initSpinBox( Group4Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
420   initSpinBox( Group4Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
421   initSpinBox( Group4Spin->SpinBox_DS, COORD_MIN, COORD_MAX, 5., "length_precision" );
422
423   /* displays Dialog */
424   MainWidget->GroupConstructors->setEnabled( false );
425   MainWidget->GroupDest1->setEnabled( false );
426   setEnabledUndo( false );
427   setEnabledRedo( false );
428
429   MainWidget->RadioButton1->setChecked( true );
430
431   TypeClicked( 0 );
432
433   FindLocalCS();
434   resize(100,100);
435
436   ActivateLocalCS();
437   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
438 }
439
440
441 //=================================================================================
442 // function : InitClick()
443 // purpose  :
444 //=================================================================================
445 void EntityGUI_SketcherDlg::InitClick()
446 {
447   disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
448   myCheckFlag = 0;
449
450   Group1Sel->hide();
451   Group2Sel->hide();
452   Group1Sel1Spin->hide();
453   Group1Spin->hide();
454   Group2Spin->hide();
455   Group3Spin->hide();
456   Group4Spin->hide();
457 }
458
459
460 //=================================================================================
461 // function : TypeClicked()
462 // purpose  : Radio button management
463 //=================================================================================
464 void EntityGUI_SketcherDlg::TypeClicked( int constructorId )
465 {
466   myConstructorId = constructorId;
467   if ( myConstructorId == 0 ) {    // SEGMENT
468     GroupPt2->RB_Point1->setChecked( true );
469     GroupPt2->setEnabled( false );
470     GroupD2->setEnabled( true );
471     MainWidget->RB_Dest1->setEnabled( true );
472     MainWidget->RB_Dest1->setChecked( true );
473     DestClicked( 1 );
474   }
475   else if (  myConstructorId == 1 ) { // ARC
476     GroupPt2->setEnabled( true );
477     GroupD2->RB_Dir21->setChecked( true );
478     GroupD2->setEnabled( false );
479     MainWidget->RB_Dest1->setEnabled( true ); 
480     MainWidget->RB_Dest1->setChecked( true );
481     DestClicked( 1 );
482   }
483 }
484
485
486 //=================================================================================
487 // function : DestClicked()
488 // purpose  : Radio button management
489 //=================================================================================
490 void EntityGUI_SketcherDlg::DestClicked( int constructorId )
491 {
492   GroupPt->hide();
493   GroupPt2->hide();
494   GroupD1->hide();
495   GroupD2->hide();
496
497   if ( constructorId == 1 ) {
498     // Point
499     GroupPt->RB_Point1->setChecked( true );
500     GroupPt->show();
501     GroupPt2->show();
502     Group3Spin->checkBox->show();
503     Group4Spin->checkBox->show();
504     PointClicked( 1 );  // XY
505   }
506   else if (  constructorId == 0 ) {
507     // Direction
508     GroupD1->RB_Dir11->setChecked( true );
509     GroupD1->show();
510     GroupD2->show();
511     Group3Spin->checkBox->hide();
512     Group4Spin->checkBox->hide();
513     Dir1Clicked( 2 );  // Angle
514   }
515   resize( minimumSizeHint() );
516 }
517
518 //=================================================================================
519 // function : PointClicked()
520 // purpose  : Radio button management
521 //=================================================================================
522 void EntityGUI_SketcherDlg::PointClicked( int constructorId )
523 {
524   MESSAGE("PointClicked")
525   myConstructorPntId = constructorId;  
526   GroupPt->RB_Point3->setEnabled( true );
527   int buttonId = GroupPt2->ButtonGroup->checkedId();
528   MESSAGE("checkedId ="<< buttonId)
529   if (buttonId >= 0){           // = If a button is checked
530     Point2Clicked(buttonId);
531   }
532   else{ 
533     GroupPt2->RB_Point1->setChecked( true );
534     Point2Clicked( 1 ); 
535   }
536 }
537
538 //=================================================================================
539 // function : Point2Clicked()
540 // purpose  : Radio button management
541 //=================================================================================
542 void EntityGUI_SketcherDlg::Point2Clicked( int constructorId )
543 {
544   MESSAGE("Point2Clicked")
545   InitClick();
546
547   // Get setting of step value from file configuration
548   double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
549
550   if ( myConstructorPntId == 1 ) {  // XY
551     if ( constructorId == 1 ){      // No additional parameter
552       mySketchType = PT_ABS;
553       initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
554       initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
555       Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X2" ) );
556       Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y2" ) );
557       myX = 0.0;
558       Group2Spin->SpinBox_DX->setValue( myX );
559       myY = 0.0;
560       Group2Spin->SpinBox_DY->setValue( myY );
561       Group2Spin->show();
562       Group2Spin->buttonApply->setFocus();
563
564       GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
565     }
566     else if ( constructorId == 0 ){   // Point + radius
567       mySketchType = PT_ABS_RADIUS;
568       initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" ); 
569       initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
570       initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step/10.0, "length_precision" );
571       Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X2" ) );
572       Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y2" ) );
573       Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_RADIUS2" ) ); 
574       myX = 0.0;
575       Group3Spin->SpinBox_DX->setValue( myX );
576       myY = 0.0;
577       Group3Spin->SpinBox_DY->setValue( myY );
578       myRadius=0.0;
579       Group3Spin->SpinBox_DZ->setValue( myRadius ); 
580       Group3Spin->show();
581       Group3Spin->buttonApply->setFocus();
582
583       GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
584     }
585     else if ( constructorId == 2 ){   // Point + center
586       mySketchType = PT_ABS_CENTER;
587       initSpinBox( Group4Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" ); 
588       initSpinBox( Group4Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
589       initSpinBox( Group4Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
590       initSpinBox( Group4Spin->SpinBox_DS, COORD_MIN, COORD_MAX, step, "length_precision" );
591       Group4Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_X2" ) );
592       Group4Spin->TextLabel4->setText( tr( "GEOM_SKETCHER_Y2" ) );
593       Group4Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_CENTER_X" ) );
594       Group4Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_CENTER_Y" ) ); 
595       myXc = 0.0;
596       Group4Spin->SpinBox_DX->setValue( myXc );
597       myYc = 0.0;
598       Group4Spin->SpinBox_DY->setValue( myYc );
599       myX = 0.0;
600       Group4Spin->SpinBox_DZ->setValue( myX ); 
601       myY = 0.0;
602       Group4Spin->SpinBox_DS->setValue( myY );
603       Group4Spin->show();
604       Group4Spin->buttonApply->setFocus();
605
606       GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
607     }
608
609   }
610   else if ( myConstructorPntId == 0 ) {  // DXDY
611     if ( constructorId == 1 ){    // No additional parameter
612       mySketchType = PT_RELATIVE;
613       initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
614       initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
615       Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_DX2" ) );
616       Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_DY2" ) );
617       myDX = 0.0;
618       Group2Spin->SpinBox_DX->setValue( myDX );
619       myDY = 0.0;
620       Group2Spin->SpinBox_DY->setValue( myDY );
621       Group2Spin->show();
622       Group2Spin->buttonApply->setFocus();
623
624       GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
625     }
626     else if ( constructorId == 0 ){   // Point + radius 
627       mySketchType = PT_REL_RADIUS;
628       initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" ); 
629       initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
630       initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step/10.0, "length_precision" );
631       Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_DX2" ) );
632       Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_DY2" ) );
633       Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_RADIUS2" ) ); 
634       myDX = 10.0;
635       Group3Spin->SpinBox_DX->setValue( myDX );
636       myDY = 0.0;
637       Group3Spin->SpinBox_DY->setValue( myDY );
638       myRadius=5.0;
639       Group3Spin->SpinBox_DZ->setValue( myRadius );
640       Group3Spin->show();
641       Group3Spin->buttonApply->setFocus();
642
643       GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
644     }
645     else if ( constructorId == 2 ){   // Point + center
646       mySketchType = PT_REL_CENTER;
647       initSpinBox( Group4Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" ); 
648       initSpinBox( Group4Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
649       initSpinBox( Group4Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
650       initSpinBox( Group4Spin->SpinBox_DS, COORD_MIN, COORD_MAX, step, "length_precision" );
651       Group4Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_DX2" ) );
652       Group4Spin->TextLabel4->setText( tr( "GEOM_SKETCHER_DY2" ) );
653       Group4Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_CENTER_DX" ) );
654       Group4Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_CENTER_DY" ) ); 
655       myDXc = 0.0;
656       Group4Spin->SpinBox_DX->setValue( myDXc );
657       myDYc = 0.0;
658       Group4Spin->SpinBox_DY->setValue( myDYc );
659       myDX = 0.0;
660       Group4Spin->SpinBox_DZ->setValue( myDX ); 
661       myDY = 0.0;
662       Group4Spin->SpinBox_DS->setValue( myDY );
663       Group4Spin->show();
664       Group4Spin->buttonApply->setFocus();
665
666       GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
667     }
668
669   }
670   else if ( myConstructorPntId == 2 ) {  // Selection
671     if ( constructorId == 1 ){    // No additional parameter
672       mySketchType = PT_SEL;
673       myEditCurrentArgument = Group1Sel->LineEdit1;
674       Group1Sel->TextLabel1->setText( tr( "GEOM_SKETCHER_END_POINT2" ) ); 
675       Group1Sel->show();
676       Group1Sel->buttonApply->setFocus();
677       SelectionIntoArgument();
678     }
679     else if ( constructorId == 0 ){   // Point + radius 
680       mySketchType = PT_SEL_RADIUS;
681       myEditCurrentArgument = Group1Sel1Spin->LineEdit1;
682       initSpinBox( Group1Sel1Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step/10.0, "length_precision" );
683       Group1Sel1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_END_POINT2" ) ); 
684       Group1Sel1Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_RADIUS2" ) ); 
685       myRadius=0.0;
686       Group1Sel1Spin->SpinBox_DX->setValue( myRadius );
687
688       Group1Sel1Spin->show();
689       Group1Sel1Spin->buttonApply->setFocus();
690       SelectionIntoArgument();
691     }
692     else if ( constructorId == 2 ){   // Point + center 
693       mySketchType = PT_SEL_CENTER;
694       myEditCurrentArgument = Group2Sel->LineEdit1;
695       Group2Sel->TextLabel2->setText( tr( "GEOM_SKETCHER_END_POINT2" ) );  
696       Group2Sel->TextLabel1->setText( tr( "GEOM_SKETCHER_CENTER2" ) );
697       Group2Sel->LineEdit1->setEnabled(true);
698       Group2Sel->PushButton1->setDown(true);
699       Group2Sel->LineEdit2->setEnabled(false);
700       Group2Sel->PushButton2->setDown(false);
701       Group2Sel->show();
702       Group2Sel->buttonApply->setFocus();
703       SelectionIntoArgument();
704     }
705
706   }
707   resize( minimumSizeHint() );
708   connect( myGeometryGUI->getApp()->selectionMgr(),
709            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
710   
711 }
712
713
714 //=================================================================================
715 // function : Dir1Clicked()
716 // purpose  : Radio button management
717 //=================================================================================
718 void EntityGUI_SketcherDlg::Dir1Clicked( int constructorId )
719 {
720   myConstructorDirId = constructorId;
721   int dirButtonId = GroupD2->ButtonGroup->checkedId();
722   MESSAGE("checkedId ="<< dirButtonId)
723   if (dirButtonId >= 0){           // = If a button is checked
724     Dir2Clicked(dirButtonId);
725   }
726   else{ 
727     GroupD2->RB_Dir21->setChecked( true );
728     Dir2Clicked( 2 ); 
729   }
730 }
731
732
733 //=================================================================================
734 // function : Dir2Clicked()
735 // purpose  : Radio button management
736 //=================================================================================
737 void EntityGUI_SketcherDlg::Dir2Clicked( int constructorId )
738 {
739   InitClick();
740   myAngle = 0.0;
741
742   // Get setting of step value from file configuration
743   double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
744
745   if ( myConstructorId == 0 ) {  // SEGMENT
746     myX = 0.0;
747     myY = 0.0;
748     myLength = 100.0;
749     if ( myConstructorDirId == 2 ) {  // Angle
750       initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 5., "length_precision" );
751       Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
752       Group2Spin->SpinBox_DX->setValue( myAngle );
753       Group2Spin->buttonApply->setFocus();
754       Group2Spin->show();
755
756       if ( constructorId == 2 ) {  // Length
757         mySketchType = DIR_ANGLE_LENGTH;
758         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
759         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
760         Group2Spin->SpinBox_DY->setValue( myLength );
761       }
762       else if ( constructorId == 0 ) {  // X
763         mySketchType = DIR_ANGLE_X;
764         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "angle_precision" );
765         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_X3" ) );
766         Group2Spin->SpinBox_DY->setValue( myX );
767       }
768       else if ( constructorId == 1 ) {  // Y
769         mySketchType = DIR_ANGLE_Y;
770         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "angle_precision" );        
771         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y3" ) );
772         Group2Spin->SpinBox_DY->setValue( myY );
773       }
774     }
775     else if ( myConstructorDirId == 0 ) {  // Perpendicular
776       Group1Spin->show();
777       Group1Spin->buttonApply->setFocus();
778
779       if ( constructorId == 2 ) {  // Length
780         mySketchType = DIR_PER_LENGTH;
781         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
782         Group1Spin->SpinBox_DX->setValue( myLength );
783       }
784       else if ( constructorId == 0 ) {  // X
785         mySketchType = DIR_PER_X;
786         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X3" ) );
787         Group1Spin->SpinBox_DX->setValue( myX );
788       }
789       else if ( constructorId == 1 ) {  // Y
790         mySketchType = DIR_PER_Y;
791         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_Y3" ) );
792         Group1Spin->SpinBox_DX->setValue( myY );
793       }
794     }
795     else if ( myConstructorDirId == 1 ) {  // Tangent
796       Group1Spin->show();
797       Group1Spin->buttonApply->setFocus();
798
799       if ( constructorId == 2 ) {  // Length
800         mySketchType = DIR_TAN_LENGTH;
801         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
802         Group1Spin->SpinBox_DX->setValue( myLength );
803       }
804       else if ( constructorId == 0 ) {  // X
805         mySketchType = DIR_TAN_X;
806         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X3" ) );
807         Group1Spin->SpinBox_DX->setValue( myX );
808       }
809       else if ( constructorId == 1 ) {  // Y
810         mySketchType = DIR_TAN_Y;
811         Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_Y3" ) );
812         Group1Spin->SpinBox_DX->setValue( myY );
813       }
814     }
815     else if ( myConstructorDirId == 3 ) {  // DXDY
816       initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
817       initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
818       initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
819       Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_VX2" ) );
820       Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_VY2" ) );
821       myDX = 0.0;
822       Group3Spin->SpinBox_DX->setValue( myDX );
823       myDY = 0.0;
824       Group3Spin->SpinBox_DY->setValue( myDY );
825       Group3Spin->show();
826       Group3Spin->buttonApply->setFocus();
827
828       if ( constructorId == 2 ) {  // Length
829         mySketchType = DIR_DXDY_LENGTH;
830         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
831         Group3Spin->SpinBox_DZ->setValue( myLength );
832       }
833       else if ( constructorId == 0 ) { // X
834         mySketchType = DIR_DXDY_X;
835         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_X3" ) );
836         Group3Spin->SpinBox_DZ->setValue( myX );
837       }
838       else if ( constructorId == 1 ) {  // Y
839         mySketchType = DIR_DXDY_Y;
840         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_Y3" ) );
841         Group3Spin->SpinBox_DZ->setValue( myY );
842       }
843     }
844   }
845   else if ( myConstructorId == 1 ) {  // ARC
846     if ( myConstructorDirId == 2 ) {  // Angle
847       if ( constructorId == 2 ) {  // Length
848         mySketchType = DIR_ANGLE_LENGTH;
849         initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 5., "angle_precision" );
850         initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
851         initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, 5., "angle_precision" );
852         Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
853         Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
854         Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_ANGLE2" ));
855         Group3Spin->SpinBox_DX->setValue( myAngle );
856         myRadius = 100.0;
857         Group3Spin->SpinBox_DY->setValue( myRadius );
858         myLength = 30.0;
859         Group3Spin->SpinBox_DZ->setValue( myLength );
860         Group3Spin->show();
861         Group3Spin->buttonApply->setFocus();
862       }
863     }
864     else if ( myConstructorDirId == 0 ) {  // Perpendicular
865       if ( constructorId == 2 ) {  // Length
866         mySketchType = DIR_PER_LENGTH;
867         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
868         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 5., "angle_precision" );
869         Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
870         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
871         myRadius = 100.0;
872         Group2Spin->SpinBox_DX->setValue( myRadius );
873         myLength = 30.0;
874         Group2Spin->SpinBox_DY->setValue( myLength );
875         Group2Spin->show();
876         Group2Spin->buttonApply->setFocus();
877       }
878     }
879     else if ( myConstructorDirId == 1 ) {  // Tangent
880       if ( constructorId == 2 ) {  // Length
881         mySketchType = DIR_TAN_LENGTH;
882         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
883         initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 5., "angle_precision" );
884         Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
885         Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
886         myRadius = 100.0;
887         Group2Spin->SpinBox_DX->setValue( myRadius );
888         myLength = 30.0;
889         Group2Spin->SpinBox_DY->setValue( myLength );
890         Group2Spin->show();
891         Group2Spin->buttonApply->setFocus();
892       }
893     }
894     else if ( myConstructorDirId == 3 ) {  // DXDY
895       if ( constructorId == 2 ) {  // Length
896         mySketchType = DIR_DXDY_LENGTH;
897         Group4Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_VX2" ) );
898         Group4Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_VY2" ) );
899         Group4Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
900         Group4Spin->TextLabel4->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
901         initSpinBox( Group4Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
902         initSpinBox( Group4Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
903         initSpinBox( Group4Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
904         initSpinBox( Group4Spin->SpinBox_DS, COORD_MIN, COORD_MAX, 5., "length_precision" );
905         myDX = 0.0;
906         Group4Spin->SpinBox_DX->setValue( myDX );
907         myDY = 0.0;
908         Group4Spin->SpinBox_DY->setValue( myDY );
909         myRadius = 100.0;
910         Group4Spin->SpinBox_DZ->setValue( myRadius );
911         myLength = 30.0;
912         Group4Spin->SpinBox_DS->setValue( myLength );
913         Group4Spin->show();
914         Group4Spin->buttonApply->setFocus();
915       }
916     }
917   }
918   resize( minimumSizeHint() );
919   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
920 }
921
922 //=================================================================================
923 // function : CheckBoxClicked()
924 // purpose  : CheckBox  management
925 //=================================================================================
926 void EntityGUI_SketcherDlg::CheckBoxClicked(int State)
927 {
928   myCheckFlag = State;
929
930   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
931 }
932
933
934 //=================================================================================
935 // function : ClickOnCancel()
936 // purpose  :
937 //=================================================================================
938 void EntityGUI_SketcherDlg::ClickOnCancel()
939 {
940   close();
941 }
942
943
944 //=================================================================================
945 // function : ClickOnEnd()
946 // purpose  : connected to buttonEnd AND buttonClose
947 //=================================================================================
948 void EntityGUI_SketcherDlg::ClickOnEnd()
949 {
950   if ( sender() == MainWidget->buttonClose ) {
951     // Verify validity of commands
952     if ( myCommand.count() <= 2 ) {
953       SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
954                                  tr( "GEOM_ERROR_STATUS" ), tr( "CANNOT_CLOSE" ), tr( "BUT_OK" ) );
955       return;
956     }
957
958     QString Parameters;
959     QString Command = myCommand.join( "" ) + GetNewCommand( Parameters );
960     Sketcher_Profile aProfile( Command.toAscii() );
961
962     Command = myCommand.join( "" );
963     aProfile = Sketcher_Profile( Command.toAscii() );
964     TopoDS_Shape myShape;
965     if ( aProfile.IsDone() )
966       myShape = aProfile.GetShape();
967
968     if ( myShape.ShapeType() != TopAbs_VERTEX )
969       myCommand.append( ":WW" );
970   }
971   else {
972     // PAL16008 (Sketcher Validation should be equal to Apply&Close)
973     if ( ( Group1Spin->buttonApply->isEnabled() && Group1Spin->isVisible() ) ||
974          ( Group2Spin->buttonApply->isEnabled() && Group2Spin->isVisible() ) ||
975          ( Group3Spin->buttonApply->isEnabled() && Group3Spin->isVisible() ) ||
976          ( Group4Spin->buttonApply->isEnabled() && Group4Spin->isVisible() ) ||
977          ( Group1Sel->buttonApply->isEnabled()  && Group1Sel->isVisible()  ) ||
978          ( Group2Sel->buttonApply->isEnabled()  && Group2Sel->isVisible()  ) ||
979          ( Group1Sel1Spin->buttonApply->isEnabled() && Group1Sel1Spin->isVisible() ) )  {     
980       ClickOnApply();
981     }
982     myIsAllAdded = true;
983   }
984
985   if ( myCommand.size() > 2 )
986     if ( !onAccept() )
987       return;
988
989   close();
990 }
991
992 //=================================================================================
993 // function : ClickOnApply()
994 // purpose  :
995 //=================================================================================
996 bool EntityGUI_SketcherDlg::ClickOnApply()
997 {
998   if ( sender() && sender()->inherits( "QPushButton" ) )
999     ( (QPushButton*)sender() )->setFocus(); // to update value of currently edited spin-box (PAL11948)
1000
1001   QString aParameters;
1002   myCommand.append( GetNewCommand( aParameters ) );
1003   mySketchState = NEXT_POINT;
1004
1005   myUndoCommand.clear();
1006   myUndoCommand.append( "Sketcher" );
1007
1008   myParameters.append( aParameters );
1009   myUndoParameters.clear();
1010
1011   MainWidget->GroupConstructors->setEnabled( true );
1012   MainWidget->GroupDest1->setEnabled( true );
1013   setEnabledUndo( true );
1014   setEnabledRedo( false );
1015
1016   myIsApply = true;
1017   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
1018   myIsApply = false;
1019
1020   // Set focus to SpinBox_DX
1021   if ( sender() == Group1Spin->buttonApply ) {
1022     (Group1Spin->SpinBox_DX)->setFocus();
1023     (Group1Spin->SpinBox_DX)->selectAll();
1024   }
1025   else if ( sender() == Group1Sel1Spin->buttonApply ) {
1026     (Group1Sel1Spin->SpinBox_DX)->setFocus();
1027     (Group1Sel1Spin->SpinBox_DX)->selectAll();
1028   }
1029   else if ( sender() == Group2Spin->buttonApply ) {
1030     (Group2Spin->SpinBox_DX)->setFocus();
1031     (Group2Spin->SpinBox_DX)->selectAll();
1032   }
1033   else if ( sender() == Group3Spin->buttonApply ) {
1034     (Group3Spin->SpinBox_DX)->setFocus();
1035     (Group3Spin->SpinBox_DX)->selectAll();
1036   }
1037   else if ( sender() == Group4Spin->buttonApply ) {
1038     (Group4Spin->SpinBox_DX)->setFocus();
1039     (Group4Spin->SpinBox_DX)->selectAll();
1040   }
1041
1042   return true;
1043 }
1044
1045 //=================================================================================
1046 // function : ClickOnHelp()
1047 // purpose  :
1048 //=================================================================================
1049 void EntityGUI_SketcherDlg::ClickOnHelp()
1050 {
1051   LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
1052   if ( app )
1053     app->onHelpContextModule( myGeometryGUI ? app->moduleName( myGeometryGUI->moduleName() ) : QString( "" ), myHelpFileName );
1054   else {
1055     QString platform;
1056 #ifdef WIN32
1057     platform = "winapplication";
1058 #else
1059     platform = "application";
1060 #endif
1061
1062     SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
1063                               QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
1064                               arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
1065                               QObject::tr( "BUT_OK" ) );
1066   }
1067 }
1068
1069 //=================================================================================
1070 // function : ClickOnUndo()
1071 // purpose  :
1072 //=================================================================================
1073 void EntityGUI_SketcherDlg::ClickOnUndo()
1074 {
1075   myUndoCommand.append( myCommand.last() );
1076   myCommand.pop_back();
1077
1078   myUndoParameters.append( myParameters.last() );
1079   myParameters.pop_back();
1080
1081   if ( myCommand.count() == 1 ) {
1082     mySketchState = FIRST_POINT;
1083
1084     MainWidget->RadioButton1->setChecked( true );
1085     TypeClicked( 0 );
1086
1087     connect( myGeometryGUI->getApp()->selectionMgr(),
1088              SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
1089
1090     MainWidget->GroupConstructors->setEnabled( false );
1091     MainWidget->GroupDest1->setEnabled( false );
1092     setEnabledUndo( false );
1093   }
1094
1095   setEnabledRedo( true );
1096
1097   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
1098 }
1099
1100 //=================================================================================
1101 // function : ClickOnRedo()
1102 // purpose  :
1103 //=================================================================================
1104 void EntityGUI_SketcherDlg::ClickOnRedo()
1105 {
1106   myCommand.append( myUndoCommand.last() );
1107   myUndoCommand.pop_back();
1108
1109   myParameters.append( myUndoParameters.last() );
1110   myUndoParameters.pop_back();
1111
1112   mySketchState = NEXT_POINT;
1113
1114   MainWidget->GroupConstructors->setEnabled( true );
1115   MainWidget->GroupDest1->setEnabled( true );
1116   setEnabledUndo( true );
1117
1118   if ( myUndoCommand.count() == 1 )
1119     setEnabledRedo( false );
1120
1121   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
1122 }
1123
1124 //=================================================================================
1125 // function : setEnabledUndo()
1126 // purpose  :
1127 //=================================================================================
1128 void EntityGUI_SketcherDlg::setEnabledUndo( bool value )
1129 {
1130   Group1Sel->buttonUndo->setEnabled( value );
1131   Group2Sel->buttonUndo->setEnabled( value );
1132   Group1Sel1Spin->buttonUndo->setEnabled( value );
1133   Group1Spin->buttonUndo->setEnabled( value );
1134   Group2Spin->buttonUndo->setEnabled( value );
1135   Group3Spin->buttonUndo->setEnabled( value );
1136   Group4Spin->buttonUndo->setEnabled( value );
1137 }
1138
1139 //=================================================================================
1140 // function : setEnabledRedo()
1141 // purpose  :
1142 //=================================================================================
1143 void EntityGUI_SketcherDlg::setEnabledRedo( bool value )
1144 {
1145   Group1Sel->buttonRedo->setEnabled( value );
1146   Group2Sel->buttonRedo->setEnabled( value );
1147   Group1Sel1Spin->buttonRedo->setEnabled( value );
1148   Group1Spin->buttonRedo->setEnabled( value );
1149   Group2Spin->buttonRedo->setEnabled( value );
1150   Group3Spin->buttonRedo->setEnabled( value );
1151   Group4Spin->buttonRedo->setEnabled( value );
1152 }
1153
1154 //=================================================================================
1155 // function : SelectionIntoArgument()
1156 // purpose  : Called when selection as changed
1157 //=================================================================================
1158 void EntityGUI_SketcherDlg::SelectionIntoArgument()
1159 {
1160   MESSAGE("EntityGUI_SketcherDlg::SelectionIntoArgument")
1161   myEditCurrentArgument->setText( "" );
1162   double tmpX = myX;
1163   double tmpY = myY;
1164   myX = myLastX1;
1165   myY = myLastY1;
1166   //  printf ("\nmyX = %f         myY = %f", myX, myY);
1167   //  printf ("\nmyLastX1 = %f    myLastY1 = %f", myLastX1, myLastY1);
1168   //  printf ("\nmyLastX2 = %f    myLastY2 = %f", myLastX2, myLastY2);
1169
1170   if ( sender() == ComboBox1 )
1171       ActivateLocalCS();
1172
1173   LightApp_SelectionMgr* aSelMgr = myGeometryGUI->getApp()->selectionMgr();
1174   SALOME_ListIO aSelList;
1175   aSelMgr->selectedObjects(aSelList);
1176
1177   int nbSel = aSelList.Extent();
1178   MESSAGE("NbSel = "<<nbSel)
1179   if (nbSel == 1 && myEditCurrentArgument == Group1Sel->LineEdit1) {
1180     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
1181     if ( !CORBA::is_nil(aSelectedObject) ) {
1182       TopoDS_Shape aShape;
1183       if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_VERTEX)) {
1184         gp_Trsf aTrans;
1185         gp_Ax3 aWPlane = GetActiveLocalCS();
1186
1187         aTrans.SetTransformation(aWPlane);
1188         BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
1189         aShape = aTransformation.Shape();
1190
1191         gp_Pnt aPnt;
1192         if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) {
1193           myX = aPnt.X();
1194           myY = aPnt.Y();
1195           Group1Sel->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
1196           if( Group2Spin->isVisible() && mySketchType == PT_ABS ) {
1197             disconnect( Group2Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1198             disconnect( Group2Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1199             Group2Spin->SpinBox_DX->setValue(myX);
1200             Group2Spin->SpinBox_DY->setValue(myY);
1201             connect( Group2Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1202             connect( Group2Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1203           } else if ( Group2Spin->isVisible() && mySketchType == PT_RELATIVE ) {
1204             if ( myLastX1 && myLastY1 ) {
1205               Group2Spin->SpinBox_DX->setValue(myX - myLastX1);
1206               Group2Spin->SpinBox_DY->setValue(myY - myLastY1);
1207             } else {
1208               if ( mySketchState != FIRST_POINT ) {
1209                 Group2Spin->SpinBox_DX->setValue(myX - tmpX);
1210                 Group2Spin->SpinBox_DY->setValue(myY - tmpY);
1211               } else {
1212                 Group2Spin->SpinBox_DX->setValue(myX);
1213                 Group2Spin->SpinBox_DY->setValue(myY);
1214               }
1215             }
1216           }
1217         }
1218       }
1219     }
1220   }
1221
1222   if (nbSel == 1 && myEditCurrentArgument == Group1Sel1Spin->LineEdit1) {
1223     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
1224     if ( !CORBA::is_nil(aSelectedObject) ) {
1225       TopoDS_Shape aShape;
1226       if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_VERTEX)) {
1227         gp_Trsf aTrans;
1228         gp_Ax3 aWPlane = GetActiveLocalCS();
1229
1230         aTrans.SetTransformation(aWPlane);
1231         BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
1232         aShape = aTransformation.Shape();
1233
1234         gp_Pnt aPnt;
1235         if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) {
1236           myX = aPnt.X();
1237           myY = aPnt.Y();
1238           Group1Sel1Spin->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
1239           if( Group3Spin->isVisible() && mySketchType == PT_ABS ) {
1240             disconnect( Group3Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1241             disconnect( Group3Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1242             Group3Spin->SpinBox_DX->setValue(myX);
1243             Group3Spin->SpinBox_DY->setValue(myY);
1244             connect( Group3Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1245             connect( Group3Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1246           } else if ( Group3Spin->isVisible() && mySketchType == PT_RELATIVE ) {
1247             if ( myLastX1 && myLastY1 ) {
1248               Group3Spin->SpinBox_DX->setValue(myX - myLastX1);
1249               Group3Spin->SpinBox_DY->setValue(myY - myLastY1);
1250             } else {
1251               if ( mySketchState != FIRST_POINT ) {
1252                 Group3Spin->SpinBox_DX->setValue(myX - tmpX);
1253                 Group3Spin->SpinBox_DY->setValue(myY - tmpY);
1254               } else {
1255                 Group3Spin->SpinBox_DX->setValue(myX);
1256                 Group3Spin->SpinBox_DY->setValue(myY);
1257               }
1258             }
1259           }
1260         }
1261       }
1262     }
1263   }
1264
1265   if (nbSel == 1 && myEditCurrentArgument == Group2Sel->LineEdit1) {
1266     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
1267     if ( !CORBA::is_nil(aSelectedObject) ) {
1268       TopoDS_Shape aShape;
1269       if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_VERTEX)) {
1270         gp_Trsf aTrans;
1271         gp_Ax3 aWPlane = GetActiveLocalCS();
1272
1273         aTrans.SetTransformation(aWPlane);
1274         BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
1275         aShape = aTransformation.Shape();
1276
1277         gp_Pnt aPnt;
1278         if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) {
1279           myXc = aPnt.X();
1280           myYc = aPnt.Y();
1281           Group2Sel->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
1282           if( Group4Spin->isVisible() && mySketchType == PT_ABS ) {
1283             disconnect( Group4Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1284             disconnect( Group4Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1285             Group4Spin->SpinBox_DX->setValue(myXc);
1286             Group4Spin->SpinBox_DY->setValue(myYc);
1287             connect( Group4Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1288             connect( Group4Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1289           } else if ( Group4Spin->isVisible() && mySketchType == PT_RELATIVE ) {
1290             if ( myLastX1 && myLastY1 ) {
1291               Group4Spin->SpinBox_DX->setValue(myXc - myLastX1);
1292               Group4Spin->SpinBox_DY->setValue(myYc - myLastY1);
1293             } else {
1294               if ( mySketchState != FIRST_POINT ) {
1295                 Group4Spin->SpinBox_DX->setValue(myXc - tmpX);
1296                 Group4Spin->SpinBox_DY->setValue(myYc - tmpY);
1297               } else {
1298                 Group4Spin->SpinBox_DX->setValue(myXc);
1299                 Group4Spin->SpinBox_DY->setValue(myYc);
1300               }
1301             }
1302           }
1303         }
1304       }
1305     }
1306   }
1307
1308   if (nbSel == 1 && myEditCurrentArgument == Group2Sel->LineEdit2) {
1309     if (!Group2Sel->LineEdit1->text().isEmpty()){    //Check wether or not Linedit2 has been modified
1310       myX=tmpX;                                      // If yes keep the old values of X and Y  
1311       myY=tmpY;
1312     }
1313     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
1314     if ( !CORBA::is_nil(aSelectedObject) ) {
1315       TopoDS_Shape aShape;
1316       if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_VERTEX)) {
1317         gp_Trsf aTrans;
1318         gp_Ax3 aWPlane = GetActiveLocalCS();
1319
1320         aTrans.SetTransformation(aWPlane);
1321         BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
1322         aShape = aTransformation.Shape();
1323
1324         gp_Pnt aPnt;
1325         if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) {
1326           myX = aPnt.X();
1327           myY = aPnt.Y();
1328           Group2Sel->LineEdit2->setText( GEOMBase::GetName( aSelectedObject ) );
1329           if( Group4Spin->isVisible() && mySketchType == PT_ABS ) {
1330             disconnect( Group4Spin->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1331             disconnect( Group4Spin->SpinBox_DS, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1332             Group4Spin->SpinBox_DZ->setValue(myX);
1333             Group4Spin->SpinBox_DS->setValue(myY);
1334             connect( Group4Spin->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1335             connect( Group4Spin->SpinBox_DS, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
1336           } else if ( Group4Spin->isVisible() && mySketchType == PT_RELATIVE ) {
1337             if ( myLastX1 && myLastY1 ) {
1338               Group4Spin->SpinBox_DZ->setValue(myX - myLastX1);
1339               Group4Spin->SpinBox_DS->setValue(myY - myLastY1);
1340             } else {
1341               if ( mySketchState != FIRST_POINT ) {
1342                 Group4Spin->SpinBox_DZ->setValue(myX - tmpX);
1343                 Group4Spin->SpinBox_DS->setValue(myY - tmpY);
1344               } else {
1345                 Group4Spin->SpinBox_DZ->setValue(myX);
1346                 Group4Spin->SpinBox_DS->setValue(myY);
1347               }
1348             }
1349           }
1350         }
1351       }
1352     }
1353   }
1354   if (nbSel == 0){                 // If no object selected
1355     myX=tmpX;                      // Don't change the point coordinates
1356     myY=tmpY;                      // and don't redisplay the preview
1357   }
1358   else if(!autoApply){
1359     GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
1360   }
1361   if ( autoApply ){    
1362     ClickOnApply();
1363     autoApply = false;
1364   }
1365   this->activateWindow();
1366   
1367 }
1368
1369
1370 //=================================================================================
1371 // function : SetEditCurrentArgument()
1372 // purpose  :
1373 //=================================================================================
1374 void EntityGUI_SketcherDlg::SetEditCurrentArgument()
1375 {
1376   if ( sender() == Group1Sel->PushButton1 ) {
1377     myEditCurrentArgument = Group1Sel->LineEdit1;
1378     myEditCurrentArgument->setFocus();
1379   }
1380   else if ( sender() == Group1Sel1Spin->PushButton1 ) {
1381     myEditCurrentArgument = Group1Sel1Spin->LineEdit1;
1382     myEditCurrentArgument->setFocus();
1383   }
1384   else if ( sender() == Group2Sel->PushButton1 ) {
1385     myEditCurrentArgument = Group2Sel->LineEdit1;
1386     Group2Sel->PushButton2->setDown(false);
1387     Group2Sel->PushButton1->setDown(true);
1388     Group2Sel->LineEdit2->setEnabled(false);
1389     Group2Sel->LineEdit1->setEnabled(true);
1390    // myEditCurrentArgument->setFocus();
1391   }
1392    else if ( sender() == Group2Sel->PushButton2 ) {
1393     myEditCurrentArgument = Group2Sel->LineEdit2;
1394     Group2Sel->PushButton1->setDown(false);
1395     Group2Sel->PushButton2->setDown(true);
1396     Group2Sel->LineEdit1->setEnabled(false);
1397     Group2Sel->LineEdit2->setEnabled(true);
1398    // myEditCurrentArgument->setFocus();
1399   }
1400   SelectionIntoArgument();
1401 }
1402
1403
1404 //=================================================================================
1405 // function : LineEditReturnPressed()
1406 // purpose  :
1407 //=================================================================================
1408 void EntityGUI_SketcherDlg::LineEditReturnPressed()
1409 {
1410   if ( sender() == Group1Sel->LineEdit1 ) 
1411     myEditCurrentArgument = Group1Sel->LineEdit1;
1412   else if ( sender() == Group1Sel1Spin->LineEdit1 ) 
1413      myEditCurrentArgument = Group1Sel1Spin->LineEdit1;
1414   else if ( sender() == Group2Sel->LineEdit1 ) 
1415      myEditCurrentArgument = Group2Sel->LineEdit1;
1416   else if ( sender() == Group2Sel->LineEdit2 )
1417      myEditCurrentArgument = Group2Sel->LineEdit2;
1418
1419   /* User name of object input management                          */
1420   /* If successfull the selection is changed and signal emitted... */
1421   /* so SelectionIntoArgument() is automatically called.           */
1422   const QString objectUserName = myEditCurrentArgument->text();
1423   QWidget* thisWidget = (QWidget*)this;
1424
1425   LightApp_SelectionMgr* aSelMgr = myGeometryGUI->getApp()->selectionMgr();
1426   SALOME_ListIO aSelList;
1427   aSelMgr->selectedObjects(aSelList);
1428
1429   if (GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, aSelList))
1430     myEditCurrentArgument->setText( objectUserName );
1431 }
1432
1433
1434 //=================================================================================
1435 // function : DeactivateActiveDialog()
1436 // purpose  :
1437 //=================================================================================
1438 void EntityGUI_SketcherDlg::DeactivateActiveDialog()
1439 {
1440   //myGeometryGUI->SetState( -1 );
1441
1442   setEnabled( false );
1443   globalSelection();
1444   disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
1445   myGeometryGUI->SetActiveDialogBox( 0 );
1446 }
1447
1448
1449 //=================================================================================
1450 // function : ActivateThisDialog()
1451 // purpose  :
1452 //=================================================================================
1453 void EntityGUI_SketcherDlg::ActivateThisDialog()
1454 {
1455   MESSAGE("EntityGUI_SketcherDlg::ActivateThisDialog()")
1456   myGeometryGUI->EmitSignalDeactivateDialog();
1457   setEnabled( true );
1458   myGeometryGUI->SetActiveDialogBox( this );
1459
1460   connect( myGeometryGUI->getApp()->selectionMgr(),
1461           SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
1462
1463   //myGeometryGUI->SetState( 0 );
1464   globalSelection( GEOM_POINT );
1465   
1466   myEditCurrentArgument = Group1Sel->LineEdit1;
1467   myEditCurrentArgument->setFocus();
1468   
1469    if ( sender() == Group1Sel->LineEdit1 ) {
1470      myEditCurrentArgument = Group1Sel->LineEdit1;
1471      myEditCurrentArgument->setFocus();
1472    }
1473    else if ( sender() == Group1Sel1Spin->LineEdit1 ) {
1474      myEditCurrentArgument = Group1Sel1Spin->LineEdit1;
1475      myEditCurrentArgument->setFocus();
1476    }
1477    else if ( sender() == Group2Sel->LineEdit1 ) {
1478      myEditCurrentArgument = Group2Sel->LineEdit1;
1479      myEditCurrentArgument->setFocus();
1480    }
1481     else if ( sender() == Group2Sel->LineEdit2 ) {
1482      myEditCurrentArgument = Group2Sel->LineEdit2;
1483      myEditCurrentArgument->setFocus();
1484    }
1485    
1486   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
1487 }
1488
1489
1490 //=================================================================================
1491 // function : enterEvent [REDEFINED]
1492 // purpose  :
1493 //=================================================================================
1494 void EntityGUI_SketcherDlg::enterEvent( QEvent* )
1495 {
1496   if ( !isEnabled() )
1497     ActivateThisDialog();
1498 }
1499
1500
1501 //=================================================================================
1502 // function : closeEvent()
1503 // purpose  :
1504 //=================================================================================
1505 void EntityGUI_SketcherDlg::closeEvent( QCloseEvent* e )
1506 {
1507   MESSAGE("EntityGUI_SketcherDlg::closeEvent")
1508   //myGeometryGUI->SetState( -1 );
1509   disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
1510   myGeometryGUI->getApp()->updateActions();
1511   QDialog::closeEvent( e );
1512 }
1513
1514 //=================================================================================
1515 // function : OnPointSelected
1516 // purpose  :
1517 //=================================================================================
1518 void EntityGUI_SketcherDlg::OnPointSelected(Qt::KeyboardModifiers modifiers, const gp_Pnt& thePnt)
1519 {
1520   MESSAGE("EntityGUI_SketcherDlg::OnPointSelected")
1521   
1522   double x, y;
1523   x = y = 0;
1524   
1525   autoApply = ( getPnt2ConstructorId() == 1 && false );  // If no additional argument needed after selection
1526                                                          // -> apply automatically --> disabled for now
1527   
1528   if ( getPnt1ConstructorId() == 0 ){                    // Relative selection mode
1529     x = thePnt.X() - myLastX1;
1530     y = thePnt.Y() - myLastY1;
1531   }
1532   else {
1533     x = thePnt.X();
1534     y = thePnt.Y();
1535   }
1536   switch (getPnt2ConstructorId()){
1537     case 1:
1538       Group2Spin->SpinBox_DX->setValue( x );
1539       Group2Spin->SpinBox_DY->setValue( y );
1540       Group2Spin->buttonApply->setFocus();               // Previous setFocus (during preview) may have been inoperative if it was disabled 
1541       break;
1542     case 0:
1543       Group3Spin->SpinBox_DX->setValue( x );
1544       Group3Spin->SpinBox_DY->setValue( y );
1545       Group3Spin->buttonApply->setFocus(); 
1546       break;
1547     case 2:
1548       if (modifiers == Qt::MetaModifier){                // Select center with Meta key
1549         Group4Spin->SpinBox_DX->setValue( x );
1550         Group4Spin->SpinBox_DY->setValue( y );
1551       }
1552       else{                                              // Select end point
1553         Group4Spin->SpinBox_DZ->setValue( x );
1554         Group4Spin->SpinBox_DS->setValue( y );
1555       }
1556       Group4Spin->buttonApply->setFocus(); 
1557       break;
1558   }
1559 }
1560
1561 //=================================================================================
1562 // function : ValueChangedInSpinBox()
1563 // purpose  :
1564 //=================================================================================
1565 void EntityGUI_SketcherDlg::ValueChangedInSpinBox( double newValue )
1566 {
1567   MESSAGE("EntityGUI_SketcherDlg::ValueChangedInSpinBox")
1568   QObject* send = (QObject*)sender();
1569   Standard_Real vx, vy, vz, vs, minRad, dx, dy;
1570   vx = vy = vz = vs = minRad = dx = dy = 0.0;
1571
1572   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1573   int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
1574   double LastDecimal = 0.0;
1575
1576   QString vxStr, vyStr, vzStr, vsStr;
1577
1578   QString newValueStr;
1579   if( SalomeApp_DoubleSpinBox* aDoubleSpinBox = (SalomeApp_DoubleSpinBox*)send )
1580     newValueStr = aDoubleSpinBox->text();
1581
1582   if ( send == Group1Spin->SpinBox_DX ) {
1583     vx = newValue;                        vxStr = newValueStr;
1584   }
1585   else if ( send == Group1Sel1Spin->SpinBox_DX ) {
1586     vx = newValue;                        vxStr = newValueStr;
1587   }
1588   else if ( send == Group2Spin->SpinBox_DX ) {
1589     vx = newValue;                        vxStr = newValueStr;
1590     vy = Group2Spin->SpinBox_DY->value(); vyStr = Group2Spin->SpinBox_DY->text();
1591   }
1592   else if ( send == Group2Spin->SpinBox_DY ) {
1593     vx = Group2Spin->SpinBox_DX->value(); vxStr = Group2Spin->SpinBox_DX->text();
1594     vy = newValue;                        vyStr = newValueStr;
1595   }
1596   else if ( send == Group3Spin->SpinBox_DX ) {
1597     vx = newValue;                        vxStr = newValueStr;
1598     vy = Group3Spin->SpinBox_DY->value(); vyStr = Group3Spin->SpinBox_DY->text();
1599     vz = Group3Spin->SpinBox_DZ->value();
1600     if ( (mySketchType == PT_REL_RADIUS || mySketchType == PT_ABS_RADIUS) && (vx != 0 || vy != 0) ) {  
1601       if (mySketchType == PT_ABS_RADIUS){
1602         dx = vx - myLastX1;
1603         dy = vy - myLastY1;
1604       }
1605       else{
1606         dx = vx;
1607         dy = vy;
1608       }
1609       minRad = 0.5 * Sqrt(dx * dx + dy * dy);                             //Computation of the minimum acceptable radius for the arc calculation
1610       if (aPrecision >= 0)    // 'f' format in the QString             
1611         LastDecimal = aPrecision;
1612       else                    // 'g' format in the Qstring
1613         LastDecimal = qAbs( aPrecision ) - ceil( log10(minRad) ); 
1614       minRad = ceil(pow(10,LastDecimal) * minRad) / pow(10,LastDecimal);  // Rounded up at the last allowed decimal place
1615       if ( Abs(vz) < minRad){
1616         if (vz < 0.0)
1617           Group3Spin->SpinBox_DZ->setValue( - minRad );
1618         else 
1619           Group3Spin->SpinBox_DZ->setValue( minRad );
1620       }
1621     }
1622     vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
1623   }
1624   else if ( send == Group3Spin->SpinBox_DY ) {
1625     vx = Group3Spin->SpinBox_DX->value(); vxStr = Group3Spin->SpinBox_DX->text();
1626     vy = newValue;                        vyStr = newValueStr;
1627     vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
1628     if ( (mySketchType == PT_REL_RADIUS || mySketchType == PT_ABS_RADIUS) && (vx != 0 || vy != 0)){
1629       if (mySketchType == PT_ABS_RADIUS){
1630         dx = vx - myLastX1;
1631         dy = vy - myLastY1;
1632       }
1633       else{
1634         dx = vx;
1635         dy = vy;
1636       }    
1637       minRad = 0.5 * Sqrt(dx * dx + dy * dy);                            //Computation of the minimum acceptable radius for the arc calculation
1638       if (aPrecision >= 0)    // 'f' format in the QString 
1639         LastDecimal = aPrecision;
1640       else                    // 'g' format in the QString 
1641         LastDecimal = qAbs( aPrecision ) - ceil( log10(minRad) ); 
1642         minRad = ceil(pow(10,LastDecimal) * minRad) / pow(10,LastDecimal); // Rounded up at the last allowed decimal place
1643       if ( Abs(vz) < minRad){
1644         if (vz < 0.0)
1645           Group3Spin->SpinBox_DZ->setValue( - minRad );
1646         else 
1647           Group3Spin->SpinBox_DZ->setValue( minRad );
1648       }
1649     }
1650     vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
1651   }
1652   else if ( send == Group3Spin->SpinBox_DZ ) {
1653     vx = Group3Spin->SpinBox_DX->value(); vxStr = Group3Spin->SpinBox_DX->text();
1654     vy = Group3Spin->SpinBox_DY->value(); vyStr = Group3Spin->SpinBox_DY->text();
1655     vz = newValue;                        vzStr = newValueStr;
1656   }
1657   else if ( send == Group4Spin->SpinBox_DX ) {
1658     vx = newValue;                        vxStr = newValueStr;
1659     vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1660     vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1661     vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1662   }
1663   else if ( send == Group4Spin->SpinBox_DY ) {
1664     vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1665     vy = newValue;                        vyStr = newValueStr;
1666     vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1667     vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1668   }
1669   else if ( send == Group4Spin->SpinBox_DZ ) {
1670     vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1671     vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1672     vz = newValue;                        vzStr = newValueStr;
1673     vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1674   }
1675   else if ( send == Group4Spin->SpinBox_DS ) {
1676     vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1677     vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1678     vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1679     vs = newValue;                        vsStr = newValueStr;
1680   }
1681   // Fix of the NPAL16010 bug is removed, because it's not actual with the Qt-4.x
1682
1683   if ( myConstructorId == 0 ) {  // SEGMENT
1684     if ( mySketchType == PT_ABS ) {
1685       myX = vx;
1686       myY = vy;
1687       myXStr = vxStr;
1688       myYStr = vyStr;
1689     }
1690     else if ( mySketchType == PT_RELATIVE ) {
1691       myDX = vx;
1692       myDY = vy;
1693       myDXStr = vxStr;
1694       myDYStr = vyStr;
1695     }
1696     else if ( mySketchType == DIR_ANGLE_LENGTH ) {
1697       myAngle = vx;
1698       myLength = vy;
1699       myAngleStr = vxStr;
1700       myLengthStr = vyStr;
1701     }
1702     else if ( mySketchType == DIR_ANGLE_X ) {
1703       myAngle = vx;
1704       myX = vy;
1705       myAngleStr = vxStr;
1706       myXStr = vyStr;
1707     }
1708     else if ( mySketchType == DIR_ANGLE_Y ) {
1709       myAngle = vx;
1710       myY = vy;
1711       myAngleStr = vxStr;
1712       myYStr = vyStr;
1713     }
1714     else if ( mySketchType == DIR_PER_LENGTH ) {
1715       myLength = vx;
1716       myLengthStr = vxStr;
1717     }
1718     else if ( mySketchType == DIR_PER_X ) {
1719       myX = vx;
1720       myXStr = vxStr;
1721     }
1722     else if ( mySketchType == DIR_PER_Y ) {
1723       myY = vx;
1724       myYStr = vxStr;
1725     }
1726     else if ( mySketchType == DIR_TAN_LENGTH ) {
1727       myLength = vx;
1728       myLengthStr = vxStr;
1729     }
1730     else if ( mySketchType == DIR_TAN_X ) {
1731       myX = vx;
1732       myXStr = vxStr;
1733     }
1734     else if ( mySketchType == DIR_TAN_Y ) {
1735       myY = vx;
1736       myYStr = vxStr;
1737     }
1738     else if ( mySketchType == DIR_DXDY_LENGTH ) {
1739       myDX = vx;
1740       myDY = vy;
1741       myLength = vz;
1742       myDXStr = vxStr;
1743       myDYStr = vyStr;
1744       myLengthStr = vzStr;
1745     }
1746     else if ( mySketchType == DIR_DXDY_X ) {
1747       myDX = vx;
1748       myDY = vy;
1749       myX = vz;
1750       myDXStr = vxStr;
1751       myDYStr = vyStr;
1752       myXStr = vzStr;
1753     }
1754     else if ( mySketchType == DIR_DXDY_Y ) {
1755       myDX = vx;
1756       myDY = vy;
1757       myY = vz;
1758       myDXStr = vxStr;
1759       myDYStr = vyStr;
1760       myYStr = vzStr;
1761     }
1762   }
1763   else if ( myConstructorId == 1 ) {  // ARC
1764     if ( mySketchType == PT_ABS ) {  
1765       myX = vx;
1766       myY = vy;
1767       myXStr = vxStr;
1768       myYStr = vyStr;
1769     }
1770     else if ( mySketchType == PT_RELATIVE ) {
1771       myDX = vx;
1772       myDY = vy;
1773       myDXStr = vxStr;
1774       myDYStr = vyStr;
1775     }
1776     if ( mySketchType == PT_ABS_RADIUS ) {  
1777       myX = vx;
1778       myY = vy;
1779       myRadius=vz;
1780       myXStr = vxStr;
1781       myYStr = vyStr;
1782       myRadiusStr = vzStr;
1783     }
1784     else if ( mySketchType == PT_REL_RADIUS ) {
1785       myDX = vx;
1786       myDY = vy;
1787       myRadius=vz;
1788       myDXStr = vxStr;
1789       myDYStr = vyStr;
1790       myRadiusStr = vzStr;
1791     }
1792     else if ( mySketchType == PT_SEL_RADIUS ) {
1793       myRadius = vx;
1794       myRadiusStr = vxStr;
1795     }
1796     if ( mySketchType == PT_ABS_CENTER ) {  
1797       myXc = vx;
1798       myYc = vy;
1799       myX = vz;
1800       myY = vs;
1801       myXcStr = vxStr;
1802       myYcStr = vyStr;
1803       myXStr = vzStr;
1804       myYStr = vsStr;
1805     }
1806     else if ( mySketchType == PT_REL_CENTER ) {
1807       myDXc = vx;
1808       myDYc = vy;
1809       myDX = vz;
1810       myDY = vs;
1811       myDXcStr = vxStr;
1812       myDYcStr = vyStr;
1813       myDXStr = vzStr;
1814       myDYStr = vsStr;
1815     }
1816     if ( mySketchType == DIR_ANGLE_LENGTH ) {
1817       myAngle = vx;
1818       myRadius = vy;
1819       myLength = vz;
1820       myAngleStr = vxStr;
1821       myRadiusStr = vyStr;
1822       myLengthStr = vzStr;
1823     }
1824     else if ( mySketchType == DIR_PER_LENGTH ) {
1825       myRadius = vx;
1826       myLength = vy;
1827       myRadiusStr = vxStr;
1828       myLengthStr = vyStr;
1829     }
1830     else if ( mySketchType == DIR_TAN_LENGTH ) {
1831       myRadius = vx;
1832       myLength = vy;
1833       myRadiusStr = vxStr;
1834       myLengthStr = vyStr;
1835     }
1836     else if ( mySketchType == DIR_DXDY_LENGTH ) {
1837       myDX = vx;
1838       myDY = vy;
1839       myRadius = vz;
1840       myLength = vs;
1841       myDXStr = vxStr;
1842       myDYStr = vyStr;
1843       myRadiusStr = vzStr;
1844       myLengthStr = vsStr;
1845     }
1846   }
1847   
1848   if (!autoApply) 
1849     GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
1850   
1851   double x, y, xc, yc;
1852   x = y = xc = yc = 0.0;
1853   if ( mySketchType == PT_ABS_CENTER || mySketchType == PT_REL_CENTER )
1854   {
1855     if ( mySketchType == PT_REL_CENTER ){
1856       x  = myDX  + myLastX1;
1857       y  = myDY  + myLastY1;
1858       xc = myDXc + myLastX1;
1859       yc = myDYc + myLastY1;
1860     }
1861     else {
1862       x  = myX ;
1863       y  = myY ;
1864       xc = myXc;
1865       yc = myYc;
1866     }
1867     displayPntPreview(xc,yc);
1868     displayPntPreview(x,y);
1869   }
1870 }
1871
1872
1873 //=================================================================================
1874 // function : GetNewCommand()
1875 // purpose  : Build the new command with context
1876 //=================================================================================
1877 QString EntityGUI_SketcherDlg::GetNewCommand( QString& theParameters )
1878 {
1879   theParameters.clear();
1880   QString myNewCommand = ":";
1881   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1882   int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
1883   int DigNum = qAbs(aPrecision);                   // options for the format of numbers in  myNewCommand
1884   char Format = 'f';
1885   if ( aPrecision < 0 )                            // f --> DigNum is the number of digits after the decimal point
1886     Format = 'g';                                  // g --> DigNum is the maximum number of significant digits 
1887
1888   if ( mySketchState == FIRST_POINT ) {
1889     if ( mySketchType == PT_ABS || mySketchType == PT_SEL ) {
1890       myNewCommand = myNewCommand + "F " + QString::number( myX, Format, DigNum) + " " + QString::number( myY, Format, DigNum);
1891       theParameters = myXStr + ":" + myYStr;
1892     }
1893     if ( mySketchType == PT_RELATIVE) {
1894       myNewCommand = myNewCommand + "F " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
1895       theParameters = myDXStr + ":" + myDYStr;
1896     }
1897     return myNewCommand;
1898   }
1899
1900   if ( myConstructorId == 0  ) {  // SEGMENT
1901     if ( mySketchType == PT_ABS || mySketchType == PT_SEL ) {
1902       myNewCommand = myNewCommand + "TT " + QString::number( myX, Format, DigNum) + " " + QString::number( myY, Format, DigNum);
1903       theParameters = myXStr + ":" + myYStr;
1904     }
1905     if ( mySketchType == PT_RELATIVE) {
1906       myNewCommand = myNewCommand + "T " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
1907       theParameters = myDXStr + ":" + myDYStr;
1908     }
1909     if ( mySketchType == DIR_ANGLE_LENGTH ) {
1910       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1911       myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength, Format, DigNum );
1912       theParameters = myAngleStr + ":" + myLengthStr;
1913     }
1914     if ( mySketchType == DIR_ANGLE_X ) {
1915       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1916       myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX, Format, DigNum);
1917       theParameters = myAngleStr + ":" + myXStr;
1918     }
1919     if ( mySketchType == DIR_ANGLE_Y ) {
1920       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1921       myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY, Format, DigNum);
1922       theParameters = myAngleStr + ":" + myYStr;
1923     }
1924     if ( mySketchType == DIR_PER_LENGTH ) {
1925       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1926       myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength, Format, DigNum );
1927       theParameters = QString::number( 90.0 ) + ":" + myLengthStr;
1928     }
1929     if ( mySketchType == DIR_PER_X ) {
1930       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1931       myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX, Format, DigNum);
1932       theParameters = QString::number( 90.0 ) + ":" + myXStr;
1933     }
1934     if ( mySketchType == DIR_PER_Y ) {
1935       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1936       myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY, Format, DigNum);
1937       theParameters = QString::number( 90.0 ) + ":" + myYStr;
1938     }
1939     if ( mySketchType == DIR_TAN_LENGTH ) {
1940       myNewCommand = myNewCommand + "L " + QString::number( myLength, Format, DigNum );
1941       theParameters = myLengthStr;
1942     }
1943     if ( mySketchType == DIR_TAN_X ) {
1944       myNewCommand = myNewCommand + "IX " + QString::number( myX, Format, DigNum);
1945       theParameters = myXStr;
1946     }
1947     if ( mySketchType == DIR_TAN_Y) {
1948       myNewCommand = myNewCommand + "IY " + QString::number(myY, Format, DigNum);
1949       theParameters = myYStr;
1950     }
1951     if ( mySketchType == DIR_DXDY_LENGTH ) {
1952       myNewCommand = myNewCommand + "D " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
1953       myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength, Format, DigNum );
1954       theParameters = myDXStr + ":" + myDYStr + ":" + myLengthStr;
1955     }
1956     if ( mySketchType == DIR_DXDY_X ) {
1957       myNewCommand = myNewCommand + "D " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
1958       myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX, Format, DigNum);
1959       theParameters = myDXStr + ":" + myDYStr + ":" + myXStr;
1960     }
1961     if ( mySketchType == DIR_DXDY_Y ) {
1962       myNewCommand = myNewCommand + "D " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
1963       myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY, Format, DigNum);
1964       theParameters = myDXStr + ":" + myDYStr + ":" + myYStr;
1965     }
1966   }
1967   else if ( myConstructorId == 1 ) {  // ARC
1968     if ( mySketchType == PT_ABS || mySketchType == PT_SEL ) {
1969       myNewCommand = myNewCommand + "AA " + QString::number( myX, Format, DigNum) + " " + QString::number( myY, Format, DigNum);
1970       theParameters = myXStr + ":" + myYStr;
1971     }
1972     if ( mySketchType == PT_RELATIVE) {
1973       myNewCommand = myNewCommand + "A " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
1974       theParameters = myDXStr + ":" + myDYStr;
1975     }
1976     if ( mySketchType == PT_ABS_RADIUS || mySketchType == PT_SEL_RADIUS ) {
1977       myNewCommand = myNewCommand + "UU " + QString::number( myX, Format, DigNum) + " " + QString::number( myY, Format, DigNum ) + " " + QString::number( myRadius , Format,  DigNum)+ " " + QString::number( myCheckFlag );
1978       theParameters = myXStr + ":" + myYStr + ":" + myRadiusStr; 
1979     }
1980     if ( mySketchType == PT_REL_RADIUS) {
1981       myNewCommand = myNewCommand + "U " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum ) + " " + QString::number( myRadius, Format, DigNum )+ " " + QString::number( myCheckFlag );
1982       theParameters = myDXStr + ":" + myDYStr + ":" + myRadiusStr;  
1983     }
1984     if ( mySketchType == PT_ABS_CENTER || mySketchType == PT_SEL_CENTER ) {
1985       myNewCommand = myNewCommand + "EE " + QString::number( myX, Format, DigNum) + " " + QString::number( myY, Format, DigNum ) + " " + QString::number( myXc , Format,  DigNum) + " " + QString::number( myYc , Format,  DigNum)+ " " + QString::number( myCheckFlag ) + " " + QString::number( 0 );
1986       theParameters = myXStr + ":" + myYStr + ":" + myXcStr+ ":" + myYcStr; 
1987     }
1988     if ( mySketchType == PT_REL_CENTER) {
1989       myNewCommand = myNewCommand + "E " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum ) + " " + QString::number( myDXc, Format, DigNum )+ " " + QString::number( myDYc, Format, DigNum )+ " " + QString::number( myCheckFlag )+ " " + QString::number( 0 );
1990       theParameters = myDXStr + ":" + myDYStr + ":" +  myDXcStr + ":" + myDYcStr ;  
1991     }
1992     if ( mySketchType == DIR_ANGLE_LENGTH ) {
1993       myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1994       myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius, Format, DigNum ) + " " + QString::number( myLength, Format, DigNum );
1995       theParameters = myAngleStr + ":" + myRadiusStr + ":" + myLengthStr;
1996     }
1997     if ( mySketchType == DIR_PER_LENGTH ) {
1998       myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1999       myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius, Format, DigNum ) + " " + QString::number( myLength, Format, DigNum );
2000       theParameters = QString::number( 90.0 ) + ":" + myRadiusStr + ":" + myLengthStr;
2001     }
2002     if ( mySketchType == DIR_TAN_LENGTH ) {
2003       myNewCommand = myNewCommand + "C " + QString::number( myRadius, Format, DigNum ) + " " + QString::number( myLength, Format, DigNum );
2004       theParameters = myRadiusStr + ":" + myLengthStr;
2005     }
2006     if ( mySketchType == DIR_DXDY_LENGTH ) {
2007       myNewCommand = myNewCommand + "D " + QString::number( myDX, Format, DigNum ) + " " + QString::number( myDY, Format, DigNum );
2008       myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius, Format, DigNum ) + " " + QString::number( myLength, Format, DigNum );
2009       theParameters = myDXStr + ":" + myDYStr + ":" + myRadiusStr + ":" + myLengthStr;
2010     }
2011   }
2012   return myNewCommand;
2013 }
2014
2015 //=================================================================================
2016 // function : createOperation
2017 // purpose  :
2018 //=================================================================================
2019 GEOM::GEOM_IOperations_ptr EntityGUI_SketcherDlg::createOperation()
2020 {
2021   return getGeomEngine()->GetICurvesOperations( getStudyId() );
2022 }
2023
2024 //=================================================================================
2025 // function : isValid
2026 // purpose  :
2027 //=================================================================================
2028 bool EntityGUI_SketcherDlg::isValid( QString& msg )
2029 {
2030   bool ok = true;
2031   bool toCorrect = !IsPreview() || myIsApply;
2032
2033   if( Group1Spin->isVisible() ) {
2034     ok = Group1Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
2035   }
2036   else if( Group1Sel1Spin->isVisible() ) {
2037     ok = Group1Sel1Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
2038   }
2039   else if( Group2Spin->isVisible() ) {
2040     ok = Group2Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
2041     ok = Group2Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
2042   }
2043   else if( Group3Spin->isVisible() ) {
2044     ok = Group3Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
2045     ok = Group3Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
2046     ok = Group3Spin->SpinBox_DZ->isValid( msg, toCorrect ) && ok;
2047   }
2048   else if( Group4Spin->isVisible() ) {
2049     ok = Group4Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
2050     ok = Group4Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
2051     ok = Group4Spin->SpinBox_DZ->isValid( msg, toCorrect ) && ok;
2052     ok = Group4Spin->SpinBox_DS->isValid( msg, toCorrect ) && ok;
2053   }
2054
2055   if( myIsApply && !ok )
2056     showError( msg );
2057
2058   return ok;
2059 }
2060
2061 //=================================================================================
2062 // function : execute
2063 // purpose  :
2064 //=================================================================================
2065 bool EntityGUI_SketcherDlg::execute( ObjectList& objects )
2066 {
2067   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2068   int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
2069   int DigNum = qAbs(aPrecision);                   // options for the format of numbers in  myNewCommand
2070   char Format = 'f';
2071   if ( aPrecision < 0 )                            // f --> DigNum is the number of digits after the decimal point
2072     Format = 'g';                                  // g --> DigNum is the maximum number of significant digits 
2073     
2074   QString aParameters;
2075   
2076   if ( mySketchState == FIRST_POINT ) {
2077     myLastX2 = myX;
2078     myLastY2 = myY;
2079   }
2080   else {
2081     //Test if the current point is the same as the last one
2082     TopoDS_Shape myShape1, myShape2;
2083
2084     // Set "C" numeric locale
2085     Kernel_Utils::Localizer loc;
2086
2087     //Last Shape
2088     QString Command1 = myCommand.join( "" );
2089     Sketcher_Profile aProfile1( Command1.toAscii() );
2090     if ( aProfile1.IsDone() )
2091       myShape1 = aProfile1.GetShape();
2092
2093     //Current Shape
2094     QString Command2 = Command1 + GetNewCommand( aParameters );
2095     Sketcher_Profile aProfile2( Command2.toAscii() );
2096
2097     //Error Message
2098     if ( mySketchType == PT_ABS_CENTER || mySketchType == PT_REL_CENTER  ){
2099       if (aProfile2.Error() > Precision::Confusion()){
2100         Group4Spin->label->show();
2101         Group4Spin->label->setText( tr("GEOM_SKETCHER_WARNING") + QString::number( aProfile2.Error(), Format, DigNum));
2102       }
2103       else{
2104         Group4Spin->label->hide();
2105       } 
2106     }
2107     else 
2108       Group4Spin->label->hide();
2109     if ( mySketchType == PT_SEL_CENTER ){
2110       if (aProfile2.Error() > Precision::Confusion()){
2111         Group2Sel->label->show();
2112         Group2Sel->label->setText( tr("GEOM_SKETCHER_WARNING") + QString::number( aProfile2.Error(), Format, DigNum));
2113       }
2114       else{
2115         Group2Sel->label->hide();
2116       } 
2117     }
2118     else 
2119       Group2Sel->label->hide();
2120
2121     if ( aProfile2.IsDone() )
2122       myShape2 = aProfile2.GetShape();
2123
2124     if ( myShape2.IsNull() ) {
2125       //the current point is the same as the last one
2126       myLastX2 = myLastX1;
2127       myLastY2 = myLastY1;
2128     }
2129     else {
2130       TopoDS_Vertex V1, V2;
2131       gp_Pnt pt;
2132       if ( myShape1.ShapeType() == TopAbs_VERTEX ) {
2133         //the last shape is the first point
2134         pt = BRep_Tool::Pnt( TopoDS::Vertex( myShape1 ) );
2135         myLastX1 = pt.X();
2136         myLastY1 = pt.Y();
2137       }
2138       else {
2139         TopExp::Vertices( TopoDS::Wire( myShape1 ), V1, V2 );
2140         pt = BRep_Tool::Pnt( V2 );
2141         myLastX1 = pt.X();
2142         myLastY1 = pt.Y();
2143       }
2144       TopExp::Vertices( TopoDS::Wire( myShape2 ), V1, V2 );
2145       pt = BRep_Tool::Pnt( V2 );
2146       myLastX2 = pt.X();
2147       myLastY2 = pt.Y();
2148     }
2149   }
2150
2151   QString cmd;
2152   if ( ( mySketchState != FIRST_POINT &&
2153          myLastX1 == myLastX2 && myLastY1 == myLastY2 ) || myIsAllAdded ) {
2154     cmd = myCommand.join( "" );
2155     if ( Group1Sel->isVisible() ) {
2156       Group1Sel->buttonApply->setEnabled( false );
2157       //Group1Sel->buttonApply->setFocus();
2158     }
2159     if ( Group2Sel->isVisible() ) {
2160       Group2Sel->buttonApply->setEnabled( false );
2161       //Group2Sel->buttonApply->setFocus();
2162     }
2163     if ( Group1Sel1Spin->isVisible() ) {
2164       Group1Sel1Spin->buttonApply->setEnabled( false );
2165       //Group1Sel1Spin->buttonApply->setFocus();
2166     }
2167     if ( Group1Spin->isVisible() ) {
2168       Group1Spin->buttonApply->setEnabled( false );
2169       //Group1Spin->buttonApply->setFocus();
2170     }
2171     if ( Group2Spin->isVisible() ) {
2172       Group2Spin->buttonApply->setEnabled( false );
2173       //Group2Spin->buttonApply->setFocus();
2174     }
2175     if ( Group3Spin->isVisible() ) {
2176       Group3Spin->buttonApply->setEnabled( false );
2177       //Group3Spin->buttonApply->setFocus();
2178     }
2179     if ( Group4Spin->isVisible() ) {
2180       Group4Spin->buttonApply->setEnabled( false );
2181       //Group4Spin->buttonApply->setFocus();
2182     }
2183   }
2184   else {
2185     cmd = myCommand.join( "" ) + GetNewCommand( aParameters );
2186
2187     if ( Group1Sel->isVisible() ) {
2188       Group1Sel->buttonApply->setEnabled( true );
2189     }
2190     if ( Group2Sel->isVisible() ) {
2191       Group2Sel->buttonApply->setEnabled( true );
2192     }
2193     if ( Group1Sel1Spin->isVisible() ) {
2194       Group1Sel1Spin->buttonApply->setEnabled( true );;
2195     }
2196     if ( Group1Spin->isVisible() ) {
2197       Group1Spin->buttonApply->setEnabled( true );
2198     }
2199     if ( Group2Spin->isVisible() ) {
2200       Group2Spin->buttonApply->setEnabled( true );
2201     }
2202     if ( Group3Spin->isVisible() ) {
2203       Group3Spin->buttonApply->setEnabled( true );
2204     }
2205     if ( Group4Spin->isVisible() ) {
2206       Group4Spin->buttonApply->setEnabled( true );
2207     }
2208   }
2209
2210   gp_Ax3 myWPlane = GetActiveLocalCS();
2211   GEOM::ListOfDouble_var WPlane = new GEOM::ListOfDouble;
2212   WPlane->length( 9 );
2213   WPlane[0] = myWPlane.Location().X();
2214   WPlane[1] = myWPlane.Location().Y();
2215   WPlane[2] = myWPlane.Location().Z();
2216
2217   WPlane[3] = myWPlane.Direction().X();
2218   WPlane[4] = myWPlane.Direction().Y();
2219   WPlane[5] = myWPlane.Direction().Z();
2220
2221   WPlane[6] = myWPlane.XDirection().X();
2222   WPlane[7] = myWPlane.XDirection().Y();
2223   WPlane[8] = myWPlane.XDirection().Z();
2224
2225   GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow(getOperation());
2226   GEOM::GEOM_Object_var anObj = anOper->MakeSketcher( cmd.toLatin1().constData(), WPlane );
2227
2228   if ( !anObj->_is_nil() )
2229   {
2230     if( !IsPreview() ) {
2231       QStringList aCurrentParameters = myParameters;
2232       aCurrentParameters << aParameters;
2233       anObj->SetParameters(aCurrentParameters.join(":").toLatin1().constData());
2234     }
2235
2236     objects.push_back( anObj._retn() );
2237   }
2238
2239   return true;
2240 }
2241
2242 //================================================================
2243 // Function : displayPreview
2244 // Purpose  : Method for displaying preview of resulting shape
2245 //            Redefined from GEOMBase_Helper.
2246 //================================================================
2247 void EntityGUI_SketcherDlg::displayPreview( GEOM::GEOM_Object_ptr object,
2248                                             const bool            append,
2249                                             const bool            activate,
2250                                             const bool            update,
2251                                             const double          lineWidth,
2252                                             const int             displayMode,
2253                                             const int             color )
2254
2255   // Set color for preview shape
2256   getDisplayer()->SetColor( Quantity_NOC_RED );
2257
2258   // set width of displayed shape
2259   getDisplayer()->SetWidth( (lineWidth == -1)?myLineWidth:lineWidth );
2260
2261   // Disable activation of selection
2262   getDisplayer()->SetToActivate( activate );
2263
2264   // Make a reference to GEOM_Object
2265   CORBA::String_var objStr = myGeometryGUI->getApp()->orb()->object_to_string( object );
2266   getDisplayer()->SetName( objStr.in() );
2267
2268   // Create wire from applayed object
2269   TopoDS_Shape anApplyedWire, aLastSegment;
2270   if ( !createShapes( object, anApplyedWire, aLastSegment ) )
2271     return;
2272
2273   // Build prs
2274   SALOME_Prs* aPrs = getDisplayer()->BuildPrs( anApplyedWire );
2275   if ( aPrs != 0 && !aPrs->IsNull() )
2276     GEOMBase_Helper::displayPreview( aPrs, append, update );
2277
2278   getDisplayer()->SetColor( Quantity_NOC_VIOLET );
2279   aPrs = getDisplayer()->BuildPrs( aLastSegment );
2280   if ( aPrs != 0 && !aPrs->IsNull() )
2281     GEOMBase_Helper::displayPreview( aPrs, append, update );
2282
2283   getDisplayer()->UnsetName();
2284
2285   // Enable activation of displayed objects
2286   getDisplayer()->SetToActivate( true );
2287 }
2288
2289 //================================================================
2290 // Function : displayPntPreview
2291 // Purpose  : creates a TopoDS_VERTEX and display a preview of it
2292 //================================================================
2293 void EntityGUI_SketcherDlg::displayPntPreview(const double x,
2294                                               const double y,
2295                                               bool append,
2296                                               bool update
2297                                              )
2298 {
2299   gp_Pnt aPnt = gp_Pnt(x,y,0.0);
2300   BRepBuilderAPI_MakeVertex mkVertex (aPnt);
2301   TopoDS_Shape aVertex = mkVertex.Shape();
2302   
2303   // Disable activation of selection
2304   getDisplayer()->SetToActivate( false );
2305   
2306   // Build prs
2307   SALOME_Prs* aPrs = getDisplayer()->BuildPrs( aVertex );
2308   if ( aPrs != 0 && !aPrs->IsNull() )
2309     GEOMBase_Helper::displayPreview( aPrs, append, update );
2310   
2311   // Enable back activation of selection
2312   getDisplayer()->SetToActivate( true );
2313 }
2314
2315 //================================================================
2316 // Function : createShapes
2317 // Purpose  : Create applyed wire, and last segment from entry object
2318 //================================================================
2319 bool EntityGUI_SketcherDlg::createShapes( GEOM::GEOM_Object_ptr theObject,
2320                                           TopoDS_Shape&         theApplyedWire,
2321                                           TopoDS_Shape&         theLastSegment )
2322 {
2323   TopoDS_Shape aShape;
2324   if (  !GEOMBase::GetShape( theObject, aShape ) ||
2325        ( aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX ) )
2326     return false;
2327
2328   if ( ( Group1Sel->isVisible()  && !Group1Sel->buttonApply->isEnabled() )||
2329        ( Group2Sel->isVisible()  && !Group2Sel->buttonApply->isEnabled() ) ||
2330        ( Group1Sel1Spin->isVisible()  && !Group1Sel1Spin->buttonApply->isEnabled() ) ||
2331        ( Group1Spin->isVisible() && !Group1Spin->buttonApply->isEnabled() ) ||
2332        ( Group2Spin->isVisible() && !Group2Spin->buttonApply->isEnabled() ) ||
2333        ( Group3Spin->isVisible() && !Group3Spin->buttonApply->isEnabled() ) ||
2334        ( Group4Spin->isVisible() && !Group4Spin->buttonApply->isEnabled() ) ) {
2335      theApplyedWire = aShape;
2336      return true;
2337   }
2338
2339   BRepBuilderAPI_MakeWire aBuilder;
2340   TopExp_Explorer anExp( aShape, TopAbs_EDGE );
2341   while ( 1 ) {
2342     TopoDS_Shape anEdge = anExp.Current();
2343     anExp.Next();
2344     if ( anExp.More() ) // i.e. non-last edge
2345       aBuilder.Add( TopoDS::Edge( anEdge ) );
2346     else {
2347       theLastSegment = anEdge;
2348       break;
2349     }
2350   }
2351
2352   if ( aBuilder.IsDone() )
2353     theApplyedWire = aBuilder.Shape();
2354
2355   return true;
2356 }
2357
2358 //=================================================================================
2359 // function : keyPressEvent()
2360 // purpose  :
2361 //=================================================================================
2362 void  EntityGUI_SketcherDlg::keyPressEvent( QKeyEvent* e )
2363 {
2364   QDialog::keyPressEvent( e );
2365   if ( e->isAccepted() )
2366     return;
2367
2368   if ( e->key() == Qt::Key_F1 ) {
2369     e->accept();
2370     ClickOnHelp();
2371   }
2372 }
2373
2374 //=================================================================================
2375 // function : initSpinBox()
2376 // purpose  :
2377 //=================================================================================
2378 void EntityGUI_SketcherDlg::initSpinBox( SalomeApp_DoubleSpinBox* spinBox,
2379                                          double min,  double max,
2380                                          double step, const char* quantity )
2381 {
2382   // The same stuff as in GEOMBase_Skeleton::initSpinBox()!
2383   // TODO: Think how to keep the single piece of code...
2384
2385   // Obtain precision from preferences
2386   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2387   int aPrecision = resMgr->integerValue( "Geometry", quantity, 6 );
2388   
2389   spinBox->setPrecision( aPrecision );
2390   spinBox->setDecimals( qAbs( aPrecision ) ); // it's necessary to set decimals before the range setting,
2391                                               // by default Qt rounds boundaries to 2 decimals at setRange
2392   spinBox->setRange( min, max );
2393   spinBox->setSingleStep( step );
2394   
2395   // Add a hint for the user saying how to tune precision
2396   QString userPropName = QObject::tr( QString( "GEOM_PREF_%1" ).arg( quantity ).toLatin1().constData() );
2397   spinBox->setProperty( "validity_tune_hint", 
2398                         QVariant( QObject::tr( "GEOM_PRECISION_HINT" ).arg( userPropName ) ) );
2399 }
2400
2401 //=================================================================================
2402 // function : SetDoubleSpinBoxStep()
2403 // purpose  : Double spin box management
2404 //=================================================================================
2405 void EntityGUI_SketcherDlg::SetDoubleSpinBoxStep( double step )
2406 {
2407   Group1Spin->SpinBox_DX->setSingleStep(step);
2408   Group1Sel1Spin->SpinBox_DX->setSingleStep(step);
2409   Group2Spin->SpinBox_DX->setSingleStep(step);
2410   Group2Spin->SpinBox_DY->setSingleStep(step);
2411   Group3Spin->SpinBox_DX->setSingleStep(step);
2412   Group3Spin->SpinBox_DY->setSingleStep(step);
2413   Group3Spin->SpinBox_DZ->setSingleStep(step);
2414   Group4Spin->SpinBox_DZ->setSingleStep(step);
2415
2416   // san: Do NOT override the step when a speicifc step value is used
2417   // in some input fields!
2418   //Group4Spin->SpinBox_DX->setSingleStep(step);
2419   //Group4Spin->SpinBox_DY->setSingleStep(step);
2420   //Group4Spin->SpinBox_DS->setSingleStep(step);
2421 }
2422
2423 //=================================================================================
2424 // function : FindLocalCS()
2425 // purpose  : Find All Coordinates systems in study
2426 //=================================================================================
2427 void EntityGUI_SketcherDlg::FindLocalCS()
2428 {
2429   ComboBox1->clear();
2430   myLCSList.clear();
2431   SalomeApp_Application* app =
2432     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2433   if ( !app )
2434     return;
2435
2436   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2437   if ( !appStudy )
2438     return;
2439
2440   _PTR(Study) aStudy = appStudy->studyDS();
2441
2442   //add Global CS
2443   ComboBox1->addItem(tr("GEOM_GCS"));
2444   gp_Pnt aOrigin = gp_Pnt(0, 0, 0);
2445   gp_Dir aDirZ = gp_Dir(0, 0, 1);
2446   gp_Dir aDirX = gp_Dir(1, 0, 0);
2447   gp_Ax3 globalCS = gp_Ax3(aOrigin, aDirZ, aDirX);
2448   myLCSList.push_back(globalCS);
2449
2450   // get GEOM component
2451   CORBA::String_var geomIOR = app->orb()->object_to_string( GeometryGUI::GetGeomGen() );
2452   _PTR(SObject) obj = aStudy->FindObjectIOR( geomIOR.in() );
2453   if (!obj)
2454     return;
2455   _PTR(SComponent) fc = obj->GetFatherComponent();
2456   QString geomComp = fc->GetID().c_str();
2457   _PTR(SObject) comp = aStudy->FindObjectID( geomComp.toLatin1().data() );
2458   if ( !comp )
2459     return;
2460
2461   // browse through all GEOM data tree
2462   _PTR(ChildIterator) it ( aStudy->NewChildIterator( comp ) );
2463   for ( it->InitEx( true ); it->More(); it->Next() ) {
2464     _PTR(SObject) child( it->Value() );
2465     CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( child );
2466     GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
2467     if( CORBA::is_nil( geomObj ) ) 
2468       continue;
2469     if (geomObj->GetType() == GEOM_MARKER) {
2470       ComboBox1->addItem(geomObj->GetName());
2471       TopoDS_Shape aShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), geomObj);
2472       
2473       gp_Ax3 aLCS;
2474       aLCS.Transform(aShape.Location().Transformation());
2475       if (aShape.ShapeType() == TopAbs_FACE) {
2476         Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(aShape));
2477         if (!aGS.IsNull() && aGS->IsKind(STANDARD_TYPE(Geom_Plane))) {
2478           Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast(aGS);
2479           gp_Pln aPln = aGPlane->Pln();
2480           aLCS = aPln.Position();
2481         }
2482       }
2483       myLCSList.push_back(aLCS);
2484     }
2485   }
2486 }
2487
2488 //=================================================================================
2489 // function : getPnt1ConstructorId()
2490 // purpose  :
2491 //=================================================================================
2492 int EntityGUI_SketcherDlg::getPnt1ConstructorId() const
2493
2494   int buttonId = GroupPt->ButtonGroup->checkedId(); 
2495 //   MESSAGE("buttonId = "<<buttonId)
2496   return buttonId;
2497 }
2498
2499 //=================================================================================
2500 // function : getPnt2ConstructorId()
2501 // purpose  :
2502 //=================================================================================
2503 int EntityGUI_SketcherDlg::getPnt2ConstructorId() const
2504
2505   int buttonId = GroupPt2->ButtonGroup->checkedId(); 
2506 //   MESSAGE("buttonId = "<<buttonId)
2507   return buttonId;
2508 }
2509
2510 //=================================================================================
2511 // function : GetActiveLocalCS()
2512 // purpose  : Get Working plane
2513 //=================================================================================
2514 gp_Ax3 EntityGUI_SketcherDlg::GetActiveLocalCS()
2515 {
2516   int ind = ComboBox1->currentIndex();
2517   if (ind == -1)
2518     return myGeometryGUI->GetWorkingPlane();
2519
2520   gp_Ax3 aLCS = myLCSList.at(ind);
2521
2522   return aLCS;
2523 }
2524
2525 //=================================================================================
2526 // function : ActivateLocalCS()
2527 // purpose  : Activate & Fit Working plane
2528 //=================================================================================
2529 void EntityGUI_SketcherDlg::ActivateLocalCS()
2530 {
2531     myGeometryGUI->SetWorkingPlane( GetActiveLocalCS() );
2532     myGeometryGUI->ActiveWorkingPlane();
2533 }