]> OCCT Git - occt.git/commitdiff
0029662: Modeling Data - Allow replacement of Compounds via BRepTools_ReShape
authoranv <anv@opencascade.com>
Thu, 29 Mar 2018 09:36:09 +0000 (12:36 +0300)
committerapn <apn@opencascade.com>
Fri, 23 Aug 2019 13:56:39 +0000 (16:56 +0300)
- Fixed condition to allow proceeding of nested compounds;
- Added new key to "reshape" draw command to state a level of type until which requests are taken into account;
- Test case added.

src/BRepTools/BRepTools_ReShape.cxx
src/SWDRAW/SWDRAW_ShapeUpgrade.cxx
tests/bugs/moddata_3/bug29662 [new file with mode: 0644]

index 9a7ad984557ecd95747e8b226df279a682e345dd..c4c10a46269df376194dca11ec30d3f1bcee906e 100644 (file)
@@ -363,8 +363,8 @@ TopoDS_Shape BRepTools_ReShape::Apply (const TopoDS_Shape& shape,
     return res;
   }
 
-  TopAbs_ShapeEnum st = shape.ShapeType(); //, subt;
-  if ( st >= until ) return newsh;    // critere d arret
+  TopAbs_ShapeEnum st = shape.ShapeType();
+  if (st > until || (st == until && until > TopAbs_COMPOUND)) return newsh; // stopping criteria
   if(st == TopAbs_VERTEX || st == TopAbs_SHAPE)
     return shape;
   // define allowed types of components
index bc04d76c3ca04c20d2a20fa962a5f705f1dae498..291728bb8522b208a0d40ca7f1ecf3babdd5e510 100644 (file)
@@ -1414,6 +1414,8 @@ static Standard_Integer reshape(Draw_Interpretor& /*theDI*/,
 
   Handle(BRepTools_ReShape) aReShaper = new BRepTools_ReShape;
 
+  TopAbs_ShapeEnum aShapeLevel = TopAbs_SHAPE;
+
   // Record the requested modifications
   for ( Standard_Integer i = 3; i < theArgc; ++i )
   {
@@ -1462,6 +1464,50 @@ static Standard_Integer reshape(Draw_Interpretor& /*theDI*/,
 
       aReShaper->Remove(aWhat);
     }
+    else if (anOpt == "-until")
+    {
+      if (theArgc - i < 2)
+      {
+        std::cout << "Error: not enough arguments for level specification\n";
+        return 1;
+      }
+
+      Standard_CString aLevelCStr = theArgv[++i];
+      TCollection_AsciiString aLevelStr(aLevelCStr);
+      aLevelStr.LowerCase();
+      if (aLevelStr == "compound" ||
+          aLevelStr == "cd")
+        aShapeLevel = TopAbs_COMPOUND;
+      else if (aLevelStr == "compsolid" ||
+               aLevelStr == "c")
+        aShapeLevel = TopAbs_COMPSOLID;
+      else if (aLevelStr == "solid" ||
+               aLevelStr == "so")
+        aShapeLevel = TopAbs_SOLID;
+      else if (aLevelStr == "shell" ||
+               aLevelStr == "sh")
+        aShapeLevel = TopAbs_SHELL;
+      else if (aLevelStr == "face" ||
+               aLevelStr == "f")
+        aShapeLevel = TopAbs_FACE;
+      else if (aLevelStr == "wire" ||
+               aLevelStr == "w")
+        aShapeLevel = TopAbs_WIRE;
+      else if (aLevelStr == "edge" ||
+               aLevelStr == "e")
+        aShapeLevel = TopAbs_EDGE;
+      else if (aLevelStr == "vertex" ||
+               aLevelStr == "v")
+        aShapeLevel = TopAbs_VERTEX;
+      else if (aLevelStr == "shape" ||
+               aLevelStr == "s")
+        aShapeLevel = TopAbs_SHAPE;
+      else
+      {
+        std::cout << "Error: unknown shape type '" << theArgv[i] << "'\n";
+        return 1;
+      }
+    }
     else
     {
       std::cout << "Error: invalid syntax at " << anOpt << "\n" ;
@@ -1470,7 +1516,7 @@ static Standard_Integer reshape(Draw_Interpretor& /*theDI*/,
   }
 
   // Apply all the recorded modifications
-  TopoDS_Shape aResult = aReShaper->Apply(aSource);
+  TopoDS_Shape aResult = aReShaper->Apply(aSource, aShapeLevel);
   if ( aResult.IsNull() )
   {
     std::cout << "Error: result shape is null\n";
@@ -1589,10 +1635,12 @@ static Standard_Integer reshape(Draw_Interpretor& /*theDI*/,
   theCommands.Add ("copytranslate","result shape dx dy dz",__FILE__,copytranslate,g);
 
   theCommands.Add ("reshape",
-    "\n    reshape : result shape [-replace what with] [-remove what]"
+    "\n    reshape : result shape [-replace what with] [-remove what] [-until level]"
     "\n    Basic utility for topological modification: "
     "\n      '-replace what with'   Replaces 'what' sub-shape with 'with' sub-shape"
     "\n      '-remove what'         Removes 'what' sub-shape"
-    "\n    Requests '-replace' and '-remove' can be repeated many times.",
+    "\n    Requests '-replace' and '-remove' can be repeated many times."
+    "\n    '-until level' specifies level until which shape for replcement/removal"
+    "\n    will be searched.",
     __FILE__, reshape, g);
 }
diff --git a/tests/bugs/moddata_3/bug29662 b/tests/bugs/moddata_3/bug29662
new file mode 100644 (file)
index 0000000..723e93b
--- /dev/null
@@ -0,0 +1,19 @@
+puts "==========="
+puts "0029662"
+puts "==========="
+puts ""
+########################################################
+# Allow replacement of Compounds via BRepTools_ReShape
+########################################################
+
+box b1 10 10 10
+box b2 10 0 0 10 10 10
+box b3 0 0 10 10 10 10
+box b4 10 0 10 10 10 10
+box b5 20 0 0 10 10 10
+compound b1 b2 c1
+compound b3 b4 c2
+compound c1 c2 c
+compound b5 c3
+reshape res c -replace c2 c3 -until compound
+checknbshapes res -solid 3
\ No newline at end of file