- Slvs_Constraint aConstraint;
- // Get coordinates of mirror line points for speed up
- double aStartEnd[4];
- for (int i = 0; i < 2; i++) {
- Slvs_Entity aPoint = myStorage->getEntity(aMirrorLine.point[i]);
- for (int j = 0; j < 2; j++)
- aStartEnd[2*i+j] = myStorage->getParameter(aPoint.param[j]).val;
- }
-
- std::vector<Slvs_Entity>::iterator aBaseIter = aBaseList.begin();
- std::vector<Slvs_Entity>::iterator aMirrorIter = aMirrorList.begin();
- for (; aBaseIter != aBaseList.end(); aBaseIter++, aMirrorIter++) {
- // Make aMirrorEnt parameters to be symmetric with aBaseEnt
- makeMirrorEntity(*aBaseIter, *aMirrorIter, aStartEnd);
-
- if (aBaseIter->type == SLVS_E_POINT_IN_2D) {
- aConstraint = Slvs_MakeConstraint(
- SLVS_E_UNKNOWN, myGroup->getId(), getType(), myGroup->getWorkplaneId(),
- 0.0, aBaseIter->h, aMirrorIter->h, aMirrorLine.h, SLVS_E_UNKNOWN);
- aConstraint.h = myStorage->addConstraint(aConstraint);
- mySlvsConstraints.push_back(aConstraint.h);
- } else if (aBaseIter->type == SLVS_E_LINE_SEGMENT) {
- for (int i = 0; i < 2; i++) {
- aConstraint = Slvs_MakeConstraint(
- SLVS_E_UNKNOWN, myGroup->getId(), getType(), myGroup->getWorkplaneId(), 0.0,
- aBaseIter->point[i], aMirrorIter->point[i], aMirrorLine.h, SLVS_E_UNKNOWN);
- aConstraint.h = myStorage->addConstraint(aConstraint);
- mySlvsConstraints.push_back(aConstraint.h);
- }
- } else if (aBaseIter->type == SLVS_E_CIRCLE) {
- aConstraint = Slvs_MakeConstraint(
- SLVS_E_UNKNOWN, myGroup->getId(), getType(), myGroup->getWorkplaneId(), 0.0,
- aBaseIter->point[0], aMirrorIter->point[0], aMirrorLine.h, SLVS_E_UNKNOWN);
- aConstraint.h = myStorage->addConstraint(aConstraint);
- mySlvsConstraints.push_back(aConstraint.h);
- // Additional constraint for equal radii
- Slvs_Constraint anEqRadConstr = Slvs_MakeConstraint(
- SLVS_E_UNKNOWN, myGroup->getId(), SLVS_C_EQUAL_RADIUS, myGroup->getWorkplaneId(),
- 0.0, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN, aBaseIter->h, aMirrorIter->h);
- anEqRadConstr.h = myStorage->addConstraint(anEqRadConstr);
- mySlvsConstraints.push_back(anEqRadConstr.h);
- } else if (aBaseIter->type == SLVS_E_ARC_OF_CIRCLE) {
- // Workaround to avoid problems in SolveSpace.
- // The symmetry of two arcs will be done using symmetry of three points on these arcs:
- // start point, end point, and any other point on the arc
- Slvs_hEntity aBaseArcPoints[3] = {
- aBaseIter->point[1],
- aBaseIter->point[2],
- SLVS_E_UNKNOWN};
- Slvs_hEntity aMirrorArcPoints[3] = { // indices of points of arc, center corresponds center, first point corresponds last point
- aMirrorIter->point[2],
- aMirrorIter->point[1],
- SLVS_E_UNKNOWN};
-
- Slvs_Entity aBothArcs[2] = {*aBaseIter, *aMirrorIter};
- Slvs_hEntity aBothMiddlePoints[2];
- for (int i = 0; i < 2; i++) {
- double x, y;
- calculateMiddlePoint(aBothArcs[i], 0.5, x, y);
- Slvs_Param aParamX = Slvs_MakeParam(SLVS_E_UNKNOWN, myGroup->getId(), x);
- Slvs_Param aParamY = Slvs_MakeParam(SLVS_E_UNKNOWN, myGroup->getId(), y);
- aParamX.h = myStorage->addParameter(aParamX);
- aParamY.h = myStorage->addParameter(aParamY);
- Slvs_Entity aPoint = Slvs_MakePoint2d(SLVS_E_UNKNOWN, myGroup->getId(),
- myGroup->getWorkplaneId(), aParamX.h, aParamY.h);
- aBothMiddlePoints[i] = myStorage->addEntity(aPoint);
- // additional constraint point-on-curve
- Slvs_Constraint aPonCircConstr = Slvs_MakeConstraint(
- SLVS_E_UNKNOWN, myGroup->getId(), SLVS_C_PT_ON_CIRCLE, myGroup->getWorkplaneId(),
- 0.0, aBothMiddlePoints[i], SLVS_E_UNKNOWN, aBothArcs[i].h, SLVS_E_UNKNOWN);
- aPonCircConstr.h = myStorage->addConstraint(aPonCircConstr);
- mySlvsConstraints.push_back(aPonCircConstr.h);
- }
-
- aBaseArcPoints[2] = aBothMiddlePoints[0];
- aMirrorArcPoints[2] = aBothMiddlePoints[1];
- for (int ind = 0; ind < 3; ind++) {
- Slvs_Constraint aConstraint = Slvs_MakeConstraint(
- SLVS_E_UNKNOWN, myGroup->getId(), getType(), myGroup->getWorkplaneId(), 0.0,
- aBaseArcPoints[ind], aMirrorArcPoints[ind], aMirrorLine.h, SLVS_E_UNKNOWN);
- aConstraint.h = myStorage->addConstraint(aConstraint);
- mySlvsConstraints.push_back(aConstraint.h);
- }
+ std::list<ConstraintWrapperPtr> aNewConstraints;
+ SketchSolver_ConstraintType aConstrType = getType();
+ BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
+ std::list<ConstraintWrapperPtr> aMirConstrList;
+
+ std::vector<EntityWrapperPtr>::iterator aBIt = aBaseList.begin();
+ std::vector<EntityWrapperPtr>::iterator aMIt = aMirrorList.begin();
+ for (; aBIt != aBaseList.end(); ++aBIt, ++aMIt) {
+ if ((*aBIt)->type() == ENTITY_ARC) {
+ // add new points on arcs and mirror them
+ EntityWrapperPtr aBasePnt = myStorage->calculateMiddlePoint(*aBIt, 0.5);
+ EntityWrapperPtr aMirrPnt = myStorage->calculateMiddlePoint(*aMIt, 0.5);
+ // point on base arc
+ aNewConstraints = aBuilder->createConstraint(myBaseConstraint, myGroupID, mySketchID,
+ CONSTRAINT_PT_ON_CIRCLE, 0.0, aBasePnt, EntityWrapperPtr(), *aBIt);
+ aMirConstrList.insert(aMirConstrList.end(), aNewConstraints.begin(), aNewConstraints.end());
+ // point on mirrored arc
+ aNewConstraints = aBuilder->createConstraint(myBaseConstraint, myGroupID, mySketchID,
+ CONSTRAINT_PT_ON_CIRCLE, 0.0, aMirrPnt, EntityWrapperPtr(), *aMIt);
+ aMirConstrList.insert(aMirConstrList.end(), aNewConstraints.begin(), aNewConstraints.end());
+ // mirror these points
+ aNewConstraints = aBuilder->createConstraint(myBaseConstraint, myGroupID, mySketchID,
+ aConstrType, 0.0, aBasePnt, aMirrPnt, aMirrorLine);
+ aMirConstrList.insert(aMirConstrList.end(), aNewConstraints.begin(), aNewConstraints.end());