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>
13 #include <GeomAPI_Pnt2d.h>
15 #include <GeomDataAPI_Point2D.h>
16 #include <GeomAlgoAPI_PointBuilder.h>
20 SketchPlugin_Point::SketchPlugin_Point()
24 void SketchPlugin_Point::initAttributes()
26 data()->addAttribute(SketchPlugin_Point::COORD_ID(), GeomDataAPI_Point2D::type());
27 data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
28 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
31 void SketchPlugin_Point::execute()
33 SketchPlugin_Sketch* aSketch = sketch();
35 // compute a point in 3D view
36 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
37 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
38 data()->attribute(SketchPlugin_Point::COORD_ID()));
39 boost::shared_ptr<GeomAPI_Pnt> aPoint3D(aSketch->to3D(aPoint->x(), aPoint->y()));
40 // make a visible point
41 boost::shared_ptr<GeomAPI_Shape> aPointShape = GeomAlgoAPI_PointBuilder::point(aPoint3D);
42 boost::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
43 aConstr->setShape(aPointShape);
44 aConstr->setIsInHistory(false);
49 void SketchPlugin_Point::move(double theDeltaX, double theDeltaY)
51 boost::shared_ptr<ModelAPI_Data> aData = data();
52 if (!aData->isValid())
55 boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
56 aData->attribute(SketchPlugin_Point::COORD_ID()));
57 aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);
60 double SketchPlugin_Point::distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint)
62 boost::shared_ptr<ModelAPI_Data> aData = data();
63 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
64 aData->attribute(SketchPlugin_Point::COORD_ID()));
66 return aPoint->pnt()->distance(thePoint);
69 bool SketchPlugin_Point::isFixed() {
70 return data()->selection(EXTERNAL_ID())->context();