1 // File: PartSet_FeaturePrs.h
2 // Created: 04 Jun 2014
3 // Author: Natalia ERMOLAEVA
5 #include <PartSet_FeaturePrs.h>
6 #include <PartSet_Tools.h>
8 #include <SketchPlugin_Feature.h>
9 #include <SketchPlugin_Sketch.h>
11 #include <GeomDataAPI_Point2D.h>
13 #include <ModelAPI_Data.h>
14 #include <ModelAPI_Document.h>
15 #include <ModelAPI_AttributeRefAttr.h>
16 #include <ModelAPI_AttributeRefList.h>
18 #include <Precision.hxx>
22 PartSet_FeaturePrs::PartSet_FeaturePrs(FeaturePtr theFeature)
23 : mySketch(theFeature)
27 PartSet_FeaturePrs::~PartSet_FeaturePrs()
31 void PartSet_FeaturePrs::init(FeaturePtr theFeature)
33 myFeature = theFeature;
36 FeaturePtr PartSet_FeaturePrs::sketch() const
41 FeaturePtr PartSet_FeaturePrs::feature() const
46 PartSet_SelectionMode PartSet_FeaturePrs::setFeature(FeaturePtr theFeature,
47 const PartSet_SelectionMode& theMode)
52 void PartSet_FeaturePrs::setConstraints(double theX, double theY,
53 const PartSet_SelectionMode& theMode)
55 // find a feature point by the selection mode
56 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = featurePoint(theMode);
58 // get all sketch features. If the point with the given coordinates belong to any sketch feature,
59 // the constraint is created between the feature point and the found sketch point
60 boost::shared_ptr<ModelAPI_Data> aData = sketch()->data();
61 boost::shared_ptr<ModelAPI_AttributeRefList> aRefList =
62 boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aData->attribute(SKETCH_ATTR_FEATURES));
64 std::list<FeaturePtr > aFeatures = aRefList->list();
65 std::list<FeaturePtr >::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
66 for (; anIt != aLast; anIt++)
68 FeaturePtr aFeature = *anIt;
69 boost::shared_ptr<GeomDataAPI_Point2D> aFPoint = PartSet_Tools::findPoint(aFeature, theX, theY);
71 PartSet_Tools::createConstraint(sketch(), aFPoint, aPoint);