[PD] fix pad uptoface and uptoshape (#16030)

* [PD] fix Pad UpToFace and UpToShape
* specify struct pointers for Win
* Rename variables for MSVC compatibility - windows.h defines 'near' and 'far' as macros
* Add unit test

---------

Co-authored-by: Chris Hennes <chennes@pioneerlibrarysystem.org>
This commit is contained in:
Florian Foinant-Willig
2024-09-19 15:51:18 +02:00
committed by GitHub
parent 85082b72d4
commit e157f0616a
8 changed files with 156 additions and 25 deletions

View File

@@ -28,6 +28,7 @@
# include <BRepAdaptor_Surface.hxx>
# include <BRepBuilderAPI_MakeEdge.hxx>
# include <BRepBuilderAPI_MakeFace.hxx>
# include <BRepIntCurveSurface_Inter.hxx>
# include <BRepLProp_SLProps.hxx>
# include <BRepMesh_IncrementalMesh.hxx>
# include <CSLib.hxx>
@@ -744,3 +745,37 @@ TopLoc_Location Part::Tools::fromPlacement(const Base::Placement& plm)
trf.SetTransformation(gp_Quaternion(q1, q2, q3, q4), gp_Vec(t.x, t.y, t.z));
return {trf};
}
bool Part::Tools::isConcave(const TopoDS_Face &face, const gp_Pnt &pointOfVue, const gp_Dir &direction){
bool result = false;
Handle(Geom_Surface) surf = BRep_Tool::Surface(face);
GeomAdaptor_Surface adapt(surf);
if(adapt.GetType() == GeomAbs_Plane){
return false;
}
// create a line through the point of vue
gp_Lin line;
line.SetLocation(pointOfVue);
line.SetDirection(direction);
// Find intersection of line with the face
BRepIntCurveSurface_Inter mkSection;
mkSection.Init(face, line, Precision::Confusion());
result = mkSection.Transition() == IntCurveSurface_In;
// compute normals at the intersection
gp_Pnt iPnt;
gp_Vec dU, dV;
surf->D1(mkSection.U(), mkSection.V(), iPnt, dU, dV);
// check normals orientation
gp_Dir dirdU(dU);
result = (dirdU.Angle(direction) - M_PI_2) <= Precision::Confusion();
gp_Dir dirdV(dV);
result = result || ((dirdV.Angle(direction) - M_PI_2) <= Precision::Confusion());
return result;
}

View File

@@ -225,6 +225,16 @@ public:
* \return TopLoc_Location
*/
static TopLoc_Location fromPlacement(const Base::Placement&);
/*!
* \brief isConcave
* \param face
* \param pointOfVue
* \param direction
* \return true if the face is concave when shown from pointOfVue and looking into direction
* and false otherwise, plane case included.
*/
static bool isConcave(const TopoDS_Face &face, const gp_Pnt &pointOfVue, const gp_Dir &direction);
};
} //namespace Part

View File

@@ -104,6 +104,8 @@
#include <ShapeAnalysis_FreeBoundsProperties.hxx>
#include <BRepFeat_MakeRevol.hxx>
#include "Tools.h"
FC_LOG_LEVEL_INIT("TopoShape", true, true) // NOLINT
#if OCC_VERSION_HEX >= 0x070600
@@ -4231,6 +4233,12 @@ TopoShape& TopoShape::makeElementPrismUntil(const TopoShape& _base,
BRepFeat_MakePrism PrismMaker;
// don't remove limits of concave face
Base::Vector3d vCog;
profile.getCenterOfGravity(vCog);
gp_Pnt pCog(vCog.x, vCog.y, vCog.z);
checkLimits = ! Part::Tools::isConcave(TopoDS::Face(__uptoface.getShape()), pCog , direction);
TopoShape _uptoface(__uptoface);
if (checkLimits && _uptoface.shapeType(true) == TopAbs_FACE
&& !BRep_Tool::NaturalRestriction(TopoDS::Face(_uptoface.getShape()))) {
@@ -4252,7 +4260,8 @@ TopoShape& TopoShape::makeElementPrismUntil(const TopoShape& _base,
// Check whether the face has limits or not. Unlimited faces have no wire
// Note: Datum planes are always unlimited
if (checkLimits && _uptoface.shapeType(true) == TopAbs_FACE && uptoface.hasSubShape(TopAbs_WIRE)) {
if (checkLimits && uptoface.shapeType(true) == TopAbs_FACE
&& uptoface.hasSubShape(TopAbs_WIRE)) {
TopoDS_Face face = TopoDS::Face(uptoface.getShape());
bool remove_limits = false;
// Remove the limits of the upToFace so that the extrusion works even if profile is larger
@@ -4292,10 +4301,7 @@ TopoShape& TopoShape::makeElementPrismUntil(const TopoShape& _base,
// use the placement of the adapter, not of the upToFace
loc = TopLoc_Location(adapt.Trsf());
BRepBuilderAPI_MakeFace mkFace(adapt.Surface().Surface(), Precision::Confusion());
if (!mkFace.IsDone()) {
remove_limits = false;
}
else {
if (mkFace.IsDone()) {
uptoface.setShape(located(mkFace.Shape(), loc), false);
}
}