Skip to content

Commit

Permalink
Part/Toposhape: Add located and moved methods
Browse files Browse the repository at this point in the history
  • Loading branch information
chennes committed Nov 20, 2023
1 parent c1f4147 commit 7b48d77
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 11 deletions.
16 changes: 8 additions & 8 deletions src/Mod/Part/App/TopoShape.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
79 changes: 76 additions & 3 deletions src/Mod/Part/App/TopoShapeExpansion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

}

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

Check warning on line 118 in src/Mod/Part/App/TopoShapeExpansion.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Could not find a newline character at the end of the file. [whitespace/ending_newline] [5]

0 comments on commit 7b48d77

Please sign in to comment.