1 // File: SketchPlugin_Arc.cpp
2 // Created: 26 Apr 2014
3 // Author: Artem ZHIDKOV
5 #include "SketchPlugin_Arc.h"
6 #include "SketchPlugin_Sketch.h"
7 #include <ModelAPI_Data.h>
9 #include <GeomDataAPI_Point2D.h>
10 #include <GeomDataAPI_Dir.h>
12 #include <GeomAlgoAPI_PointBuilder.h>
13 #include <GeomAlgoAPI_EdgeBuilder.h>
14 #include <GeomAlgoAPI_CompoundBuilder.h>
16 SketchPlugin_Arc::SketchPlugin_Arc()
17 : SketchPlugin_Feature()
21 void SketchPlugin_Arc::initAttributes()
23 data()->addAttribute(ARC_ATTR_CENTER, GeomDataAPI_Point2D::type());
24 data()->addAttribute(ARC_ATTR_START, GeomDataAPI_Point2D::type());
25 data()->addAttribute(ARC_ATTR_END, GeomDataAPI_Point2D::type());
28 void SketchPlugin_Arc::execute()
32 const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Arc::preview()
34 SketchPlugin_Sketch* aSketch = sketch();
36 std::list<boost::shared_ptr<GeomAPI_Shape> > aShapes;
38 // compute a circle point in 3D view
39 boost::shared_ptr<GeomDataAPI_Point2D> aCenterAttr =
40 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(ARC_ATTR_CENTER));
41 boost::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y()));
42 // make a visible point
43 boost::shared_ptr<GeomAPI_Shape> aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter);
44 aShapes.push_back(aCenterPointShape);
46 // make a visible circle
47 boost::shared_ptr<GeomDataAPI_Dir> aNDir =
48 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aSketch->data()->attribute(SKETCH_ATTR_NORM));
49 bool aHasPlane = aNDir && !(aNDir->x() == 0 && aNDir->y() == 0 && aNDir->z() == 0);
51 boost::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z()));
52 // compute the arc start point
53 boost::shared_ptr<GeomDataAPI_Point2D> aStartAttr =
54 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(ARC_ATTR_START));
55 boost::shared_ptr<GeomAPI_Pnt> aStartPoint(aSketch->to3D(aStartAttr->x(), aStartAttr->y()));
57 // compute the arc end point
58 boost::shared_ptr<GeomDataAPI_Point2D> anEndAttr =
59 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(ARC_ATTR_END));
60 boost::shared_ptr<GeomAPI_Pnt> aEndPoint(aSketch->to3D(anEndAttr->x(), anEndAttr->y()));
62 boost::shared_ptr<GeomAPI_Shape> aCircleShape =
63 GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, aStartPoint, aEndPoint, aNormal);
64 aShapes.push_back(aCircleShape);
66 boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
67 setPreview(aCompound);