#include <ModelAPI_CompositeFeature.h>
#include <ModelAPI_Tools.h>
#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
#include <Events_InfoMessage.h>
#include <GeomAPI_Edge.h>
#include <GeomAPI_Vertex.h>
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;
}
}
}
}
+ // 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<AttributePtr>& aRefs = aCont->data()->refsToMe();
+ std::set<AttributePtr>::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<ModelAPI_Feature>((*aRef)->owner());
+ if (!ModelAPI_Session::get()->validators()->isConcealed(
+ aRefFeat->getKind(), (*aRef)->id()))
+ continue;
+ // search the feature result that contains sub-shape selected
+ std::list<std::shared_ptr<ModelAPI_Result> > aResults;
+ ModelAPI_Tools::allResults(aRefFeat, aResults);
+ std::list<std::shared_ptr<ModelAPI_Result> >::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;
# 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)
#=========================================================================
# 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)
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())