Toponaming/Part: transfer in linearize

This commit is contained in:
Zheng, Lei
2024-02-15 08:05:23 -05:00
committed by bgbsww
parent 93e94d8868
commit 17a01963e0
2 changed files with 88 additions and 0 deletions

View File

@@ -317,6 +317,10 @@ public:
bool isInfinite() const;
/// Checks whether the shape is a planar face
bool isPlanar(double tol = 1.0e-7) const;
/// Check if this shape is a single linear edge, works on BSplineCurve and BezierCurve
bool isLinearEdge(Base::Vector3d *dir = nullptr, Base::Vector3d *base = nullptr) const;
/// Check if this shape is a single planar face, works on BSplineSurface and BezierSurface
bool isPlanarFace(double tol=1e-7) const;
//@}
/** @name Boolean operation*/
@@ -680,6 +684,12 @@ public:
}
//@}
/** Try to simplify geometry of any linear/planar subshape to line/plane
*
* @return Return true if the shape is modified
*/
bool linearize(bool face, bool edge);
static TopAbs_ShapeEnum shapeType(const char* type, bool silent = false);
static TopAbs_ShapeEnum shapeType(char type, bool silent = false);
TopAbs_ShapeEnum shapeType(bool silent = false) const;

View File

@@ -34,6 +34,7 @@
#include <BRepTools.hxx>
#include <BRep_Builder.hxx>
#include <BRep_Tool.hxx>
#include <BRepAdaptor_CompCurve.hxx>
#include <BRepAlgoAPI_BooleanOperation.hxx>
#include <BRepAlgoAPI_Common.hxx>
#include <BRepAlgoAPI_Cut.hxx>
@@ -71,6 +72,8 @@
#include "Geometry.h"
#include <App/ElementNamingUtils.h>
#include <BRepLib.hxx>
#include "Geometry.h"
FC_LOG_LEVEL_INIT("TopoShape", true, true) // NOLINT
@@ -2490,6 +2493,81 @@ TopoShape TopoShape::splitWires(std::vector<TopoShape>* inner, SplitWireReorient
return TopoShape {};
}
bool TopoShape::isLinearEdge(Base::Vector3d* dir, Base::Vector3d* base) const
{
if (isNull() || getShape().ShapeType() != TopAbs_EDGE) {
return false;
}
if (!GeomCurve::isLinear(BRepAdaptor_Curve(TopoDS::Edge(getShape())).Curve().Curve(),
dir,
base)) {
return false;
}
// BRep_Tool::Curve() will transform the returned geometry, so no need to
// check the shape's placement.
return true;
}
bool TopoShape::isPlanarFace(double tol) const
{
if (isNull() || getShape().ShapeType() != TopAbs_FACE) {
return false;
}
return GeomSurface::isPlanar(BRepAdaptor_Surface(TopoDS::Face(getShape())).Surface().Surface(),
nullptr,
tol);
}
bool TopoShape::linearize(bool face, bool edge)
{
bool touched = false;
BRep_Builder builder;
// Note: changing edge geometry seems to mess up with face (or shell, or solid)
// Probably need to do some fix afterwards.
if (edge) {
for (auto& edge : getSubTopoShapes(TopAbs_EDGE)) {
TopoDS_Edge e = TopoDS::Edge(edge.getShape());
BRepAdaptor_Curve curve(e);
if (curve.GetType() == GeomAbs_Line || !edge.isLinearEdge()) {
continue;
}
std::unique_ptr<Geometry> geo(
Geometry::fromShape(e.Located(TopLoc_Location()).Oriented(TopAbs_FORWARD)));
std::unique_ptr<Geometry> gline(static_cast<GeomCurve*>(geo.get())->toLine());
if (gline) {
touched = true;
builder.UpdateEdge(e,
Handle(Geom_Curve)::DownCast(gline->handle()),
e.Location(),
BRep_Tool::Tolerance(e));
}
}
}
if (face) {
for (auto& face : getSubTopoShapes(TopAbs_FACE)) {
TopoDS_Face f = TopoDS::Face(face.getShape());
BRepAdaptor_Surface surf(f);
if (surf.GetType() == GeomAbs_Plane || !face.isPlanarFace()) {
continue;
}
std::unique_ptr<Geometry> geo(
Geometry::fromShape(f.Located(TopLoc_Location()).Oriented(TopAbs_FORWARD)));
std::unique_ptr<Geometry> gplane(static_cast<GeomSurface*>(geo.get())->toPlane());
if (gplane) {
touched = true;
builder.UpdateFace(f,
Handle(Geom_Surface)::DownCast(gplane->handle()),
f.Location(),
BRep_Tool::Tolerance(f));
}
}
}
return touched;
}
struct MapperFill: Part::TopoShape::Mapper
{
BRepFill_Generator& maker;