printrun-src/testtools/gcodeviewer.py

Sat, 08 Sep 2018 12:00:12 +0200

author
mdd
date
Sat, 08 Sep 2018 12:00:12 +0200
changeset 39
74801c0f2709
parent 15
0bbb006204fc
child 45
c82943fb205f
permissions
-rw-r--r--

bad idea :(

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

mercurial