1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: SketchPlugin_IntersectionPoint.cpp
4 // Created: 07 May 2014
5 // Author: Artem ZHIDKOV
7 #include "SketchPlugin_IntersectionPoint.h"
9 #include <ModelAPI_AttributeRefAttr.h>
11 #include <GeomAPI_Edge.h>
12 #include <GeomAPI_Lin.h>
13 #include <GeomDataAPI_Point2D.h>
15 SketchPlugin_IntersectionPoint::SketchPlugin_IntersectionPoint()
16 : SketchPlugin_Point()
20 void SketchPlugin_IntersectionPoint::initDerivedClassAttributes()
22 data()->addAttribute(EXTERNAL_LINE_ID(), ModelAPI_AttributeRefAttr::typeId());
24 SketchPlugin_Point::initDerivedClassAttributes();
27 void SketchPlugin_IntersectionPoint::execute()
29 SketchPlugin_Sketch* aSketch = sketch();
32 SketchPlugin_Point::execute();
34 // set this feature as external
35 data()->selection(EXTERNAL_ID())->setValue(lastResult(), lastResult()->shape());
39 void SketchPlugin_IntersectionPoint::move(double theDeltaX, double theDeltaY)
43 void SketchPlugin_IntersectionPoint::attributeChanged(const std::string& theID)
45 if (theID == EXTERNAL_LINE_ID()) {
46 // compute intersection between line and sketch plane
51 void SketchPlugin_IntersectionPoint::computePoint()
53 AttributeRefAttrPtr aLineRefAttr =
54 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(attribute(EXTERNAL_LINE_ID()));
55 ResultPtr aLineResult = std::dynamic_pointer_cast<ModelAPI_Result>(aLineRefAttr->object());
59 std::shared_ptr<GeomAPI_Edge> aLinearEdge =
60 std::dynamic_pointer_cast<GeomAPI_Edge>(aLineResult->shape());
61 std::shared_ptr<GeomAPI_Lin> aLine = aLinearEdge->line();
62 std::shared_ptr<GeomAPI_Pln> aSketchPlane = sketch()->plane();
64 std::shared_ptr<GeomAPI_Pnt> anIntersection = aSketchPlane->intersect(aLine);
68 std::shared_ptr<GeomDataAPI_Point2D> aCoordAttr =
69 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(COORD_ID()));
70 aCoordAttr->setValue(sketch()->to2D(anIntersection));