From 3a5b3112ad7799da9cae19aa208ba30b972afb2f Mon Sep 17 00:00:00 2001 From: mpv Date: Mon, 19 Nov 2018 10:23:08 +0300 Subject: [PATCH] Debug of refactored Selector --- src/Selector/Selector_Algo.cpp | 14 +++++----- src/Selector/Selector_Algo.h | 2 +- src/Selector/Selector_Container.cpp | 4 +-- src/Selector/Selector_FilterByNeighbors.cpp | 6 ++--- src/Selector/Selector_Intersect.cpp | 4 +-- src/Selector/Selector_Modify.cpp | 2 ++ src/Selector/Selector_Selector.cpp | 6 ++--- test.models/CSWA.py | 30 ++++++++++----------- 8 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/Selector/Selector_Algo.cpp b/src/Selector/Selector_Algo.cpp index c64e012d5..50e652a63 100644 --- a/src/Selector/Selector_Algo.cpp +++ b/src/Selector/Selector_Algo.cpp @@ -324,10 +324,10 @@ TopoDS_Shape Selector_Algo::value() return TopoDS_Shape(); // empty, error shape } -Selector_Algo* Selector_Algo::restoreByLab(TDF_Label theLab) +Selector_Algo* Selector_Algo::restoreByLab(TDF_Label theLab, TDF_Label theBaseDocLab) { Handle(TDataStd_Integer) aTypeAttr; - if (!myLab.FindAttribute(kSEL_TYPE, aTypeAttr)) + if (!theLab.FindAttribute(kSEL_TYPE, aTypeAttr)) return NULL; Selector_Type aType = Selector_Type(aTypeAttr->Get()); Selector_Algo* aResult = NULL; @@ -360,12 +360,9 @@ Selector_Algo* Selector_Algo::restoreByLab(TDF_Label theLab) } } if (aResult) { - bool aGeomNaming = myLab.IsAttribute(kGEOMETRICAL_NAMING); aResult->myLab = theLab; - aResult->myBaseDocumentLab = myBaseDocumentLab; - aResult->myGeometricalNaming = aGeomNaming; - aResult->myUseNeighbors = myUseNeighbors; - aResult->myUseIntersections = myUseIntersections; + aResult->myBaseDocumentLab = theBaseDocLab; + aResult->myGeometricalNaming = theLab.IsAttribute(kGEOMETRICAL_NAMING); if (!aResult->restore()) { delete aResult; aResult = NULL; @@ -396,7 +393,8 @@ Selector_Algo* Selector_Algo::restoreByName(TDF_Label theLab, TDF_Label theBaseD } } else if (theName[0] == '(') { // filter by neighbors aResult = new Selector_FilterByNeighbors; - } if (theName.find(pureWeakNameID()) == 0) { // weak naming identifier + } else if (theName.find(pureWeakNameID()) == 0) { // weak naming identifier + aResult = new Selector_WeakName; } else if (theName.find('&') != std::string::npos) { // modification aResult = new Selector_Modify; } else { // primitive diff --git a/src/Selector/Selector_Algo.h b/src/Selector/Selector_Algo.h index b58e99df0..f2149fe5e 100644 --- a/src/Selector/Selector_Algo.h +++ b/src/Selector/Selector_Algo.h @@ -94,7 +94,7 @@ public: /// Returns the current sub-shape value (null if can not resolve) SELECTOR_EXPORT TopoDS_Shape value(); /// Restores sub-algorithm of a given type by the storage-label - SELECTOR_EXPORT Selector_Algo* restoreByLab(TDF_Label theLab); + SELECTOR_EXPORT static Selector_Algo* restoreByLab(TDF_Label theLab, TDF_Label theBaseDocLab); /// Restores the selected sub-algorithm by the naming name. /// Returns not empty label of the context. SELECTOR_EXPORT static Selector_Algo* restoreByName( diff --git a/src/Selector/Selector_Container.cpp b/src/Selector/Selector_Container.cpp index 32d7134ee..f10fa46d6 100644 --- a/src/Selector/Selector_Container.cpp +++ b/src/Selector/Selector_Container.cpp @@ -73,7 +73,7 @@ bool Selector_Container::restore() // restore sub-selectors bool aSubResult = true; for(TDF_ChildIterator aSub(label(), false); aSub.More(); aSub.Next()) { - Selector_Algo* aSubSel = restoreByLab(aSub.Value()); + Selector_Algo* aSubSel = restoreByLab(aSub.Value(), baseDocument()); if (!append(aSubSel, false)) { break; // some empty label left in the end } @@ -99,7 +99,7 @@ TDF_Label Selector_Container::restoreByName(std::string theName, TDF_Label aSubContext; Selector_Algo* aSubSel = Selector_Algo::restoreByName( - label(), baseDocument(), aSubStr, aSubShapeType, theNameGenerator, aSubContext); + newSubLabel(), baseDocument(), aSubStr, aSubShapeType, theNameGenerator, aSubContext); if (!append(aSubSel)) return TDF_Label(); diff --git a/src/Selector/Selector_FilterByNeighbors.cpp b/src/Selector/Selector_FilterByNeighbors.cpp index 43221ba64..440e65b33 100644 --- a/src/Selector/Selector_FilterByNeighbors.cpp +++ b/src/Selector/Selector_FilterByNeighbors.cpp @@ -125,7 +125,7 @@ static const TopoDS_Shape findNeighbor(const TopoDS_Shape theContext, if (aMatches.Extent() == 1) return aMatches.First(); // already found good candidate TopoDS_Compound aResultCompound; // in case of geometrical name and many candidates - // iterate all matches to find by other (higher level) neighbors the best candidate + // iterate all matches to find by other (higher level) neighbors the best candidate TopoDS_Shape aGoodCandidate; TopTools_MapOfShape aGoodCandidates; // already added good candidates to the map for(TopoDS_ListOfShape::Iterator aCandidate(aMatches); aCandidate.More(); aCandidate.Next()) { @@ -254,7 +254,7 @@ bool Selector_FilterByNeighbors::restore() // restore sub-selectors bool aSubResult = true; for(TDF_ChildIterator aSub(label(), false); aSub.More(); aSub.Next()) { - Selector_Algo* aSubSel = restoreByLab(aSub.Value()); + Selector_Algo* aSubSel = restoreByLab(aSub.Value(), baseDocument()); if (!append(aSubSel, false)) { break; // some empty label left in the end } @@ -275,7 +275,7 @@ TDF_Label Selector_FilterByNeighbors::restoreByName(std::string theName, TDF_Label aSubContext; Selector_Algo* aSubSel = Selector_Algo::restoreByName( - label(), baseDocument(), aSubStr, myShapeType, theNameGenerator, aSubContext); + newSubLabel(), baseDocument(), aSubStr, myShapeType, theNameGenerator, aSubContext); if (!append(aSubSel)) return TDF_Label(); diff --git a/src/Selector/Selector_Intersect.cpp b/src/Selector/Selector_Intersect.cpp index 8d1a3de88..5d003a2a9 100644 --- a/src/Selector/Selector_Intersect.cpp +++ b/src/Selector/Selector_Intersect.cpp @@ -168,7 +168,7 @@ bool Selector_Intersect::restore() // restore sub-selectors bool aSubResult = true; for(TDF_ChildIterator aSub(label(), false); aSub.More(); aSub.Next()) { - Selector_Algo* aSubSel = restoreByLab(aSub.Value()); + Selector_Algo* aSubSel = restoreByLab(aSub.Value(), baseDocument()); if (!append(aSubSel, false)) { break; // some empty label left in the end } @@ -213,7 +213,7 @@ TDF_Label Selector_Intersect::restoreByName(std::string theName, TDF_Label aSubContext; Selector_Algo* aSubSel = Selector_Algo::restoreByName( - label(), baseDocument(), aSubStr, aSubShapeType, theNameGenerator, aSubContext); + newSubLabel(), baseDocument(), aSubStr, aSubShapeType, theNameGenerator, aSubContext); if (!append(aSubSel)) return TDF_Label(); diff --git a/src/Selector/Selector_Modify.cpp b/src/Selector/Selector_Modify.cpp index f764e1d39..e17ae2d33 100644 --- a/src/Selector/Selector_Modify.cpp +++ b/src/Selector/Selector_Modify.cpp @@ -184,6 +184,8 @@ bool Selector_Modify::select(NCollection_List& theMo return true; } } + } else if (aCommon.Extent() == 1) { + return true; // simple modification } } // weak naming case diff --git a/src/Selector/Selector_Selector.cpp b/src/Selector/Selector_Selector.cpp index 62d1ad0cb..c04ceb79a 100644 --- a/src/Selector/Selector_Selector.cpp +++ b/src/Selector/Selector_Selector.cpp @@ -59,9 +59,9 @@ bool Selector_Selector::store(const TopoDS_Shape theContext) bool Selector_Selector::restore(const TopoDS_Shape theContext) { - if (myAlgo->restoreByLab(myLab)) { - myAlgo->solve(theContext); // to update the selection shape on the label - return true; + myAlgo = Selector_Algo::restoreByLab(myLab, myBaseDocumentLab); + if (myAlgo) { + return myAlgo->solve(theContext); // to update the selection shape on the label } return false; } diff --git a/test.models/CSWA.py b/test.models/CSWA.py index 2885ff6c2..45a0a6f60 100644 --- a/test.models/CSWA.py +++ b/test.models/CSWA.py @@ -127,8 +127,8 @@ SketchConstraintCoincidence_23 = Sketch_3.setCoincident(SketchArc_3.results()[1] SketchConstraintCoincidence_23.setName("SketchConstraintCoincidence_24") model.do() ExtrusionFuse_1 = model.addExtrusionFuse(Part_1_doc, [model.selection("FACE", "Sketch_3/Face-SketchArc_3_2f-SketchLine_12f-SketchArc_5_2r")], model.selection(), 5, 0, [model.selection("SOLID", "ExtrusionCut_1_1")]) -Sketch_4 = model.addSketch(Part_1_doc, model.selection("FACE", "(ExtrusionFuse_1_1/Generated_Face&Sketch_3/SketchArc_5_2)(ExtrusionFuse_1_1/Generated_Face&Sketch_3/SketchLine_12)(ExtrusionFuse_1_1/Generated_Face&Sketch_3/SketchArc_3_2)")) -SketchPoint_4 = Sketch_4.addPoint(model.selection("VERTEX", "[ExtrusionFuse_1_1/Generated_Face&Sketch_3/SketchArc_5_2][ExtrusionFuse_1_1/Generated_Face&Sketch_3/SketchLine_12][(ExtrusionFuse_1_1/Generated_Face&Sketch_3/SketchArc_5_2)(ExtrusionFuse_1_1/Generated_Face&Sketch_3/SketchLine_12)(ExtrusionFuse_1_1/Generated_Face&Sketch_3/SketchArc_3_2)]")) +Sketch_4 = model.addSketch(Part_1_doc, model.selection("FACE", "ExtrusionFuse_1_1/To_Face")) +SketchPoint_4 = Sketch_4.addPoint(model.selection("VERTEX", "[ExtrusionFuse_1_1/Generated_Face&Sketch_3/SketchArc_5_2][ExtrusionFuse_1_1/Generated_Face&Sketch_3/SketchLine_12][ExtrusionFuse_1_1/To_Face]")) SketchCircle_2 = Sketch_4.addCircle(-15, 35.00000000000001, 5) SketchConstraintCoincidence_24 = Sketch_4.setCoincident(SketchPoint_4.result(), SketchCircle_2.center()) SketchConstraintCoincidence_24.setName("SketchConstraintCoincidence_25") @@ -140,7 +140,7 @@ SketchArc_6 = Sketch_5.addArc(model.selection("EDGE", "[ExtrusionCut_1_1/Modifie SketchArc_7 = Sketch_5.addArc(-45, 35, -45, 5, -25.41666666666737, 12.27351642784166, False) SketchConstraintCoincidence_25 = Sketch_5.setCoincident(SketchArc_6.result(), SketchArc_7.center()) SketchConstraintCoincidence_25.setName("SketchConstraintCoincidence_26") -SketchCircle_3 = Sketch_5.addCircle(model.selection("EDGE", "[ExtrusionFuse_2_1/Generated_Face&Sketch_4/SketchCircle_2_2][_weak_name_6_ExtrusionFuse_2_1]")) +SketchCircle_3 = Sketch_5.addCircle(model.selection("EDGE", "[ExtrusionFuse_2_1/Generated_Face&Sketch_4/SketchCircle_2_2][ExtrusionFuse_2_1/To_Face]")) SketchArc_8 = Sketch_5.addArc(-15, 35.00000000000001, -25.41666666666737, 12.27351642784166, -30.00000000000075, 14.99999999999944, True) SketchConstraintCoincidence_26 = Sketch_5.setCoincident(SketchCircle_3.result(), SketchArc_8.center()) SketchConstraintCoincidence_26.setName("SketchConstraintCoincidence_27") @@ -173,7 +173,7 @@ SketchConstraintCoincidence_35 = Sketch_6.setCoincident(SketchLine_14.result(), SketchConstraintCoincidence_35.setName("SketchConstraintCoincidence_36") SketchLine_15 = Sketch_6.addLine(model.selection("EDGE", "[ExtrusionFuse_3_1/Modified_Face&Extrusion_1_1/To_Face][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4]")) SketchConstraintDistance_8 = Sketch_6.setDistance(SketchArc_10.center(), SketchLine_15.result(), 35, False) -SketchLine_16 = Sketch_6.addLine(35, 35, 35, 48) +SketchLine_16 = Sketch_6.addLine(35, 35, 35, 47.99999999999999) SketchConstraintCoincidence_36 = Sketch_6.setCoincident(SketchArc_10.endPoint(), SketchLine_16.startPoint()) SketchConstraintCoincidence_36.setName("SketchConstraintCoincidence_37") SketchLine_17 = Sketch_6.addLine(model.selection("EDGE", "[ExtrusionFuse_3_1/Modified_Face&Extrusion_1_1/To_Face][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6]")) @@ -182,26 +182,26 @@ SketchConstraintCoincidence_37.setName("SketchConstraintCoincidence_38") SketchConstraintVertical_6 = Sketch_6.setVertical(SketchLine_16.result()) SketchConstraintTangent_4 = Sketch_6.setTangent(SketchLine_16.result(), SketchArc_10.results()[1]) SketchConstraintRadius_5 = Sketch_6.setRadius(SketchArc_10.results()[1], 20) -SketchLine_18 = Sketch_6.addLine(55, 15, 55, 48) +SketchLine_18 = Sketch_6.addLine(55, 15, 55, 47.99999999999999) SketchConstraintCoincidence_38 = Sketch_6.setCoincident(SketchArc_10.startPoint(), SketchLine_18.startPoint()) SketchConstraintCoincidence_38.setName("SketchConstraintCoincidence_39") SketchConstraintCoincidence_39 = Sketch_6.setCoincident(SketchLine_14.endPoint(), SketchLine_18.endPoint()) SketchConstraintCoincidence_39.setName("SketchConstraintCoincidence_40") -SketchLine_19 = Sketch_6.addLine(35, 48, 55, 48) +SketchLine_19 = Sketch_6.addLine(35, 47.99999999999999, 55, 47.99999999999999) SketchConstraintCoincidence_40 = Sketch_6.setCoincident(SketchLine_16.endPoint(), SketchLine_19.startPoint()) SketchConstraintCoincidence_40.setName("SketchConstraintCoincidence_41") SketchConstraintCoincidence_41 = Sketch_6.setCoincident(SketchLine_14.endPoint(), SketchLine_19.endPoint()) SketchConstraintCoincidence_41.setName("SketchConstraintCoincidence_42") model.do() ExtrusionCut_2 = model.addExtrusionCut(Part_1_doc, [model.selection("WIRE", "Sketch_6/Face-SketchArc_10_2f-SketchLine_18f-SketchLine_19r-SketchLine_16r_wire")], model.selection(), 0, 9, [model.selection("SOLID", "ExtrusionFuse_3_1")]) -Sketch_7 = model.addSketch(Part_1_doc, model.selection("FACE", "_weak_name_30_ExtrusionCut_2_1")) +Sketch_7 = model.addSketch(Part_1_doc, model.selection("FACE", "ExtrusionCut_2_1/From_Face")) SketchCircle_4 = Sketch_7.addCircle(45, -35, 5) -SketchLine_20 = Sketch_7.addLine(model.selection("EDGE", "[ExtrusionCut_2_1/Modified_Face&Sketch_1/SketchLine_5][_weak_name_30_ExtrusionCut_2_1]")) +SketchLine_20 = Sketch_7.addLine(model.selection("EDGE", "[ExtrusionCut_2_1/Modified_Face&Sketch_1/SketchLine_5][ExtrusionCut_2_1/From_Face]")) SketchConstraintDistance_9 = Sketch_7.setDistance(SketchCircle_4.center(), SketchLine_20.result(), 10, False) SketchConstraintRadius_6 = Sketch_7.setRadius(SketchCircle_4.results()[1], "10/2") SketchLine_21 = Sketch_7.addLine(35, -35, 45, -35) SketchLine_21.setAuxiliary(True) -SketchPoint_5 = Sketch_7.addPoint(model.selection("VERTEX", "[ExtrusionCut_2_1/Generated_Face&Sketch_6/SketchLine_16][ExtrusionCut_2_1/Generated_Face&Sketch_6/SketchArc_10_2][_weak_name_30_ExtrusionCut_2_1]")) +SketchPoint_5 = Sketch_7.addPoint(model.selection("VERTEX", "[ExtrusionCut_2_1/Generated_Face&Sketch_6/SketchLine_16][ExtrusionCut_2_1/Generated_Face&Sketch_6/SketchArc_10_2][ExtrusionCut_2_1/From_Face]")) SketchConstraintCoincidence_42 = Sketch_7.setCoincident(SketchLine_21.startPoint(), SketchPoint_5.result()) SketchConstraintCoincidence_42.setName("SketchConstraintCoincidence_43") SketchConstraintCoincidence_43 = Sketch_7.setCoincident(SketchCircle_4.center(), SketchLine_21.endPoint()) @@ -238,16 +238,16 @@ SketchConstraintCoincidence_49.setName("SketchConstraintCoincidence_50") model.do() ExtrusionCut_4 = model.addExtrusionCut(Part_1_doc, [model.selection("FACE", "Sketch_8/Face-SketchLine_22r-SketchLine_23f-SketchLine_24f-SketchLine_25f")], model.selection(), model.selection(), 0, model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4"), 0, [model.selection("SOLID", "ExtrusionCut_3_1")]) Sketch_9 = model.addSketch(Part_1_doc, model.selection("FACE", "ExtrusionFuse_1_1/Modified_Face&Sketch_1/SketchLine_9")) -SketchLine_28 = Sketch_9.addLine(25, -45, 18.44853578320836, -63) +SketchLine_28 = Sketch_9.addLine(25, -45, 18.44853578320833, -63) SketchLine_29 = Sketch_9.addLine(model.selection("EDGE", "[ExtrusionFuse_1_1/Modified_Face&Sketch_1/SketchLine_9][ExtrusionCut_4_1/Modified_Face&Sketch_1/SketchLine_8]")) SketchConstraintCoincidence_50 = Sketch_9.setCoincident(SketchLine_28.endPoint(), SketchLine_29.result()) SketchConstraintCoincidence_50.setName("SketchConstraintCoincidence_51") SketchLine_30 = Sketch_9.addLine(model.selection("EDGE", "[ExtrusionCut_4_1/Modified_Face&Extrusion_1_1/From_Face][ExtrusionFuse_1_1/Modified_Face&Sketch_1/SketchLine_9]")) SketchConstraintCoincidence_51 = Sketch_9.setCoincident(SketchLine_28.startPoint(), SketchLine_30.result()) SketchConstraintCoincidence_51.setName("SketchConstraintCoincidence_52") -SketchConstraintAngle_3 = Sketch_9.setAngle(SketchLine_28.result(), SketchLine_30.result(), 20) -SketchConstraintDistance_10 = Sketch_9.setDistance(SketchLine_28.startPoint(), SketchLine_29.result(), 18) -SketchLine_31 = Sketch_9.addLine(18.44853578320836, -63, 25, -63) +SketchConstraintAngle_3 = Sketch_9.setAngle(SketchLine_28.result(), SketchLine_30.result(), 20.00000000000009) +SketchConstraintDistance_10 = Sketch_9.setDistance(SketchLine_28.startPoint(), SketchLine_29.result(), 18, False) +SketchLine_31 = Sketch_9.addLine(18.44853578320833, -63, 25, -63) SketchConstraintCoincidence_52 = Sketch_9.setCoincident(SketchLine_28.endPoint(), SketchLine_31.startPoint()) SketchConstraintCoincidence_52.setName("SketchConstraintCoincidence_53") SketchConstraintCoincidence_53 = Sketch_9.setCoincident(SketchLine_29.startPoint(), SketchLine_31.endPoint()) @@ -262,9 +262,9 @@ ExtrusionCut_5 = model.addExtrusionCut(Part_1_doc, [model.selection("FACE", "Ske Sketch_10 = model.addSketch(Part_1_doc, model.selection("FACE", "ExtrusionCut_5_1/Modified_Face&Sketch_1/SketchLine_8")) SketchCircle_5 = Sketch_10.addCircle(-6.000000000000002, 4.999999999999997, 5) SketchLine_33 = Sketch_10.addLine(model.selection("EDGE", "[ExtrusionCut_2_1/Modified_Face&Extrusion_1_1/To_Face][ExtrusionCut_5_1/Modified_Face&Sketch_1/SketchLine_8]")) -SketchConstraintDistance_11 = Sketch_10.setDistance(SketchCircle_5.center(), SketchLine_33.result(), 30) +SketchConstraintDistance_11 = Sketch_10.setDistance(SketchCircle_5.center(), SketchLine_33.result(), 30, False) SketchLine_34 = Sketch_10.addLine(model.selection("EDGE", "[ExtrusionCut_5_1/Modified_Face&Sketch_1/SketchLine_9][ExtrusionCut_5_1/Modified_Face&Sketch_1/SketchLine_8]")) -SketchConstraintDistance_12 = Sketch_10.setDistance(SketchCircle_5.result(), SketchLine_34.result(), 9) +SketchConstraintDistance_12 = Sketch_10.setDistance(SketchCircle_5.result(), SketchLine_34.result(), 9, False) SketchConstraintRadius_7 = Sketch_10.setRadius(SketchCircle_5.results()[1], "10/2") model.do() ExtrusionCut_6 = model.addExtrusionCut(Part_1_doc, [model.selection("FACE", "Sketch_10/Face-SketchCircle_5_2r")], model.selection(), model.selection(), 0, model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_1"), 0, [model.selection("SOLID", "ExtrusionCut_5_1")]) -- 2.39.2