From a0d983b897197391d7af1a1eadb83361e6b241b8 Mon Sep 17 00:00:00 2001 From: azv Date: Thu, 13 Feb 2020 15:39:09 +0300 Subject: [PATCH] Fix the issue related to copying AttributeSelectionList (issue #18710) --- src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp | 10 ++-------- src/Model/Model_AttributeSelectionList.cpp | 10 ++++++++++ src/Model/Model_AttributeSelectionList.h | 3 +++ src/ModelAPI/ModelAPI_AttributeSelectionList.h | 3 +++ 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp index 05826f0a8..ca42c50ea 100644 --- a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp @@ -111,15 +111,9 @@ void ExchangePlugin_ExportFeature::initAttributes() AttributeStringPtr aTypeAttr = string(EXPORT_TYPE_ID()); if (aTypeAttr->isInitialized() && aTypeAttr->value() == "XAO") { AttributeSelectionListPtr aSelList = selectionList(SELECTION_LIST_ID()); - int aSelListSize = aSelList->size(); AttributeSelectionListPtr aXAOSelList = selectionList(XAO_SELECTION_LIST_ID()); - if (aSelListSize > 0 && aXAOSelList->size() == 0) { - for (int i = 0; i < aSelListSize; ++i) { - AttributeSelectionPtr aSelection = aSelList->value(i); - aXAOSelList->append(aSelection->context(), aSelection->value()); - } - aXAOSelList->setSelectionType(aSelList->selectionType()); - } + if (aSelList->size() > 0 && aXAOSelList->size() == 0) + aSelList->copyTo(aXAOSelList); aSelList->clear(); } } diff --git a/src/Model/Model_AttributeSelectionList.cpp b/src/Model/Model_AttributeSelectionList.cpp index 170190ef6..9e7b0b6ff 100644 --- a/src/Model/Model_AttributeSelectionList.cpp +++ b/src/Model/Model_AttributeSelectionList.cpp @@ -269,6 +269,16 @@ void Model_AttributeSelectionList::remove(const std::set& theIndices) } } +void Model_AttributeSelectionList::copyTo(AttributeSelectionListPtr theTarget) const +{ + std::shared_ptr aTarget = + std::dynamic_pointer_cast(theTarget); + if (aTarget) { + copyAttrs(myLab, aTarget->myLab); + aTarget->reinit(); + } +} + int Model_AttributeSelectionList::size() { return mySize->Get(); diff --git a/src/Model/Model_AttributeSelectionList.h b/src/Model/Model_AttributeSelectionList.h index 3ed3e2804..2db50d9b4 100644 --- a/src/Model/Model_AttributeSelectionList.h +++ b/src/Model/Model_AttributeSelectionList.h @@ -66,6 +66,9 @@ public: MODEL_EXPORT virtual void append(const std::string& theType, const std::string& theContextName, const int theIndex); + /// Copy the selection list to the destination attribute + MODEL_EXPORT virtual void copyTo(AttributeSelectionListPtr theTarget) const; + /// Reset temporary stored values virtual void removeTemporaryValues(); diff --git a/src/ModelAPI/ModelAPI_AttributeSelectionList.h b/src/ModelAPI/ModelAPI_AttributeSelectionList.h index 60b9becfa..16cd5f979 100644 --- a/src/ModelAPI/ModelAPI_AttributeSelectionList.h +++ b/src/ModelAPI/ModelAPI_AttributeSelectionList.h @@ -64,6 +64,9 @@ public: virtual void append(const std::string& theType, const std::string& theContextName, const int theIndex) = 0; + /// Copy the selection list to the destination attribute + virtual void copyTo(std::shared_ptr theTarget) const = 0; + /// Reset temporary stored values virtual void removeTemporaryValues() = 0; -- 2.39.2