Skip to content

Commit e98e26d

Browse files
authored
Merge pull request #20 from plottertools/xy-lines-layers
x, y, ix, and iy for layer_start, line_start, line_end, layer_end
2 parents 414e78b + b3bf907 commit e98e26d

File tree

3 files changed

+109
-12
lines changed

3 files changed

+109
-12
lines changed

README.md

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ G4 P0.5\n"""
6767
document_end = """M5
6868
G00 X0.0000 Y0.0000
6969
M2"""
70+
invert_y = "True"
7071
```
7172

7273
You can use the following options inside a profile. You only need to provide the options where you need to change the default. If you want a newline character in an option, you can either use escape sequences (`\n`) or you use TOML multi line strings wrapped in `""""`.
@@ -98,13 +99,33 @@ All of the options below default to an empty text which means no output is gener
9899

99100
### Segment formatting
100101
`gwrite` uses `.format()` encoding which means that data elements must be encapsulated in `{}` brackets. This provides a particular syntax token which differs from between elements.
101-
For example every element except `layer_join` and `segment_join` accepts the value of `index`. You would encode that in the text as `{index:d}` the d denotes an integer value. If you need to have a `{` value in your text you would encode that as `{{` likewise you would encode a `}` as `}}`.
102-
- `layer_start`: Accepts `index` the current layer index starting from 0, `index1` the current layer number starting from 1, and `layer_id` as vpype layer ID.
103-
- `layer_end`: Accepts `index` the current layer index starting from 0, `index1` the current layer number starting from 1, and `layer_id` as vpype layer ID.
104-
- `line_start`: Accepts `index` the current line number starting from 0, `index1` the current line number starting from 1, and `layer_index`, `layer_index1`, and `layer_id` values for the current layer this line is within.
105-
- `line_end`: Accepts `index` the current line number starting from 0, `index1` the current line number starting from 1, and `layer_index`, `layer_index1`, and `layer_id` values for the current layer this line is within.
102+
For example every element accepts the value of `index`. You would encode that in the text as `{index:d}` the d denotes an integer value. If you need to have a `{` value in your text you would encode that as `{{` likewise you would encode a `}` as `}}`.
103+
- `layer_start`, `layer_end` and `layer_join`: Accepts `x`, `y`, `ix`, `iy`, `index`, `index1`, `layer_index`, `layer_index1`, `layer_id`, and `filename`.
104+
- `x` the last_x position before this layer, this is 0 for the first layer
105+
- `y` the last_y position before this layer, this is 0 for the first layer
106+
- `ix` the last integer x location before this layer, this is 0 for the first layer.
107+
- `iy` the last integer y location before this layer, this is 0 for the first layer.
108+
- `index` same as `layer_index`
109+
- `index1` same as `layer_index1`
110+
- `layer_index` the current layer index starting from 0
111+
- `layer_index1` the current layer number starting from 1
112+
- `layer_id` as vpype layer ID.
113+
- `filename` file name of the file being saved
114+
- `line_start`, `line_end` and `line_join`: Accepts `x`, `y`, `ix`, `iy`, `index`, `index1`, `lines_index`, `lines_index1`, `layer_index`, `layer_index1`, `layer_id`, and `filename`.
115+
- `x` the last_x position before this line, this is 0 for the first line of the first layer
116+
- `y` the last_y position before this line, this is 0 for the first line of the first layer
117+
- `ix` the last integer x location before this layer, this is 0 for the first layer.
118+
- `iy` the last integer y location before this layer, this is 0 for the first layer.
119+
- `index` same as `line_index`
120+
- `index1` same as `line_index1`
121+
- `line_index` the current line index within this layer starting from 0
122+
- `line_index1` the current line index within this layer number starting from 1
123+
- `layer_index` the current layer index starting from 0
124+
- `layer_index1` the current layer number starting from 1
125+
- `layer_id` values for the current vpype layer ID that contains this line
126+
- `filename` file name of the file being saved
106127

