Salome HOME
d6e2b0075c7958cdbff8f71c55da53209fbd6f6f
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_ConstraintDistance.cpp
1 // File:    SketchPlugin_ConstraintDistance.cpp
2 // Created: 23 May 2014
3 // Author:  Artem ZHIDKOV
4
5 #include "SketchPlugin_ConstraintDistance.h"
6
7 #include "GeomDataAPI_Point2D.h"
8
9 #include <ModelAPI_AttributeDouble.h>
10 #include <ModelAPI_Data.h>
11 #include <SketchPlugin_Point.h>
12
13 SketchPlugin_ConstraintDistance::SketchPlugin_ConstraintDistance()
14 {
15 }
16
17 void SketchPlugin_ConstraintDistance::initAttributes()
18 {
19   data()->addAttribute(CONSTRAINT_ATTR_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   data()->addAttribute(CONSTRAINT_ATTR_ENTITY_B, ModelAPI_AttributeRefAttr::type());
23 }
24
25 void SketchPlugin_ConstraintDistance::execute()
26 {
27   boost::shared_ptr<ModelAPI_Data> aData = data();
28
29   boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr_A = 
30           boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
31   boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr_B = 
32           boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_B));
33
34   AttributeDoublePtr anAttribute =
35       boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
36
37   if (anAttr_A && anAttr_B && anAttribute->value() == 0)
38   {
39     FeaturePtr aFeature_A = anAttr_A->feature();
40     FeaturePtr aFeature_B = anAttr_B->feature();
41
42     double aValue = 40; // TODO
43     anAttribute->setValue(aValue);
44   }
45 }
46
47 const boost::shared_ptr<GeomAPI_Shape>&  SketchPlugin_ConstraintDistance::preview()
48 {
49   /// \todo Preview for distance constraint
50   return getPreview();
51 }
52