Welcome to mirror list, hosted at ThFree Co, Russian Federation.

injectgcode.py « printrun - github.com/kliment/Printrun.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 858f09d5db489d4e0d1c7afbb407ab151cb7afc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# This file is part of the Printrun suite.
#
# Printrun is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Printrun is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Printrun.  If not, see <http://www.gnu.org/licenses/>.

import logging

from .gui.widgets import MacroEditor

from .utils import install_locale
install_locale('pronterface')

def injector(gcode, viz_layer, layer_idx):
    cb = lambda toadd: inject(gcode, viz_layer, layer_idx, toadd)
    z = gcode.all_layers[layer_idx].z
    z = z if z is not None else 0
    MacroEditor(_("Inject G-Code at layer %d (Z = %.03f)") % (viz_layer, z), "", cb, True)

def injector_edit(gcode, viz_layer, layer_idx):
    cb = lambda toadd: rewritelayer(gcode, viz_layer, layer_idx, toadd)
    layer = gcode.all_layers[layer_idx]
    z = layer.z
    z = z if z is not None else 0
    lines = [line.raw for line in layer]
    MacroEditor(_("Edit G-Code of layer %d (Z = %.03f)") % (viz_layer, z), lines, cb, True)

def inject(gcode, viz_layer, layer_idx, toadd):
    # TODO: save modified gcode after injection ?
    nlines = len(gcode.prepend_to_layer(toadd, layer_idx))
    logging.info(_("Successfully injected %d lines at beginning of layer %d") % (nlines, viz_layer))

def rewritelayer(gcode, viz_layer, layer_idx, toadd):
    # TODO: save modified gcode after edit ?
    nlines = len(gcode.rewrite_layer(toadd, layer_idx))
    logging.info(_("Successfully edited layer %d (which now contains %d lines)") % (viz_layer, nlines))