From 8ebc9a7d5f87057b61b174e7568e01e44571549d Mon Sep 17 00:00:00 2001 From: mpv Date: Wed, 19 Aug 2015 15:05:38 +0300 Subject: [PATCH] Object Browser tree needed method implementation --- src/ModelAPI/ModelAPI_Tools.cpp | 19 +++++++++++++++++++ src/ModelAPI/ModelAPI_Tools.h | 8 ++++++++ 2 files changed, 27 insertions(+) diff --git a/src/ModelAPI/ModelAPI_Tools.cpp b/src/ModelAPI/ModelAPI_Tools.cpp index a1e962da2..31e2b031b 100644 --- a/src/ModelAPI/ModelAPI_Tools.cpp +++ b/src/ModelAPI/ModelAPI_Tools.cpp @@ -185,4 +185,23 @@ CompositeFeaturePtr compositeOwner(const FeaturePtr& theFeature) return CompositeFeaturePtr(); // not found } +ResultCompSolidPtr compSolidOwner(const ResultPtr& theSub) +{ + ResultBodyPtr aBody = std::dynamic_pointer_cast(theSub); + if (theSub.get()) { + FeaturePtr aFeatureOwner = aBody->document()->feature(aBody); + if (aFeatureOwner.get()) { + std::list >::const_iterator aResIter = + aFeatureOwner->results().cbegin(); + for(; aResIter != aFeatureOwner->results().cend(); aResIter++) { + ResultCompSolidPtr aComp = std::dynamic_pointer_cast(*aResIter); + if (aComp && aComp->isSub(aBody)) + return aComp; + } + } + } + return ResultCompSolidPtr(); // not found +} + } // namespace ModelAPI_Tools + diff --git a/src/ModelAPI/ModelAPI_Tools.h b/src/ModelAPI/ModelAPI_Tools.h index 11e4b6ff0..97b93c9d5 100644 --- a/src/ModelAPI/ModelAPI_Tools.h +++ b/src/ModelAPI/ModelAPI_Tools.h @@ -14,6 +14,7 @@ #include #include #include +#include #include @@ -59,6 +60,13 @@ MODELAPI_EXPORT ResultPtr findPartResult(const DocumentPtr& theMain, const Docum */ MODELAPI_EXPORT CompositeFeaturePtr compositeOwner(const FeaturePtr& theFeature); +/*! + * Returns the compsolid result - parent of this result. + * \param theSub the sub-element of comp-solid + * \returns null if it is not sub-element of composite + */ +MODELAPI_EXPORT ResultCompSolidPtr compSolidOwner(const ResultPtr& theSub); + } #endif -- 2.39.2