1 // File: PartSet_FeaturePrs.h
2 // Created: 04 Jun 2014
3 // Author: Natalia ERMOLAEVA
5 #include <PartSet_FeaturePointPrs.h>
6 #include <PartSet_Tools.h>
8 #include <SketchPlugin_Feature.h>
9 #include <SketchPlugin_Sketch.h>
10 #include <SketchPlugin_Point.h>
12 #include <GeomAPI_Pnt2d.h>
13 #include <GeomDataAPI_Point2D.h>
15 #include <ModelAPI_Data.h>
16 #include <ModelAPI_Document.h>
17 #include <ModelAPI_AttributeRefAttr.h>
18 #include <ModelAPI_AttributeRefList.h>
20 #include <Precision.hxx>
24 PartSet_FeaturePointPrs::PartSet_FeaturePointPrs(FeaturePtr theSketch)
25 : PartSet_FeaturePrs(theSketch)
29 std::string PartSet_FeaturePointPrs::getKind()
31 return SKETCH_POINT_KIND;
34 PartSet_SelectionMode PartSet_FeaturePointPrs::setPoint(double theX, double theY,
35 const PartSet_SelectionMode& theMode)
37 PartSet_SelectionMode aMode = theMode;
41 PartSet_Tools::setFeaturePoint(feature(), theX, theY, POINT_ATTR_COORD);
51 std::string PartSet_FeaturePointPrs::getAttribute(const PartSet_SelectionMode& theMode) const
53 std::string aAttribute;
57 aAttribute = POINT_ATTR_COORD;
65 PartSet_SelectionMode PartSet_FeaturePointPrs::getNextMode(const std::string& theAttribute) const
67 PartSet_SelectionMode aMode;
69 if (theAttribute == POINT_ATTR_COORD)
74 void PartSet_FeaturePointPrs::move(double theDeltaX, double theDeltaY)
76 boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
77 if (!aData->isValid())
80 boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
81 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(POINT_ATTR_COORD));
82 aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);
85 double PartSet_FeaturePointPrs::distanceToPoint(FeaturePtr theFeature,
86 double theX, double theY)
89 if (!theFeature || theFeature->getKind() != getKind())
92 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
93 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
94 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(POINT_ATTR_COORD));
96 boost::shared_ptr<GeomAPI_Pnt2d> aPoint2d(new GeomAPI_Pnt2d(theX, theY));
97 return aPoint->pnt()->distance(aPoint2d);
100 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeaturePointPrs::findPoint(FeaturePtr theFeature,
101 double theX, double theY)
103 boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D;
104 if (!theFeature || theFeature->getKind() != getKind())
107 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
108 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
109 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(POINT_ATTR_COORD));
110 if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
116 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeaturePointPrs::featurePoint
117 (const PartSet_SelectionMode& theMode)
119 std::string aPointArg;
123 aPointArg = POINT_ATTR_COORD;
128 boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
129 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
130 (aData->attribute(aPointArg));