From: azv Date: Thu, 2 Jul 2015 05:40:38 +0000 (+0300) Subject: Remove unused entities in sketch solver while changing number of copies in multi... X-Git-Tag: V_1.3.0~126 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0b8e9cd0f92b45ade5e9d639a6323ae50555ed34;p=modules%2Fshaper.git Remove unused entities in sketch solver while changing number of copies in multi translation and multi rotation. --- diff --git a/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp b/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp index 0e8ec23d6..0ceaee690 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp @@ -230,6 +230,9 @@ bool SketchSolver_ConstraintMultiRotation::remove(ConstraintPtr theConstraint) std::map::iterator aFeatIt = myFeatureMap.begin(); for (; aFeatIt != myFeatureMap.end(); aFeatIt++) myStorage->removeEntity(aFeatIt->second); + myStorage->removeUnusedEntities(); + + std::map aFeatureMapCopy = myFeatureMap; if (isFullyRemoved) { myFeatureMap.clear(); @@ -237,6 +240,18 @@ bool SketchSolver_ConstraintMultiRotation::remove(ConstraintPtr theConstraint) myValueMap.clear(); } else cleanRemovedEntities(); + + // Restore initial features + std::map::iterator aFIter = aFeatureMapCopy.begin(); + for (; aFIter != aFeatureMapCopy.end(); ++aFIter) + { + if (myFeatureMap.find(aFIter->first) != myFeatureMap.end()) + continue; // the feature was not removed + Slvs_hEntity anEntity = myGroup->getFeatureId(aFIter->first); + if (anEntity != SLVS_E_UNKNOWN) + myFeatureMap[aFIter->first] = anEntity; + } + return true; } @@ -263,7 +278,9 @@ void SketchSolver_ConstraintMultiRotation::adjustConstraint() if (squareDistance(myStorage, aLine.point[0], aLine.point[1]) < tolerance * tolerance) { myStorage->removeConstraint(aConstraint.h); isFirstRemoved = aConstr == mySlvsConstraints.begin(); - std::vector::iterator aTmpIter = aConstr--; + std::vector::iterator aTmpIter = aConstr; + if (!isFirstRemoved) + --aConstr; mySlvsConstraints.erase(aTmpIter); } // Store the lines into the map diff --git a/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.cpp b/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.cpp index a90354a84..8dba38189 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.cpp @@ -199,12 +199,26 @@ bool SketchSolver_ConstraintMultiTranslation::remove(ConstraintPtr theConstraint for (; aFeatIt != myFeatureMap.end(); aFeatIt++) myStorage->removeEntity(aFeatIt->second); + std::map aFeatureMapCopy = myFeatureMap; + if (isFullyRemoved) { myFeatureMap.clear(); myAttributeMap.clear(); myValueMap.clear(); } else cleanRemovedEntities(); + + // Restore initial features + std::map::iterator aFIter = aFeatureMapCopy.begin(); + for (; aFIter != aFeatureMapCopy.end(); ++aFIter) + { + if (myFeatureMap.find(aFIter->first) != myFeatureMap.end()) + continue; // the feature was not removed + Slvs_hEntity anEntity = myGroup->getFeatureId(aFIter->first); + if (anEntity != SLVS_E_UNKNOWN) + myFeatureMap[aFIter->first] = anEntity; + } + return true; } diff --git a/src/SketchSolver/SketchSolver_Storage.cpp b/src/SketchSolver/SketchSolver_Storage.cpp index 2dca44233..dade8f43f 100644 --- a/src/SketchSolver/SketchSolver_Storage.cpp +++ b/src/SketchSolver/SketchSolver_Storage.cpp @@ -187,6 +187,65 @@ bool SketchSolver_Storage::removeEntity(const Slvs_hEntity& theEntityID) return aResult; } +void SketchSolver_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] != 0) + anUnusedEntities.erase(myEntities[aPos].point[j]); + } + } + } + } + + std::set::const_iterator anEntIt = anUnusedEntities.begin(); + for (; 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]); + myRemovedEntities.insert(*anEntIt); + if (anEntity.type == SLVS_E_POINT_IN_2D || anEntity.type == SLVS_E_POINT_IN_3D) + removeCoincidentPoint(*anEntIt); + } + } + + if (!anUnusedEntities.empty()) + myNeedToResolve = true; +} + const Slvs_Entity& SketchSolver_Storage::getEntity(const Slvs_hEntity& theEntityID) const { int aPos = Search(theEntityID, myEntities); diff --git a/src/SketchSolver/SketchSolver_Storage.h b/src/SketchSolver/SketchSolver_Storage.h index 3167dd157..3f965fca2 100644 --- a/src/SketchSolver/SketchSolver_Storage.h +++ b/src/SketchSolver/SketchSolver_Storage.h @@ -58,6 +58,9 @@ 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