]> 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)
32 {
33   myFeature = theFeature;
34 }
35
36 FeaturePtr PartSet_FeaturePrs::sketch() const
37 {
38   return mySketch;
39 }
40
41 FeaturePtr PartSet_FeaturePrs::feature() const
42 {
43   return myFeature;
44 }
45
46 PartSet_SelectionMode PartSet_FeaturePrs::setFeature(FeaturePtr theFeature,
47                                                      const PartSet_SelectionMode& theMode)
48 {
49   return SM_FirstPoint;
50 }
51
52 void PartSet_FeaturePrs::setConstraints(double theX, double theY,
53                                         const PartSet_SelectionMode& theMode)
54 {
55   // find a feature point by the selection mode
56   boost::shared_ptr<GeomDataAPI_Point2D> aPoint = featurePoint(theMode);
57
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));
63
64   std::list<FeaturePtr > aFeatures = aRefList->list();
65   std::list<FeaturePtr >::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
66   for (; anIt != aLast; anIt++)
67   {
68     FeaturePtr aFeature = *anIt;
69     boost::shared_ptr<GeomDataAPI_Point2D> aFPoint = PartSet_Tools::findPoint(aFeature, theX, theY);
70     if (aFPoint)
71       PartSet_Tools::createConstraint(sketch(), aFPoint, aPoint);
72   }
73 }