1 // Name : SketchAPI_Constraint.cpp
5 // 08/08/16 - Artem ZHIDKOV - Creation of the file
7 #include "SketchAPI_Constraint.h"
9 #include <ModelHighAPI_Dumper.h>
10 #include <ModelHighAPI_Tools.h>
12 #include <SketchPlugin_Constraint.h>
13 #include <SketchPlugin_ConstraintAngle.h>
14 #include <SketchPlugin_ConstraintCoincidence.h>
15 #include <SketchPlugin_ConstraintCollinear.h>
16 #include <SketchPlugin_ConstraintDistance.h>
17 #include <SketchPlugin_ConstraintEqual.h>
18 #include <SketchPlugin_ConstraintHorizontal.h>
19 #include <SketchPlugin_ConstraintLength.h>
20 #include <SketchPlugin_ConstraintMiddle.h>
21 #include <SketchPlugin_ConstraintParallel.h>
22 #include <SketchPlugin_ConstraintPerpendicular.h>
23 #include <SketchPlugin_ConstraintRadius.h>
24 #include <SketchPlugin_ConstraintRigid.h>
25 #include <SketchPlugin_ConstraintTangent.h>
26 #include <SketchPlugin_ConstraintVertical.h>
28 SketchAPI_Constraint::SketchAPI_Constraint(
29 const std::shared_ptr<ModelAPI_Feature> & theFeature)
30 : ModelHighAPI_Interface(theFeature)
32 ConstraintPtr aConstraint = std::dynamic_pointer_cast<SketchPlugin_Constraint>(theFeature);
37 SketchAPI_Constraint::~SketchAPI_Constraint()
41 bool SketchAPI_Constraint::initialize()
44 throwException("Constraint exception: The feature is NULL.");
50 static const std::string& constraintTypeToSetter(const std::string& theType)
52 if (theType == SketchPlugin_ConstraintCoincidence::ID()) {
53 static const std::string COINCIDENCE_SETTER("setCoincident");
54 return COINCIDENCE_SETTER;
56 if (theType == SketchPlugin_ConstraintAngle::ID()) {
57 static const std::string ANGLE_SETTER("setAngle");
60 if (theType == SketchPlugin_ConstraintCollinear::ID()) {
61 static const std::string COLLINEAR_SETTER("setCollinear");
62 return COLLINEAR_SETTER;
64 if (theType == SketchPlugin_ConstraintDistance::ID()) {
65 static const std::string DISTANCE_SETTER("setDistance");
66 return DISTANCE_SETTER;
68 if (theType == SketchPlugin_ConstraintEqual::ID()) {
69 static const std::string EQUAL_SETTER("setEqual");
72 if (theType == SketchPlugin_ConstraintHorizontal::ID()) {
73 static const std::string HORIZONTAL_SETTER("setHorizontal");
74 return HORIZONTAL_SETTER;
76 if (theType == SketchPlugin_ConstraintLength::ID()) {
77 static const std::string LENGTH_SETTER("setLength");
80 if (theType == SketchPlugin_ConstraintMiddle::ID()) {
81 static const std::string MIDDLE_SETTER("setMiddlePoint");
84 if (theType == SketchPlugin_ConstraintParallel::ID()) {
85 static const std::string PARALLEL_SETTER("setParallel");
86 return PARALLEL_SETTER;
88 if (theType == SketchPlugin_ConstraintPerpendicular::ID()) {
89 static const std::string PERPENDICULAR_SETTER("setPerpendicular");
90 return PERPENDICULAR_SETTER;
92 if (theType == SketchPlugin_ConstraintRadius::ID()) {
93 static const std::string RADIUS_SETTER("setRadius");
96 if (theType == SketchPlugin_ConstraintRigid::ID()) {
97 static const std::string FIXED_SETTER("setFixed");
100 if (theType == SketchPlugin_ConstraintTangent::ID()) {
101 static const std::string TANGENT_SETTER("setTangent");
102 return TANGENT_SETTER;
104 if (theType == SketchPlugin_ConstraintVertical::ID()) {
105 static const std::string VERTICAL_SETTER("setVertical");
106 return VERTICAL_SETTER;
109 static const std::string DUMMY;
113 void SketchAPI_Constraint::dump(ModelHighAPI_Dumper& theDumper) const
115 ConstraintPtr aConstraint = std::dynamic_pointer_cast<SketchPlugin_Constraint>(feature());
117 return; // dump constraints only
119 const std::string& aSetter = constraintTypeToSetter(aConstraint->getKind());
121 return; // incorrect constraint type
123 const std::string& aSketchName = theDumper.parentName(aConstraint);
124 theDumper << aConstraint << " = " << aSketchName << "." << aSetter << "(";
126 bool isFirstAttr = true;
127 for (int i = 0; i < CONSTRAINT_ATTR_SIZE; ++i) {
128 AttributeRefAttrPtr aRefAttr = aConstraint->refattr(SketchPlugin_Constraint::ATTRIBUTE(i));
129 if (aRefAttr && aRefAttr->isInitialized()) {
130 theDumper << (isFirstAttr ? "" : ", ") << aRefAttr;
135 AttributeDoublePtr aValueAttr = aConstraint->real(SketchPlugin_Constraint::VALUE());
136 if (aValueAttr && aValueAttr->isInitialized())
137 theDumper << ", " << aValueAttr;
139 theDumper << ")" << std::endl;