X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FSketchSolver_ConstraintMovement.cpp;h=bbaf6ac24a33074bf48e4a4917683609b8b2761e;hb=d5b5ce2284869d8b97ce638502c58c810bbeb0c7;hp=85542cb42c7cad8c36e86a18530dc18c8479da23;hpb=29d446f4dd2969d80087745fe44adb5638d13de7;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_ConstraintMovement.cpp b/src/SketchSolver/SketchSolver_ConstraintMovement.cpp index 85542cb42..bbaf6ac24 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMovement.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintMovement.cpp @@ -1,7 +1,30 @@ +// Copyright (C) 2017 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or +// email : webmaster.salome@opencascade.com +// + #include #include #include +#include +#include + #include #include #include @@ -9,90 +32,197 @@ #include +#include + + +SketchSolver_ConstraintMovement::SketchSolver_ConstraintMovement(FeaturePtr theFeature) + : SketchSolver_ConstraintFixed(ConstraintPtr()), + myMovedFeature(theFeature), + mySimpleMove(true) +{ +} + +SketchSolver_ConstraintMovement::SketchSolver_ConstraintMovement(AttributePtr thePoint) + : SketchSolver_ConstraintFixed(ConstraintPtr()), + myDraggedPoint(thePoint), + mySimpleMove(true) +{ + myMovedFeature = ModelAPI_Feature::feature(thePoint->owner()); +} + +void SketchSolver_ConstraintMovement::blockEvents(bool isBlocked) +{ + if (myMovedFeature) + myMovedFeature->data()->blockSendAttributeUpdated(isBlocked); +} void SketchSolver_ConstraintMovement::process() { cleanErrorMsg(); - if (!myBaseFeature || !myStorage || myGroupID == GID_UNKNOWN) { + if (!myMovedFeature || !myStorage) { // Not enough parameters are initialized return; } - ParameterWrapperPtr aValue; - getAttributes(aValue, myMovedEntities); - if (!myErrorMsg.empty() || myMovedEntities.empty()) { + mySolverConstraint = initMovement(); + if (!myErrorMsg.empty() || !mySolverConstraint) { // Nothing to move, clear the feature to avoid changing its group // after removing the Movement constraint. - myBaseFeature = FeaturePtr(); + myMovedFeature = FeaturePtr(); return; } - - std::vector::iterator anEntIt = myMovedEntities.begin(); - for (; anEntIt != myMovedEntities.end(); ++anEntIt) - fixFeature(*anEntIt); + myStorage->addMovementConstraint(mySolverConstraint); } -static std::list movedEntities( - EntityWrapperPtr theOld, StoragePtr theOldStorage, - EntityWrapperPtr theNew, StoragePtr theNewStorage) +static bool isSimpleMove(FeaturePtr theMovedFeature, AttributePtr theDraggedPoint) +{ + bool isSimple = true; +#ifdef CHANGE_RADIUS_WHILE_MOVE + if (theMovedFeature->getKind() == SketchPlugin_Circle::ID()) + isSimple = (theDraggedPoint.get() != 0); + else if (theMovedFeature->getKind() == SketchPlugin_Arc::ID()) { + isSimple = (theDraggedPoint.get() != 0 && + theDraggedPoint->id() == SketchPlugin_Arc::CENTER_ID()); + } +#endif + return isSimple; +} + +ConstraintWrapperPtr SketchSolver_ConstraintMovement::initMovement() { - bool isFullyMoved = true; - std::list aMoved; - if (theOld->isEqual(theNew)) - return aMoved; - - 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 (aMovedSubs.size() != 1 || aMovedSubs.front() != *anOldIt) - isFullyMoved = false; - aMoved.insert(aMoved.end(), aMovedSubs.begin(), aMovedSubs.end()); + ConstraintWrapperPtr aConstraint; + + // if the feature is copy, do not move it + std::shared_ptr aSketchFeature = + std::dynamic_pointer_cast(myMovedFeature); + if (!aSketchFeature || aSketchFeature->isCopy()) { + myStorage->setNeedToResolve(true); + return aConstraint; } - if (isFullyMoved) { - aMoved.clear(); - aMoved.push_back(theOld); + + EntityWrapperPtr anEntity = + myDraggedPoint ? myStorage->entity(myDraggedPoint) : myStorage->entity(myMovedFeature); + if (!anEntity) { + myStorage->update(myMovedFeature, true); + anEntity = + myDraggedPoint ? myStorage->entity(myDraggedPoint) : myStorage->entity(myMovedFeature); + if (!anEntity) + return aConstraint; + } + + mySimpleMove = isSimpleMove(myMovedFeature, myDraggedPoint); + + if (mySimpleMove) + aConstraint = fixFeature(anEntity); + else { + if (myDraggedPoint) // start or end point of arc has been moved + aConstraint = fixArcExtremity(anEntity); + else // arc or circle has been moved + aConstraint = fixPointOnCircle(anEntity); } - return aMoved; + + return aConstraint; } +ConstraintWrapperPtr SketchSolver_ConstraintMovement::fixArcExtremity( + const EntityWrapperPtr& theArcExtremity) +{ + static const int nbParams = 4; + myFixedValues.reserve(nbParams); // moved point and center of arc + + EdgeWrapperPtr aCircularEntity = std::dynamic_pointer_cast( + myStorage->entity(myMovedFeature)); + std::shared_ptr anArc = + std::dynamic_pointer_cast(aCircularEntity->entity()); + + PointWrapperPtr aPoint = + std::dynamic_pointer_cast(theArcExtremity); + + double* aParams[nbParams] = { aPoint->point()->x, aPoint->point()->y, + anArc->center.x, anArc->center.y }; + + std::list aConstraints; + for (int i = 0; i < nbParams; ++i) { + myFixedValues.push_back(*aParams[i]); + GCSConstraintPtr aNewConstraint(new GCS::ConstraintEqual(&myFixedValues[i], aParams[i])); + aNewConstraint->rescale(0.01); + aConstraints.push_back(aNewConstraint); + } -void SketchSolver_ConstraintMovement::getAttributes( - ParameterWrapperPtr& theValue, - std::vector& theAttributes) + return ConstraintWrapperPtr( + new PlaneGCSSolver_ConstraintWrapper(aConstraints, getType())); +} + +ConstraintWrapperPtr SketchSolver_ConstraintMovement::fixPointOnCircle( + const EntityWrapperPtr& theCircular) { - // 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; - EntityWrapperPtr aNewEntity = anOtherStorage->entity(myBaseFeature); - EntityWrapperPtr anOldEntity = myStorage->entity(myBaseFeature); + static const double scale = 0.01; + static const int nbParams = 4; + myFixedValues.reserve(nbParams); // moved point and center of arc/circle - 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()); - } + EdgeWrapperPtr aCircularEntity = + std::dynamic_pointer_cast(theCircular); + std::shared_ptr aCircular = + std::dynamic_pointer_cast(aCircularEntity->entity()); + + // initialize fixed values + myFixedValues.push_back(*aCircular->center.x + *aCircular->rad); + myFixedValues.push_back(*aCircular->center.y); + myFixedValues.push_back(*aCircular->center.x); + myFixedValues.push_back(*aCircular->center.y); + + // create a moved point + GCS::Point aPointOnCircle; + aPointOnCircle.x = &myFixedValues[0]; + aPointOnCircle.y = &myFixedValues[1]; + + std::list aConstraints; + // point-on-circle + GCSConstraintPtr aNewConstraint( + new GCS::ConstraintP2PDistance(aPointOnCircle, aCircular->center, aCircular->rad)); + aNewConstraint->rescale(scale); + aConstraints.push_back(aNewConstraint); + // fixed center (x) + aNewConstraint = GCSConstraintPtr( + new GCS::ConstraintEqual(&myFixedValues[2], aCircular->center.x)); + aNewConstraint->rescale(scale); + aConstraints.push_back(aNewConstraint); + // fixed center (y) + aNewConstraint = GCSConstraintPtr( + new GCS::ConstraintEqual(&myFixedValues[3], aCircular->center.y)); + aNewConstraint->rescale(scale); + aConstraints.push_back(aNewConstraint); + + return ConstraintWrapperPtr( + new PlaneGCSSolver_ConstraintWrapper(aConstraints, getType())); +} + + +void SketchSolver_ConstraintMovement::startPoint( + const std::shared_ptr& theStartPoint) +{ + myStartPoint = theStartPoint; + if (!mySimpleMove) { + myFixedValues[0] = myStartPoint->x(); + myFixedValues[1] = myStartPoint->y(); } - theAttributes.clear(); - theAttributes.insert(theAttributes.begin(), aMoved.begin(), aMoved.end()); +} + +void SketchSolver_ConstraintMovement::moveTo( + const std::shared_ptr& theDestinationPoint) +{ + if (!myMovedFeature) + return; // nothing to move + + double aDelta[2] = { theDestinationPoint->x() - myStartPoint->x(), + theDestinationPoint->y() - myStartPoint->y() }; + +#ifdef CHANGE_RADIUS_WHILE_MOVE + int aMaxSize = mySimpleMove ? (int)myFixedValues.size() : 2; +#else + int aMaxSize = myMovedFeature->getKind() == SketchPlugin_Line::ID() && !myDraggedPoint ? 4 : 2; +#endif + for (int i = 0; i < aMaxSize; ++i) + myFixedValues[i] += aDelta[i % 2]; }