|
6 | 6 | import vpype as vp |
7 | 7 |
|
8 | 8 | # Load the default config |
| 9 | + |
9 | 10 | vp.CONFIG_MANAGER.load_config_file(str(Path(__file__).parent / "bundled_configs.toml")) |
10 | 11 |
|
11 | 12 |
|
| 13 | +def invert_axis(document: vp.Document, invert_x: bool, invert_y: bool): |
| 14 | + """Inverts none, one or both axis of the document. |
| 15 | + This applies a relative scale operation with factors of 1 or -1 |
| 16 | + on the two axis to all layers. The inversion happens relative to |
| 17 | + the center of the bounds. |
| 18 | + """ |
| 19 | + |
| 20 | + bounds = document.bounds() |
| 21 | + if not bounds: |
| 22 | + return document |
| 23 | + |
| 24 | + origin = ( |
| 25 | + 0.5 * (bounds[0] + bounds[2]), |
| 26 | + 0.5 * (bounds[1] + bounds[3]), |
| 27 | + ) |
| 28 | + |
| 29 | + document.translate(-origin[0], -origin[1]) |
| 30 | + document.scale(-1 if invert_x else 1, -1 if invert_y else 1) |
| 31 | + document.translate(origin[0], origin[1]) |
| 32 | + |
| 33 | + return document |
| 34 | + |
| 35 | + |
12 | 36 | @click.command() |
13 | 37 | @click.argument("output", type=click.File("w")) |
14 | 38 | @click.option( |
|
21 | 45 | ) |
22 | 46 | @vp.global_processor |
23 | 47 | def gwrite(document: vp.Document, output: typing.TextIO, profile: str): |
| 48 | + """ |
| 49 | + Write gcode or other ascii files for the vpype pipeline. |
| 50 | +
|
| 51 | + The output format can be customized by the user heavily to an extent that you can also output most known |
| 52 | + non-gcode ascii text files. |
| 53 | + """ |
24 | 54 | gwrite_config = vp.CONFIG_MANAGER.config["gwrite"] |
25 | 55 |
|
26 | 56 | # If no profile was provided, try to use a default |
@@ -73,6 +103,12 @@ def gwrite(document: vp.Document, output: typing.TextIO, profile: str): |
73 | 103 | document.scale(scale_x / unit_scale, scale_y / unit_scale) |
74 | 104 | document.translate(offset_x, offset_y) |
75 | 105 |
|
| 106 | + invert_x = config.get("invert_x", False) |
| 107 | + invert_y = config.get("invert_y", False) |
| 108 | + # transform the document according to inversion parameters |
| 109 | + if invert_x or invert_y: |
| 110 | + document = invert_axis(document, invert_x, invert_y) |
| 111 | + |
76 | 112 | # process file |
77 | 113 | filename = output.name |
78 | 114 | if document_start is not None: |
@@ -187,7 +223,9 @@ def gwrite(document: vp.Document, output: typing.TextIO, profile: str): |
187 | 223 | output.write(document_end.format(filename=filename)) |
188 | 224 | output.flush() |
189 | 225 | output.close() |
190 | | - |
| 226 | + info = config.get("info", None) |
| 227 | + if info: |
| 228 | + print(info) |
191 | 229 | return orig_document |
192 | 230 |
|
193 | 231 |
|
|
0 commit comments