From b523ee33c94b11b1945513b17d94aa96257f3eb7 Mon Sep 17 00:00:00 2001 From: mpv Date: Thu, 2 Apr 2015 15:28:27 +0300 Subject: [PATCH] Fixed the problem with fillet undo --- src/Model/Model_AttributeRefAttr.cpp | 15 ++++++--------- src/Model/Model_AttributeRefList.cpp | 6 ++---- src/Model/Model_AttributeReference.cpp | 12 ++++++------ src/Model/Model_AttributeSelection.cpp | 2 +- src/Model/Model_Data.h | 24 ++++++++++++++++++++++++ 5 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/Model/Model_AttributeRefAttr.cpp b/src/Model/Model_AttributeRefAttr.cpp index 2d900eb14..38e989e04 100644 --- a/src/Model/Model_AttributeRefAttr.cpp +++ b/src/Model/Model_AttributeRefAttr.cpp @@ -23,8 +23,10 @@ void Model_AttributeRefAttr::setAttr(std::shared_ptr theAttr string anID = aData->id(theAttr); if (myIsInitialized && object() == theAttr->owner() && myID->Get().IsEqual(anID.c_str())) return; // nothing is changed + REMOVE_BACK_REF(theAttr->owner()); myRef->Set(aData->label().Father()); myID->Set(aData->id(theAttr).c_str()); + ADD_BACK_REF(theAttr->owner()); owner()->data()->sendAttributeUpdated(this); } @@ -43,16 +45,9 @@ void Model_AttributeRefAttr::setObject(ObjectPtr theObject) { // the back reference from the previous object to the attribute should be removed ObjectPtr anObject = object(); - if (anObject.get() && anObject != theObject) { - FeaturePtr anOwnerFeature = std::dynamic_pointer_cast(owner()); - if (anOwnerFeature.get()) { - std::shared_ptr aData = std::dynamic_pointer_cast( - anObject->data()); - aData->removeBackReference(anOwnerFeature, id()); - } - } - if (theObject && (!myIsInitialized || myID->Get().Length() != 0 || object() != theObject)) { + REMOVE_BACK_REF(anObject); + std::shared_ptr aData = std::dynamic_pointer_cast( theObject->data()); myRef->Set(aData->label().Father()); @@ -64,8 +59,10 @@ void Model_AttributeRefAttr::setObject(ObjectPtr theObject) if (anOwnerFeature.get()) { aData->addBackReference(anOwnerFeature, id(), false); } + ADD_BACK_REF(theObject); owner()->data()->sendAttributeUpdated(this); } else if (theObject.get() == NULL) { + REMOVE_BACK_REF(anObject); myRef->Set(myRef->Label()); // reference to itself means that object is null myID->Set(""); // feature is identified by the empty ID owner()->data()->sendAttributeUpdated(this); diff --git a/src/Model/Model_AttributeRefList.cpp b/src/Model/Model_AttributeRefList.cpp index c97228358..c09190f33 100644 --- a/src/Model/Model_AttributeRefList.cpp +++ b/src/Model/Model_AttributeRefList.cpp @@ -18,10 +18,7 @@ void Model_AttributeRefList::append(ObjectPtr theObject) myRef->Append(aData->label().Father()); // store label of the object // do it before the transaction finish to make just created/removed objects know dependencies // and reference from composite feature is removed automatically - FeaturePtr anOwnerFeature = std::dynamic_pointer_cast(owner()); - if (anOwnerFeature.get()) { - aData->addBackReference(anOwnerFeature, id()); - } + ADD_BACK_REF(theObject); owner()->data()->sendAttributeUpdated(this); } @@ -42,6 +39,7 @@ void Model_AttributeRefList::remove(ObjectPtr theObject) ObjectPtr anObj = aDoc->object(aLIter.Value()); if (anObj.get() == NULL) { myRef->Remove(aLIter.Value()); + REMOVE_BACK_REF(theObject); break; } } diff --git a/src/Model/Model_AttributeReference.cpp b/src/Model/Model_AttributeReference.cpp index 860968cdd..9c51e545b 100644 --- a/src/Model/Model_AttributeReference.cpp +++ b/src/Model/Model_AttributeReference.cpp @@ -21,9 +21,12 @@ void Model_AttributeReference::setValue(ObjectPtr theObject) { if(!theObject) return; - if (!myIsInitialized || value() != theObject) { + ObjectPtr aValue = value(); + if (!myIsInitialized || aValue != theObject) { + REMOVE_BACK_REF(aValue); + std::shared_ptr aData = std::dynamic_pointer_cast( - theObject->data()); + theObject->data()); TDF_Label anObjLab = aData->label().Father(); // object label if (owner()->document() == theObject->document()) { // same document, use reference attribute @@ -43,10 +46,7 @@ void Model_AttributeReference::setValue(ObjectPtr theObject) } // do it before the transaction finish to make just created/removed objects know dependencies // and reference from composite feature is removed automatically - FeaturePtr anOwnerFeature = std::dynamic_pointer_cast(owner()); - if (anOwnerFeature.get()) { - aData->addBackReference(anOwnerFeature, id(), false); - } + ADD_BACK_REF(theObject); owner()->data()->sendAttributeUpdated(this); } diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index ca0653fcc..3e2333345 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -92,7 +92,7 @@ void Model_AttributeSelection::setValue(const ResultPtr& theContext, if (theSubShape.get() && !theSubShape->isNull() && theSubShape->isEdge()) { const TopoDS_Shape& aSubShape = theSubShape->impl(); if (aSubShape.ShapeType() == TopAbs_EDGE) - isDegeneratedEdge = BRep_Tool::Degenerated(TopoDS::Edge(aSubShape)); + isDegeneratedEdge = BRep_Tool::Degenerated(TopoDS::Edge(aSubShape)) == Standard_True; } if (!theContext.get() || isDegeneratedEdge) { // to keep the reference attribute label diff --git a/src/Model/Model_Data.h b/src/Model/Model_Data.h index f3fd1c384..93de6977d 100644 --- a/src/Model/Model_Data.h +++ b/src/Model/Model_Data.h @@ -195,4 +195,28 @@ private: const bool theApplyConcealment = true); }; +/// Generic method to register back reference, used in referencing attributes. +/// Without concealment change, it will be done later, on synchronization. +#define ADD_BACK_REF(TARGET) \ + if (TARGET.get() != NULL) { \ + FeaturePtr anAttributeOwnerFeature = std::dynamic_pointer_cast(owner()); \ + if (anAttributeOwnerFeature.get()) { \ + std::shared_ptr aTargetData = std::dynamic_pointer_cast( \ + (TARGET)->data()); \ + aTargetData->addBackReference(anAttributeOwnerFeature, id(), false); \ + } \ + } + +/// Generic method to unregister back reference, used in referencing attributes. +/// Without concealment change, it will be done later, on synchronization. +#define REMOVE_BACK_REF(TARGET) \ + if (TARGET.get() != NULL) { \ + FeaturePtr anAttOwnerFeature = std::dynamic_pointer_cast(owner()); \ + if (anAttOwnerFeature.get()) { \ + std::shared_ptr aTargetData = std::dynamic_pointer_cast( \ + (TARGET)->data()); \ + aTargetData->removeBackReference(anAttOwnerFeature, id()); \ + } \ + } + #endif -- 2.39.2