Skip to content

Commit

Permalink
Moved 'drawPoints' from gears.py and pulley.py into Boxes main class
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ccrome authored and florianfesti committed May 26, 2023
1 parent 7459e13 commit c177728
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 34 deletions.
19 changes: 19 additions & 0 deletions boxes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
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
Expand Down Expand Up @@ -1560,6 +1561,24 @@ def NEMA(self, size, x=0, y=0, angle=0, screwholes=None):
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)
Expand Down
24 changes: 3 additions & 21 deletions boxes/gears.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,24 +385,6 @@ def __init__(self, boxes, **kw) -> None:
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
Expand Down Expand Up @@ -628,8 +610,8 @@ def __call__(self, teeth_only=False, move="", callback=None, **kw):
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
Expand Down Expand Up @@ -660,7 +642,7 @@ def __call__(self, teeth_only=False, move="", callback=None, **kw):
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,
Expand Down
14 changes: 1 addition & 13 deletions boxes/pulley.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,6 @@ def __init__(self, boxes) -> None:
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:])
Expand Down Expand Up @@ -149,5 +137,5 @@ def __call__(self, teeth, profile, insideout=False, r_axle=None,
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)

0 comments on commit c177728

Please sign in to comment.