From: azv Date: Wed, 20 Jan 2016 11:12:47 +0000 (+0300) Subject: Code cleanup in SketchPlugin and SketchSolver. X-Git-Tag: V_2.2.0~197 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d73b65e0b6e8c38fc7fdcbd302e69b51db4082d8;p=modules%2Fshaper.git Code cleanup in SketchPlugin and SketchSolver. Update unit tests for code coverage. --- diff --git a/src/SketchPlugin/Test/TestConstraintDistance.py b/src/SketchPlugin/Test/TestConstraintDistance.py index f1fa087b1..e9703fa63 100644 --- a/src/SketchPlugin/Test/TestConstraintDistance.py +++ b/src/SketchPlugin/Test/TestConstraintDistance.py @@ -100,6 +100,8 @@ assert (not refattrA.isInitialized()) assert (not refattrB.isInitialized()) aLineResult = aSketchLine.firstResult() assert (aLineResult is not None) +# the following line is necessary to check automatic calculation of a distance +aConstraint.execute() refattrA.setAttr(aSketchPointCoords) refattrB.setAttr(aLineAStartPoint) aSession.finishOperation() diff --git a/src/SketchPlugin/Test/TestConstraintEqual.py b/src/SketchPlugin/Test/TestConstraintEqual.py index cd3fb37ca..959a0be1c 100644 --- a/src/SketchPlugin/Test/TestConstraintEqual.py +++ b/src/SketchPlugin/Test/TestConstraintEqual.py @@ -48,6 +48,16 @@ def lineLength(theLine): aVecY = aLineStart.y() - aLineEnd.y() return math.hypot(aVecX, aVecY) +def arcLength(theArc): + aCenter = geomDataAPI_Point2D(theArc.attribute("ArcCenter")) + aStart = geomDataAPI_Point2D(theArc.attribute("ArcStartPoint")) + aEnd = geomDataAPI_Point2D(theArc.attribute("ArcEndPoint")) + # use the law of cosines to calculate angular length of arc + aRadius = math.hypot(aStart.x() - aCenter.x(), aStart.y() - aCenter.y()) + aDist2 = (aEnd.x()-aStart.x())**2 + (aEnd.y()-aStart.y())**2 + anAngle = math.acos(1. - aDist2 / (2. * aRadius**2)) + return aRadius * anAngle + #========================================================================= # Start of test @@ -205,6 +215,28 @@ aLine1Len = lineLength(aSketchLine1) aLine2Len = lineLength(aSketchLine2) assert (math.fabs(aLine1Len - anExtLineLen) < 1.e-10) assert (math.fabs(aLine2Len - anExtLineLen) < 1.e-10) + +#========================================================================= +# A constraint to make equal lengths of line and arc +#========================================================================= +# Third Line +aSession.startOperation() +aSketchLine3 = aSketchFeature.addFeature("SketchLine") +aLine3StartPoint = geomDataAPI_Point2D(aSketchLine3.attribute("StartPoint")) +aLine3EndPoint = geomDataAPI_Point2D(aSketchLine3.attribute("EndPoint")) +aLine3StartPoint.setValue(20., 15.) +aLine3EndPoint.setValue(20., 25.) +aSession.finishOperation() +aSession.startOperation() +anEqArcLineLen = aSketchFeature.addFeature("SketchConstraintEqual") +aRefObjectA = anEqArcLineLen.refattr("ConstraintEntityA") +aRefObjectB = anEqArcLineLen.refattr("ConstraintEntityB") +aRefObjectA.setObject(aSketchArc.lastResult()) +aRefObjectB.setObject(aSketchLine3.lastResult()) +aSession.finishOperation() +aLine3Len = lineLength(aSketchLine3) +anArcLen = arcLength(aSketchArc) +assert (math.fabs(aLine3Len - anArcLen) < 1.e-7) #========================================================================= # End of test #========================================================================= diff --git a/src/SketchPlugin/Test/TestConstraintRadius.py b/src/SketchPlugin/Test/TestConstraintRadius.py index 9349352b3..b3bacf265 100644 --- a/src/SketchPlugin/Test/TestConstraintRadius.py +++ b/src/SketchPlugin/Test/TestConstraintRadius.py @@ -53,6 +53,17 @@ anArcStartPoint.setValue(0., 50.) anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint")) anArcEndPoint.setValue(50., 0.) aSession.finishOperation() +# Test changing the arc start/end point +aSession.startOperation() +anArcStartPoint.setValue(anArcStartPoint.x(), 40.) +anArcStartPoint.setValue(0., 50.) +assert (math.hypot(anArcStartPoint.x() - 0., anArcStartPoint.y() - 50.) < 1.e-10) +aSession.finishOperation() +aSession.startOperation() +anArcEndPoint.setValue(40., anArcEndPoint.y()) +anArcEndPoint.setValue(50., 0.) +assert (math.hypot(anArcEndPoint.x() - 50., anArcEndPoint.y() - 0.) < 1.e-10) +aSession.finishOperation() # Circle aSession.startOperation() aSketchCircle = aSketchFeature.addFeature("SketchCircle") diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.cpp index fccec67af..dd1d542fb 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.cpp +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.cpp @@ -135,10 +135,6 @@ static ConstraintWrapperPtr static void adjustAngle(ConstraintWrapperPtr theConstraint); /// \brief Update mirror points static void adjustMirror(ConstraintWrapperPtr theConstraint); -/// \brief Update positions of rotated features -static void adjustMultiRotation(ConstraintWrapperPtr theConstraint); -/// \brief Update positions of translated features -static void adjustMultiTranslation(ConstraintWrapperPtr theConstraint); /// \brief Transform points to be symmetric regarding to the mirror line static void makeMirrorPoints(EntityWrapperPtr theOriginal, @@ -443,12 +439,6 @@ void PlaneGCSSolver_Builder::adjustConstraint(ConstraintWrapperPtr theConstraint // Update flags and parameters in constraints if (aType == CONSTRAINT_ANGLE) adjustAngle(theConstraint); - //else if (aType == CONSTRAINT_SYMMETRIC) - // adjustMirror(theConstraint); - else if (aType == CONSTRAINT_MULTI_ROTATION) - adjustMultiRotation(theConstraint); - else if (aType == CONSTRAINT_MULTI_TRANSLATION) - adjustMultiTranslation(theConstraint); } EntityWrapperPtr PlaneGCSSolver_Builder::createFeature( @@ -1095,23 +1085,6 @@ void adjustAngle(ConstraintWrapperPtr theConstraint) } } -////void adjustMirror(ConstraintWrapperPtr theConstraint) -////{ -//// std::vector aPoints; -//// EntityWrapperPtr aMirrorLine; -//// -//// const std::list& aSubs = theConstraint->entities(); -//// std::list::const_iterator anIt = aSubs.begin(); -//// for (; anIt != aSubs.end(); ++anIt) { -//// if ((*anIt)->type() == ENTITY_POINT) -//// aPoints.push_back(*anIt); -//// else if ((*anIt)->type() == ENTITY_LINE) -//// aMirrorLine = *anIt; -//// } -//// -//// makeMirrorPoints(aPoints[0], aPoints[1], aMirrorLine); -////} - void makeMirrorPoints(EntityWrapperPtr theOriginal, EntityWrapperPtr theMirrored, EntityWrapperPtr theMirrorLine) @@ -1140,105 +1113,3 @@ void makeMirrorPoints(EntityWrapperPtr theOriginal, } } -static void rotate(EntityWrapperPtr theSource, EntityWrapperPtr theDest, - std::shared_ptr theCenter, - double theSin, double theCos) -{ - if (theSource->type() == ENTITY_POINT) { - // Rotate single point - std::shared_ptr aSrcAttr = - std::dynamic_pointer_cast(theSource->baseAttribute()); - std::shared_ptr aDstAttr = - std::dynamic_pointer_cast(theDest->baseAttribute()); - if (aSrcAttr && aDstAttr) { - std::shared_ptr aVec = aSrcAttr->pnt()->xy()->decreased(theCenter->xy()); - double aNewX = aVec->x() * theCos - aVec->y() * theSin; - double aNewY = aVec->x() * theSin + aVec->y() * theCos; - aDstAttr->setValue(theCenter->x() + aNewX, theCenter->y() + aNewY); - // set also parameters of the solver - double aCoord[2] = {aDstAttr->x(), aDstAttr->y()}; - std::list::const_iterator aDIt = theDest->parameters().begin(); - for (int i = 0; aDIt != theDest->parameters().end(); ++aDIt, ++i) - (*aDIt)->setValue(aCoord[i]); - } - return; - } - - FeaturePtr aDestFeature = theDest->baseFeature(); - if (aDestFeature) - aDestFeature->data()->blockSendAttributeUpdated(true); - - // Rotate points of the feature - const std::list& aSrcSubs = theSource->subEntities(); - const std::list& aDstSubs = theDest->subEntities(); - std::list::const_iterator aSrcIt, aDstIt; - for (aSrcIt = aSrcSubs.begin(), aDstIt = aDstSubs.begin(); - aSrcIt != aSrcSubs.end() && aDstIt != aDstSubs.end(); ++aSrcIt, ++aDstIt) - rotate(*aSrcIt, *aDstIt, theCenter, theSin, theCos); - - if (aDestFeature) - aDestFeature->data()->blockSendAttributeUpdated(false); -} - -static void translate(EntityWrapperPtr theSource, EntityWrapperPtr theDest, - std::shared_ptr theDelta) -{ - if (theSource->type() == ENTITY_POINT) { - // Translate single point - std::shared_ptr aSrcAttr = - std::dynamic_pointer_cast(theSource->baseAttribute()); - std::shared_ptr aDstAttr = - std::dynamic_pointer_cast(theDest->baseAttribute()); - if (aSrcAttr && aDstAttr) - aDstAttr->setValue(aSrcAttr->x() + theDelta->x(), aSrcAttr->y() + theDelta->y()); - return; - } - - FeaturePtr aDestFeature = theDest->baseFeature(); - if (aDestFeature) - aDestFeature->data()->blockSendAttributeUpdated(true); - - // Translate points of the feature - const std::list& aSrcSubs = theSource->subEntities(); - const std::list& aDstSubs = theDest->subEntities(); - std::list::const_iterator aSrcIt, aDstIt; - for (aSrcIt = aSrcSubs.begin(), aDstIt = aDstSubs.begin(); - aSrcIt != aSrcSubs.end() && aDstIt != aDstSubs.end(); ++aSrcIt, ++aDstIt) - translate(*aSrcIt, *aDstIt, theDelta); - - if (aDestFeature) - aDestFeature->data()->blockSendAttributeUpdated(false); -} - -void adjustMultiRotation(ConstraintWrapperPtr theConstraint) -{ - BuilderPtr aBuilder = PlaneGCSSolver_Builder::getInstance(); - - double anAngleRad = theConstraint->value() * PI / 180.0; - double aSin = sin(anAngleRad); - double aCos = cos(anAngleRad); - - const std::list& aSubs = theConstraint->entities(); - std::list::const_iterator aSIt = aSubs.begin(); - - std::shared_ptr aCenter = aBuilder->point(*aSIt++); - std::list::const_iterator aPrevIt = aSIt++; - for (; aSIt != aSubs.end(); ++aPrevIt, ++aSIt) - rotate(*aPrevIt, *aSIt, aCenter, aSin, aCos); -} - -void adjustMultiTranslation(ConstraintWrapperPtr theConstraint) -{ - BuilderPtr aBuilder = PlaneGCSSolver_Builder::getInstance(); - - const std::list& aSubs = theConstraint->entities(); - std::list::const_iterator aSIt = aSubs.begin(); - - std::shared_ptr aStartPnt = aBuilder->point(*aSIt++); - std::shared_ptr aEndPnt = aBuilder->point(*aSIt++); - std::shared_ptr aDelta = aEndPnt->xy()->decreased(aStartPnt->xy()); - - std::list::const_iterator aPrevIt = aSIt++; - for (; aSIt != aSubs.end(); ++aPrevIt, ++aSIt) - translate(*aPrevIt, *aSIt, aDelta); -} diff --git a/src/SketchSolver/SketchSolver_Group.cpp b/src/SketchSolver/SketchSolver_Group.cpp index c74580b07..34fb4d17b 100644 --- a/src/SketchSolver/SketchSolver_Group.cpp +++ b/src/SketchSolver/SketchSolver_Group.cpp @@ -516,18 +516,6 @@ void SketchSolver_Group::removeConstraint(ConstraintPtr theConstraint) myConstraints.erase(aCIter); } -// ============================================================================ -// Function: isComplexConstraint -// Class: SketchSolver_Group -// Purpose: verifies the constraint is complex, i.e. it needs another constraints to be created before -// ============================================================================ -bool SketchSolver_Group::isComplexConstraint(FeaturePtr theConstraint) -{ - return theConstraint->getKind() == SketchPlugin_ConstraintFillet::ID() || - theConstraint->getKind() == SketchPlugin_ConstraintMirror::ID() || - theConstraint->getKind() == SketchPlugin_ConstraintTangent::ID(); -} - // ============================================================================ // Function: setTemporary // Class: SketchSolver_Group diff --git a/src/SketchSolver/SketchSolver_Group.h b/src/SketchSolver/SketchSolver_Group.h index 7544fbaa2..6d7dff339 100644 --- a/src/SketchSolver/SketchSolver_Group.h +++ b/src/SketchSolver/SketchSolver_Group.h @@ -61,9 +61,6 @@ class SketchSolver_Group return mySketch->data() && mySketch->data()->isValid(); } - /// \brief Verifies the constraint is complex, i.e. it needs another constraints to be created before - static bool isComplexConstraint(FeaturePtr theConstraint); - /** \brief Adds or updates a constraint in the group * \param[in] theConstraint constraint to be changed * \return \c true if the constraint added or updated successfully diff --git a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Builder.cpp b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Builder.cpp index 704b4b0d5..9d7339ac7 100644 --- a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Builder.cpp +++ b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Builder.cpp @@ -51,10 +51,6 @@ static void adjustTangency(ConstraintWrapperPtr theConstraint); static void adjustAngle(ConstraintWrapperPtr theConstraint); /// \brief Update mirror points static void adjustMirror(ConstraintWrapperPtr theConstraint); -/// \brief Update positions of rotated features -static void adjustMultiRotation(ConstraintWrapperPtr theConstraint); -/// \brief Update positions of translated features -static void adjustMultiTranslation(ConstraintWrapperPtr theConstraint); /// \brief Transform points to be symmetric regarding to the mirror line static void makeMirrorPoints(EntityWrapperPtr theOriginal, @@ -121,6 +117,7 @@ std::list SolveSpaceSolver_Builder::createConstraint( SLVS_C_UNKNOWN, (Slvs_hGroup)theGroupID, aType, (Slvs_hEntity)theSketchID, theValue, aSlvsEntities[0], aSlvsEntities[1], aSlvsEntities[2], aSlvsEntities[3]); ConstraintWrapperPtr aResult(new SolveSpaceSolver_ConstraintWrapper(theConstraint, aConstraint)); + aResult->setGroup(theGroupID); aResult->setValue(theValue); aResult->setEntities(aConstrAttrList); adjustConstraint(aResult); @@ -156,6 +153,7 @@ std::list SolveSpaceSolver_Builder::createConstraint( aConstrAttrList.push_front(thePoint1); ConstraintWrapperPtr aResult(new SolveSpaceSolver_ConstraintWrapper(theConstraint, aConstraint)); + aResult->setGroup(theGroupID); aResult->setValue(theValue); aResult->setIsFullValue(theFullValue); aResult->setEntities(aConstrAttrList); @@ -189,6 +187,7 @@ std::list SolveSpaceSolver_Builder::createMirror( ConstraintWrapperPtr aWrapper(new SolveSpaceSolver_ConstraintWrapper( theConstraint, aConstraint)); + aWrapper->setGroup(theGroupID); aWrapper->setEntities(aConstrAttrList); aResult.push_back(aWrapper); } @@ -265,10 +264,6 @@ void SolveSpaceSolver_Builder::adjustConstraint(ConstraintWrapperPtr theConstrai adjustAngle(theConstraint); else if (aType == CONSTRAINT_SYMMETRIC) adjustMirror(theConstraint); - else if (aType == CONSTRAINT_MULTI_ROTATION) - adjustMultiRotation(theConstraint); - else if (aType == CONSTRAINT_MULTI_TRANSLATION) - adjustMultiTranslation(theConstraint); } EntityWrapperPtr SolveSpaceSolver_Builder::createFeature( @@ -789,126 +784,3 @@ void makeMirrorPoints(EntityWrapperPtr theOriginal, aMirroredPnt->setValue(aCoord[0], aCoord[1]); } } - -static void rotate(EntityWrapperPtr theSource, EntityWrapperPtr theDest, - std::shared_ptr theCenter, - double theSin, double theCos) -{ - std::shared_ptr aSource = - std::dynamic_pointer_cast(theSource); - std::shared_ptr aDest = - std::dynamic_pointer_cast(theDest); - - if (theSource->type() == ENTITY_POINT) { - // Rotate single point - std::shared_ptr aSrcAttr = - std::dynamic_pointer_cast(aSource->baseAttribute()); - std::shared_ptr aDstAttr = - std::dynamic_pointer_cast(aDest->baseAttribute()); - if (aSrcAttr && aDstAttr) { - std::shared_ptr aVec = aSrcAttr->pnt()->xy()->decreased(theCenter->xy()); - double aNewX = aVec->x() * theCos - aVec->y() * theSin; - double aNewY = aVec->x() * theSin + aVec->y() * theCos; - aDstAttr->setValue(theCenter->x() + aNewX, theCenter->y() + aNewY); - } - return; - } - - FeaturePtr aDestFeature = aDest->baseFeature(); - if (aDestFeature) - aDestFeature->data()->blockSendAttributeUpdated(true); - - // Rotate points of the feature - const std::list& aSrcSubs = theSource->subEntities(); - const std::list& aDstSubs = theDest->subEntities(); - std::list::const_iterator aSrcIt, aDstIt; - for (aSrcIt = aSrcSubs.begin(), aDstIt = aDstSubs.begin(); - aSrcIt != aSrcSubs.end() && aDstIt != aDstSubs.end(); ++aSrcIt, ++aDstIt) - rotate(*aSrcIt, *aDstIt, theCenter, theSin, theCos); - - if (aDestFeature) - aDestFeature->data()->blockSendAttributeUpdated(false); -} - -static void translate(EntityWrapperPtr theSource, EntityWrapperPtr theDest, - std::shared_ptr theDelta) -{ - std::shared_ptr aSource = - std::dynamic_pointer_cast(theSource); - std::shared_ptr aDest = - std::dynamic_pointer_cast(theDest); - - if (theSource->type() == ENTITY_POINT) { - // Translate single point - std::shared_ptr aSrcAttr = - std::dynamic_pointer_cast(aSource->baseAttribute()); - std::shared_ptr aDstAttr = - std::dynamic_pointer_cast(aDest->baseAttribute()); - if (aSrcAttr && aDstAttr) - aDstAttr->setValue(aSrcAttr->x() + theDelta->x(), aSrcAttr->y() + theDelta->y()); - return; - } - - FeaturePtr aDestFeature = aDest->baseFeature(); - if (aDestFeature) - aDestFeature->data()->blockSendAttributeUpdated(true); - - // Translate points of the feature - const std::list& aSrcSubs = theSource->subEntities(); - const std::list& aDstSubs = theDest->subEntities(); - std::list::const_iterator aSrcIt, aDstIt; - for (aSrcIt = aSrcSubs.begin(), aDstIt = aDstSubs.begin(); - aSrcIt != aSrcSubs.end() && aDstIt != aDstSubs.end(); ++aSrcIt, ++aDstIt) - translate(*aSrcIt, *aDstIt, theDelta); - - if (aDestFeature) - aDestFeature->data()->blockSendAttributeUpdated(false); -} - -void adjustMultiRotation(ConstraintWrapperPtr theConstraint) -{ - BuilderPtr aBuilder = SolveSpaceSolver_Builder::getInstance(); - - double anAngleValue = theConstraint->value(); - const std::list& aSubs = theConstraint->entities(); - - bool isFullValue = theConstraint->isFullValue(); - int aNbObjects = aSubs.size()-2; - if (isFullValue && aNbObjects > 0) { - anAngleValue /= aNbObjects; - } - - double anAngleRad = anAngleValue * PI / 180.0; - double aSin = sin(anAngleRad); - double aCos = cos(anAngleRad); - - std::list::const_iterator aSIt = aSubs.begin(); - - std::shared_ptr aCenter = aBuilder->point(*aSIt++); - std::list::const_iterator aPrevIt = aSIt++; - for (; aSIt != aSubs.end(); ++aPrevIt, ++aSIt) - rotate(*aPrevIt, *aSIt, aCenter, aSin, aCos); -} - -void adjustMultiTranslation(ConstraintWrapperPtr theConstraint) -{ - BuilderPtr aBuilder = SolveSpaceSolver_Builder::getInstance(); - - const std::list& aSubs = theConstraint->entities(); - std::list::const_iterator aSIt = aSubs.begin(); - - std::shared_ptr aStartPnt = aBuilder->point(*aSIt++); - std::shared_ptr aEndPnt = aBuilder->point(*aSIt++); - std::shared_ptr aDelta = aEndPnt->xy()->decreased(aStartPnt->xy()); - - bool isFullValue = theConstraint->isFullValue(); - int aNbObjects = aSubs.size()-3; - if (isFullValue && aNbObjects > 0) { - aDelta->setX(aDelta->x()/aNbObjects); - aDelta->setY(aDelta->y()/aNbObjects); - } - - std::list::const_iterator aPrevIt = aSIt++; - for (; aSIt != aSubs.end(); ++aPrevIt, ++aSIt) - translate(*aPrevIt, *aSIt, aDelta); -} diff --git a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.cpp b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.cpp index e065fd245..fcd53d0e6 100644 --- a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.cpp +++ b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.cpp @@ -741,105 +741,6 @@ bool SolveSpaceSolver_Storage::removeEntity(const Slvs_hEntity& theEntityID) return aResult; } -void SolveSpaceSolver_Storage::removeUnusedEntities() -{ - std::set anUnusedEntities; - std::vector::const_iterator aEIt = myEntities.begin(); - for (; aEIt != myEntities.end(); ++aEIt) { - if (aEIt->h == aEIt->wrkpl) { - // don't remove workplane - anUnusedEntities.erase(aEIt->point[0]); - anUnusedEntities.erase(aEIt->normal); - continue; - } - anUnusedEntities.insert(aEIt->h); - } - - std::vector::const_iterator aCIt = myConstraints.begin(); - for (; aCIt != myConstraints.end(); ++aCIt) { - Slvs_hEntity aSubs[6] = { - aCIt->entityA, aCIt->entityB, - aCIt->entityC, aCIt->entityD, - aCIt->ptA, aCIt->ptB}; - for (int i = 0; i < 6; i++) { - if (aSubs[i] != SLVS_E_UNKNOWN) { - anUnusedEntities.erase(aSubs[i]); - int aPos = Search(aSubs[i], myEntities); - if (aPos >= 0 && aPos < (int)myEntities.size()) { - for (int j = 0; j < 4; j++) - if (myEntities[aPos].point[j] != SLVS_E_UNKNOWN) - anUnusedEntities.erase(myEntities[aPos].point[j]); - if (myEntities[aPos].distance != SLVS_E_UNKNOWN) - anUnusedEntities.erase(myEntities[aPos].distance); - } - } - } - } - - std::set::const_iterator anEntIt = anUnusedEntities.begin(); - while (anEntIt != anUnusedEntities.end()) { - int aPos = Search(*anEntIt, myEntities); - if (aPos < 0 && aPos >= (int)myEntities.size()) - continue; - Slvs_Entity anEntity = myEntities[aPos]; - // Remove entity if and only if all its parameters unused - bool isUsed = false; - if (anEntity.distance != SLVS_E_UNKNOWN && - anUnusedEntities.find(anEntity.distance) == anUnusedEntities.end()) - isUsed = true; - for (int i = 0; i < 4 && !isUsed; i++) - if (anEntity.point[i] != SLVS_E_UNKNOWN && - anUnusedEntities.find(anEntity.point[i]) == anUnusedEntities.end()) - isUsed = true; - if (isUsed) { - anUnusedEntities.erase(anEntity.distance); - for (int i = 0; i < 4; i++) - if (anEntity.point[i] != SLVS_E_UNKNOWN) - anUnusedEntities.erase(anEntity.point[i]); - std::set::iterator aRemoveIt = anEntIt++; - anUnusedEntities.erase(aRemoveIt); - continue; - } - ++anEntIt; - } - - for (anEntIt = anUnusedEntities.begin(); anEntIt != anUnusedEntities.end(); ++anEntIt) { - int aPos = Search(*anEntIt, myEntities); - if (aPos >= 0 && aPos < (int)myEntities.size()) { - // Remove entity and its parameters - Slvs_Entity anEntity = myEntities[aPos]; - myEntities.erase(myEntities.begin() + aPos); - myEntityMaxID = myEntities.empty() ? SLVS_E_UNKNOWN : myEntities.back().h; - if (anEntity.distance != SLVS_E_UNKNOWN) - removeParameter(anEntity.distance); - for (int i = 0; i < 4; i++) - if (anEntity.param[i] != SLVS_E_UNKNOWN) - removeParameter(anEntity.param[i]); - for (int i = 0; i < 4; i++) - if (anEntity.point[i] != SLVS_E_UNKNOWN) - removeEntity(anEntity.point[i]); - } - } - - if (!anUnusedEntities.empty()) - myNeedToResolve = true; -} - -bool SolveSpaceSolver_Storage::isUsedByConstraints(const Slvs_hEntity& theEntityID) const -{ - std::vector::const_iterator aCIt = myConstraints.begin(); - for (; aCIt != myConstraints.end(); ++aCIt) { - Slvs_hEntity aSubs[6] = { - aCIt->entityA, aCIt->entityB, - aCIt->entityC, aCIt->entityD, - aCIt->ptA, aCIt->ptB}; - for (int i = 0; i < 6; i++) - if (aSubs[i] != SLVS_E_UNKNOWN && aSubs[i] == theEntityID) - return true; - } - return false; -} - const Slvs_Entity& SolveSpaceSolver_Storage::getEntity(const Slvs_hEntity& theEntityID) const { int aPos = Search(theEntityID, myEntities); @@ -852,59 +753,6 @@ const Slvs_Entity& SolveSpaceSolver_Storage::getEntity(const Slvs_hEntity& theEn return aDummy; } -Slvs_hEntity SolveSpaceSolver_Storage::copyEntity(const Slvs_hEntity& theCopied) -{ - int aPos = Search(theCopied, myEntities); - if (aPos < 0 || aPos >= (int)myEntities.size()) - return SLVS_E_UNKNOWN; - - Slvs_Entity aCopy = myEntities[aPos]; - aCopy.h = SLVS_E_UNKNOWN; - int i = 0; - while (aCopy.point[i] != SLVS_E_UNKNOWN) { - aCopy.point[i] = copyEntity(aCopy.point[i]); - i++; - } - if (aCopy.param[0] != SLVS_E_UNKNOWN) { - aPos = Search(aCopy.param[0], myParameters); - i = 0; - while (aCopy.param[i] != SLVS_E_UNKNOWN) { - Slvs_Param aNewParam = myParameters[aPos]; - aNewParam.h = SLVS_E_UNKNOWN; - aCopy.param[i] = addParameter(aNewParam); - i++; - aPos++; - } - } - return addEntity(aCopy); -} - -void SolveSpaceSolver_Storage::copyEntity(const Slvs_hEntity& theFrom, const Slvs_hEntity& theTo) -{ - int aPosFrom = Search(theFrom, myEntities); - int aPosTo = Search(theTo, myEntities); - if (aPosFrom < 0 || aPosFrom >= (int)myEntities.size() || - aPosTo < 0 || aPosTo >= (int)myEntities.size()) - return; - - Slvs_Entity aEntFrom = myEntities[aPosFrom]; - Slvs_Entity aEntTo = myEntities[aPosTo]; - int i = 0; - while (aEntFrom.point[i] != SLVS_E_UNKNOWN) { - copyEntity(aEntFrom.point[i], aEntTo.point[i]); - i++; - } - if (aEntFrom.param[0] != SLVS_E_UNKNOWN) { - aPosFrom = Search(aEntFrom.param[0], myParameters); - aPosTo = Search(aEntTo.param[0], myParameters); - i = 0; - while (aEntFrom.param[i] != SLVS_E_UNKNOWN) { - myParameters[aPosTo++].val = myParameters[aPosFrom++].val; - i++; - } - } -} - Slvs_hConstraint SolveSpaceSolver_Storage::addConstraint(const Slvs_Constraint& theConstraint) { diff --git a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.h b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.h index a6646caa0..b9937ce21 100644 --- a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.h +++ b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.h @@ -112,17 +112,8 @@ public: * \return \c true if the entity was successfully removed */ bool removeEntity(const Slvs_hEntity& theEntityID); - /** \brief Remove all entities, which are not used in constraints - */ - void removeUnusedEntities(); /// \brief Returns the entity by its ID const Slvs_Entity& getEntity(const Slvs_hEntity& theEntityID) const; - /// \brief Makes a full copy of the given entity - Slvs_hEntity copyEntity(const Slvs_hEntity& theCopied); - /// \brief Copy one entity to another - void copyEntity(const Slvs_hEntity& theFrom, const Slvs_hEntity& theTo); - /// \brief Check the entity is used in constraints - bool isUsedByConstraints(const Slvs_hEntity& theEntityID) const; /// \brief Returns maximal ID of entities in this storage const Slvs_hEntity& entityMaxID() const { return myEntityMaxID; }