From c177728f0d7a5baafe4d8f95bc8e31370db5bb04 Mon Sep 17 00:00:00 2001 From: caleb crome Date: Fri, 26 May 2023 10:34:24 -0700 Subject: [PATCH] Moved 'drawPoints' from gears.py and pulley.py into Boxes main class This move makes it easier to use Cartesian points directly. I tested both the gearbox and rotary generators (with default settings) to ensure that they both still work. --- boxes/__init__.py | 19 +++++++++++++++++++ boxes/gears.py | 24 +++--------------------- boxes/pulley.py | 14 +------------- 3 files changed, 23 insertions(+), 34 deletions(-) diff --git a/boxes/__init__.py b/boxes/__init__.py index 77c45ce..8d8a6db 100755 --- a/boxes/__init__.py +++ b/boxes/__init__.py @@ -39,6 +39,7 @@ from boxes import parts from boxes import pulley from boxes import svgutil from boxes.Color import * +from boxes.vectors import kerf import qrcode from boxes.qrcode_factory import BoxesQrCodeFactory @@ -1560,6 +1561,24 @@ class Boxes: y * 0.5 * holedistance, 0.5 * diameter) + def drawPoints(self, lines, kerfdir=1, close=True): + + if not lines: + return + + if kerfdir != 0: + lines = kerf(lines, self.burn*kerfdir, closed=close) + + self.ctx.save() + self.ctx.move_to(*lines[0]) + + for x, y in lines[1:]: + self.ctx.line_to(x, y) + + if close: + self.ctx.line_to(*lines[0]) + self.ctx.restore() + def qrcode(self, content, box_size=1.0, color=Color.ETCHING, move=None): q = qrcode.QRCode(image_factory=BoxesQrCodeFactory, box_size=box_size*10) q.add_data(content) diff --git a/boxes/gears.py b/boxes/gears.py index 0162b02..5228b19 100644 --- a/boxes/gears.py +++ b/boxes/gears.py @@ -385,24 +385,6 @@ class Gears(): dest="undercut_alert", default=False, help="Let the user confirm a warning dialog if undercut occurs. This dialog also shows helpful hints against undercut") - def drawPoints(self, lines, kerfdir=1, close=True): - - if not lines: - return - - if kerfdir != 0: - lines = kerf(lines, self.boxes.burn*kerfdir, closed=close) - - self.boxes.ctx.save() - self.boxes.ctx.move_to(*lines[0]) - - for x, y in lines[1:]: - self.boxes.ctx.line_to(x, y) - - if close: - self.boxes.ctx.line_to(*lines[0]) - self.boxes.ctx.restore() - def calc_circular_pitch(self): """We use math based on circular pitch.""" dimension = self.options.dimension @@ -628,8 +610,8 @@ class Gears(): self.boxes.moveTo(width/2.0, base_height+addendum, -180) if base_height < 0: points = points[1:-1] - self.drawPoints(points, close=base_height >= 0) - self.drawPoints(guide_points, kerfdir=0) + self.boxes.drawPoints(points, close=base_height >= 0) + self.boxes.drawPoints(guide_points, kerfdir=0) self.boxes.move(width, height, move) return @@ -660,7 +642,7 @@ class Gears(): if not teeth_only: self.boxes.moveTo(width/2, height/2) self.boxes.cc(callback, None, 0, 0) - self.drawPoints(points) + self.boxes.drawPoints(points) # Spokes if not teeth_only and not self.options.internal_ring: # only draw internals if spur gear msg = self.generate_spokes(root_radius, spoke_width, spoke_count, mount_radius, mount_hole, diff --git a/boxes/pulley.py b/boxes/pulley.py index 113ed47..c13f7d9 100644 --- a/boxes/pulley.py +++ b/boxes/pulley.py @@ -86,18 +86,6 @@ class Pulley: def getProfiles(cls): return list(sorted(cls.teeth.keys())) - def drawPoints(self, lines, kerfdir=1): - if kerfdir != 0: - lines = kerf(lines, self.boxes.burn * kerfdir) - self.boxes.ctx.save() - self.boxes.ctx.move_to(*lines[0]) - - for x, y in lines[1:]: - self.boxes.ctx.line_to(x, y) - - self.boxes.ctx.line_to(*lines[0]) - self.boxes.ctx.restore() - def diameter(self, teeth, profile): if self.spacing[profile][0]: return tooth_spaceing_curvefit(teeth, *self.spacing[profile][1:]) @@ -149,5 +137,5 @@ class Pulley: m = mmul(m, rotm(i * 2 * pi / teeth)) points.extend(vtransl(pt, m) for pt in self.teeth[profile][1:-1]) - self.drawPoints(points, kerfdir=-1 if insideout else 1) + self.boxes.drawPoints(points, kerfdir=-1 if insideout else 1) self.boxes.move(total_width, total_width, move)