Salome HOME
e7e6182d646636fcf7716b93ebcd6f9aedd89957
[modules/geom.git] / src / EntityGUI / EntityGUI_3DSketcherDlg.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18
19 // GEOM GEOMGUI : GUI for Geometry component
20 // File   : EntityGUI_3DSketcherDlg.cxx
21 // Author : DMV, OCN
22
23 #include <cmath>
24 #include <string>
25 #include <boost/lexical_cast.hpp>
26
27 #include "EntityGUI_3DSketcherDlg.h"
28 #include "EntityGUI_Widgets.h"
29 #include <SalomeApp_DoubleSpinBox.h>
30
31 #include <GEOMBase.h>
32 #include <GeometryGUI.h>
33 #include <Precision.hxx>
34
35 #include <DlgRef.h>
36 #include <SUIT_Session.h>
37 #include <SUIT_Desktop.h>
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_ResourceMgr.h>
40 #include <SUIT_ViewWindow.h>
41 #include <SUIT_ViewManager.h>
42 #include <SOCC_Prs.h>
43 #include <SOCC_ViewModel.h>
44 #include <SalomeApp_Application.h>
45 #include <LightApp_Application.h>
46 #include <LightApp_SelectionMgr.h>
47
48 #include <SalomeApp_Tools.h>
49
50 //OCCT includes
51 #include <TopoDS.hxx>
52 #include <TColStd_IndexedMapOfInteger.hxx>
53 #include <BRepBuilderAPI_MakeVertex.hxx>
54 #include <BRepBuilderAPI_MakePolygon.hxx>
55 #include <BRepBuilderAPI_MakeEdge.hxx>
56
57 #include <AIS_Trihedron.hxx>
58 #include <AIS_AngleDimension.hxx>
59 #include <AIS_LengthDimension.hxx>
60 #include <AIS_Drawer.hxx>
61 #include <Geom_Axis2Placement.hxx>
62 #include <Geom_Plane.hxx>
63 #include <SelectMgr_Selection.hxx>
64 #include <gce_MakePln.hxx>
65 #include <Prs3d_AngleAspect.hxx>
66 #include <Prs3d_LineAspect.hxx>
67 #include <Prs3d_LengthAspect.hxx>
68 #include <Prs3d_TextAspect.hxx>
69 #include <Prs3d_Presentation.hxx>
70 #include <Prs3d_Text.hxx>
71
72 #include <Graphic3d_VerticalTextAlignment.hxx>
73 #include <Graphic3d_HorizontalTextAlignment.hxx>
74 #include <Graphic3d_AspectText3d.hxx>
75
76 #include <Font_FontAspect.hxx>
77
78 // This include must be *AFTER* SOCC_ViewModel.h because
79 // of the constant ROTATE which is a #define in
80 // GEOMImpl_Types.hxx and an enum in SOCC_ViewModel.h
81 #include <GEOMImpl_Types.hxx>
82
83 // TODO
84 //
85 // Avoid duplication of angle coordinates in cylindrical mode
86 // Check spherical mode in absolute
87
88 enum
89 {
90   OXY,
91   OYZ,
92   OXZ
93 };
94
95 class Locker
96 {
97 public:
98   Locker(bool& l) : myLock(l) { myLock = true;  }
99   ~Locker()                   { myLock = false; }
100 private:
101   bool& myLock;
102 };
103
104 DEFINE_STANDARD_HANDLE(AIS_Text, AIS_InteractiveObject)
105
106 class AIS_Text:public AIS_InteractiveObject
107 {
108 public:
109   // CASCADE RTTI
110   DEFINE_STANDARD_RTTI(AIS_Text );
111
112   AIS_Text(){};
113
114   AIS_Text
115     (
116       const TCollection_ExtendedString& , const gp_Pnt& ,
117       Quantity_Color color,
118       Standard_Integer aHJust,
119       Standard_Integer aVJust ,
120       Standard_Real Angle ,
121       Standard_Boolean Zoom ,
122       Standard_Real  Height,
123       Font_FontAspect FontAspect,
124       Standard_CString Font
125     );
126
127 private:
128
129   void Compute (  const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
130                   const Handle(Prs3d_Presentation)& aPresentation,
131                   const Standard_Integer aMode);
132
133   void ComputeSelection (  const Handle(SelectMgr_Selection)& aSelection,
134                            const Standard_Integer aMode){} ;
135
136 protected:
137   TCollection_ExtendedString          aText;
138   gp_Pnt                              aPosition;
139   Standard_Real                       Red;
140   Standard_Real                       Green;
141   Standard_Real                       Blue;
142   Standard_Real                       aAngle;
143   Standard_Real                       aHeight;
144   Standard_Boolean                    aZoomable;
145   Quantity_Color                      aColor;
146   Standard_CString                    aFont;
147   Font_FontAspect                      aFontAspect;
148   Graphic3d_HorizontalTextAlignment   aHJustification;
149   Graphic3d_VerticalTextAlignment     aVJustification;
150 };
151
152 IMPLEMENT_STANDARD_HANDLE(AIS_Text, AIS_InteractiveObject)
153 IMPLEMENT_STANDARD_RTTIEXT(AIS_Text, AIS_InteractiveObject)
154
155 AIS_Text::AIS_Text( const TCollection_ExtendedString& text, const gp_Pnt& position,
156                           Quantity_Color    color       = Quantity_NOC_YELLOW,
157                           Standard_Integer  aHJust      = Graphic3d_HTA_LEFT,
158                           Standard_Integer  aVJust      = Graphic3d_VTA_BOTTOM,
159                           Standard_Real     angle       = 0.0 ,
160                           Standard_Boolean  zoomable    = Standard_False,
161                           Standard_Real     height      = 16.,
162                           Font_FontAspect    fontAspect  = Font_FA_Regular,
163                           Standard_CString  font        = "Courier")
164 {
165   aText           = text;
166   aPosition       = position;
167   aHJustification = Graphic3d_HorizontalTextAlignment(aHJust);
168   aVJustification = Graphic3d_VerticalTextAlignment(aVJust);
169   aAngle          = angle;
170   aZoomable       = zoomable;
171   aHeight         = height;
172   aColor          = color;
173   aFontAspect     = fontAspect;
174   aFont           = font;
175 };
176
177 void AIS_Text::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
178                           const Handle(Prs3d_Presentation)& aPresentation,
179                           const Standard_Integer aMode)
180 {
181
182   aPresentation->Clear();
183
184   Handle_Prs3d_TextAspect asp = myDrawer->TextAspect();
185
186   asp->SetFont(aFont);
187   asp->SetColor(aColor);
188   asp->SetHeight(aHeight); // I am changing the myHeight value
189
190   asp->SetHorizontalJustification(aHJustification);
191   asp->SetVerticalJustification(aVJustification);
192   asp->Aspect()->SetTextZoomable(aZoomable);
193   asp->Aspect()->SetTextAngle(aAngle);
194   asp->Aspect()->SetTextFontAspect(aFontAspect);
195   Prs3d_Text::Draw(aPresentation, asp, aText, aPosition);
196 };
197
198 bool isSame (double d1, double d2)
199
200   return Abs(d1 - d2) <= Precision::Confusion();
201 }
202
203 //=================================================================================
204 // class    : EntityGUI_3DSketcherDlg()
205 // purpose  : Constructs a EntityGUI_3DSketcherDlg which is a child of 'parent', with the
206 //            name 'name' and widget flags set to 'f'.
207 //            The dialog will by default be modeless, unless you set 'modal' to
208 //            TRUE to construct a modal dialog.
209 //=================================================================================
210 EntityGUI_3DSketcherDlg::EntityGUI_3DSketcherDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
211                                                   bool modal, Qt::WindowFlags fl,
212                                                   const double lineWidth)
213   : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
214     myMode(-1),
215     myOK(false),
216     myLineWidth(lineWidth),
217     myGeometryGUI(theGeometryGUI),
218     myLengthIORedoList()
219 {
220   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
221   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_UNDO")));
222   QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_REDO")));
223   QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICO_3DSKETCH")));
224
225   setWindowTitle(tr("GEOM_3DSKETCHER_TITLE"));
226
227   /***************************************************************/
228
229   mainFrame()->GroupConstructors->setTitle(tr("GEOM_3DSKETCHER"));
230   mainFrame()->RadioButton1->setIcon(image3);;
231   mainFrame()->RadioButton2->close();
232   mainFrame()->RadioButton3->close();
233
234   GroupType = new EntityGUI_Type(centralWidget());
235   GroupType->GroupType2->setTitle(tr("GEOM_COORDINATES_TYPE"));
236   GroupType->GroupType1->setTitle(tr("GEOM_MODE"));
237   GroupType->RadioButton1->setText(tr("GEOM_SKETCHER_ABS"));
238   GroupType->RadioButton2->setText(tr("GEOM_SKETCHER_REL"));
239   GroupType->RadioButton3->setText(tr("(X,Y,Z)"));
240   GroupType->RadioButton4->setText(tr("GEOM_ANGLES"));
241  
242   myTypeGroup1 = new QButtonGroup(this);
243   myTypeGroup1->setExclusive(true);
244   myTypeGroup1->addButton(GroupType->RadioButton1, 0);
245   myTypeGroup1->addButton(GroupType->RadioButton2, 1);
246   
247   myTypeGroup2 = new QButtonGroup(this);
248   myTypeGroup2->setExclusive(true);
249   myTypeGroup2->addButton(GroupType->RadioButton3, 0);
250   myTypeGroup2->addButton(GroupType->RadioButton4, 1);
251
252   Group3Spin = new EntityGUI_3Spin(centralWidget());
253   Group3Spin->GroupBox1->setTitle(tr("GEOM_SKETCHER_VALUES"));
254   Group3Spin->buttonApply->setText(tr("GEOM_SKETCHER_APPLY"));
255   Group3Spin->buttonUndo->setIcon(image1);
256   Group3Spin->buttonRedo->setIcon(image2);
257   Group3Spin->TextLabel1->setText(tr("GEOM_SKETCHER_X2"));
258   Group3Spin->TextLabel2->setText(tr("GEOM_SKETCHER_Y2"));
259   Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_Z2"));
260
261   GroupAngles = new EntityGUI_Angles(centralWidget());
262   GroupAngles->buttonApply->setText(tr("GEOM_SKETCHER_APPLY"));
263   GroupAngles->buttonUndo->setIcon(image1);
264   GroupAngles->buttonRedo->setIcon(image2);
265   GroupAngles->TextLabel1->setText(tr("GEOM_LENGTH"));
266   GroupAngles->TextLabel2->setText(tr("GEOM_ANGLE")); 
267   GroupAngles->checkBox  ->setText(tr("GEOM_ANGLE_2"));
268   GroupAngles->checkBox_2->setText(tr("GEOM_HEIGHT"));
269
270   GroupControls = new EntityGUI_Controls(centralWidget());
271   GroupControls->GroupBox1->setTitle(tr("GEOM_CONTROLS"));
272   GroupControls->CheckBox1->setText(tr("GEOM_SHOW_LENGTH")); 
273   GroupControls->CheckBox2->setText(tr("GEOM_SHOW_ANGLE"));
274   GroupControls->CheckBox3->setText(tr("GEOM_SHOW_POINTS_COORD"));
275   GroupControls->lineEdit_1->setReadOnly(true);
276   GroupControls->lineEdit_2->setReadOnly(true);
277   GroupControls->lineEdit_3->setReadOnly(true);
278   GroupControls->lineEdit_4->setReadOnly(true);
279   GroupControls->lineEdit_5->setReadOnly(true);
280   GroupControls->lineEdit_6->setReadOnly(true);
281   GroupControls->label_1->setText(tr("X:"));
282   GroupControls->label_2->setText(tr("Y:"));
283   GroupControls->label_3->setText(tr("Z:"));
284   GroupControls->label_4->setText(tr("X:"));
285   GroupControls->label_5->setText(tr("Y:"));
286   GroupControls->label_6->setText(tr("Z:"));
287   GroupControls->label_7->setText(tr("GEOM_START"));
288   GroupControls->label_8->setText(tr("GEOM_END"));
289
290   buttonOk()->setText(tr("GEOM_BUT_END_SKETCH"));
291   buttonApply()->setText(tr("GEOM_BUT_CLOSE_SKETCH"));
292
293   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
294   layout->setMargin(0); layout->setSpacing(6);
295   layout->addWidget(GroupType);
296   layout->addWidget(Group3Spin);
297   layout->addWidget(GroupAngles);
298   layout->addWidget(GroupControls);
299
300   setHelpFileName("create_3dsketcher_page.html");
301
302   resize(100,100);
303   Init();
304 }
305
306 //=================================================================================
307 // function : ~EntityGUI_3DSketcherDlg()
308 // purpose  : Destroys the object and frees any allocated resources
309 //=================================================================================
310 EntityGUI_3DSketcherDlg::~EntityGUI_3DSketcherDlg()
311 {
312   myGeomGUI->SetActiveDialogBox(0);
313 }
314
315 //=================================================================================
316 // function : Init()
317 // purpose  :
318 //=================================================================================
319 void EntityGUI_3DSketcherDlg::Init()
320 {
321   myOK = false;
322   myOrientation = OXY;
323   myPrsType = prsType();
324
325   SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
326   myAnglePrs = dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
327   myLengthPrs = dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
328   myTextPrs = dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
329
330   localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
331
332   /* Get setting of step value from file configuration */
333   double step = SUIT_Session::session()->resourceMgr()->doubleValue("Geometry", "SettingsGeomStep", 100.0);
334
335   /* min, max, step and decimals for spin boxes */
336   initSpinBox(Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision");
337   initSpinBox(Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision");
338   initSpinBox(Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision");
339
340   initSpinBox(GroupAngles->SpinBox_DA , -360.0, 360.0, step, "angular_precision");
341   initSpinBox(GroupAngles->SpinBox_DA2,  -90.0,  90.0, step, "angular_precision");
342   initSpinBox(GroupAngles->SpinBox_DL , COORD_MIN, COORD_MAX, step, "length_precision");
343   initSpinBox(GroupAngles->SpinBox_DH , COORD_MIN, COORD_MAX, step, "length_precision");
344
345   Group3Spin->SpinBox_DX->setValue(0.0);
346   Group3Spin->SpinBox_DY->setValue(0.0);
347   Group3Spin->SpinBox_DZ->setValue(0.0);
348
349   GroupAngles->SpinBox_DA->setValue(0.0);
350   GroupAngles->SpinBox_DA2->setValue(0.0);
351   GroupAngles->SpinBox_DL->setValue(0.0);
352   GroupAngles->SpinBox_DH->setValue(0.0);
353
354   GroupAngles->radioButton_1->setChecked(true);
355   GroupAngles->checkBox->setChecked(false);
356   GroupAngles->checkBox_2->setChecked(false);
357   GroupAngles->SpinBox_DA2->setEnabled(false);
358   GroupAngles->SpinBox_DH->setEnabled(false);
359
360   GroupControls->CheckBox1->setChecked(true);
361   GroupControls->CheckBox2->setChecked(true);
362   GroupControls->CheckBox3->setChecked(true);
363   
364   isLengthVisible = true;
365   isAngleVisible = true;
366
367   GroupAngles->hide();
368
369   /* signals and slots connections */
370   connect(buttonOk(),     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
371   connect(buttonApply(),  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
372
373   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
374
375   connect(Group3Spin->buttonApply,   SIGNAL(clicked()), this, SLOT(ClickOnAddPoint()));
376   connect(Group3Spin->buttonUndo,    SIGNAL(clicked()), this, SLOT(ClickOnUndo()));
377   connect(Group3Spin->buttonRedo,    SIGNAL(clicked()), this, SLOT(ClickOnRedo())) ;
378
379   connect(GroupAngles->buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnAddPoint()));
380   connect(GroupAngles->buttonUndo,   SIGNAL(clicked()), this, SLOT(ClickOnUndo()));
381   connect(GroupAngles->buttonRedo,   SIGNAL(clicked()), this, SLOT(ClickOnRedo())) ;
382
383   connect(myTypeGroup1, SIGNAL(buttonClicked(int)),  this, SLOT(TypeClicked(int)));
384   connect(myTypeGroup2, SIGNAL(buttonClicked(int)),  this, SLOT(TypeClicked(int)));
385
386   connect(Group3Spin->SpinBox_DX,       SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
387   connect(Group3Spin->SpinBox_DY,       SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
388   connect(Group3Spin->SpinBox_DZ,       SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
389
390   connect(GroupAngles->SpinBox_DA,      SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
391   connect(GroupAngles->SpinBox_DA2,     SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
392   connect(GroupAngles->SpinBox_DL,      SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
393   connect(GroupAngles->SpinBox_DH,      SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
394
395   connect(GroupAngles->radioButton_1,   SIGNAL(clicked (bool)), this, SLOT(ButtonClicked(bool))) ;
396   connect(GroupAngles->radioButton_2,   SIGNAL(clicked (bool)), this, SLOT(ButtonClicked(bool))) ;
397   connect(GroupAngles->radioButton_3,   SIGNAL(clicked (bool)), this, SLOT(ButtonClicked(bool))) ;
398
399   connect(GroupAngles->checkBox,        SIGNAL(clicked (bool)), this, SLOT(BoxChecked (bool))) ;
400   connect(GroupAngles->checkBox_2,      SIGNAL(clicked (bool)), this, SLOT(BoxChecked (bool))) ;
401   connect(GroupControls->CheckBox1,     SIGNAL(clicked (bool)), this, SLOT(BoxChecked (bool))) ;
402   connect(GroupControls->CheckBox2,     SIGNAL(clicked (bool)), this, SLOT(BoxChecked (bool))) ;
403   connect(GroupControls->CheckBox3,     SIGNAL(clicked (bool)), this, SLOT(BoxChecked (bool))) ;
404
405   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
406
407   connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
408   connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()),        this, SLOT(ClickOnCancel()));
409
410   initName(tr("GEOM_3DSKETCHER"));
411   
412   GroupControls->CheckBox3->click();
413
414   UpdateButtonsState();
415   
416   myMode      = 0;
417   myCoordType = 0;
418   
419   GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
420 }
421
422 //=================================================================================
423 // function : TypeClicked()
424 // purpose  : Radio button management
425 //=================================================================================
426 void EntityGUI_3DSketcherDlg::TypeClicked (int id)
427 {
428   QButtonGroup* send = (QButtonGroup*) sender();
429   
430   int coordType = myCoordType;
431   int mode      = myMode;
432   
433   if (send == myTypeGroup1)
434   {
435     if(id == myMode) return;
436     mode = id;   
437   }
438   else if (send == myTypeGroup2)
439   {
440     if (id == myCoordType) return;
441     coordType = id;  
442   }
443   
444   GroupAngles->hide();
445   Group3Spin->show();
446
447   bool blocked = Group3Spin->SpinBox_DX->signalsBlocked();
448   Group3Spin->SpinBox_DX->blockSignals(true);
449   Group3Spin->SpinBox_DY->blockSignals(true);
450   Group3Spin->SpinBox_DZ->blockSignals(true);
451
452   // Get setting of step value from file configuration
453   XYZ xyz = getLastPoint();
454   bool okx, oky, okz;
455   Group3Spin->SpinBox_DX->text().toDouble(&okx);
456   Group3Spin->SpinBox_DY->text().toDouble(&oky);
457   Group3Spin->SpinBox_DZ->text().toDouble(&okz);
458
459   if (coordType == 0)  // Cartesian coordinates
460   {
461     if (mode == 0) {   // XYZ
462       Group3Spin->TextLabel1->setText(tr("GEOM_SKETCHER_X2"));
463       Group3Spin->TextLabel2->setText(tr("GEOM_SKETCHER_Y2"));
464       Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_Z2"));
465       if (myCoordType == 0 && myMode == 1)
466       {
467         if (okx) Group3Spin->SpinBox_DX->setValue(xyz.x + Group3Spin->SpinBox_DX->value());
468         if (oky) Group3Spin->SpinBox_DY->setValue(xyz.y + Group3Spin->SpinBox_DY->value());
469         if (okz) Group3Spin->SpinBox_DZ->setValue(xyz.z + Group3Spin->SpinBox_DZ->value());
470       }
471       Group3Spin->buttonApply->setFocus();
472     }
473     else if (mode == 1) { // DXDYDZ
474       Group3Spin->TextLabel1->setText(tr("GEOM_SKETCHER_DX2"));
475       Group3Spin->TextLabel2->setText(tr("GEOM_SKETCHER_DY2"));
476       Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_DZ2"));
477       if (myCoordType == 0 && myMode == 0)
478       {
479         if (okx) Group3Spin->SpinBox_DX->setValue(Group3Spin->SpinBox_DX->value() - xyz.x);
480         if (oky) Group3Spin->SpinBox_DY->setValue(Group3Spin->SpinBox_DY->value() - xyz.y);
481         if (okz) Group3Spin->SpinBox_DZ->setValue(Group3Spin->SpinBox_DZ->value() - xyz.z);
482       }
483       Group3Spin->buttonApply->setFocus();
484     }
485   }
486   else if (coordType == 1) // Angles and Length
487   {
488     Group3Spin->hide();
489     GroupAngles->show();
490     GroupAngles->buttonApply->setFocus();
491   }
492
493   Group3Spin->SpinBox_DX->blockSignals(blocked);
494   Group3Spin->SpinBox_DY->blockSignals(blocked);
495   Group3Spin->SpinBox_DZ->blockSignals(blocked);
496
497   myMode = mode;
498   myCoordType = coordType;
499
500   updateGeometry();
501   resize(minimumSizeHint());
502
503   GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
504 }
505
506 //=================================================================================
507 // function : ClickOnAddPoint()
508 // purpose  : called when the point coordinates is Applyed
509 //=================================================================================
510 void EntityGUI_3DSketcherDlg::ClickOnAddPoint()
511
512   QString msg;
513   if (!isValid(msg)) {
514     showError(msg);
515     return;
516   }
517   
518   myPrsType   = prsType();
519   
520 //   if(myMode == 1)
521     displayDimensions( /*store = */true);
522
523   myPointsList.append(getCurrentPoint());
524   myRedoList.clear();
525   myLengthIORedoList.Clear();
526   myAngleIORedoList.Clear();
527
528   if (myCoordType == 0 && myMode == 1)     // RELATIVE CARTESIAN COORDINATES
529   {
530     Group3Spin->SpinBox_DX->setValue(0.0);
531     Group3Spin->SpinBox_DY->setValue(0.0);
532     Group3Spin->SpinBox_DZ->setValue(0.0);
533   }
534   else if (myCoordType == 1 && myMode == 1) // RELATIVE ANGULAR COORDINATES
535   {
536     GroupAngles->SpinBox_DA->setValue(0.0);
537     GroupAngles->SpinBox_DL->setValue(0.0);
538     GroupAngles->SpinBox_DA2->setValue(0.0);
539   }
540   
541   UpdatePointCoordinates();
542     
543   UpdateButtonsState();
544   GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
545 }
546
547 //=================================================================================
548 // function : UpdateButtonsState()
549 // purpose  :
550 //=================================================================================
551 void EntityGUI_3DSketcherDlg::UpdateButtonsState()
552 {
553   if (myPointsList.count() == 0) 
554   {
555     GroupType->RadioButton1->click();
556     GroupType->RadioButton3->click();
557   }
558   GroupType->RadioButton2->setEnabled(myPointsList.count() > 0);
559 //   GroupType->RadioButton3->setEnabled(myPointsList.count() > 0);
560 //   GroupType->RadioButton4->setEnabled(myPointsList.count() > 0);
561   Group3Spin->buttonUndo->setEnabled(myPointsList.count() > 0);
562   Group3Spin->buttonRedo->setEnabled(myRedoList.count() > 0);
563   GroupAngles->buttonUndo->setEnabled(myPointsList.count() > 0);
564   GroupAngles->buttonRedo->setEnabled(myRedoList.count() > 0);
565 }
566
567 //=================================================================================
568 // function : UpdatePointCoordinates()
569 // purpose  :Update point coordinates in the control groupbox
570 //=================================================================================
571 void EntityGUI_3DSketcherDlg::UpdatePointCoordinates()
572 {
573   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
574   int aPrecision = resMgr->integerValue("Geometry", "length_precision", 6);
575   
576   if (myPointsList.count() == 0)
577   {
578     GroupControls->lineEdit_1->setText("");
579     GroupControls->lineEdit_2->setText("");
580     GroupControls->lineEdit_3->setText("");
581     
582     GroupControls->lineEdit_4->setText("");
583     GroupControls->lineEdit_5->setText("");
584     GroupControls->lineEdit_6->setText("");
585   }
586   else if (myPointsList.count() == 1)
587   {
588     GroupControls->lineEdit_1->setText(DlgRef::PrintDoubleValue(getLastPoint().x, aPrecision));
589     GroupControls->lineEdit_2->setText(DlgRef::PrintDoubleValue(getLastPoint().y, aPrecision));
590     GroupControls->lineEdit_3->setText(DlgRef::PrintDoubleValue(getLastPoint().z, aPrecision));
591     
592     GroupControls->lineEdit_4->setText("");
593     GroupControls->lineEdit_5->setText("");
594     GroupControls->lineEdit_6->setText("");
595   }
596   else
597   {
598     GroupControls->lineEdit_4->setText(DlgRef::PrintDoubleValue(getLastPoint().x, aPrecision));
599     GroupControls->lineEdit_5->setText(DlgRef::PrintDoubleValue(getLastPoint().y, aPrecision));
600     GroupControls->lineEdit_6->setText(DlgRef::PrintDoubleValue(getLastPoint().z, aPrecision));
601   }
602   
603 }
604
605 //=================================================================================
606 // function : ClickOnUndo()
607 // purpose  :
608 //=================================================================================
609 void EntityGUI_3DSketcherDlg::ClickOnUndo()
610 {
611   if (myPointsList.count() > 0) {
612     
613     myRedoList.append(myPointsList.last());
614
615     // Erase dimensions presentations
616     SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
617     ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myLengthPrs, true);
618     ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myAnglePrs, true);
619     
620     removeLastIOFromPrs();
621
622     // Display modified presentation
623     if (isLengthVisible)
624       ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myLengthPrs);
625     if (isAngleVisible)
626       ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myAnglePrs);
627     
628     // Remove last point from list
629     myPointsList.removeLast();
630     GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
631     UpdateButtonsState();
632     
633     // Update of point coordinates in the control groupbox
634     UpdatePointCoordinates();
635
636     updateViewer();
637   }
638 }
639
640 //=================================================================================
641 // function : ClickOnRedo()
642 // purpose  :
643 //=================================================================================
644 void EntityGUI_3DSketcherDlg::ClickOnRedo()
645 {
646   if (myRedoList.count() > 0) {
647     
648     myPointsList.append(myRedoList.last());
649
650     // Erase dimensions presentations
651     SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
652     ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myLengthPrs, true);
653     ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myAnglePrs, true);
654     
655     restoreLastIOToPrs();
656
657     // Display modified presentation
658     if (isLengthVisible)
659       ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myLengthPrs);
660     if (isAngleVisible)
661       ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myAnglePrs);
662     
663     // Remove last point from redo list
664     myRedoList.removeLast();
665     GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
666     UpdateButtonsState();
667     
668     // Update of point coordinates in the control groupbox
669     UpdatePointCoordinates();
670
671     updateViewer();
672   }
673 }
674
675 //=================================================================================
676 // function : removeLastIO()
677 // purpose  :
678 //=================================================================================
679 void EntityGUI_3DSketcherDlg::removeLastIOFromPrs ()
680 {
681   AIS_ListOfInteractive anIOList;
682   XYZ Last = getLastPoint();
683   
684   for (int l = 0; l<Last.L; l++)
685   {
686     myLengthPrs->GetObjects(anIOList);
687     myLengthIORedoList.Prepend(anIOList.First());  // Store last prepended Length IO in redo list
688     myLengthPrs->RemoveFirst();                    // Remove it from myLengthPrs
689   }
690   for (int a = 0; a<Last.A; a++)
691   {
692     myAnglePrs->GetObjects(anIOList);
693     myAngleIORedoList.Prepend(anIOList.First());  // Store last prepended Angle IO in redo list
694     myAnglePrs->RemoveFirst();                    // Remove it from myAnglePrs
695   }
696 }
697
698 //=================================================================================
699 // function : restoreLastIO()
700 // purpose  :
701 //=================================================================================
702 void EntityGUI_3DSketcherDlg::restoreLastIOToPrs ()
703 {
704   XYZ LastDeleted = myRedoList.last();
705   
706   for (int l = 0; l<LastDeleted.L; l++)
707   {
708     myLengthPrs->PrependObject(myLengthIORedoList.First()); // Restore last removed IO
709     myLengthIORedoList.RemoveFirst();                       // Remove it from redo list
710   } 
711   for (int a = 0; a<LastDeleted.A; a++)
712   {
713     myAnglePrs->PrependObject(myAngleIORedoList.First());  // Restore last removed IO
714     myAngleIORedoList.RemoveFirst();                       // Remove it from redo list
715   }
716 }
717
718 //=================================================================================
719 // function : SelectionIntoArgument()
720 // purpose  : Called when selection as changed
721 //=================================================================================
722 void EntityGUI_3DSketcherDlg::SelectionIntoArgument()
723 {
724   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
725   SALOME_ListIO aSelList;
726   aSelMgr->selectedObjects(aSelList);
727
728   int nbSel = aSelList.Extent();
729   if (nbSel == 1) {
730     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First());
731     if (!CORBA::is_nil(aSelectedObject)) {
732       TopoDS_Shape aShape;
733       if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE)) {
734         // Explore the shape if its a local selection
735         TColStd_IndexedMapOfInteger aMap;
736         aSelMgr->GetIndexes(aSelList.First(), aMap);
737         if (aMap.Extent() == 1) {
738           int anIndex = aMap(1);
739           GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
740           aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
741         }
742       }
743       bool isOk = true;
744       if (aShape.ShapeType() != TopAbs_VERTEX)
745         isOk = GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_VERTEX);
746       if (isOk) {
747         gp_Pnt aPnt;
748         if (GEOMBase::VertexToPoint(aShape, aPnt)) {
749           // set coordinates to the Spin Boxes
750           double aX, aY, aZ;
751           aX = aPnt.X();
752           aY = aPnt.Y();
753           aZ = aPnt.Z();
754           bool blocked = Group3Spin->SpinBox_DX->signalsBlocked();
755           Group3Spin->SpinBox_DX->blockSignals(true);
756           Group3Spin->SpinBox_DY->blockSignals(true);
757           Group3Spin->SpinBox_DZ->blockSignals(true);
758           if (GroupType->RadioButton1->isChecked()) {
759             Group3Spin->SpinBox_DX->setValue(aX);
760             Group3Spin->SpinBox_DY->setValue(aY);
761             Group3Spin->SpinBox_DZ->setValue(aZ);
762           }
763           else if (GroupType->RadioButton2->isChecked()) {
764             XYZ xyz = getLastPoint();
765             Group3Spin->SpinBox_DX->setValue(aX - xyz.x);
766             Group3Spin->SpinBox_DY->setValue(aY - xyz.y);
767             Group3Spin->SpinBox_DZ->setValue(aZ - xyz.z);
768           }
769           Group3Spin->SpinBox_DX->blockSignals(blocked);
770           Group3Spin->SpinBox_DY->blockSignals(blocked);
771           Group3Spin->SpinBox_DZ->blockSignals(blocked);
772         }
773       }
774     }
775   }
776   GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
777 }
778
779 //=================================================================================
780 // function : DeactivateActiveDialog()
781 // purpose  :
782 //=================================================================================
783 void EntityGUI_3DSketcherDlg::DeactivateActiveDialog()
784 {
785   setEnabled(false);
786   globalSelection();
787   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
788   myGeomGUI->SetActiveDialogBox(0);
789 }
790
791 //=================================================================================
792 // function : ActivateThisDialog()
793 // purpose  :
794 //=================================================================================
795 void EntityGUI_3DSketcherDlg::ActivateThisDialog()
796 {
797   myGeomGUI->EmitSignalDeactivateDialog();
798   setEnabled(true);
799   myGeomGUI->SetActiveDialogBox(this);
800
801   connect(myGeomGUI->getApp()->selectionMgr(),
802           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
803
804   localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
805   GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
806 }
807
808 //=================================================================================
809 // function : ValueChangedInSpinBox()
810 // purpose  :
811 //=================================================================================
812 void EntityGUI_3DSketcherDlg::ValueChangedInSpinBox (double newValue)
813 {
814   GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
815 }
816
817 //=================================================================================
818 // function : BoxChecked()
819 // purpose  : ChecBoxes management
820 //=================================================================================
821 void EntityGUI_3DSketcherDlg::BoxChecked (bool checked)
822 {
823   QCheckBox* send = (QCheckBox*) sender();
824   SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
825
826   if (send == GroupAngles->checkBox)
827   {
828     GroupAngles->SpinBox_DA2->setEnabled(checked);
829     if(checked)
830     {
831       GroupAngles->SpinBox_DH->setEnabled(false);
832       GroupAngles->checkBox_2->setChecked(false);
833     }
834   }
835   else if (send == GroupAngles->checkBox_2)
836   {
837     GroupAngles->SpinBox_DH->setEnabled(checked);
838     if(checked)
839     {
840       GroupAngles->SpinBox_DA2->setEnabled(false);
841       GroupAngles->checkBox->setChecked(false);
842     }
843   }
844
845   else if (send == GroupControls->CheckBox1)
846   {
847     ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myLengthPrs, true);
848     if (checked){
849       ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myLengthPrs);
850       isLengthVisible=true;
851     }
852     else
853       isLengthVisible=false;
854   }
855   else if (send == GroupControls->CheckBox2)
856   {
857     ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myAnglePrs, true);
858     if (checked)
859     {
860       ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myAnglePrs);
861       isAngleVisible=true;
862     }
863     else
864       isAngleVisible=false;
865   }
866   else if (send == GroupControls->CheckBox3)
867   {
868     GroupControls->lineEdit_1->setVisible(checked);
869     GroupControls->lineEdit_2->setVisible(checked);
870     GroupControls->lineEdit_3->setVisible(checked);
871     GroupControls->lineEdit_4->setVisible(checked);
872     GroupControls->lineEdit_5->setVisible(checked);
873     GroupControls->lineEdit_6->setVisible(checked);
874     
875     GroupControls->label_1->setVisible(checked);
876     GroupControls->label_2->setVisible(checked);
877     GroupControls->label_3->setVisible(checked);
878     GroupControls->label_4->setVisible(checked);
879     GroupControls->label_5->setVisible(checked);
880     GroupControls->label_6->setVisible(checked);
881     GroupControls->label_7->setVisible(checked);
882     GroupControls->label_8->setVisible(checked);
883     
884     GroupControls->updateGeometry();
885     GroupControls->resize(minimumSizeHint());
886   } 
887
888   updateGeometry();
889   resize(minimumSizeHint());
890   
891   GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
892 }
893
894 //=================================================================================
895 // function : ButtonClicked()
896 // purpose  :
897 //=================================================================================
898 void EntityGUI_3DSketcherDlg::ButtonClicked (bool checked)
899 {
900   if (GroupAngles->radioButton_1->isChecked())
901     myOrientation = OXY;
902   else if (GroupAngles->radioButton_2->isChecked())
903     myOrientation = OYZ;
904   else
905     myOrientation = OXZ;
906
907   GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
908 }
909
910 //=================================================================================
911 // function : enterEvent()
912 // purpose  :
913 //=================================================================================
914 void EntityGUI_3DSketcherDlg::enterEvent (QEvent*)
915 {
916   if (!mainFrame()->GroupConstructors->isEnabled())
917     ActivateThisDialog();
918 }
919
920 //=================================================================================
921 // function : createOperation
922 // purpose  :
923 //=================================================================================
924 GEOM::GEOM_IOperations_ptr EntityGUI_3DSketcherDlg::createOperation()
925 {
926   return getGeomEngine()->GetICurvesOperations(getStudyId());
927 }
928
929 //=================================================================================
930 // function : isValid
931 // purpose  :
932 //=================================================================================
933 bool EntityGUI_3DSketcherDlg::isValid (QString& msg)
934 {
935   bool ok = true;
936   ok = Group3Spin->SpinBox_DX->isValid(msg, !IsPreview()) && ok;
937   ok = Group3Spin->SpinBox_DY->isValid(msg, !IsPreview()) && ok;
938   ok = Group3Spin->SpinBox_DZ->isValid(msg, !IsPreview()) && ok;
939   return ok;
940 }
941
942 //=================================================================================
943 // function : execute
944 // purpose  :
945 //=================================================================================
946 bool EntityGUI_3DSketcherDlg::execute (ObjectList& objects)
947 {
948   //GEOM::ListOfDouble_var aCoordsArray = new GEOM::ListOfDouble;
949   //if (!myOK || myPointsList.size() == 0)
950   //  aCoordsArray->length((myPointsList.size()+1)*3);
951   //else
952   //  aCoordsArray->length(myPointsList.size()*3);
953
954   QStringList aCommands;
955   aCommands << "3DSketcher";
956   QStringList aParameters;
957
958   //int i = 0;
959   QList<XYZ>::const_iterator it;
960   for (it = myPointsList.begin(); it != myPointsList.end(); ++it) {
961     //aCoordsArray[i++] = (*it).x;
962     //aCoordsArray[i++] = (*it).y;
963     //aCoordsArray[i++] = (*it).z;
964     aCommands << (*it).command;
965     aParameters << (*it).params;
966   }
967
968   if (!myOK || myPointsList.size() == 0) {
969     XYZ xyz = getCurrentPoint();
970     //aCoordsArray[i++] = xyz.x;
971     //aCoordsArray[i++] = xyz.y;
972     //aCoordsArray[i++] = xyz.z;
973     aCommands << xyz.command;
974     aParameters << xyz.params;
975   }
976
977 //   MESSAGE("aCommands.last() = "<< aCommands.last().toStdString());
978   GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow(getOperation());
979   //GEOM::GEOM_Object_var anObj = anOper->Make3DSketcher(aCoordsArray);
980   GEOM::GEOM_Object_var anObj = anOper->Make3DSketcherCommand(aCommands.join(":").toLatin1().constData());
981
982   if (!anObj->_is_nil()) {
983     if (!IsPreview()) anObj->SetParameters(aParameters.join(":").toLatin1().constData());
984     objects.push_back(anObj._retn());
985   }
986
987   return true;
988 }
989
990 //=================================================================================
991 // function : SetDoubleSpinBoxStep()
992 // purpose  : Double spin box management
993 //=================================================================================
994 void EntityGUI_3DSketcherDlg::SetDoubleSpinBoxStep (double step)
995 {
996   Group3Spin->SpinBox_DX->setSingleStep(step);
997   Group3Spin->SpinBox_DY->setSingleStep(step);
998   Group3Spin->SpinBox_DZ->setSingleStep(step);
999   GroupAngles->SpinBox_DA ->setSingleStep(step);
1000   GroupAngles->SpinBox_DA2->setSingleStep(step);
1001   GroupAngles->SpinBox_DL->setSingleStep(step);
1002   GroupAngles->SpinBox_DH->setSingleStep(step);
1003 }
1004
1005 //=================================================================================
1006 // function : ClickOnOk()
1007 // purpose  :
1008 //=================================================================================
1009 void EntityGUI_3DSketcherDlg::ClickOnOk()
1010 {
1011   Locker lock(myOK);
1012
1013   if (!onAccept())
1014     return;
1015
1016   ClickOnCancel();
1017 }
1018
1019 //=================================================================================
1020 // function : ClickOnApply()
1021 // purpose  :
1022 //=================================================================================
1023 bool EntityGUI_3DSketcherDlg::ClickOnApply()
1024 {
1025   QString msg;
1026   if (!isValid(msg)) {
1027     showError(msg);
1028     return false;
1029   }
1030
1031   if (myPointsList.count() > 0)
1032     myPointsList.append(myPointsList[0]);
1033
1034   Locker lock(myOK);
1035
1036   if (!onAccept())
1037     return false;
1038
1039   ClickOnCancel();
1040   return true;
1041 }
1042
1043 //=================================================================================
1044 // function : getLastPoint()
1045 // purpose  : return last points from list
1046 //=================================================================================
1047 EntityGUI_3DSketcherDlg::XYZ EntityGUI_3DSketcherDlg::getLastPoint() const
1048 {
1049   return myPointsList.count() > 0 ? myPointsList.last() : XYZ();
1050 }
1051
1052 //=================================================================================
1053 // function : getPenultimatePoint()
1054 // purpose  : return penultimate point from list
1055 //=================================================================================
1056 EntityGUI_3DSketcherDlg::XYZ EntityGUI_3DSketcherDlg::getPenultimatePoint() const
1057 {
1058   double size = myPointsList.count();
1059   return size > 1 ? myPointsList.at(size - 2) : XYZ();
1060 }
1061
1062 //=================================================================================
1063 // function : getCurrentPoint()
1064 // purpose  : returns current point
1065 //=================================================================================
1066 EntityGUI_3DSketcherDlg::XYZ EntityGUI_3DSketcherDlg::getCurrentPoint() const
1067 {
1068   XYZ xyz;
1069
1070   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1071   int aPrecision = resMgr->integerValue("Geometry", "length_precision", 7);
1072   
1073   bool spherical   = GroupAngles->checkBox->isChecked();
1074   bool cylindrical = GroupAngles->checkBox_2->isChecked();
1075
1076   if (myCoordType == 1) 
1077   {
1078     if (GroupAngles->radioButton_1->isChecked())
1079       xyz.command = "OXY";
1080     else if (GroupAngles->radioButton_2->isChecked())
1081       xyz.command = "OYZ";
1082     else
1083       xyz.command = "OXZ";
1084     
1085     if (cylindrical)       // Cylindrical coordinates (radius, angle, height)
1086       xyz.command += "C";
1087     else
1088       xyz.command += "S";  // Spherical coordinates (radius, angle1, angle2) --> polar if angle2 = 0
1089     
1090     if (myMode == 0)       // Absolute coordinates
1091       xyz.command += "A ";
1092     else if (myMode == 1)  // Relative coordinates
1093       xyz.command += "R ";
1094       
1095
1096     double anAngle  = GroupAngles->SpinBox_DA->value();
1097     double aLength  = GroupAngles->SpinBox_DL->value();
1098
1099     double anAngle2 = 0.0;
1100     QString da2 = "0";
1101     if (spherical) {       // Spherical coordinates (radius, angle1, angle2)
1102       anAngle2 = GroupAngles->SpinBox_DA2->value();
1103       da2 = GroupAngles->SpinBox_DA2->text();
1104     }
1105     
1106     double aHeight = 0.0;
1107     QString dh = "0";
1108     if (cylindrical) {
1109       aHeight = GroupAngles->SpinBox_DH->value();
1110       dh = GroupAngles->SpinBox_DH->text();
1111     }
1112
1113     xyz.command +=
1114       QString::number(anAngle, 'g', aPrecision) + " ";
1115     xyz.params =
1116       GroupAngles->SpinBox_DA->text() + ":"; 
1117     
1118     if(cylindrical)
1119     {
1120       xyz.command +=
1121         QString::number(aHeight, 'g', aPrecision) + " ";
1122       xyz.params +=
1123         dh + ":";
1124     }
1125     else                  // Spherical or polar coordinates
1126     {
1127       xyz.command +=
1128         QString::number(anAngle2, 'g', aPrecision) + " ";
1129       xyz.params +=
1130         dh + ":";
1131     }
1132     
1133     xyz.command +=
1134       QString::number(aLength, 'g', aPrecision);
1135     xyz.params +=
1136       GroupAngles->SpinBox_DL->text();
1137
1138       
1139     // Calculate point coordinates for preview
1140     anAngle  = anAngle * M_PI/180.0;
1141     anAngle2 = anAngle2 * M_PI/180.0;
1142     double aProjectedLength = aLength * cos(anAngle2);
1143     
1144     XYZ xyzP = getLastPoint();
1145     if (myMode == 0)
1146       xyzP.x=xyzP.y=xyzP.z=0.0; 
1147     if (GroupAngles->radioButton_1->isChecked()) // OXY
1148     {
1149       xyz.x = xyzP.x + aProjectedLength * cos(anAngle);
1150       xyz.y = xyzP.y + aProjectedLength * sin(anAngle);
1151       if (cylindrical)
1152         xyz.z = xyzP.z + aHeight;
1153       else
1154         xyz.z = xyzP.z + aLength * sin(anAngle2);
1155     }
1156     else if (GroupAngles->radioButton_2->isChecked()) // OYZ
1157     {
1158       xyz.y = xyzP.y + aProjectedLength * cos(anAngle);
1159       xyz.z = xyzP.z + aProjectedLength * sin(anAngle);
1160       if (cylindrical)
1161         xyz.x = xyzP.x + aHeight;
1162       else
1163         xyz.x = xyzP.x + aLength * sin(anAngle2);
1164     }
1165     else // OXZ
1166     {
1167       xyz.z = xyzP.z + aProjectedLength * sin(anAngle);
1168       xyz.x = xyzP.x + aProjectedLength * cos(anAngle);
1169       if (cylindrical)
1170         xyz.y = xyzP.y + aHeight;
1171       else
1172         xyz.y = xyzP.y + aLength * sin(anAngle2);
1173     }
1174   }
1175   else if(myCoordType == 0) {
1176     if (myMode == 0) { // XYZ
1177       xyz.x = Group3Spin->SpinBox_DX->value();
1178       xyz.y = Group3Spin->SpinBox_DY->value();
1179       xyz.z = Group3Spin->SpinBox_DZ->value();
1180       xyz.command = "TT ";
1181     }
1182     else { // DXDYDZ
1183       xyz = getLastPoint();
1184       xyz.x += Group3Spin->SpinBox_DX->value();
1185       xyz.y += Group3Spin->SpinBox_DY->value();
1186       xyz.z += Group3Spin->SpinBox_DZ->value();
1187       xyz.command = "T ";
1188     }
1189
1190     double aX  = Group3Spin->SpinBox_DX->value();
1191     double aY  = Group3Spin->SpinBox_DY->value();
1192     double aZ  = Group3Spin->SpinBox_DZ->value();
1193
1194     xyz.command +=
1195       QString::number(aX, 'g', aPrecision) + " " +
1196       QString::number(aY, 'g', aPrecision) + " " +
1197       QString::number(aZ, 'g', aPrecision);
1198     xyz.params =
1199       Group3Spin->SpinBox_DX->text() + ":" +
1200       Group3Spin->SpinBox_DY->text() + ":" +
1201       Group3Spin->SpinBox_DZ->text();
1202   }
1203   // Update point presentation type
1204   xyz.A = myPrsType.A;  // Number of angle diomensions
1205   xyz.L = myPrsType.L;  // Number of length dimensions
1206   
1207   return xyz;
1208 }
1209
1210
1211 //=================================================================================
1212 // function : getPresentationPlane()
1213 // purpose  : returns the suitable plane for right
1214 //            relative positioning of dimension presentations
1215 //=================================================================================
1216 gp_Dir EntityGUI_3DSketcherDlg::getPresentationPlane() const
1217
1218   bool withAngle = (myCoordType == 1);
1219   bool twoAngles = GroupAngles->checkBox->isChecked();
1220   
1221   XYZ Last    = getLastPoint();
1222   XYZ Current = getCurrentPoint();
1223   XYZ Penultimate = getPenultimatePoint();
1224   
1225   gp_Pnt P1 = gp_Pnt(Last.x,Last.y,Last.z);
1226   if (myMode == 0) // Absolute coordinates
1227     P1 = gp::Origin();
1228   
1229   gp_Pnt P2 = gp_Pnt(Current.x,Current.y,Current.z);
1230   gp_Pnt P3 = gp_Pnt(Penultimate.x,Penultimate.y,Penultimate.z);
1231   
1232   gp_Vec Vec1(P1,P2);
1233   gp_Vec Vec2(P1,P3);
1234   
1235   gp_Dir aNormal;                  // Normal defining the plane of the presentation 
1236   
1237   if (withAngle)                   // If one angle
1238   {
1239     // Transformation from the current coordinate system 
1240     // to the reference coordinate system
1241     gp_Trsf aTransform = toReferenceSystem (P1);
1242     gp_Dir N1 = gp::DZ();
1243     gp_Dir N2 = gp::DY();
1244     N1.Transform(aTransform);
1245     N2.Transform(aTransform);
1246     
1247     if (Vec1.CrossMagnitude(N1) > Precision::Confusion())
1248     {
1249       // The plane is orthogonal to the angle presentation plane 
1250       // and contains the current edge
1251       aNormal = N1.Crossed(gp_Dir(Vec1));
1252     }
1253     else
1254       aNormal = N2;
1255
1256     if (twoAngles)
1257     { 
1258       gp_Vec V = Vec1.Transformed(aTransform.Inverted());
1259       gp_Vec Vec3(V.X(),V.Y(),0.0);
1260       
1261       // Express the coordinates in the refernce coordinate system (OXY)
1262       Vec3.Transform(aTransform);   
1263       if(Abs(Vec1.CrossMagnitude(Vec3)) > Precision::Confusion())                                  
1264       { 
1265         //  set the normal as the cross product of the current edge with its projection
1266         //  it ensures that the dimension changes side when the angle becomes negative
1267         aNormal = gp_Dir(Vec1.Crossed(Vec3));  
1268       } 
1269     }         
1270   }
1271   else
1272   {
1273     // Check colinearity
1274     if (Abs(Vec1.CrossMagnitude(Vec2)) < Precision::Confusion())
1275     {
1276       Vec2 = gp_Vec(gp::DX());
1277       if (Abs(Vec1.CrossMagnitude(Vec2)) < Precision::Confusion())
1278       {
1279         Vec2 = gp_Vec(gp::DY());
1280       }
1281     }
1282     // If no angles, the plane is the one formed by the last edge and the current one
1283     aNormal = gp_Dir(Vec1.Crossed(Vec2)); 
1284   }
1285   return aNormal;
1286 }
1287
1288 //================================================================
1289 // Function : displayPreview
1290 // Purpose  : Method for displaying preview of resulting shape
1291 //            Redefined from GEOMBase_Helper.
1292 //================================================================
1293 void EntityGUI_3DSketcherDlg::displayPreview (GEOM::GEOM_Object_ptr object,
1294                                               const bool            append,
1295                                               const bool            activate,
1296                                               const bool            update,
1297                                               const double          lineWidth,
1298                                               const int             displayMode,
1299                                               const int             color)
1300 {
1301   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1302
1303   QColor aColor = resMgr->colorValue("Geometry","line_color",QColor(255,0,0));
1304   Quantity_NameOfColor line_color = SalomeApp_Tools::color(aColor).Name();
1305
1306   // set width of displayed shape
1307   int lw = lineWidth;
1308   if (lw == -1) {
1309     lw = resMgr->integerValue("Geometry", "preview_edge_width", -1);
1310   }
1311   getDisplayer()->SetWidth(lw);
1312
1313   // Disable activation of selection
1314   getDisplayer()->SetToActivate(activate);
1315
1316   // Make a reference to GEOM_Object
1317   CORBA::String_var objStr = myGeometryGUI->getApp()->orb()->object_to_string(object);
1318   getDisplayer()->SetName(objStr.in());
1319
1320   // Create wire from applied object
1321   TopoDS_Shape anApplyedWire, aLastSegment;
1322   if (!createShapes(object, anApplyedWire, aLastSegment))
1323     return;
1324
1325   // Set color for preview shape
1326   getDisplayer()->SetColor(line_color);
1327
1328   // Build prs
1329   SALOME_Prs* aPrs = getDisplayer()->BuildPrs(anApplyedWire);
1330   if (aPrs != 0 && !aPrs->IsNull())
1331     GEOMBase_Helper::displayPreview(aPrs, append, update);
1332
1333   getDisplayer()->SetColor(Quantity_NOC_VIOLET);
1334   aPrs = getDisplayer()->BuildPrs(aLastSegment);
1335
1336   if (aPrs != 0 && !aPrs->IsNull())
1337     GEOMBase_Helper::displayPreview(aPrs, append, update);
1338
1339   getDisplayer()->SetColor(line_color);
1340
1341   // Display local trihedron if the mode is relative
1342   if (myMode == 1)
1343     displayTrihedron(2);
1344
1345   // Display preview of suitable dimension presentations
1346   displayDimensions(false);
1347
1348   getDisplayer()->UnsetName();
1349
1350   // Enable activation of displayed objects
1351   getDisplayer()->SetToActivate(true);
1352 }
1353
1354 //================================================================
1355 // Function : displayTrihedron()
1356 // Purpose  : Method for displaying trihedron
1357 //================================================================
1358 void EntityGUI_3DSketcherDlg::displayTrihedron (int selMode)
1359 {
1360   // Add trihedron to preview
1361   SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
1362
1363   gp_Pnt P(getLastPoint().x,getLastPoint().y,getLastPoint().z);
1364   Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(P,gp::DZ(),gp::DX());
1365   Handle(AIS_Trihedron) anIO = new AIS_Trihedron(anAxis);
1366   anIO->SetSelectionMode(selMode);
1367
1368   SOCC_Prs* aSPrs = dynamic_cast<SOCC_Prs*>
1369     (((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
1370
1371   if (aSPrs) {
1372     aSPrs->PrependObject(anIO);
1373     GEOMBase_Helper::displayPreview(aSPrs, true, true);
1374   }
1375 }
1376
1377 //================================================================
1378 // Function : displayDimensions( bool store )
1379 // Purpose  : Method for displaying dimensions. If store = true
1380 //            the presentation is stored in a list
1381 //================================================================
1382 void EntityGUI_3DSketcherDlg::displayDimensions (bool store)
1383 {
1384   myPrsType   = prsType();
1385   XYZ Last    = getLastPoint();
1386   XYZ Current = getCurrentPoint();
1387
1388   gp_Pnt Last_Pnt(Last.x,Last.y,Last.z);
1389   
1390   gp_Pnt P0 = Last_Pnt;
1391   gp_Pnt Origin = gp::Origin();
1392   if (myMode == 0)                 // Absolute coordinates
1393     P0 = Origin;
1394   
1395   gp_Pnt Current_Pnt(Current.x,Current.y,Current.z);
1396   gp_Pnt P1, P2;
1397   
1398   // Check if last end current point are coincident
1399   if (Last_Pnt.IsEqual(Current_Pnt, 1e-7))
1400     return;
1401   
1402   gp_Dir aNormal = getPresentationPlane();
1403   
1404   if (myCoordType == 0)
1405   {
1406     bool oneDimensionalMove =  (isSame(Last_Pnt.X(), Current_Pnt.X()) && 
1407                                 isSame(Last_Pnt.Y(), Current_Pnt.Y()) ) ||
1408                                (isSame(Last_Pnt.Y(), Current_Pnt.Y()) && 
1409                                 isSame(Last_Pnt.Z(), Current_Pnt.Z()) ) ||
1410                                (isSame(Last_Pnt.X(), Current_Pnt.X()) && 
1411                                 isSame(Last_Pnt.Z(), Current_Pnt.Z()) );
1412      
1413     if (myMode == 0)
1414     {
1415       std::string aCoordText = "( " + doubleToString(Current_Pnt.X()) + 
1416                                ", " + doubleToString(Current_Pnt.Y()) +
1417                                ", " + doubleToString(Current_Pnt.Z()) + " )";
1418       displayText(aCoordText, Current_Pnt, store);
1419     }
1420     else 
1421     { 
1422       if (oneDimensionalMove)
1423       {
1424         // For better colocation of dimensions if only one coordinate changes (aNormal is a better choice)
1425         displayLength(P0, Current_Pnt, aNormal, store);
1426       }
1427       else
1428       {
1429         displayLength(gp_Pnt(P0.X(),Current.y,P0.Z()), gp_Pnt(Current.x,Current.y,P0.Z()), gp::DZ().Reversed(), store);
1430         displayLength(gp_Pnt(Current.x,P0.Y(),P0.Z()), gp_Pnt(Current.x,Current.y,P0.Z()), gp::DZ(), store);
1431         displayLength(gp_Pnt(Current.x,Current.y,P0.Z()), Current_Pnt, gp::DX(), store);
1432       }
1433     }
1434   }
1435   else if (myCoordType == 1)             // ANGLES
1436   {
1437     bool spherical   = GroupAngles->checkBox->isChecked(); 
1438     bool cylindrical = GroupAngles->checkBox_2->isChecked();
1439     
1440     double anAngle1 = GroupAngles->SpinBox_DA->value();
1441     double aLength  = GroupAngles->SpinBox_DL->value();
1442     
1443     // Set the coordinates in the current coordinate system
1444     P1.SetCoord( aLength, 0.0, 0.0);    // X direction
1445     P2.SetCoord( aLength * cos(anAngle1 * M_PI / 180. ),
1446                  aLength * sin(anAngle1 * M_PI / 180. ),
1447                  0.0); 
1448     
1449     // Express the coordinates in the refernce coordinate system (OXY)
1450     gp_Trsf aTranform = toReferenceSystem(P0);
1451     P1.Transform(aTranform);    
1452     P2.Transform(aTranform);
1453     P1.Translate(Origin, P0);
1454     P2.Translate(Origin, P0);
1455     
1456     if(myMode !=0  || !store)
1457       displayAngle(anAngle1, P0, P1, P2, store);
1458     else
1459     {
1460       std::string anAngleText = doubleToString(anAngle1) + "deg";
1461       displayText(anAngleText, Current_Pnt, store);
1462     }
1463     
1464     if(spherical)
1465     {
1466       double anAngle2 = GroupAngles->SpinBox_DA2->value();
1467       displayAngle(anAngle2, P0, P2, Current_Pnt, store);
1468       displayLength(P0, Current_Pnt, aNormal, store);
1469     }
1470     else
1471     {
1472       bool sameRadius = isSame ( radius(Last_Pnt), radius(Current_Pnt) );
1473       bool sameHeight = isSame ( height(Last_Pnt), height(Current_Pnt) );
1474                             
1475       gp_Vec aVec(P2, Current_Pnt);
1476       
1477       if (myMode == 0 && !sameRadius)
1478       {
1479         displayLength(P0.Translated(aVec), P2.Translated(aVec), aNormal, store);  // Radius  
1480       }
1481       else if (myMode == 1)
1482         displayLength(P0, P2, aNormal, store);
1483       
1484       if ( cylindrical && 
1485           (myMode == 1 || !sameHeight) )
1486         displayLength(P2, Current_Pnt, aNormal.Reversed(), store); // Height
1487     }
1488   }
1489 }
1490
1491 //================================================================
1492 // Function : displayAngle()
1493 // Purpose  : Method for displaying angle dimensions
1494 //================================================================
1495 void EntityGUI_3DSketcherDlg::displayAngle (double theAngle,
1496                                             gp_Pnt P0, 
1497                                             gp_Pnt P1, 
1498                                             gp_Pnt P2,
1499                                             bool store)
1500 {
1501   SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
1502   
1503   // Creation of the AIS object
1504   Handle(AIS_AngleDimension) anAngleIO = createAISAngleDimension(theAngle, 
1505                                                                  P0, 
1506                                                                  P1, 
1507                                                                  P2);
1508   if (anAngleIO == NULL)
1509     return;
1510   
1511   if (store)
1512   {
1513     // Erase dimensions presentations
1514     ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myAnglePrs, true);
1515     myAnglePrs->PrependObject(anAngleIO);
1516     
1517     // Display modified presentation
1518     if (isAngleVisible)
1519       ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myAnglePrs);
1520     
1521     // Update dimension presentation angle count for later undo / redo
1522     myPrsType.A += 1;
1523   }
1524   else if ( isAngleVisible)
1525   {
1526     SOCC_Prs* aSPrs = dynamic_cast<SOCC_Prs*>
1527         (((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
1528         
1529     if (aSPrs)
1530     {
1531       aSPrs->AddObject(anAngleIO);
1532       GEOMBase_Helper::displayPreview(aSPrs, true, true); 
1533     }
1534   }
1535 }
1536
1537
1538 //================================================================
1539 // Function : displayLength()
1540 // Purpose  : Method for displaying length dimensions for a segment
1541 //            creation step
1542 //================================================================
1543 void EntityGUI_3DSketcherDlg::displayLength (gp_Pnt P1,
1544                                              gp_Pnt P2,
1545                                              gp_Dir theNormal,
1546                                              bool store)
1547 {
1548   SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
1549   
1550   double aLength = P1.Distance(P2);
1551   
1552   if (aLength < Precision::Confusion())
1553     return;
1554     
1555   Handle(AIS_LengthDimension) anIO = createAISLengthDimension(aLength, P1, P2, theNormal);
1556
1557   if (store)
1558   {
1559     // Erase length dimensions presentation
1560     ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myLengthPrs, true);
1561     myLengthPrs->PrependObject(anIO);
1562
1563     // Display modified presentation
1564     if (isLengthVisible)
1565       ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myLengthPrs);
1566     
1567     // Update dimension presentation length count for later undo / redo
1568     myPrsType.L += 1;
1569   }
1570   else if (isLengthVisible)
1571   {
1572     SOCC_Prs* aSPrs = dynamic_cast<SOCC_Prs*>
1573       (((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
1574     if (aSPrs)
1575     {
1576       aSPrs->PrependObject(anIO);
1577       GEOMBase_Helper::displayPreview(aSPrs, true, true);
1578     }
1579   }
1580 }
1581
1582 //================================================================
1583 // Function : displayText()
1584 // Purpose  : Method for displaying length dimensions for a segment
1585 //            creation step
1586 //================================================================
1587 void EntityGUI_3DSketcherDlg::displayText ( std::string theText,
1588                                             gp_Pnt P,
1589                                             bool store )
1590 {
1591   SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
1592     
1593   Handle(AIS_Text) anIO = new AIS_Text(TCollection_ExtendedString(theText.c_str()), P);
1594
1595   if (store)
1596   {
1597     // Erase length dimensions presentation
1598     ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myTextPrs, true);
1599     myTextPrs->PrependObject(anIO);
1600
1601     // Display modified presentation
1602     ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myTextPrs);
1603   }
1604   else
1605   {
1606     SOCC_Prs* aSPrs = dynamic_cast<SOCC_Prs*>
1607       (((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
1608     if (aSPrs)
1609     {
1610       aSPrs->PrependObject(anIO);
1611       GEOMBase_Helper::displayPreview(aSPrs, true, true);
1612     }
1613   }
1614 }
1615
1616 //================================================================
1617 // Function : createAISLengthDimension()
1618 // Purpose  : Method for creation of a length dimension object
1619 //            Returns an Handle on the AIS_LengthDimension obect
1620 //================================================================
1621 Handle(AIS_LengthDimension) EntityGUI_3DSketcherDlg::createAISLengthDimension(double theLength, 
1622                                                                               gp_Pnt P1, 
1623                                                                               gp_Pnt P2, 
1624                                                                               gp_Dir theNormal)
1625 {
1626   // Convert length to string
1627   std::string aLength_str = doubleToString(theLength);
1628   
1629   // Plane construction
1630   gce_MakePln gce_MP(P1, theNormal);
1631   Handle(Geom_Plane) aPlane = new Geom_Plane(gce_MP.Value());
1632   
1633   TopoDS_Vertex aVert1 = BRepBuilderAPI_MakeVertex(P1);
1634   TopoDS_Vertex aVert2 = BRepBuilderAPI_MakeVertex(P2);
1635
1636   Handle(AIS_LengthDimension) anIO =
1637     new AIS_LengthDimension(aVert1,
1638                             aVert2,
1639                             aPlane,
1640                             theLength,
1641                             TCollection_ExtendedString(aLength_str.c_str()));
1642   anIO->SetArrowSize(theLength/20);
1643
1644   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1645   int w = resMgr->integerValue("Geometry", "measures_line_width", 1);
1646   Handle(Prs3d_LengthAspect) asp = new Prs3d_LengthAspect();
1647   asp->LineAspect()->SetWidth(w);
1648   anIO->Attributes()->SetLengthAspect(asp);
1649   
1650   return anIO;
1651 }
1652
1653 //================================================================
1654 // Function : createAISAngleDimension()
1655 // Purpose  : Method for creation of an angle dimension object
1656 //            Returns an Handle on the AIS_AngleDimension obect
1657 //================================================================
1658 Handle(AIS_AngleDimension) EntityGUI_3DSketcherDlg::createAISAngleDimension(double theAngle, 
1659                                                                             gp_Pnt P0, 
1660                                                                             gp_Pnt P1, 
1661                                                                             gp_Pnt P2)
1662 {
1663   // Length of the built segment
1664   double aLength = P0.Distance(P1);
1665   
1666   // Check input data
1667   if (Abs(theAngle) < Precision::Angular() ||
1668       aLength < Precision::Confusion())
1669     return NULL;
1670   
1671   // Convert angles to string
1672   std::string Angle_str = doubleToString(theAngle);
1673   
1674   // Construction of the plane
1675   gce_MakePln gce_MP2(P0, P1, P2);
1676   Handle(Geom_Plane) aPlane = new Geom_Plane(gce_MP2.Value());
1677   
1678   TopoDS_Vertex V0 = BRepBuilderAPI_MakeVertex(P0);
1679   TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(P1);
1680   TopoDS_Vertex V2 = BRepBuilderAPI_MakeVertex(P2);
1681   
1682   TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge(V0, V1);
1683   TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge(V0, V2);
1684
1685   Handle(AIS_AngleDimension) anIO =
1686     new AIS_AngleDimension(anEdge1, anEdge2, aPlane, theAngle * M_PI / 180.,
1687                            TCollection_ExtendedString(Angle_str.c_str()));
1688     
1689   anIO->SetArrowSize((theAngle * M_PI / 180) * (aLength/20));
1690   
1691   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1692   int w = resMgr->integerValue("Geometry", "measures_line_width", 1);
1693   Handle(Prs3d_AngleAspect) asp = new Prs3d_AngleAspect();
1694   asp->LineAspect()->SetWidth(w);
1695   anIO->Attributes()->SetAngleAspect(asp);
1696   
1697   return anIO;
1698 }
1699
1700 //================================================================
1701 // Function : createShapes
1702 // Purpose  : Create applyed wire, and last segment from entry object
1703 //================================================================
1704 bool EntityGUI_3DSketcherDlg::createShapes (GEOM::GEOM_Object_ptr /*theObject*/,
1705                                             TopoDS_Shape&         theApplyedWire,
1706                                             TopoDS_Shape&         theLastSegment)
1707 {
1708   QList<gp_Pnt> points;
1709   foreach (XYZ xyz, myPointsList) {
1710     gp_Pnt p(xyz.x, xyz.y, xyz.z);
1711     if (points.isEmpty() || points.last().Distance(p) > gp::Resolution())
1712       points << p;
1713   }
1714
1715   if (points.count() == 1) {
1716     // only one point is created
1717     BRepBuilderAPI_MakeVertex mkVertex (points.last());
1718     theApplyedWire = mkVertex.Shape();
1719   }
1720   else if (points.count() > 1) {
1721     // wire is created
1722     BRepBuilderAPI_MakePolygon mkWire;
1723     foreach(gp_Pnt p, points)
1724       mkWire.Add(p);
1725     theApplyedWire = mkWire.Shape();
1726   }
1727
1728   XYZ curxyz = getCurrentPoint();
1729   gp_Pnt curpnt(curxyz.x, curxyz.y, curxyz.z);
1730
1731   if (points.isEmpty() || points.last().Distance(curpnt) <= gp::Resolution()) {
1732     BRepBuilderAPI_MakeVertex mkVertex (curpnt);
1733     theLastSegment = mkVertex.Shape();
1734   }
1735   else {
1736     BRepBuilderAPI_MakeEdge mkEdge(points.last(), curpnt);
1737     theLastSegment = mkEdge.Shape();
1738   }
1739
1740   /* VSR: old algorithm does not work properly, see bug 0020899
1741   TopoDS_Shape aShape;
1742   if (!GEOMBase::GetShape(theObject, aShape))
1743     return false;
1744
1745   if (aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX)
1746     return false;
1747
1748   theApplyedWire = aShape;
1749   if (myOK)
1750      return true;
1751
1752   BRepBuilderAPI_MakeWire aBuilder;
1753   TopExp_Explorer edgeExp(aShape, TopAbs_EDGE);
1754   while (1) {
1755     TopoDS_Shape anEdge = edgeExp.Current();
1756     edgeExp.Next();
1757     if (edgeExp.More()) // i.e. non-last edge
1758       aBuilder.Add(TopoDS::Edge(anEdge));
1759     else {
1760       theLastSegment = anEdge;
1761       break;
1762     }
1763   }
1764
1765   if (aBuilder.IsDone()) {
1766     theApplyedWire = aBuilder.Shape();
1767   }
1768   else if (!theLastSegment.IsNull()) {
1769     TopExp_Explorer vertexExp(theLastSegment, TopAbs_VERTEX);
1770     theApplyedWire = vertexExp.Current();
1771     }
1772   */
1773
1774   return true;
1775 }
1776
1777 //================================================================
1778 // Function : doubleToString
1779 // Purpose  : converts double to string
1780 //================================================================
1781 std::string EntityGUI_3DSketcherDlg::doubleToString (double num)
1782 {
1783   // truncate num
1784   int digNum = 5;
1785   char format = 'g'; // truncated to a number of significant digits
1786
1787   return QString::number(num, format, digNum).toStdString();
1788 }
1789
1790 //================================================================
1791 // Function : toReferenceSystem ()
1792 // Purpose  :
1793 //================================================================
1794 gp_Trsf EntityGUI_3DSketcherDlg::toReferenceSystem(gp_Pnt origin) const
1795
1796   gp_Trsf T;                        // Identity transformation
1797   gp_Ax3 reference_system;          // OXY
1798   reference_system.SetLocation(origin);
1799   
1800   gp_Ax3 current_system = reference_system;
1801   switch (myOrientation)
1802   {
1803     case OYZ:
1804     {
1805       current_system = gp_Ax3(origin, gp::DX(), gp::DY());
1806       break;
1807     }
1808     case OXZ:
1809     {
1810       current_system = gp_Ax3(origin, gp::DY().Reversed(), gp::DX());
1811       break;
1812     }
1813   }
1814   
1815   T.SetTransformation( current_system, reference_system );
1816   
1817   return T;
1818 }
1819
1820 //================================================================
1821 // Function : toCurrentSystem ()
1822 // Purpose  :
1823 //================================================================
1824 gp_Trsf EntityGUI_3DSketcherDlg::toCurrentSystem(gp_Pnt origin) const
1825 {
1826   return toReferenceSystem(origin).Inverted();
1827 }
1828
1829 //================================================================
1830 // Function : radius (gp_Pnt) const
1831 // Purpose  :
1832 //================================================================
1833 double EntityGUI_3DSketcherDlg::radius (gp_Pnt thePnt) const
1834 {
1835   // Get the point coordinates in the current coordinates system
1836   gp_Trsf aTrsf = toCurrentSystem(gp::Origin());
1837   gp_Pnt aPnt = thePnt.Transformed(aTrsf);
1838   
1839   double radius = sqrt(aPnt.X()*aPnt.X() + aPnt.Y()*aPnt.Y());
1840   return radius;
1841 }
1842
1843 //================================================================
1844 // Function : height (gp_Pnt) const
1845 // Purpose  :
1846 //================================================================
1847 double EntityGUI_3DSketcherDlg::height (gp_Pnt thePnt) const
1848 {
1849   // Get the point coordinates in the current coordinates system
1850   gp_Trsf aTrsf = toCurrentSystem(gp::Origin());
1851   gp_Pnt aPnt = thePnt.Transformed(aTrsf);
1852   
1853   return aPnt.Z();
1854 }