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