]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_FeaturePrs.cpp
Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
[modules/shaper.git] / src / PartSet / PartSet_FeaturePrs.cpp
1 // File:        PartSet_FeaturePrs.h
2 // Created:     04 Jun 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #include <PartSet_FeaturePrs.h>
6 #include <PartSet_Tools.h>
7
8 #include <SketchPlugin_Feature.h>
9 #include <SketchPlugin_Sketch.h>
10
11 #include <GeomDataAPI_Point2D.h>
12
13 #include <ModelAPI_Data.h>
14 #include <ModelAPI_Document.h>
15 #include <ModelAPI_AttributeRefAttr.h>
16 #include <ModelAPI_AttributeRefList.h>
17
18 #include <Precision.hxx>
19
20 using namespace std;
21
22 PartSet_FeaturePrs::PartSet_FeaturePrs(FeaturePtr theFeature)
23 : mySketch(theFeature)
24 {
25 }
26
27 PartSet_FeaturePrs::~PartSet_FeaturePrs()
28 {
29 }
30
31 void PartSet_FeaturePrs::init(FeaturePtr theFeature, FeaturePtr theSourceFeature)
32 {
33   myFeature = theFeature;
34   if (theSourceFeature) {
35     initFeature(theSourceFeature);
36   }
37 }
38
39 FeaturePtr PartSet_FeaturePrs::sketch() const
40 {
41   return mySketch;
42 }
43
44 FeaturePtr PartSet_FeaturePrs::feature() const
45 {
46   return myFeature;
47 }
48
49 void PartSet_FeaturePrs::setConstraints(double theX, double theY,
50                                         const PartSet_SelectionMode& theMode)
51 {
52   // find a feature point by the selection mode
53   boost::shared_ptr<GeomDataAPI_Point2D> aPoint = featurePoint(theMode);
54
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));
60
61   std::list<FeaturePtr > aFeatures = aRefList->list();
62   std::list<FeaturePtr >::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
63   for (; anIt != aLast; anIt++)
64   {
65     FeaturePtr aFeature = *anIt;
66     boost::shared_ptr<GeomDataAPI_Point2D> aFPoint = PartSet_Tools::findPoint(aFeature, theX, theY);
67     if (aFPoint)
68       PartSet_Tools::createConstraint(sketch(), aFPoint, aPoint);
69   }
70 }