Toposhape/Part: Clean and test replacEShape and removEShape

This commit is contained in:
bgbsww
2024-02-24 16:59:45 -05:00
parent b5af3d38c3
commit 4e1c37cd6e
3 changed files with 115 additions and 41 deletions

View File

@@ -1040,8 +1040,9 @@ public:
const char* op = nullptr,
double tol3d = 0.0,
double tolBound = 0.0,
double tolAngluar = 0.0);
/* Make a shape with some subshapes replaced
double tolAngular = 0.0);
/* Make a shape with some subshapes replaced.
*
* @param source: the source shape
* @param s: replacement mapping the existing sub shape of source to new shapes
@@ -1051,15 +1052,17 @@ public:
* a self reference so that multiple operations can be carried out
* for the same shape in the same line of code.
*/
TopoShape &replacEShape(const TopoShape &source, const std::vector<std::pair<TopoShape,TopoShape> > &s);
TopoShape& replaceElementShape(const TopoShape& source,
const std::vector<std::pair<TopoShape, TopoShape>>& s);
/* Make a new shape using this shape with some subshapes replaced by others
*
* @param s: replacement mapping the existing sub shape of source to new shapes
*
* @return Return the new shape. The TopoShape itself is not modified.
*/
TopoShape replacEShape(const std::vector<std::pair<TopoShape,TopoShape> > &s) const {
return TopoShape(0,Hasher).replacEShape(*this,s);
TopoShape replaceElementShape(const std::vector<std::pair<TopoShape, TopoShape>>& s) const
{
return TopoShape(0, Hasher).replaceElementShape(*this, s);
}
/* Make a shape with some subshapes removed
@@ -1072,18 +1075,18 @@ public:
* a self reference so that multiple operations can be carried out
* for the same shape in the same line of code.
*/
TopoShape &removEShape(const TopoShape &source, const std::vector<TopoShape>& s);
TopoShape& removeElementShape(const TopoShape& source, const std::vector<TopoShape>& s);
/* Make a new shape using this shape with some subshapes removed
*
* @param s: the subshapes to be removed
*
* @return Return the new shape. The TopoShape itself is not modified.
*/
TopoShape removEShape(const std::vector<TopoShape>& s) const {
return TopoShape(0,Hasher).removEShape(*this,s);
TopoShape removeElementShape(const std::vector<TopoShape>& s) const
{
return TopoShape(0, Hasher).removeElementShape(*this, s);
}
/** Make shape using generalized fusion and return the modified sub shapes
*
* @param sources: the source shapes

View File

@@ -3108,34 +3108,41 @@ TopoShape& TopoShape::makeElementSlices(const TopoShape& shape,
return makeElementCompound(wires, op, SingleShapeCompoundCreationPolicy::returnShape);
}
TopoShape &TopoShape::replacEShape(const TopoShape &shape,
const std::vector<std::pair<TopoShape,TopoShape> > &s)
TopoShape& TopoShape::replaceElementShape(const TopoShape& shape,
const std::vector<std::pair<TopoShape, TopoShape>>& s)
{
if(shape.isNull())
HANDLE_NULL_SHAPE;
if (shape.isNull()) {
FC_THROWM(NullShapeException, "Null shape");
}
BRepTools_ReShape reshape;
std::vector<TopoShape> shapes;
shapes.reserve(s.size()+1);
for (auto &v : s) {
if(v.first.isNull() || v.second.isNull())
HANDLE_NULL_INPUT;
shapes.reserve(s.size() + 1);
for (auto& v : s) {
if (v.first.isNull() || v.second.isNull()) {
FC_THROWM(NullShapeException, "Null input shape");
}
reshape.Replace(v.first.getShape(), v.second.getShape());
shapes.push_back(v.second);
}
// TODO: This does not work when replacing a shape in a compound. Should we replace with
// something else?
// Note that remove works with a compound.
shapes.push_back(shape);
setShape(reshape.Apply(shape.getShape(),TopAbs_SHAPE));
setShape(reshape.Apply(shape.getShape(), TopAbs_SHAPE));
mapSubElement(shapes);
return *this;
}
TopoShape &TopoShape::removEShape(const TopoShape &shape, const std::vector<TopoShape>& s)
TopoShape& TopoShape::removeElementShape(const TopoShape& shape, const std::vector<TopoShape>& s)
{
if(shape.isNull())
HANDLE_NULL_SHAPE;
if (shape.isNull()) {
FC_THROWM(NullShapeException, "Null shape");
}
BRepTools_ReShape reshape;
for(auto &sh : s) {
if(sh.isNull())
HANDLE_NULL_INPUT;
for (auto& sh : s) {
if (sh.isNull()) {
FC_THROWM(NullShapeException, "Null input shape");
}
reshape.Remove(sh.getShape());
}
setShape(reshape.Apply(shape.getShape(), TopAbs_SHAPE));