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 <GeomDataAPI_Dir.h>
14 #include <GeomAPI_Pnt2d.h>
15 #include <GeomAPI_Circ2d.h>
16 #include <GeomAPI_Dir2d.h>
17 #include <GeomAPI_Dir.h>
19 #include <ModelAPI_Data.h>
20 #include <ModelAPI_Document.h>
21 #include <ModelAPI_AttributeRefAttr.h>
22 #include <ModelAPI_AttributeRefList.h>
24 #include <V3d_View.hxx>
25 #include <Precision.hxx>
29 PartSet_FeatureCirclePrs::PartSet_FeatureCirclePrs(FeaturePtr theSketch)
30 : PartSet_FeaturePrs(theSketch)
34 std::string PartSet_FeatureCirclePrs::getKind()
36 return SKETCH_CIRCLE_KIND;
39 PartSet_SelectionMode PartSet_FeatureCirclePrs::setPoint(double theX, double theY,
40 const PartSet_SelectionMode& theMode)
42 PartSet_SelectionMode aMode = theMode;
46 PartSet_Tools::setFeaturePoint(feature(), theX, theY, CIRCLE_ATTR_CENTER);
47 aMode = SM_SecondPoint;
50 case SM_SecondPoint: {
51 boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
52 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
53 (aData->attribute(CIRCLE_ATTR_CENTER));
54 boost::shared_ptr<GeomAPI_Pnt2d> aCoordPoint(new GeomAPI_Pnt2d(theX, theY));
55 double aRadius = aCoordPoint->distance(aPoint->pnt());
56 PartSet_Tools::setFeatureValue(feature(), aRadius, CIRCLE_ATTR_RADIUS);
67 std::string PartSet_FeatureCirclePrs::getAttribute(const PartSet_SelectionMode& theMode) const
69 std::string aAttribute;
73 aAttribute = CIRCLE_ATTR_CENTER;
76 aAttribute = CIRCLE_ATTR_RADIUS;
84 PartSet_SelectionMode PartSet_FeatureCirclePrs::getNextMode(const std::string& theAttribute) const
86 PartSet_SelectionMode aMode;
88 if (theAttribute == CIRCLE_ATTR_CENTER)
89 aMode = SM_SecondPoint;
90 else if (theAttribute == CIRCLE_ATTR_RADIUS)
95 double PartSet_FeatureCirclePrs::distanceToPoint(FeaturePtr theFeature,
96 double theX, double theY)
99 if (!theFeature || theFeature->getKind() != getKind())
102 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
103 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
104 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CIRCLE_ATTR_CENTER));
106 boost::shared_ptr<GeomAPI_Pnt2d> aPoint2d(new GeomAPI_Pnt2d(theX, theY));
107 return aPoint->pnt()->distance(aPoint2d);
110 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureCirclePrs::findPoint(FeaturePtr theFeature,
111 double theX, double theY)
113 boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D;
114 if (!theFeature || theFeature->getKind() != getKind())
117 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
118 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
119 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CIRCLE_ATTR_CENTER));
120 if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
126 void PartSet_FeatureCirclePrs::projectPointOnFeature(FeaturePtr theFeature, FeaturePtr theSketch,
127 gp_Pnt& thePoint, Handle(V3d_View) theView,
128 double& theX, double& theY)
130 FeaturePtr aSketch = theSketch;
133 PartSet_Tools::convertTo2D(thePoint, aSketch, theView, aX, anY);
135 // circle origin point and radius
136 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
137 boost::shared_ptr<GeomDataAPI_Point2D> aCenter = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
138 (aData->attribute(CIRCLE_ATTR_CENTER));
140 double aRadius = PartSet_Tools::featureValue(theFeature, CIRCLE_ATTR_RADIUS, isValid);
142 boost::shared_ptr<GeomAPI_Dir2d> aNormal(new GeomAPI_Dir2d(aX, anY));
143 boost::shared_ptr<GeomAPI_Circ2d> aCirc(new GeomAPI_Circ2d(aCenter->pnt(), aNormal, aRadius));
144 boost::shared_ptr<GeomAPI_Pnt2d> aGeomPoint2d(new GeomAPI_Pnt2d(aX, anY));
145 boost::shared_ptr<GeomAPI_Pnt2d> aPnt2d = aCirc->project(aGeomPoint2d);
153 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureCirclePrs::featurePoint
154 (const PartSet_SelectionMode& theMode)
156 std::string aPointArg;
160 aPointArg = CIRCLE_ATTR_CENTER;
165 boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
166 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
167 (aData->attribute(aPointArg));