From: dbv Date: Thu, 30 Mar 2017 09:32:20 +0000 (+0300) Subject: Issue #2045: crash when load python script X-Git-Tag: V_2.7.0~128 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=433c89ef414e18ccc2efe09b4121beece7a9b7e9;p=modules%2Fshaper.git Issue #2045: crash when load python script Fixed order of shapes in TNaming_NamedShape after copy of Part. --- diff --git a/src/Model/Model_Session.cpp b/src/Model/Model_Session.cpp index 924783bb2..c73516a43 100644 --- a/src/Model/Model_Session.cpp +++ b/src/Model/Model_Session.cpp @@ -26,11 +26,18 @@ #include #include +#include #include #include #include #include +#include +#include +#include + +#include + static Model_Session* myImpl = new Model_Session(); // t oredirect all calls to the root document @@ -331,6 +338,50 @@ std::shared_ptr Model_Session::copy( aRT->SetRelocation(aSourceRoot, aTargetRoot); TDF_CopyTool::Copy(aDS, aRT); + // TODO: remove after fix in OCCT. + // All named shapes are stored in reversed order, so to fix this we reverse them back. + for(TDF_ChildIDIterator aChildIter(aTargetRoot, TNaming_NamedShape::GetID(), true); + aChildIter.More(); + aChildIter.Next()) { + Handle(TNaming_NamedShape) aNamedShape = + Handle(TNaming_NamedShape)::DownCast(aChildIter.Value()); + if (aNamedShape.IsNull()) { + continue; + } + + TopoDS_Shape aShape = aNamedShape->Get(); + if(aShape.IsNull() || aShape.ShapeType() != TopAbs_COMPOUND) { + continue; + } + + TNaming_Evolution anEvol = aNamedShape->Evolution(); + std::list > aShapePairs; // to store old and new shapes + for(TNaming_Iterator anIter(aNamedShape); anIter.More(); anIter.Next()) { + aShapePairs.push_back( + std::pair(anIter.OldShape(), anIter.NewShape())); + } + + // Add in reverse order. + TDF_Label aLabel = aNamedShape->Label(); + TNaming_Builder aBuilder(aLabel); + for(std::list >::iterator aPairsIter = + aShapePairs.begin(); + aPairsIter != aShapePairs.end(); + aPairsIter++) { + if (anEvol == TNaming_GENERATED) { + aBuilder.Generated(aPairsIter->first, aPairsIter->second); + } else if (anEvol == TNaming_MODIFY) { + aBuilder.Modify(aPairsIter->first, aPairsIter->second); + } else if (anEvol == TNaming_DELETE) { + aBuilder.Delete(aPairsIter->first); + } else if (anEvol == TNaming_PRIMITIVE) { + aBuilder.Generated(aPairsIter->second); + } else if (anEvol == TNaming_SELECTED) { + aBuilder.Select(aPairsIter->second, aPairsIter->first); + } + } + } + TDF_LabelList anEmptyUpdated; aNew->objects()->synchronizeFeatures(anEmptyUpdated, true, true, true, true); return aNew;