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