From 9251c073a7764931c71667245ef1a4664978c1a3 Mon Sep 17 00:00:00 2001 From: mpv Date: Tue, 9 Apr 2019 19:32:16 +0300 Subject: [PATCH] Update unit tests to make objects are referenced correctly --- src/BuildPlugin/Test/TestCompSolid.py | 6 ++++++ src/FeaturesPlugin/Test/TestFusionFaces.py | 9 +++++++-- .../Test/TestFusionFaces2697.py | 4 +++- src/FeaturesPlugin/Test/TestRecover.py | 3 ++- src/GeomAPI/Test/TestCone.py | 19 +++++++++++++++++-- src/Model/Model_AttributeValidator.cpp | 15 +++++++++++++++ src/ModelAPI/Test/Test2903.py | 4 ++-- 7 files changed, 52 insertions(+), 8 deletions(-) diff --git a/src/BuildPlugin/Test/TestCompSolid.py b/src/BuildPlugin/Test/TestCompSolid.py index 077834374..3ebbd9121 100644 --- a/src/BuildPlugin/Test/TestCompSolid.py +++ b/src/BuildPlugin/Test/TestCompSolid.py @@ -147,6 +147,12 @@ CompSolid_1 = createCompSolidStepByStep(boundaries1, expectType1) model.checkResult(CompSolid_1, model, 1, [2], [2], [13], [54], [108]) model.testHaveNamingSubshapes(CompSolid_1, model, Part_1_doc) +# to reuse all results, undo the solid and 3 groups creation +model.undo() +model.undo() +model.undo() +model.undo() + # ============================================================================= # Test 2. Build compsolid containing 3 solids # ============================================================================= diff --git a/src/FeaturesPlugin/Test/TestFusionFaces.py b/src/FeaturesPlugin/Test/TestFusionFaces.py index 848175745..b0adb7f32 100644 --- a/src/FeaturesPlugin/Test/TestFusionFaces.py +++ b/src/FeaturesPlugin/Test/TestFusionFaces.py @@ -32,16 +32,21 @@ Box_1 = model.addBox(Part_1_doc, 10, 10, 10) Box_2 = model.addBox(Part_1_doc, 10, 10, 10) Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_2_1")], model.selection("EDGE", "PartSet/OX"), 10) +model.do() Shell_1 = model.addShell(Part_1_doc, [model.selection("FACE", "Box_1_1/Top"), model.selection("FACE", "Translation_1_1/MF:Translated&Box_2_1/Top")]) model.do() model.checkResult(Shell_1, model, 1, [0], [0], [2], [8], [16]) FusionFaces_1 = model.addFusionFaces(Part_1_doc, model.selection("SHELL", "Shell_1_1")) -model.do() +model.end() model.checkResult(FusionFaces_1, model, 1, [0], [0], [1], [4], [8]) +model.undo() # to reuse Box_1_1 and Translation_1_1 +model.undo() +model.begin() + # ============================================================================= # Test 2. Fusion faces for solid of 2 adjacent boxes # ============================================================================= @@ -63,7 +68,7 @@ Shell_2 = model.addShell(Part_1_doc, [model.selection("FACE", "Cylinder_1_1/Face Point_1 = model.addPoint(Part_1_doc, 0, 0, 5) Plane_1 = model.addPlane(Part_1_doc, model.selection("EDGE", "PartSet/OZ"), model.selection("VERTEX", "Point_1"), True) -Partition_1 = model.addPartition(Part_1_doc, [model.selection("SHELL", "Shell_2_1"), model.selection("FACE", "Plane_1")]) +Partition_1 = model.addPartition(Part_1_doc, [model.selection("SHELL", "Shell_1_1"), model.selection("FACE", "Plane_1")]) model.do() model.checkResult(Partition_1, model, 1, [0], [0], [2], [8], [16]) diff --git a/src/FeaturesPlugin/Test/TestFusionFaces2697.py b/src/FeaturesPlugin/Test/TestFusionFaces2697.py index e3e84ed52..ff2147790 100644 --- a/src/FeaturesPlugin/Test/TestFusionFaces2697.py +++ b/src/FeaturesPlugin/Test/TestFusionFaces2697.py @@ -256,7 +256,9 @@ Symmetry_1.results()[1].subResult(1).setName("Symmetry_1_2_2") Cut_1 = model.addCut(Part_1_doc, [model.selection("SOLID", "Revolution_1_1")], [model.selection("COMPOUND", "Cut_tool")]) Fuse_1 = model.addFuse(Part_1_doc, [model.selection("SOLID", "Cut_1_1"), model.selection("COMPOUND", "Fuse_tool")]) FusionFaces_1 = model.addFusionFaces(Part_1_doc, model.selection("SOLID", "Fuse_1_1")) -model.end() +model.do() # check the faces are fused model.checkResult(FusionFaces_1, model, 1, [0], [1], [16], [76], [152]) + +model.end() \ No newline at end of file diff --git a/src/FeaturesPlugin/Test/TestRecover.py b/src/FeaturesPlugin/Test/TestRecover.py index 392d85ae7..88cdb0cdc 100644 --- a/src/FeaturesPlugin/Test/TestRecover.py +++ b/src/FeaturesPlugin/Test/TestRecover.py @@ -75,7 +75,8 @@ c3 = sk3.addCircle(0, 0, 90) model.do() big2 = model.addExtrusion(mypart, sk3.selectFace(), 110) -cut2 = model.addCut(mypart, big2.results(), smallcyl.results()) +smallcyl2 = model.addExtrusion(mypart, sk2.selectFace(), 150) +cut2 = model.addCut(mypart, big2.results(), smallcyl2.results()) model.end() diff --git a/src/GeomAPI/Test/TestCone.py b/src/GeomAPI/Test/TestCone.py index a7c2d72ed..556c9bd85 100644 --- a/src/GeomAPI/Test/TestCone.py +++ b/src/GeomAPI/Test/TestCone.py @@ -259,14 +259,21 @@ checkConeSolid(Part_1_doc, Solid_1_objects, anApex, anAxis, aSemiAngle, ParamR1. Cone_2 = model.addCone(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 10, 5, 10) Cone_3 = model.addCone(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10, 20) Fuse_1 = model.addFuse(Part_1_doc, [model.selection("SOLID", "Cone_2_1"), model.selection("SOLID", "Cone_3_1")], True) + +model.do() Solid_2_objects = [model.selection("FACE", "Fuse_1_1/Modified_Face&Cone_2_1/Face_3&Cone_3_1/Face_3"), model.selection("FACE", "Fuse_1_1/Modified_Face&Cone_2_1/Face_1"), model.selection("FACE", "Fuse_1_1/Modified_Face&Cone_3_1/Face_1"), model.selection("FACE", "Cone_3_1/Face_2")] Solid_2 = model.addSolid(Part_1_doc, Solid_2_objects) checkNonCone(Solid_2) +model.end() + +# in order to use study objects once again, undo Test7 actions +model.undo() # Test 8. Check non-conical shell +model.begin() Shell_1_objects = [model.selection("FACE", "Rotation_1_1/MF:Rotated&Cone_1_1/Face_3"), model.selection("FACE", "Partition_1_1_1/Modified_Face&Cone_1_1/Face_1"), model.selection("FACE", "Partition_1_1_2/Modified_Face&Cone_1_1/Face_1"), @@ -276,13 +283,23 @@ checkNonConeShell(Shell_1) Shell_2 = model.addShell(Part_1_doc, [model.selection("FACE", "Fuse_1_1/Modified_Face&Cone_2_1/Face_1"), model.selection("FACE", "Fuse_1_1/Modified_Face&Cone_3_1/Face_1")]) checkNonConeShell(Shell_2) +model.end() + +# in order to use study objects once again, undo Test8 actions +model.undo() # Test 9. Check error on conversion to wrong type of curve +model.begin() anEdge = model.addEdge(Part_1_doc, [model.selection("EDGE", "[Partition_1_1_2/Modified_Face&Cone_1_1/Face_1][Rotation_1_1/MF:Rotated&Cone_1_1/Face_2]")]) aShape = anEdge.result().resultSubShapePair()[0].shape() assert(aShape.isEdge()) assert(aShape.edge().ellipse() is None) assert(aShape.edge().line() is None) +model.end() + +model.undo() + +model.begin() anEdge = model.addEdge(Part_1_doc, [model.selection("EDGE", "[Partition_1_1_2/Modified_Face&Cone_1_1/Face_1][weak_name_2]")]) aShape = anEdge.result().resultSubShapePair()[0].shape() @@ -301,6 +318,4 @@ radius = 5 cone = GeomAPI_Cone(apex, dir, semiAngle, radius) assert(cone.location().distance(apex) < TOLERANCE) - - model.end() diff --git a/src/Model/Model_AttributeValidator.cpp b/src/Model/Model_AttributeValidator.cpp index 135a6a423..8dabfc413 100644 --- a/src/Model/Model_AttributeValidator.cpp +++ b/src/Model/Model_AttributeValidator.cpp @@ -101,6 +101,8 @@ bool Model_AttributeValidator::isValid(const AttributePtr& theAttribute, std::list::const_iterator aRefIter = aReferencedList.cbegin(); for(; aRefIter != aReferencedList.cend(); aRefIter++) { const ObjectPtr& aReferenced = *aRefIter; + if (!aReferenced.get()) + continue; // get all results and feature that is referenced to see all references to them FeaturePtr aReferencedFeature; if (aReferenced->groupName() == ModelAPI_Feature::group()) { @@ -112,8 +114,21 @@ bool Model_AttributeValidator::isValid(const AttributePtr& theAttribute, if (alreadyProcessed.count(aReferencedFeature)) continue; alreadyProcessed.insert(aReferencedFeature); + /* it takes all results, not only concealed std::list aReferencedResults; ModelAPI_Tools::allResults(aReferencedFeature, aReferencedResults); + */ + std::list aReferencedResults; + ResultBodyPtr aRefBody = std::dynamic_pointer_cast(aReferenced); + if (aRefBody.get()) { // take only sub-results of this result or sub-result + ResultBodyPtr aRoot = ModelAPI_Tools::bodyOwner(aRefBody, true); + if (aRoot.get()) { + ModelAPI_Tools::allSubs(aRoot, aReferencedResults, false); + aReferencedResults.push_back(aRoot); + } else + aReferencedResults.push_back(aRefBody); + } + std::list::iterator aRefRes = aReferencedResults.begin(); bool aCheckFeature = true; // the last iteration to check the feature while(aRefRes != aReferencedResults.end() || aCheckFeature) { diff --git a/src/ModelAPI/Test/Test2903.py b/src/ModelAPI/Test/Test2903.py index c66ce71ef..b868a4fcc 100644 --- a/src/ModelAPI/Test/Test2903.py +++ b/src/ModelAPI/Test/Test2903.py @@ -37,5 +37,5 @@ assert(aFactory.validate(Partition_1.feature())) Fuse_1.setMainObjects([model.selection("COMPOUND", "all-in-Box_1"), model.selection("COMPOUND", "all-in-Cylinder_1"), model.selection("COMPOUND", "all-in-Sphere_1")]) model.end() # partition must become invalid because it refers to the same object as fuse -assert(not aFactory.validate(Fuse_1.feature())) -assert(aFactory.validate(Partition_1.feature())) +assert(aFactory.validate(Fuse_1.feature())) +assert(not aFactory.validate(Partition_1.feature())) -- 2.39.2