]> SALOME platform Git repositories - modules/geom.git/blob - src/EntityGUI/EntityGUI_SketcherDlg.cxx
Salome HOME
Updated for bug 0020052 from Mantis.
[modules/geom.git] / src / EntityGUI / EntityGUI_SketcherDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  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 //
24 //  File   : EntityGUI_SketcherDlg.cxx
25 //  Author : Damien COQUERET
26 //  Module : GEOM
27 //  $Header$
28
29 #include "EntityGUI_SketcherDlg.h"
30 #include "Sketcher_Profile.hxx"
31 #include "GEOM_Displayer.h"
32 #include "GEOMBase.h"
33
34 #include "SUIT_Desktop.h"
35 #include "SUIT_Session.h"
36 #include "SUIT_MessageBox.h"
37 #include "SUIT_ResourceMgr.h"
38 #include "SalomeApp_Application.h"
39 #include "LightApp_Application.h"
40 #include "LightApp_SelectionMgr.h"
41
42 #include <qpushbutton.h>
43 #include <qlabel.h>
44
45 #include <BRep_Tool.hxx>
46 #include <TopExp.hxx>
47 #include <TopExp_Explorer.hxx>
48 #include <TopoDS_Vertex.hxx>
49 #include <TopoDS.hxx>
50 #include <BRepBuilderAPI_Transform.hxx>
51 #include <BRepBuilderAPI_MakeWire.hxx>
52
53 #include "GEOMImpl_Types.hxx"
54
55 #include "utilities.h"
56
57 using namespace std;
58
59 //=================================================================================
60 // class    : EntityGUI_SketcherDlg()
61 // purpose  : Constructs a EntityGUI_SketcherDlg which is a child of 'parent', with the
62 //            name 'name' and widget flags set to 'f'.
63 //            The dialog will by default be modeless, unless you set 'modal' to
64 //            TRUE to construct a modal dialog.
65 //=================================================================================
66 EntityGUI_SketcherDlg::EntityGUI_SketcherDlg(GeometryGUI* GUI, QWidget* parent,
67                                              const char* name, bool modal, WFlags fl,
68                                              const double lineWidth)
69   :EntityGUI_Skeleton_QTD(parent, name, modal, WStyle_Customize |
70                           WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose),
71    myIsAllAdded( false ),
72    GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
73    myGeometryGUI( GUI ),
74    myLineWidth( lineWidth )
75 {
76   myGeometryGUI->SetActiveDialogBox(this);
77
78   if ( !name ) setName("EntityGUI_SketcherDlg");
79
80   buttonCancel->setText(tr("GEOM_BUT_CANCEL"));
81   buttonEnd->setText(tr("GEOM_BUT_END_SKETCH"));
82   buttonClose->setText(tr("GEOM_BUT_CLOSE_SKETCH"));
83   buttonHelp->setText(tr("GEOM_BUT_HELP"));
84
85   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
86   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_UNDO")));
87   QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_REDO")));
88
89   setCaption(tr("GEOM_SKETCHER_TITLE"));
90
91   GroupConstructors->setTitle(tr("GEOM_SKETCHER_EL"));
92   RadioButton1->setText(tr("GEOM_SKETCHER_SEGMENT"));
93   RadioButton2->setText(tr("GEOM_SKETCHER_ARC"));
94   GroupDest->setTitle(tr("GEOM_SKETCHER_DEST"));
95   GroupDest1->setTitle(tr("GEOM_SKETCHER_TYPE"));
96   RB_Dest1->setText(tr("GEOM_SKETCHER_POINT"));
97   RB_Dest2->setText(tr("GEOM_SKETCHER_DIR"));
98
99   /***************************************************************/
100   GroupPt = new EntityGUI_Point_QTD(GroupDest, "GroupPt");
101   GroupPt->GroupPoint->setTitle(tr("GEOM_SKETCHER_POINT"));
102   GroupPt->RB_Point1->setText(tr("GEOM_SKETCHER_ABS"));
103   GroupPt->RB_Point2->setText(tr("GEOM_SKETCHER_REL"));
104   GroupPt->RB_Point3->setText(tr("GEOM_SKETCHER_SEL"));
105
106   GroupD1 = new EntityGUI_Dir1_QTD(GroupDest, "GroupD1");
107   GroupD1->GroupDir1->setTitle(tr("GEOM_SKETCHER_DIR"));
108   GroupD1->RB_Dir11->setText(tr("GEOM_SKETCHER_ANGLE"));
109   GroupD1->RB_Dir12->setText(tr("GEOM_SKETCHER_PER"));
110   GroupD1->RB_Dir13->setText(tr("GEOM_SKETCHER_TAN"));
111   GroupD1->RB_Dir14->setText(tr("GEOM_SKETCHER_VXVY"));
112
113   GroupD2 = new EntityGUI_Dir2_QTD(GroupDest, "GroupD2");
114   GroupD2->GroupDir2->setTitle(tr("GEOM_SKETCHER_DIR"));
115   GroupD2->RB_Dir21->setText(tr("GEOM_SKETCHER_LENGTH"));
116   GroupD2->RB_Dir22->setText(tr("GEOM_SKETCHER_X"));
117   GroupD2->RB_Dir23->setText(tr("GEOM_SKETCHER_Y"));
118
119   Group1Sel = new EntityGUI_1Sel_QTD(this, "Group1Sel");
120   Group1Sel->TextLabel1->setText(tr("GEOM_SKETCHER_POINT2"));
121   Group1Sel->GroupBox1->setTitle(tr("GEOM_SKETCHER_VALUES"));
122   Group1Sel->buttonApply->setText(tr("GEOM_SKETCHER_APPLY"));
123   Group1Sel->PushButton1->setPixmap(image0);
124   Group1Sel->buttonUndo->setPixmap(image1);
125   Group1Sel->buttonRedo->setPixmap(image2);
126   Group1Sel->LineEdit1->setReadOnly( true );
127
128   Group1Spin = new EntityGUI_1Spin(this, "Group1Spin");
129   Group1Spin->GroupBox1->setTitle(tr("GEOM_SKETCHER_VALUES"));
130   Group1Spin->buttonApply->setText(tr("GEOM_SKETCHER_APPLY"));
131   Group1Spin->buttonUndo->setPixmap(image1);
132   Group1Spin->buttonRedo->setPixmap(image2);
133   QWidget::setTabOrder(Group1Spin->SpinBox_DX , Group1Spin->buttonApply);
134   QWidget::setTabOrder(Group1Spin->buttonApply, Group1Spin->buttonUndo);
135   QWidget::setTabOrder(Group1Spin->buttonUndo , Group1Spin->buttonRedo);
136
137   Group2Spin = new EntityGUI_2Spin(this, "Group2Spin");
138   Group2Spin->GroupBox1->setTitle(tr("GEOM_SKETCHER_VALUES"));
139   Group2Spin->buttonApply->setText(tr("GEOM_SKETCHER_APPLY"));
140   Group2Spin->buttonUndo->setPixmap(image1);
141   Group2Spin->buttonRedo->setPixmap(image2);
142   QWidget::setTabOrder(Group2Spin->SpinBox_DX , Group2Spin->SpinBox_DY);
143   QWidget::setTabOrder(Group2Spin->SpinBox_DY , Group2Spin->buttonApply);
144   QWidget::setTabOrder(Group2Spin->buttonApply, Group2Spin->buttonUndo);
145   QWidget::setTabOrder(Group2Spin->buttonUndo , Group2Spin->buttonRedo);
146
147   Group3Spin = new EntityGUI_3Spin(this, "Group3Spin");
148   Group3Spin->GroupBox1->setTitle(tr("GEOM_SKETCHER_VALUES"));
149   Group3Spin->buttonApply->setText(tr("GEOM_SKETCHER_APPLY"));
150   Group3Spin->buttonUndo->setPixmap(image1);
151   Group3Spin->buttonRedo->setPixmap(image2);
152   QWidget::setTabOrder(Group3Spin->SpinBox_DX , Group3Spin->SpinBox_DY);
153   QWidget::setTabOrder(Group3Spin->SpinBox_DY , Group3Spin->SpinBox_DZ);
154   QWidget::setTabOrder(Group3Spin->SpinBox_DZ , Group3Spin->buttonApply);
155   QWidget::setTabOrder(Group3Spin->buttonApply, Group3Spin->buttonUndo);
156   QWidget::setTabOrder(Group3Spin->buttonUndo , Group3Spin->buttonRedo);
157
158   Group4Spin = new EntityGUI_4Spin(this, "Group4Spin");
159   Group4Spin->GroupBox1->setTitle(tr("GEOM_SKETCHER_VALUES"));
160   Group4Spin->buttonApply->setText(tr("GEOM_SKETCHER_APPLY"));
161   Group4Spin->buttonUndo->setPixmap(image1);
162   Group4Spin->buttonRedo->setPixmap(image2);
163   QWidget::setTabOrder(Group4Spin->SpinBox_DX , Group4Spin->SpinBox_DY);
164   QWidget::setTabOrder(Group4Spin->SpinBox_DY , Group4Spin->SpinBox_DZ);
165   QWidget::setTabOrder(Group4Spin->SpinBox_DZ , Group4Spin->SpinBox_DS);
166   QWidget::setTabOrder(Group4Spin->SpinBox_DS , Group4Spin->buttonApply);
167   QWidget::setTabOrder(Group4Spin->buttonApply, Group4Spin->buttonUndo);
168   QWidget::setTabOrder(Group4Spin->buttonUndo , Group4Spin->buttonRedo);
169
170   Layout5->addMultiCellWidget(GroupPt, 1, 1, 0, 1);
171   Layout5->addWidget(GroupD1, 1, 0);
172   Layout5->addWidget(GroupD2, 1, 1);
173
174   Layout1->addWidget(Group1Sel, 2, 0);
175   Layout1->addWidget(Group1Spin, 2, 0);
176   Layout1->addWidget(Group2Spin, 2, 0);
177   Layout1->addWidget(Group3Spin, 2, 0);
178   Layout1->addWidget(Group4Spin, 2, 0);
179   /***************************************************************/
180
181   /* signals and slots connections */
182   connect(buttonEnd, SIGNAL(clicked()), this, SLOT(ClickOnEnd()));
183   connect(buttonClose, SIGNAL(clicked()), this, SLOT(ClickOnEnd()));
184   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
185   connect(buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp()));
186
187   connect(Group1Sel->buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
188   connect(Group1Sel->buttonUndo, SIGNAL(clicked()), this, SLOT(ClickOnUndo()));
189   connect(Group1Sel->buttonRedo, SIGNAL(clicked()), this, SLOT(ClickOnRedo()));
190   connect(Group1Spin->buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
191   connect(Group1Spin->buttonUndo, SIGNAL(clicked()), this, SLOT(ClickOnUndo()));
192   connect(Group1Spin->buttonRedo, SIGNAL(clicked()), this, SLOT(ClickOnRedo()));
193   connect(Group2Spin->buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
194   connect(Group2Spin->buttonUndo, SIGNAL(clicked()), this, SLOT(ClickOnUndo()));
195   connect(Group2Spin->buttonRedo, SIGNAL(clicked()), this, SLOT(ClickOnRedo()));
196   connect(Group3Spin->buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
197   connect(Group3Spin->buttonUndo, SIGNAL(clicked()), this, SLOT(ClickOnUndo()));
198   connect(Group3Spin->buttonRedo, SIGNAL(clicked()), this, SLOT(ClickOnRedo()));
199   connect(Group4Spin->buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
200   connect(Group4Spin->buttonUndo, SIGNAL(clicked()), this, SLOT(ClickOnUndo()));
201   connect(Group4Spin->buttonRedo, SIGNAL(clicked()), this, SLOT(ClickOnRedo()));
202
203   connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(TypeClicked(int)));
204   connect(GroupDest1, SIGNAL(clicked(int)), this, SLOT(DestClicked(int)));
205   connect(GroupPt->GroupPoint, SIGNAL(clicked(int)), this, SLOT(PointClicked(int)));
206   connect(GroupD1->GroupDir1, SIGNAL(clicked(int)), this, SLOT(Dir1Clicked(int)));
207   connect(GroupD2->GroupDir2, SIGNAL(clicked(int)), this, SLOT(Dir2Clicked(int)));
208
209   connect(Group1Sel->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
210   connect(Group1Sel->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
211
212   connect(Group1Spin->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
213   connect(Group2Spin->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
214   connect(Group2Spin->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
215   connect(Group3Spin->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
216   connect(Group3Spin->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
217   connect(Group3Spin->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
218   connect(Group4Spin->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
219   connect(Group4Spin->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
220   connect(Group4Spin->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
221   connect(Group4Spin->SpinBox_DS, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
222
223   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group1Spin->SpinBox_DX, SLOT(SetStep(double)));
224   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group2Spin->SpinBox_DX, SLOT(SetStep(double)));
225   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group2Spin->SpinBox_DY, SLOT(SetStep(double)));
226   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group3Spin->SpinBox_DX, SLOT(SetStep(double)));
227   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group3Spin->SpinBox_DY, SLOT(SetStep(double)));
228   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group3Spin->SpinBox_DZ, SLOT(SetStep(double)));
229   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group4Spin->SpinBox_DX, SLOT(SetStep(double)));
230   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group4Spin->SpinBox_DY, SLOT(SetStep(double)));
231   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group4Spin->SpinBox_DZ, SLOT(SetStep(double)));
232   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group4Spin->SpinBox_DS, SLOT(SetStep(double)));
233
234   connect(myGeometryGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
235   connect(myGeometryGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
236
237   // install event filter on spin-boxes to provide Apply action on Return pressed
238   Group1Spin->SpinBox_DX->installEventFilter(this);
239   Group2Spin->SpinBox_DX->installEventFilter(this);
240   Group2Spin->SpinBox_DY->installEventFilter(this);
241   Group3Spin->SpinBox_DX->installEventFilter(this);
242   Group3Spin->SpinBox_DY->installEventFilter(this);
243   Group3Spin->SpinBox_DZ->installEventFilter(this);
244   Group4Spin->SpinBox_DX->installEventFilter(this);
245   Group4Spin->SpinBox_DY->installEventFilter(this);
246   Group4Spin->SpinBox_DZ->installEventFilter(this);
247   Group4Spin->SpinBox_DS->installEventFilter(this);
248
249   Init();
250 }
251
252 //=================================================================================
253 // function : ~EntityGUI_SketcherDlg()
254 // purpose  : Destroys the object and frees any allocated resources
255 //=================================================================================
256 EntityGUI_SketcherDlg::~EntityGUI_SketcherDlg()
257 {
258   myGeometryGUI->SetActiveDialogBox( 0 );
259 }
260
261 //=================================================================================
262 // function : eventFilter()
263 // purpose  : event filter for spin-boxes to provide Apply action on Return pressed
264 //=================================================================================
265 bool EntityGUI_SketcherDlg::eventFilter (QObject* object, QEvent* event)
266 {
267   if (event->type() == QEvent::KeyPress) {
268     QKeyEvent* ke = (QKeyEvent*)event;
269     if (ke->key() == Key_Return) {
270       if (object == Group1Spin->SpinBox_DX) {
271         Group1Spin->buttonApply->animateClick();
272         return true;
273       } else if (object == Group2Spin->SpinBox_DX ||
274                  object == Group2Spin->SpinBox_DY) {
275         Group2Spin->buttonApply->animateClick();
276         return true;
277       } else if (object == Group3Spin->SpinBox_DX ||
278                  object == Group3Spin->SpinBox_DY ||
279                  object == Group3Spin->SpinBox_DZ) {
280         Group3Spin->buttonApply->animateClick();
281         return true;
282       } else if (object == Group4Spin->SpinBox_DX ||
283                  object == Group4Spin->SpinBox_DY ||
284                  object == Group4Spin->SpinBox_DZ ||
285                  object == Group4Spin->SpinBox_DS) {
286         Group4Spin->buttonApply->animateClick();
287         return true;
288       }
289     }
290   }
291
292   if (event->type() == QEvent::KeyRelease) {
293     // NPAL16010 (Sketcher Apply non available if only one line is modified)
294     // To have Apply active as soon as value text changed
295     QString s = ((QtxDblSpinBox*) object)->text();
296     bool ok;
297     double newVal = s.toDouble( &ok );
298     if ( ok )
299       ValueChangedInSpinBox( newVal );
300   }
301
302   return EntityGUI_Skeleton_QTD::eventFilter(object, event);
303 }
304
305
306 //=================================================================================
307 // function : Init()
308 // purpose  :
309 //=================================================================================
310 void EntityGUI_SketcherDlg::Init()
311 {
312   /* init variables */
313   myEditCurrentArgument = Group1Sel->LineEdit1;
314   myCommand.append( "Sketcher" );
315   myUndoCommand.append( "Sketcher" );
316
317   mySketchState = FIRST_POINT;
318   globalSelection( GEOM_POINT );
319
320   myLastX1 = 0.0;
321   myLastY1 = 0.0;
322   myLastX2 = 0.0;
323   myLastY2 = 0.0;
324
325   myHelpFileName = "create_sketcher_page.html";
326
327   /* Get setting of step value from file configuration */
328   double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
329
330   /* min, max, step and decimals for spin boxes */
331   Group1Spin->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
332   Group2Spin->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
333   Group2Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
334   Group3Spin->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
335   Group3Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
336   Group3Spin->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
337   Group4Spin->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.1, DBL_DIGITS_DISPLAY);
338   Group4Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.1, DBL_DIGITS_DISPLAY);
339   Group4Spin->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
340   Group4Spin->SpinBox_DS->RangeStepAndValidator(COORD_MIN, COORD_MAX, 5., DBL_DIGITS_DISPLAY);
341
342   /* displays Dialog */
343   GroupConstructors->setEnabled(false);
344   GroupDest1->setEnabled(false);
345   setEnabledUndo(false);
346   setEnabledRedo(false);
347
348   RadioButton1->setChecked(true);
349
350   resize( 0, 0 );
351   TypeClicked(0);
352
353   GEOMBase_Helper::displayPreview(false, true, true, myLineWidth);
354 }
355
356
357 //=================================================================================
358 // function : InitClick()
359 // purpose  :
360 //=================================================================================
361 void EntityGUI_SketcherDlg::InitClick()
362 {
363   disconnect(myGeometryGUI->getApp()->selectionMgr(), 0, this, 0);
364
365   Group1Sel->hide();
366   Group1Spin->hide();
367   Group2Spin->hide();
368   Group3Spin->hide();
369   Group4Spin->hide();
370
371   resize(0, 0);
372 }
373
374
375 //=================================================================================
376 // function : TypeClicked()
377 // purpose  : Radio button management
378 //=================================================================================
379 void EntityGUI_SketcherDlg::TypeClicked(int constructorId)
380 {
381   myConstructorId = constructorId;
382   if ( myConstructorId == 0 )     // SEGMENT
383   {
384     GroupD2->setEnabled(true);
385     RB_Dest1->setEnabled(true);
386     RB_Dest1->setChecked(true);
387     DestClicked(1);
388   }
389   else if (  myConstructorId == 1 ) // ARC
390   {
391     GroupD2->setEnabled(false);
392     RB_Dest1->setEnabled(false);
393     RB_Dest2->setChecked(true);
394     DestClicked(0);
395   }
396 }
397
398
399 //=================================================================================
400 // function : DestClicked()
401 // purpose  : Radio button management
402 //=================================================================================
403 void EntityGUI_SketcherDlg::DestClicked( int constructorId )
404 {
405   GroupPt->hide();
406   GroupD1->hide();
407   GroupD2->hide();
408
409   if ( constructorId == 1 )
410   {  // Point
411     GroupPt->RB_Point1->setChecked(true);
412     GroupPt->show();
413     PointClicked(1);  // XY
414   }
415   else if (  constructorId == 0 )
416   {  // Direction
417     GroupD1->RB_Dir11->setChecked(true);
418     GroupD1->show();
419     GroupD2->show();
420     Dir1Clicked(2);  // Angle
421   }
422 }
423
424
425 //=================================================================================
426 // function : PointClicked()
427 // purpose  : Radio button management
428 //=================================================================================
429 void EntityGUI_SketcherDlg::PointClicked(int constructorId)
430 {
431   InitClick();
432
433   // Get setting of step value from file configuration
434   double step = SUIT_Session::session()->resourceMgr()->doubleValue("Geometry", "SettingsGeomStep", 100.0);
435
436   if ( myConstructorId == 0 )
437   {  // SEGMENT
438     if ( constructorId == 1 )
439     {  // XY
440       mySketchType = PT_ABS;
441       Group2Spin->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
442       Group2Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
443       Group2Spin->TextLabel1->setText(tr("GEOM_SKETCHER_X2"));
444       Group2Spin->TextLabel2->setText(tr("GEOM_SKETCHER_Y2"));
445       myX = 0.0;
446       Group2Spin->SpinBox_DX->SetValue(myX);
447       myY = 0.0;
448       Group2Spin->SpinBox_DY->SetValue(myY);
449       Group2Spin->show();
450       Group2Spin->buttonApply->setFocus();
451
452       GEOMBase_Helper::displayPreview(false, true, true, myLineWidth);
453     }
454     else if ( constructorId == 0 )
455     {  // DXDY
456       mySketchType = PT_RELATIVE;
457       Group2Spin->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
458       Group2Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
459       Group2Spin->TextLabel1->setText(tr("GEOM_SKETCHER_DX2"));
460       Group2Spin->TextLabel2->setText(tr("GEOM_SKETCHER_DY2"));
461       myDX = 0.0;
462       Group2Spin->SpinBox_DX->SetValue(myDX);
463       myDY = 0.0;
464       Group2Spin->SpinBox_DY->SetValue(myDY);
465       Group2Spin->show();
466       Group2Spin->buttonApply->setFocus();
467
468       GEOMBase_Helper::displayPreview(false, true, true, myLineWidth);
469     }
470     else if ( constructorId == 2 )
471     {  // Selection
472       mySketchType = PT_SEL;
473       myEditCurrentArgument = Group1Sel->LineEdit1;
474       connect(myGeometryGUI->getApp()->selectionMgr(),
475               SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
476       Group1Sel->show();
477       Group1Sel->buttonApply->setFocus();
478       SelectionIntoArgument();
479     }
480   }
481 }
482
483
484 //=================================================================================
485 // function : Dir1Clicked()
486 // purpose  : Radio button management
487 //=================================================================================
488 void EntityGUI_SketcherDlg::Dir1Clicked(int constructorId)
489 {
490   myConstructorDirId = constructorId;
491   GroupD2->RB_Dir21->setChecked(true);
492   Dir2Clicked(2);
493 }
494
495
496 //=================================================================================
497 // function : Dir2Clicked()
498 // purpose  : Radio button management
499 //=================================================================================
500 void EntityGUI_SketcherDlg::Dir2Clicked(int constructorId)
501 {
502   InitClick();
503   myAngle = 0.0;
504
505   // Get setting of step value from file configuration
506   double step = SUIT_Session::session()->resourceMgr()->doubleValue("Geometry", "SettingsGeomStep", 100.0);
507
508   if ( myConstructorId == 0 )
509   {  // SEGMENT
510     myX = 0.0;
511     myY = 0.0;
512     myLength = 100.0;
513     if ( myConstructorDirId == 2 )
514     {  // Angle
515       Group2Spin->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 5., DBL_DIGITS_DISPLAY);
516       Group2Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
517       Group2Spin->TextLabel1->setText(tr("GEOM_SKETCHER_ANGLE2"));
518       Group2Spin->SpinBox_DX->SetValue(myAngle);
519       Group2Spin->buttonApply->setFocus();
520       Group2Spin->show();
521
522       if ( constructorId == 2 )
523       {  // Length
524                                 mySketchType = DIR_ANGLE_LENGTH;
525                                 Group2Spin->TextLabel2->setText(tr("GEOM_SKETCHER_LENGTH2"));
526                                 Group2Spin->SpinBox_DY->SetValue(myLength);
527       }
528       else if ( constructorId == 0 )
529       {  // X
530                                 mySketchType = DIR_ANGLE_X;
531                                 Group2Spin->TextLabel2->setText(tr("GEOM_SKETCHER_X3"));
532                                 Group2Spin->SpinBox_DY->SetValue(myX);
533       }
534       else if ( constructorId == 1 )
535       {  // Y
536                                 mySketchType = DIR_ANGLE_Y;
537                                 Group2Spin->TextLabel2->setText(tr("GEOM_SKETCHER_Y3"));
538                                 Group2Spin->SpinBox_DY->SetValue(myY);
539       }
540     }
541     else if ( myConstructorDirId == 0 )
542     {  // Perpendicular
543       Group1Spin->show();
544       Group1Spin->buttonApply->setFocus();
545
546       if ( constructorId == 2 )
547       {  // Length
548                                 mySketchType = DIR_PER_LENGTH;
549                                 Group1Spin->TextLabel1->setText(tr("GEOM_SKETCHER_LENGTH2"));
550                                 Group1Spin->SpinBox_DX->SetValue(myLength);
551       }
552       else if ( constructorId == 0 )
553       {  // X
554                                 mySketchType = DIR_PER_X;
555                                 Group1Spin->TextLabel1->setText(tr("GEOM_SKETCHER_X3"));
556                                 Group1Spin->SpinBox_DX->SetValue(myX);
557       }
558       else if ( constructorId == 1 )
559       {  // Y
560                                 mySketchType = DIR_PER_Y;
561                                 Group1Spin->TextLabel1->setText(tr("GEOM_SKETCHER_Y3"));
562                                 Group1Spin->SpinBox_DX->SetValue(myY);
563       }
564     }
565     else if ( myConstructorDirId == 1 )
566     {  // Tangent
567       Group1Spin->show();
568       Group1Spin->buttonApply->setFocus();
569
570       if ( constructorId == 2 )
571       {  // Length
572                                 mySketchType = DIR_TAN_LENGTH;
573                                 Group1Spin->TextLabel1->setText(tr("GEOM_SKETCHER_LENGTH2"));
574                                 Group1Spin->SpinBox_DX->SetValue(myLength);
575       }
576       else if ( constructorId == 0 )
577       {  // X
578                                 mySketchType = DIR_TAN_X;
579                                 Group1Spin->TextLabel1->setText(tr("GEOM_SKETCHER_X3"));
580                                 Group1Spin->SpinBox_DX->SetValue(myX);
581       }
582       else if ( constructorId == 1 )
583       {  // Y
584                                 mySketchType = DIR_TAN_Y;
585                                 Group1Spin->TextLabel1->setText(tr("GEOM_SKETCHER_Y3"));
586                                 Group1Spin->SpinBox_DX->SetValue(myY);
587       }
588     }
589     else if ( myConstructorDirId == 3 )
590     {  // DXDY
591       Group3Spin->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.1, DBL_DIGITS_DISPLAY);
592       Group3Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.1, DBL_DIGITS_DISPLAY);
593       Group3Spin->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
594       Group3Spin->TextLabel1->setText(tr("GEOM_SKETCHER_VX2"));
595       Group3Spin->TextLabel2->setText(tr("GEOM_SKETCHER_VY2"));
596       myDX = 0.0;
597       Group3Spin->SpinBox_DX->SetValue(myDX);
598       myDY = 0.0;
599       Group3Spin->SpinBox_DY->SetValue(myDY);
600       Group3Spin->show();
601       Group3Spin->buttonApply->setFocus();
602
603       if ( constructorId == 2 )
604       {  // Length
605                                 mySketchType = DIR_DXDY_LENGTH;
606                                 Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_LENGTH2"));
607                                 Group3Spin->SpinBox_DZ->SetValue(myLength);
608       }
609       else if ( constructorId == 0 )
610       {  // X
611                                 mySketchType = DIR_DXDY_X;
612                                 Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_X3"));
613                                 Group3Spin->SpinBox_DZ->SetValue(myX);
614       }
615       else if ( constructorId == 1 )
616       {  // Y
617                                 mySketchType = DIR_DXDY_Y;
618                                 Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_Y3"));
619                                 Group3Spin->SpinBox_DZ->SetValue(myY);
620       }
621     }
622   }
623   else if ( myConstructorId == 1 )
624   {  // ARC
625     if ( myConstructorDirId == 2 )
626     {  // Angle
627       if ( constructorId == 2 )
628       {  // Length
629         mySketchType = DIR_ANGLE_LENGTH;
630         Group3Spin->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 5., DBL_DIGITS_DISPLAY);
631         Group3Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
632         Group3Spin->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 5., DBL_DIGITS_DISPLAY);
633         Group3Spin->TextLabel1->setText(tr("GEOM_SKETCHER_ANGLE2"));
634         Group3Spin->TextLabel2->setText(tr("GEOM_SKETCHER_RADIUS2"));
635         Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_ANGLE2"));
636         Group3Spin->SpinBox_DX->SetValue(myAngle);
637         myRadius = 100.0;
638         Group3Spin->SpinBox_DY->SetValue(myRadius);
639         myLength = 30.0;
640         Group3Spin->SpinBox_DZ->SetValue(myLength);
641         Group3Spin->show();
642         Group3Spin->buttonApply->setFocus();
643       }
644     }
645     else if ( myConstructorDirId == 0 )
646     {  // Perpendicular
647       if ( constructorId == 2 )
648       {  // Length
649         mySketchType = DIR_PER_LENGTH;
650         Group2Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
651         Group2Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 5., DBL_DIGITS_DISPLAY);
652         Group2Spin->TextLabel1->setText(tr("GEOM_SKETCHER_RADIUS2"));
653         Group2Spin->TextLabel2->setText(tr("GEOM_SKETCHER_ANGLE2"));
654         myRadius = 100.0;
655         Group2Spin->SpinBox_DX->SetValue(myRadius);
656         myLength = 30.0;
657         Group2Spin->SpinBox_DY->SetValue(myLength);
658         Group2Spin->show();
659         Group2Spin->buttonApply->setFocus();
660       }
661     }
662     else if ( myConstructorDirId == 1 )
663     {  // Tangent
664       if ( constructorId == 2 )
665       {  // Length
666         mySketchType = DIR_TAN_LENGTH;
667         Group2Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
668         Group2Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 5., DBL_DIGITS_DISPLAY);
669         Group2Spin->TextLabel1->setText(tr("GEOM_SKETCHER_RADIUS2"));
670         Group2Spin->TextLabel2->setText(tr("GEOM_SKETCHER_ANGLE2"));
671         myRadius = 100.0;
672         Group2Spin->SpinBox_DX->SetValue(myRadius);
673         myLength = 30.0;
674         Group2Spin->SpinBox_DY->SetValue(myLength);
675         Group2Spin->show();
676         Group2Spin->buttonApply->setFocus();
677       }
678     }
679     else if ( myConstructorDirId == 3 )
680     {  // DXDY
681       if ( constructorId == 2 )
682       {  // Length
683                                 mySketchType = DIR_DXDY_LENGTH;
684                                 Group4Spin->TextLabel1->setText(tr("GEOM_SKETCHER_VX2"));
685                                 Group4Spin->TextLabel2->setText(tr("GEOM_SKETCHER_VY2"));
686                                 Group4Spin->TextLabel3->setText(tr("GEOM_SKETCHER_RADIUS2"));
687                                 Group4Spin->TextLabel4->setText(tr("GEOM_SKETCHER_ANGLE2"));
688                                 myDX = 0.0;
689                                 Group4Spin->SpinBox_DX->SetValue(myDX);
690                                 myDY = 0.0;
691                                 Group4Spin->SpinBox_DY->SetValue(myDY);
692                                 myRadius = 100.0;
693                                 Group4Spin->SpinBox_DZ->SetValue(myRadius);
694                                 myLength = 30.0;
695                                 Group4Spin->SpinBox_DS->SetValue(myLength);
696                                 Group4Spin->show();
697                                 Group4Spin->buttonApply->setFocus();
698       }
699     }
700   }
701
702   GEOMBase_Helper::displayPreview(false, true, true, myLineWidth);
703 }
704
705
706 //=================================================================================
707 // function : ClickOnCancel()
708 // purpose  :
709 //=================================================================================
710 void EntityGUI_SketcherDlg::ClickOnCancel()
711 {
712   close();
713 }
714
715
716 //=================================================================================
717 // function : ClickOnEnd()
718 // purpose  : connected to buttonEnd AND buttonClose
719 //=================================================================================
720 void EntityGUI_SketcherDlg::ClickOnEnd()
721 {
722   if ( sender() == buttonClose )
723   {
724     // Verify validity of commands
725     if ( myCommand.count() <= 2 )
726     {
727       SUIT_MessageBox::error1( SUIT_Session::session()->activeApplication()->desktop(),
728                                tr( "GEOM_ERROR_STATUS" ), tr( "CANNOT_CLOSE" ), tr( "BUT_OK" ) );
729       return;
730     }
731
732     QString Command = myCommand.join( "" ) + GetNewCommand();
733     Sketcher_Profile aProfile (Command.ascii());
734
735     Command = myCommand.join( "" );
736     aProfile = Sketcher_Profile(Command.ascii());
737     TopoDS_Shape myShape;
738     if ( aProfile.IsDone() )
739       myShape = aProfile.GetShape();
740
741     if(myShape.ShapeType() != TopAbs_VERTEX)
742       myCommand.append( ":WW" );
743   }
744   else
745   {
746     // PAL16008 (Sketcher Validation should be equal to Apply&Close)
747     if (Group1Spin->buttonApply->isEnabled() && Group1Spin->isVisible() ||
748         Group2Spin->buttonApply->isEnabled() && Group2Spin->isVisible() ||
749         Group3Spin->buttonApply->isEnabled() && Group3Spin->isVisible() ||
750         Group4Spin->buttonApply->isEnabled() && Group4Spin->isVisible() ||
751         Group1Sel ->buttonApply->isEnabled() && Group1Sel->isVisible() )
752     {
753       ClickOnApply();
754     }
755     myIsAllAdded = true;
756   }
757
758   if( myCommand.size() > 2 )
759     if( !onAccept() )
760       return;
761
762   close();
763 }
764
765 //=================================================================================
766 // function : ClickOnApply()
767 // purpose  :
768 //=================================================================================
769 bool EntityGUI_SketcherDlg::ClickOnApply()
770 {
771   if (sender() && sender()->inherits("QPushButton"))
772     ((QPushButton*)sender())->setFocus(); // to update value of currently edited spin-box (PAL11948)
773
774   myCommand.append( GetNewCommand() );
775   mySketchState = NEXT_POINT;
776
777   myUndoCommand.clear();
778   myUndoCommand.append( "Sketcher" );
779
780   GroupConstructors->setEnabled(true);
781   GroupDest1->setEnabled(true);
782   setEnabledUndo(true);
783   setEnabledRedo(false);
784
785   GEOMBase_Helper::displayPreview(false, true, true, myLineWidth);
786
787   // Set focus to SpinBox_DX
788   if (sender() == Group1Spin->buttonApply) {
789     (Group1Spin->SpinBox_DX)->setFocus();
790     (Group1Spin->SpinBox_DX)->selectAll();
791   }
792   else if (sender() == Group2Spin->buttonApply) {
793     (Group2Spin->SpinBox_DX)->setFocus();
794     (Group2Spin->SpinBox_DX)->selectAll();
795   }
796   else if (sender() == Group3Spin->buttonApply) {
797     (Group3Spin->SpinBox_DX)->setFocus();
798     (Group3Spin->SpinBox_DX)->selectAll();
799   }
800   else if (sender() == Group4Spin->buttonApply) {
801     (Group4Spin->SpinBox_DX)->setFocus();
802     (Group4Spin->SpinBox_DX)->selectAll();
803   }
804
805   return true;
806 }
807
808 //=================================================================================
809 // function : ClickOnHelp()
810 // purpose  :
811 //=================================================================================
812 void EntityGUI_SketcherDlg::ClickOnHelp()
813 {
814   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
815   if (app)
816     app->onHelpContextModule(myGeometryGUI ? app->moduleName(myGeometryGUI->moduleName()) : QString(""), myHelpFileName);
817   else {
818                 QString platform;
819 #ifdef WIN32
820                 platform = "winapplication";
821 #else
822                 platform = "application";
823 #endif
824
825     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
826                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
827                            arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
828                            QObject::tr("BUT_OK"));
829   }
830 }
831
832 //=================================================================================
833 // function : ClickOnUndo()
834 // purpose  :
835 //=================================================================================
836 void EntityGUI_SketcherDlg::ClickOnUndo()
837 {
838   myUndoCommand.append( myCommand.last() );
839   myCommand.pop_back();
840
841   if(myCommand.count() == 1) {
842     mySketchState = FIRST_POINT;
843
844     RadioButton1->setChecked(true);
845     TypeClicked(0);
846
847     GroupConstructors->setEnabled(false);
848     GroupDest1->setEnabled(false);
849     setEnabledUndo(false);
850   }
851
852   setEnabledRedo(true);
853
854   GEOMBase_Helper::displayPreview(false, true, true, myLineWidth);
855 }
856
857 //=================================================================================
858 // function : ClickOnRedo()
859 // purpose  :
860 //=================================================================================
861 void EntityGUI_SketcherDlg::ClickOnRedo()
862 {
863   myCommand.append( myUndoCommand.last() );
864   myUndoCommand.pop_back();
865
866   mySketchState = NEXT_POINT;
867
868   GroupConstructors->setEnabled(true);
869   GroupDest1->setEnabled(true);
870   setEnabledUndo(true);
871
872   if(myUndoCommand.count() == 1)
873     setEnabledRedo(false);
874
875   GEOMBase_Helper::displayPreview(false, true, true, myLineWidth);
876 }
877
878 //=================================================================================
879 // function : setEnabledUndo()
880 // purpose  :
881 //=================================================================================
882 void EntityGUI_SketcherDlg::setEnabledUndo(bool value)
883 {
884   Group1Sel->buttonUndo->setEnabled(value);
885   Group1Spin->buttonUndo->setEnabled(value);
886   Group2Spin->buttonUndo->setEnabled(value);
887   Group3Spin->buttonUndo->setEnabled(value);
888   Group4Spin->buttonUndo->setEnabled(value);
889 }
890
891 //=================================================================================
892 // function : setEnabledRedo()
893 // purpose  :
894 //=================================================================================
895 void EntityGUI_SketcherDlg::setEnabledRedo(bool value)
896 {
897   Group1Sel->buttonRedo->setEnabled(value);
898   Group1Spin->buttonRedo->setEnabled(value);
899   Group2Spin->buttonRedo->setEnabled(value);
900   Group3Spin->buttonRedo->setEnabled(value);
901   Group4Spin->buttonRedo->setEnabled(value);
902 }
903
904 //=================================================================================
905 // function : SelectionIntoArgument()
906 // purpose  : Called when selection as changed
907 //=================================================================================
908 void EntityGUI_SketcherDlg::SelectionIntoArgument()
909 {
910   myEditCurrentArgument->setText("");
911   myX = myLastX1;
912   myY = myLastY1;
913
914   int nbSel = IObjectCount();
915   if ( nbSel == 1 && myEditCurrentArgument == Group1Sel->LineEdit1 )
916   {
917     Standard_Boolean aRes = Standard_False;
918     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
919     if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
920       TopoDS_Shape aShape;
921       if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_VERTEX ) ) {
922         gp_Trsf aTrans;
923         gp_Ax3 aWPlane = myGeometryGUI->GetWorkingPlane();
924
925         aTrans.SetTransformation(aWPlane);
926         BRepBuilderAPI_Transform aTransformation(aShape, aTrans, Standard_False);
927         aShape = aTransformation.Shape();
928
929         gp_Pnt aPnt;
930         if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) {
931           myX = aPnt.X();
932           myY = aPnt.Y();
933           Group1Sel->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
934         }
935       }
936     }
937   }
938
939   GEOMBase_Helper::displayPreview(false, true, true, myLineWidth);
940 }
941
942
943 //=================================================================================
944 // function : SetEditCurrentArgument()
945 // purpose  :
946 //=================================================================================
947 void EntityGUI_SketcherDlg::SetEditCurrentArgument()
948 {
949   if ( sender() == Group1Sel->PushButton1 )
950   {
951     myEditCurrentArgument = Group1Sel->LineEdit1;
952     myEditCurrentArgument->setFocus();
953   }
954   SelectionIntoArgument();
955 }
956
957
958 //=================================================================================
959 // function : LineEditReturnPressed()
960 // purpose  :
961 //=================================================================================
962 void EntityGUI_SketcherDlg::LineEditReturnPressed()
963 {
964   if ( sender() == Group1Sel->LineEdit1 )
965   {
966     myEditCurrentArgument = Group1Sel->LineEdit1;
967
968         /* User name of object input management                          */
969         /* If successfull the selection is changed and signal emitted... */
970         /* so SelectionIntoArgument() is automatically called.           */
971         const QString objectUserName = myEditCurrentArgument->text();
972         QWidget* thisWidget = (QWidget*)this;
973         if(GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, selectedIO()))
974         myEditCurrentArgument->setText(objectUserName);
975   }
976 }
977
978
979 //=================================================================================
980 // function : DeactivateActiveDialog()
981 // purpose  :
982 //=================================================================================
983 void EntityGUI_SketcherDlg::DeactivateActiveDialog()
984 {
985   //myGeometryGUI->SetState( -1 );
986
987   setEnabled( false );
988   globalSelection();
989   disconnect(myGeometryGUI->getApp()->selectionMgr(), 0, this, 0);
990   myGeometryGUI->SetActiveDialogBox(0);
991 }
992
993
994 //=================================================================================
995 // function : ActivateThisDialog()
996 // purpose  :
997 //=================================================================================
998 void EntityGUI_SketcherDlg::ActivateThisDialog()
999 {
1000   myGeometryGUI->EmitSignalDeactivateDialog();
1001   setEnabled(true);
1002   myGeometryGUI->SetActiveDialogBox((QDialog*)this);
1003
1004   connect(myGeometryGUI->getApp()->selectionMgr(),
1005           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
1006
1007   //myGeometryGUI->SetState( 0 );
1008   globalSelection( GEOM_POINT );
1009
1010   myEditCurrentArgument = Group1Sel->LineEdit1;
1011   myEditCurrentArgument->setFocus();
1012
1013   GEOMBase_Helper::displayPreview(false, true, true, myLineWidth);
1014 }
1015
1016
1017 //=================================================================================
1018 // function : enterEvent [REDEFINED]
1019 // purpose  :
1020 //=================================================================================
1021 void EntityGUI_SketcherDlg::enterEvent(QEvent* e)
1022 {
1023   if ( !GroupConstructors->isEnabled())
1024     ActivateThisDialog();
1025 }
1026
1027
1028 //=================================================================================
1029 // function : closeEvent()
1030 // purpose  :
1031 //=================================================================================
1032 void EntityGUI_SketcherDlg::closeEvent(QCloseEvent* e)
1033 {
1034   //myGeometryGUI->SetState( -1 );
1035   disconnect(myGeometryGUI->getApp()->selectionMgr(), 0, this, 0);
1036   myGeometryGUI->getApp()->updateActions();
1037   QDialog::closeEvent( e );
1038 }
1039
1040
1041 //=================================================================================
1042 // function : ValueChangedInSpinBox()
1043 // purpose  :
1044 //=================================================================================
1045 void EntityGUI_SketcherDlg::ValueChangedInSpinBox(double newValue)
1046 {
1047   QObject* send = (QObject*)sender();
1048   Standard_Real vx, vy, vz, vs;
1049   vx = vy = vz = vs = 0.0;
1050
1051   if ( send == Group1Spin->SpinBox_DX)
1052   {
1053     vx = newValue;
1054   }
1055   else if ( send == Group2Spin->SpinBox_DX )
1056   {
1057     vx = newValue;
1058     vy = Group2Spin->SpinBox_DY->GetValue();
1059   }
1060   else if ( send == Group2Spin->SpinBox_DY)
1061   {
1062     vx = Group2Spin->SpinBox_DX->GetValue();
1063     vy = newValue;
1064   }
1065   else if ( send == Group3Spin->SpinBox_DX)
1066   {
1067     vx = newValue;
1068     vy = Group3Spin->SpinBox_DY->GetValue();
1069     vz = Group3Spin->SpinBox_DZ->GetValue();
1070   }
1071   else if ( send == Group3Spin->SpinBox_DY)
1072   {
1073     vx = Group3Spin->SpinBox_DX->GetValue();
1074     vy = newValue;
1075     vz = Group3Spin->SpinBox_DZ->GetValue();
1076   }
1077   else if ( send == Group3Spin->SpinBox_DZ)
1078   {
1079     vx = Group3Spin->SpinBox_DX->GetValue();
1080     vy = Group3Spin->SpinBox_DY->GetValue();
1081     vz = newValue;
1082   }
1083   else if ( send == Group4Spin->SpinBox_DX)
1084   {
1085     vx = newValue;
1086     vy = Group4Spin->SpinBox_DY->GetValue();
1087     vz = Group4Spin->SpinBox_DZ->GetValue();
1088     vs = Group4Spin->SpinBox_DS->GetValue();
1089   }
1090   else if ( send == Group4Spin->SpinBox_DY)
1091   {
1092     vx = Group4Spin->SpinBox_DX->GetValue();
1093     vy = newValue;
1094     vz = Group4Spin->SpinBox_DZ->GetValue();
1095     vs = Group4Spin->SpinBox_DS->GetValue();
1096   }
1097   else if ( send == Group4Spin->SpinBox_DZ)
1098   {
1099     vx = Group4Spin->SpinBox_DX->GetValue();
1100     vy = Group4Spin->SpinBox_DY->GetValue();
1101     vz = newValue;
1102     vs = Group4Spin->SpinBox_DS->GetValue();
1103   }
1104   else if ( send == Group4Spin->SpinBox_DS)
1105   {
1106     vx = Group4Spin->SpinBox_DX->GetValue();
1107     vy = Group4Spin->SpinBox_DY->GetValue();
1108     vz = Group4Spin->SpinBox_DZ->GetValue();
1109     vs = newValue;
1110   }
1111   // NPAL16010 (Sketcher Apply non available if only one line is modified)
1112   // if ValueChangedInSpinBox() called from eventFilter()
1113   else if ( Group1Spin->SpinBox_DX->hasFocus() )
1114   {
1115     vx = newValue;
1116   }
1117   else if ( Group2Spin->SpinBox_DX ->hasFocus() )
1118   {
1119     vx = newValue;
1120     vy = Group2Spin->SpinBox_DY->GetValue();
1121   }
1122   else if ( Group2Spin->SpinBox_DY->hasFocus() )
1123   {
1124     vx = Group2Spin->SpinBox_DX->GetValue();
1125     vy = newValue;
1126   }
1127   else if ( Group3Spin->SpinBox_DX->hasFocus() )
1128   {
1129     vx = newValue;
1130     vy = Group3Spin->SpinBox_DY->GetValue();
1131     vz = Group3Spin->SpinBox_DZ->GetValue();
1132   }
1133   else if ( Group3Spin->SpinBox_DY->hasFocus() )
1134   {
1135     vx = Group3Spin->SpinBox_DX->GetValue();
1136     vy = newValue;
1137     vz = Group3Spin->SpinBox_DZ->GetValue();
1138   }
1139   else if ( Group3Spin->SpinBox_DZ->hasFocus() )
1140   {
1141     vx = Group3Spin->SpinBox_DX->GetValue();
1142     vy = Group3Spin->SpinBox_DY->GetValue();
1143     vz = newValue;
1144   }
1145   else if ( Group4Spin->SpinBox_DX->hasFocus() )
1146   {
1147     vx = newValue;
1148     vy = Group4Spin->SpinBox_DY->GetValue();
1149     vz = Group4Spin->SpinBox_DZ->GetValue();
1150     vs = Group4Spin->SpinBox_DS->GetValue();
1151   }
1152   else if ( Group4Spin->SpinBox_DY->hasFocus() )
1153   {
1154     vx = Group4Spin->SpinBox_DX->GetValue();
1155     vy = newValue;
1156     vz = Group4Spin->SpinBox_DZ->GetValue();
1157     vs = Group4Spin->SpinBox_DS->GetValue();
1158   }
1159   else if ( Group4Spin->SpinBox_DZ->hasFocus() )
1160   {
1161     vx = Group4Spin->SpinBox_DX->GetValue();
1162     vy = Group4Spin->SpinBox_DY->GetValue();
1163     vz = newValue;
1164     vs = Group4Spin->SpinBox_DS->GetValue();
1165   }
1166   else if ( Group4Spin->SpinBox_DS->hasFocus() )
1167   {
1168     vx = Group4Spin->SpinBox_DX->GetValue();
1169     vy = Group4Spin->SpinBox_DY->GetValue();
1170     vz = Group4Spin->SpinBox_DZ->GetValue();
1171     vs = newValue;
1172   }
1173
1174   if ( myConstructorId == 0 )
1175   {  // SEGMENT
1176     if ( mySketchType == PT_ABS)
1177     {
1178       myX = vx;
1179       myY = vy;
1180     }
1181     else if ( mySketchType == PT_RELATIVE)
1182     {
1183       myDX = vx;
1184       myDY = vy;
1185     }
1186     else if ( mySketchType == DIR_ANGLE_LENGTH)
1187     {
1188       myAngle = vx;
1189       myLength = vy;
1190     }
1191     else if ( mySketchType == DIR_ANGLE_X)
1192     {
1193       myAngle = vx;
1194       myX = vy;
1195     }
1196     else if ( mySketchType == DIR_ANGLE_Y)
1197     {
1198       myAngle = vx;
1199       myY = vy;
1200     }
1201     else if ( mySketchType == DIR_PER_LENGTH)
1202     {
1203       myLength = vx;
1204     }
1205     else if ( mySketchType == DIR_PER_X)
1206     {
1207       myX = vx;
1208     }
1209     else if ( mySketchType == DIR_PER_Y)
1210     {
1211       myY = vx;
1212     }
1213     else if ( mySketchType == DIR_TAN_LENGTH)
1214     {
1215       myLength = vx;
1216     }
1217     else if ( mySketchType == DIR_TAN_X)
1218     {
1219       myX = vx;
1220     }
1221     else if ( mySketchType == DIR_TAN_Y)
1222     {
1223       myY = vx;
1224     }
1225     else if ( mySketchType == DIR_DXDY_LENGTH)
1226     {
1227       myDX = vx;
1228       myDY = vy;
1229       myLength = vz;
1230     }
1231     else if ( mySketchType == DIR_DXDY_X)
1232     {
1233       myDX = vx;
1234       myDY = vy;
1235       myX = vz;
1236     }
1237     else if ( mySketchType == DIR_DXDY_Y)
1238     {
1239       myDX = vx;
1240       myDY = vy;
1241       myY = vz;
1242     }
1243   }
1244   else if ( myConstructorId == 1 )
1245   {  // ARC
1246     if ( mySketchType == DIR_ANGLE_LENGTH)
1247     {
1248       myAngle = vx;
1249       myRadius = vy;
1250       myLength = vz;
1251     }
1252     else if ( mySketchType == DIR_PER_LENGTH)
1253     {
1254       myRadius = vx;
1255       myLength = vy;
1256     }
1257     else if ( mySketchType == DIR_TAN_LENGTH)
1258     {
1259       myRadius = vx;
1260       myLength = vy;
1261     }
1262     else if ( mySketchType == DIR_DXDY_LENGTH)
1263     {
1264       myDX = vx;
1265       myDY = vy;
1266       myRadius = vz;
1267       myLength = vs;
1268     }
1269   }
1270
1271   GEOMBase_Helper::displayPreview(false, true, true, myLineWidth);
1272 }
1273
1274
1275 //=================================================================================
1276 // function : GetNewCommand()
1277 // purpose  : Build the new command with context
1278 //=================================================================================
1279 QString EntityGUI_SketcherDlg::GetNewCommand()
1280 {
1281   QString myNewCommand = ":";
1282   if ( mySketchState == FIRST_POINT ) {
1283     if ( mySketchType == PT_ABS || mySketchType == PT_SEL)
1284       myNewCommand = myNewCommand + "F " + QString::number(myX) + " " + QString::number(myY);
1285     if ( mySketchType == PT_RELATIVE)
1286       myNewCommand = myNewCommand + "F " + QString::number(myDX) + " " + QString::number(myDY);
1287     return myNewCommand;
1288   }
1289
1290   if ( myConstructorId == 0  )
1291   {  // SEGMENT
1292     if ( mySketchType == PT_ABS || mySketchType == PT_SEL)
1293       myNewCommand = myNewCommand + "TT " + QString::number(myX) + " " + QString::number(myY);
1294     if ( mySketchType == PT_RELATIVE)
1295       myNewCommand = myNewCommand + "T " + QString::number(myDX) + " " + QString::number(myDY);
1296     if ( mySketchType == DIR_ANGLE_LENGTH)
1297     {
1298       myNewCommand = myNewCommand + "R " + QString::number(myAngle);
1299       myNewCommand = myNewCommand + ":" + "L " + QString::number(myLength);
1300     }
1301     if ( mySketchType == DIR_ANGLE_X)
1302     {
1303       myNewCommand = myNewCommand + "R " + QString::number(myAngle);
1304       myNewCommand = myNewCommand + ":" + "IX " + QString::number(myX);
1305     }
1306     if ( mySketchType == DIR_ANGLE_Y)
1307     {
1308       myNewCommand = myNewCommand + "R " + QString::number(myAngle);
1309       myNewCommand = myNewCommand + ":" + "IY " + QString::number(myY);
1310     }
1311     if ( mySketchType == DIR_PER_LENGTH)
1312     {
1313       myNewCommand = myNewCommand + "R " + QString::number(90.0);
1314       myNewCommand = myNewCommand + ":" + "L " + QString::number(myLength);
1315     }
1316     if ( mySketchType == DIR_PER_X)
1317     {
1318       myNewCommand = myNewCommand + "R " + QString::number(90.0);
1319       myNewCommand = myNewCommand + ":" + "IX " + QString::number(myX);
1320     }
1321     if ( mySketchType == DIR_PER_Y)
1322     {
1323       myNewCommand = myNewCommand + "R " + QString::number(90.0);
1324       myNewCommand = myNewCommand + ":" + "IY " + QString::number(myY);
1325     }
1326     if ( mySketchType == DIR_TAN_LENGTH)
1327       myNewCommand = myNewCommand + "L " + QString::number(myLength);
1328     if ( mySketchType == DIR_TAN_X)
1329       myNewCommand = myNewCommand + "IX " + QString::number(myX);
1330     if ( mySketchType == DIR_TAN_Y)
1331       myNewCommand = myNewCommand + "IY " + QString::number(myY);
1332     if ( mySketchType == DIR_DXDY_LENGTH)
1333     {
1334       myNewCommand = myNewCommand + "D " + QString::number(myDX) + " " + QString::number(myDY);
1335       myNewCommand = myNewCommand + ":" + "L " + QString::number(myLength);
1336     }
1337     if ( mySketchType == DIR_DXDY_X)
1338     {
1339       myNewCommand = myNewCommand + "D " + QString::number(myDX) + " " + QString::number(myDY);
1340       myNewCommand = myNewCommand + ":" + "IX " + QString::number(myX);
1341     }
1342     if ( mySketchType == DIR_DXDY_Y)
1343     {
1344       myNewCommand = myNewCommand + "D " + QString::number(myDX) + " " + QString::number(myDY);
1345       myNewCommand = myNewCommand + ":" + "IY " + QString::number(myY);
1346     }
1347   }
1348   else if ( myConstructorId == 1 )
1349   {  // ARC
1350     if ( mySketchType == DIR_ANGLE_LENGTH)
1351     {
1352       myNewCommand = myNewCommand + "R " + QString::number(myAngle);
1353       myNewCommand = myNewCommand + ":" + "C " + QString::number(myRadius) + " " + QString::number(myLength);
1354     }
1355     if ( mySketchType == DIR_PER_LENGTH)
1356     {
1357       myNewCommand = myNewCommand + "R " + QString::number(90.0);
1358       myNewCommand = myNewCommand + ":" + "C " + QString::number(myRadius) + " " + QString::number(myLength);
1359     }
1360     if ( mySketchType == DIR_TAN_LENGTH)
1361     {
1362       myNewCommand = myNewCommand + "C " + QString::number(myRadius) + " " + QString::number(myLength);
1363     }
1364     if ( mySketchType == DIR_DXDY_LENGTH)
1365     {
1366       myNewCommand = myNewCommand + "D " + QString::number(myDX) + " " + QString::number(myDY);
1367       myNewCommand = myNewCommand + ":" + "C " + QString::number(myRadius) + " " + QString::number(myLength);
1368     }
1369   }
1370   return myNewCommand;
1371 }
1372
1373 //=================================================================================
1374 // function : createOperation
1375 // purpose  :
1376 //=================================================================================
1377 GEOM::GEOM_IOperations_ptr EntityGUI_SketcherDlg::createOperation()
1378 {
1379   return getGeomEngine()->GetICurvesOperations( getStudyId() );
1380 }
1381
1382 //=================================================================================
1383 // function : isValid
1384 // purpose  :
1385 //=================================================================================
1386 bool EntityGUI_SketcherDlg::isValid( QString& msg )
1387 {
1388   return true;
1389 }
1390
1391 //=================================================================================
1392 // function : execute
1393 // purpose  :
1394 //=================================================================================
1395 bool EntityGUI_SketcherDlg::execute( ObjectList& objects )
1396 {
1397   if(mySketchState == FIRST_POINT) {
1398     myLastX2 = myX;
1399     myLastY2 = myY;
1400   }
1401   else {
1402     //Test if the current point is the same as the last one
1403     TopoDS_Shape myShape1, myShape2;
1404
1405     //Last Shape
1406     QString Command1 = myCommand.join( "" );
1407     Sketcher_Profile aProfile1 (Command1.ascii());
1408     if(aProfile1.IsDone())
1409       myShape1 = aProfile1.GetShape();
1410
1411     //Current Shape
1412     QString Command2 = Command1 + GetNewCommand();
1413     Sketcher_Profile aProfile2 (Command2.ascii());
1414     if(aProfile2.IsDone())
1415       myShape2 = aProfile2.GetShape();
1416
1417     if(myShape2.IsNull()) {
1418       //the current point is the same as the last one
1419       myLastX2 = myLastX1;
1420       myLastY2 = myLastY1;
1421     }
1422     else {
1423       TopoDS_Vertex V1, V2;
1424       gp_Pnt pt;
1425       if(myShape1.ShapeType() == TopAbs_VERTEX) {
1426         //the last shape is the first point
1427         pt = BRep_Tool::Pnt(TopoDS::Vertex(myShape1));
1428         myLastX1 = pt.X();
1429         myLastY1 = pt.Y();
1430       }
1431       else {
1432         TopExp::Vertices(TopoDS::Wire(myShape1), V1, V2);
1433         pt = BRep_Tool::Pnt(V2);
1434         myLastX1 = pt.X();
1435         myLastY1 = pt.Y();
1436       }
1437       TopExp::Vertices(TopoDS::Wire(myShape2), V1, V2);
1438       pt = BRep_Tool::Pnt(V2);
1439       myLastX2 = pt.X();
1440       myLastY2 = pt.Y();
1441     }
1442   }
1443
1444   QString cmd;
1445   if( ( mySketchState != FIRST_POINT &&
1446         myLastX1 == myLastX2 && myLastY1 == myLastY2 ) || myIsAllAdded ) {
1447     cmd = myCommand.join( "" );
1448
1449     if ( Group1Sel->isVisible() ) {
1450       Group1Sel->buttonApply->setEnabled(false);
1451       //Group1Sel->buttonApply->setFocus();
1452     }
1453     if ( Group1Spin->isVisible() ) {
1454       Group1Spin->buttonApply->setEnabled(false);
1455       //Group1Spin->buttonApply->setFocus();
1456     }
1457     if ( Group2Spin->isVisible() ) {
1458       Group2Spin->buttonApply->setEnabled(false);
1459       //Group2Spin->buttonApply->setFocus();
1460     }
1461     if ( Group3Spin->isVisible() ) {
1462       Group3Spin->buttonApply->setEnabled(false);
1463       //Group3Spin->buttonApply->setFocus();
1464     }
1465     if ( Group4Spin->isVisible() ) {
1466       Group4Spin->buttonApply->setEnabled(false);
1467       //Group4Spin->buttonApply->setFocus();
1468     }
1469   }
1470   else {
1471     cmd = myCommand.join( "" ) + GetNewCommand();
1472
1473     if ( Group1Sel->isVisible() ) {
1474       Group1Sel->buttonApply->setEnabled(true);
1475       //Group1Sel->buttonApply->setFocus();
1476     }
1477     if ( Group1Spin->isVisible() ) {
1478       Group1Spin->buttonApply->setEnabled(true);
1479       //Group1Spin->buttonApply->setFocus();
1480     }
1481     if ( Group2Spin->isVisible() ) {
1482       Group2Spin->buttonApply->setEnabled(true);
1483       //Group2Spin->buttonApply->setFocus();
1484     }
1485     if ( Group3Spin->isVisible() ) {
1486       Group3Spin->buttonApply->setEnabled(true);
1487       //Group3Spin->buttonApply->setFocus();
1488     }
1489     if ( Group4Spin->isVisible() ) {
1490       Group4Spin->buttonApply->setEnabled(true);
1491       //Group4Spin->buttonApply->setFocus();
1492     }
1493   }
1494
1495   gp_Ax3 myWPlane = myGeometryGUI->GetWorkingPlane();
1496   GEOM::ListOfDouble_var WPlane = new GEOM::ListOfDouble;
1497   WPlane->length(9);
1498   WPlane[0] = myWPlane.Location().X();
1499   WPlane[1] = myWPlane.Location().Y();
1500   WPlane[2] = myWPlane.Location().Z();
1501
1502   WPlane[3] = myWPlane.Direction().X();
1503   WPlane[4] = myWPlane.Direction().Y();
1504   WPlane[5] = myWPlane.Direction().Z();
1505
1506   WPlane[6] = myWPlane.XDirection().X();
1507   WPlane[7] = myWPlane.XDirection().Y();
1508   WPlane[8] = myWPlane.XDirection().Z();
1509
1510   GEOM::GEOM_Object_var anObj =
1511     GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSketcher( cmd.latin1(), WPlane );
1512
1513   if ( !anObj->_is_nil() )
1514     objects.push_back( anObj._retn() );
1515
1516   return true;
1517 }
1518
1519 //================================================================
1520 // Function : displayPreview
1521 // Purpose  : Method for displaying preview of resulting shape
1522 //            Redefined from GEOMBase_Helper.
1523 //================================================================
1524 void EntityGUI_SketcherDlg::displayPreview( GEOM::GEOM_Object_ptr object,
1525                                             const bool            append,
1526                                             const bool            activate,
1527                                             const bool            update,
1528                                             const double          lineWidth,
1529                                             const int             displayMode,
1530                                             const int             color)
1531 {
1532   // Set color for preview shape
1533   getDisplayer()->SetColor( Quantity_NOC_RED );
1534
1535   // set width of displayed shape
1536   getDisplayer()->SetWidth( (lineWidth == -1)?myLineWidth:lineWidth );
1537
1538   // Disable activation of selection
1539   getDisplayer()->SetToActivate( activate );
1540
1541   // Make a reference to GEOM_Object
1542   CORBA::String_var objStr = myGeometryGUI->getApp()->orb()->object_to_string( object );
1543   getDisplayer()->SetName( objStr.in() );
1544
1545   // Create wire from applayed object
1546   TopoDS_Shape anApplyedWire, aLastSegment;
1547   if ( !createShapes( object, anApplyedWire, aLastSegment ) )
1548     return;
1549
1550   // Build prs
1551   SALOME_Prs* aPrs = getDisplayer()->BuildPrs( anApplyedWire );
1552   if ( aPrs != 0 && !aPrs->IsNull() )
1553     GEOMBase_Helper::displayPreview( aPrs, append, update );
1554
1555   getDisplayer()->SetColor( Quantity_NOC_VIOLET );
1556   aPrs = getDisplayer()->BuildPrs( aLastSegment );
1557   if ( aPrs != 0 && !aPrs->IsNull() )
1558     GEOMBase_Helper::displayPreview( aPrs, append, update );
1559
1560   getDisplayer()->UnsetName();
1561
1562   // Enable activation of displayed objects
1563   getDisplayer()->SetToActivate( true );
1564 }
1565
1566 //================================================================
1567 // Function : createShapes
1568 // Purpose  : Create applyed wire, and last segment from entry object
1569 //================================================================
1570 bool EntityGUI_SketcherDlg::createShapes( GEOM::GEOM_Object_ptr theObject,
1571                                           TopoDS_Shape&         theApplyedWire,
1572                                           TopoDS_Shape&         theLastSegment )
1573 {
1574   TopoDS_Shape aShape;
1575   if ( !GEOMBase::GetShape( theObject, aShape ) ||
1576        aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX )
1577     return false;
1578
1579   if ( Group1Sel->isVisible()  && !Group1Sel->buttonApply->isEnabled()  ||
1580        Group1Spin->isVisible() && !Group1Spin->buttonApply->isEnabled() ||
1581        Group2Spin->isVisible() && !Group2Spin->buttonApply->isEnabled() ||
1582        Group3Spin->isVisible() && !Group3Spin->buttonApply->isEnabled() ||
1583        Group4Spin->isVisible() && !Group4Spin->buttonApply->isEnabled() )
1584   {
1585      theApplyedWire = aShape;
1586      return true;
1587   }
1588
1589   BRepBuilderAPI_MakeWire aBuilder;
1590   TopExp_Explorer anExp( aShape, TopAbs_EDGE );
1591   while( 1 )
1592   {
1593     TopoDS_Shape anEdge = anExp.Current();
1594     anExp.Next();
1595     if ( anExp.More() ) // i.e. non-last edge
1596       aBuilder.Add( TopoDS::Edge( anEdge ) );
1597     else
1598     {
1599       theLastSegment = anEdge;
1600       break;
1601     }
1602   }
1603
1604   if ( aBuilder.IsDone() )
1605     theApplyedWire = aBuilder.Shape();
1606
1607   return true;
1608 }
1609
1610 //=================================================================================
1611 // function : keyPressEvent()
1612 // purpose  :
1613 //=================================================================================
1614 void  EntityGUI_SketcherDlg::keyPressEvent( QKeyEvent* e )
1615 {
1616   QDialog::keyPressEvent( e );
1617   if ( e->isAccepted() )
1618     return;
1619
1620   if ( e->key() == Key_F1 )
1621     {
1622       e->accept();
1623       ClickOnHelp();
1624     }
1625 }