From aa58bae23056bfc1c2efd91da2653db750273597 Mon Sep 17 00:00:00 2001 From: mpv Date: Tue, 27 Nov 2018 15:58:58 +0300 Subject: [PATCH] Make unit-tests produce an error if the function for test of naming gets feature without results (due to comment in the issue #2291 ) --- src/BuildPlugin/Test/Test2439.py | 4 ++-- src/FeaturesPlugin/Test/Test2520.py | 2 +- src/FeaturesPlugin/Test/TestBooleanCut_Vertex_Vertex.py | 1 - src/Model/Model_Objects.cpp | 2 +- src/ModelAPI/ModelAPI_Feature.cpp | 4 +++- src/ModelAPI/ModelAPI_Object.h | 3 ++- src/ModelAPI/Test/TestWeakNaming2291.py | 6 +++--- src/ModelAPI/Test/TestWeakNaming2437.py | 4 ++-- src/ModelAPI/Test/TestWeakNaming2452.py | 4 ++-- src/PythonAPI/model/tests/tests.py | 1 + 10 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/BuildPlugin/Test/Test2439.py b/src/BuildPlugin/Test/Test2439.py index 3a66d3930..6d3d8fc70 100644 --- a/src/BuildPlugin/Test/Test2439.py +++ b/src/BuildPlugin/Test/Test2439.py @@ -38,8 +38,8 @@ SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result()) SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result()) SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result()) model.do() -Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("WIRE", "Sketch_1/Wire-SketchLine_1f-SketchLine_2f-SketchLine_3f-SketchLine_4f")], model.selection(), 100, 0) -Edge_1 = model.addEdge(Part_1_doc, [model.selection("EDGE", "Extrusion_1_1/Generated_Face_2&Extrusion_1_1/To_Face_1")]) +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("WIRE", "Sketch_1/Face-SketchLine_1r-SketchLine_2f-SketchLine_3f-SketchLine_4f_wire")], model.selection(), 100, 0) +Edge_1 = model.addEdge(Part_1_doc, [model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/To_Face]")]) model.do() model.testHaveNamingSubshapes(Edge_1, model, Part_1_doc) diff --git a/src/FeaturesPlugin/Test/Test2520.py b/src/FeaturesPlugin/Test/Test2520.py index c6aa13dd7..d12325da3 100644 --- a/src/FeaturesPlugin/Test/Test2520.py +++ b/src/FeaturesPlugin/Test/Test2520.py @@ -84,7 +84,7 @@ SketchConstraintCoincidence_14 = Sketch_1.setCoincident(SketchLine_13.startPoint SketchConstraintHorizontal_7 = Sketch_1.setHorizontal(SketchLine_13.result()) SketchConstraintCoincidence_15 = Sketch_1.setCoincident(SketchLine_13.endPoint(), SketchLine_8.result()) model.do() -Revolution_1 = model.addRevolution(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_1r-SketchLine_2r-SketchLine_3r-SketchLine_4r-SketchLine_5r-SketchLine_6r-SketchLine_7r-SketchLine_8r-SketchLine_9r-SketchLine_10r-SketchLine_11r-SketchLine_12r")], model.selection("EDGE", "Sketch_1/Edge-SketchLine_13"), 360, 0) +Revolution_1 = model.addRevolution(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_12r-SketchLine_11r-SketchLine_10r-SketchLine_9r-SketchLine_8r-SketchLine_7r-SketchLine_6r-SketchLine_5r-SketchLine_4r-SketchLine_3r-SketchLine_2r-SketchLine_1r")], model.selection("EDGE", "Sketch_1/SketchLine_13"), 360, 0) model.do() # check that naming of the revolution is correct model.testHaveNamingSubshapes(Revolution_1, model, Part_1_doc) diff --git a/src/FeaturesPlugin/Test/TestBooleanCut_Vertex_Vertex.py b/src/FeaturesPlugin/Test/TestBooleanCut_Vertex_Vertex.py index a109e0cdd..5015061a4 100644 --- a/src/FeaturesPlugin/Test/TestBooleanCut_Vertex_Vertex.py +++ b/src/FeaturesPlugin/Test/TestBooleanCut_Vertex_Vertex.py @@ -36,7 +36,6 @@ Vertex_3 = model.addVertex(Part_1_doc, [model.selection("VERTEX", "Sketch_1/Sket Vertex_4 = model.addVertex(Part_1_doc, [model.selection("VERTEX", "Sketch_1/SketchPoint_2")]) Cut_1 = model.addCut(Part_1_doc, [model.selection("VERTEX", "Vertex_1_1")], [model.selection("VERTEX", "Vertex_2_1")]) Cut_2 = model.addCut(Part_1_doc, [model.selection("VERTEX", "Vertex_3_1")], [model.selection("VERTEX", "Vertex_4_1")]) -model.testHaveNamingSubshapes(Cut_1, model, Part_1_doc) model.testHaveNamingSubshapes(Cut_2, model, Part_1_doc) model.do() model.end() diff --git a/src/Model/Model_Objects.cpp b/src/Model/Model_Objects.cpp index 18dfb8573..352c2e60c 100644 --- a/src/Model/Model_Objects.cpp +++ b/src/Model/Model_Objects.cpp @@ -1797,7 +1797,7 @@ std::shared_ptr Model_Objects::feature( const std::shared_ptr& theResult) { std::shared_ptr aData = std::dynamic_pointer_cast(theResult->data()); - if (aData.get()) { + if (aData.get() && aData->isValid()) { TDF_Label aFeatureLab = aData->label().Father().Father().Father(); FeaturePtr aFeature = feature(aFeatureLab); while(!aFeature.get() && aFeatureLab.Depth() > 1) { // this may be sub-result of result diff --git a/src/ModelAPI/ModelAPI_Feature.cpp b/src/ModelAPI/ModelAPI_Feature.cpp index 4ac1b9886..5f1e3c989 100644 --- a/src/ModelAPI/ModelAPI_Feature.cpp +++ b/src/ModelAPI/ModelAPI_Feature.cpp @@ -173,8 +173,10 @@ void ModelAPI_Feature::erase() while (!myResults.empty()) { // remove one by one with messages std::shared_ptr aRes = *(myResults.begin()); aRes->setDisabled(aRes, true); // to avoid activation of the Part result - if (!myResults.empty()) // disabling result may erase the list (on undo of Part, issue 665) + if (!myResults.empty()) {// disabling result may erase the list (on undo of Part, issue 665) myResults.erase(myResults.begin()); + aRes->erase(); + } } ModelAPI_Object::erase(); } diff --git a/src/ModelAPI/ModelAPI_Object.h b/src/ModelAPI/ModelAPI_Object.h index 1f09fb2be..64a2d432e 100644 --- a/src/ModelAPI/ModelAPI_Object.h +++ b/src/ModelAPI/ModelAPI_Object.h @@ -30,7 +30,7 @@ class ModelAPI_Data; class ModelAPI_Document; -// sometimes it is usefull for debug to see name of each object (bad for memory and performance) +// sometimes it is useful for debug to see name of each object (bad for memory and performance) //#define DEBUG_NAMES /**\class ModelAPI_Object @@ -115,6 +115,7 @@ class ModelAPI_Object: public ModelAPI_Entity MODELAPI_EXPORT virtual void erase(); friend class Model_Objects; + friend class ModelAPI_Feature; friend class Model_Document; }; diff --git a/src/ModelAPI/Test/TestWeakNaming2291.py b/src/ModelAPI/Test/TestWeakNaming2291.py index 10c00199a..c075e912d 100644 --- a/src/ModelAPI/Test/TestWeakNaming2291.py +++ b/src/ModelAPI/Test/TestWeakNaming2291.py @@ -40,8 +40,8 @@ SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result()) SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result()) SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result()) model.do() -Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_1f-SketchLine_2f-SketchLine_3f-SketchLine_4f")], model.selection(), 10, 0) -Sketch_2 = model.addSketch(Part_1_doc, model.selection("FACE", "Sketch_1/Face-SketchLine_1f-SketchLine_2f-SketchLine_3f-SketchLine_4f")) +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_1r-SketchLine_2f-SketchLine_3f-SketchLine_4f")], model.selection(), 10, 0) +Sketch_2 = model.addSketch(Part_1_doc, model.selection("FACE", "Sketch_1/Face-SketchLine_1r-SketchLine_2f-SketchLine_3f-SketchLine_4f")) SketchLine_5 = Sketch_2.addLine(-3.660618520812283, -7.666051414039341, -9.927240775274454, -7.666051414039341) SketchLine_6 = Sketch_2.addLine(-9.927240775274454, -7.666051414039341, -9.927240775274454, 7.885614342469023) SketchLine_7 = Sketch_2.addLine(-9.927240775274454, 7.885614342469023, -3.660618520812283, 7.885614342469023) @@ -55,7 +55,7 @@ SketchConstraintVertical_3 = Sketch_2.setVertical(SketchLine_6.result()) SketchConstraintHorizontal_4 = Sketch_2.setHorizontal(SketchLine_7.result()) SketchConstraintVertical_4 = Sketch_2.setVertical(SketchLine_8.result()) model.do() -Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchLine_5r-SketchLine_6r-SketchLine_7r-SketchLine_8r")], model.selection(), 10, 0) +Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchLine_8r-SketchLine_7r-SketchLine_6r-SketchLine_5r")], model.selection(), 10, 0) Fuse_1 = model.addFuse(Part_1_doc, [model.selection("SOLID", "Extrusion_1_1"), model.selection("SOLID", "Extrusion_2_1")]) model.do() model.testHaveNamingSubshapes(Fuse_1, model, Part_1_doc) diff --git a/src/ModelAPI/Test/TestWeakNaming2437.py b/src/ModelAPI/Test/TestWeakNaming2437.py index 6656fbe9d..288989030 100644 --- a/src/ModelAPI/Test/TestWeakNaming2437.py +++ b/src/ModelAPI/Test/TestWeakNaming2437.py @@ -178,9 +178,9 @@ SketchLine_22 = SketchProjection_4.createdFeature() SketchConstraintDistance_9 = Sketch_2.setDistance(SketchLine_19.startPoint(), SketchLine_22.result(), "(TL/2-3)-20", True) SketchConstraintDistance_10 = Sketch_2.setDistance(SketchLine_19.endPoint(), SketchLine_22.result(), "(TL/2-3)-20", True) model.do() -Wire_1_objects = [model.selection("EDGE", "Sketch_1/Edge-SketchLine_11"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_10"), model.selection("EDGE", "Sketch_1/Edge-SketchArc_4_2"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_12"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_14"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_13"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_15"), model.selection("EDGE", "Sketch_1/Edge-SketchArc_5_2"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_16"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_9"), model.selection("EDGE", "Sketch_1/Edge-SketchArc_1_2"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_8"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_7"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_5"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_4"), model.selection("EDGE", "Sketch_1/Edge-SketchArc_3_2"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_3"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_1")] +Wire_1_objects = [model.selection("EDGE", "Sketch_1/SketchLine_11"), model.selection("EDGE", "Sketch_1/SketchLine_10"), model.selection("EDGE", "Sketch_1/SketchArc_4_2"), model.selection("EDGE", "Sketch_1/SketchLine_12"), model.selection("EDGE", "Sketch_1/SketchLine_14"), model.selection("EDGE", "Sketch_1/SketchLine_13"), model.selection("EDGE", "Sketch_1/SketchLine_15"), model.selection("EDGE", "Sketch_1/SketchArc_5_2"), model.selection("EDGE", "Sketch_1/SketchLine_16"), model.selection("EDGE", "Sketch_1/SketchLine_9"), model.selection("EDGE", "Sketch_1/SketchArc_1_2"), model.selection("EDGE", "Sketch_1/SketchLine_8"), model.selection("EDGE", "Sketch_1/SketchLine_7"), model.selection("EDGE", "Sketch_1/SketchLine_5"), model.selection("EDGE", "Sketch_1/SketchLine_4"), model.selection("EDGE", "Sketch_1/SketchArc_3_2"), model.selection("EDGE", "Sketch_1/SketchLine_3"), model.selection("EDGE", "Sketch_1/SketchLine_1")] Wire_1 = model.addWire(Part_1_doc, Wire_1_objects) -Wire_2_objects = [model.selection("EDGE", "Sketch_2/Edge-SketchLine_17"), model.selection("EDGE", "Sketch_2/Edge-SketchArc_7_2"), model.selection("EDGE", "Sketch_2/Edge-SketchLine_20"), model.selection("EDGE", "Sketch_2/Edge-SketchLine_19"), model.selection("EDGE", "Sketch_2/Edge-SketchLine_18"), model.selection("EDGE", "Sketch_2/Edge-SketchArc_6_2")] +Wire_2_objects = [model.selection("EDGE", "Sketch_2/SketchLine_17"), model.selection("EDGE", "Sketch_2/SketchArc_7_2"), model.selection("EDGE", "Sketch_2/SketchLine_20"), model.selection("EDGE", "Sketch_2/SketchLine_19"), model.selection("EDGE", "Sketch_2/SketchLine_18"), model.selection("EDGE", "Sketch_2/SketchArc_6_2")] Wire_2 = model.addWire(Part_1_doc, Wire_2_objects) Face_1 = model.addFace(Part_1_doc, [model.selection("WIRE", "Wire_1_1")]) Face_2 = model.addFace(Part_1_doc, [model.selection("WIRE", "Wire_2_1")]) diff --git a/src/ModelAPI/Test/TestWeakNaming2452.py b/src/ModelAPI/Test/TestWeakNaming2452.py index 21caaa1da..83613dda4 100644 --- a/src/ModelAPI/Test/TestWeakNaming2452.py +++ b/src/ModelAPI/Test/TestWeakNaming2452.py @@ -87,9 +87,9 @@ SketchConstraintHorizontal_10 = Sketch_1.setHorizontal(SketchLine_19.result()) SketchConstraintVertical_10 = Sketch_1.setVertical(SketchLine_20.result()) model.do() Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")], model.selection(), 100, 100) -Translation_1 = model.addTranslation(Part_1_doc, [model.selection("COMPSOLID", "Extrusion_1_1")], model.selection("EDGE", "Extrusion_1_1/Generated_Face_24&Extrusion_1_1/To_Face_2"), 200) +Translation_1 = model.addTranslation(Part_1_doc, [model.selection("COMPSOLID", "Extrusion_1_1")], model.selection("EDGE", "[Extrusion_1_1_2/Generated_Face&Sketch_1/SketchLine_20][Extrusion_1_1_2/To_Face]"), 200) Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")], model.selection(), 50, 50) -Translation_2 = model.addTranslation(Part_1_doc, [model.selection("COMPSOLID", "Extrusion_2_1")], model.selection("EDGE", "Extrusion_2_1/Generated_Face_24&Extrusion_2_1/To_Face_2"), 150) +Translation_2 = model.addTranslation(Part_1_doc, [model.selection("COMPSOLID", "Extrusion_2_1")], model.selection("EDGE", "[Extrusion_2_1_2/Generated_Face&Sketch_1/SketchLine_20][Extrusion_2_1_2/To_Face]"), 150) Boolean_1 = model.addCut(Part_1_doc, [model.selection("COMPSOLID", "Translation_1_1")], [model.selection("COMPSOLID", "Translation_2_1")]) model.do() model.testHaveNamingSubshapes(Boolean_1, model, Part_1_doc) diff --git a/src/PythonAPI/model/tests/tests.py b/src/PythonAPI/model/tests/tests.py index 92ff8a609..ea60df69f 100644 --- a/src/PythonAPI/model/tests/tests.py +++ b/src/PythonAPI/model/tests/tests.py @@ -263,6 +263,7 @@ def testHaveNamingSubshapes(theFeature, theModel, thePartDoc) : """ Tests if all vertices/edges/faces of result have a unique name :param theFeature: feature to test. """ + assert(len(theFeature.results()) > 0) testHaveNamingByType(theFeature, theModel, thePartDoc, GeomAPI_Shape.VERTEX) testHaveNamingByType(theFeature, theModel, thePartDoc, GeomAPI_Shape.EDGE) testHaveNamingByType(theFeature, theModel, thePartDoc, GeomAPI_Shape.FACE) -- 2.39.2