From 71e54dccdd7194a911151c626896ec7dc2942241 Mon Sep 17 00:00:00 2001 From: Artem Zhidkov Date: Fri, 16 Oct 2020 11:37:21 +0300 Subject: [PATCH] Issue #20167: checkPythonDump() errors Improve performance of bounding box calculation while dumping. --- .../Test/TestFillet_MultiLevelCompound_v0_3.py | 2 +- .../Test/TestFillet_MultiLevelCompound_v0_4.py | 2 +- .../Test/TestFillet_MultiLevelCompound_v95_3.py | 4 ++-- .../Test/TestFillet_MultiLevelCompound_v95_4.py | 6 +++--- .../Test/TestScale_MultiLevelCompound_v95_2.py | 8 ++++---- src/GeomAPI/GeomAPI_Shape.cpp | 14 +++++++++++++- 6 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/FeaturesPlugin/Test/TestFillet_MultiLevelCompound_v0_3.py b/src/FeaturesPlugin/Test/TestFillet_MultiLevelCompound_v0_3.py index e035002b6..b15634542 100644 --- a/src/FeaturesPlugin/Test/TestFillet_MultiLevelCompound_v0_3.py +++ b/src/FeaturesPlugin/Test/TestFillet_MultiLevelCompound_v0_3.py @@ -124,7 +124,7 @@ model.testNbSubShapes(Fillet_6, GeomAPI_Shape.FACE, [23]) model.testNbSubShapes(Fillet_6, GeomAPI_Shape.EDGE, [95]) model.testNbSubShapes(Fillet_6, GeomAPI_Shape.VERTEX, [190]) model.testResultsVolumes(Fillet_6, [1565.568094166]) -refPoint = GeomAPI_Pnt(2.50004995, 2.50004995, 5.00005) +refPoint = GeomAPI_Pnt(2.7448, 2.7448, 5) midPoint = Fillet_6.defaultResult().shape().middlePoint() assert(midPoint.distance(refPoint) < TOLERANCE) diff --git a/src/FeaturesPlugin/Test/TestFillet_MultiLevelCompound_v0_4.py b/src/FeaturesPlugin/Test/TestFillet_MultiLevelCompound_v0_4.py index 258f7ef01..b1b177b65 100644 --- a/src/FeaturesPlugin/Test/TestFillet_MultiLevelCompound_v0_4.py +++ b/src/FeaturesPlugin/Test/TestFillet_MultiLevelCompound_v0_4.py @@ -127,7 +127,7 @@ model.testNbSubShapes(Fillet_6, GeomAPI_Shape.FACE, [23]) model.testNbSubShapes(Fillet_6, GeomAPI_Shape.EDGE, [95]) model.testNbSubShapes(Fillet_6, GeomAPI_Shape.VERTEX, [190]) model.testResultsVolumes(Fillet_6, [1565.568094166]) -refPoint = GeomAPI_Pnt(2.50004995, 2.50004995, 5.00005) +refPoint = GeomAPI_Pnt(2.7448, 2.7448, 5) midPoint = Fillet_6.defaultResult().shape().middlePoint() assert(midPoint.distance(refPoint) < TOLERANCE) diff --git a/src/FeaturesPlugin/Test/TestFillet_MultiLevelCompound_v95_3.py b/src/FeaturesPlugin/Test/TestFillet_MultiLevelCompound_v95_3.py index d02ae8827..4ad363735 100644 --- a/src/FeaturesPlugin/Test/TestFillet_MultiLevelCompound_v95_3.py +++ b/src/FeaturesPlugin/Test/TestFillet_MultiLevelCompound_v95_3.py @@ -124,7 +124,7 @@ model.testNbSubShapes(Fillet_6, GeomAPI_Shape.FACE, [23]) model.testNbSubShapes(Fillet_6, GeomAPI_Shape.EDGE, [95]) model.testNbSubShapes(Fillet_6, GeomAPI_Shape.VERTEX, [190]) model.testResultsVolumes(Fillet_6, [1565.568094166]) -refPoint = GeomAPI_Pnt(2.50004995, 2.50004995, 5.00005) +refPoint = GeomAPI_Pnt(2.7448, 2.7448, 5) midPoint = Fillet_6.defaultResult().shape().middlePoint() assert(midPoint.distance(refPoint) < TOLERANCE) @@ -136,7 +136,7 @@ model.testNbSubShapes(Fillet_7, GeomAPI_Shape.FACE, [23]) model.testNbSubShapes(Fillet_7, GeomAPI_Shape.EDGE, [98]) model.testNbSubShapes(Fillet_7, GeomAPI_Shape.VERTEX, [196]) model.testResultsVolumes(Fillet_7, [2976.0685684791988]) -refPoint = GeomAPI_Pnt(-20.9807621135, 42.5, 5) +refPoint = GeomAPI_Pnt(-20.9807621135, 42.806, 5) midPoint = Fillet_7.defaultResult().shape().middlePoint() assert(midPoint.distance(refPoint) < TOLERANCE) model.end() diff --git a/src/FeaturesPlugin/Test/TestFillet_MultiLevelCompound_v95_4.py b/src/FeaturesPlugin/Test/TestFillet_MultiLevelCompound_v95_4.py index f4545a1f5..ebd1bf9d3 100644 --- a/src/FeaturesPlugin/Test/TestFillet_MultiLevelCompound_v95_4.py +++ b/src/FeaturesPlugin/Test/TestFillet_MultiLevelCompound_v95_4.py @@ -142,7 +142,7 @@ VOLUME = 5565.117188528191 assertResult(Fillet_5) Fillet_6 = model.addFillet(Part_1_doc, [model.selection("EDGE", "[Compound_1_1_7_2/Modified_Face&Box_2_1/Top][Compound_1_1_7_2/Modified_Face&Box_2_1/Front]"), model.selection("FACE", "Compound_1_1_7_2/Modified_Face&Box_2_1/Right")], RADIUS_1, RADIUS_2, keepSubResults = True) -REFERENCE[6] = GeomAPI_Pnt(2.50004995, 2.50004995, 5.00005) +REFERENCE[6] = GeomAPI_Pnt(2.7448, 2.7448, 5) NB_FACES += 6 NB_EDGES += 29 NB_VERTICES += 58 @@ -150,7 +150,7 @@ VOLUME = 5541.63666 assertResult(Fillet_6) Fillet_7 = model.addFillet(Part_1_doc, [model.selection("EDGE", "[Compound_1_1_8_1/Modified_Face&Box_3_1/Back][Compound_1_1_8_1/Modified_Face&Box_3_1/Top]"), model.selection("FACE", "Compound_1_1_8_2/Modified_Face&Box_3_1/Left")], RADIUS_1, RADIUS_2, keepSubResults = True) -REFERENCE[7] = GeomAPI_Pnt(-20.9807621135, 42.5, 5) +REFERENCE[7] = GeomAPI_Pnt(-20.9807621135, 42.806, 5) NB_FACES += 5 NB_EDGES += 26 NB_VERTICES += 52 @@ -163,7 +163,7 @@ NB_EDGES += 12 NB_VERTICES += 24 VOLUME = 5507.602043482 REFERENCE[5] = GeomAPI_Pnt(55.041662114, 5.021870383, 5.009557179275) -REFERENCE[7] = GeomAPI_Pnt(-20.9807621135, 42.5, 5) +REFERENCE[7] = GeomAPI_Pnt(-20.9807621135, 42.5409962, 5) assertResult(Fillet_8) model.end() diff --git a/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v95_2.py b/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v95_2.py index 077241b69..7975a6792 100644 --- a/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v95_2.py +++ b/src/FeaturesPlugin/Test/TestScale_MultiLevelCompound_v95_2.py @@ -107,14 +107,14 @@ assert(Scale_1.feature().error() != "") model.begin() Scale_1.setMainObjects([model.selection("COMPSOLID", "Compound_2_1_1")]) REFERENCE[0] = GeomAPI_Pnt(REFERENCE[0].x() * SCALE_X, REFERENCE[0].y() * SCALE_Y, REFERENCE[0].z() * SCALE_Z) -##REFERENCE[0].setX(0) # <= B-spline poles are used to calculate the bounding box and thus the middle point +REFERENCE[0].setX(0) # <= B-spline poles are used to calculate the bounding box and thus the middle point assertResult(Scale_1, 74139.07479) Scale_2 = model.addScale(Part_1_doc, [model.selection("SOLID", "Scale_1_1_2_1")], model.selection("VERTEX", "PartSet/Origin"), SCALE_X, SCALE_Y, SCALE_Z, keepSubResults = True) subs = subsRefPoints(Compound_2.result().subResult(1)) subs[0] = GeomAPI_Pnt(subs[0].xyz().added(GeomAPI_XYZ(5, -5, 5))) subs[0] = GeomAPI_Pnt(subs[0].x() * SCALE_X, subs[0].y() * SCALE_Y, subs[0].z() * SCALE_Z) -##subs[0].setY(-117.3204876) # <= B-spline poles are used to calculate the bounding box and thus the middle point +subs[0].setY(-117.3204876) # <= B-spline poles are used to calculate the bounding box and thus the middle point subs[1] = GeomAPI_Pnt(subs[1].xyz().added(GeomAPI_XYZ(-5, 5, -5))) REFERENCE[1] = average(subs) assertResult(Scale_2, 78066.07487341) @@ -133,8 +133,8 @@ Scale_4.setMainObjects([model.selection("COMPSOLID", "Scale_3_1_1"), model.selec REFERENCE[0] = GeomAPI_Pnt(REFERENCE[0].x() / SCALE_X, REFERENCE[0].y() / SCALE_Y, REFERENCE[0].z() / SCALE_Z) subs[1] = GeomAPI_Pnt(subs[1].x() / SCALE_X, subs[1].y() / SCALE_Y, subs[1].z() / SCALE_Z) # B-spline poles are used to calculate the bounding box and thus the middle point -##subs[1].setX(-30.59017) -##subs[1].setY(-2.83826244) +subs[1].setX(-30.59017) +subs[1].setY(-2.83826244) REFERENCE[1] = average(subs) REFERENCE[2] = GeomAPI_Pnt(REFERENCE[2].x() / SCALE_X, REFERENCE[2].y() / SCALE_Y, REFERENCE[2].z() / SCALE_Z) assertResult(Scale_4, 17592.5112883) diff --git a/src/GeomAPI/GeomAPI_Shape.cpp b/src/GeomAPI/GeomAPI_Shape.cpp index ea59ae09b..cd044b69a 100644 --- a/src/GeomAPI/GeomAPI_Shape.cpp +++ b/src/GeomAPI/GeomAPI_Shape.cpp @@ -593,7 +593,19 @@ bool GeomAPI_Shape::computeSize(double& theXmin, double& theYmin, double& theZmi if (aShape.IsNull()) return false; Bnd_Box aBndBox; - BRepBndLib::AddOptimal(aShape, aBndBox, false, true); + // Workaround: compute optimal bounding box for the compounds of edges/vertices, because sometimes + // the bounding box of sketch is calculated if the transformation is applied twice (issue #20167). + bool isShape1D = false; + if (aShape.ShapeType() == TopAbs_COMPOUND) { + isShape1D = true; + for (TopoDS_Iterator anIt(aShape); anIt.More() && isShape1D; anIt.Next()) + if (anIt.Value().ShapeType() < TopAbs_WIRE) + isShape1D = false; + } + if (isShape1D) + BRepBndLib::AddOptimal(aShape, aBndBox, false, true); + else + BRepBndLib::Add(aShape, aBndBox, false); if (aBndBox.IsVoid()) return false; aBndBox.Get(theXmin, theYmin, theZmin, theXmax, theYmax, theZmax); -- 2.39.2