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>
10 #include <ModelAPI_AttributeSelection.h>
11 #include <ModelAPI_Validator.h>
12 #include <ModelAPI_Session.h>
14 #include <GeomAPI_Pnt2d.h>
16 #include <GeomDataAPI_Point2D.h>
17 #include <GeomAlgoAPI_PointBuilder.h>
21 SketchPlugin_Point::SketchPlugin_Point()
25 void SketchPlugin_Point::initAttributes()
27 data()->addAttribute(SketchPlugin_Point::COORD_ID(), GeomDataAPI_Point2D::type());
28 data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
29 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
32 void SketchPlugin_Point::execute()
34 SketchPlugin_Sketch* aSketch = sketch();
36 // compute a point in 3D view
37 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
38 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
39 data()->attribute(SketchPlugin_Point::COORD_ID()));
40 std::shared_ptr<GeomAPI_Pnt> aPoint3D(aSketch->to3D(aPoint->x(), aPoint->y()));
41 // make a visible point
42 std::shared_ptr<GeomAPI_Shape> aPointShape = GeomAlgoAPI_PointBuilder::point(aPoint3D);
43 std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
44 aConstr->setShape(aPointShape);
45 aConstr->setIsInHistory(false);
50 void SketchPlugin_Point::move(double theDeltaX, double theDeltaY)
52 std::shared_ptr<ModelAPI_Data> aData = data();
53 if (!aData->isValid())
56 std::shared_ptr<GeomDataAPI_Point2D> aPoint1 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
57 aData->attribute(SketchPlugin_Point::COORD_ID()));
58 aPoint1->move(theDeltaX, theDeltaY);
61 double SketchPlugin_Point::distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
63 std::shared_ptr<ModelAPI_Data> aData = data();
64 std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
65 aData->attribute(SketchPlugin_Point::COORD_ID()));
67 return aPoint->pnt()->distance(thePoint);
70 bool SketchPlugin_Point::isFixed() {
71 return data()->selection(EXTERNAL_ID())->context();