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