1 // File: SketchPlugin_Point.cpp
2 // Created: 07 May 2014
3 // Author: Artem ZHIDKOV
5 #include "SketchPlugin_Point.h"
6 #include "SketchPlugin_Sketch.h"
8 #include <ModelAPI_Data.h>
9 #include <ModelAPI_ResultConstruction.h>
11 #include <GeomAPI_Pnt2d.h>
13 #include <GeomDataAPI_Point2D.h>
14 #include <GeomAlgoAPI_PointBuilder.h>
18 SketchPlugin_Point::SketchPlugin_Point()
22 void SketchPlugin_Point::initAttributes()
24 data()->addAttribute(SketchPlugin_Point::COORD_ID(), GeomDataAPI_Point2D::type());
27 void SketchPlugin_Point::execute()
29 SketchPlugin_Sketch* aSketch = sketch();
31 // compute a point in 3D view
32 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
33 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
34 data()->attribute(SketchPlugin_Point::COORD_ID()));
35 boost::shared_ptr<GeomAPI_Pnt> aPoint3D(aSketch->to3D(aPoint->x(), aPoint->y()));
36 // make a visible point
37 boost::shared_ptr<GeomAPI_Shape> aPointShape = GeomAlgoAPI_PointBuilder::point(aPoint3D);
38 boost::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
39 aConstr->setShape(aPointShape);
40 aConstr->setIsInHistory(false);
45 void SketchPlugin_Point::move(double theDeltaX, double theDeltaY)
47 boost::shared_ptr<ModelAPI_Data> aData = data();
48 if (!aData->isValid())
51 boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
52 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
53 aData->attribute(SketchPlugin_Point::COORD_ID()));
54 aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);
57 double SketchPlugin_Point::distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint)
59 boost::shared_ptr<ModelAPI_Data> aData = data();
60 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
61 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
62 aData->attribute(SketchPlugin_Point::COORD_ID()));
64 return aPoint->pnt()->distance(thePoint);