1 // File: PartSet_FeaturePrs.h
2 // Created: 04 Jun 2014
3 // Author: Natalia ERMOLAEVA
5 #include <PartSet_FeatureCirclePrs.h>
6 #include <PartSet_Tools.h>
8 #include <SketchPlugin_Feature.h>
9 #include <SketchPlugin_Sketch.h>
10 #include <SketchPlugin_Circle.h>
12 #include <GeomDataAPI_Point2D.h>
13 #include <GeomAPI_Pnt2d.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_FeatureCirclePrs::PartSet_FeatureCirclePrs(FeaturePtr theSketch)
25 : PartSet_FeaturePrs(theSketch)
29 std::string PartSet_FeatureCirclePrs::getKind()
31 return SKETCH_CIRCLE_KIND;
34 PartSet_SelectionMode PartSet_FeatureCirclePrs::setPoint(double theX, double theY,
35 const PartSet_SelectionMode& theMode)
37 PartSet_SelectionMode aMode = theMode;
41 PartSet_Tools::setFeaturePoint(feature(), theX, theY, CIRCLE_ATTR_CENTER);
42 aMode = SM_SecondPoint;
45 case SM_SecondPoint: {
46 boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
47 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
48 (aData->attribute(CIRCLE_ATTR_CENTER));
49 boost::shared_ptr<GeomAPI_Pnt2d> aCoordPoint(new GeomAPI_Pnt2d(theX, theY));
50 double aRadius = aCoordPoint->distance(aPoint->pnt());
51 PartSet_Tools::setFeatureValue(feature(), aRadius, CIRCLE_ATTR_RADIUS);
62 std::string PartSet_FeatureCirclePrs::getAttribute(const PartSet_SelectionMode& theMode) const
64 std::string aAttribute;
68 aAttribute = CIRCLE_ATTR_CENTER;
71 aAttribute = CIRCLE_ATTR_RADIUS;
79 PartSet_SelectionMode PartSet_FeatureCirclePrs::getNextMode(const std::string& theAttribute) const
81 PartSet_SelectionMode aMode;
83 if (theAttribute == CIRCLE_ATTR_CENTER)
84 aMode = SM_SecondPoint;
85 else if (theAttribute == CIRCLE_ATTR_RADIUS)
90 double PartSet_FeatureCirclePrs::distanceToPoint(FeaturePtr theFeature,
91 double theX, double theY)
94 if (!theFeature || theFeature->getKind() != getKind())
97 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
98 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
99 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CIRCLE_ATTR_CENTER));
101 boost::shared_ptr<GeomAPI_Pnt2d> aPoint2d(new GeomAPI_Pnt2d(theX, theY));
102 return aPoint->pnt()->distance(aPoint2d);
105 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureCirclePrs::findPoint(FeaturePtr theFeature,
106 double theX, double theY)
108 boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D;
109 if (!theFeature || theFeature->getKind() != getKind())
112 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
113 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
114 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CIRCLE_ATTR_CENTER));
115 if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
121 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureCirclePrs::featurePoint
122 (const PartSet_SelectionMode& theMode)
124 std::string aPointArg;
128 aPointArg = CIRCLE_ATTR_CENTER;
133 boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
134 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
135 (aData->attribute(aPointArg));