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