printrun-src/printrun/injectgcode.py

Fri, 28 Jul 2017 15:57:22 +0200

author
mdd
date
Fri, 28 Jul 2017 15:57:22 +0200
changeset 29
c96f20e95029
parent 15
0bbb006204fc
permissions
-rw-r--r--

Changed min/max setting values

15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1 # This file is part of the Printrun suite.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
3 # Printrun is free software: you can redistribute it and/or modify
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
4 # it under the terms of the GNU General Public License as published by
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
5 # the Free Software Foundation, either version 3 of the License, or
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
6 # (at your option) any later version.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
7 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
8 # Printrun is distributed in the hope that it will be useful,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
11 # GNU General Public License for more details.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
12 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
13 # You should have received a copy of the GNU General Public License
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
14 # along with Printrun. If not, see <http://www.gnu.org/licenses/>.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
16 import logging
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
17
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
18 from .gui.widgets import MacroEditor
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
19
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
20 from .utils import install_locale
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
21 install_locale('pronterface')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
22
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
23 def injector(gcode, viz_layer, layer_idx):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
24 cb = lambda toadd: inject(gcode, viz_layer, layer_idx, toadd)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
25 z = gcode.all_layers[layer_idx].z
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
26 z = z if z is not None else 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
27 MacroEditor(_("Inject G-Code at layer %d (Z = %.03f)") % (viz_layer, z), "", cb, True)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
28
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
29 def injector_edit(gcode, viz_layer, layer_idx):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
30 cb = lambda toadd: rewritelayer(gcode, viz_layer, layer_idx, toadd)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
31 layer = gcode.all_layers[layer_idx]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
32 z = layer.z
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
33 z = z if z is not None else 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
34 lines = [line.raw for line in layer]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
35 MacroEditor(_("Edit G-Code of layer %d (Z = %.03f)") % (viz_layer, z), lines, cb, True)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
36
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
37 def inject(gcode, viz_layer, layer_idx, toadd):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
38 # TODO: save modified gcode after injection ?
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
39 nlines = len(gcode.prepend_to_layer(toadd, layer_idx))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
40 logging.info(_("Successfully injected %d lines at beginning of layer %d") % (nlines, viz_layer))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
41
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
42 def rewritelayer(gcode, viz_layer, layer_idx, toadd):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
43 # TODO: save modified gcode after edit ?
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
44 nlines = len(gcode.rewrite_layer(toadd, layer_idx))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
45 logging.info(_("Successfully edited layer %d (which now contains %d lines)") % (viz_layer, nlines))

mercurial