Skip to content

Commit

Permalink
Part: fixes #4774: Datum plane or line is not available in sketch in …
Browse files Browse the repository at this point in the history
…another body via binder
  • Loading branch information
wwmayer committed Oct 30, 2021
1 parent c5b3ee7 commit 9e85160
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 2 deletions.
66 changes: 66 additions & 0 deletions src/Mod/Part/App/Tools.cpp
Expand Up @@ -25,6 +25,11 @@
# include <cassert>
# include <gp_Pln.hxx>
# include <gp_Lin.hxx>
# include <BRepAdaptor_Curve.hxx>
# include <BRepAdaptor_Surface.hxx>
# include <BRepBuilderAPI_MakeEdge.hxx>
# include <BRepBuilderAPI_MakeFace.hxx>
# include <BRepMesh_IncrementalMesh.hxx>
# include <BRep_Tool.hxx>
# include <Geom_BSplineSurface.hxx>
# include <Geom_Plane.hxx>
Expand Down Expand Up @@ -590,3 +595,64 @@ void Part::Tools::applyTransformationOnNormals(const TopLoc_Location& loc, std::
}
}
}

Handle (Poly_Triangulation) Part::Tools::triangulationOfFace(const TopoDS_Face& face)
{
TopLoc_Location loc;
Handle (Poly_Triangulation) mesh = BRep_Tool::Triangulation(face, loc);
if (!mesh.IsNull())
return mesh;

// If no triangulation exists then the shape is probably infinite
BRepAdaptor_Surface adapt(face);
double u1 = adapt.FirstUParameter();
double u2 = adapt.LastUParameter();
double v1 = adapt.FirstVParameter();
double v2 = adapt.LastVParameter();

// recreate a face with a clear boundary
u1 = std::max(-50.0, u1);
u2 = std::min( 50.0, u2);
v1 = std::max(-50.0, v1);
v2 = std::min( 50.0, v2);

Handle(Geom_Surface) surface = BRep_Tool::Surface(face);
BRepBuilderAPI_MakeFace mkBuilder(surface, u1, u2, v1, v2
#if OCC_VERSION_HEX >= 0x060502
, Precision::Confusion()
#endif
);

TopoDS_Shape shape = mkBuilder.Shape();
shape.Location(loc);

BRepMesh_IncrementalMesh(shape, 0.1);
return BRep_Tool::Triangulation(TopoDS::Face(shape), loc);
}

Handle(Poly_Polygon3D) Part::Tools::polygonOfEdge(const TopoDS_Edge& edge, TopLoc_Location& loc)
{
BRepAdaptor_Curve adapt(edge);
double u = adapt.FirstParameter();
double v = adapt.LastParameter();
Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(edge, loc);
if (!aPoly.IsNull() && !Precision::IsInfinite(u) && !Precision::IsInfinite(v))
return aPoly;

// recreate an edge with a clear range
u = std::max(-50.0, u);
v = std::min( 50.0, v);

double uv;
Handle(Geom_Curve) curve = BRep_Tool::Curve(edge, uv, uv);

BRepBuilderAPI_MakeEdge mkBuilder(curve, u, v);
TopoDS_Shape shape = mkBuilder.Shape();
// why do we have to set the inverted location here?
TopLoc_Location inv = loc.Inverted();
shape.Location(inv);

BRepMesh_IncrementalMesh(shape, 0.1);
TopLoc_Location tmp;
return BRep_Tool::Polygon3D(TopoDS::Edge(shape), tmp);
}
18 changes: 18 additions & 0 deletions src/Mod/Part/App/Tools.h
Expand Up @@ -30,6 +30,7 @@
#include <gp_Dir.hxx>
#include <gp_XYZ.hxx>
#include <Geom_Surface.hxx>
#include <Poly_Polygon3D.hxx>
#include <Poly_Triangle.hxx>
#include <Poly_Triangulation.hxx>
#include <TColStd_ListOfTransient.hxx>
Expand All @@ -38,6 +39,7 @@
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <vector>
#include <Mod/Part/PartGlobal.h>

class gp_Lin;
class gp_Pln;
Expand Down Expand Up @@ -177,6 +179,22 @@ class PartExport Tools
* \param normals
*/
static void applyTransformationOnNormals(const TopLoc_Location& loc, std::vector<gp_Vec>& normals);
/*!
* \brief triangulationOfInfinite
* Returns the triangulation of the face of the tessellated shape. In case the face has infinite lengths
* the triangulation of a limited parameter range is computed.
* \param edge
* \param loc
*/
static Handle (Poly_Triangulation) triangulationOfFace(const TopoDS_Face& face);
/*!
* \brief polygonOfEdge
* Returns the polygon of the edge of the tessellated shape. In case the edge has infinite length
* the polygon of a limited parameter range is computed.
* \param edge
* \param loc
*/
static Handle(Poly_Polygon3D) polygonOfEdge(const TopoDS_Edge& edge, TopLoc_Location& loc);
};

} //namespace Part
Expand Down
10 changes: 8 additions & 2 deletions src/Mod/Part/Gui/ViewProviderExt.cpp
Expand Up @@ -985,6 +985,9 @@ void ViewProviderPartExt::updateVisual()
TopExp::MapShapes(cShape, TopAbs_FACE, faceMap);
for (int i=1; i <= faceMap.Extent(); i++) {
Handle (Poly_Triangulation) mesh = BRep_Tool::Triangulation(TopoDS::Face(faceMap(i)), aLoc);
if (mesh.IsNull()) {
mesh = Part::Tools::triangulationOfFace(TopoDS::Face(faceMap(i)));
}
// Note: we must also count empty faces
if (!mesh.IsNull()) {
numTriangles += mesh->NbTriangles();
Expand Down Expand Up @@ -1024,7 +1027,7 @@ void ViewProviderPartExt::updateVisual()
// a free edge.
int hash = aEdge.HashCode(INT_MAX);
if (faceEdges.find(hash) == faceEdges.end()) {
Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(aEdge, aLoc);
Handle(Poly_Polygon3D) aPoly = Part::Tools::polygonOfEdge(aEdge, aLoc);
if (!aPoly.IsNull()) {
int nbNodesInEdge = aPoly->NbNodes();
numNodes += nbNodesInEdge;
Expand Down Expand Up @@ -1058,6 +1061,9 @@ void ViewProviderPartExt::updateVisual()
const TopoDS_Face &actFace = TopoDS::Face(faceMap(i));
// get the mesh of the shape
Handle (Poly_Triangulation) mesh = BRep_Tool::Triangulation(actFace,aLoc);
if (mesh.IsNull()) {
mesh = Part::Tools::triangulationOfFace(actFace);
}
if (mesh.IsNull()) {
parts[ii] = 0;
continue;
Expand Down Expand Up @@ -1220,7 +1226,7 @@ void ViewProviderPartExt::updateVisual()
// handling of the free edge that are not associated to a face
int hash = aEdge.HashCode(INT_MAX);
if (faceEdges.find(hash) == faceEdges.end()) {
Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(aEdge, aLoc);
Handle(Poly_Polygon3D) aPoly = Part::Tools::polygonOfEdge(aEdge, aLoc);
if (!aPoly.IsNull()) {
if (!aLoc.IsIdentity()) {
identity = false;
Expand Down

0 comments on commit 9e85160

Please sign in to comment.