Sat, 04 Jun 2016 13:06:30 +0200
Remove empty lines output on bitmap plotter
15 | 1 | #!/usr/bin/env python |
2 | ||
3 | # This file is part of the Printrun suite. | |
4 | # | |
5 | # Printrun is free software: you can redistribute it and/or modify | |
6 | # it under the terms of the GNU General Public License as published by | |
7 | # the Free Software Foundation, either version 3 of the License, or | |
8 | # (at your option) any later version. | |
9 | # | |
10 | # Printrun is distributed in the hope that it will be useful, | |
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | # GNU General Public License for more details. | |
14 | # | |
15 | # You should have received a copy of the GNU General Public License | |
16 | # along with Printrun. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | import sys | |
19 | import os | |
20 | import logging | |
21 | logging.basicConfig(level=logging.INFO) | |
22 | ||
23 | import wx | |
24 | ||
25 | sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")) | |
26 | ||
27 | from printrun.gcview import GcodeViewFrame | |
28 | from printrun import gcoder | |
29 | ||
30 | app = wx.App(redirect = False) | |
31 | build_dimensions = [200, 200, 100, -100, -100, 0] | |
32 | build_dimensions = [200, 200, 100, 0, 0, 0] | |
33 | frame = GcodeViewFrame(None, wx.ID_ANY, 'Gcode view, shift to move view, mousewheel to set layer', size = (800, 800), build_dimensions = build_dimensions) | |
34 | gcode = gcoder.GCode(open(sys.argv[1])) | |
35 | print "Gcode loaded" | |
36 | frame.addfile(gcode) | |
37 | ||
38 | first_move = None | |
39 | for i in range(len(gcode.lines)): | |
40 | if gcode.lines[i].is_move: | |
41 | first_move = gcode.lines[i] | |
42 | break | |
43 | last_move = None | |
44 | for i in range(len(gcode.lines) - 1, -1, -1): | |
45 | if gcode.lines[i].is_move: | |
46 | last_move = gcode.lines[i] | |
47 | break | |
48 | nsteps = 20 | |
49 | steptime = 50 | |
50 | lines = [first_move] \ | |
51 | + [gcode.lines[int(float(i) * (len(gcode.lines) - 1) / nsteps)] | |
52 | for i in range(1, nsteps)] + [last_move] | |
53 | current_line = 0 | |
54 | def setLine(): | |
55 | global current_line | |
56 | frame.set_current_gline(lines[current_line]) | |
57 | current_line = (current_line + 1) % len(lines) | |
58 | timer.Start() | |
59 | ||
60 | timer = wx.CallLater(steptime, setLine) | |
61 | timer.Start() | |
62 | ||
63 | frame.Show(True) | |
64 | app.MainLoop() | |
65 | app.Destroy() |