]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
authormpv <mpv@opencascade.com>
Thu, 2 Apr 2015 12:28:54 +0000 (15:28 +0300)
committermpv <mpv@opencascade.com>
Thu, 2 Apr 2015 12:28:54 +0000 (15:28 +0300)
src/Model/Model_AttributeRefAttr.cpp
src/Model/Model_AttributeRefList.cpp
src/Model/Model_AttributeReference.cpp
src/Model/Model_AttributeSelection.cpp
src/Model/Model_Data.h

index 2d900eb142221d089617a372e714d182ebf54aa2..38e989e047ca7f10928df123f79e44117b43d02a 100644 (file)
@@ -23,8 +23,10 @@ void Model_AttributeRefAttr::setAttr(std::shared_ptr<ModelAPI_Attribute> 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<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());
@@ -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);
index c9722835887b00258b8e1acbac9797dac0dd06c1..c09190f3326da11cd0057ac0236d4397780762c9 100644 (file)
@@ -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<ModelAPI_Feature>(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;
         }
       }
index 860968cdd14f40f5381cea5a5193c354163104e3..9c51e545b66ee0983cfcb17eb8747ce7dfe96654 100644 (file)
@@ -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<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
@@ -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<ModelAPI_Feature>(owner());
-    if (anOwnerFeature.get()) {
-      aData->addBackReference(anOwnerFeature, id(), false);
-    }
+    ADD_BACK_REF(theObject);
 
     owner()->data()->sendAttributeUpdated(this);
   }
index ca0653fcc2ac05c0be6e13f45d6c37a2d525b372..3e23333451931c81706be68835312774179d2a04 100644 (file)
@@ -92,7 +92,7 @@ void Model_AttributeSelection::setValue(const ResultPtr& theContext,
   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
index f3fd1c384e8dfa7c6704e0f3f9cf357e64bfa60a..93de6977de7bb6cd633575d623c99ecb60a3d36f 100644 (file)
@@ -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<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