From e837b3a26ce3af7639a37e41d13b864de1e139ac Mon Sep 17 00:00:00 2001 From: anv Date: Thu, 29 Mar 2018 12:36:09 +0300 Subject: [PATCH] 0029662: Modeling Data - Allow replacement of Compounds via BRepTools_ReShape - 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 | 4 +-- src/SWDRAW/SWDRAW_ShapeUpgrade.cxx | 54 +++++++++++++++++++++++++++-- tests/bugs/moddata_3/bug29662 | 19 ++++++++++ 3 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 tests/bugs/moddata_3/bug29662 diff --git a/src/BRepTools/BRepTools_ReShape.cxx b/src/BRepTools/BRepTools_ReShape.cxx index 9a7ad98455..c4c10a4626 100644 --- a/src/BRepTools/BRepTools_ReShape.cxx +++ b/src/BRepTools/BRepTools_ReShape.cxx @@ -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 diff --git a/src/SWDRAW/SWDRAW_ShapeUpgrade.cxx b/src/SWDRAW/SWDRAW_ShapeUpgrade.cxx index bc04d76c3c..291728bb85 100644 --- a/src/SWDRAW/SWDRAW_ShapeUpgrade.cxx +++ b/src/SWDRAW/SWDRAW_ShapeUpgrade.cxx @@ -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 index 0000000000..723e93b0d9 --- /dev/null +++ b/tests/bugs/moddata_3/bug29662 @@ -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