1 // File: PartSet_FeaturePrs.h
2 // Created: 16 Jun 2014
3 // Author: Natalia ERMOLAEVA
5 #include <PartSet_FeatureDistancePrs.h>
6 #include <PartSet_Tools.h>
8 #include <PartSet_FeatureLinePrs.h>
10 #include <SketchPlugin_Feature.h>
11 #include <SketchPlugin_Sketch.h>
12 #include <SketchPlugin_Line.h>
13 #include <SketchPlugin_ConstraintDistance.h>
15 #include <GeomDataAPI_Point2D.h>
16 #include <GeomAPI_Pnt2d.h>
17 #include <GeomAPI_Lin2d.h>
19 #include <ModelAPI_Data.h>
20 #include <ModelAPI_Document.h>
21 #include <ModelAPI_AttributeRefAttr.h>
22 #include <ModelAPI_AttributeRefList.h>
23 #include <ModelAPI_AttributeDouble.h>
25 #include <Precision.hxx>
29 PartSet_FeatureDistancePrs::PartSet_FeatureDistancePrs(FeaturePtr theSketch)
30 : PartSet_FeaturePrs(theSketch)
34 std::string PartSet_FeatureDistancePrs::getKind()
36 return SKETCH_CONSTRAINT_DISTANCE_KIND;
39 bool PartSet_FeatureDistancePrs::setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode)
42 if (feature() && theFeature && theFeature->getKind() == SKETCH_LINE_KIND && theMode == SM_FirstPoint)
45 boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
46 boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
47 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
48 aRef->setFeature(theFeature);
51 aData = theFeature->data();
52 boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
53 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
54 boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
55 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
57 double aLenght = aPoint1->pnt()->distance(aPoint2->pnt());
58 PartSet_Tools::setFeatureValue(feature(), aLenght, CONSTRAINT_ATTR_VALUE);
64 PartSet_SelectionMode PartSet_FeatureDistancePrs::setPoint(double theX, double theY,
65 const PartSet_SelectionMode& theMode)
67 PartSet_SelectionMode aMode = theMode;
70 case SM_SecondPoint: {
71 boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
72 boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
73 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
76 aFeature = anAttr->feature();
77 if (aFeature->getKind() != SKETCH_LINE_KIND) {
78 aFeature = FeaturePtr();
81 boost::shared_ptr<GeomAPI_Pnt2d> aPoint = boost::shared_ptr<GeomAPI_Pnt2d>
82 (new GeomAPI_Pnt2d(theX, theY));
83 boost::shared_ptr<GeomAPI_Lin2d> aFeatureLin = PartSet_FeatureLinePrs::createLin2d(aFeature);
84 boost::shared_ptr<GeomAPI_Pnt2d> aResult = aFeatureLin->project(aPoint);
85 double aDistance = aPoint->distance(aResult);
87 double aStartX, aStartY;
88 PartSet_FeatureLinePrs::getLinePoint(aFeature, LINE_ATTR_START, aStartX, aStartY);
90 if (!aFeatureLin->isRight(aPoint))
91 aDistance = -aDistance;
93 AttributeDoublePtr aFlyoutAttr =
94 boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
95 aFlyoutAttr->setValue(aDistance);
106 std::string PartSet_FeatureDistancePrs::getAttribute(const PartSet_SelectionMode& theMode) const
111 PartSet_SelectionMode PartSet_FeatureDistancePrs::getNextMode(const std::string& theAttribute) const
113 return SM_FirstPoint;
116 void PartSet_FeatureDistancePrs::move(double theDeltaX, double theDeltaY)
120 double PartSet_FeatureDistancePrs::distanceToPoint(FeaturePtr theFeature,
121 double theX, double theY)
126 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureDistancePrs::findPoint(FeaturePtr theFeature,
127 double theX, double theY)
129 boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D;
133 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureDistancePrs::featurePoint
134 (const PartSet_SelectionMode& theMode)
136 return boost::shared_ptr<GeomDataAPI_Point2D>();