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