]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_FeatureCirclePrs.cpp
Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
[modules/shaper.git] / src / PartSet / PartSet_FeatureCirclePrs.cpp
1 // File:        PartSet_FeaturePrs.h
2 // Created:     04 Jun 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #include <PartSet_FeatureCirclePrs.h>
6 #include <PartSet_Tools.h>
7
8 #include <SketchPlugin_Feature.h>
9 #include <SketchPlugin_Sketch.h>
10 #include <SketchPlugin_Circle.h>
11
12 #include <GeomDataAPI_Point2D.h>
13 #include <GeomAPI_Pnt2d.h>
14
15 #include <ModelAPI_Data.h>
16 #include <ModelAPI_Document.h>
17 #include <ModelAPI_AttributeRefAttr.h>
18 #include <ModelAPI_AttributeRefList.h>
19
20 #include <Precision.hxx>
21
22 using namespace std;
23
24 PartSet_FeatureCirclePrs::PartSet_FeatureCirclePrs(FeaturePtr theSketch)
25 : PartSet_FeaturePrs(theSketch)
26 {
27 }
28
29 PartSet_SelectionMode PartSet_FeatureCirclePrs::setPoint(double theX, double theY,
30                                                          const PartSet_SelectionMode& theMode)
31 {
32   PartSet_SelectionMode aMode = theMode;
33   switch (theMode)
34   {
35     case SM_FirstPoint: {
36       PartSet_Tools::setFeaturePoint(feature(), theX, theY, CIRCLE_ATTR_CENTER);
37       aMode = SM_SecondPoint;
38     }
39     break;
40     case SM_SecondPoint: {
41       boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
42       boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
43                                                                   (aData->attribute(CIRCLE_ATTR_CENTER));
44       boost::shared_ptr<GeomAPI_Pnt2d> aCoordPoint(new GeomAPI_Pnt2d(theX, theY));
45       double aRadius = aCoordPoint->distance(aPoint->pnt());
46       PartSet_Tools::setFeatureValue(feature(), aRadius, CIRCLE_ATTR_RADIUS);
47
48       aMode = SM_DonePoint;
49    }
50     break;
51     default:
52       break;
53   }
54   return aMode;
55 }
56
57 std::string PartSet_FeatureCirclePrs::getAttribute(const PartSet_SelectionMode& theMode) const
58 {
59   std::string aAttribute;
60   switch (theMode)
61   {
62     case SM_FirstPoint:
63       aAttribute = CIRCLE_ATTR_CENTER;
64     break;
65     case SM_SecondPoint:
66       aAttribute = CIRCLE_ATTR_RADIUS;
67     break;
68     default:
69     break;
70   }
71   return aAttribute;
72 }
73
74 PartSet_SelectionMode PartSet_FeatureCirclePrs::getNextMode(const std::string& theAttribute) const
75 {
76   PartSet_SelectionMode aMode;
77
78   if (theAttribute == CIRCLE_ATTR_CENTER)
79     aMode = SM_SecondPoint;
80   else if (theAttribute == CIRCLE_ATTR_RADIUS)
81     aMode = SM_DonePoint;
82   return aMode;
83 }
84
85 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureCirclePrs::featurePoint
86                                                      (const PartSet_SelectionMode& theMode)
87 {
88   std::string aPointArg;
89   switch (theMode)
90   {
91     case SM_FirstPoint:
92       aPointArg = CIRCLE_ATTR_CENTER;
93       break;
94     default:
95       break;
96   }
97   boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
98   boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
99                                                               (aData->attribute(aPointArg));
100   return aPoint;
101 }