Part/Toponaming: Refactor to eliminate boolean blindness
This commit is contained in:
@@ -616,15 +616,21 @@ public:
|
||||
void mapSubElementsTo(std::vector<TopoShape> &shapes, const char *op=nullptr) const;
|
||||
bool hasPendingElementMap() const;
|
||||
|
||||
/**
|
||||
* When given a single shape to create a compound, two results are possible: either to simply
|
||||
* return the shape as given, or to force it to be placed in a Compound.
|
||||
*/
|
||||
enum class SingleShapeCompoundCreationPolicy {
|
||||
RETURN_SHAPE,
|
||||
FORCE_COMPOUND
|
||||
};
|
||||
|
||||
/** Make a compound shape
|
||||
*
|
||||
* @param shapes: input shapes
|
||||
* @param op: optional string to be encoded into topo naming for indicating
|
||||
* the operation
|
||||
* @param force: if true and there is only one input shape, then return
|
||||
* that shape instead. If false, then always return a
|
||||
* compound, even if there is no input shape.
|
||||
* @param policy: set behavior when only a single shape is given
|
||||
*
|
||||
* @return The original content of this TopoShape is discarded and replaced
|
||||
* with the new shape. The function returns the TopoShape itself as
|
||||
@@ -633,7 +639,7 @@ public:
|
||||
*/
|
||||
TopoShape& makeElementCompound(const std::vector<TopoShape>& shapes,
|
||||
const char* op = nullptr,
|
||||
bool force = true);
|
||||
SingleShapeCompoundCreationPolicy policy = SingleShapeCompoundCreationPolicy::FORCE_COMPOUND);
|
||||
|
||||
|
||||
enum class ConnectionPolicy {
|
||||
@@ -666,7 +672,7 @@ public:
|
||||
TopoShape& makeElementWires(const std::vector<TopoShape>& shapes,
|
||||
const char* op = nullptr,
|
||||
double tol = 0.0,
|
||||
bool shared = false,
|
||||
ConnectionPolicy policy = ConnectionPolicy::MERGE_WITH_TOLERANCE,
|
||||
TopoShapeMap* output = nullptr);
|
||||
|
||||
|
||||
@@ -743,10 +749,10 @@ public:
|
||||
*/
|
||||
TopoShape makeElementWires(const char* op = nullptr,
|
||||
double tol = 0.0,
|
||||
bool shared = false,
|
||||
ConnectionPolicy policy = ConnectionPolicy::MERGE_WITH_TOLERANCE,
|
||||
TopoShapeMap* output = nullptr) const
|
||||
{
|
||||
return TopoShape(0, Hasher).makeElementWires(*this, op, tol, shared, output);
|
||||
return TopoShape(0, Hasher).makeElementWires(*this, op, tol, policy, output);
|
||||
}
|
||||
|
||||
friend class TopoShapeCache;
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
#include <math.h>
|
||||
#include <cmath>
|
||||
|
||||
#include <BRep_Builder.hxx>
|
||||
#include <BRep_Tool.hxx>
|
||||
@@ -533,9 +533,11 @@ void addShapesToBuilder(const std::vector<TopoShape>& shapes,
|
||||
} // namespace
|
||||
|
||||
TopoShape&
|
||||
TopoShape::makeElementCompound(const std::vector<TopoShape>& shapes, const char* op, bool force)
|
||||
TopoShape::makeElementCompound(const std::vector<TopoShape>& shapes,
|
||||
const char* op,
|
||||
SingleShapeCompoundCreationPolicy policy)
|
||||
{
|
||||
if (!force && shapes.size() == 1) {
|
||||
if (policy == SingleShapeCompoundCreationPolicy::RETURN_SHAPE && shapes.size() == 1) {
|
||||
*this = shapes[0];
|
||||
return *this;
|
||||
}
|
||||
@@ -559,23 +561,23 @@ TopoShape::makeElementCompound(const std::vector<TopoShape>& shapes, const char*
|
||||
TopoShape& TopoShape::makeElementWires(const std::vector<TopoShape>& shapes,
|
||||
const char* op,
|
||||
double tol,
|
||||
bool shared,
|
||||
ConnectionPolicy policy,
|
||||
TopoShapeMap* output)
|
||||
{
|
||||
if (shapes.empty()) {
|
||||
FC_THROWM(NullShapeException, "Null shape");
|
||||
}
|
||||
if (shapes.size() == 1) {
|
||||
return makeElementWires(shapes[0], op, tol, shared, output);
|
||||
return makeElementWires(shapes[0], op, tol, policy, output);
|
||||
}
|
||||
return makeElementWires(TopoShape(Tag).makeElementCompound(shapes), op, tol, shared, output);
|
||||
return makeElementWires(TopoShape(Tag).makeElementCompound(shapes), op, tol, policy, output);
|
||||
}
|
||||
|
||||
|
||||
TopoShape& TopoShape::makeElementWires(const TopoShape& shape,
|
||||
const char* op,
|
||||
double tol,
|
||||
bool shared,
|
||||
ConnectionPolicy policy,
|
||||
TopoShapeMap* output)
|
||||
{
|
||||
if (!op) {
|
||||
@@ -585,7 +587,7 @@ TopoShape& TopoShape::makeElementWires(const TopoShape& shape,
|
||||
tol = Precision::Confusion();
|
||||
}
|
||||
|
||||
if (shared) {
|
||||
if (policy == ConnectionPolicy::REQUIRE_SHARED_VERTEX) {
|
||||
// Can't use ShapeAnalysis_FreeBounds if not shared. It seems the output
|
||||
// edges are modified somehow, and it is not obvious how to map the
|
||||
// resulting edges.
|
||||
@@ -605,10 +607,10 @@ TopoShape& TopoShape::makeElementWires(const TopoShape& shape,
|
||||
std::vector<TopoShape> wires;
|
||||
for (int i = 1; i <= hWires->Length(); i++) {
|
||||
auto wire = hWires->Value(i);
|
||||
wires.push_back(TopoShape(Tag, Hasher, wire));
|
||||
wires.emplace_back(Tag, Hasher, wire);
|
||||
}
|
||||
shape.mapSubElementsTo(wires, op);
|
||||
return makeElementCompound(wires, "", false);
|
||||
return makeElementCompound(wires, "", SingleShapeCompoundCreationPolicy::RETURN_SHAPE);
|
||||
}
|
||||
|
||||
std::vector<TopoShape> wires;
|
||||
@@ -666,7 +668,7 @@ TopoShape& TopoShape::makeElementWires(const TopoShape& shape,
|
||||
wires.back().mapSubElement(edges, op);
|
||||
wires.back().fix();
|
||||
}
|
||||
return makeElementCompound(wires, nullptr, false);
|
||||
return makeElementCompound(wires, nullptr, SingleShapeCompoundCreationPolicy::RETURN_SHAPE);
|
||||
}
|
||||
|
||||
|
||||
@@ -833,7 +835,7 @@ TopoShape& TopoShape::makeElementOrderedWires(const std::vector<TopoShape>& shap
|
||||
std::vector<TopoShape> wires;
|
||||
std::list<TopoShape> edgeList;
|
||||
|
||||
auto shape = TopoShape().makeElementCompound(shapes, "", false);
|
||||
auto shape = TopoShape().makeElementCompound(shapes, "", SingleShapeCompoundCreationPolicy::RETURN_SHAPE);
|
||||
for (auto& edge : shape.getSubTopoShapes(TopAbs_EDGE)) {
|
||||
edgeList.push_back(edge);
|
||||
}
|
||||
@@ -855,7 +857,7 @@ TopoShape& TopoShape::makeElementOrderedWires(const std::vector<TopoShape>& shap
|
||||
wires.emplace_back(mkWire.Wire());
|
||||
wires.back().mapSubElement(edges, op);
|
||||
}
|
||||
return makeElementCompound(wires, nullptr, false);
|
||||
return makeElementCompound(wires, nullptr, SingleShapeCompoundCreationPolicy::RETURN_SHAPE);
|
||||
}
|
||||
|
||||
} // namespace Part
|
||||
|
||||
Reference in New Issue
Block a user