Toposhape/Part: clean, add tests for makeElementFillet and makeElementChamfer

This commit is contained in:
bgbsww
2024-02-21 15:18:11 -05:00
parent 952ae46d49
commit 1470616abe
3 changed files with 356 additions and 60 deletions

View File

@@ -197,9 +197,21 @@ enum class MapElement
/// Defines how to fill the holes that may appear after offset two adjacent faces
enum class JoinType
{
Arc,
Tangent,
Intersection,
arc,
tangent,
intersection,
};
enum class Flip
{
none,
flip
};
enum class AsAngle
{
no,
yes
};
/** The representation for a CAD Shape
@@ -808,7 +820,7 @@ public:
*/
TopoShape &makeElementThickSolid(const TopoShape &source, const std::vector<TopoShape> &faces,
double offset, double tol, bool intersection = false, bool selfInter = false,
short offsetMode = 0, JoinType join = JoinType::Arc, const char *op=nullptr);
short offsetMode = 0, JoinType join = JoinType::arc, const char *op=nullptr);
/** Make a hollowed solid by removing some faces from a given solid
*
@@ -830,7 +842,7 @@ public:
*/
TopoShape makeElementThickSolid(const std::vector<TopoShape> &faces,
double offset, double tol, bool intersection = false, bool selfInter = false,
short offsetMode = 0, JoinType join = JoinType::Arc, const char *op=nullptr) const {
short offsetMode = 0, JoinType join = JoinType::arc, const char *op=nullptr) const {
return TopoShape(0,Hasher).makeElementThickSolid(*this,faces,offset,tol,intersection,selfInter,
offsetMode,join,op);
}
@@ -1332,8 +1344,11 @@ public:
* a self reference so that multiple operations can be carried out
* for the same shape in the same line of code.
*/
TopoShape &makEFillet(const TopoShape &source, const std::vector<TopoShape> &edges,
double radius1, double radius2, const char *op=nullptr);
TopoShape& makeElementFillet(const TopoShape& source,
const std::vector<TopoShape>& edges,
double radius1,
double radius2,
const char* op = nullptr);
/* Make fillet shape
*
* @param source: the source shape
@@ -1345,9 +1360,12 @@ public:
*
* @return Return the new shape. The TopoShape itself is not modified.
*/
TopoShape makEFillet(const std::vector<TopoShape> &edges,
double radius1, double radius2, const char *op=nullptr) const {
return TopoShape(0,Hasher).makEFillet(*this,edges,radius1,radius2,op);
TopoShape makeElementFillet(const std::vector<TopoShape>& edges,
double radius1,
double radius2,
const char* op = nullptr) const
{
return TopoShape(0, Hasher).makeElementFillet(*this, edges, radius1, radius2, op);
}
/* Make chamfer shape
@@ -1364,8 +1382,13 @@ public:
* a self reference so that multiple operations can be carried out
* for the same shape in the same line of code.
*/
TopoShape &makEChamfer(const TopoShape &source, const std::vector<TopoShape> &edges,
double radius1, double radius2, const char *op=nullptr, bool flipDirection=false, bool asAngle=false);
TopoShape& makeElementChamfer(const TopoShape& source,
const std::vector<TopoShape>& edges,
double radius1,
double radius2,
const char* op = nullptr,
Flip flipDirection = Flip::none,
AsAngle asAngle = AsAngle::no);
/* Make chamfer shape
*
* @param source: the source shape
@@ -1377,9 +1400,15 @@ public:
*
* @return Return the new shape. The TopoShape itself is not modified.
*/
TopoShape makEChamfer(const std::vector<TopoShape> &edges,
double radius1, double radius2, const char *op=nullptr, bool flipDirection=false, bool asAngle=false) const {
return TopoShape(0,Hasher).makEChamfer(*this,edges,radius1,radius2,op,flipDirection,asAngle);
TopoShape makeElementChamfer(const std::vector<TopoShape>& edges,
double radius1,
double radius2,
const char* op = nullptr,
Flip flipDirection = Flip::none,
AsAngle asAngle = AsAngle::no) const
{
return TopoShape(0, Hasher)
.makeElementChamfer(*this, edges, radius1, radius2, op, flipDirection, asAngle);
}
/* Make draft shape

View File

@@ -49,6 +49,8 @@
#include <BRepAlgoAPI_Section.hxx>
#include <BRepBuilderAPI_Copy.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepFilletAPI_MakeChamfer.hxx>
#include <BRepFilletAPI_MakeFillet.hxx>
#include <BRepLib.hxx>
#include <BRepOffsetAPI_DraftAngle.hxx>
#include <BRepOffsetAPI_MakePipe.hxx>
@@ -2143,11 +2145,11 @@ TopoShape& TopoShape::makeElementThickSolid(const TopoShape& shape,
// we do not offer tangent join type
switch (join) {
case JoinType::Arc:
case JoinType::Intersection:
case JoinType::arc:
case JoinType::intersection:
break;
default:
join = JoinType::Intersection;
join = JoinType::intersection;
}
if (shape.isNull()) {
@@ -2594,57 +2596,78 @@ struct MapperThruSections: MapperMaker
}
};
TopoShape &TopoShape::makEFillet(const TopoShape &shape, const std::vector<TopoShape> &edges,
double radius1, double radius2, const char *op)
TopoShape& TopoShape::makeElementFillet(const TopoShape& shape,
const std::vector<TopoShape>& edges,
double radius1,
double radius2,
const char* op)
{
if(!op) op = Part::OpCodes::Fillet;
if(shape.isNull())
HANDLE_NULL_SHAPE;
if(edges.empty())
HANDLE_NULL_INPUT;
if (!op) {
op = Part::OpCodes::Fillet;
}
if (shape.isNull()) {
FC_THROWM(NullShapeException, "Null shape");
}
if (edges.empty()) {
FC_THROWM(NullShapeException, "Null input shape");
}
BRepFilletAPI_MakeFillet mkFillet(shape.getShape());
for(auto &e : edges) {
if(e.isNull())
HANDLE_NULL_INPUT;
const auto &edge = e.getShape();
if(!shape.findShape(edge))
FC_THROWM(Base::CADKernelError,"edge does not belong to the shape");
for (auto& e : edges) {
if (e.isNull()) {
FC_THROWM(NullShapeException, "Null input shape");
}
const auto& edge = e.getShape();
if (!shape.findShape(edge)) {
FC_THROWM(Base::CADKernelError, "edge does not belong to the shape");
}
mkFillet.Add(radius1, radius2, TopoDS::Edge(edge));
}
return makEShape(mkFillet,shape,op);
return makeElementShape(mkFillet, shape, op);
}
TopoShape &TopoShape::makEChamfer(const TopoShape &shape, const std::vector<TopoShape> &edges,
double radius1, double radius2, const char *op, bool flipDirection, bool asAngle)
TopoShape& TopoShape::makeElementChamfer(const TopoShape& shape,
const std::vector<TopoShape>& edges,
double radius1,
double radius2,
const char* op,
Flip flipDirection,
AsAngle asAngle)
{
if(!op) op = Part::OpCodes::Chamfer;
if(shape.isNull())
HANDLE_NULL_SHAPE;
if(edges.empty())
HANDLE_NULL_INPUT;
BRepFilletAPI_MakeChamfer mkChamfer(shape.getShape());
for(auto &e : edges) {
const auto &edge = e.getShape();
if(e.isNull())
HANDLE_NULL_INPUT;
if(!shape.findShape(edge))
FC_THROWM(Base::CADKernelError,"edge does not belong to the shape");
//Add edge to fillet algorithm
TopoDS_Shape face;
if(flipDirection)
face = shape.findAncestorsShapes(edge,TopAbs_FACE).back();
else
face = shape.findAncestorShape(edge,TopAbs_FACE);
if(asAngle)
mkChamfer.AddDA(radius1, radius2, TopoDS::Edge(edge), TopoDS::Face(face));
else
mkChamfer.Add(radius1, radius2, TopoDS::Edge(edge), TopoDS::Face(face));
if (!op) {
op = Part::OpCodes::Chamfer;
}
return makEShape(mkChamfer,shape,op);
if (shape.isNull()) {
FC_THROWM(NullShapeException, "Null shape");
}
if (edges.empty()) {
FC_THROWM(NullShapeException, "Null input shape");
}
BRepFilletAPI_MakeChamfer mkChamfer(shape.getShape());
for (auto& e : edges) {
const auto& edge = e.getShape();
if (e.isNull()) {
FC_THROWM(NullShapeException, "Null input shape");
}
if (!shape.findShape(edge)) {
FC_THROWM(Base::CADKernelError, "edge does not belong to the shape");
}
// Add edge to fillet algorithm
TopoDS_Shape face;
if (flipDirection == Flip::flip) {
face = shape.findAncestorsShapes(edge, TopAbs_FACE).back();
}
else {
face = shape.findAncestorShape(edge, TopAbs_FACE);
}
if (asAngle == AsAngle::yes) {
mkChamfer.AddDA(radius1, radius2, TopoDS::Edge(edge), TopoDS::Face(face));
}
else {
mkChamfer.Add(radius1, radius2, TopoDS::Edge(edge), TopoDS::Face(face));
}
}
return makeElementShape(mkChamfer, shape, op);
}
TopoShape& TopoShape::makeElementGeneralFuse(const std::vector<TopoShape>& _shapes,