]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Bug #1170: wrong object names in Main objects field Partition
authordbv <dbv@opencascade.com>
Fri, 25 Dec 2015 07:17:20 +0000 (10:17 +0300)
committerdbv <dbv@opencascade.com>
Fri, 25 Dec 2015 07:17:42 +0000 (10:17 +0300)
src/Model/Model_BodyBuilder.cpp
src/Model/Model_BodyBuilder.h
src/Model/Model_ResultCompSolid.cpp
src/ModelAPI/ModelAPI_BodyBuilder.h
src/ModelAPI/ModelAPI_ResultBody.cpp
src/ModelAPI/ModelAPI_ResultBody.h

index e8b3479d78b202275129ab0af0c1f5d21b38d82d..476e22ace55e122a536b9f91fc66e80b49c8b1ee 100755 (executable)
@@ -18,6 +18,7 @@
 #include <TopoDS.hxx>
 #include <TopoDS_Face.hxx>
 #include <TDF_ChildIterator.hxx>
+#include <TDF_Reference.hxx>
 #include <TopTools_MapOfShape.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopTools_ListOfShape.hxx>
@@ -107,7 +108,8 @@ void Model_BodyBuilder::evolutionToSelection(const bool theFlag)
   evolutionToSelectionRec(aShapeLab, theFlag);
 }
 
-void Model_BodyBuilder::store(const std::shared_ptr<GeomAPI_Shape>& theShape)
+void Model_BodyBuilder::store(const std::shared_ptr<GeomAPI_Shape>& theShape,
+                              const bool theIsStoreSameShapes)
 {
   std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
   if (aData) {
@@ -122,6 +124,16 @@ void Model_BodyBuilder::store(const std::shared_ptr<GeomAPI_Shape>& theShape)
     if (aShape.IsNull())
       return;  // null shape inside
 
+    if(!theIsStoreSameShapes) {
+      Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aShape, aShapeLab);
+      if(!aNS.IsNull() && !aNS->IsEmpty()) {
+        // This shape is already in document, store reference instead of shape;
+        const TDF_Label aFoundLabel = aNS->Label();
+        TDF_Reference::Set(aShapeLab, aFoundLabel);
+        return;
+      }
+    }
+
     aBuilder.Generated(aShape);        
     // register name
     if(!aBuilder.NamedShape()->IsEmpty()) {
@@ -202,6 +214,12 @@ void Model_BodyBuilder::storeModified(const std::shared_ptr<GeomAPI_Shape>& theO
 
       TopoDS_Iterator aSubIter(aShapeNew);
       for(int aTag = theDecomposeSolidsTag; aSubIter.More(); aSubIter.Next()) {
+        const TopoDS_Shape& aShape = aSubIter.Value();
+        Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aShape, aShapeLab);
+        if(!aNS.IsNull() && !aNS->IsEmpty()) {
+          // This shape is already in document, don't add it.
+          continue;
+        }
         TNaming_Builder aSubBuilder(aShapeLab.FindChild(aTag++));
         aSubBuilder.Generated(aSubIter.Value());
         if(!aName.IsEmpty()) {
@@ -763,6 +781,10 @@ std::shared_ptr<GeomAPI_Shape> Model_BodyBuilder::shape()
   std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
   if (aData) {
     TDF_Label& aShapeLab = aData->shapeLab();
+    Handle(TDF_Reference) aRef;
+    if (aShapeLab.FindAttribute(TDF_Reference::GetID(), aRef)) {
+      aShapeLab = aRef->Get();
+    }
     Handle(TNaming_NamedShape) aName;
     if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
       TopoDS_Shape aShape = aName->Get();
index 90092e59eba3be0425989f2573d5e273697e5639..0941d38b2aaf990b7709af4fb8442a5264808b3c 100755 (executable)
@@ -27,7 +27,8 @@ class Model_BodyBuilder : public ModelAPI_BodyBuilder
   std::vector<TNaming_Builder*> myBuilders;
 public:
   /// Stores the shape (called by the execution method).
-  MODEL_EXPORT virtual void store(const std::shared_ptr<GeomAPI_Shape>& theShape);
+  MODEL_EXPORT virtual void store(const std::shared_ptr<GeomAPI_Shape>& theShape,
+                                  const bool theIsStoreSameShapes = true);
 
   /// Stores the generated shape (called by the execution method).
   MODEL_EXPORT virtual void storeGenerated(const std::shared_ptr<GeomAPI_Shape>& theFromShape,
index e66ba2d3084ea26e511ab0bde2caa1dc8b35fc66..8f4523c4580b0dc4cbf2658996bc7e0f0ba8d6ee 100755 (executable)
@@ -183,7 +183,7 @@ void Model_ResultCompSolid::updateSubs(const std::shared_ptr<GeomAPI_Shape>& the
         aSub = mySubs[aSubIndex];
       }
       if (!aSolidShape->isEqual(aSub->shape())) {
-        aSub->store(aSolidShape);
+        aSub->store(aSolidShape, false);
         aECreator->sendUpdated(aSub, EVENT_DISP);
         aECreator->sendUpdated(aSub, EVENT_UPD);
       }
index 424f9857b5f43558c8b430e160c6cdbe92d4acf5..629e1fa9a3ca7508283b48ddc46a0e434b5dcbe4 100755 (executable)
@@ -28,7 +28,8 @@ public:
   MODELAPI_EXPORT virtual ~ModelAPI_BodyBuilder() {};
 
   /// Stores the shape (called by the execution method).
-  virtual void store(const std::shared_ptr<GeomAPI_Shape>& theShape) = 0;
+  virtual void store(const std::shared_ptr<GeomAPI_Shape>& theShape,
+                     const bool theIsStoreSameShapes = true) = 0;
 
   /// Stores the generated shape (called by the execution method).
   virtual void storeGenerated(const std::shared_ptr<GeomAPI_Shape>& theFromShape,
index bcdc0bcb59442dbc1114e7b02d77184e8b160c52..6792f18bc335dd0bdc7c07b89e9aad0468e7a60e 100644 (file)
@@ -25,9 +25,10 @@ std::string ModelAPI_ResultBody::groupName()
   return group();
 }
 
-void ModelAPI_ResultBody::store(const std::shared_ptr<GeomAPI_Shape>& theShape)
+void ModelAPI_ResultBody::store(const std::shared_ptr<GeomAPI_Shape>& theShape,
+                                const bool theIsStoreSameShapes)
 {
-  myBuilder->store(theShape);
+  myBuilder->store(theShape, theIsStoreSameShapes);
 
   static Events_Loop* aLoop = Events_Loop::loop();
   static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
index a09c80638c103c6b72a69e294f407dae8f69bddf..ad5846e0f10a84927141a7b1f729b954c35d2bad 100644 (file)
@@ -44,8 +44,11 @@ public:
     return RESULT_BODY_COLOR;
   }
 
-  /// Stores the shape (called by the execution method).
-  MODELAPI_EXPORT virtual void store(const std::shared_ptr<GeomAPI_Shape>& theShape);
+  /// \brief Stores the shape (called by the execution method).
+  /// param[in] theShape shape to store.
+  /// param[in] theIsStoreSameShapes if false stores reference to the same shape if it is already in document.
+  MODELAPI_EXPORT virtual void store(const std::shared_ptr<GeomAPI_Shape>& theShape,
+                                     const bool theIsStoreSameShapes = true);
 
   /// Stores the generated shape (called by the execution method).
   MODELAPI_EXPORT virtual void storeGenerated(const std::shared_ptr<GeomAPI_Shape>& theFromShape,