From ba98986f2b5c1ec0f3b6640319c1381ffc09f37a Mon Sep 17 00:00:00 2001 From: mpv Date: Thu, 31 Oct 2019 16:16:32 +0300 Subject: [PATCH] Fix for the issue #3076 ExportToGEOM: Fatal error SWIG director method error --- src/FeaturesPlugin/CMakeLists.txt | 1 + src/FeaturesPlugin/Test/Test3076.py | 142 +++++++++++++++++++++++++ src/Model/Model_AttributeSelection.cpp | 13 ++- 3 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 src/FeaturesPlugin/Test/Test3076.py diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 82a9d3bc2..d2e81e3c4 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -534,5 +534,6 @@ ADD_UNIT_TESTS(TestExtrusion.py Test17281.py TestChamfer.py Test3033.py + Test3076.py Test17909.py ) diff --git a/src/FeaturesPlugin/Test/Test3076.py b/src/FeaturesPlugin/Test/Test3076.py new file mode 100644 index 000000000..574019186 --- /dev/null +++ b/src/FeaturesPlugin/Test/Test3076.py @@ -0,0 +1,142 @@ +from SketchAPI import * + +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +anAngle = model.addParameter(Part_1_doc, "angle", "45") +model.addParameter(Part_1_doc, "r1", "0.6671") +model.addParameter(Part_1_doc, "ep", "0.02") +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("YOZ")) +SketchLine_1 = Sketch_1.addLine(1.25, 4.0171, 1.25, 2.5971) +SketchLine_2 = Sketch_1.addLine(1.25, 2.5971, 1.4, 2.5971) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchLine_3 = Sketch_1.addLine(1.4, 2.5971, 1.4, 2.0871) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint()) +SketchLine_4 = Sketch_1.addLine(1.4, 2.0871, 1.25, 2.0871) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_1.result()) +SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_3.result()) +SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_4.result()) +SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_2.result()) +SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OY"), False) +SketchLine_5 = SketchProjection_1.createdFeature() +SketchLine_5.setName("SketchLine_6") +SketchLine_5.result().setName("SketchLine_6") +SketchProjection_2 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OZ"), False) +SketchLine_6 = SketchProjection_2.createdFeature() +SketchLine_6.setName("SketchLine_7") +SketchLine_6.result().setName("SketchLine_7") +SketchLine_7 = Sketch_1.addLine(1.25, 2.0871, 1.25, 0.6671) +SketchLine_7.setName("SketchLine_12") +SketchLine_7.result().setName("SketchLine_12") +SketchEllipticArc_1 = Sketch_1.addEllipticArc(0, 0.6671, 1.057108125973878, 0.6671, 0, 2.733995794193338e-31, 1.25, 0.6671000000000001, False) +[SketchPoint_1, SketchPoint_2, SketchPoint_3, SketchPoint_4, SketchPoint_5, SketchPoint_6, SketchPoint_7, SketchLine_8, SketchLine_9] = SketchEllipticArc_1.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux") +SketchConstraintVertical_3 = Sketch_1.setVertical(SketchLine_9.result()) +SketchConstraintVertical_3.setName("SketchConstraintVertical_4") +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_9).startPoint(), SketchEllipticArc_1.startPoint()) +SketchConstraintCoincidence_4.setName("SketchConstraintCoincidence_22") +SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchEllipticArc_1.endPoint(), SketchAPI_Point(SketchPoint_5).coordinates()) +SketchConstraintCoincidence_5.setName("SketchConstraintCoincidence_23") +SketchConstraintDistance_1 = Sketch_1.setDistance(SketchEllipticArc_1.minorAxisNegative(), SketchLine_8.result(), "r1", True) +SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_7.endPoint(), SketchEllipticArc_1.majorAxisPositive()) +SketchConstraintCoincidence_6.setName("SketchConstraintCoincidence_27") +SketchConstraintVertical_4 = Sketch_1.setVertical(SketchLine_7.result()) +SketchConstraintVertical_4.setName("SketchConstraintVertical_5") +SketchConstraintDistance_2 = Sketch_1.setDistance(SketchEllipticArc_1.majorAxisPositive(), SketchLine_6.result(), 1.25, True) +SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_7.result(), 1.42) +SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_7.startPoint()) +SketchConstraintCoincidence_7.setName("SketchConstraintCoincidence_13") +SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_7.result()) +SketchConstraintCoincidence_8.setName("SketchConstraintCoincidence_14") +SketchConstraintLength_2 = Sketch_1.setLength(SketchLine_3.result(), 0.51) +SketchConstraintLength_3 = Sketch_1.setLength(SketchLine_2.result(), 0.15) +SketchConstraintLength_4 = Sketch_1.setLength(SketchLine_1.result(), 1.42) +SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchEllipticArc_1.minorAxisNegative(), SketchLine_5.result()) +SketchConstraintCoincidence_9.setName("SketchConstraintCoincidence_9") +SketchConstraintCoincidence_10 = Sketch_1.setCoincident(SketchAPI_Point(SketchPoint_6).coordinates(), SketchLine_6.result()) +SketchConstraintCoincidence_10.setName("SketchConstraintCoincidence_10") +SketchEllipticArc_2 = Sketch_1.addEllipticArc(0, 4.0171, 1.057108125973878, 4.0171, 1.25, 4.0171, -1.323488743421758e-23, 4.6842, False) +[SketchPoint_8, SketchPoint_9, SketchPoint_10, SketchPoint_11, SketchPoint_12, SketchPoint_13, SketchPoint_14, SketchLine_10, SketchLine_11] = SketchEllipticArc_2.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux") +SketchConstraintCoincidence_11 = Sketch_1.setCoincident(SketchLine_6.result(), SketchEllipticArc_2.center()) +SketchConstraintCoincidence_11.setName("SketchConstraintCoincidence_11") +SketchConstraintCoincidence_12 = Sketch_1.setCoincident(SketchEllipticArc_2.startPoint(), SketchAPI_Line(SketchLine_10).endPoint()) +SketchConstraintCoincidence_12.setName("SketchConstraintCoincidence_12") +SketchConstraintCoincidence_13 = Sketch_1.setCoincident(SketchEllipticArc_2.endPoint(), SketchAPI_Line(SketchLine_11).endPoint()) +SketchConstraintCoincidence_13.setName("SketchConstraintCoincidence_15") +SketchConstraintHorizontal_3 = Sketch_1.setHorizontal(SketchLine_10.result()) +SketchConstraintCoincidence_14 = Sketch_1.setCoincident(SketchAPI_Point(SketchPoint_12).coordinates(), SketchLine_1.startPoint()) +SketchConstraintCoincidence_14.setName("SketchConstraintCoincidence_16") +SketchConstraintDistance_3 = Sketch_1.setDistance(SketchEllipticArc_2.minorAxisPositive(), SketchLine_10.result(), "r1", True) +SketchLine_12 = Sketch_1.addLine(1.229999999999999, 4.0171, 1.229999999999999, 0.6671) +SketchLine_12.setName("SketchLine_13") +SketchLine_12.result().setName("SketchLine_13") +SketchConstraintCoincidence_15 = Sketch_1.setCoincident(SketchLine_12.startPoint(), SketchLine_10.result()) +SketchConstraintCoincidence_15.setName("SketchConstraintCoincidence_17") +SketchConstraintCoincidence_16 = Sketch_1.setCoincident(SketchLine_12.endPoint(), SketchLine_8.result()) +SketchConstraintCoincidence_16.setName("SketchConstraintCoincidence_18") +SketchConstraintVertical_5 = Sketch_1.setVertical(SketchLine_12.result()) +SketchConstraintVertical_5.setName("SketchConstraintVertical_6") +SketchConstraintDistance_4 = Sketch_1.setDistance(SketchLine_12.startPoint(), SketchLine_1.result(), "ep", True) +SketchEllipticArc_3 = Sketch_1.addEllipticArc(0, 4.0171, 1.046021792316405, 4.0171, 0, 4.664199999999999, 1.23, 4.0171, True) +[SketchPoint_15, SketchPoint_16, SketchPoint_17, SketchPoint_18, SketchPoint_19, SketchPoint_20, SketchPoint_21, SketchLine_13, SketchLine_14] = SketchEllipticArc_3.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux") +SketchConstraintCoincidence_17 = Sketch_1.setCoincident(SketchEllipticArc_2.center(), SketchEllipticArc_3.center()) +SketchConstraintCoincidence_17.setName("SketchConstraintCoincidence_19") +SketchConstraintCoincidence_18 = Sketch_1.setCoincident(SketchLine_6.result(), SketchEllipticArc_3.startPoint()) +SketchConstraintCoincidence_18.setName("SketchConstraintCoincidence_20") +SketchConstraintCoincidence_19 = Sketch_1.setCoincident(SketchLine_10.result(), SketchEllipticArc_3.endPoint()) +SketchConstraintCoincidence_19.setName("SketchConstraintCoincidence_21") +SketchConstraintCoincidence_20 = Sketch_1.setCoincident(SketchEllipticArc_3.endPoint(), SketchLine_12.startPoint()) +SketchConstraintCoincidence_20.setName("SketchConstraintCoincidence_24") +SketchConstraintDistanceVertical_1 = Sketch_1.setVerticalDistance(SketchEllipticArc_2.minorAxisPositive(), SketchEllipticArc_3.startPoint(), "ep") +SketchConstraintHorizontal_4 = Sketch_1.setHorizontal(SketchLine_13.result()) +SketchEllipticArc_4 = Sketch_1.addEllipticArc(0, 0.6671, 1.046021792316011, 0.6671, 0, 0.02, 1.229999999999999, 0.6670999999999999, False) +[SketchPoint_22, SketchPoint_23, SketchPoint_24, SketchPoint_25, SketchPoint_26, SketchPoint_27, SketchPoint_28, SketchLine_15, SketchLine_16] = SketchEllipticArc_4.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux") +SketchConstraintCoincidence_21 = Sketch_1.setCoincident(SketchEllipticArc_1.center(), SketchEllipticArc_4.center()) +SketchConstraintCoincidence_21.setName("SketchConstraintCoincidence_25") +SketchConstraintCoincidence_22 = Sketch_1.setCoincident(SketchLine_12.endPoint(), SketchEllipticArc_4.result()) +SketchConstraintCoincidence_22.setName("SketchConstraintCoincidence_26") +SketchConstraintCoincidence_23 = Sketch_1.setCoincident(SketchLine_6.result(), SketchEllipticArc_4.startPoint()) +SketchConstraintCoincidence_23.setName("SketchConstraintCoincidence_28") +SketchConstraintCoincidence_24 = Sketch_1.setCoincident(SketchLine_12.endPoint(), SketchEllipticArc_4.endPoint()) +SketchConstraintCoincidence_24.setName("SketchConstraintCoincidence_29") +SketchConstraintDistanceVertical_2 = Sketch_1.setVerticalDistance(SketchEllipticArc_4.minorAxisNegative(), SketchEllipticArc_1.minorAxisNegative(), "ep") +SketchConstraintHorizontal_5 = Sketch_1.setHorizontal(SketchLine_15.result()) +SketchLine_17 = Sketch_1.addLine(9.702173021404511e-32, 0.02, -2.296340201324298e-16, -1.110223024625157e-16) +SketchConstraintCoincidence_25 = Sketch_1.setCoincident(SketchEllipticArc_4.minorAxisNegative(), SketchLine_17.startPoint()) +SketchConstraintCoincidence_25.setName("SketchConstraintCoincidence_30") +SketchConstraintCoincidence_26 = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_5).startPoint(), SketchLine_17.endPoint()) +SketchConstraintCoincidence_26.setName("SketchConstraintCoincidence_31") +SketchLine_18 = Sketch_1.addLine(7.654042494670958e-17, 4.684199999999996, 7.524363077049401e-17, 4.664199999999999) +SketchConstraintCoincidence_27 = Sketch_1.setCoincident(SketchEllipticArc_2.minorAxisPositive(), SketchLine_18.startPoint()) +SketchConstraintCoincidence_27.setName("SketchConstraintCoincidence_32") +SketchConstraintCoincidence_28 = Sketch_1.setCoincident(SketchEllipticArc_3.minorAxisPositive(), SketchLine_18.endPoint()) +SketchConstraintCoincidence_28.setName("SketchConstraintCoincidence_33") +model.do() +Revolution_1 = model.addRevolution(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchEllipticArc_2f-SketchLine_18f-SketchEllipticArc_3r-SketchLine_13f-SketchEllipticArc_4r-SketchLine_17f-SketchEllipticArc_1f-SketchLine_12r-SketchLine_4r-SketchLine_3r-SketchLine_2r-SketchLine_1r")], model.selection("EDGE", "PartSet/OZ"), "angle", 0) +Group_1_objects = [model.selection("FACE", "Revolution_1_1/Generated_Face&Sketch_1/SketchEllipticArc_4"), model.selection("FACE", "Revolution_1_1/Generated_Face&Sketch_1/SketchLine_13"), model.selection("FACE", "Revolution_1_1/Generated_Face&Sketch_1/SketchEllipticArc_3")] +Group_1 = model.addGroup(Part_1_doc, "Faces", Group_1_objects) +Group_1.setName("Group_int") +Group_1.result().setName("Group_int") +Group_1.result().setColor(170, 0, 0) +Group_2_objects = [model.selection("FACE", "Revolution_1_1/Generated_Face&Sketch_1/SketchEllipticArc_2"), model.selection("FACE", "Revolution_1_1/Generated_Face&Sketch_1/SketchLine_1"), model.selection("FACE", "Revolution_1_1/Generated_Face&Sketch_1/SketchLine_2"), model.selection("FACE", "Revolution_1_1/Generated_Face&Sketch_1/SketchLine_3"), model.selection("FACE", "Revolution_1_1/Generated_Face&Sketch_1/SketchLine_4"), model.selection("FACE", "Revolution_1_1/Generated_Face&Sketch_1/SketchLine_12"), model.selection("FACE", "Revolution_1_1/Generated_Face&Sketch_1/SketchEllipticArc_1")] +Group_2 = model.addGroup(Part_1_doc, "Faces", Group_2_objects) +Group_2.setName("Group_ext") +Group_2.result().setName("Group_ext") +Group_2.result().setColor(0, 170, 0) +Group_3 = model.addGroup(Part_1_doc, "Faces", [model.selection("FACE", "Revolution_1_1/From_Face")]) +Group_3.setName("Face_lat1") +Group_3.result().setName("Face_lat1") +Group_4 = model.addGroup(Part_1_doc, "Faces", [model.selection("FACE", "Revolution_1_1/To_Face")]) +Group_4.setName("Face_lat2") +Group_4.result().setName("Face_lat2") +model.do() +# change revolution to be 360 degrees => no lateral faces anymore +anAngle.setValue(360) +model.end() + +# check that group 3 and group 4 become invalid +assert(Group_3.groupList().value(0).isInvalid()) +assert(Group_4.groupList().value(0).isInvalid()) diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index d636a3804..091ae432f 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -602,19 +602,30 @@ bool Model_AttributeSelection::update() TopoDS_Shape aContextShape = aContext->shape()->impl(); Selector_Selector aSelector(aSelLab, baseDocumentLab()); aResult = aSelector.restore(aContextShape); + bool aWasInvalid = aSelLab.IsAttribute(kINVALID_SELECTION); setInvalidIfFalse(aSelLab, aResult); TopoDS_Shape aNewShape; if (aSelLab.FindAttribute(TNaming_NamedShape::GetID(), aNS)) aNewShape = aNS->Get(); - if (anOldShape.IsNull() || aNewShape.IsNull() || !anOldShape.IsEqual(aNewShape)) { + if (anOldShape.IsNull() || aNewShape.IsNull() || !anOldShape.IsEqual(aNewShape) || aWasInvalid) + { // shape type should not be changed: if shape becomes compound of such shapes, then split if (myParent && !anOldShape.IsNull() && !aNewShape.IsNull() && anOldShape.ShapeType() != aNewShape.ShapeType() && aNewShape.ShapeType() == TopAbs_COMPOUND) { split(aContext, aNewShape, anOldShape.ShapeType()); } + // for issue #3076 check that the new value belongs to the new context + if (!aNewShape.IsNull() && !aContextShape.IsNull()) { + TopExp_Explorer anExp(aContextShape, aNewShape.ShapeType()); + for(; anExp.More(); anExp.Next()) { + if (anExp.Current().IsSame(aNewShape)) + break; + } + aResult = setInvalidIfFalse(aSelLab, anExp.More()); + } owner()->data()->sendAttributeUpdated(this); // send updated if shape is changed } return aResult; -- 2.39.2