Merge branch 'main' into bgbsww-toponamingMakeElementSliceMirror

This commit is contained in:
bgbsww
2024-02-23 10:37:47 -05:00
committed by GitHub
3 changed files with 131 additions and 0 deletions

View File

@@ -1844,6 +1844,46 @@ public:
CN,
};
/** Make a solid using shells or CompSolid
*
* @param shapes: input shapes of either shells or CompSolid.
* @param op: optional string to be encoded into topo naming for indicating
* the operation
*
* @return The function produces a solid. The original content of this
* TopoShape is discarded and replaced with the new shape. The
* function returns the TopoShape itself as a self reference so
* that multiple operations can be carried out for the same shape
* in the same line of code.
*/
// TODO: This does not appear to be called, and the implementation seems impossible
// TopoShape &makeElementSolid(const std::vector<TopoShape> &shapes, const char *op=nullptr);
/** Make a solid using shells or CompSolid
*
* @param shape: input shape of either a shell, a compound of shells, or a
* CompSolid.
* @param op: optional string to be encoded into topo naming for indicating
* the operation
*
* @return The function produces a solid. The original content of this
* TopoShape is discarded and replaced with the new shape. The
* function returns the TopoShape itself as a self reference so
* that multiple operations can be carried out for the same shape
* in the same line of code.
*/
TopoShape &makeElementSolid(const TopoShape &shape, const char *op=nullptr);
/** Make a solid using this shape
*
* @param op: optional string to be encoded into topo naming for indicating
* the operation
*
* @return The function returns a new solid using the shell or CompSolid
* inside this shape. The shape itself is not modified.
*/
TopoShape makeElementSolid(const char *op=nullptr) const {
return TopoShape(0,Hasher).makeElementSolid(*this,op);
}
/** Generic shape making with mapped element name from shape history
*

View File

@@ -51,6 +51,7 @@
#include <BRepBuilderAPI_GTransform.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_Transform.hxx>
#include <BRepBuilderAPI_MakeSolid.hxx>
#include <BRepFilletAPI_MakeChamfer.hxx>
#include <BRepFilletAPI_MakeFillet.hxx>
#include <BRepBuilderAPI_Transform.hxx>
@@ -2702,6 +2703,69 @@ struct MapperThruSections: MapperMaker
}
};
// TODO: This method does not appear to ever be called in the codebase, and it is probably
// broken, because using TopoShape() with no parameters means the result will not have an
// element Map. If ever restored, code like this should be used to make a tag.
//TopoShape& TopoShape::makeElementSolid(const std::vector<TopoShape>& shapes, const char* op)
//{
// static std::random_device _RD;
// static std::mt19937 _RGEN(_RD());
// static std::uniform_int_distribution<> _RDIST(1, 10000);
// long idx = _RDIST(_RGEN);
// return makeElementSolid(TopoShape(idx).makeElementCompound(shapes), op);
//}
TopoShape& TopoShape::makeElementSolid(const TopoShape& shape, const char* op)
{
if (!op) {
op = Part::OpCodes::Solid;
}
if (shape.isNull()) {
FC_THROWM(NullShapeException, "Null shape");
}
// first, if we were given a compsolid, try making a solid out of it
TopoDS_CompSolid compsolid;
int count = 0;
for (const auto& s : shape.getSubShapes(TopAbs_COMPSOLID)) {
++count;
compsolid = TopoDS::CompSolid(s);
if (count > 1) {
break;
}
}
if (count == 0) {
// no compsolids. Get shells...
BRepBuilderAPI_MakeSolid mkSolid;
count = 0;
for (const auto& s : shape.getSubShapes(TopAbs_SHELL)) {
++count;
mkSolid.Add(TopoDS::Shell(s));
}
if (count == 0) { // no shells?
FC_THROWM(Base::CADKernelError, "No shells or compsolids found in shape");
}
makeElementShape(mkSolid, shape, op);
TopoDS_Solid solid = TopoDS::Solid(_Shape);
BRepLib::OrientClosedSolid(solid);
setShape(solid, false);
}
else if (count == 1) {
BRepBuilderAPI_MakeSolid mkSolid(compsolid);
makeElementShape(mkSolid, shape, op);
}
else { // if (count > 1)
FC_THROWM(Base::CADKernelError,
"Only one compsolid can be accepted. "
"Provided shape has more than one compsolid.");
}
return *this;
}
TopoShape& TopoShape::makeElementMirror(const TopoShape& shape, const gp_Ax2& ax2, const char* op)
{
if (!op) {