This commit is contained in:
Michael Fogleman 2018-02-28 15:09:07 -05:00
parent c3ca0b65bc
commit 6a3ab49cbe
3 changed files with 34 additions and 10 deletions

View File

@ -20,6 +20,13 @@ from .planner import Planner
from .turtle import Turtle from .turtle import Turtle
from .util import draw, reset from .util import draw, reset
from .drawing import (
V3_SIZE,
V3_BOUNDS,
A3_SIZE,
A3_BOUNDS,
)
from .hershey import text, justify_text from .hershey import text, justify_text
from .hershey_fonts import ( from .hershey_fonts import (
ASTROLOGY, ASTROLOGY,

View File

@ -10,7 +10,7 @@ from .paths import path_length
from .planner import Planner from .planner import Planner
from .progress import Bar from .progress import Bar
TIMESLICE_MS = 20 TIMESLICE_MS = 10
MICROSTEPPING_MODE = 2 MICROSTEPPING_MODE = 2
STEP_DIVIDER = 2 ** (MICROSTEPPING_MODE - 1) STEP_DIVIDER = 2 ** (MICROSTEPPING_MODE - 1)
@ -22,16 +22,16 @@ PEN_UP_POSITION = 60
PEN_UP_SPEED = 150 PEN_UP_SPEED = 150
PEN_UP_DELAY = 0 PEN_UP_DELAY = 0
PEN_DOWN_POSITION = 45 PEN_DOWN_POSITION = 40
PEN_DOWN_SPEED = 150 PEN_DOWN_SPEED = 150
PEN_DOWN_DELAY = 0 PEN_DOWN_DELAY = 0
ACCELERATION = 6 ACCELERATION = 8
MAX_VELOCITY = 1 MAX_VELOCITY = 3
CORNER_FACTOR = 0.005*3 CORNER_FACTOR = 0.005
JOG_ACCELERATION = 8 JOG_ACCELERATION = 16
JOG_MAX_VELOCITY = 5 JOG_MAX_VELOCITY = 8
VID_PID = '04D8:FD92' VID_PID = '04D8:FD92'
@ -105,7 +105,7 @@ class Device(object):
def move(self, dx, dy): def move(self, dx, dy):
self.run_path([(0, 0), (dx, dy)]) self.run_path([(0, 0), (dx, dy)])
def goto(self, x, y, jog=False): def goto(self, x, y, jog=True):
# TODO: jog if pen up # TODO: jog if pen up
px, py = self.read_position() px, py = self.read_position()
self.run_path([(px, py), (x, y)], jog) self.run_path([(px, py), (x, y)], jog)

View File

@ -11,6 +11,12 @@ try:
except ImportError: except ImportError:
cairo = None cairo = None
V3_SIZE = (12, 8.5)
V3_BOUNDS = (0, 0, 12, 8.5)
A3_SIZE = (16.93, 11.69)
A3_BOUNDS = (0, 0, 16.93, 11.69)
class Drawing(object): class Drawing(object):
def __init__(self, paths=None): def __init__(self, paths=None):
self.paths = paths or [] self.paths = paths or []
@ -125,6 +131,10 @@ class Drawing(object):
x1, y1, x2, y2 = self.bounds x1, y1, x2, y2 = self.bounds
return y2 - y1 return y2 - y1
@property
def size(self):
return (self.width, self.height)
@property @property
def all_paths(self): def all_paths(self):
result = [] result = []
@ -234,10 +244,12 @@ class Drawing(object):
return Drawing(paths) return Drawing(paths)
def render(self, scale=109, margin=1, line_width=0.5/25.4, def render(self, scale=109, margin=1, line_width=0.5/25.4,
use_axi_bounds=True, show_axi_bounds=True): bounds=None, show_bounds=True,
use_axi_bounds=False, show_axi_bounds=False):
if cairo is None: if cairo is None:
raise Exception('Drawing.render() requires cairo') raise Exception('Drawing.render() requires cairo')
x1, y1, x2, y2 = self.bounds bounds = bounds or self.bounds
x1, y1, x2, y2 = bounds
if use_axi_bounds: if use_axi_bounds:
x1, y1, x2, y2 = (0, 0, 12, 8.5) x1, y1, x2, y2 = (0, 0, 12, 8.5)
w = x2 - x1 w = x2 - x1
@ -259,6 +271,11 @@ class Drawing(object):
dc.set_line_width(1 / scale) dc.set_line_width(1 / scale)
dc.rectangle(0, 0, 12, 8.5) dc.rectangle(0, 0, 12, 8.5)
dc.stroke() dc.stroke()
if show_bounds:
dc.set_source_rgb(0.5, 0.5, 0.5)
dc.set_line_width(1 / scale)
dc.rectangle(*bounds)
dc.stroke()
dc.set_source_rgb(0, 0, 0) dc.set_source_rgb(0, 0, 0)
dc.set_line_width(line_width) dc.set_line_width(line_width)
for path in self.paths: for path in self.paths: