1 // File: SketchPlugin_ConstraintDistance.cpp
2 // Created: 23 May 2014
3 // Author: Artem ZHIDKOV
5 #include "SketchPlugin_ConstraintDistance.h"
7 #include "GeomDataAPI_Point2D.h"
9 #include <ModelAPI_AttributeDouble.h>
10 #include <ModelAPI_Data.h>
11 #include <SketchPlugin_Point.h>
13 SketchPlugin_ConstraintDistance::SketchPlugin_ConstraintDistance()
17 void SketchPlugin_ConstraintDistance::initAttributes()
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());
25 void SketchPlugin_ConstraintDistance::execute()
27 boost::shared_ptr<ModelAPI_Data> aData = data();
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));
34 AttributeDoublePtr anAttr_Value =
35 boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
36 if (anAttr_A && anAttr_B && !anAttr_Value->isInitialized())
38 FeaturePtr aFeature_A = anAttr_A->feature();
39 FeaturePtr aFeature_B = anAttr_B->feature();
41 double aValue = 40; // TODO
42 anAttr_Value->setValue(aValue);
46 const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_ConstraintDistance::preview()
48 /// \todo Preview for distance constraint