]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/SketchPlugin_Point.cpp
Salome HOME
Initial version of redesign of working with results
[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 #include <ModelAPI_ResultConstruction.h>
10
11 #include <GeomAPI_Pnt2d.h>
12
13 #include <GeomDataAPI_Point2D.h>
14 #include <GeomAlgoAPI_PointBuilder.h>
15
16 using namespace std;
17
18 SketchPlugin_Point::SketchPlugin_Point()
19 {
20 }
21
22 void SketchPlugin_Point::initAttributes()
23 {
24   data()->addAttribute(POINT_ATTR_COORD, GeomDataAPI_Point2D::type());
25 }
26
27 void SketchPlugin_Point::execute(boost::shared_ptr<ModelAPI_Result>& theResult) 
28 {
29   SketchPlugin_Sketch* aSketch = sketch();
30   if (aSketch) {
31     // compute a point in 3D view
32     boost::shared_ptr<GeomDataAPI_Point2D> aPoint = 
33       boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(POINT_ATTR_COORD));
34     boost::shared_ptr<GeomAPI_Pnt> aPoint3D(aSketch->to3D(aPoint->x(), aPoint->y()));
35     // make a visible point
36     boost::shared_ptr<GeomAPI_Shape> aPointShape = GeomAlgoAPI_PointBuilder::point(aPoint3D);
37     boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theResult)->setShape(aPointShape);
38   }
39 }
40
41 void SketchPlugin_Point::move(double theDeltaX, double theDeltaY)
42 {
43   boost::shared_ptr<ModelAPI_Data> aData = data();
44   if (!aData->isValid())
45     return;
46
47   boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
48         boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(POINT_ATTR_COORD));
49   aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);
50 }
51
52 double SketchPlugin_Point::distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint)
53 {
54   boost::shared_ptr<ModelAPI_Data> aData = data();
55   boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
56         boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(POINT_ATTR_COORD));
57
58   return aPoint->pnt()->distance(thePoint);
59 }