From 5626878481d8751d9c8c0eb1df71cec208df5cb7 Mon Sep 17 00:00:00 2001 From: mpv Date: Thu, 14 Dec 2017 16:50:20 +0300 Subject: [PATCH] Fixes for the updated naming rules for generation of lower-level topology --- src/Model/Model_AttributeSelection.cpp | 37 +++++++++++++++++++++++++- src/ModelAPI/Test/Test1757.py | 8 +++--- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index c29cca229..5c35d4b9c 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -658,7 +659,7 @@ void Model_AttributeSelection::selectBody( bool isFound = false; TopExp_Explorer anExp(aNewContext, aNewSub.ShapeType()); for(; anExp.More(); anExp.Next()) { - if (anExp.Current().IsEqual(aNewSub)) { + if (anExp.Current().IsSame(aNewSub)) { isFound = true; break; } @@ -863,7 +864,41 @@ void Model_AttributeSelection::selectSubShape( } } } + // try to find the latest active result that must be used instead of the selected + // to set the active context (like in GUI selection), not concealed one + bool aFindNewContext = true; + while(aFindNewContext && aCont.get() && aShapeToBeSelected.get()) { + aFindNewContext = false; + const std::set& aRefs = aCont->data()->refsToMe(); + std::set::const_iterator aRef = aRefs.begin(); + for(; !aFindNewContext && aRef != aRefs.end(); aRef++) { + if (!aRef->get() || !(*aRef)->owner().get()) + continue; + // concealed attribute only + FeaturePtr aRefFeat = std::dynamic_pointer_cast((*aRef)->owner()); + if (!ModelAPI_Session::get()->validators()->isConcealed( + aRefFeat->getKind(), (*aRef)->id())) + continue; + // search the feature result that contains sub-shape selected + std::list > aResults; + ModelAPI_Tools::allResults(aRefFeat, aResults); + std::list >::iterator aResIter = aResults.begin(); + for(; aResIter != aResults.end(); aResIter++) { + if (!aResIter->get() || !(*aResIter)->data()->isValid() || (*aResIter)->isDisabled()) + continue; + GeomShapePtr aShape = (*aResIter)->shape(); + if (aShape.get() && aShape->isSubShape(aShapeToBeSelected, false)) { + aCont = *aResIter; // found new context (produced from this) with same subshape + //if (!aShape->isSubShape(aShapeToBeSelected, true)) // take context orientation + // aShapeToBeSelected->setOrientation(); + aFindNewContext = true; // continue searching futher + break; + } + } + } + } } + if (aCenterType != NOT_CENTER) { if (!aShapeToBeSelected->isEdge()) continue; diff --git a/src/ModelAPI/Test/Test1757.py b/src/ModelAPI/Test/Test1757.py index 52f4dcb21..8418bdc89 100644 --- a/src/ModelAPI/Test/Test1757.py +++ b/src/ModelAPI/Test/Test1757.py @@ -80,7 +80,7 @@ model.do() # Make a cylindrical hole using one of the produced faces #========================================================================= ExtrusionCut_2 = model.addExtrusionCut(Part_1_doc, [], model.selection(), model.selection(), 0, model.selection("FACE", "Extrusion_1_1/Generated_Face_2"), 0, [model.selection("SOLID", "ExtrusionCut_1_1")]) -Sketch_3 = model.addSketch(Part_1_doc, model.selection("FACE", "ExtrusionCut_1_1/Modfied_4")) +Sketch_3 = model.addSketch(Part_1_doc, model.selection("FACE", "ExtrusionCut_1_1/Modfied_3")) SketchCircle_1 = Sketch_3.addCircle(143.412751420315, -228.52745656314, 32.158435160764) ExtrusionCut_2.setNestedSketch(Sketch_3) @@ -92,8 +92,8 @@ Part_1.document().setCurrentFeature(ExtrusionCut_1.feature(), True) #========================================================================= # Modify the cylindrical hole base face by another groove in the history before the hole is created #========================================================================= -ExtrusionCut_3 = model.addExtrusionCut(Part_1_doc, [], model.selection(), model.selection(), 0, model.selection("FACE", "Extrusion_1_1/Generated_Face_3"), -50, [model.selection("SOLID", "ExtrusionCut_1_1")]) -Sketch_4 = model.addSketch(Part_1_doc, model.selection("FACE", "Extrusion_1_1/Generated_Face_1")) +ExtrusionCut_3 = model.addExtrusionCut(Part_1_doc, [], model.selection(), model.selection(), 0, model.selection("FACE", "Extrusion_1_1/Generated_Face_1"), -50, [model.selection("SOLID", "ExtrusionCut_1_1")]) +Sketch_4 = model.addSketch(Part_1_doc, model.selection("FACE", "Extrusion_1_1/Generated_Face_3")) SketchLine_9 = Sketch_4.addLine(-176.701443076057, -151.212050129331, -91.83965287802501, -151.212050129331) SketchLine_10 = Sketch_4.addLine(-91.83965287802501, -151.212050129331, -91.83965287802501, -84.473709256573) SketchLine_11 = Sketch_4.addLine(-91.83965287802501, -84.473709256573, -176.701443076057, -84.473709256573) @@ -125,6 +125,6 @@ import ModelAPI assert(ModelAPI.ModelAPI_Session.get().validators().validate(Sketch_4.feature())) assert(ModelAPI.ModelAPI_Session.get().validators().validate(ExtrusionCut_2.feature())) -assert(Sketch_3.feature().selection("External").namingName() == "ExtrusionCut_1_1/Modfied_4") +assert(Sketch_3.feature().selection("External").namingName() == "ExtrusionCut_3_1/Modfied_5") assert(model.checkPythonDump()) -- 2.39.2