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