From 69be57369aecc178f4eda88cfee33278925b8902 Mon Sep 17 00:00:00 2001 From: azv Date: Fri, 31 Aug 2018 08:48:37 +0300 Subject: [PATCH] Dump with geometrical selection Iteratively process compsolids within other compsolids --- src/GeomAPI/GeomAPI_Shape.cpp | 2 +- src/ModelGeomAlgo/ModelGeomAlgo_Shape.cpp | 48 ++++++++++++++++------- src/ModelHighAPI/ModelHighAPI_Dumper.cpp | 9 ++--- 3 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/GeomAPI/GeomAPI_Shape.cpp b/src/GeomAPI/GeomAPI_Shape.cpp index 369ad7ef1..c4f30b6d3 100644 --- a/src/GeomAPI/GeomAPI_Shape.cpp +++ b/src/GeomAPI/GeomAPI_Shape.cpp @@ -567,7 +567,7 @@ bool GeomAPI_Shape::computeSize(double& theXmin, double& theYmin, double& theZmi if (aShape.IsNull()) return false; Bnd_Box aBndBox; - BRepBndLib::Add(aShape, aBndBox); + BRepBndLib::Add(aShape, aBndBox, false); if (aBndBox.IsVoid()) return false; aBndBox.Get(theXmin, theYmin, theZmin, theXmax, theYmax, theZmax); diff --git a/src/ModelGeomAlgo/ModelGeomAlgo_Shape.cpp b/src/ModelGeomAlgo/ModelGeomAlgo_Shape.cpp index a1c4af701..73266b8cf 100644 --- a/src/ModelGeomAlgo/ModelGeomAlgo_Shape.cpp +++ b/src/ModelGeomAlgo/ModelGeomAlgo_Shape.cpp @@ -148,6 +148,38 @@ namespace ModelGeomAlgo_Shape } } + static bool findSubshapeInCompsolid(const ResultBodyPtr& theCompsolid, + const std::shared_ptr& thePoint, + const GeomAPI_Shape::ShapeType& theShapeType, + const double theTolerance, + std::list& theSelected) + { + bool isSubshapeFound = false; + int aNbSolids = theCompsolid->numberOfSubs(); + for (int i = 0; i < aNbSolids; ++i) { + ResultPtr aSubResult = theCompsolid->subResult(i); + + // process subs of compsolid + ResultBodyPtr aSubCompSolid = std::dynamic_pointer_cast(aSubResult); + if (aSubCompSolid && aSubCompSolid->numberOfSubs() > 0) { + isSubshapeFound = findSubshapeInCompsolid(aSubCompSolid, + thePoint, theShapeType, theTolerance, theSelected); + } + else { + GeomShapePtr aSubSolid = aSubResult->shape(); + if (aSubSolid && isPointWithinBB(thePoint, aSubSolid, theTolerance)) { + std::list aSubshapes = + findSubShape(aSubSolid, theShapeType, thePoint, theTolerance); + if (!aSubshapes.empty()) { + appendSubshapeOfResult(theSelected, aSubResult, aSubshapes); + isSubshapeFound = true; + } + } + } + } + return isSubshapeFound; + } + bool findSubshapeByPoint(const std::shared_ptr& theFeature, const std::shared_ptr& thePoint, const GeomAPI_Shape::ShapeType& theShapeType, @@ -173,20 +205,8 @@ namespace ModelGeomAlgo_Shape if (theShapeType != GeomAPI_Shape::COMPOUND || !aSketchEdges) { ResultBodyPtr aCompSolid = std::dynamic_pointer_cast(*aResIt); if (aCompSolid) { - // process solids - int aNbSolids = aCompSolid->numberOfSubs(); - for (int i = 0; i < aNbSolids; ++i) { - ResultPtr aSubResult = aCompSolid->subResult(i); - GeomShapePtr aSubSolid = aSubResult->shape(); - if (aSubSolid && isPointWithinBB(thePoint, aSubSolid, TOLERANCE)) { - std::list aSubshapes = - findSubShape(aSubSolid, theShapeType, thePoint, TOLERANCE); - if (!aSubshapes.empty()) { - appendSubshapeOfResult(theSelected, aSubResult, aSubshapes); - isSubshapeFound = true; - } - } - } + isSubshapeFound = findSubshapeInCompsolid(aCompSolid, + thePoint, theShapeType, TOLERANCE, theSelected); } if (!isSubshapeFound) { diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp index b4df71cc7..304a95b97 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp @@ -1033,13 +1033,10 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( FeaturePtr aSelectedFeature; if (isDumpByGeom) { ResultPtr aRes = theAttrSelect->context(); - if (aRes) + FeaturePtr aFeature = theAttrSelect->contextFeature(); + if (aRes && !aFeature) aSelectedFeature = ModelAPI_Feature::feature(aRes->data()->owner()); - else - aSelectedFeature = theAttrSelect->contextFeature(); - - if (aSelectedFeature) - isDumpByGeom = aSelectedFeature->isInHistory(); + isDumpByGeom = aSelectedFeature && aSelectedFeature->isInHistory(); } myDumpBuffer << "\"" << aShape->shapeTypeStr(); -- 2.39.2