Salome HOME
Issue #2615 : EDF 2018-3 Sub-results states
authormpv <mpv@opencascade.com>
Tue, 18 Sep 2018 07:21:38 +0000 (10:21 +0300)
committermpv <mpv@opencascade.com>
Tue, 18 Sep 2018 07:22:01 +0000 (10:22 +0300)
Keep the connected compounds information.

src/Model/Model_Data.h
src/Model/Model_Objects.cpp
src/Model/Model_ResultBody.cpp
src/Model/Model_ResultBody.h
src/ModelAPI/ModelAPI_ResultBody.h

index 8d12bc4d32a53f8ec81dec7a9b5d98aaec7262f2..598193cb8903bc6eae4ed0b44601ca727bd94e46 100644 (file)
@@ -96,6 +96,7 @@ class Model_Data : public ModelAPI_Data
   friend class Model_ValidatorsFactory;
   friend class Model_SelectionNaming;
   friend class Model_ResultConstruction;
+  friend class Model_ResultBody;
 
  public:
   /// The simplest constructor. "setLabel" must be called just after to initialize correctly.
index 1b8dad602a530662715676095a544506794aa6fd..70183795c0f94329fc2eb74310a998e5d7ed8e98 100644 (file)
@@ -1903,7 +1903,7 @@ void Model_Objects::updateResults(FeaturePtr theFeature, std::set<FeaturePtr>& t
     for (; aResSize && aRes != theFeature->results().cend(); aRes++, aResSize++) {
       if ((*aRes)->data()->isValid() && (*aRes)->groupName() == ModelAPI_ResultBody::group()) {
         ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aRes);
-        aBody->updateSubs(aBody->shape());
+        aBody->updateSubs(aBody->shape(), false);
       }
     }
   }
index c68a4ae4b54f2107f56759a0fa7c5bcfbc99ed29..514b0406d1083a2fd01196424e5e62167dd4b3e7 100644 (file)
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Tools.h>
+#include <Model_Data.h>
 #include <Events_Loop.h>
 
 #include <TopoDS_Shape.hxx>
 #include <TopExp_Explorer.hxx>
+#include <TDataStd_UAttribute.hxx>
 
+// if this attribute exists, the shape is connected topology
+Standard_GUID kIsConnectedTopology("e51392e0-3a4d-405d-8e36-bbfe19858ef5");
+// if this attribute exists, the connected topology flag must be recomputed
+Standard_GUID kUpdateConnectedTopology("01ef7a45-0bec-4266-b0b4-4aa570921818");
 
 Model_ResultBody::Model_ResultBody() : ModelAPI_ResultBody()
 {
@@ -121,7 +127,7 @@ bool Model_ResultBody::setDisabled(std::shared_ptr<ModelAPI_Result> theThis, con
   bool aChanged = ModelAPI_ResultBody::setDisabled(theThis, theFlag);
   if (aChanged) { // state is changed, so modifications are needed
     myBuilder->evolutionToSelection(theFlag);
-    updateSubs(shape()); // to set disabled/enabled
+    updateSubs(shape(), false); // to set disabled/enabled
   }
   return aChanged;
 }
@@ -192,12 +198,20 @@ void Model_ResultBody::updateConcealment()
   }
 }
 
-void Model_ResultBody::updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisShape)
+void Model_ResultBody::updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisShape,
+                                  const bool theShapeChanged)
 {
   static Events_Loop* aLoop = Events_Loop::loop();
   static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
   static Events_ID EVENT_UPD = aLoop->eventByName(EVENT_OBJECT_UPDATED);
   static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
+  // erase flag that topology is connected: the shape is new
+  if (theShapeChanged && data().get()) {
+    TDF_Label aDataLab = std::dynamic_pointer_cast<Model_Data>(data())->label();
+    if (!aDataLab.IsNull()) {
+      TDataStd_UAttribute::Set(aDataLab, kUpdateConnectedTopology);
+    }
+  }
   // iterate all sub-solids of compsolid to make sub-results synchronized with them
   TopoDS_Shape aThisShape;
   if (theThisShape.get()) aThisShape = theThisShape->impl<TopoDS_Shape>();
@@ -269,3 +283,21 @@ bool Model_ResultBody::isLatestEqual(const std::shared_ptr<GeomAPI_Shape>& theSh
   }
   return false;
 }
+
+bool Model_ResultBody::isConnectedTopology()
+{
+  TDF_Label aDataLab = std::dynamic_pointer_cast<Model_Data>(data())->label();
+  if (!aDataLab.IsNull()) {
+    if (aDataLab.IsAttribute(kUpdateConnectedTopology)) { // recompute state
+      aDataLab.ForgetAttribute(kUpdateConnectedTopology);
+      GeomShapePtr aShape = shape();
+      if (aShape.get() && aShape->isConnectedTopology()) {
+        TDataStd_UAttribute::Set(aDataLab, kIsConnectedTopology);
+      } else {
+        aDataLab.ForgetAttribute(kIsConnectedTopology);
+      }
+    }
+    return aDataLab.IsAttribute(kIsConnectedTopology);
+  }
+  return false; // invalid case
+}
index ad5f1c53136a25ca5a985f834ea5e400823a229f..6047bc059c71ea4e56f277b0bea1c4c6e561f5eb 100644 (file)
@@ -87,12 +87,16 @@ public:
   // is equal to the given shape
   MODEL_EXPORT virtual bool isLatestEqual(const std::shared_ptr<GeomAPI_Shape>& theShape);
 
+  /// Returns true is the topology is connected.
+  MODEL_EXPORT virtual bool isConnectedTopology();
+
 protected:
   /// Makes a body on the given feature
   Model_ResultBody();
 
   /// Updates the sub-bodies if shape of this object is composite-solid
-  void updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisShape);
+  void updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisShape,
+                  const bool theShapeChanged = true);
 
   // Checks the state of children and partents to send events of creation/erase when needed
   void updateConcealment();
index 049e821753affd06603fb426f2ccfcb1a61cd424..cb17e6522241d13c3303946089413c22c19f04db 100644 (file)
@@ -170,16 +170,16 @@ public:
   // is equal to the given shape
   MODELAPI_EXPORT virtual bool isLatestEqual(const std::shared_ptr<GeomAPI_Shape>& theShape) = 0;
 
-  /// Returns true is the topology is connected. Cashes this information for the current shape,
-  /// so it is more effective to use this method than directly GeomAPI_Shape.
-  MODELAPI_EXPORT virtual bool isConnectedTopology();
+  /// Returns true is the topology is connected.
+  MODELAPI_EXPORT virtual bool isConnectedTopology() = 0;
 
   /// Set displayed flag to the result and all sub results
   /// \param theDisplay a boolean value
   MODELAPI_EXPORT virtual void setDisplayed(const bool theDisplay);
 
   /// Updates the sub-bodies if shape of this object is compsolid or compound
-  MODELAPI_EXPORT virtual void updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisShape) = 0;
+  MODELAPI_EXPORT virtual void updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisShape,
+    const bool theShapeChanged = true) = 0;
 
 protected:
   /// Default constructor accessible only from Model_Objects