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