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, FeaturePtr theSourceFeature)
33 myFeature = theFeature;
34 if (theSourceFeature) {
35 initFeature(theSourceFeature);
39 FeaturePtr PartSet_FeaturePrs::sketch() const
44 FeaturePtr PartSet_FeaturePrs::feature() const
49 void PartSet_FeaturePrs::setConstraints(double theX, double theY,
50 const PartSet_SelectionMode& theMode)
52 // find a feature point by the selection mode
53 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = featurePoint(theMode);
55 // get all sketch features. If the point with the given coordinates belong to any sketch feature,
56 // the constraint is created between the feature point and the found sketch point
57 boost::shared_ptr<ModelAPI_Data> aData = sketch()->data();
58 boost::shared_ptr<ModelAPI_AttributeRefList> aRefList =
59 boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aData->attribute(SKETCH_ATTR_FEATURES));
61 std::list<FeaturePtr > aFeatures = aRefList->list();
62 std::list<FeaturePtr >::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
63 for (; anIt != aLast; anIt++)
65 FeaturePtr aFeature = *anIt;
66 boost::shared_ptr<GeomDataAPI_Point2D> aFPoint = PartSet_Tools::findPoint(aFeature, theX, theY);
68 PartSet_Tools::createConstraint(sketch(), aFPoint, aPoint);