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