From 5d99e1e3ab1479b0f05fb7158612cb59801cb14f Mon Sep 17 00:00:00 2001 From: mpv Date: Thu, 21 May 2015 09:44:27 +0300 Subject: [PATCH] Make references are not initialized is they references to nothing: parallelity in sketch, from/to in extrusion, etc. --- src/Model/Model_AttributeRefAttr.cpp | 10 +++++++- src/Model/Model_AttributeRefAttr.h | 4 +++ src/Model/Model_AttributeReference.cpp | 34 +++++++++++++++++++------- src/Model/Model_AttributeReference.h | 4 +++ 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/Model/Model_AttributeRefAttr.cpp b/src/Model/Model_AttributeRefAttr.cpp index f399ba5be..0c24fe3e1 100644 --- a/src/Model/Model_AttributeRefAttr.cpp +++ b/src/Model/Model_AttributeRefAttr.cpp @@ -46,7 +46,7 @@ void Model_AttributeRefAttr::setObject(ObjectPtr theObject) { // the back reference from the previous object to the attribute should be removed ObjectPtr anObject = object(); - if (theObject && (!myIsInitialized || myID->Get().Length() != 0 || object() != theObject)) { + if (theObject.get() && (!myIsInitialized || myID->Get().Length() != 0 || object() != theObject)) { REMOVE_BACK_REF(anObject); std::shared_ptr aData = std::dynamic_pointer_cast( @@ -84,6 +84,14 @@ ObjectPtr Model_AttributeRefAttr::object() return ObjectPtr(); } +bool Model_AttributeRefAttr::isInitialized() +{ + if (myRef->Get() == myRef->Label()) { // empty is not initialized: sketch parallelity + return false; + } + return ModelAPI_AttributeRefAttr::isInitialized(); +} + Model_AttributeRefAttr::Model_AttributeRefAttr(TDF_Label& theLabel) { myIsInitialized = theLabel.FindAttribute(TDataStd_Comment::GetID(), myID) == Standard_True; diff --git a/src/Model/Model_AttributeRefAttr.h b/src/Model/Model_AttributeRefAttr.h index 94609a8f5..66c0870e6 100644 --- a/src/Model/Model_AttributeRefAttr.h +++ b/src/Model/Model_AttributeRefAttr.h @@ -40,6 +40,10 @@ class Model_AttributeRefAttr : public ModelAPI_AttributeRefAttr /// Returns object referenced from this attribute MODEL_EXPORT virtual ObjectPtr object(); + /// Returns true if attribute was initialized by some value + MODEL_EXPORT virtual bool isInitialized(); + + protected: /// Objects are created for features automatically MODEL_EXPORT Model_AttributeRefAttr(TDF_Label& theLabel); diff --git a/src/Model/Model_AttributeReference.cpp b/src/Model/Model_AttributeReference.cpp index 011c8bfbc..8a44eec0e 100644 --- a/src/Model/Model_AttributeReference.cpp +++ b/src/Model/Model_AttributeReference.cpp @@ -20,21 +20,29 @@ using namespace std; void Model_AttributeReference::setValue(ObjectPtr theObject) { - if(!theObject) - return; + // now allow to deselect in this attribute: extrusion from/to + //if(!theObject) + // return; ObjectPtr aValue = value(); if (!myIsInitialized || aValue != theObject) { REMOVE_BACK_REF(aValue); - std::shared_ptr aData = std::dynamic_pointer_cast( - theObject->data()); - TDF_Label anObjLab = aData->label().Father(); // object label - - if (owner()->document() == theObject->document()) { // same document, use reference attribute + TDF_Label anObjLab; + if (theObject.get() && theObject->data().get() && theObject->data()->isValid()) { + std::shared_ptr aData = std::dynamic_pointer_cast( + theObject->data()); + anObjLab = aData->label().Father(); // object label + } + // same document, use reference attribute + if (anObjLab.IsNull() || owner()->document() == theObject->document()) { std::shared_ptr aDoc = std::dynamic_pointer_cast(owner()->document()); - myRef->Set(anObjLab); // references to the object label + if (anObjLab.IsNull()) { + myRef->Set(myRef->Label()); + } else { + myRef->Set(anObjLab); // references to the object label + } // remove external link attributes (if any) myRef->Label().ForgetAttribute(TDataStd_Comment::GetID()); myRef->Label().ForgetAttribute(TDataStd_AsciiString::GetID()); @@ -55,7 +63,7 @@ void Model_AttributeReference::setValue(ObjectPtr theObject) ObjectPtr Model_AttributeReference::value() { - if (myIsInitialized) { + if (isInitialized()) { Handle(TDataStd_Comment) aDocID; if (myRef->Label().FindAttribute(TDataStd_Comment::GetID(), aDocID)) { // external ref DocumentPtr aRefDoc = @@ -86,6 +94,14 @@ ObjectPtr Model_AttributeReference::value() return FeaturePtr(); } +bool Model_AttributeReference::isInitialized() +{ + if (myRef->Label() == myRef->Get()) { // empty reference is not initialized + return false; + } + return ModelAPI_AttributeReference::isInitialized(); +} + Model_AttributeReference::Model_AttributeReference(TDF_Label& theLabel) { myIsInitialized = theLabel.FindAttribute(TDF_Reference::GetID(), myRef) == Standard_True; diff --git a/src/Model/Model_AttributeReference.h b/src/Model/Model_AttributeReference.h index 991f4e725..7ea779b6c 100644 --- a/src/Model/Model_AttributeReference.h +++ b/src/Model/Model_AttributeReference.h @@ -32,6 +32,10 @@ class Model_AttributeReference : public ModelAPI_AttributeReference MODEL_EXPORT virtual void setObject(const std::shared_ptr& theObject); + /// Returns true if attribute was initialized by some value + MODEL_EXPORT virtual bool isInitialized(); + + protected: /// Objects are created for features automatically MODEL_EXPORT Model_AttributeReference(TDF_Label& theLabel); -- 2.39.2