]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_FeaturePointPrs.cpp
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 <GeomAPI_Pnt2d.h>
13 #include <GeomDataAPI_Point2D.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_FeaturePointPrs::PartSet_FeaturePointPrs(FeaturePtr theSketch)
25 : PartSet_FeaturePrs(theSketch)
26 {
27 }
28
29 std::string PartSet_FeaturePointPrs::getKind()
30 {
31   return SKETCH_POINT_KIND;
32 }
33
34 PartSet_SelectionMode PartSet_FeaturePointPrs::setPoint(double theX, double theY,
35                                                        const PartSet_SelectionMode& theMode)
36 {
37   PartSet_SelectionMode aMode = theMode;
38   switch (theMode)
39   {
40     case SM_FirstPoint: {
41       PartSet_Tools::setFeaturePoint(feature(), theX, theY, POINT_ATTR_COORD);
42       aMode = SM_DonePoint;
43     }
44     break;
45     default:
46       break;
47   }
48   return aMode;
49 }
50
51 std::string PartSet_FeaturePointPrs::getAttribute(const PartSet_SelectionMode& theMode) const
52 {
53   std::string aAttribute;
54   switch (theMode)
55   {
56     case SM_FirstPoint:
57       aAttribute = POINT_ATTR_COORD;
58     break;
59     default:
60     break;
61   }
62   return aAttribute;
63 }
64
65 PartSet_SelectionMode PartSet_FeaturePointPrs::getNextMode(const std::string& theAttribute) const
66 {
67   PartSet_SelectionMode aMode;
68
69   if (theAttribute == POINT_ATTR_COORD)
70     aMode = SM_DonePoint;
71   return aMode;
72 }
73
74 double PartSet_FeaturePointPrs::distanceToPoint(FeaturePtr theFeature,
75                                                 double theX, double theY)
76 {
77   double aDelta = 0;
78   if (!theFeature || theFeature->getKind() != getKind())
79     return aDelta;
80
81   boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
82   boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
83         boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(POINT_ATTR_COORD));
84
85   boost::shared_ptr<GeomAPI_Pnt2d> aPoint2d(new GeomAPI_Pnt2d(theX, theY));
86   return aPoint->pnt()->distance(aPoint2d);
87 }
88
89 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeaturePointPrs::findPoint(FeaturePtr theFeature,
90                                                                           double theX, double theY)
91 {
92   boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D;
93   if (!theFeature || theFeature->getKind() != getKind())
94     return aPoint2D;
95
96   boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
97   boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
98         boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(POINT_ATTR_COORD));
99   if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
100     aPoint2D = aPoint;
101
102   return aPoint2D;
103 }
104
105 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeaturePointPrs::featurePoint
106                                                      (const PartSet_SelectionMode& theMode)
107 {
108   std::string aPointArg;
109   switch (theMode)
110   {
111     case SM_FirstPoint:
112       aPointArg = POINT_ATTR_COORD;
113       break;
114     default:
115       break;
116   }
117   boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
118   boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
119                                                               (aData->attribute(aPointArg));
120   return aPoint;
121 }