1 #include <SketchSolver_ConstraintTangent.h>
2 #include <SketchSolver_Group.h>
3 #include <SketchSolver_Error.h>
6 void SketchSolver_ConstraintTangent::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> anEntID;
18 getAttributes(aValue, anEntID);
19 if (!myErrorMsg.empty())
21 // Check the quantity of entities of each type and their order (arcs first)
24 Slvs_Entity anEntities[2];
25 myType = SLVS_C_CURVE_CURVE_TANGENT;
26 std::vector<Slvs_hEntity>::iterator anEntIter = anEntID.begin();
27 for (; anEntIter != anEntID.end(); anEntIter++) {
28 Slvs_Entity anEnt = myStorage->getEntity(*anEntIter);
29 if (anEnt.type == SLVS_E_LINE_SEGMENT) {
31 anEntities[1 + aNbLines] = anEnt;
33 myType = SLVS_C_ARC_LINE_TANGENT;
35 else if (anEnt.type == SLVS_E_ARC_OF_CIRCLE) {
37 anEntities[aNbArcs] = anEnt;
42 if (aNbLines + aNbArcs != 2) {
43 myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
45 } else if (aNbArcs < 1) {
46 myErrorMsg = SketchSolver_Error::INCORRECT_TANGENCY_ATTRIBUTE();
50 // It is necessary to identify which points of entities are coincident
51 int aSlvsOtherFlag = 0;
52 int aSlvsOther2Flag = 0;
53 // Obtain start and end points of entities
54 Slvs_hEntity aPointsToFind[4];
55 for (int i = 0; i < 2; i++) {
56 int aShift = anEntities[i].type == SLVS_E_ARC_OF_CIRCLE ? 1 : 0;
57 aPointsToFind[2*i] = anEntities[i].point[aShift];
58 aPointsToFind[2*i+1]= anEntities[i].point[aShift+1];
60 // Search coincident points
61 bool isPointFound = false;
62 for (int i = 0; i < 2 && !isPointFound; i++)
63 for (int j = 2; j < 4 && !isPointFound; j++)
64 if (myStorage->isCoincident(aPointsToFind[i], aPointsToFind[j])) {
66 aSlvsOther2Flag = j - 2;
70 // There is no coincident points between tangential objects. Generate error message
71 myErrorMsg = SketchSolver_Error::NO_COINCIDENT_POINTS();
75 Slvs_Constraint aConstraint = Slvs_MakeConstraint(SLVS_C_UNKNOWN, myGroup->getId(),
76 getType(), myGroup->getWorkplaneId(), aValue,
77 SLVS_E_UNKNOWN, SLVS_E_UNKNOWN, anEntities[0].h, anEntities[1].h);
78 aConstraint.other = aSlvsOtherFlag;
79 aConstraint.other2 = aSlvsOther2Flag;
80 aConstraint.h = myStorage->addConstraint(aConstraint);
81 mySlvsConstraints.push_back(aConstraint.h);