0028226: Incorrect history support in ShapeUpgrade_UnifySameDomain algorithm
[occt.git] / src / SWDRAW / SWDRAW_ShapeUpgrade.cxx
index 22cf895..134d605 100644 (file)
@@ -19,6 +19,7 @@
 //pdn,gka 10.06.99 S4189: command DT_ShapeConvertRev added
 
 #include <BRep_Tool.hxx>
+#include <BRep_Builder.hxx>
 #include <BRepBuilderAPI.hxx>
 #include <BRepBuilderAPI_Transform.hxx>
 #include <BRepTools.hxx>
@@ -1358,30 +1359,97 @@ static Standard_Integer unifysamedom(Draw_Interpretor& di, Standard_Integer n, c
   return 0;
 }
 
-Standard_Integer unifysamedomgen (Draw_Interpretor& di, 
-                                  Standard_Integer n, 
-                                  const char** a)
+Standard_Integer unifysamedomgen(Draw_Interpretor& di,
+                                 Standard_Integer n,
+                                 const char** a)
 {
-  if (n!=3) {
-    di << "use unifysamedomgen newshape oldshape";
+  if (n != 3) {
+    di << "use unifysamedomgen newshape oldshape\n";
     return 0;
   }
   TopoDS_Shape aShape;
-  aShape=DBRep::Get(a[2]);
+  aShape = DBRep::Get(a[2]);
   if (aShape.IsNull()) {
-    di<<" null shape is not allowed here\n";
+    di << "Null shape is not allowed here\n";
     return 1;
   }
-  TopoDS_Shape ResShape = Unifier().Generated(aShape);
-  if (ResShape.IsNull()) {
-    di << " null shape\n";
+
+  const TopTools_ListOfShape& aLS = Unifier().Generated(aShape);
+
+  if (aLS.Extent() > 1) {
+    BRep_Builder aBB;
+    TopoDS_Compound aRes;
+    aBB.MakeCompound(aRes);
+    TopTools_ListIteratorOfListOfShape aIt(aLS);
+    for (; aIt.More(); aIt.Next()) {
+      const TopoDS_Shape& aShape = aIt.Value();
+      aBB.Add(aRes, aShape);
+    }
+    DBRep::Set(a[1], aRes);
+  }
+  else if (aLS.Extent() == 1) {
+    DBRep::Set(a[1], aLS.First());
   }
   else {
-    DBRep::Set(a[1], ResShape);
+    di << "No shapes were generated from the shape\n";
   }
   return 0;
 }
 
+Standard_Integer unifysamedommod(Draw_Interpretor& di,
+                                 Standard_Integer n,
+                                 const char** a)
+{
+  if (n != 3) {
+    di << "use unifysamedommod newshape oldshape\n";
+    return 0;
+  }
+  TopoDS_Shape aShape;
+  aShape = DBRep::Get(a[2]);
+  if (aShape.IsNull()) {
+    di << "Null shape is not allowed here\n";
+    return 1;
+  }
+
+  const TopTools_ListOfShape& aLS = Unifier().Modified(aShape);
+
+  if (aLS.Extent() > 1) {
+    BRep_Builder aBB;
+    TopoDS_Compound aRes;
+    aBB.MakeCompound(aRes);
+    TopTools_ListIteratorOfListOfShape aIt(aLS);
+    for (; aIt.More(); aIt.Next()) {
+      const TopoDS_Shape& aShape = aIt.Value();
+      aBB.Add(aRes, aShape);
+    }
+    DBRep::Set(a[1], aRes);
+  }
+  else if (aLS.Extent() == 1) {
+    DBRep::Set(a[1], aLS.First());
+  }
+  else {
+    di << "The shape has not been modified\n";
+  }
+  return 0;
+}
+
+Standard_Integer unifysamedomisdel(Draw_Interpretor& di,
+                                   Standard_Integer n,
+                                   const char** a)
+{
+  if (n < 2) {
+    di << "Use: unifysamedomisdel shape\n";
+    return 1;
+  }
+  TopoDS_Shape aShape = DBRep::Get(a[1]);
+  if (aShape.IsNull()) {
+    di << "Null shape is not allowed here\n";
+    return 1;
+  }
+  Standard_Boolean IsDeleted = Unifier().IsDeleted(aShape);
+  di << "The shape has" << (IsDeleted ? " " : " not ") << "been deleted" << "\n";
+  return 0;
+}
 
 static Standard_Integer copytranslate(Draw_Interpretor& di, 
                                    Standard_Integer argc, 
@@ -1588,10 +1656,19 @@ Standard_Integer reshape(Draw_Interpretor& di,
   theCommands.Add ("unifysamedom",
                    "unifysamedom result shape [s1 s2 ...] [-f] [-e] [+b] [+i] [-t val] [-a val]", __FILE__,unifysamedom,g);
   
-  theCommands.Add ("unifysamedomgen",
-                   "unifysamedomgen newshape oldshape : get new shape generated "
-                   "by unifysamedom command from the old one",
-                   __FILE__,unifysamedomgen,g);
+  theCommands.Add("unifysamedomgen",
+                  "unifysamedomgen newshape oldshape : get new shape generated "
+                  "by unifysamedom command from the old one",
+                  __FILE__, unifysamedomgen, g);
+
+  theCommands.Add("unifysamedommod",
+                  "unifysamedommod newshape oldshape : get new shape modified "
+                  "by unifysamedom command from the old one",
+                  __FILE__, unifysamedommod, g);
+
+  theCommands.Add("unifysamedomisdel",
+                  "unifysamedomisdel shape : shape is deleted ",
+                  __FILE__, unifysamedomisdel, g);
   
   theCommands.Add ("copytranslate","result shape dx dy dz",__FILE__,copytranslate,g);