- const std::string& aConstraintKind = theConstraint->getKind();
- // Constraint for coincidence of two points
- if (aConstraintKind.compare(SketchPlugin_ConstraintCoincidence::ID()) == 0) {
- int anAttrPos = 0;
- // Verify the constraint has only two attributes and they are points
- int aPt2d = 0; // bit-mapped field, each bit indicates whether the attribute is 2D point
- int aPt3d = 0; // bit-mapped field, the same information for 3D points
- for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++) {
- std::shared_ptr<ModelAPI_Attribute> anAttr =
- aConstrData->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr));
- if (!anAttr)
- continue;
- switch (typeOfAttribute(anAttr)) {
- case POINT2D: // the attribute is a 2D point
- aPt2d |= (1 << indAttr);
- myAttributesList[anAttrPos++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr);
- break;
- case POINT3D: // the attribute is a 3D point
- aPt3d |= (1 << indAttr);
- myAttributesList[anAttrPos++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr);
- break;
- default:
- // Attribute neither 2D nor 3D point is not supported by this type of constraint
- return getType();
- }
- }
- // The constrained points should be in first and second positions,
- // so the expected value of aPt2d or aPt3d is 3
- if ((aPt2d == 3 && aPt3d == 0) || (aPt2d == 0 && aPt3d == 3))
- myType = SLVS_C_POINTS_COINCIDENT;
- // Constraint parameters are wrong
- return getType();
- }
-
- // Constraint for distance between point and another entity
- if (aConstraintKind.compare(SketchPlugin_ConstraintDistance::ID()) == 0) {
- int aNbPoints = 0;
- int aNbEntities = 0;
- for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++) {
- std::shared_ptr<ModelAPI_Attribute> anAttr =
- aConstrData->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr));
- switch (typeOfAttribute(anAttr)) {
- case POINT2D:
- case POINT3D:
- myAttributesList[aNbPoints++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr);
- break;
- case LINE:
- // entities are placed starting from SketchPlugin_Constraint::ENTITY_C() attribute
- myAttributesList[2 + aNbEntities++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr);
- myType = SLVS_C_PT_LINE_DISTANCE;
- break;
- }
- }
- // Verify the correctness of constraint arguments
- if (aNbPoints == 2 && aNbEntities == 0)
- myType = SLVS_C_PT_PT_DISTANCE;
- else if (aNbPoints != 1 || aNbEntities != 1)
- myType = SLVS_C_UNKNOWN;
- return getType();
- }
-
- // Constraint for the given length of a line
- if (aConstraintKind.compare(SketchPlugin_ConstraintLength::ID()) == 0) {
- int aNbLines = 0;
- for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++) {
- std::shared_ptr<ModelAPI_Attribute> anAttr =
- aConstrData->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr));
- if (typeOfAttribute(anAttr) == LINE)
- myAttributesList[aNbLines++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr);
- }
- if (aNbLines == 1)
- myType = SLVS_C_PT_PT_DISTANCE;
- return getType();
- }
+SketchSolver_ConstraintType SketchSolver_Constraint::TYPE(ConstraintPtr theConstraint)
+{
+ const std::string& aType = theConstraint->getKind();
+ if (aType == SketchPlugin_ConstraintCoincidence::ID() ||
+ aType == SketchPlugin_ConstraintCoincidenceInternal::ID())
+ return CONSTRAINT_COINCIDENCE;
+ else if (aType == SketchPlugin_ConstraintRigid::ID())
+ return CONSTRAINT_FIXED;
+ else if (aType == SketchPlugin_ConstraintHorizontal::ID())
+ return CONSTRAINT_HORIZONTAL;
+ else if (aType == SketchPlugin_ConstraintVertical::ID())
+ return CONSTRAINT_VERTICAL;
+ else if (aType == SketchPlugin_ConstraintAngle::ID())
+ return CONSTRAINT_ANGLE;
+ else if (aType == SketchPlugin_ConstraintDistance::ID())
+ return CONSTRAINT_DISTANCE;
+ else if (aType == SketchPlugin_ConstraintEqual::ID())
+ return CONSTRAINT_EQUAL;
+ else if (aType == SketchPlugin_ConstraintLength::ID())
+ return CONSTRAINT_PT_PT_DISTANCE;
+ else if (aType == SketchPlugin_ConstraintMirror::ID())
+ return CONSTRAINT_SYMMETRIC;
+ else if (aType == SketchPlugin_ConstraintParallel::ID())
+ return CONSTRAINT_PARALLEL;
+ else if (aType == SketchPlugin_ConstraintPerpendicular::ID())
+ return CONSTRAINT_PERPENDICULAR;
+ else if (aType == SketchPlugin_ConstraintRadius::ID())
+ return CONSTRAINT_RADIUS;
+ else if (aType == SketchPlugin_ConstraintTangent::ID())
+ return CONSTRAINT_TANGENT;
+ else if (aType == SketchPlugin_ConstraintCollinear::ID())
+ return CONSTRAINT_COLLINEAR;
+ else if (aType == SketchPlugin_ConstraintMiddle::ID())
+ return CONSTRAINT_MIDDLE_POINT;
+ return CONSTRAINT_UNKNOWN;
+}