From 2d983262575f003194a7cece728987a6a6e9a2c4 Mon Sep 17 00:00:00 2001 From: mpv Date: Mon, 11 Dec 2017 15:55:51 +0300 Subject: [PATCH] Fix the stability of the naming names generation (use the context in searching of the same shapes labels) --- src/Model/Model_BodyBuilder.cpp | 2 +- src/Model/Model_SelectionNaming.cpp | 38 ++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/Model/Model_BodyBuilder.cpp b/src/Model/Model_BodyBuilder.cpp index d26fdb1f7..c25d5dfa5 100755 --- a/src/Model/Model_BodyBuilder.cpp +++ b/src/Model/Model_BodyBuilder.cpp @@ -412,7 +412,7 @@ void Model_BodyBuilder::loadAndOrientModifiedShapes ( int aBuilderTag = aTag; if (!theIsStoreSeparate) aSameParentShapes++; - if (aSameParentShapes > 0) { // store in other label ( + if (aSameParentShapes > 0) { // store in other label aBuilderTag = 100000 - aSameParentShapes * 10 - aTag; } if(theIsStoreAsGenerated) { diff --git a/src/Model/Model_SelectionNaming.cpp b/src/Model/Model_SelectionNaming.cpp index dfd20739c..50b64918e 100644 --- a/src/Model/Model_SelectionNaming.cpp +++ b/src/Model/Model_SelectionNaming.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -61,6 +62,34 @@ Model_SelectionNaming::Model_SelectionNaming(TDF_Label theSelectionLab) myLab = theSelectionLab; } +// searches named shape by the shape in the given document (identified by the label) +// tries to find s shape nearest to the context-label +static Handle(TNaming_NamedShape) shapeToNS(const TDF_Label theLabAccess, + const TopoDS_Shape& theShape, const TDF_Label& theContextLab) +{ + Handle(TNaming_NamedShape) aResult; + if (!TNaming_Tool::HasLabel(theLabAccess, theShape)) // no shape in the document + return aResult; + int aContextLabDepth = theContextLab.IsNull() ? 100 : theContextLab.Depth(); + TNaming_SameShapeIterator aNSIter(theShape, theLabAccess); + for(; aNSIter.More(); aNSIter.Next()) { + TDF_Label aLabel = aNSIter.Label(); + Handle(TNaming_NamedShape) aNS; + if (aLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS)) { + if (aNS->Evolution() != TNaming_SELECTED) { + // check this is the context-shape + while(aLabel.Depth() > aContextLabDepth) + aLabel = aLabel.Father(); + if (aLabel.IsEqual(theContextLab)) + return aNS; + if (aResult.IsNull()) // take the first, otherwise it will get shapes from results, etc + aResult = aNS; // keep some result anyway - if there are no context labels return any + } + } + } + return aResult; +} + std::string Model_SelectionNaming::getShapeName( std::shared_ptr theDoc, const TopoDS_Shape& theShape, ResultPtr& theContext, const bool theAnotherDoc, const bool theWholeContext) @@ -70,13 +99,14 @@ std::string Model_SelectionNaming::getShapeName( // (it was in BodyBuilder, but did not work on Result rename) bool isNeedContextName = theContext->shape().get() != NULL; // check if the subShape is already in DF - Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(theShape, myLab); + std::shared_ptr aData = + std::dynamic_pointer_cast(theContext->data()); + TDF_Label aContextDataLab(aData.get() && aData->isValid() ? aData->label() : TDF_Label()); + Handle(TNaming_NamedShape) aNS = shapeToNS(myLab, theShape, aContextDataLab); Handle(TDataStd_Name) anAttr; if(!aNS.IsNull() && !aNS->IsEmpty()) { // in the document if(aNS->Label().FindAttribute(TDataStd_Name::GetID(), anAttr)) { - std::shared_ptr aData = - std::dynamic_pointer_cast(theContext->data()); - if (isNeedContextName && aData && aData->label().IsEqual(aNS->Label())) { + if (isNeedContextName && aData && aContextDataLab.IsEqual(aNS->Label())) { // do nothing because this context name will be added later in this method } else { aName = TCollection_AsciiString(anAttr->Get()).ToCString(); -- 2.39.2