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