107-
The segments accept a lot of values that may be useful statistics for various formats:
128+
The segments (`segment_first`, `segment`, `segment_last`) accept a lot of values that may be useful statistics for various formats:
108129
* `index`: index of the particular coordinate pair. eg `{index:d}`
109130
* `x` absolute position x in floating point number. eg `{x:.4f}`
110131
* `y` absolute position y in floating point number. eg `{y:g}`
@@ -118,11 +139,24 @@ The segments accept a lot of values that may be useful statistics for various fo
118139
* `iy` absolute position y in integer number. eg `{iy:d}`
119140
* `idx` relative position x in integer number. eg `{idx:d}`
120141
* `idy` relative position y in integer number. eg `{idy:d}`
121-
122-
Note: `idx` and `idy` are properly guarded against compounding fractional rounding errors. Moving 0.1 units 1000 times results in a location 100 units away and not zero.
142+
* `index` same as `segment_index`
143+
* `index1` same as `segment_index1`
144+
* `segment_index` the current segment within this line starting from 0
145+
* `segment_index1` the current segment within this line starting from 1
146+
* `line_index` the current line index within this layer starting from 0
147+
* `line_index1` the current line index within this layer number starting from 1
148+
* `layer_index` the current layer index starting from 0
149+
* `layer_index1` the current layer number starting from 1
150+
* `layer_id` values for the current vpype layer ID that contains this line
151+
* `filename` file name of the file being saved
152+
153+
#### Notes
154+
* `idx` and `idy` are properly guarded against compounding fractional rounding errors. Moving 0.1 units 1000 times results in a location 100 units away and not zero.
155+
* `line_join` occurs after `line_end` but only appears *between* lines, it does not occur after the last line.
156+
* `layer_join` occurs after `layer_end` but only appears *between* layers, it does not occur after the last layer.
123157

124158
### Information Control
125-
- `info`: prints text after file is written to inform the user of said information
159+
- `info`: prints text to the console after file is written to inform the user of said information
126160

