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);
}
{
// 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<ModelAPI_Feature>(owner());
- if (anOwnerFeature.get()) {
- std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(
- anObject->data());
- aData->removeBackReference(anOwnerFeature, id());
- }
- }
-
if (theObject && (!myIsInitialized || myID->Get().Length() != 0 || object() != theObject)) {
+ REMOVE_BACK_REF(anObject);
+
std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(
theObject->data());
myRef->Set(aData->label().Father());
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);
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<ModelAPI_Feature>(owner());
- if (anOwnerFeature.get()) {
- aData->addBackReference(anOwnerFeature, id());
- }
+ ADD_BACK_REF(theObject);
owner()->data()->sendAttributeUpdated(this);
}
ObjectPtr anObj = aDoc->object(aLIter.Value());
if (anObj.get() == NULL) {
myRef->Remove(aLIter.Value());
+ REMOVE_BACK_REF(theObject);
break;
}
}
{
if(!theObject)
return;
- if (!myIsInitialized || value() != theObject) {
+ ObjectPtr aValue = value();
+ if (!myIsInitialized || aValue != theObject) {
+ REMOVE_BACK_REF(aValue);
+
std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(
- theObject->data());
+ theObject->data());
TDF_Label anObjLab = aData->label().Father(); // object label
if (owner()->document() == theObject->document()) { // same document, use reference attribute
}
// 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<ModelAPI_Feature>(owner());
- if (anOwnerFeature.get()) {
- aData->addBackReference(anOwnerFeature, id(), false);
- }
+ ADD_BACK_REF(theObject);
owner()->data()->sendAttributeUpdated(this);
}
if (theSubShape.get() && !theSubShape->isNull() && theSubShape->isEdge()) {
const TopoDS_Shape& aSubShape = theSubShape->impl<TopoDS_Shape>();
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
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<ModelAPI_Feature>(owner()); \
+ if (anAttributeOwnerFeature.get()) { \
+ std::shared_ptr<Model_Data> aTargetData = std::dynamic_pointer_cast<Model_Data>( \
+ (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<ModelAPI_Feature>(owner()); \
+ if (anAttOwnerFeature.get()) { \
+ std::shared_ptr<Model_Data> aTargetData = std::dynamic_pointer_cast<Model_Data>( \
+ (TARGET)->data()); \
+ aTargetData->removeBackReference(anAttOwnerFeature, id()); \
+ } \
+ }
+
#endif