1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include <SketchSolver_ConstraintEqual.h>
4 #include <SketchSolver_Error.h>
6 #include <ModelAPI_AttributeRefAttr.h>
7 #include <SketchPlugin_Line.h>
9 void SketchSolver_ConstraintEqual::getAttributes(
10 EntityWrapperPtr& theValue,
11 std::vector<EntityWrapperPtr>& theAttributes)
13 SketchSolver_Constraint::getAttributes(theValue, theAttributes);
14 if (!myErrorMsg.empty() || !theAttributes[2] || !theAttributes[3]) {
15 theAttributes.clear();
19 // Check the quantity of entities of each type
23 bool isArcFirst = false; // in line-arc equivalence, the line should be first
24 std::vector<EntityWrapperPtr>::iterator anAttrIt = theAttributes.begin() + 2;
25 for (; anAttrIt != theAttributes.end(); ++anAttrIt) {
26 SketchSolver_EntityType aType = (*anAttrIt)->type();
27 if (aType == ENTITY_LINE)
29 else if (aType == ENTITY_CIRCLE)
31 else if (aType == ENTITY_ARC) {
33 isArcFirst = (aNbLines == 0);
37 if (aNbLines + aNbArcs + aNbCircs != 2 ||
38 (aNbLines == aNbCircs && aNbArcs == 0)) {
39 myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
45 myType = CONSTRAINT_EQUAL_RADIUS;
48 myType = CONSTRAINT_EQUAL_LINE_ARC;
49 if (isArcFirst) { // change the order of arc and line
50 EntityWrapperPtr aTmp = theAttributes[2];
51 theAttributes[2] = theAttributes[3];
52 theAttributes[3] = aTmp;
56 myType = CONSTRAINT_EQUAL_LINES;
58 AttributeRefAttrPtr aRefLine1 =
59 myBaseConstraint->refattr(SketchPlugin_Constraint::ENTITY_A());
60 FeaturePtr aLine1 = ModelAPI_Feature::feature(aRefLine1->object());
62 // store length of first line as a value for constraint
63 // (will be used to make equal lengths of lines)
64 theValue = myStorage->entity(aLine1->attribute(SketchPlugin_Line::LENGTH_ID()));