127161
## Output structure
128162
The gwrite command gives you access to write to a variety of formats that fit the given outline. We're writing generic ascii. Since gcode can have more flavors than a Baskin Robbins™, it's best to simply draw broad strokes as to what ascii output should look like. Here we define the various elements without any regard to the gcode it will largely be producing.
@@ -137,6 +171,7 @@ The gwrite command gives you access to write to a variety of formats that fit th
137171
<segment>
138172
<segment_last>
139173
<line_end>
174+
<line_join>
140175
<line_start>
141176
<segment_first>
142177
<segment>
@@ -145,6 +180,7 @@ The gwrite command gives you access to write to a variety of formats that fit th
145180
<segment>
146181
<segment_last>
147182
<line_end>
183+
<line_join>
148184
<line_start>
149185
<segment_first>
150186
<segment>
@@ -154,6 +190,7 @@ The gwrite command gives you access to write to a variety of formats that fit th
154190
<segment_last>
155191
<line_end>
156192
<layer_end>
193+
<layer_join>
157194
<layer_start>
158195
<line_start>
159196
<segment_first>
@@ -163,6 +200,7 @@ The gwrite command gives you access to write to a variety of formats that fit th
163200
<segment>
164201
<segment_last>
165202
<line_end>
203+
<line_join>
166204
<line_start>
167205
<segment_first>
168206
<segment>
@@ -171,6 +209,7 @@ The gwrite command gives you access to write to a variety of formats that fit th
171209
<segment>
172210
<segment_last>
173211
<line_end>
212+
<line_join>
174213
<line_start>
175214
<segment_first>
176215
<segment>
@@ -189,6 +228,20 @@ To prevent having to provide the profile on every invocation of the gcode plugin
189228
default_profile = "gcode"
190229
```
191230

231+
## Coordinate System
232+
`Vpype-Gcode` uses the standard coordinate system of vpype which uses the SVG spec' system. The origin point is located in the upper-left hand corner. Positive y values are towards the bottom. If you wish to change the coordinate system you should use `invert_y` and `invert_x` equals `"True"` in your profile. This will mirror the work horizontally or vertically within the same euclidean space. For example the native Coordinate system of gcode is origin point in the bottom left. This requires that for gcode profiles be marked as `invert_y`.
233+
234+
```toml
235+
[gwrite.gcode]
236+
document_start = "G20\nG17\nG90\n"
237+
segment_first = "G00 X{x:.4f} Y{y:.4f}\n"
238+
segment = "G01 X{x:.4f} Y{y:.4f}\n"
239+
document_end = "M2\n"
240+
unit = "in"
241+
invert_y = "True"
242+
info= "This gcode profile is correctly inverted across the y-axis"
243+
```
244+
192245
# Examples
193246
## Convert SVG -> GCode
194247
Loads up a svg and writes it in default gcode.:

setup.py

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

66
setup(
77
name="vpype-gcode",
8-
version="0.10.1",
8+
version="0.10.2",
99
description="vpype gcode plugin",
1010
long_description=readme,
1111
long_description_content_type="text/markdown",

vpype_gcode/gwrite.py

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ def gwrite(document: vp.Document, output: typing.TextIO, profile: str):
123123
if layer_start is not None:
124124
output.write(
125125
layer_start.format(
126+
x=last_x,
127+
y=last_y,
128+
ix=xx,
129+
iy=yy,
126130
index=layer_index,
127131
index1=layer_index + 1,
128132
layer_index=layer_index,
@@ -136,6 +140,10 @@ def gwrite(document: vp.Document, output: typing.TextIO, profile: str):
136140
if line_start is not None:
137141
output.write(
138142
line_start.format(
143+
x=last_x,
144+
y=last_y,
145+
ix=xx,
146+
iy=yy,
139147
index=lines_index,
140148
index1=lines_index + 1,
141149
lines_index=lines_index,
@@ -194,6 +202,10 @@ def gwrite(document: vp.Document, output: typing.TextIO, profile: str):
194202
if line_end is not None:
195203
output.write(
196204
line_end.format(
205+
x=last_x,
206+
y=last_y,
207+
ix=xx,
208+
iy=yy,
197209
index=lines_index,
198210
index1=lines_index + 1,
199211
lines_index=lines_index,
@@ -205,10 +217,29 @@ def gwrite(document: vp.Document, output: typing.TextIO, profile: str):
205217
)
206218
)
207219
if line_join is not None and lines_index != lastlines_index:
208-
output.write(line_join)
220+
output.write(
221+
line_join.format(
222+
x=last_x,
223+
y=last_y,
224+
ix=xx,
225+
iy=yy,
226+
index=lines_index,
227+
index1=lines_index + 1,
228+
lines_index=lines_index,
229+
lines_index1=lines_index + 1,
230+
layer_index=layer_index,
231+
layer_index1=layer_index + 1,
232+
layer_id=layer_id,
233+
filename=filename,
234+
)
235+
)
209236
if layer_end is not None:
210237
output.write(
211238
layer_end.format(
239+
x=last_x,
240+
y=last_y,
241+
ix=xx,
242+
iy=yy,
212243
index=layer_index,
213244
index1=layer_index + 1,
214245
layer_index=layer_index,
@@ -218,7 +249,20 @@ def gwrite(document: vp.Document, output: typing.TextIO, profile: str):
218249
)
219250
)
220251
if layer_join is not None and layer_index != lastlayer_index:
221-
output.write(layer_join)
252+
output.write(
253+
layer_join.format(
254+
x=last_x,
255+
y=last_y,
256+
ix=xx,
257+
iy=yy,
258+
index=layer_index,
259+
index1=layer_index + 1,
260+
layer_index=layer_index,
261+
layer_index1=layer_index + 1,
262+
layer_id=layer_id,
263+
filename=filename,
264+
)
265+
)
222266
if document_end is not None:
223267
output.write(document_end.format(filename=filename))
224268
output.flush()

0 commit comments

Comments
 (0)