Skip to content

Commit 05901e3

Browse files
committed
inkscape integration
1 parent c31422f commit 05901e3

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

gcodeplot.inx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@
4141
<item value="center">center</item>
4242
<item value="top">right</item>
4343
</param>
44-
<param name="boolean-extract-color" type="boolean" _gui-text="Extract one color from drawing" _gui-description="If enabled, only paths in the selected color are drawn.">0</param>
45-
<param name="extract-color" type="color" _gui-text="Color to extract from drawing" _gui-description="If extract option is active, this selects the color to extract.">#000000</param>
44+
<param name="extract-color" type="string" _gui-text="Extract one color from drawing" _gui-description="Put 'all' or leave blank to include all colors, red=#FF0000, green=#00FF00, blue=#0000FF."></param>
4645
</page>
4746
<page name="drawing" _gui-text="Drawing Settings">
4847
<param name="shading-threshold" type="float" min="0" max="1" precision="2" _gui-text="Shading threshold:" _gui-description="Shade whenever the shade is below this value, where 0=black and 1=white. To turn off shading, set to 0. (Default: 1, shade everything other than white).">1</param>

gcodeplot.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ def penColor(pens, pen):
299299
return (0.,0.,0.)
300300

301301
def emitGcode(data, pens = {}, plotter=Plotter(), scalingMode=SCALE_NONE, align = None, tolerance=0, gcodePause="@pause", pauseAtStart = False, simulation = False):
302+
if len(data) == 0:
303+
return None
304+
302305
xyMin = [float("inf"),float("inf")]
303306
xyMax = [float("-inf"),float("-inf")]
304307

@@ -322,7 +325,6 @@ def emitGcode(data, pens = {}, plotter=Plotter(), scalingMode=SCALE_NONE, align
322325
return None
323326
elif scalingMode != SCALE_DOWN_ONLY or not allFit:
324327
if xyMin[0] > xyMax[0]:
325-
sys.stderr.write("No points.\n")
326328
return None
327329
scale = Scale()
328330
scale.fit(plotter, xyMin, xyMax)
@@ -436,12 +438,13 @@ def flip(y):
436438

437439
park()
438440

439-
sys.stderr.write('Estimated printing time: %dm %.1fs\n' % (state.time // 60, state.time % 60))
440-
sys.stderr.flush()
441-
442441
if simulation:
443442
gcode.append('</svg>')
444443

444+
if not quiet:
445+
sys.stderr.write('Estimated printing time: %dm %.1fs\n' % (state.time // 60, state.time % 60))
446+
sys.stderr.flush()
447+
445448
return gcode
446449

447450
def parseHPGL(hpgl,dpi=(1016.,1016.)):
@@ -587,9 +590,13 @@ def getConfigOpts(filename):
587590

588591
if __name__ == '__main__':
589592

590-
def help():
591-
sys.stdout.write("gcodeplot.py [options] [inputfile [> output.gcode]\n")
592-
sys.stdout.write("""
593+
def help(error=False):
594+
if error:
595+
output = sys.stderr
596+
else:
597+
output = sys.stdout
598+
output.write("gcodeplot.py [options] [inputfile [> output.gcode]\n")
599+
output.write("""
593600
--dump-options: show current settings instead of doing anything
594601
-h|--help: this
595602
-r|--allow-repeats*: do not deduplicate paths
@@ -653,17 +660,18 @@ def help():
653660
overcut = 0.
654661
toolMode = "custom"
655662
booleanExtractColor = False
663+
quiet = False
656664

657665
try:
658666
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:",
659667
["help", "down", "up", "lower-left", "allow-repeats", "no-allow-repeats", "scale=", "config-file=",
660668
"area=", 'align-x=', 'align-y=', 'optimization-time=', "pens=",
661-
'input-dpi=', 'tolerance=', 'send=', 'send-speed=', 'pen-down-z=', 'pen-up-z=', 'parking-z=',
669+
'input-dpi=', 'tolerance=', 'send=', 'send-speed=', 'work-z=', 'lift-delta-z=', 'safe-delta-z=',
662670
'pen-down-speed=', 'pen-up-speed=', 'z-speed=', 'hpgl-out', 'no-hpgl-out', 'shading-threshold=',
663671
'shading-angle=', 'shading-crosshatch', 'no-shading-crosshatch', 'shading-avoid-outline',
664672
'pause-at-start', 'no-pause-at-start', 'min-x=', 'max-x=', 'min-y=', 'max-y=',
665673
'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=',
666-
'boolean-shading-crosshatch=', 'boolean-extract-color=', 'boolean-sort=' ], )
674+
'boolean-shading-crosshatch=', 'boolean-sort=', 'tool-mode=' ], )
667675

668676
if len(args) + len(opts) == 0:
669677
raise getopt.GetoptError("invalid commandline")
@@ -772,11 +780,9 @@ def help():
772780
elif opt in ('-A', '--shading-angle'):
773781
shader.angle = float(arg)
774782
elif opt == '--boolean-shading-crosshatch':
775-
shader.crossHatch = int(arg) != 0
776-
elif opt == '--boolean-extract-color':
777-
booleanExtractColor = int(arg) != 0
783+
shader.crossHatch = arg.strip() != 'false'
778784
elif opt == '--boolean-sort':
779-
sort = int(arg) != 0
785+
sort = arg.strip() != 'false'
780786
elif opt in ('-X', '--shading-crosshatch'):
781787
shader.crossHatch = True
782788
elif opt == '--no-shading-crosshatch':
@@ -809,7 +815,7 @@ def help():
809815
doDump = True
810816
elif opt in ('R', '--extract-color'):
811817
arg = arg.lower()
812-
if arg == 'all':
818+
if arg == 'all' or len(arg.strip())==0:
813819
extractColor = None
814820
else:
815821
extractColor = parser.rgbFromColor(arg)
@@ -823,15 +829,16 @@ def help():
823829
elif opt == '--no-simulation':
824830
svgSimulation = False
825831
elif opt == '--tab':
826-
pass # Inkscape
832+
quiet = True # Inkscape
827833
elif opt == "--tool-mode":
828834
toolMode = arg
829835
else:
830836
raise ValueError("Unrecognized argument "+opt)
831837
i += 1
832838

833-
except getopt.GetoptError:
834-
help()
839+
except getopt.GetoptError as e:
840+
sys.stderr.write(str(e)+"\n")
841+
help(error=True)
835842
sys.exit(2)
836843

837844
if doDump:
@@ -942,7 +949,7 @@ def help():
942949
else:
943950
penData = parseHPGL(data, dpi=dpi)
944951
penData = removePenBob(penData)
945-
952+
946953
if doDedup:
947954
penData = dedup(penData)
948955

@@ -955,7 +962,7 @@ def help():
955962

956963
if optimizationTime > 0.:
957964
for pen in penData:
958-
penData[pen] = anneal.optimize(penData[pen], timeout=optimizationTime/2.)
965+
penData[pen] = anneal.optimize(penData[pen], timeout=optimizationTime/2., quiet=quiet)
959966
penData = removePenBob(penData)
960967

961968
if sortPaths:

0 commit comments

Comments
 (0)