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