Salome HOME
Fix of crash on feature in new part creation
[modules/shaper.git] / src / Model / Model_Data.h
index 5a2f6296e1a385745534e42fd2c56312aa4be27a..4e96a5be5c65e126cc2352ca2fc2f07e72904e44 100644 (file)
@@ -163,7 +163,10 @@ class Model_Data : public ModelAPI_Data
   MODEL_EXPORT virtual ModelAPI_ExecState execState();
 
   /// Registers error during the execution, causes the ExecutionFailed state
-  MODEL_EXPORT virtual void setError(const std::string& theError);
+  MODEL_EXPORT virtual void setError(const std::string& theError, bool theSend = true);
+
+  /// Registers error during the execution, causes the ExecutionFailed state
+  MODEL_EXPORT virtual std::string error() const;
 
   /// Returns the identifier of feature-owner, unique in this document
   MODEL_EXPORT virtual int featureId() const;
@@ -180,10 +183,43 @@ class Model_Data : public ModelAPI_Data
   MODEL_EXPORT virtual void copyTo(std::shared_ptr<ModelAPI_Data> theTarget);
 
 private:
-  /// removes all information about back references
+  /// Removes all information about back references
   void eraseBackReferences();
-  // adds a back reference (with identifier which attribute references to this object
-  void addBackReference(FeaturePtr theFeature, std::string theAttrID);
+  /// Adds a back reference (with identifier which attribute references to this object
+  /// It does not change the consealment flag of the data object result
+  /// \param theFeature feature referenced to this
+  /// \param theAttrID identifier of the attribute that is references from theFeature to this
+  void removeBackReference(FeaturePtr theFeature, std::string theAttrID);
+  /// Adds a back reference (with identifier which attribute references to this object
+  /// \param theFeature feature referenced to this
+  /// \param theAttrID identifier of the attribute that is references from theFeature to this
+  /// \param theApplyConcealment applies consealment flag changes
+  void addBackReference(FeaturePtr theFeature, std::string theAttrID, 
+    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