Skip to content

Commit 3ec113e

Browse files
committed
Terminology Shift.
header=document_start footer=document_end firstsegment=segment_first lastsegment=segment_last prelayer=layer_start postlayer=layer_end layerjoin=layer_join preline=linecollection_start postline=linecollection_end linejoin=linecollection_join
1 parent 2949595 commit 3ec113e

3 files changed

Lines changed: 60 additions & 62 deletions

File tree

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setup(
88
name="vpype-gcode",
9-
version="0.5.0",
9+
version="0.6.0",
1010
description="vpype gcode plugin",
1111
long_description=readme,
1212
long_description_content_type="text/markdown",

vpype_gcode/bundled_configs.toml

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,50 @@
11
[gwrite.ninja]
2-
header = "G20\nG17\nG90\n"
3-
firstsegment = "M380\nG00 X{x:.4f} Y{y:.4f}\nM381\n"
2+
document_start = "G20\nG17\nG90\n"
3+
segment_first = "M380\nG00 X{x:.4f} Y{y:.4f}\nM381\n"
44
segment = "G01 X{x:.4f} Y{y:.4f}\n"
5-
footer = "M2\n"
5+
document_end = "M2\n"
66
unit = "mm"
77

88
[gwrite.gcode]
9-
header = "G20\nG17\nG90\n"
10-
firstsegment = "G00 X{x:.4f} Y{y:.4f}\n"
9+
document_start = "G20\nG17\nG90\n"
10+
segment_first = "G00 X{x:.4f} Y{y:.4f}\n"
1111
segment = "G01 X{x:.4f} Y{y:.4f}\n"
12-
footer = "M2\n"
12+
document_end = "M2\n"
1313
unit = "mm"
1414

1515
[gwrite.gcode_relative]
16-
header = "G20\nG17\nG91\n"
17-
firstsegment = "G00 X{dx:.4f} Y{dy:.4f}\n"
16+
document_start = "G20\nG17\nG91\n"
17+
segment_first = "G00 X{dx:.4f} Y{dy:.4f}\n"
1818
segment = "G01 X{dx:.4f} Y{dy:.4f}\n"
19-
footer = "M2\n"
19+
document_end = "M2\n"
2020
unit = "mm"
2121

2222
[gwrite.csv]
23-
header = "#Operation, X-value, Y-value\n"
24-
firstsegment = "Move, {x:f}, {x:f}\n"
23+
document_start = "#Operation, X-value, Y-value\n"
24+
segment_first = "Move, {x:f}, {x:f}\n"
2525
segment = "Line-to, {x:f}, {x:f}\n"
26-
lastsegment = "Stop, {x:f}, {x:f}\n"
26+
segment_last = "Stop, {x:f}, {x:f}\n"
2727

2828
[gwrite.json]
29-
header = "{{"
30-
footer = "}}\n"
31-
linejoin = ","
32-
layerjoin = ","
33-
prelayer = "\n\t\"Layer\": {{"
34-
postlayer = "\t}}\n"
35-
preline = "\n\t\t\"LineCollection{index:d}\": [\n"
36-
postline = "\n\t\t]"
29+
document_start = "{{"
30+
document_end = "}}\n"
31+
linecollection_join = ","
32+
layer_join = ","
33+
layer_start = "\n\t\"Layer\": {{"
34+
layer_end = "\t}}\n"
35+
linecollection_start = "\n\t\t\"LineCollection{index:d}\": [\n"
36+
linecollection_end = "\n\t\t]"
3737
segment = "\t\t{{\n\t\t\t\"X\": {ix:d},\n\t\t\t\"Y\": {iy:d}\n\t\t}},\n"
38-
lastsegment = "\t\t{{\n\t\t\t\"X\": {ix:d},\n\t\t\t\"Y\": {iy:d}\n\t\t}}"
39-
40-
38+
segment_last = "\t\t{{\n\t\t\t\"X\": {ix:d},\n\t\t\t\"Y\": {iy:d}\n\t\t}}"
4139

4240
[gwrite.isvg]
43-
header = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
41+
document_start = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
4442
<svg xmlns="http://www.w3.org/2000/svg" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xlink="http://www.w3.org/1999/xlink">
4543
"""
46-
footer = "</svg>"
47-
prelayer = '<g fill="none" stroke="black">'
48-
preline = '<path d="M '
49-
firstsegment = "{ix:d} {iy:d} l"
44+
document_end = "</svg>"
45+
layer_start = '<g fill="none" stroke="black">'
46+
linecollection_start = '<path d="M '
47+
segment_first = "{ix:d} {iy:d} l"
5048
segment = "{idx:d} {idy:d} "
51-
postline = '"/>'
52-
postlayer = "</g>"
49+
linecollection_end = '"/>'
50+
layer_end = "</g>"

vpype_gcode/gwrite.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,17 @@ def gwrite(document: vp.Document, filename: str, profile: str):
7474

7575
# Read the config for the profile from the main vpype
7676
config = gwrite_config[profile]
77-
header = config.get("header", None)
78-
firstsegment = config.get("firstsegment", None)
77+
document_start = config.get("document_start", None)
78+
document_end = config.get("document_end", None)
79+
layer_start = config.get("layer_start", None)
80+
layer_end = config.get("layer_end", None)
81+
layer_join = config.get("layer_join", None)
82+
linecollection_start = config.get("linecollection_start", None)
83+
linecollection_end = config.get("linecollection_end", None)
84+
linecollection_join = config.get("linecollection_join", None)
85+
segment_first = config.get("segment_first", None)
7986
segment = config.get("segment", None)
80-
lastsegment = config.get("lastsegment", None)
81-
prelayer = config.get("prelayer", None)
82-
postlayer = config.get("postlayer", None)
83-
layerjoin = config.get("layerjoin", None)
84-
preline = config.get("preline", None)
85-
postline = config.get("postline", None)
86-
linejoin = config.get("linejoin", None)
87-
footer = config.get("footer", None)
87+
segment_last = config.get("segment_last", None)
8888
unit = config.get("unit", "mm")
8989

9090
invert_x = config.get("invert_x", False)
@@ -96,22 +96,22 @@ def gwrite(document: vp.Document, filename: str, profile: str):
9696
document = invert_axis(document, invert_x, invert_y)
9797

9898
with open(filename, "w") as f:
99-
if header is not None:
100-
f.write(header.format(filename=filename))
99+
if document_start is not None:
100+
f.write(document_start.format(filename=filename))
101101
last_x = 0
102102
last_y = 0
103103
xx = 0
104104
yy = 0
105105
lastlayer_index = len(document.layers.values()) - 1
106106
for layer_index, layer in enumerate(document.layers.values()):
107-
if prelayer is not None:
108-
f.write(prelayer.format(index=layer_index))
107+
if layer_start is not None:
108+
f.write(layer_start.format(index=layer_index))
109109
lastlines_index = len(layer) - 1
110110
for lines_index, lines in enumerate(layer):
111111
lines_scaled = lines * scale
112-
if preline is not None:
113-
f.write(preline.format(index=lines_index))
114-
lastsegment_index = len(lines_scaled) - 1
112+
if linecollection_start is not None:
113+
f.write(linecollection_start.format(index=lines_index))
114+
segment_last_index = len(lines_scaled) - 1
115115
for segment_index, seg in enumerate(lines_scaled):
116116
x = seg.real
117117
y = seg.imag
@@ -121,10 +121,10 @@ def gwrite(document: vp.Document, filename: str, profile: str):
121121
idy = int(round(y - yy))
122122
xx += idx
123123
yy += idy
124-
if firstsegment is not None and segment_index == 0:
125-
seg_write = firstsegment
126-
elif lastsegment is not None and segment_index == lastsegment_index:
127-
seg_write = lastsegment
124+
if segment_first is not None and segment_index == 0:
125+
seg_write = segment_first
126+
elif segment_last is not None and segment_index == segment_last_index:
127+
seg_write = segment_last
128128
else:
129129
seg_write = segment
130130
f.write(
@@ -146,16 +146,16 @@ def gwrite(document: vp.Document, filename: str, profile: str):
146146
)
147147
last_x = x
148148
last_y = y
149-
if postline is not None:
150-
f.write(postline.format(index=lines_index))
151-
if linejoin is not None and lines_index != lastlines_index:
152-
f.write(linejoin)
153-
if postlayer is not None:
154-
f.write(postlayer.format(index=layer_index))
155-
if layerjoin is not None and layer_index != lastlayer_index:
156-
f.write(layerjoin)
157-
if footer is not None:
158-
f.write(footer.format(filename=filename))
149+
if linecollection_end is not None:
150+
f.write(linecollection_end.format(index=lines_index))
151+
if linecollection_join is not None and lines_index != lastlines_index:
152+
f.write(linecollection_join)
153+
if layer_end is not None:
154+
f.write(layer_end.format(index=layer_index))
155+
if layer_join is not None and layer_index != lastlayer_index:
156+
f.write(layer_join)
157+
if document_end is not None:
158+
f.write(document_end.format(filename=filename))
159159

160160
return document
161161

0 commit comments

Comments
 (0)