From 7b48d77cd9305026b4ce8088a98190e9790e8bf1 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Mon, 20 Nov 2023 10:09:41 -0600 Subject: [PATCH] Part/Toposhape: Add located and moved methods --- src/Mod/Part/App/TopoShape.h | 16 ++--- src/Mod/Part/App/TopoShapeExpansion.cpp | 79 ++++++++++++++++++++++++- 2 files changed, 84 insertions(+), 11 deletions(-) diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h index 775396f1bc2eb..644d8258a8532 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -389,14 +389,14 @@ class PartExport TopoShape : public Data::ComplexGeoData return ret; } - static TopoDS_Shape &move(TopoDS_Shape &s, const TopLoc_Location &); - static TopoDS_Shape moved(const TopoDS_Shape &s, const TopLoc_Location &); - static TopoDS_Shape &move(TopoDS_Shape &s, const gp_Trsf &); - static TopoDS_Shape moved(const TopoDS_Shape &s, const gp_Trsf &); - static TopoDS_Shape &locate(TopoDS_Shape &s, const TopLoc_Location &loc); - static TopoDS_Shape located(const TopoDS_Shape &s, const TopLoc_Location &); - static TopoDS_Shape &locate(TopoDS_Shape &s, const gp_Trsf &); - static TopoDS_Shape located(const TopoDS_Shape &s, const gp_Trsf &); + static TopoDS_Shape& move(TopoDS_Shape& tds, const TopLoc_Location& loc); + static TopoDS_Shape moved(const TopoDS_Shape& tds, const TopLoc_Location& loc); + static TopoDS_Shape& move(TopoDS_Shape& tds, const gp_Trsf& transfer); + static TopoDS_Shape moved(const TopoDS_Shape& tds, const gp_Trsf& transfer); + static TopoDS_Shape& locate(TopoDS_Shape& tds, const TopLoc_Location& loc); + static TopoDS_Shape located(const TopoDS_Shape& tds, const TopLoc_Location& loc); + static TopoDS_Shape& locate(TopoDS_Shape& tds, const gp_Trsf& transfer); + static TopoDS_Shape located(const TopoDS_Shape& tds, const gp_Trsf& transfer); TopoShape &makeGTransform(const TopoShape &shape, const Base::Matrix4D &mat, const char *op=nullptr, bool copy=false); diff --git a/src/Mod/Part/App/TopoShapeExpansion.cpp b/src/Mod/Part/App/TopoShapeExpansion.cpp index c5d3794a462d1..ff6b278ad8571 100644 --- a/src/Mod/Part/App/TopoShapeExpansion.cpp +++ b/src/Mod/Part/App/TopoShapeExpansion.cpp @@ -32,14 +32,87 @@ void TopoShape::setShape(const TopoDS_Shape& shape, bool resetElementMap) { if (resetElementMap) { this->resetElementMap(); - } else if (_cache && _cache->isTouched(shape)) { + } + else if (_cache && _cache->isTouched(shape)) { this->flushElementMap(); } - //_Shape._Shape = shape; // TODO: Replace the next line with this once ShapeProtector is available. + //_Shape._Shape = shape; // TODO: Replace the next line with this once ShapeProtector is + //available. _Shape = shape; if (_cache) { initCache(); } } -} \ No newline at end of file + +TopoDS_Shape& TopoShape::move(TopoDS_Shape& tds, const TopLoc_Location& loc) +{ +#if OCC_VERSION_HEX < 0x070600 + tds.Move(loc); +#else + tds.Move(loc, false); +#endif + return tds; +} + +TopoDS_Shape TopoShape::moved(const TopoDS_Shape& tds, const TopLoc_Location& loc) +{ +#if OCC_VERSION_HEX < 0x070600 + return tds.Moved(loc); +#else + return tds.Moved(loc, false); +#endif +} + +TopoDS_Shape& TopoShape::move(TopoDS_Shape& tds, const gp_Trsf& transfer) +{ +#if OCC_VERSION_HEX < 0x070600 + static constexpr double scalePrecision{1e-14}; + if (std::abs(transfer.ScaleFactor()) > scalePrecision) +#else + if (std::abs(transfer.ScaleFactor()) > TopLoc_Location::ScalePrec()) +#endif + { + auto transferCopy(transfer); + transferCopy.SetScaleFactor(1.0); + tds.Move(transferCopy); + } + else { + tds.Move(transfer); + } + return tds; +} + +TopoDS_Shape TopoShape::moved(const TopoDS_Shape& tds, const gp_Trsf& transfer) +{ + TopoDS_Shape sCopy(tds); + return move(sCopy, transfer); +} + +TopoDS_Shape& TopoShape::locate(TopoDS_Shape& tds, const TopLoc_Location& loc) +{ + tds.Location(TopLoc_Location()); + return move(tds, loc); +} + +TopoDS_Shape TopoShape::located(const TopoDS_Shape& tds, const TopLoc_Location& loc) +{ + auto sCopy(tds); + sCopy.Location(TopLoc_Location()); + return moved(sCopy, loc); +} + +TopoDS_Shape& TopoShape::locate(TopoDS_Shape& tds, const gp_Trsf& transfer) +{ + tds.Location(TopLoc_Location()); + return move(tds, transfer); +} + +TopoDS_Shape TopoShape::located(const TopoDS_Shape& tds, const gp_Trsf& transfer) +{ + auto sCopy(tds); + sCopy.Location(TopLoc_Location()); + return moved(sCopy, transfer); +} + +} // namespace Part \ No newline at end of file