X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FSketchSolver%2FSketchSolver_ConstraintMovement.cpp;h=7f4c8d78be74bc356fa3c967a41d612b9bbb1b0f;hb=9cc0e604ee4cbed8c99b916b659728f0f2dc3835;hp=030274ac2dcc831be74167f26a689dcb20acb1ab;hpb=6fb5c9e4214f528d9836d6e6cd82d5e9ba978f7c;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_ConstraintMovement.cpp b/src/SketchSolver/SketchSolver_ConstraintMovement.cpp index 030274ac2..7f4c8d78b 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMovement.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintMovement.cpp @@ -1,118 +1,117 @@ #include #include -#include +#include + +#include +#include +#include +#include + +#include -SketchSolver_ConstraintMovement::SketchSolver_ConstraintMovement(FeaturePtr theFeature) - : SketchSolver_ConstraintRigid(theFeature) -{ - process(); -} void SketchSolver_ConstraintMovement::process() { cleanErrorMsg(); - if (!myBaseFeature || !myStorage || myGroup == 0) { - /// TODO: Put error message here + if (!myBaseFeature || !myStorage || myGroupID == GID_UNKNOWN) { + // Not enough parameters are initialized return; } - if (!mySlvsConstraints.empty()) // some data is changed, update constraint - update(myBaseConstraint); - double aValue; - std::vector anEntities; - bool isFullyMoved; - getAttributes(aValue, anEntities, isFullyMoved); - if (!myErrorMsg.empty() || (myFeatureMap.empty() && myAttributeMap.empty())) + ParameterWrapperPtr aValue; + getAttributes(aValue, myMovedEntities); + if (!myErrorMsg.empty() || myMovedEntities.empty()) { + // Nothing to move, clear the feature to avoid changing its group + // after removing the Movement constraint. + myBaseFeature = FeaturePtr(); return; - - if (isFullyMoved) - fixFeature(); - else { - std::vector::iterator anEntIt = anEntities.begin(); - for (; anEntIt != anEntities.end(); ++anEntIt) - fixPoint(*anEntIt); } + + std::vector::iterator anEntIt = myMovedEntities.begin(); + for (; anEntIt != myMovedEntities.end(); ++anEntIt) + fixFeature(*anEntIt); } -void SketchSolver_ConstraintMovement::getAttributes( - double& theValue, - std::vector& theAttributes, - bool& theIsFullyMoved) +static std::list movedEntities( + EntityWrapperPtr theOld, StoragePtr theOldStorage, + EntityWrapperPtr theNew, StoragePtr theNewStorage) { - bool isComplexFeature = false; - theValue = 0.0; - theIsFullyMoved = true; - int aType = SLVS_E_UNKNOWN; // type of created entity - Slvs_hEntity anEntityID = SLVS_E_UNKNOWN; - anEntityID = myGroup->getFeatureId(myBaseFeature); - if (anEntityID == SLVS_E_UNKNOWN) { - anEntityID = changeEntity(myBaseFeature, aType); - if (anEntityID == SLVS_E_UNKNOWN) { - myErrorMsg = SketchSolver_Error::NOT_INITIALIZED(); - return; - } + bool isFullyMoved = true; + std::list aMoved; + if (theOld->isEqual(theNew)) + return aMoved; - // Check the entity is complex - Slvs_Entity anEntity = myStorage->getEntity(anEntityID); - if (anEntity.point[0] != SLVS_E_UNKNOWN) - isComplexFeature = true; - else // simple entity - theAttributes.push_back(anEntityID); + std::list anOldSubs = theOld->subEntities(); + std::list aNewSubs = theNew->subEntities(); + std::list::const_iterator anOldIt = anOldSubs.begin(); + std::list::const_iterator aNewIt = aNewSubs.begin(); + for (; anOldIt != anOldSubs.end() && aNewIt != aNewSubs.end(); ++anOldIt, ++aNewIt) { + std::list aMovedSubs = movedEntities( + *anOldIt, theOldStorage, *aNewIt, theNewStorage); + if ((*anOldIt)->type() == ENTITY_POINT && // check only the points to be moved (because arcs in PlaneGCS have scalar subs too) + (aMovedSubs.size() != 1 || aMovedSubs.front() != *anOldIt)) + isFullyMoved = false; + aMoved.insert(aMoved.end(), aMovedSubs.begin(), aMovedSubs.end()); } - else { - myFeatureMap[myBaseFeature] = anEntityID; - isComplexFeature = true; + if (isFullyMoved) { + aMoved.clear(); + aMoved.push_back(theOld); } + return aMoved; +} - if (isComplexFeature) { - std::list aPoints = - myBaseFeature->data()->attributes(GeomDataAPI_Point2D::typeId()); - std::list::iterator anIt = aPoints.begin(); - for (; anIt != aPoints.end(); ++anIt) { - Slvs_hEntity anAttr = myGroup->getAttributeId(*anIt); - - // Check the attribute changes coordinates - std::shared_ptr aPt = - std::dynamic_pointer_cast(*anIt); - if (isMoved(aPt, anAttr)) { - theAttributes.push_back(anAttr); - // update point coordinates - Slvs_Entity anAttrEnt = myStorage->getEntity(anAttr); - double aNewPos[2] = {aPt->x(), aPt->y()}; - for (int i = 0; i < 2; i++) { - Slvs_Param aParam = myStorage->getParameter(anAttrEnt.param[i]); - aParam.val = aNewPos[i]; - myStorage->updateParameter(aParam); - } - } - else - theIsFullyMoved = false; - } - } - // Leave only points which are used in constraints - if (myStorage->isUsedByConstraints(anEntityID)) +void SketchSolver_ConstraintMovement::getAttributes( + ParameterWrapperPtr& theValue, + std::vector& theAttributes) +{ + // There will be build entities, according to the fixed feature, in the separate storage + // to check whether any point is moved + BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder(); + StoragePtr anOtherStorage = aBuilder->createStorage(myGroupID); + anOtherStorage->setSketch(myStorage->sketch()); + if (!anOtherStorage->update(myBaseFeature, myGroupID)) return; - std::vector::iterator anIt = theAttributes.begin(); - while (anIt != theAttributes.end()) { - if (myStorage->isUsedByConstraints(*anIt)) - ++anIt; - else { - int aShift = anIt - theAttributes.begin(); - theAttributes.erase(anIt); - anIt = theAttributes.begin() + aShift; + EntityWrapperPtr aNewEntity = anOtherStorage->entity(myBaseFeature); + EntityWrapperPtr anOldEntity = myStorage->entity(myBaseFeature); + + std::list aMoved; + if (aNewEntity && anOldEntity) + aMoved = movedEntities(anOldEntity, myStorage, aNewEntity, anOtherStorage); + else { + // get attributes moved + std::list anAttrList = + myBaseFeature->data()->attributes(GeomDataAPI_Point2D::typeId()); + std::list::const_iterator anIt = anAttrList.begin(); + for (; anIt != anAttrList.end(); ++anIt) { + aNewEntity = anOtherStorage->entity(*anIt); + anOldEntity = myStorage->entity(*anIt); + if (!aNewEntity || !anOldEntity) + continue; + std::list aMovedAttr = movedEntities( + anOldEntity, myStorage, aNewEntity, anOtherStorage); + aMoved.insert(aMoved.end(), aMovedAttr.begin(), aMovedAttr.end()); } } + theAttributes.clear(); + theAttributes.insert(theAttributes.begin(), aMoved.begin(), aMoved.end()); } -bool SketchSolver_ConstraintMovement::isMoved( - std::shared_ptr thePoint, Slvs_hEntity theEntity) +bool SketchSolver_ConstraintMovement::remove() { - Slvs_Entity anAttrEnt = myStorage->getEntity(theEntity); - double aDeltaX = myStorage->getParameter(anAttrEnt.param[0]).val; - double aDeltaY = myStorage->getParameter(anAttrEnt.param[1]).val; - aDeltaX -= thePoint->x(); - aDeltaY -= thePoint->y(); - return aDeltaX * aDeltaX + aDeltaY * aDeltaY >= tolerance * tolerance; + cleanErrorMsg(); + // Move fixed entities back to the current group + std::vector::iterator aMoveIt = myMovedEntities.begin(); + for (; aMoveIt != myMovedEntities.end(); ++aMoveIt) { + if ((*aMoveIt)->baseAttribute()) + myStorage->update((*aMoveIt)->baseAttribute(), myGroupID); + else if ((*aMoveIt)->baseFeature()) + myStorage->update((*aMoveIt)->baseFeature(), myGroupID); + } + + // Remove base feature + if (myBaseFeature) + myStorage->removeEntity(myBaseFeature); + return true; }