From af80cfd8be99a0a23cb2f755e62be141107a0591 Mon Sep 17 00:00:00 2001 From: mpv Date: Wed, 2 Mar 2016 11:44:45 +0300 Subject: [PATCH] Fix for the issue #1346 : the copy of NamedShapes keeps the previous shapes now. --- src/Model/Model_AttributeSelectionList.cpp | 48 +++++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/src/Model/Model_AttributeSelectionList.cpp b/src/Model/Model_AttributeSelectionList.cpp index a51cfae97..85f522a6e 100644 --- a/src/Model/Model_AttributeSelectionList.cpp +++ b/src/Model/Model_AttributeSelectionList.cpp @@ -85,6 +85,44 @@ void Model_AttributeSelectionList::removeLast() } } +#include +#include + +// copies named shapes: we need the implementation of this +static void CopyNS(const Handle(TNaming_NamedShape)& theFrom, + const Handle(TDF_Attribute)& theTo) +{ + TDF_Label aLab = theTo->Label(); + TNaming_Builder B(aLab); + + TNaming_Iterator It (theFrom); + for ( ;It.More() ; It.Next()) { + const TopoDS_Shape& OS = It.OldShape(); + const TopoDS_Shape& NS = It.NewShape(); + TNaming_Evolution Status = It.Evolution(); + + switch (Status) { + case TNaming_PRIMITIVE : + B.Generated(NS); + break; + case TNaming_GENERATED : + B.Generated(OS, NS); + break; + case TNaming_MODIFY : + B.Modify(OS, NS); + break; + case TNaming_DELETE : + B.Delete (OS); + break; + case TNaming_SELECTED : + B.Select(NS, OS); + break; + default: + break; + } + } +} + /// makes copy of all attributes on the given label and all sub-labels static void copyAttrs(TDF_Label theSource, TDF_Label theDestination) { TDF_AttributeIterator anAttrIter(theSource); @@ -95,8 +133,14 @@ static void copyAttrs(TDF_Label theSource, TDF_Label theDestination) { aTargetAttr = anAttrIter.Value()->NewEmpty(); theDestination.AddAttribute(aTargetAttr); } - Handle(TDF_RelocationTable) aRelocTable = new TDF_RelocationTable(); // no relocation, empty map - anAttrIter.Value()->Paste(aTargetAttr, aRelocTable); + // for named shape copy exact shapes (in NamedShape Paste method the CopyTool is used) + Handle(TNaming_NamedShape) aNS = Handle(TNaming_NamedShape)::DownCast(anAttrIter.Value()); + if (aNS.IsNull()) { + Handle(TDF_RelocationTable) aRelocTable = new TDF_RelocationTable(); // no relocation, empty map + anAttrIter.Value()->Paste(aTargetAttr, aRelocTable); + } else { + CopyNS(aNS, aTargetAttr); + } } // copy the sub-labels content TDF_ChildIterator aSubLabsIter(theSource); -- 2.39.2