1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SketcherPrs_Tools.cpp
4 // Created: 10 March 2015
5 // Author: Vitaly SMETANNIKOV
7 #include "SketcherPrs_Tools.h"
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>
15 #include <GeomDataAPI_Point2D.h>
18 namespace SketcherPrs_Tools {
21 std::shared_ptr<GeomAPI_Shape> getLine(SketchPlugin_Constraint* theFeature,
22 const std::string& theAttrName)
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));
28 ObjectPtr aObject = anAttr->object();
29 ResultConstructionPtr aRes = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aObject);
30 if (aRes.get() != NULL) {
33 return std::shared_ptr<GeomAPI_Shape>();
37 std::shared_ptr<GeomAPI_Pnt2d> getPoint(SketchPlugin_Constraint* theFeature,
38 const std::string& theAttribute)
40 std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
42 if (!theFeature->data())
43 return std::shared_ptr<GeomAPI_Pnt2d>();
46 std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
47 ModelAPI_AttributeRefAttr>(theFeature->data()->attribute(theAttribute));
49 aFeature = ModelAPI_Feature::feature(anAttr->object());
51 if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID())
52 aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
53 aFeature->data()->attribute(SketchPlugin_Point::COORD_ID()));
55 else if (aFeature && aFeature->getKind() == SketchPlugin_Circle::ID())
56 aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
57 aFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID()));
59 else if (anAttr->attr()) {
60 aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
62 return aPointAttr->pnt();