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