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