Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
[modules/shaper.git] / src / PartSet / PartSet_FeaturePointPrs.cpp
1 // File:        PartSet_FeaturePrs.h
2 // Created:     04 Jun 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #include <PartSet_FeaturePointPrs.h>
6 #include <PartSet_Tools.h>
7
8 #include <SketchPlugin_Feature.h>
9 #include <SketchPlugin_Sketch.h>
10 #include <SketchPlugin_Point.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_FeaturePointPrs::PartSet_FeaturePointPrs(FeaturePtr theSketch)
24 : PartSet_FeaturePrs(theSketch)
25 {
26 }
27
28 PartSet_SelectionMode PartSet_FeaturePointPrs::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, POINT_ATTR_COORD);
36       aMode = SM_DonePoint;
37     }
38     break;
39     default:
40       break;
41   }
42   return aMode;
43 }
44
45 std::string PartSet_FeaturePointPrs::getAttribute(const PartSet_SelectionMode& theMode) const
46 {
47   std::string aAttribute;
48   switch (theMode)
49   {
50     case SM_FirstPoint:
51       aAttribute = POINT_ATTR_COORD;
52     break;
53     default:
54     break;
55   }
56   return aAttribute;
57 }
58
59 PartSet_SelectionMode PartSet_FeaturePointPrs::getNextMode(const std::string& theAttribute) const
60 {
61   PartSet_SelectionMode aMode;
62
63   if (theAttribute == POINT_ATTR_COORD)
64     aMode = SM_DonePoint;
65   return aMode;
66 }
67
68 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeaturePointPrs::featurePoint
69                                                      (const PartSet_SelectionMode& theMode)
70 {
71   std::string aPointArg;
72   switch (theMode)
73   {
74     case SM_FirstPoint:
75       aPointArg = POINT_ATTR_COORD;
76       break;
77     default:
78       break;
79   }
80   boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
81   boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
82                                                               (aData->attribute(aPointArg));
83   return aPoint;
84 }