1 // File: SketchPlugin_ConstraintDistance.cpp
2 // Created: 08 May 2014
3 // Author: Artem ZHIDKOV
5 #include "SketchPlugin_ConstraintDistance.h"
7 #include <ModelAPI_AttributeDouble.h>
8 #include <ModelAPI_Data.h>
9 #include <SketchPlugin_Point.h>
11 SketchPlugin_ConstraintDistance::SketchPlugin_ConstraintDistance()
13 myAttrList.push_back(CONSTRAINT_ATTR_DISTANCE);
16 void SketchPlugin_ConstraintDistance::execute()
21 void SketchPlugin_ConstraintDistance::setAttributes(
22 const double theDistance,
23 const boost::shared_ptr<SketchPlugin_Feature> theEntityA,
24 const boost::shared_ptr<SketchPlugin_Feature> theEntityB)
26 // Assign the value of the distance
27 data()->addAttribute(CONSTRAINT_ATTR_DISTANCE, ModelAPI_AttributeDouble::type());
28 boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
29 data()->attribute(CONSTRAINT_ATTR_DISTANCE))->setValue(theDistance);
31 // Assign parameters of the constraint
32 std::string aPoints[2] = {CONSTRAINT_ATTR_POINT_A, CONSTRAINT_ATTR_POINT_B};
33 std::string anEntities[2] = {CONSTRAINT_ATTR_ENTITY_A, CONSTRAINT_ATTR_ENTITY_B};
37 // add entityA depending on its type
38 if (theEntityA->getKind() == SketchPlugin_Point().getKind())
39 aCurAttr = aPoints[aCurPt++];
41 aCurAttr = anEntities[aCurEnt++];
42 myAttrList.push_back(aCurAttr);
43 data()->addAttribute(aCurAttr, ModelAPI_AttributeReference::type());
44 boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(
45 data()->attribute(aCurAttr))->setValue(theEntityA);
46 // add entityB depending on its type
47 if (theEntityB->getKind() == SketchPlugin_Point().getKind())
48 aCurAttr = aPoints[aCurPt++];
50 aCurAttr = anEntities[aCurEnt++];
51 myAttrList.push_back(aCurAttr);
52 data()->addAttribute(aCurAttr, ModelAPI_AttributeReference::type());
53 boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(
54 data()->attribute(aCurAttr))->setValue(theEntityB);
57 void SketchPlugin_ConstraintDistance::setAttributes(
58 const double theDistance,
59 const boost::shared_ptr<ModelAPI_Attribute> thePoint,
60 const boost::shared_ptr<SketchPlugin_Feature> theEntity)
62 // Assign the value of the distance
63 data()->addAttribute(CONSTRAINT_ATTR_DISTANCE, ModelAPI_AttributeDouble::type());
64 boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
65 data()->attribute(CONSTRAINT_ATTR_DISTANCE))->setValue(theDistance);
67 // Assign reference to the first point
68 myAttrList.push_back(CONSTRAINT_ATTR_POINT_A);
69 data()->addAttribute(CONSTRAINT_ATTR_POINT_A, ModelAPI_AttributeRefAttr::type());
70 //boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
71 // data()->attribute(CONSTRAINT_ATTR_POINT_A))->setValue(thePoint);
73 // Assign reference to the entity
75 if (theEntity->getKind() == SketchPlugin_Point().getKind())
76 aCurAttr = CONSTRAINT_ATTR_POINT_B;
78 aCurAttr = CONSTRAINT_ATTR_ENTITY_A;
79 myAttrList.push_back(aCurAttr);
80 data()->addAttribute(aCurAttr, ModelAPI_AttributeReference::type());
81 boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(
82 data()->attribute(aCurAttr))->setValue(theEntity);
85 void SketchPlugin_ConstraintDistance::setAttributes(
86 const double theDistance,
87 const boost::shared_ptr<ModelAPI_Attribute> thePointA,
88 const boost::shared_ptr<ModelAPI_Attribute> thePointB)
90 // Assign the value of the distance
91 data()->addAttribute(CONSTRAINT_ATTR_DISTANCE, ModelAPI_AttributeDouble::type());
92 boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
93 data()->attribute(CONSTRAINT_ATTR_DISTANCE))->setValue(theDistance);
95 // Assign reference to the first point
96 myAttrList.push_back(CONSTRAINT_ATTR_POINT_A);
97 data()->addAttribute(CONSTRAINT_ATTR_POINT_A, ModelAPI_AttributeRefAttr::type());
98 //boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
99 // data()->attribute(CONSTRAINT_ATTR_POINT_A))->setValue(thePointA);
101 // Assign reference to the second point
102 myAttrList.push_back(CONSTRAINT_ATTR_POINT_B);
103 data()->addAttribute(CONSTRAINT_ATTR_POINT_B, ModelAPI_AttributeRefAttr::type());
104 //boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
105 // data()->attribute(CONSTRAINT_ATTR_POINT_B))->setValue(thePointB);
108 void SketchPlugin_ConstraintDistance::setAttributes(
109 const double theRadius,
110 const boost::shared_ptr<SketchPlugin_Feature> theCircle)
112 /// \todo Need to be implemented
115 void SketchPlugin_ConstraintDistance::setAttributes(
116 const double theDistance,
117 const boost::shared_ptr<SketchPlugin_Feature> thePointA,
118 const boost::shared_ptr<SketchPlugin_Feature> thePointB,
119 const boost::shared_ptr<SketchPlugin_Feature> theEntity)
121 /// \todo Need to be implemented. Possibly need to add points by their attributes