From 661e9cfd56e1f8bb05d868292a669d7ccc8b12e8 Mon Sep 17 00:00:00 2001 From: mpv Date: Mon, 15 Aug 2016 16:29:51 +0300 Subject: [PATCH] Issue #1648: Dump Python in the High Level Parameterized Geometry API. Debug of naming name in selection: external document construction elements and compsolids (for remove shape) --- src/Model/Model_AttributeSelection.cpp | 27 ++++++++++++++++++++++---- src/Model/Model_AttributeSelection.h | 3 +++ src/Model/Model_SelectionNaming.cpp | 13 +++++++++---- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index ec6c691f8..d35ea9cee 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -148,7 +148,8 @@ void Model_AttributeSelection::setValue(const ResultPtr& theContext, aBuilder.Generated(theContext->shape()->impl()); std::shared_ptr aMyDoc = std::dynamic_pointer_cast(owner()->document()); - std::string aName = theContext->data()->name(); + std::string aName = contextName(theContext); + // for selection in different document, add the document name aMyDoc->addNamingName(aSelLab, aName); TDataStd_Name::Set(aSelLab, aName.c_str()); } else { // for sketch the naming is needed in DS @@ -417,7 +418,7 @@ bool Model_AttributeSelection::update() aBuilder.Generated(aContext->shape()->impl()); std::shared_ptr aMyDoc = std::dynamic_pointer_cast(owner()->document()); - std::string aName = aContext->data()->name(); + std::string aName = contextName(aContext); aMyDoc->addNamingName(aSelLab, aName); TDataStd_Name::Set(aSelLab, aName.c_str()); } @@ -714,8 +715,9 @@ void Model_AttributeSelection::selectConstruction( // saving of context is enough: result construction contains exactly the needed shape TNaming_Builder aBuilder(selectionLabel()); aBuilder.Generated(aSubShape); - aMyDoc->addNamingName(selectionLabel(), theContext->data()->name()); - TDataStd_Name::Set(selectionLabel(), theContext->data()->name().c_str()); + std::string aName = contextName(theContext); + aMyDoc->addNamingName(selectionLabel(), aName); + TDataStd_Name::Set(selectionLabel(), aName.c_str()); return; } std::shared_ptr aData = std::dynamic_pointer_cast(owner()->data()); @@ -990,3 +992,20 @@ void Model_AttributeSelection::setId(int theID) setValue(aContext, aSelection); } +std::string Model_AttributeSelection::contextName(const ResultPtr& theContext) const +{ + std::string aResult; + if (owner()->document() != theContext->document()) { + if (theContext->document() == ModelAPI_Session::get()->moduleDocument()) { + aResult = theContext->document()->kind() + "/"; + } else { + ResultPtr aDocRes = ModelAPI_Tools::findPartResult( + ModelAPI_Session::get()->moduleDocument(), theContext->document()); + if (aDocRes.get()) { + aResult = aDocRes->data()->name() + "/"; + } + } + } + aResult += theContext->data()->name(); + return aResult; +} diff --git a/src/Model/Model_AttributeSelection.h b/src/Model/Model_AttributeSelection.h index 1f3c45945..2f9250642 100644 --- a/src/Model/Model_AttributeSelection.h +++ b/src/Model/Model_AttributeSelection.h @@ -104,6 +104,9 @@ protected: /// Sets the ID of the attribute in Data (called from Data): here it is used for myRef ID setting MODEL_EXPORT virtual void setID(const std::string theID); + /// Returns the name by context. Adds the part name if the context is located in other document + std::string contextName(const ResultPtr& theContext) const; + friend class Model_Data; friend class Model_AttributeSelectionList; }; diff --git a/src/Model/Model_SelectionNaming.cpp b/src/Model/Model_SelectionNaming.cpp index a9275e4d1..fe623ef2e 100644 --- a/src/Model/Model_SelectionNaming.cpp +++ b/src/Model/Model_SelectionNaming.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -627,20 +628,24 @@ bool Model_SelectionNaming::selectSubShape(const std::string& theType, ResultPtr aCont = aDoc->findByName(aContName); // possible this is body where postfix is added to distinguish several shapes on the same label int aSubShapeId = -1; // -1 means sub shape not found - if (!aCont.get() && aContName == aSubShapeName) { + // for result body the name wihtout "_" has higher priority than with it: it is always added + if ((!aCont.get() || (aCont->groupName() == ModelAPI_ResultBody::group())) && + aContName == aSubShapeName) { size_t aPostIndex = aContName.rfind('_'); if (aPostIndex != std::string::npos) { std::string aSubContName = aContName.substr(0, aPostIndex); - aCont = aDoc->findByName(aSubContName); - if (aCont.get()) { + ResultPtr aSubCont = aDoc->findByName(aSubContName); + if (aSubCont.get()) { try { std::string aNum = aContName.substr(aPostIndex + 1); aSubShapeId = std::stoi(aNum); } catch (std::invalid_argument&) { aSubShapeId = -1; } - if (aSubShapeId > 0) + if (aSubShapeId > 0) { aContName = aSubContName; + aCont = aSubCont; + } } } } -- 2.39.2