Salome HOME
Merge remote-tracking branch 'remotes/origin/master' into SketchSolver
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Point.cpp
1 // File:    SketchPlugin_Point.cpp
2 // Created: 07 May 2014
3 // Author:  Artem ZHIDKOV
4
5 #include "SketchPlugin_Point.h"
6 #include "SketchPlugin_Sketch.h"
7
8 #include <ModelAPI_Data.h>
9
10 #include <GeomAPI_Pnt2d.h>
11
12 #include <GeomDataAPI_Point2D.h>
13 #include <GeomAlgoAPI_PointBuilder.h>
14
15 using namespace std;
16
17 SketchPlugin_Point::SketchPlugin_Point()
18 {
19 }
20
21 void SketchPlugin_Point::initAttributes()
22 {
23   data()->addAttribute(POINT_ATTR_COORD, GeomDataAPI_Point2D::type());
24 }
25
26 void SketchPlugin_Point::execute() 
27 {
28 }
29
30 const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Point::preview()
31 {
32   SketchPlugin_Sketch* aSketch = sketch();
33   if (aSketch) {
34     // compute a point in 3D view
35     boost::shared_ptr<GeomDataAPI_Point2D> aPoint = 
36       boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(POINT_ATTR_COORD));
37     boost::shared_ptr<GeomAPI_Pnt> aPoint3D(aSketch->to3D(aPoint->x(), aPoint->y()));
38     // make a visible point
39     boost::shared_ptr<GeomAPI_Shape> aPointShape = GeomAlgoAPI_PointBuilder::point(aPoint3D);
40     setPreview(aPointShape);
41   }
42   return getPreview();
43 }
44
45 boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_Point::getAISObject(
46                                 boost::shared_ptr<GeomAPI_AISObject> thePrevious)
47 {
48   return prepareAISShape(thePrevious);
49 }
50
51 void SketchPlugin_Point::move(double theDeltaX, double theDeltaY)
52 {
53   boost::shared_ptr<ModelAPI_Data> aData = data();
54   if (!aData->isValid())
55     return;
56
57   boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
58         boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(POINT_ATTR_COORD));
59   aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);
60 }
61
62 double SketchPlugin_Point::distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint)
63 {
64   boost::shared_ptr<ModelAPI_Data> aData = data();
65   boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
66         boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(POINT_ATTR_COORD));
67
68   return aPoint->pnt()->distance(thePoint);
69 }