support svg's with negative coordinates

This commit is contained in:
Hendrik Schutter 2022-06-14 22:00:17 +02:00
parent 29ab5ee5d0
commit 27b790180a
5 changed files with 9444 additions and 112 deletions

View File

@ -11,3 +11,16 @@ Based on the vector to gcode implementation from [Vishal Patil](https://github.c
# Usage
`clear && cat test_data/10mmx10mm.svg | python3 svg2gcode.py > test_data/test.gcode`
## Fix for Pronterface
`nano /usr/lib64/python3.8/site-packages/printrun/gl/libtatlin/actors.py`
replace content in lines 442 to 447 with:
```
prev_move_normal_x = 0
prev_move_normal_y = 0
prev_move_angle = 0
prev_pos = (0, 0, 0)
prev_gline = None
layer_idx = 0
```

View File

@ -20,7 +20,7 @@ def gcode_write(gcode_file, gcode):
gcode_file.write(gcode)
def close_on_failure():
os.remove(gcode_file_path)
os.remove(conf.gcode_file_path)
sys.exit(1)
def laserpower_to_pwm(percent):
@ -72,8 +72,11 @@ def generate_gcode(svg_file_root_tree, gcode_file):
points = point_generator(obj_path, obj_trans_matrix, conf.smoothness)
num_points = 0
for x,y in points:
x = abs(x)
y = abs(y)
if (debug): print("[Point] X: " + str(x) + " Y: " + str(y))
if x > 0 and x < conf.bedsizex and y > 0 and y < conf.bedsizey:
if x < conf.bedsizex and y < conf.bedsizey:
gcode_write(gcode_file, "G1 X%0.001f Y%0.001f\n" % (x, y))
num_points += 1
if (num_points == 1):
@ -83,6 +86,7 @@ def generate_gcode(svg_file_root_tree, gcode_file):
print("\n; Coordinates out of range:", "G1 X%0.01f Y%0.01f" % (x, y))
print("; Raw:", str(x), str(y), "\nScaled:", str(x), str(y), "\n")
close_on_failure()
gcode_write(gcode_file, "M5 ;stop laser\n")
gcode_write(gcode_file, "; == End of " + tag_suffix + " ==\n")
generated_points_count += num_points

View File

@ -1,8 +0,0 @@
<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="61.2mm" height="31.200000000000006mm" viewBox="0 0 61.2 31.200000000000006" xmlns="http://www.w3.org/2000/svg" version="1.1">
<g id="Sketch" transform="translate(30.600000,30.600000) scale(1,-1)">
<path id="Sketch_w0000" d="M -30.0 0.0 L 30.0 0.0 A 60 60 0 0 1 21.9615 30L -30.0 0.0 " stroke="#000000" stroke-width="0.35 px" style="stroke-width:0.35;stroke-miterlimit:4;stroke-dasharray:none;fill:none;fill-opacity:1;fill-rule: evenodd"/>
<title>b'Sketch'</title>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 609 B

View File

@ -2,52 +2,20 @@
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="100mm"
height="100mm"
viewBox="0 0 100 100"
width="54.875031mm"
height="8.0408278mm"
viewBox="0 0 54.875031 8.0408278"
version="1.1"
id="svg5"
inkscape:version="1.2 (dc2aedaf03, 2022-05-15)"
sodipodi:docname="Test_H.svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cc="http://creativecommons.org/ns#">
<sodipodi:namedview
id="namedview7"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="mm"
showgrid="false"
inkscape:zoom="1.7492917"
inkscape:cx="166.06721"
inkscape:cy="244.67046"
inkscape:window-width="1920"
inkscape:window-height="1011"
inkscape:window-x="1680"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="text221"
showguides="false">
<sodipodi:guide
position="30.40159,95.916204"
orientation="0,-1"
id="guide20"
inkscape:locked="false" />
</sodipodi:namedview>
<defs
id="defs2" />
<g
inkscape:label="Ebene 1"
inkscape:groupmode="layer"
id="layer1">
id="layer1"
transform="translate(-42.962838,-5.5320735)">
<g
aria-label="H"
id="text115"
@ -57,32 +25,53 @@
id="text221"
style="font-size:10.5833px;stroke-width:0.0700042"
transform="matrix(1,0,0,-1,0,87.650687)">
<g
aria-label="Hallo Jacob"
transform="matrix(1,0,0,-1,2.1478405,-1.3889376)"
id="text1639"
style="stroke-width:0.0185219">
<path
d="m 34.367619,26.146512 v 9.507547 h -9.491125 v -9.507547 h -2.495623 v 20.569076 h 2.495623 v -8.843573 h 9.491125 v 8.843573 h 2.482692 V 26.146512 Z"
id="path172"
style="stroke-width:0.183092" />
d="m 45.605388,-75.570076 v -3.477813 H 41.81235 v 3.477813 h -0.997352 v -7.524065 h 0.997352 v 3.234935 h 3.793038 v -3.234935 h 0.992185 v 7.524065 z"
id="path794" />
<path
d="m 49.548248,26.146512 q -0.232759,0.550959 -0.336199,1.610493 -0.672395,-0.776993 -1.680989,-1.342077 -1.008594,-0.550956 -2.301663,-0.550956 -2.146494,0 -3.439562,1.31382 -1.293069,1.313821 -1.293069,3.220982 0,2.458117 1.706851,3.729556 1.706849,1.285567 4.590394,1.285567 h 2.366316 v 1.214932 q 0,1.356203 -0.749981,2.161449 -0.737048,0.819371 -2.198216,0.819371 -1.357723,0 -2.198218,-0.734608 -0.827564,-0.720483 -0.827564,-1.681127 H 40.79417 q 0,1.638745 1.512893,3.079711 1.512889,1.440965 4.047305,1.440965 2.2758,0 3.736969,-1.271441 1.461168,-1.271439 1.461168,-3.842573 v -6.865778 q 0,-2.119066 0.491366,-3.362252 v -0.226028 z m -3.969722,2.00605 q 1.293069,0 2.23701,0.706355 0.95687,0.706357 1.344791,1.568111 v 3.150346 h -2.224079 q -4.034376,-0.08477 -4.034376,-2.825424 0,-1.087787 0.672397,-1.850651 0.672397,-0.748737 2.004257,-0.748737 z"
id="path174"
style="stroke-width:0.183092" />
d="m 51.672182,-75.570076 q -0.09302,-0.201537 -0.134358,-0.589109 -0.268716,0.284219 -0.671791,0.490924 -0.403075,0.201538 -0.919838,0.201538 -0.857826,0 -1.374589,-0.48059 -0.516762,-0.480589 -0.516762,-1.178219 0,-0.899167 0.682126,-1.364253 0.682127,-0.470254 1.834508,-0.470254 h 0.945676 v -0.444416 q 0,-0.496092 -0.299723,-0.790647 -0.294554,-0.299722 -0.878496,-0.299722 -0.542601,0 -0.878497,0.268716 -0.330728,0.263549 -0.330728,0.614948 h -0.956011 q 0,-0.599445 0.604612,-1.126543 0.604613,-0.527098 1.617468,-0.527098 0.909502,0 1.493444,0.465087 0.583942,0.465086 0.583942,1.405594 v 2.511467 q 0,0.775144 0.196369,1.229895 v 0.08268 z m -1.586461,-0.733803 q 0.516763,0 0.893999,-0.258381 0.382405,-0.258382 0.537434,-0.573607 v -1.152381 h -0.888832 q -1.6123,0.03101 -1.6123,1.033526 0,0.397907 0.268717,0.676959 0.268716,0.273884 0.800982,0.273884 z"
id="path796" />
<path
d="M 57.914403,47.845757 V 26.146512 h -2.405109 v 21.699245 z"
id="path176"
style="stroke-width:0.183092" />
d="m 55.015637,-83.507551 v 7.937475 h -0.961179 v -7.937475 z"
id="path798" />
<path
d="M 64.353885,47.845757 V 26.146512 h -2.405106 v 21.699245 z"
id="path178"
style="stroke-width:0.183092" />
d="m 57.589115,-83.507551 v 7.937475 h -0.961178 v -7.937475 z"
id="path800" />
<path
d="m 67.560698,33.944678 q 0,3.319871 1.706851,5.537829 1.706852,2.232083 4.642118,2.232083 2.935265,0 4.642117,-2.189701 1.706851,-2.175577 1.745644,-5.43894 v -0.466193 q 0,-3.319873 -1.719784,-5.537829 -1.706849,-2.217955 -4.642117,-2.217955 -2.948195,0 -4.667978,2.217955 -1.706851,2.217956 -1.706851,5.537829 z m 2.392177,-0.324922 q 0,-2.274465 0.982733,-3.941465 0.995663,-1.666999 2.999919,-1.666999 1.952535,0 2.948198,1.638746 0.995664,1.652871 1.008594,3.927336 v 0.367304 q 0,2.246212 -0.995663,3.927337 -0.995662,1.695252 -2.986989,1.695252 -1.978396,0 -2.974059,-1.695252 -0.982733,-1.681125 -0.982733,-3.927337 z"
id="path180"
style="stroke-width:0.183092" />
d="m 58.870687,-78.422606 q 0,-1.214392 0.682127,-2.02571 0.682127,-0.816485 1.855178,-0.816485 1.173051,0 1.855178,0.800982 0.682127,0.795815 0.69763,1.989537 v 0.170531 q 0,1.214393 -0.687295,2.02571 -0.682126,0.811318 -1.855178,0.811318 -1.178219,0 -1.865513,-0.811318 -0.682127,-0.811317 -0.682127,-2.02571 z m 0.956011,0.118855 q 0,0.831988 0.39274,1.441768 0.397907,0.60978 1.198889,0.60978 0.780312,0 1.178219,-0.599444 0.397907,-0.604613 0.403075,-1.436601 v -0.134358 q 0,-0.821653 -0.397907,-1.4366 -0.397907,-0.620115 -1.193722,-0.620115 -0.790647,0 -1.188554,0.620115 -0.39274,0.614947 -0.39274,1.4366 z"
id="path802" />
<path
d="m 71.086957,-83.094141 h 0.992184 v 5.327824 q 0,1.116207 -0.671792,1.710484 -0.666623,0.58911 -1.700149,0.58911 -1.038693,0 -1.710484,-0.537434 -0.666624,-0.537433 -0.666624,-1.648473 h 0.997352 q 0,0.713133 0.382404,1.043861 0.387572,0.330728 0.997352,0.330728 0.58911,0 0.981849,-0.377237 0.397908,-0.377236 0.397908,-1.111039 z"
id="path804" />
<path
d="m 77.076236,-75.570076 q -0.09302,-0.201537 -0.134358,-0.589109 -0.268717,0.284219 -0.671792,0.490924 -0.403075,0.201538 -0.919837,0.201538 -0.857826,0 -1.374589,-0.48059 -0.516763,-0.480589 -0.516763,-1.178219 0,-0.899167 0.682127,-1.364253 0.682127,-0.470254 1.834508,-0.470254 h 0.945675 v -0.444416 q 0,-0.496092 -0.299722,-0.790647 -0.294555,-0.299722 -0.878497,-0.299722 -0.5426,0 -0.878496,0.268716 -0.330728,0.263549 -0.330728,0.614948 h -0.956011 q 0,-0.599445 0.604612,-1.126543 0.604612,-0.527098 1.617467,-0.527098 0.909503,0 1.493444,0.465087 0.583942,0.465086 0.583942,1.405594 v 2.511467 q 0,0.775144 0.19637,1.229895 v 0.08268 z m -1.586461,-0.733803 q 0.516762,0 0.893999,-0.258381 0.382405,-0.258382 0.537433,-0.573607 v -1.152381 h -0.888831 q -1.6123,0.03101 -1.6123,1.033526 0,0.397907 0.268717,0.676959 0.268716,0.273884 0.800982,0.273884 z"
id="path806" />
<path
d="m 81.618581,-76.252203 q 0.511595,0 0.893999,-0.30489 0.387572,-0.30489 0.423745,-0.780311 h 0.909503 q -0.03617,0.749306 -0.687295,1.312577 -0.651121,0.558104 -1.539952,0.558104 -1.260901,0 -1.875849,-0.831988 -0.60978,-0.831988 -0.60978,-1.958531 v -0.21704 q 0,-1.126543 0.60978,-1.958531 0.614948,-0.831988 1.875849,-0.831988 0.981849,0 1.586461,0.583942 0.604612,0.578774 0.640786,1.441768 h -0.909503 q -0.03617,-0.516763 -0.392739,-0.878497 -0.351399,-0.361733 -0.925005,-0.361733 -0.58911,0 -0.925006,0.299722 -0.330728,0.299722 -0.470254,0.759641 -0.134358,0.459919 -0.134358,0.945676 v 0.21704 q 0,0.490925 0.134358,0.950843 0.134359,0.459919 0.465087,0.759642 0.335896,0.294554 0.930173,0.294554 z"
id="path808" />
<path
d="m 84.66748,-78.422606 q 0,-1.214392 0.682127,-2.02571 0.682127,-0.816485 1.855178,-0.816485 1.173051,0 1.855178,0.800982 0.682127,0.795815 0.69763,1.989537 v 0.170531 q 0,1.214393 -0.687295,2.02571 -0.682126,0.811318 -1.855178,0.811318 -1.178219,0 -1.865513,-0.811318 -0.682127,-0.811317 -0.682127,-2.02571 z m 0.956011,0.118855 q 0,0.831988 0.39274,1.441768 0.397907,0.60978 1.198889,0.60978 0.780312,0 1.178219,-0.599444 0.397907,-0.604613 0.403075,-1.436601 v -0.134358 q 0,-0.821653 -0.397907,-1.4366 -0.397908,-0.620115 -1.193722,-0.620115 -0.790647,0 -1.188554,0.620115 -0.39274,0.614947 -0.39274,1.4366 z"
id="path810" />
<path
d="m 95.69003,-78.303751 q 0,1.224728 -0.568439,2.030878 -0.568439,0.80615 -1.607132,0.80615 -1.059364,0 -1.63297,-0.749306 l -0.05168,0.645953 h -0.878496 v -7.937475 h 0.961178 v 2.950715 q 0.568439,-0.707965 1.591629,-0.707965 1.054196,0 1.617468,0.78548 0.568439,0.785479 0.568439,2.06705 z m -2.423617,-2.1549 q -0.521931,0 -0.847491,0.253214 -0.325561,0.248046 -0.506428,0.614947 v 2.433953 q 0.186035,0.372069 0.516763,0.625282 0.330728,0.253214 0.847491,0.253214 0.775144,0 1.11104,-0.594277 0.341063,-0.599445 0.341063,-1.431433 v -0.10852 q 0,-0.831988 -0.325561,-1.4366 -0.320392,-0.60978 -1.136877,-0.60978 z"
id="path812" />
</g>
</g>
</g>
</g>
<metadata
id="metadata59">
<rdf:RDF>
<cc:Work
rdf:about="">
<cc:license
rdf:resource="http://artlibre.org/licence/lal" />
</cc:Work>
<cc:License
rdf:about="http://artlibre.org/licence/lal">
<cc:permits
@ -98,11 +87,6 @@
<cc:requires
rdf:resource="http://creativecommons.org/ns#Attribution" />
</cc:License>
<cc:Work
rdf:about="">
<cc:license
rdf:resource="http://artlibre.org/licence/lal" />
</cc:Work>
</rdf:RDF>
</metadata>
</svg>

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 7.2 KiB

File diff suppressed because it is too large Load Diff