Skip to content

Commit f4f4796

Browse files
committed
begin directional drawing support
1 parent 2383091 commit f4f4796

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

gcodeplot.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -670,17 +670,18 @@ def help(error=False):
670670
booleanExtractColor = False
671671
quiet = False
672672
sendAndSave = False
673+
directionAngle = None
673674

674675
try:
675-
opts, args = getopt.getopt(sys.argv[1:], "UR:Uhdulw:P:o:Oc:LT:M:m:A:XHrf:na:D:t:s:S:x:y:z:Z:p:f:F:",
676+
opts, args = getopt.getopt(sys.argv[1:], "e:UR:Uhdulw:P:o:Oc:LT:M:m:A:XHrf:na:D:t:s:S:x:y:z:Z:p:f:F:",
676677
["help", "down", "up", "lower-left", "allow-repeats", "no-allow-repeats", "scale=", "config-file=",
677678
"area=", 'align-x=', 'align-y=', 'optimization-time=', "pens=",
678679
'input-dpi=', 'tolerance=', 'send=', 'send-speed=', 'work-z=', 'lift-delta-z=', 'safe-delta-z=',
679680
'pen-down-speed=', 'pen-up-speed=', 'z-speed=', 'hpgl-out', 'no-hpgl-out', 'shading-threshold=',
680681
'shading-angle=', 'shading-crosshatch', 'no-shading-crosshatch', 'shading-avoid-outline',
681682
'pause-at-start', 'no-pause-at-start', 'min-x=', 'max-x=', 'min-y=', 'max-y=',
682683
'no-shading-avoid-outline', 'shading-darkest=', 'shading-lightest=', 'stroke-all', 'no-stroke-all', 'gcode-pause', 'dump-options', 'tab=', 'extract-color=', 'sort', 'no-sort', 'simulation', 'no-simulation', 'tool-offset=', 'overcut=',
683-
'boolean-shading-crosshatch=', 'boolean-sort=', 'tool-mode=', 'send-and-save=' ], )
684+
'boolean-shading-crosshatch=', 'boolean-sort=', 'tool-mode=', 'send-and-save=', 'direction=' ], )
684685

685686
if len(args) + len(opts) == 0:
686687
raise getopt.GetoptError("invalid commandline")
@@ -826,13 +827,13 @@ def help(error=False):
826827
sys.exit(0)
827828
elif opt == '--dump-options':
828829
doDump = True
829-
elif opt in ('R', '--extract-color'):
830+
elif opt in ('-R', '--extract-color'):
830831
arg = arg.lower()
831832
if arg == 'all' or len(arg.strip())==0:
832833
extractColor = None
833834
else:
834835
extractColor = parser.rgbFromColor(arg)
835-
elif opt in ('d', '--sort'):
836+
elif opt in ('-d', '--sort'):
836837
sortPaths = True
837838
optimizationTime = 0
838839
elif opt == '--no-sort':
@@ -845,6 +846,11 @@ def help(error=False):
845846
quiet = True # Inkscape
846847
elif opt == "--tool-mode":
847848
toolMode = arg
849+
elif opt in ('e', '--direction'):
850+
if len(arg.strip()) == 0 or arg == 'none':
851+
directionAngle = None
852+
else:
853+
directionAngle = float(arg)
848854
else:
849855
raise ValueError("Unrecognized argument "+opt)
850856
i += 1
@@ -956,7 +962,8 @@ def help(error=False):
956962
if svgTree is None and 'PD' not in data and 'PU' not in data:
957963
sys.stderr.write("Unrecognized file.\n")
958964
exit(1)
959-
965+
966+
shader.setDrawingDirectionAngle(directionAngle)
960967
if svgTree is not None:
961968
penData = parseSVG(svgTree, tolerance=tolerance, shader=shader, strokeAll=strokeAll, pens=pens, extractColor=extractColor)
962969
else:

svgpath/shader.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,23 @@ def __init__(self, unshadedThreshold=1., lightestSpacing=3., darkestSpacing=0.5,
1010
self.lightestSpacing = lightestSpacing
1111
self.darkestSpacing = darkestSpacing
1212
self.angle = angle
13+
self.secondaryAngle = angle + 90
1314
self.crossHatch = False
1415

1516
def isActive(self):
1617
return self.unshadedThreshold > 0.000001
1718

19+
def setDrawingDirectionAngle(self, drawingDirectionAngle):
20+
self.drawingDirectionAngle = drawingDirectionAngle
21+
22+
if drawingDirectionAngle is None:
23+
return
24+
25+
if 90 < (self.angle - drawingDirectionAngle) % 360 < 270:
26+
self.angle = (self.angle + 180) % 360
27+
if 90 < (self.secondaryAngle - drawingDirectionAngle) % 360 < 270:
28+
self.secondaryAngle = (self.secondaryAngle + 180) % 360
29+
1830
def shade(self, polygon, grayscale, avoidOutline=True, mode=None):
1931
if mode is None:
2032
mode = Shader.MODE_EVEN_ODD
@@ -24,11 +36,11 @@ def shade(self, polygon, grayscale, avoidOutline=True, mode=None):
2436
spacing = self.lightestSpacing * (1-intensity) + self.darkestSpacing * intensity
2537
lines = Shader.shadePolygon(polygon, self.angle, spacing, avoidOutline=avoidOutline, mode=mode)
2638
if self.crossHatch:
27-
lines += Shader.shadePolygon(polygon, self.angle+90, spacing, avoidOutline=avoidOutline, mode=mode)
39+
lines += Shader.shadePolygon(polygon, self.angle+90, spacing, avoidOutline=avoidOutline, mode=mode, alternate=(self.drawingDirectionAngle==None))
2840
return lines
2941

3042
@staticmethod
31-
def shadePolygon(polygon, angleDegrees, spacing, avoidOutline=True, mode=None):
43+
def shadePolygon(polygon, angleDegrees, spacing, avoidOutline=True, mode=None, alternate=True):
3244
if mode is None:
3345
mode = Shader.MODE_EVEN_ODD
3446

@@ -102,7 +114,7 @@ def shadePolygon(polygon, angleDegrees, spacing, avoidOutline=True, mode=None):
102114
else:
103115
raise ValueError()
104116

105-
if odd:
117+
if odd and alternate:
106118
thisLine = list(reversed([(l[1],l[0]) for l in thisLine]))
107119

108120
if not avoidOutline and len(thisLine) and len(all) and all[-1][1][2] == thisLine[0][0][2]:

0 commit comments

Comments
 (0)