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