ResultPtr findPartResult(const DocumentPtr& theMain, const DocumentPtr& theSub)
{
- for (int a = theMain->size(ModelAPI_ResultPart::group()) - 1; a >= 0; a--) {
- ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(
- theMain->object(ModelAPI_ResultPart::group(), a));
- if (aPart && aPart->data()->document(ModelAPI_ResultPart::DOC_REF())->value() == theSub) {
- return aPart;
+ if (theMain != theSub) { // to optimize and avoid of crash on partset document close (don't touch the sub-document structure)
+ for (int a = theMain->size(ModelAPI_ResultPart::group()) - 1; a >= 0; a--) {
+ ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(
+ theMain->object(ModelAPI_ResultPart::group(), a));
+ if (aPart && aPart->data()->document(ModelAPI_ResultPart::DOC_REF())->value() == theSub) {
+ return aPart;
+ }
}
}
return ResultPtr();
ResultCompSolidPtr compSolidOwner(const ResultPtr& theSub)
{
ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theSub);
- if (theSub.get()) {
+ if (aBody.get()) {
FeaturePtr aFeatureOwner = aBody->document()->feature(aBody);
if (aFeatureOwner.get()) {
std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aResIter =
return ResultCompSolidPtr(); // not found
}
+bool hasSubResults(const ResultPtr& theResult)
+{
+ ResultCompSolidPtr aCompSolid = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theResult);
+ return aCompSolid.get() && aCompSolid->numberOfSubs() > 0;
+}
+
} // namespace ModelAPI_Tools