1 #include <SketchSolver_ConstraintEqual.h>
2 #include <SketchSolver_Group.h>
3 #include <SketchSolver_Error.h>
6 void SketchSolver_ConstraintEqual::process()
9 if (!myBaseConstraint || !myStorage || myGroup == 0) {
10 /// TODO: Put error message here
13 if (!mySlvsConstraints.empty()) // some data is changed, update constraint
14 update(myBaseConstraint);
17 std::vector<Slvs_hEntity> anEntities;
18 getAttributes(aValue, anEntities);
19 if (!myErrorMsg.empty())
22 // Check the quantity of entities of each type
26 bool isArcFirst = false; // in line-arc equivalence, the line should be first
27 std::vector<Slvs_hEntity>::iterator anEntIter = anEntities.begin();
28 for (; anEntIter != anEntities.end(); anEntIter++) {
29 Slvs_Entity anEnt = myStorage->getEntity(*anEntIter);
30 if (anEnt.type == SLVS_E_LINE_SEGMENT)
32 else if (anEnt.type == SLVS_E_CIRCLE)
34 else if (anEnt.type == SLVS_E_ARC_OF_CIRCLE) {
36 isArcFirst = (aNbLines == 0);
40 if (aNbLines + aNbArcs + aNbCircs != 2 ||
41 (aNbLines == aNbCircs && aNbArcs == 0)) {
42 myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
48 myType = SLVS_C_EQUAL_RADIUS;
51 myType = SLVS_C_EQUAL_LINE_ARC_LEN;
52 if (isArcFirst) { // change the order of arc and line
53 Slvs_hEntity aTmp = anEntities[2];
54 anEntities[2] = anEntities[3];
59 myType = SLVS_C_EQUAL_LENGTH_LINES;
63 Slvs_Constraint aConstraint = Slvs_MakeConstraint(SLVS_C_UNKNOWN, myGroup->getId(),
64 getType(), myGroup->getWorkplaneId(), aValue,
65 anEntities[0], anEntities[1], anEntities[2], anEntities[3]);
66 aConstraint.h = myStorage->addConstraint(aConstraint);
67 mySlvsConstraints.push_back(aConstraint.h);