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.
This commit is contained in:
parent
7459e133b2
commit
c177728f0d
|
@ -39,6 +39,7 @@ from boxes import parts
|
||||||
from boxes import pulley
|
from boxes import pulley
|
||||||
from boxes import svgutil
|
from boxes import svgutil
|
||||||
from boxes.Color import *
|
from boxes.Color import *
|
||||||
|
from boxes.vectors import kerf
|
||||||
|
|
||||||
import qrcode
|
import qrcode
|
||||||
from boxes.qrcode_factory import BoxesQrCodeFactory
|
from boxes.qrcode_factory import BoxesQrCodeFactory
|
||||||
|
@ -1560,6 +1561,24 @@ class Boxes:
|
||||||
y * 0.5 * holedistance,
|
y * 0.5 * holedistance,
|
||||||
0.5 * diameter)
|
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):
|
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 = qrcode.QRCode(image_factory=BoxesQrCodeFactory, box_size=box_size*10)
|
||||||
q.add_data(content)
|
q.add_data(content)
|
||||||
|
|
|
@ -385,24 +385,6 @@ class Gears():
|
||||||
dest="undercut_alert", default=False,
|
dest="undercut_alert", default=False,
|
||||||
help="Let the user confirm a warning dialog if undercut occurs. This dialog also shows helpful hints against undercut")
|
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):
|
def calc_circular_pitch(self):
|
||||||
"""We use math based on circular pitch."""
|
"""We use math based on circular pitch."""
|
||||||
dimension = self.options.dimension
|
dimension = self.options.dimension
|
||||||
|
@ -628,8 +610,8 @@ class Gears():
|
||||||
self.boxes.moveTo(width/2.0, base_height+addendum, -180)
|
self.boxes.moveTo(width/2.0, base_height+addendum, -180)
|
||||||
if base_height < 0:
|
if base_height < 0:
|
||||||
points = points[1:-1]
|
points = points[1:-1]
|
||||||
self.drawPoints(points, close=base_height >= 0)
|
self.boxes.drawPoints(points, close=base_height >= 0)
|
||||||
self.drawPoints(guide_points, kerfdir=0)
|
self.boxes.drawPoints(guide_points, kerfdir=0)
|
||||||
self.boxes.move(width, height, move)
|
self.boxes.move(width, height, move)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -660,7 +642,7 @@ class Gears():
|
||||||
if not teeth_only:
|
if not teeth_only:
|
||||||
self.boxes.moveTo(width/2, height/2)
|
self.boxes.moveTo(width/2, height/2)
|
||||||
self.boxes.cc(callback, None, 0, 0)
|
self.boxes.cc(callback, None, 0, 0)
|
||||||
self.drawPoints(points)
|
self.boxes.drawPoints(points)
|
||||||
# Spokes
|
# Spokes
|
||||||
if not teeth_only and not self.options.internal_ring: # only draw internals if spur gear
|
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,
|
msg = self.generate_spokes(root_radius, spoke_width, spoke_count, mount_radius, mount_hole,
|
||||||
|
|
|
@ -86,18 +86,6 @@ class Pulley:
|
||||||
def getProfiles(cls):
|
def getProfiles(cls):
|
||||||
return list(sorted(cls.teeth.keys()))
|
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):
|
def diameter(self, teeth, profile):
|
||||||
if self.spacing[profile][0]:
|
if self.spacing[profile][0]:
|
||||||
return tooth_spaceing_curvefit(teeth, *self.spacing[profile][1:])
|
return tooth_spaceing_curvefit(teeth, *self.spacing[profile][1:])
|
||||||
|
@ -149,5 +137,5 @@ class Pulley:
|
||||||
m = mmul(m, rotm(i * 2 * pi / teeth))
|
m = mmul(m, rotm(i * 2 * pi / teeth))
|
||||||
points.extend(vtransl(pt, m) for pt in self.teeth[profile][1:-1])
|
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)
|
self.boxes.move(total_width, total_width, move)
|
||||||
|
|
Loading…
Reference in New Issue