model.do()
Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")], model.selection(), 100, 0)
Boolean_1 = model.addFill(Part_1_doc, [model.selection("SOLID", "Extrusion_1_1_2")], [model.selection("FACE", "PartSet/YOZ")])
-Group_1 = model.addGroup(Part_1_doc, [model.selection("FACE", "Boolean_1_1_4/Modified_Face_5"), model.selection("FACE", "Boolean_1_1_4/Modified_Face_2"), model.selection("FACE", "Boolean_1_1_4/Modified_Face_1"), model.selection("FACE", "Extrusion_1_1/Generated_Face_7"), model.selection("FACE", "Boolean_1_1_4/Modified_Face_4"), model.selection("FACE", "Boolean_1_1_4/Modified_Face_3"), model.selection("FACE", "Boolean_1_1_4/Modified_Face_5"), model.selection("FACE", "Extrusion_1_1/Generated_Face_10"), model.selection("FACE", "Extrusion_1_1/Generated_Face_9"), model.selection("FACE", "Boolean_1_1_3/Modified_Face_5"), model.selection("FACE", "Boolean_1_1_1/Modified_Face_1"), model.selection("FACE", "Extrusion_1_1/Generated_Face_7"), model.selection("FACE", "Boolean_1_1_1/Modified_Face_2"), model.selection("FACE", "Boolean_1_1_3/Modified_Face_4"), model.selection("FACE", "Extrusion_1_1/Generated_Face_11"), model.selection("FACE", "Boolean_1_1_4/Modified_Face_4"), model.selection("FACE", "Extrusion_1_1/Generated_Face_12"), model.selection("FACE", "Extrusion_1_1/Generated_Face_5"), model.selection("FACE", "Boolean_1_1_3/Modified_Face_5"), model.selection("FACE", "Boolean_1_1_3/Modified_Face_2"), model.selection("FACE", "Boolean_1_1_3/Modified_Face_3"), model.selection("FACE", "Boolean_1_1_4/Modified_Face_1"), model.selection("FACE", "Boolean_1_1_3/Modified_Face_4"), model.selection("FACE", "Extrusion_1_1/Generated_Face_4"), model.selection("FACE", "Extrusion_1_1/Generated_Face_4"), model.selection("FACE", "Extrusion_1_1/To_Face_3"), model.selection("FACE", "Extrusion_1_1/Generated_Face_3"), model.selection("FACE", "Extrusion_1_1/From_Face_3"), model.selection("FACE", "Extrusion_1_1/Generated_Face_1"), model.selection("FACE", "Extrusion_1_1/Generated_Face_2")])
model.do()
+
+model.testHaveNamingSubshapes(Boolean_1, model, Part_1_doc)
+
model.end()
from GeomAPI import GeomAPI_Shape
}
}
}
+ // if compsolid is context, try to take sub-solid as context: like in GUI and scripts
+ if (aCont.get() && aShapeToBeSelected.get()) {
+ ResultCompSolidPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aCont);
+ if (aComp && aComp->numberOfSubs()) {
+ for(int aSubNum = aComp->numberOfSubs() - 1; aSubNum >= 0; aSubNum--) {
+ ResultPtr aSub = aComp->subResult(aSubNum);
+ if (aSub && aSub->shape().get() && aSub->shape()->isSubShape(aShapeToBeSelected)) {
+ aCont = aSub;
+ 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;
// 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++) {
+ std::list<std::shared_ptr<ModelAPI_Result> >::reverse_iterator aResIter =
+ aResults.rbegin(); // iterate from the end to find the sub-solid first than compsolid
+ for(; aResIter != aResults.rend(); aResIter++) {
if (!aResIter->get() || !(*aResIter)->data()->isValid() || (*aResIter)->isDisabled())
continue;
GeomShapePtr aShape = (*aResIter)->shape();
}
// stores shape and name on sub-label of the main stored shape
-static void saveSubName(TDF_Label& theLab, const bool isSelectionMode, const TopoDS_Shape& aSub,
+static void saveSubName(CompositeFeaturePtr theComposite,
+ TDF_Label& theLab, const bool isSelectionMode, TopoDS_Shape aSub,
std::shared_ptr<Model_Document> theDoc, std::string theFullName)
{
+ // trying to store the edge of composite result, not sketch sub as it is
+ if (aSub.ShapeType() == TopAbs_EDGE) {
+ ResultPtr aRes = theComposite->firstResult();
+ ResultConstructionPtr aConstr = std::dynamic_pointer_cast<Model_ResultConstruction>(aRes);
+ if (aConstr.get()) {
+ Standard_Real aSubFirst, aSubLast;
+ TopoDS_Edge aSubEdge = TopoDS::Edge(aSub);
+ Handle(Geom_Curve) aSubCurve = BRep_Tool::Curve(aSubEdge, aSubFirst, aSubLast);
+ for(int aFaceIndex = 0; aFaceIndex < aConstr->facesNum(); aFaceIndex++) {
+ GeomShapePtr aGFace = aConstr->face(aFaceIndex);
+ TopoDS_Shape aFace = aGFace->impl<TopoDS_Shape>();
+ for(TopExp_Explorer anExp(aFace, TopAbs_EDGE); anExp.More(); anExp.Next()) {
+ TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
+ Standard_Real aFirst, aLast;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
+ if (aCurve == aSubCurve &&
+ ((fabs(aFirst - aSubFirst) < 1.e-9 && fabs(aLast - aSubLast) < 1.e-9)) ||
+ (fabs(aFirst - aSubLast) < 1.e-9 && fabs(aLast - aSubFirst) < 1.e-9)) {
+ aSub = anEdge;
+ break;
+ }
+ }
+ }
+ }
+ }
+
TNaming_Builder aBuilder(theLab);
if (isSelectionMode)
aBuilder.Select(aSub, aSub);
TDF_Label aSubLab = aLab.FindChild(anID);
TDF_Label aShapeSubLab = aLab.FindChild(aSubLabId++);
std::string aFullNameSub = fullName(aComposite, anEdge);
- saveSubName(aShapeSubLab, isSelectionMode, anEdge, aMyDoc, aFullNameSub);
+ saveSubName(aComposite,
+ aShapeSubLab, isSelectionMode, anEdge, aMyDoc, aFullNameSub);
int anOrient = Model_SelectionNaming::edgeOrientation(aSubShape, anEdge);
if (anOrient != 0) {
TopoDS_Vertex aV = TopoDS::Vertex(anEdgeExp.Current());
TDF_Label aShapeSubLab = aLab.FindChild(aSubLabId++);
std::string aFullNameSub = fullName(aComposite, aV);
- saveSubName(aShapeSubLab, isSelectionMode, aV, aMyDoc, aFullNameSub);
+ saveSubName(aComposite,
+ aShapeSubLab, isSelectionMode, aV, aMyDoc, aFullNameSub);
}
}
}
aFaceContext = aDoc->findByName(aContName, *it, anUniqueContext);
}
}
- const TopoDS_Shape aFace = findFaceByName(*it, aDoc, aFaceContext, anUniqueContext);
+ TopoDS_Shape aFace = findFaceByName(*it, aDoc, aFaceContext, anUniqueContext);
+ if (aFace.IsNull() && aFaceContext.get() &&
+ aFaceContext->groupName() == ModelAPI_ResultConstruction::group() ) {
+ // search the construction sub-elements for the intersection if they are in the tree
+ size_t aSlash = it->find("/");
+ if (aSlash != std::string::npos) {
+ std::string aSubShapeName = it->substr(aSlash + 1);
+ aFace = findFaceByName(aSubShapeName, aDoc, aFaceContext, true);
+ }
+ }
if(!aFace.IsNull())
aList.Append(aFace);
}
}
// in case of construction, there is no registered names for all sub-elements,
// even for the main element; so, trying to find them by name (without "&" intersections)
- if (aN < 2) {
+ if (aSelection.IsNull() && aN < 2) {
size_t aConstrNamePos = aSubShapeName.find("/");
bool isFullName = aConstrNamePos == std::string::npos;
std::string anEmpty, aContrName = aContName;