From 04d7bcf071f895d43f6c4ecc4d741dc8b365d1da Mon Sep 17 00:00:00 2001 From: mpv Date: Fri, 15 Dec 2017 09:37:21 +0300 Subject: [PATCH] Fix the naming problems for the sketch edges --- .../Test/TestBooleanFillWithPlane.py | 4 ++- src/Model/Model_AttributeSelection.cpp | 18 ++++++++-- src/Model/Model_ResultConstruction.cpp | 35 +++++++++++++++++-- src/Model/Model_SelectionNaming.cpp | 13 +++++-- 4 files changed, 62 insertions(+), 8 deletions(-) diff --git a/src/FeaturesPlugin/Test/TestBooleanFillWithPlane.py b/src/FeaturesPlugin/Test/TestBooleanFillWithPlane.py index 61f040a44..eeb224064 100644 --- a/src/FeaturesPlugin/Test/TestBooleanFillWithPlane.py +++ b/src/FeaturesPlugin/Test/TestBooleanFillWithPlane.py @@ -52,8 +52,10 @@ SketchConstraintVertical_4 = Sketch_1.setVertical(SketchLine_8.result()) 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 diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index 916e93328..3f4ee57be 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -865,6 +865,19 @@ void Model_AttributeSelection::selectSubShape( } } } + // 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(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; @@ -883,8 +896,9 @@ void Model_AttributeSelection::selectSubShape( // 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++) { + std::list >::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(); diff --git a/src/Model/Model_ResultConstruction.cpp b/src/Model/Model_ResultConstruction.cpp index 4962932bf..127507249 100644 --- a/src/Model/Model_ResultConstruction.cpp +++ b/src/Model/Model_ResultConstruction.cpp @@ -267,9 +267,36 @@ std::string fullName(CompositeFeaturePtr theComposite, const TopoDS_Shape& theSu } // 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 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(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(); + 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); @@ -447,7 +474,8 @@ int Model_ResultConstruction::select(const std::shared_ptr& theSu 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) { @@ -463,7 +491,8 @@ int Model_ResultConstruction::select(const std::shared_ptr& theSu 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); } } } diff --git a/src/Model/Model_SelectionNaming.cpp b/src/Model/Model_SelectionNaming.cpp index 7d4c36cc0..8c794c3dc 100644 --- a/src/Model/Model_SelectionNaming.cpp +++ b/src/Model/Model_SelectionNaming.cpp @@ -885,7 +885,16 @@ bool Model_SelectionNaming::selectSubShape(const std::string& theType, 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); } @@ -894,7 +903,7 @@ bool Model_SelectionNaming::selectSubShape(const std::string& theType, } // 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; -- 2.39.2