From: azv Date: Wed, 9 Sep 2015 13:15:26 +0000 (+0300) Subject: Update groups merging (issue #933) X-Git-Tag: V_1.4.0_beta4~59 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9dab645107f5df8b7a9b7fbba3b2cb52114bd6a2;p=modules%2Fshaper.git Update groups merging (issue #933) --- diff --git a/src/SketchSolver/SketchSolver_ConstraintManager.cpp b/src/SketchSolver/SketchSolver_ConstraintManager.cpp index 6bcd23b91..682bbf23a 100644 --- a/src/SketchSolver/SketchSolver_ConstraintManager.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintManager.cpp @@ -16,22 +16,6 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include #include @@ -51,9 +35,6 @@ SketchSolver_ConstraintManager* SketchSolver_ConstraintManager::_self = 0; SketchSolver_ConstraintManager* myManager = SketchSolver_ConstraintManager::Instance(); -/// \brief Select and sort features applicable for SketchSolver -static std::list selectApplicableFeatures(const std::set& theObjects); - // ======================================================== // ========= SketchSolver_ConstraintManager =============== // ======================================================== @@ -114,7 +95,7 @@ void SketchSolver_ConstraintManager::processEvent( } } } else { - std::list aSketchFeatures = selectApplicableFeatures(aFeatures); + std::list aSketchFeatures = SketchSolver_Group::selectApplicableFeatures(aFeatures); std::list::iterator aFeatIter = aSketchFeatures.begin(); for (; aFeatIter != aSketchFeatures.end(); ++aFeatIter) { if ((*aFeatIter)->getKind() == SketchPlugin_Sketch::ID()) { @@ -384,76 +365,3 @@ void SketchSolver_ConstraintManager::resolveConstraints(const bool theForceUpdat Events_Loop::loop()->flush(anUpdateEvent); } - - - -// =========== Auxiliary functions ======================================== -static double featureToVal(FeaturePtr theFeature) -{ - if (theFeature->getKind() == SketchPlugin_Sketch::ID()) - return 0.0; // sketch - ConstraintPtr aConstraint = std::dynamic_pointer_cast(theFeature); - if (!aConstraint) - return 1.0; // features (arc, circle, line, point) - - const std::string& anID = aConstraint->getKind(); - if (anID == SketchPlugin_ConstraintCoincidence::ID()) - return 2.0; - if (anID == SketchPlugin_ConstraintDistance::ID() || - anID == SketchPlugin_ConstraintLength::ID() || - anID == SketchPlugin_ConstraintRadius::ID() || - anID == SketchPlugin_ConstraintAngle::ID()) - return 3.0; - if (anID == SketchPlugin_ConstraintHorizontal::ID() || - anID == SketchPlugin_ConstraintVertical::ID() || - anID == SketchPlugin_ConstraintParallel::ID() || - anID == SketchPlugin_ConstraintPerpendicular::ID()) - return 4.0; - if (anID == SketchPlugin_ConstraintEqual::ID()) - return 5.0; - if (anID == SketchPlugin_ConstraintTangent::ID() || - anID == SketchPlugin_ConstraintMirror::ID()) - return 6.0; - if (anID == SketchPlugin_ConstraintRigid::ID()) - return 7.0; - if (anID == SketchPlugin_MultiRotation::ID() || - anID == SketchPlugin_MultiTranslation::ID()) - return 8.0; - - // all other constraints are placed between Equal and Tangent constraints - return 5.5; -} - -static bool operator< (FeaturePtr theFeature1, FeaturePtr theFeature2) -{ - return featureToVal(theFeature1) < featureToVal(theFeature2); -} - -std::list selectApplicableFeatures(const std::set& theObjects) -{ - std::list aResult; - std::list::iterator aResIt; - - std::set::const_iterator anObjIter = theObjects.begin(); - for (; anObjIter != theObjects.end(); ++anObjIter) { - // Operate sketch itself and SketchPlugin features only. - // Also, the Fillet need to be skipped, because there are several separated constraints composing it. - FeaturePtr aFeature = std::dynamic_pointer_cast(*anObjIter); - if (!aFeature) - continue; - std::shared_ptr aSketchFeature = - std::dynamic_pointer_cast(aFeature); - if ((aFeature->getKind() != SketchPlugin_Sketch::ID() && !aSketchFeature) || - aFeature->getKind() == SketchPlugin_ConstraintFillet::ID()) - continue; - - // Find the place where to insert a feature - for (aResIt = aResult.begin(); aResIt != aResult.end(); ++aResIt) - if (aFeature < *aResIt) - break; - aResult.insert(aResIt, aFeature); - } - - return aResult; -} - diff --git a/src/SketchSolver/SketchSolver_Group.cpp b/src/SketchSolver/SketchSolver_Group.cpp index 9371607d2..c965b8ee9 100644 --- a/src/SketchSolver/SketchSolver_Group.cpp +++ b/src/SketchSolver/SketchSolver_Group.cpp @@ -28,13 +28,20 @@ #include #include +#include #include +#include #include -#include +#include #include +#include #include +#include +#include +#include #include #include +#include #include #include #include @@ -545,18 +552,19 @@ void SketchSolver_Group::mergeGroups(const SketchSolver_Group& theGroup) if (!myFeatureStorage) myFeatureStorage = FeatureStoragePtr(new SketchSolver_FeatureStorage); - std::vector aComplexConstraints; + std::set aConstraints; ConstraintConstraintMap::const_iterator aConstrIter = theGroup.myConstraints.begin(); - // append simple constraints for (; aConstrIter != theGroup.myConstraints.end(); aConstrIter++) - if (isComplexConstraint(aConstrIter->first)) - aComplexConstraints.push_back(aConstrIter->first); - else - changeConstraint(aConstrIter->first); - // append complex constraints - std::vector::iterator aComplexIter = aComplexConstraints.begin(); - for (; aComplexIter != aComplexConstraints.end(); aComplexIter++) - changeConstraint(*aComplexIter); + aConstraints.insert(aConstrIter->first); + + std::list aSortedConstraints = selectApplicableFeatures(aConstraints); + std::list::iterator aSCIter = aSortedConstraints.begin(); + for (; aSCIter != aSortedConstraints.end(); ++aSCIter) { + ConstraintPtr aConstr = std::dynamic_pointer_cast(*aSCIter); + if (!aConstr) + continue; + changeConstraint(aConstr); + } } // ============================================================================ @@ -740,3 +748,77 @@ bool SketchSolver_Group::checkFeatureValidity(FeaturePtr theFeature) return aFactory->validate(theFeature); } + + + + +// =========== Auxiliary functions ======================================== +static double featureToVal(FeaturePtr theFeature) +{ + if (theFeature->getKind() == SketchPlugin_Sketch::ID()) + return 0.0; // sketch + ConstraintPtr aConstraint = std::dynamic_pointer_cast(theFeature); + if (!aConstraint) + return 1.0; // features (arc, circle, line, point) + + const std::string& anID = aConstraint->getKind(); + if (anID == SketchPlugin_ConstraintCoincidence::ID()) + return 2.0; + if (anID == SketchPlugin_ConstraintDistance::ID() || + anID == SketchPlugin_ConstraintLength::ID() || + anID == SketchPlugin_ConstraintRadius::ID() || + anID == SketchPlugin_ConstraintAngle::ID()) + return 3.0; + if (anID == SketchPlugin_ConstraintHorizontal::ID() || + anID == SketchPlugin_ConstraintVertical::ID() || + anID == SketchPlugin_ConstraintParallel::ID() || + anID == SketchPlugin_ConstraintPerpendicular::ID()) + return 4.0; + if (anID == SketchPlugin_ConstraintEqual::ID()) + return 5.0; + if (anID == SketchPlugin_ConstraintTangent::ID() || + anID == SketchPlugin_ConstraintMirror::ID()) + return 6.0; + if (anID == SketchPlugin_ConstraintRigid::ID()) + return 7.0; + if (anID == SketchPlugin_MultiRotation::ID() || + anID == SketchPlugin_MultiTranslation::ID()) + return 8.0; + + // all other constraints are placed between Equal and Tangent constraints + return 5.5; +} + +static bool operator< (FeaturePtr theFeature1, FeaturePtr theFeature2) +{ + return featureToVal(theFeature1) < featureToVal(theFeature2); +} + +std::list SketchSolver_Group::selectApplicableFeatures(const std::set& theObjects) +{ + std::list aResult; + std::list::iterator aResIt; + + std::set::const_iterator anObjIter = theObjects.begin(); + for (; anObjIter != theObjects.end(); ++anObjIter) { + // Operate sketch itself and SketchPlugin features only. + // Also, the Fillet need to be skipped, because there are several separated constraints composing it. + FeaturePtr aFeature = std::dynamic_pointer_cast(*anObjIter); + if (!aFeature) + continue; + std::shared_ptr aSketchFeature = + std::dynamic_pointer_cast(aFeature); + if ((aFeature->getKind() != SketchPlugin_Sketch::ID() && !aSketchFeature) || + aFeature->getKind() == SketchPlugin_ConstraintFillet::ID()) + continue; + + // Find the place where to insert a feature + for (aResIt = aResult.begin(); aResIt != aResult.end(); ++aResIt) + if (aFeature < *aResIt) + break; + aResult.insert(aResIt, aFeature); + } + + return aResult; +} + diff --git a/src/SketchSolver/SketchSolver_Group.h b/src/SketchSolver/SketchSolver_Group.h index 3197bd6da..79181c382 100644 --- a/src/SketchSolver/SketchSolver_Group.h +++ b/src/SketchSolver/SketchSolver_Group.h @@ -133,6 +133,12 @@ class SketchSolver_Group */ bool resolveConstraints(); + /** \brief Collect all features applicable for the sketch + * \param theObjects list of features + * \return list of bolted and sorted features + */ + static std::list selectApplicableFeatures(const std::set& theObjects); + protected: /** \brief Removes constraints from the group * \param[in] theConstraint constraint to be removed