From 0950719fabb1015dc7e77761eb0889bad9d38f80 Mon Sep 17 00:00:00 2001 From: azv Date: Thu, 14 Dec 2017 17:42:53 +0300 Subject: [PATCH] Adjust unit tests --- .../Test/TestFillSolidCompFace.py | 10 ++--- .../Test/TestFillSolidCompShell.py | 12 +++--- src/FeaturesPlugin/Test/TestFillSolidShell.py | 10 ++--- src/Model/Model_BodyBuilder.cpp | 43 ++++++++++--------- 4 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/FeaturesPlugin/Test/TestFillSolidCompFace.py b/src/FeaturesPlugin/Test/TestFillSolidCompFace.py index 302e5cca3..d38ece362 100644 --- a/src/FeaturesPlugin/Test/TestFillSolidCompFace.py +++ b/src/FeaturesPlugin/Test/TestFillSolidCompFace.py @@ -28,9 +28,9 @@ partSet = model.moduleDocument() Part_1 = model.addPart(partSet) Part_1_doc = Part_1.document() model.addParameter(Part_1_doc, "L", "10") -model.addParameter(Part_1_doc, "Shift", "5") +model.addParameter(Part_1_doc, "Shift", "12") Box_1 = model.addBox(Part_1_doc, "L", "L", "L") -Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "Box_1_1/Bottom"), "Shift", True) +Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "Box_1_1/Bottom"), "L/2", True) Sketch_1 = model.addSketch(Part_1_doc, model.selection("FACE", "Plane_1")) SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False) SketchPoint_1 = SketchProjection_1.createdFeature() @@ -46,16 +46,16 @@ SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchArc_1.endPoint()) SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_1.result()) SketchConstraintRadius_1 = Sketch_1.setRadius(SketchArc_1.results()[1], "L+Shift/2") -SketchConstraintDistanceVertical_1 = Sketch_1.setVerticalDistance(SketchAPI_Line(SketchLine_1).startPoint(), SketchLine_2.startPoint(), -5) +SketchConstraintDistanceVertical_1 = Sketch_1.setVerticalDistance(SketchAPI_Line(SketchLine_1).startPoint(), SketchLine_2.startPoint(), "-Shift/3") SketchConstraintDistance_1 = Sketch_1.setDistance(SketchAPI_Line(SketchLine_1).startPoint(), SketchLine_3.startPoint(), "Shift", True) model.do() -Plane_5 = model.addPlane(Part_1_doc, model.selection("FACE", "Box_1_1/Left"), "Shift", True) +Plane_5 = model.addPlane(Part_1_doc, model.selection("FACE", "Box_1_1/Left"), "Shift/3", True) Face_1 = model.addFace(Part_1_doc, [model.selection("WIRE", "Sketch_1/Wire-SketchArc_1_2f-SketchLine_2f-SketchLine_3f")]) Boolean_1 = model.addFill(Part_1_doc, [model.selection("FACE", "Face_1_1")], [model.selection("FACE", "Plane_2")]) Boolean_2 = model.addFill(Part_1_doc, [model.selection("SOLID", "Box_1_1")], [model.selection("COMPOUND", "Boolean_1_1")]) model.do() -model.checkBooleansResult(Boolean_2, model, 1, [0], [1], [9], [46], [92]) +model.checkBooleansResult(Boolean_2, model, 1, [2], [2], [14], [60], [120]) model.testHaveNamingSubshapes(Boolean_2, model, Part_1_doc) model.end() diff --git a/src/FeaturesPlugin/Test/TestFillSolidCompShell.py b/src/FeaturesPlugin/Test/TestFillSolidCompShell.py index df0b4815d..997708c53 100644 --- a/src/FeaturesPlugin/Test/TestFillSolidCompShell.py +++ b/src/FeaturesPlugin/Test/TestFillSolidCompShell.py @@ -28,9 +28,9 @@ partSet = model.moduleDocument() Part_1 = model.addPart(partSet) Part_1_doc = Part_1.document() model.addParameter(Part_1_doc, "L", "10") -model.addParameter(Part_1_doc, "Shift", "5") +model.addParameter(Part_1_doc, "Shift", "12") Box_1 = model.addBox(Part_1_doc, "L", "L", "L") -Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "Box_1_1/Bottom"), "Shift", True) +Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "Box_1_1/Bottom"), "L/2", True) Sketch_1 = model.addSketch(Part_1_doc, model.selection("FACE", "Plane_1")) SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False) SketchPoint_1 = SketchProjection_1.createdFeature() @@ -46,18 +46,18 @@ SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchArc_1.endPoint()) SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_1.result()) SketchConstraintRadius_1 = Sketch_1.setRadius(SketchArc_1.results()[1], "L+Shift/2") -SketchConstraintDistanceVertical_1 = Sketch_1.setVerticalDistance(SketchAPI_Line(SketchLine_1).startPoint(), SketchLine_2.startPoint(), -5) +SketchConstraintDistanceVertical_1 = Sketch_1.setVerticalDistance(SketchAPI_Line(SketchLine_1).startPoint(), SketchLine_2.startPoint(), "-Shift/3") SketchConstraintDistance_1 = Sketch_1.setDistance(SketchAPI_Line(SketchLine_1).startPoint(), SketchLine_3.startPoint(), "Shift", True) model.do() -Plane_5 = model.addPlane(Part_1_doc, model.selection("FACE", "Box_1_1/Left"), "Shift", True) +Plane_5 = model.addPlane(Part_1_doc, model.selection("FACE", "Box_1_1/Left"), "Shift/3", True) Face_1 = model.addFace(Part_1_doc, [model.selection("WIRE", "Sketch_1/Wire-SketchArc_1_2f-SketchLine_2f-SketchLine_3f")]) Boolean_1 = model.addFill(Part_1_doc, [model.selection("FACE", "Face_1_1")], [model.selection("FACE", "Plane_2")]) Shell_1 = model.addShell(Part_1_doc, [model.selection("FACE", "Boolean_1_1_2"), model.selection("FACE", "Boolean_1_1_1")]) MultiTranslation_1 = model.addMultiTranslation(Part_1_doc, [model.selection("SHELL", "Shell_1_1")], model.selection("EDGE", "PartSet/OZ"), 1, 3) -Boolean_2 = model.addFill(Part_1_doc, [model.selection("SOLID", "Box_1_1")], [model.selection("COMPOUND", "MultiTranslation_1_1")]) +Boolean_2 = model.addFill(Part_1_doc, [model.selection("SOLID", "Box_1_1")], [model.selection("COMPOUND", "LinearCopy_1_1")]) model.do() -model.checkBooleansResult(Boolean_2, model, 1, [0], [1], [15], [90], [180]) +model.checkBooleansResult(Boolean_2, model, 1, [4], [4], [30], [132], [264]) model.testHaveNamingSubshapes(Boolean_2, model, Part_1_doc) model.end() diff --git a/src/FeaturesPlugin/Test/TestFillSolidShell.py b/src/FeaturesPlugin/Test/TestFillSolidShell.py index 33fe90bb4..2a06dab42 100644 --- a/src/FeaturesPlugin/Test/TestFillSolidShell.py +++ b/src/FeaturesPlugin/Test/TestFillSolidShell.py @@ -28,9 +28,9 @@ partSet = model.moduleDocument() Part_1 = model.addPart(partSet) Part_1_doc = Part_1.document() model.addParameter(Part_1_doc, "L", "10") -model.addParameter(Part_1_doc, "Shift", "5") +model.addParameter(Part_1_doc, "Shift", "12") Box_1 = model.addBox(Part_1_doc, "L", "L", "L") -Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "Box_1_1/Bottom"), "Shift", True) +Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "Box_1_1/Bottom"), "L/2", True) Sketch_1 = model.addSketch(Part_1_doc, model.selection("FACE", "Plane_1")) SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False) SketchPoint_1 = SketchProjection_1.createdFeature() @@ -46,17 +46,17 @@ SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchArc_1.endPoint()) SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_1.result()) SketchConstraintRadius_1 = Sketch_1.setRadius(SketchArc_1.results()[1], "L+Shift/2") -SketchConstraintDistanceVertical_1 = Sketch_1.setVerticalDistance(SketchAPI_Line(SketchLine_1).startPoint(), SketchLine_2.startPoint(), -5) +SketchConstraintDistanceVertical_1 = Sketch_1.setVerticalDistance(SketchAPI_Line(SketchLine_1).startPoint(), SketchLine_2.startPoint(), "-Shift/3") SketchConstraintDistance_1 = Sketch_1.setDistance(SketchAPI_Line(SketchLine_1).startPoint(), SketchLine_3.startPoint(), "Shift", True) model.do() -Plane_5 = model.addPlane(Part_1_doc, model.selection("FACE", "Box_1_1/Left"), "Shift", True) +Plane_5 = model.addPlane(Part_1_doc, model.selection("FACE", "Box_1_1/Left"), "Shift/3", True) Face_1 = model.addFace(Part_1_doc, [model.selection("WIRE", "Sketch_1/Wire-SketchArc_1_2f-SketchLine_2f-SketchLine_3f")]) Boolean_1 = model.addFill(Part_1_doc, [model.selection("FACE", "Face_1_1")], [model.selection("FACE", "Plane_2")]) Shell_1 = model.addShell(Part_1_doc, [model.selection("FACE", "Boolean_1_1_2"), model.selection("FACE", "Boolean_1_1_1")]) Boolean_2 = model.addFill(Part_1_doc, [model.selection("SOLID", "Box_1_1")], [model.selection("SHELL", "Shell_1_1")]) model.do() -model.checkBooleansResult(Boolean_2, model, 1, [0], [1], [9], [46], [92]) +model.checkBooleansResult(Boolean_2, model, 1, [2], [2], [14], [60], [120]) model.testHaveNamingSubshapes(Boolean_2, model, Part_1_doc) model.end() diff --git a/src/Model/Model_BodyBuilder.cpp b/src/Model/Model_BodyBuilder.cpp index 623ed23ed..fc25d4ecc 100755 --- a/src/Model/Model_BodyBuilder.cpp +++ b/src/Model/Model_BodyBuilder.cpp @@ -370,6 +370,27 @@ void Model_BodyBuilder::loadDeletedShapes (GeomAlgoAPI_MakeShape* theMS, } } +// Keep only the shapes with minimal shape type +static void keepTopLevelShapes(ListOfShape& theShapes) +{ + GeomAPI_Shape::ShapeType aKeepShapeType = GeomAPI_Shape::SHAPE; + ListOfShape::iterator anIt = theShapes.begin(); + while (anIt != theShapes.end()) { + GeomAPI_Shape::ShapeType aType = (*anIt)->shapeType(); + if (aType < aKeepShapeType) { + // found a shape with lesser shape type => remove all previous shapes + aKeepShapeType = aType; + theShapes.erase(theShapes.begin(), anIt); + ++anIt; + } else if (aType > aKeepShapeType) { + // shapes with greater shape type should be removed from the list + ListOfShape::iterator aRemoveIt = anIt++; + theShapes.erase(aRemoveIt); + } else + ++anIt; + } +} + void Model_BodyBuilder::loadAndOrientModifiedShapes ( GeomAlgoAPI_MakeShape* theMS, std::shared_ptr theShapeIn, @@ -398,6 +419,7 @@ void Model_BodyBuilder::loadAndOrientModifiedShapes ( std::shared_ptr aRShape(new GeomAPI_Shape()); aRShape->setImpl((new TopoDS_Shape(aRoot))); theMS->modified(aRShape, aList); + keepTopLevelShapes(aList); // sort the list of images before naming GeomAlgoAPI_SortListOfShapes::sort(aList); @@ -460,27 +482,6 @@ void Model_BodyBuilder::loadAndOrientModifiedShapes ( } } -// Keep only the shapes with minimal shape type -static void keepTopLevelShapes(ListOfShape& theShapes) -{ - GeomAPI_Shape::ShapeType aKeepShapeType = GeomAPI_Shape::SHAPE; - ListOfShape::iterator anIt = theShapes.begin(); - while (anIt != theShapes.end()) { - GeomAPI_Shape::ShapeType aType = (*anIt)->shapeType(); - if (aType < aKeepShapeType) { - // found a shape with lesser shape type => remove all previous shapes - aKeepShapeType = aType; - theShapes.erase(theShapes.begin(), anIt); - ++anIt; - } else if (aType > aKeepShapeType) { - // shapes with greater shape type should be removed from the list - ListOfShape::iterator aRemoveIt = anIt++; - theShapes.erase(aRemoveIt); - } else - ++anIt; - } -} - void Model_BodyBuilder::loadAndOrientGeneratedShapes ( GeomAlgoAPI_MakeShape* theMS, std::shared_ptr theShapeIn, -- 2.39.2