Salome HOME
Fix for the issue #686: now compounds produced by the Boolean operations can be corre...
[modules/shaper.git] / src / Model / Model_ResultBody.cpp
index afc1c21c81d0b32e608b693fba86889ae413319b..8cecd4a92d837d8ed336dba3218e673456270b35 100644 (file)
@@ -66,14 +66,26 @@ static void EvolutionToSelection(TDF_Label theLab, const bool theFlag) {
   Handle(TNaming_NamedShape) aName;
   int anEvolution = -1;
   if (theLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
-    anEvolution = (int)(aName->Evolution());
+    TNaming_Evolution aNSEvol = aName->Evolution();
+    if ((aNSEvol == TNaming_SELECTED && theFlag) ||
+        (aNSEvol != TNaming_SELECTED && !theFlag)) { // nothing to do, it is already correct
+      return;
+    }
+    anEvolution = (int)(aNSEvol);
+    if (!theFlag) {
+      Handle(TDataStd_Integer) anAttrEvol;
+      if (theLab.FindAttribute(TDataStd_Integer::GetID(), anAttrEvol)) {
+        anEvolution = anAttrEvol->Get();
+      }
+    } else {
+      TDataStd_Integer::Set(theLab, anEvolution);
+    }
+
     for(TNaming_Iterator anIter(aName); anIter.More(); anIter.Next()) {
       aShapePairs.push_back(std::pair<TopoDS_Shape, TopoDS_Shape>
         (anIter.OldShape(), anIter.NewShape()));
     }
   }
-  // remove old
-  theLab.ForgetAttribute(TNaming_NamedShape::GetID());
   // create new
   TNaming_Builder aBuilder(theLab);
   TNaming_Evolution anEvol = (TNaming_Evolution)(anEvolution);
@@ -175,7 +187,7 @@ void Model_ResultBody::storeGenerated(const std::shared_ptr<GeomAPI_Shape>& theF
 }
 
 void Model_ResultBody::storeModified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
-  const std::shared_ptr<GeomAPI_Shape>& theNewShape)
+  const std::shared_ptr<GeomAPI_Shape>& theNewShape, const int theDecomposeSolidsTag)
 {
   std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
   if (aData) {
@@ -193,6 +205,31 @@ void Model_ResultBody::storeModified(const std::shared_ptr<GeomAPI_Shape>& theOl
     if (aShapeNew.IsNull())
       return;  // null shape inside
     aBuilder.Modify(aShapeOld, aShapeNew);
+    if (theDecomposeSolidsTag && aShapeNew.ShapeType() == TopAbs_COMPOUND) { // make sub elements as subs
+
+      // register name if it is possible
+      TCollection_AsciiString aName;
+      if(!aBuilder.NamedShape()->IsEmpty()) {
+        Handle(TDataStd_Name) anAttr;
+        if(aBuilder.NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
+          aName = TCollection_AsciiString(anAttr->Get()).ToCString();
+        }
+      }
+
+      TopoDS_Iterator aSubIter(aShapeNew);
+      for(int aTag = theDecomposeSolidsTag; aSubIter.More(); aSubIter.Next()) {
+        TNaming_Builder aSubBuilder(aShapeLab.FindChild(aTag++));
+        aSubBuilder.Generated(aSubIter.Value());
+        if(!aName.IsEmpty()) {
+          std::string aSolidName = 
+            (aName + "_Solid_" + TCollection_AsciiString(aTag - theDecomposeSolidsTag)).ToCString(); 
+          std::shared_ptr<Model_Document> aDoc = 
+            std::dynamic_pointer_cast<Model_Document>(document());
+          aDoc->addNamingName(aSubBuilder.NamedShape()->Label(), aSolidName);
+          TDataStd_Name::Set(aSubBuilder.NamedShape()->Label(), aSolidName.c_str());
+        }
+      }
+    }
   }
 }