- double aRelCoord[2] = {0.0, 0.0}; // relative coordinates of point
- double anAbsCoord[2] = {0.0, 0.0}; // absolute coordinates of point
-
- std::list<Slvs_Constraint> aCoincident = myStorage->getConstraintsByType(SLVS_C_POINTS_COINCIDENT);
- std::list<Slvs_Constraint>::const_iterator aCoIt;
-
- // Update positions of all points to satisfy angles
- std::vector< std::vector<Slvs_hEntity> >::const_iterator aPointsIter = myPointsAndCopies.begin();
- std::vector<Slvs_hEntity>::const_iterator aCopyIter;
- for (; aPointsIter != myPointsAndCopies.end(); ++aPointsIter) {
- aCopyIter = aPointsIter->begin();
- const Slvs_Entity& anInitial = myStorage->getEntity(*aCopyIter);
- for (int i = 0; i < 2; i++)
- anAbsCoord[i] = myStorage->getParameter(anInitial.param[i]).val;
- getRelative(anAbsCoord[0], anAbsCoord[1], aRelCoord[0], aRelCoord[1]);
-
- // if the point is coincident with another one which is temporary fixed (moved by user),
- // we will update its position correspondingly
- Slvs_hConstraint aFixed;
- for (aCoIt = aCoincident.begin(); aCoIt != aCoincident.end(); ++aCoIt) {
- if ((aCoIt->ptA == anInitial.h && myInitialPoints.find(aCoIt->ptB) != myInitialPoints.end()) ||
- (aCoIt->ptB == anInitial.h && myInitialPoints.find(aCoIt->ptA) != myInitialPoints.end())) {
- Slvs_hEntity anOtherId = aCoIt->ptA == anInitial.h ? aCoIt->ptB : aCoIt->ptA;
- if (!myStorage->isTemporary(aFixed) &&
- myPointsJustUpdated.find(anOtherId) == myPointsJustUpdated.end())
- continue; // nothing to change
-
- const Slvs_Entity& anOtherPnt = myStorage->getEntity(anOtherId);
- for (int i = 0; i < 2; i++) {
- Slvs_Param anInitParam = myStorage->getParameter(anInitial.param[i]);
- const Slvs_Param& anOtherParam = myStorage->getParameter(anOtherPnt.param[i]);
- anInitParam.val = anOtherParam.val;
- myStorage->updateParameter(anInitParam);
- anAbsCoord[i] = anOtherParam.val;
- }
- getRelative(anAbsCoord[0], anAbsCoord[1], aRelCoord[0], aRelCoord[1]);
- }
- }
-
- // update copied points
- aCopyIter = aPointsIter->begin();
- for (++aCopyIter; aCopyIter != aPointsIter->end(); ++aCopyIter) {
- // transform coordinates
- transformRelative(aRelCoord[0], aRelCoord[1]);
- getAbsolute(aRelCoord[0], aRelCoord[1], anAbsCoord[0], anAbsCoord[1]);
-
- const Slvs_Entity& aTarget = myStorage->getEntity(*aCopyIter);
- for (int i = 0; i < 2; i++) {
- Slvs_Param aParam = myStorage->getParameter(aTarget.param[i]);
- aParam.val = anAbsCoord[i];
- myStorage->updateParameter(aParam);
- }
- }
- }
-
- std::list<Slvs_Constraint> aDiamConstr;
- for (aPointsIter = myCircsAndCopies.begin(); aPointsIter != myCircsAndCopies.end(); ++aPointsIter) {
- aCopyIter = aPointsIter->begin();
- const Slvs_Entity& anInitial = myStorage->getEntity(*aCopyIter);
- if (anInitial.type == SLVS_E_DISTANCE) {
- const Slvs_Param& anInitRad = myStorage->getParameter(anInitial.param[0]);
- for (++aCopyIter; aCopyIter != aPointsIter->end(); ++aCopyIter) {
- const Slvs_Entity& aCopy = myStorage->getEntity(*aCopyIter);
- Slvs_Param aCopyRad = myStorage->getParameter(aCopy.param[0]);
- aCopyRad.val = anInitRad.val;
- myStorage->updateParameter(aCopyRad);
- }
- } else if (anInitial.type == SLVS_E_ARC_OF_CIRCLE) {
- const Slvs_Entity& aCenterEnt = myStorage->getEntity(anInitial.point[0]);
- const Slvs_Entity& aStartEnt = myStorage->getEntity(anInitial.point[1]);
-
- if (aDiamConstr.empty())
- aDiamConstr = myStorage->getConstraintsByType(SLVS_C_DIAMETER);
- // Calculate diameter of initial arc
- double aDiam = 0.0;
- for (int i = 0; i < 2; i++) {
- double d = myStorage->getParameter(aStartEnt.param[i]).val -
- myStorage->getParameter(aCenterEnt.param[i]).val;
- aDiam += d * d;
- }
- aDiam = sqrt(aDiam) * 2.0;
- // Update the Diameter constraints of copied arcs
- for (++aCopyIter; aCopyIter != aPointsIter->end(); ++aCopyIter) {
- std::list<Slvs_Constraint>::iterator aDCIt = aDiamConstr.begin();
- for (; aDCIt != aDiamConstr.end(); ++aDCIt)
- if (aDCIt->entityA == *aCopyIter) {
- aDCIt->valA = aDiam;
- myStorage->updateConstraint(*aDCIt);
- aDiamConstr.erase(aDCIt);
- break;
- }
- }
- }
- }