]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketcherPrs/SketcherPrs_Tools.cpp
Salome HOME
2f356e16b756122862c8d44a581ea064a4da07d3
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Tools.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        SketcherPrs_Tools.cpp
4 // Created:     10 March 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "SketcherPrs_Tools.h"
8
9 #include <SketchPlugin_Constraint.h>
10 #include <SketchPlugin_Point.h>
11 #include <SketchPlugin_Circle.h>
12 #include <ModelAPI_ResultConstruction.h>
13 #include <ModelAPI_AttributeRefAttr.h>
14
15 #include <GeomDataAPI_Point2D.h>
16
17
18 namespace SketcherPrs_Tools {
19
20
21 std::shared_ptr<GeomAPI_Edge> getLine(SketchPlugin_Constraint* theFeature,
22                                       const std::string& theAttrName)
23 {
24   std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
25   std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
26     std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(theAttrName));
27
28   ObjectPtr aObject = anAttr->object();
29   ResultConstructionPtr aRes = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aObject);
30   if (aRes.get() != NULL) {
31     std::shared_ptr<GeomAPI_Shape> aShape = aRes->shape();
32     if (aShape.get() != NULL) {   
33       return std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aShape));
34     }
35   }
36   return std::shared_ptr<GeomAPI_Edge>();
37 }
38
39
40 std::shared_ptr<GeomAPI_Pnt2d> getPoint(SketchPlugin_Constraint* theFeature,
41                                                const std::string& theAttribute)
42 {
43   std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
44
45   if (!theFeature->data())
46     return std::shared_ptr<GeomAPI_Pnt2d>();
47
48   FeaturePtr aFeature;
49   std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
50       ModelAPI_AttributeRefAttr>(theFeature->data()->attribute(theAttribute));
51   if (anAttr)
52     aFeature = ModelAPI_Feature::feature(anAttr->object());
53
54   if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID())
55     aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
56         aFeature->data()->attribute(SketchPlugin_Point::COORD_ID()));
57
58   else if (aFeature && aFeature->getKind() == SketchPlugin_Circle::ID())
59     aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
60         aFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID()));
61
62   else if (anAttr->attr()) {
63     aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
64   }
65   return aPointAttr->pnt();
66 }
67
68
69 };