From a2ddb0f84f00241a308497a921e1a06ed5c56437 Mon Sep 17 00:00:00 2001 From: mpv Date: Mon, 13 Apr 2015 11:24:19 +0300 Subject: [PATCH] Make list not initialized if it is empty: on sketch add and then remove element sketch becomes invalid. --- src/Model/Model_AttributeRefList.cpp | 8 ++++++++ src/Model/Model_AttributeRefList.h | 2 ++ src/Model/Model_AttributeSelectionList.cpp | 8 ++++++++ src/Model/Model_AttributeSelectionList.h | 3 +++ src/ModelAPI/ModelAPI_Attribute.h | 2 +- 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Model/Model_AttributeRefList.cpp b/src/Model/Model_AttributeRefList.cpp index 13233fb9c..b1fcda046 100644 --- a/src/Model/Model_AttributeRefList.cpp +++ b/src/Model/Model_AttributeRefList.cpp @@ -54,6 +54,14 @@ int Model_AttributeRefList::size() const return myRef->Extent(); } +bool Model_AttributeRefList::isInitialized() +{ + if (size() == 0) { // empty list is not initialized list: sketch will be not valid after add/undo + return false; + } + return ModelAPI_AttributeRefList::isInitialized(); +} + list Model_AttributeRefList::list() { std::list aResult; diff --git a/src/Model/Model_AttributeRefList.h b/src/Model/Model_AttributeRefList.h index 2a4550a80..f59229a1a 100644 --- a/src/Model/Model_AttributeRefList.h +++ b/src/Model/Model_AttributeRefList.h @@ -37,6 +37,8 @@ class Model_AttributeRefList : public ModelAPI_AttributeRefList /// Returns the list of features MODEL_EXPORT virtual ObjectPtr object(const int theIndex) const; + /// Returns true if attribute was initialized by some value + MODEL_EXPORT virtual bool isInitialized(); protected: /// Objects are created for features automatically MODEL_EXPORT Model_AttributeRefList(TDF_Label& theLabel); diff --git a/src/Model/Model_AttributeSelectionList.cpp b/src/Model/Model_AttributeSelectionList.cpp index 79eb5c714..3b67df9eb 100644 --- a/src/Model/Model_AttributeSelectionList.cpp +++ b/src/Model/Model_AttributeSelectionList.cpp @@ -102,6 +102,14 @@ void Model_AttributeSelectionList::clear() } } +bool Model_AttributeSelectionList::isInitialized() +{ + if (size() == 0) { // empty list is not initialized list: sketch will be not valid after add/undo + return false; + } + return ModelAPI_AttributeSelectionList::isInitialized(); +} + Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel) { myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True; diff --git a/src/Model/Model_AttributeSelectionList.h b/src/Model/Model_AttributeSelectionList.h index 584c170e9..5865b8562 100644 --- a/src/Model/Model_AttributeSelectionList.h +++ b/src/Model/Model_AttributeSelectionList.h @@ -50,6 +50,9 @@ public: /// Returns all attributes MODEL_EXPORT virtual void clear(); + /// Returns true if attribute was initialized by some value + MODEL_EXPORT virtual bool isInitialized(); + protected: /// Objects are created for features automatically MODEL_EXPORT Model_AttributeSelectionList(TDF_Label& theLabel); diff --git a/src/ModelAPI/ModelAPI_Attribute.h b/src/ModelAPI/ModelAPI_Attribute.h index e3b1b056d..442e4e4a0 100644 --- a/src/ModelAPI/ModelAPI_Attribute.h +++ b/src/ModelAPI/ModelAPI_Attribute.h @@ -44,7 +44,7 @@ class ModelAPI_Attribute MODELAPI_EXPORT const std::shared_ptr& owner() const; /// Returns true if attribute was initialized by some value - MODELAPI_EXPORT bool isInitialized(); + MODELAPI_EXPORT virtual bool isInitialized(); /// Makes attribute initialized MODELAPI_EXPORT void setInitialized(); -- 2.39.2