]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/Model/Model_BodyBuilder.cpp
Salome HOME
Updated copyright comment
[modules/shaper.git] / src / Model / Model_BodyBuilder.cpp
index fd33d7724a93e582d70040c160931e8b7c90a60c..d397d0a9b3f4176d8a862af9d6d89d1b81a4c46e 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -132,7 +132,7 @@ static bool isShapeInTree(const TDF_Label& theAccess1, const TDF_Label& theAcces
   if (aResult) { //check evolution and a label of this shape
     for(TNaming_SameShapeIterator aShapes(theShape, theAccess1); aShapes.More(); aShapes.Next())
     {
-      static Handle(TNaming_NamedShape) aNS;
+      Handle(TNaming_NamedShape) aNS;
       if (aShapes.Label().FindAttribute(TNaming_NamedShape::GetID(), aNS)) {
         if (aNS->Evolution() != TNaming_SELECTED) {
           theOriginalLabel = aNS->Label();
@@ -336,7 +336,23 @@ void Model_BodyBuilder::storeModified(const GeomShapePtr& theOldShape,
     TDF_Label anAccess2 = std::dynamic_pointer_cast<Model_Document>(
       ModelAPI_Session::get()->moduleDocument())->generalLabel();
     TDF_Label anOriginalLabel;
+    TopTools_ListOfShape anOldList;
     if (!isShapeInTree(aData->shapeLab(), anAccess2, aShapeOld, anOriginalLabel)) {
+      // check this could be a compund by the whole feature selection
+      if (aShapeOld.ShapeType() == TopAbs_COMPOUND)  {
+        for(TopoDS_Iterator aCompIter(aShapeOld); aCompIter.More(); aCompIter.Next()) {
+          if (isShapeInTree(aData->shapeLab(), anAccess2, aCompIter.Value(), anOriginalLabel)) {
+            anOldList.Append(aCompIter.Value());
+          } else {
+            anOldList.Clear();
+            break;
+          }
+        }
+      }
+    } else {
+      anOldList.Append(aShapeOld);
+    }
+    if (anOldList.IsEmpty()) {
       if (aBuilder->NamedShape()->Get().IsNull()) { // store as primitive if alone anyway
         aBuilder->Generated(aShapeNew);
       }
@@ -345,8 +361,10 @@ void Model_BodyBuilder::storeModified(const GeomShapePtr& theOldShape,
         myBuilders.erase(0);
         aBuilder = builder(0);
       }
-
-      aBuilder->Modify(aShapeOld, aShapeNew);
+      TopTools_ListIteratorOfListOfShape anOldIter(anOldList);
+      for(; anOldIter.More(); anOldIter.Next()) {
+        aBuilder->Modify(anOldIter.Value(), aShapeNew);
+      }
       // store information about the external document reference to restore old shape on open
       storeExternalReference(anOriginalLabel, aBuilder->NamedShape()->Label());
     }
@@ -511,7 +529,7 @@ void Model_BodyBuilder::generated(const GeomShapePtr& theOldShape,
   if (aNewShapeType == TopAbs_WIRE || aNewShapeType == TopAbs_SHELL) {
     // TODO: This is a workaround. New shape should be only vertex, edge or face.
     TopAbs_ShapeEnum aShapeTypeToExplore = aNewShapeType == TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE;
-    aTag = TopAbs_WIRE ? GENERATED_EDGES_TAG : GENERATED_FACES_TAG;
+    aTag = aNewShapeType == TopAbs_WIRE ? GENERATED_EDGES_TAG : GENERATED_FACES_TAG;
     for (TopExp_Explorer anExp(aNewShape, aShapeTypeToExplore); anExp.More(); anExp.Next()) {
       builder(aTag)->Generated(anOldShape, anExp.Current());
     }
@@ -616,6 +634,11 @@ void Model_BodyBuilder::loadModifiedShapes(const GeomMakeShapePtr& theAlgo,
     if (aCompound.get()) aShapeToExplore = aCompound;
   }
 
+  // Store all types of subshapes in the map to use them for checking
+  // if the new shapes are sub-shapes of this result
+  TopTools_MapOfShape aResultShapeSubMap;
+  TopExp::MapShapes(aResultShape->impl<TopoDS_Shape>(), aResultShapeSubMap);
+
   TopTools_MapOfShape anAlreadyProcessedShapes;
   std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
   for (GeomAPI_ShapeExplorer anOldShapeExp(aShapeToExplore, theShapeTypeToExplore);
@@ -627,36 +650,40 @@ void Model_BodyBuilder::loadModifiedShapes(const GeomMakeShapePtr& theAlgo,
 
     // There is no sense to write history if shape already processed
     // or old shape does not exist in the document.
-    bool anOldSubShapeAlreadyProcessed = !anAlreadyProcessedShapes.Add(anOldSubShape_);
-    TDF_Label anAccess2 = std::dynamic_pointer_cast<Model_Document>(
-      ModelAPI_Session::get()->moduleDocument())->generalLabel();
+    if (!anAlreadyProcessedShapes.Add(anOldSubShape_))
+    {
+      continue;
+    }
+
+    TDF_Label anAccess2 = std::dynamic_pointer_cast<Model_Document>(ModelAPI_Session::get()->moduleDocument())->generalLabel();
     TDF_Label anOriginalLabel;
-    bool anOldSubShapeNotInTree =
-      !isShapeInTree(aData->shapeLab(), anAccess2, anOldSubShape_, anOriginalLabel);
-    if (anOldSubShapeAlreadyProcessed || anOldSubShapeNotInTree) {
+    if (!isShapeInTree(aData->shapeLab(), anAccess2, anOldSubShape_, anOriginalLabel))
+    {
       continue;
     }
 
     // Get new shapes.
     ListOfShape aNewShapes;
     theAlgo->modified(anOldSubShape, aNewShapes);
-
     for (ListOfShape::const_iterator aNewShapesIt = aNewShapes.cbegin();
          aNewShapesIt != aNewShapes.cend();
          ++aNewShapesIt)
     {
       GeomShapePtr aNewShape = *aNewShapesIt;
       const TopoDS_Shape& aNewShape_ = aNewShape->impl<TopoDS_Shape>();
-      bool isGenerated = anOldSubShape_.ShapeType() != aNewShape_.ShapeType();
 
-      bool aNewShapeIsSameAsOldShape = anOldSubShape->isSame(aNewShape);
-      bool aNewShapeIsNotInResultShape = !aResultShape->isSubShape(aNewShape, false);
-      if (aNewShapeIsSameAsOldShape || aNewShapeIsNotInResultShape)
+      if (anOldSubShape->isSame(aNewShape))
         continue;
 
       if (aResultShape->isSame(aNewShape))
         continue; // it is stored on the root level (2241 - history propagation issue)
 
+      // Look in the map instead of aResultShape->isSubShape(aNewShape, false)
+      // to avoid many iterations of sub-shapes hierarchy that leads to performance issues
+      if (!aResultShapeSubMap.Contains(aNewShape_))
+        continue;
+
+      const bool isGenerated = anOldSubShape_.ShapeType() != aNewShape_.ShapeType();
       int aTag = isGenerated ? getGenerationTag(aNewShape_) : getModificationTag(aNewShape_);
       TNaming_Builder*aBuilder = builder(aTag);
       if (isAlreadyStored(aBuilder, anOldSubShape_, aNewShape_))
@@ -696,7 +723,9 @@ void Model_BodyBuilder::loadGeneratedShapes(const GeomMakeShapePtr& theAlgo,
     bool anOldSubShapeNotInTree =
       !isShapeInTree(aData->shapeLab(), anAccess2, anOldSubShape_, anOriginalLabel);
     if (anOldSubShapeAlreadyProcessed || anOldSubShapeNotInTree) {
-      if (theSaveOldIfNotInTree) {
+      // The second condition is added due to #20170 because sub-shape must be added to real parent
+      // shape, not the reference. The naming name of pure reference is not registered in document.
+      if (theSaveOldIfNotInTree && !aData->shapeLab().IsAttribute(TDF_Reference::GetID())) {
         std::string aSelectionName = theName + "Selected";
         generated(anOldSubShape, aSelectionName, false);
       } else
@@ -730,7 +759,7 @@ void Model_BodyBuilder::loadGeneratedShapes(const GeomMakeShapePtr& theAlgo,
         // TODO: This is a workaround. New shape should be only edge or face.
         TopAbs_ShapeEnum aShapeTypeToExplore = aNewShapeType == TopAbs_WIRE ? TopAbs_EDGE
                                                                             : TopAbs_FACE;
-        int aTag = TopAbs_WIRE ? GENERATED_EDGES_TAG : GENERATED_FACES_TAG;
+        int aTag = aNewShapeType == TopAbs_WIRE ? GENERATED_EDGES_TAG : GENERATED_FACES_TAG;
         for (TopExp_Explorer anExp(aNewShape_, aShapeTypeToExplore); anExp.More(); anExp.Next()) {
           builder(aTag)->Generated(anOldSubShape_, anExp.Current());
           // store information about the external document reference to restore old shape on open