Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_ConstraintLength.cpp
1 // File:    SketchPlugin_ConstraintLength.cpp
2 // Created: 30 May 2014
3 // Author:  Artem ZHIDKOV
4
5 #include "SketchPlugin_ConstraintLength.h"
6
7 #include <GeomDataAPI_Point2D.h>
8
9 #include <ModelAPI_AttributeDouble.h>
10 #include <ModelAPI_Data.h>
11
12 SketchPlugin_ConstraintLength::SketchPlugin_ConstraintLength()
13 {
14 }
15
16 void SketchPlugin_ConstraintLength::initAttributes()
17 {
18   data()->addAttribute(CONSTRAINT_ATTR_VALUE,    ModelAPI_AttributeDouble::type());
19   data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE, ModelAPI_AttributeDouble::type());
20   data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT, GeomDataAPI_Point2D::type());
21   data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type());
22 }
23
24 void SketchPlugin_ConstraintLength::execute()
25 {
26 }
27
28 const boost::shared_ptr<GeomAPI_Shape>&  SketchPlugin_ConstraintLength::preview()
29 {
30   /// \todo Preview for distance constraint
31   return getPreview();
32 }
33
34 void SketchPlugin_ConstraintLength::move(double theDeltaX, double theDeltaY)
35 {
36   boost::shared_ptr<ModelAPI_Data> aData = data();
37   if (!aData->isValid())
38     return;
39
40   boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
41         boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
42   aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);
43 }
44