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 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureCirclePrs::findPoint(FeaturePtr theFeature,
96 double theX, double theY)
98 boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D;
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));
105 if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
111 void PartSet_FeatureCirclePrs::projectPointOnFeature(FeaturePtr theFeature, FeaturePtr theSketch,
112 gp_Pnt& thePoint, Handle(V3d_View) theView,
113 double& theX, double& theY)
115 FeaturePtr aSketch = theSketch;
118 PartSet_Tools::convertTo2D(thePoint, aSketch, theView, aX, anY);
120 // circle origin point and radius
121 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
122 boost::shared_ptr<GeomDataAPI_Point2D> aCenter = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
123 (aData->attribute(CIRCLE_ATTR_CENTER));
125 double aRadius = PartSet_Tools::featureValue(theFeature, CIRCLE_ATTR_RADIUS, isValid);
127 boost::shared_ptr<GeomAPI_Dir2d> aNormal(new GeomAPI_Dir2d(aX, anY));
128 boost::shared_ptr<GeomAPI_Circ2d> aCirc(new GeomAPI_Circ2d(aCenter->pnt(), aNormal, aRadius));
129 boost::shared_ptr<GeomAPI_Pnt2d> aGeomPoint2d(new GeomAPI_Pnt2d(aX, anY));
130 boost::shared_ptr<GeomAPI_Pnt2d> aPnt2d = aCirc->project(aGeomPoint2d);
138 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureCirclePrs::featurePoint
139 (const PartSet_SelectionMode& theMode)
141 std::string aPointArg;
145 aPointArg = CIRCLE_ATTR_CENTER;
150 boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
151 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
152 (aData->attribute(aPointArg));