From e1e8e038ed7d347bc08ff9c723f5e96a00b9950b Mon Sep 17 00:00:00 2001 From: hyOzd Date: Sun, 19 Jul 2015 15:44:22 +0300 Subject: [PATCH] added autoSimplify() and enabled it for union() method --- cadquery/CQ.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/cadquery/CQ.py b/cadquery/CQ.py index 77ebc51..ff939ec 100644 --- a/cadquery/CQ.py +++ b/cadquery/CQ.py @@ -38,6 +38,8 @@ class CQContext(object): self.firstPoint = None self.tolerance = 0.0001 # user specified tolerance + # call `simplify()` automatically for related operations + self.autoSimplifyEnabled = True class CQ(object): """ @@ -2037,11 +2039,14 @@ class Workplane(CQ): # look for parents to cut from solidRef = self.findSolid(searchStack=True, searchParents=True) if combine and solidRef is not None: - t = solidRef.fuse(newS) + r = solidRef.fuse(newS) solidRef.wrapped = newS.wrapped - return self.newObject([t]) else: - return self.newObject([newS]) + r = newS + + if self.ctx.autoSimplifyEnabled: r = r.simplify() + + return self.newObject([r]) def cut(self, toCut, combine=True): """ @@ -2363,3 +2368,15 @@ class Workplane(CQ): return self.newObject([t]) else: raise ValueError("There is no solid to simplify!") + + def autoSimplify(self, enabled=True): + """ + Enables/Disables calling of `simplify()` operation automatically. + + Using `autoSimplify(False)` to disable this feature can + improve run time of some operations substantially but may also + break some other solid operations. See `simplify()` for more + info. + """ + self.ctx.autoSimplifyEnabled = bool(enabled) + return self