printrun-src/printrun/projectlayer.py

Wed, 20 Jan 2021 10:15:13 +0100

author
mdd
date
Wed, 20 Jan 2021 10:15:13 +0100
changeset 46
cce0af6351f0
parent 15
0bbb006204fc
permissions
-rw-r--r--

updated and added new files for printrun

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 xml.etree.ElementTree
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
17 import wx
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
18 import wx.lib.agw.floatspin as floatspin
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
19 import os
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
20 import time
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
21 import zipfile
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
22 import tempfile
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
23 import shutil
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
24 from cairosvg.surface import PNGSurface
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
25 import io
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
26 import imghdr
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
27 import copy
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
28 import re
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
29 from collections import OrderedDict
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
30 import math
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
31
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
32 class DisplayFrame(wx.Frame):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
33 def __init__(self, parent, title, res = (1024, 768), printer = None, scale = 1.0, offset = (0, 0)):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
34 wx.Frame.__init__(self, parent = parent, title = title, size = res)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
35 self.printer = printer
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
36 self.control_frame = parent
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
37 self.pic = wx.StaticBitmap(self)
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
38 self.bitmap = wx.Bitmap(*res)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
39 self.bbitmap = wx.Bitmap(*res)
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
40 self.slicer = 'bitmap'
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
41 self.dpi = 96
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
42 dc = wx.MemoryDC()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
43 dc.SelectObject(self.bbitmap)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
44 dc.SetBackground(wx.Brush("black"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
45 dc.Clear()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
46 dc.SelectObject(wx.NullBitmap)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
47
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
48 self.SetBackgroundColour("black")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
49 self.pic.Hide()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
50 self.SetDoubleBuffered(True)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
51 self.SetPosition((self.control_frame.GetSize().x, 0))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
52 self.Show()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
53
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
54 self.scale = scale
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
55 self.index = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
56 self.size = res
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
57 self.offset = offset
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
58 self.running = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
59 self.layer_red = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
60
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
61 def clear_layer(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
62 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
63 dc = wx.MemoryDC()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
64 dc.SelectObject(self.bitmap)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
65 dc.SetBackground(wx.Brush("black"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
66 dc.Clear()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
67 self.pic.SetBitmap(self.bitmap)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
68 self.pic.Show()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
69 self.Refresh()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
70 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
71 raise
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
72 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
73
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
74 def resize(self, res = (1024, 768)):
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
75 self.bitmap = wx.Bitmap(*res)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
76 self.bbitmap = wx.Bitmap(*res)
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
77 dc = wx.MemoryDC()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
78 dc.SelectObject(self.bbitmap)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
79 dc.SetBackground(wx.Brush("black"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
80 dc.Clear()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
81 dc.SelectObject(wx.NullBitmap)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
82
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
83 def draw_layer(self, image):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
84 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
85 dc = wx.MemoryDC()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
86 dc.SelectObject(self.bitmap)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
87 dc.SetBackground(wx.Brush("black"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
88 dc.Clear()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
89
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
90 if self.slicer == 'Slic3r' or self.slicer == 'Skeinforge':
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
91
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
92 if self.scale != 1.0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
93 layercopy = copy.deepcopy(image)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
94 height = float(layercopy.get('height').replace('m', ''))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
95 width = float(layercopy.get('width').replace('m', ''))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
96
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
97 layercopy.set('height', str(height * self.scale) + 'mm')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
98 layercopy.set('width', str(width * self.scale) + 'mm')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
99 layercopy.set('viewBox', '0 0 ' + str(width * self.scale) + ' ' + str(height * self.scale))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
100
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
101 g = layercopy.find("{http://www.w3.org/2000/svg}g")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
102 g.set('transform', 'scale(' + str(self.scale) + ')')
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
103 stream = io.StringIO(PNGSurface.convert(dpi = self.dpi, bytestring = xml.etree.ElementTree.tostring(layercopy)))
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
104 else:
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
105 stream = io.StringIO(PNGSurface.convert(dpi = self.dpi, bytestring = xml.etree.ElementTree.tostring(image)))
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
106
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
107 pngImage = wx.ImageFromStream(stream)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
108
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
109 # print "w:", pngImage.Width, ", dpi:", self.dpi, ", w (mm): ",(pngImage.Width / self.dpi) * 25.4
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
110
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
111 if self.layer_red:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
112 pngImage = pngImage.AdjustChannels(1, 0, 0, 1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
113
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
114 dc.DrawBitmap(wx.BitmapFromImage(pngImage), self.offset[0], self.offset[1], True)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
115
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
116 elif self.slicer == 'bitmap':
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
117 if isinstance(image, str):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
118 image = wx.Image(image)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
119 if self.layer_red:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
120 image = image.AdjustChannels(1, 0, 0, 1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
121 dc.DrawBitmap(wx.BitmapFromImage(image.Scale(image.Width * self.scale, image.Height * self.scale)), self.offset[0], -self.offset[1], True)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
122 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
123 raise Exception(self.slicer + " is an unknown method.")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
124
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
125 self.pic.SetBitmap(self.bitmap)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
126 self.pic.Show()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
127 self.Refresh()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
128
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
129 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
130 raise
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
131 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
132
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
133 def show_img_delay(self, image):
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
134 print("Showing", str(time.clock()))
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
135 self.control_frame.set_current_layer(self.index)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
136 self.draw_layer(image)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
137 wx.FutureCall(1000 * self.interval, self.hide_pic_and_rise)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
138
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
139 def rise(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
140 if (self.direction == "Top Down"):
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
141 print("Lowering", str(time.clock()))
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
142 else:
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
143 print("Rising", str(time.clock()))
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
144
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
145 if self.printer is not None and self.printer.online:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
146 self.printer.send_now("G91")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
147
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
148 if (self.prelift_gcode):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
149 for line in self.prelift_gcode.split('\n'):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
150 if line:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
151 self.printer.send_now(line)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
152
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
153 if (self.direction == "Top Down"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
154 self.printer.send_now("G1 Z-%f F%g" % (self.overshoot, self.z_axis_rate,))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
155 self.printer.send_now("G1 Z%f F%g" % (self.overshoot - self.thickness, self.z_axis_rate,))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
156 else: # self.direction == "Bottom Up"
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
157 self.printer.send_now("G1 Z%f F%g" % (self.overshoot, self.z_axis_rate,))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
158 self.printer.send_now("G1 Z-%f F%g" % (self.overshoot - self.thickness, self.z_axis_rate,))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
159
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
160 if (self.postlift_gcode):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
161 for line in self.postlift_gcode.split('\n'):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
162 if line:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
163 self.printer.send_now(line)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
164
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
165 self.printer.send_now("G90")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
166 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
167 time.sleep(self.pause)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
168
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
169 wx.FutureCall(1000 * self.pause, self.next_img)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
170
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
171 def hide_pic(self):
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
172 print("Hiding", str(time.clock()))
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
173 self.pic.Hide()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
174
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
175 def hide_pic_and_rise(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
176 wx.CallAfter(self.hide_pic)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
177 wx.FutureCall(500, self.rise)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
178
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
179 def next_img(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
180 if not self.running:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
181 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
182 if self.index < len(self.layers):
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
183 print(self.index)
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
184 wx.CallAfter(self.show_img_delay, self.layers[self.index])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
185 self.index += 1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
186 else:
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
187 print("end")
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
188 wx.CallAfter(self.pic.Hide)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
189 wx.CallAfter(self.Refresh)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
190
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
191 def present(self,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
192 layers,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
193 interval = 0.5,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
194 pause = 0.2,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
195 overshoot = 0.0,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
196 z_axis_rate = 200,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
197 prelift_gcode = "",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
198 postlift_gcode = "",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
199 direction = "Top Down",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
200 thickness = 0.4,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
201 scale = 1,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
202 size = (1024, 768),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
203 offset = (0, 0),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
204 layer_red = False):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
205 wx.CallAfter(self.pic.Hide)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
206 wx.CallAfter(self.Refresh)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
207 self.layers = layers
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
208 self.scale = scale
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
209 self.thickness = thickness
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
210 self.size = size
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
211 self.interval = interval
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
212 self.pause = pause
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
213 self.overshoot = overshoot
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
214 self.z_axis_rate = z_axis_rate
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
215 self.prelift_gcode = prelift_gcode
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
216 self.postlift_gcode = postlift_gcode
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
217 self.direction = direction
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
218 self.layer_red = layer_red
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
219 self.offset = offset
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
220 self.index = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
221 self.running = True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
222
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
223 self.next_img()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
224
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
225 class SettingsFrame(wx.Frame):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
226
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
227 def _set_setting(self, name, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
228 if self.pronterface:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
229 self.pronterface.set(name, value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
230
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
231 def _get_setting(self, name, val):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
232 if self.pronterface:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
233 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
234 return getattr(self.pronterface.settings, name)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
235 except AttributeError:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
236 return val
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
237 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
238 return val
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
239
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
240 def __init__(self, parent, printer = None):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
241 wx.Frame.__init__(self, parent, title = "ProjectLayer Control", style = (wx.DEFAULT_FRAME_STYLE | wx.WS_EX_CONTEXTHELP))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
242 self.SetExtraStyle(wx.FRAME_EX_CONTEXTHELP)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
243 self.pronterface = parent
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
244 self.display_frame = DisplayFrame(self, title = "ProjectLayer Display", printer = printer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
245
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
246 self.panel = wx.Panel(self)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
247
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
248 vbox = wx.BoxSizer(wx.VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
249 buttonbox = wx.StaticBoxSizer(wx.StaticBox(self.panel, label = "Controls"), wx.HORIZONTAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
250
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
251 load_button = wx.Button(self.panel, -1, "Load")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
252 load_button.Bind(wx.EVT_BUTTON, self.load_file)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
253 load_button.SetHelpText("Choose an SVG file created from Slic3r or Skeinforge, or a zip file of bitmap images (with extension: .3dlp.zip).")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
254 buttonbox.Add(load_button, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
255
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
256 present_button = wx.Button(self.panel, -1, "Present")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
257 present_button.Bind(wx.EVT_BUTTON, self.start_present)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
258 present_button.SetHelpText("Starts the presentation of the slices.")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
259 buttonbox.Add(present_button, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
260
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
261 self.pause_button = wx.Button(self.panel, -1, "Pause")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
262 self.pause_button.Bind(wx.EVT_BUTTON, self.pause_present)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
263 self.pause_button.SetHelpText("Pauses the presentation. Can be resumed afterwards by clicking this button, or restarted by clicking present again.")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
264 buttonbox.Add(self.pause_button, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
265
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
266 stop_button = wx.Button(self.panel, -1, "Stop")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
267 stop_button.Bind(wx.EVT_BUTTON, self.stop_present)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
268 stop_button.SetHelpText("Stops presenting the slices.")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
269 buttonbox.Add(stop_button, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
270
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
271 self.help_button = wx.ContextHelpButton(self.panel)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
272 buttonbox.Add(self.help_button, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
273
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
274 fieldboxsizer = wx.StaticBoxSizer(wx.StaticBox(self.panel, label = "Settings"), wx.VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
275 fieldsizer = wx.GridBagSizer(10, 10)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
276
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
277 # Left Column
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
278
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
279 fieldsizer.Add(wx.StaticText(self.panel, -1, "Layer (mm):"), pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
280 self.thickness = wx.TextCtrl(self.panel, -1, str(self._get_setting("project_layer", "0.1")), size = (125, -1))
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
281 self.thickness.Bind(wx.EVT_TEXT, self.update_thickness)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
282 self.thickness.SetHelpText("The thickness of each slice. Should match the value used to slice the model. SVG files update this value automatically, 3dlp.zip files have to be manually entered.")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
283 fieldsizer.Add(self.thickness, pos = (0, 1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
284
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
285 fieldsizer.Add(wx.StaticText(self.panel, -1, "Exposure (s):"), pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
286 self.interval = wx.TextCtrl(self.panel, -1, str(self._get_setting("project_interval", "0.5")), size = (125, -1))
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
287 self.interval.Bind(wx.EVT_TEXT, self.update_interval)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
288 self.interval.SetHelpText("How long each slice should be displayed.")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
289 fieldsizer.Add(self.interval, pos = (1, 1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
290
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
291 fieldsizer.Add(wx.StaticText(self.panel, -1, "Blank (s):"), pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL)
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
292 self.pause = wx.TextCtrl(self.panel, -1, str(self._get_setting("project_pause", "0.5")), size = (125, -1))
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
293 self.pause.Bind(wx.EVT_TEXT, self.update_pause)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
294 self.pause.SetHelpText("The pause length between slices. This should take into account any movement of the Z axis, plus time to prepare the resin surface (sliding, tilting, sweeping, etc).")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
295 fieldsizer.Add(self.pause, pos = (2, 1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
296
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
297 fieldsizer.Add(wx.StaticText(self.panel, -1, "Scale:"), pos = (3, 0), flag = wx.ALIGN_CENTER_VERTICAL)
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
298 self.scale = wx.SpinCtrlDouble(self.panel, -1, initial = self._get_setting('project_scale', 1.0), inc = 0.1, size = (125, -1))
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
299 self.scale.SetDigits(3)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
300 self.scale.Bind(wx.EVT_SPINCTRLDOUBLE, self.update_scale)
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
301 self.scale.SetHelpText("The additional scaling of each slice.")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
302 fieldsizer.Add(self.scale, pos = (3, 1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
303
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
304 fieldsizer.Add(wx.StaticText(self.panel, -1, "Direction:"), pos = (4, 0), flag = wx.ALIGN_CENTER_VERTICAL)
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
305 self.direction = wx.ComboBox(self.panel, -1, choices = ["Top Down", "Bottom Up"], value = self._get_setting('project_direction', "Top Down"), size = (125, -1))
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
306 self.direction.Bind(wx.EVT_COMBOBOX, self.update_direction)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
307 self.direction.SetHelpText("The direction the Z axis should move. Top Down is where the projector is above the model, Bottom up is where the projector is below the model.")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
308 fieldsizer.Add(self.direction, pos = (4, 1), flag = wx.ALIGN_CENTER_VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
309
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
310 fieldsizer.Add(wx.StaticText(self.panel, -1, "Overshoot (mm):"), pos = (5, 0), flag = wx.ALIGN_CENTER_VERTICAL)
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
311 self.overshoot = wx.SpinCtrlDouble(self.panel, -1, initial = self._get_setting('project_overshoot', 3.0), inc = 0.1, min = 0, size = (125, -1))
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
312 self.overshoot.SetDigits(1)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
313 self.overshoot.Bind(wx.EVT_SPINCTRLDOUBLE, self.update_overshoot)
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
314 self.overshoot.SetHelpText("How far the axis should move beyond the next slice position for each slice. For Top Down printers this would dunk the model under the resi and then return. For Bottom Up printers this would raise the base away from the vat and then return.")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
315 fieldsizer.Add(self.overshoot, pos = (5, 1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
316
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
317 fieldsizer.Add(wx.StaticText(self.panel, -1, "Pre-lift Gcode:"), pos = (6, 0), flag = wx.ALIGN_CENTER_VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
318 self.prelift_gcode = wx.TextCtrl(self.panel, -1, str(self._get_setting("project_prelift_gcode", "").replace("\\n", '\n')), size = (-1, 35), style = wx.TE_MULTILINE)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
319 self.prelift_gcode.SetHelpText("Additional gcode to run before raising the Z axis. Be sure to take into account any additional time needed in the pause value, and be careful what gcode is added!")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
320 self.prelift_gcode.Bind(wx.EVT_TEXT, self.update_prelift_gcode)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
321 fieldsizer.Add(self.prelift_gcode, pos = (6, 1), span = (2, 1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
322
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
323 fieldsizer.Add(wx.StaticText(self.panel, -1, "Post-lift Gcode:"), pos = (6, 2), flag = wx.ALIGN_CENTER_VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
324 self.postlift_gcode = wx.TextCtrl(self.panel, -1, str(self._get_setting("project_postlift_gcode", "").replace("\\n", '\n')), size = (-1, 35), style = wx.TE_MULTILINE)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
325 self.postlift_gcode.SetHelpText("Additional gcode to run after raising the Z axis. Be sure to take into account any additional time needed in the pause value, and be careful what gcode is added!")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
326 self.postlift_gcode.Bind(wx.EVT_TEXT, self.update_postlift_gcode)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
327 fieldsizer.Add(self.postlift_gcode, pos = (6, 3), span = (2, 1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
328
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
329 # Right Column
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
330
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
331 fieldsizer.Add(wx.StaticText(self.panel, -1, "X (px):"), pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
332 projectX = int(math.floor(float(self._get_setting("project_x", 1920))))
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
333 self.X = wx.SpinCtrl(self.panel, -1, str(projectX), max = 999999, size = (125, -1))
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
334 self.X.Bind(wx.EVT_SPINCTRL, self.update_resolution)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
335 self.X.SetHelpText("The projector resolution in the X axis.")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
336 fieldsizer.Add(self.X, pos = (0, 3))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
337
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
338 fieldsizer.Add(wx.StaticText(self.panel, -1, "Y (px):"), pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
339 projectY = int(math.floor(float(self._get_setting("project_y", 1200))))
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
340 self.Y = wx.SpinCtrl(self.panel, -1, str(projectY), max = 999999, size = (125, -1))
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
341 self.Y.Bind(wx.EVT_SPINCTRL, self.update_resolution)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
342 self.Y.SetHelpText("The projector resolution in the Y axis.")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
343 fieldsizer.Add(self.Y, pos = (1, 3))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
344
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
345 fieldsizer.Add(wx.StaticText(self.panel, -1, "OffsetX (mm):"), pos = (2, 2), flag = wx.ALIGN_CENTER_VERTICAL)
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
346 self.offset_X = wx.SpinCtrlDouble(self.panel, -1, initial = self._get_setting("project_offset_x", 0.0), inc = 1, size = (125, -1))
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
347 self.offset_X.SetDigits(1)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
348 self.offset_X.Bind(wx.EVT_SPINCTRLDOUBLE, self.update_offset)
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
349 self.offset_X.SetHelpText("How far the slice should be offset from the edge in the X axis.")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
350 fieldsizer.Add(self.offset_X, pos = (2, 3))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
351
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
352 fieldsizer.Add(wx.StaticText(self.panel, -1, "OffsetY (mm):"), pos = (3, 2), flag = wx.ALIGN_CENTER_VERTICAL)
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
353 self.offset_Y = wx.SpinCtrlDouble(self.panel, -1, initial = self._get_setting("project_offset_y", 0.0), inc = 1, size = (125, -1))
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
354 self.offset_Y.SetDigits(1)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
355 self.offset_Y.Bind(wx.EVT_SPINCTRLDOUBLE, self.update_offset)
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
356 self.offset_Y.SetHelpText("How far the slice should be offset from the edge in the Y axis.")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
357 fieldsizer.Add(self.offset_Y, pos = (3, 3))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
358
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
359 fieldsizer.Add(wx.StaticText(self.panel, -1, "ProjectedX (mm):"), pos = (4, 2), flag = wx.ALIGN_CENTER_VERTICAL)
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
360 self.projected_X_mm = wx.SpinCtrlDouble(self.panel, -1, initial = self._get_setting("project_projected_x", 505.0), inc = 1, size = (125, -1))
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
361 self.projected_X_mm.SetDigits(1)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
362 self.projected_X_mm.Bind(wx.EVT_SPINCTRLDOUBLE, self.update_projected_Xmm)
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
363 self.projected_X_mm.SetHelpText("The actual width of the entire projected image. Use the Calibrate grid to show the full size of the projected image, and measure the width at the same level where the slice will be projected onto the resin.")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
364 fieldsizer.Add(self.projected_X_mm, pos = (4, 3))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
365
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
366 fieldsizer.Add(wx.StaticText(self.panel, -1, "Z Axis Speed (mm/min):"), pos = (5, 2), flag = wx.ALIGN_CENTER_VERTICAL)
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
367 self.z_axis_rate = wx.SpinCtrl(self.panel, -1, str(self._get_setting("project_z_axis_rate", 200)), max = 9999, size = (125, -1))
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
368 self.z_axis_rate.Bind(wx.EVT_SPINCTRL, self.update_z_axis_rate)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
369 self.z_axis_rate.SetHelpText("Speed of the Z axis in mm/minute. Take into account that slower rates may require a longer pause value.")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
370 fieldsizer.Add(self.z_axis_rate, pos = (5, 3))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
371
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
372 fieldboxsizer.Add(fieldsizer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
373
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
374 # Display
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
375
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
376 displayboxsizer = wx.StaticBoxSizer(wx.StaticBox(self.panel, label = "Display"), wx.VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
377 displaysizer = wx.GridBagSizer(10, 10)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
378
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
379 displaysizer.Add(wx.StaticText(self.panel, -1, "Fullscreen:"), pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
380 self.fullscreen = wx.CheckBox(self.panel, -1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
381 self.fullscreen.Bind(wx.EVT_CHECKBOX, self.update_fullscreen)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
382 self.fullscreen.SetHelpText("Toggles the project screen to full size.")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
383 displaysizer.Add(self.fullscreen, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
384
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
385 displaysizer.Add(wx.StaticText(self.panel, -1, "Calibrate:"), pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
386 self.calibrate = wx.CheckBox(self.panel, -1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
387 self.calibrate.Bind(wx.EVT_CHECKBOX, self.show_calibrate)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
388 self.calibrate.SetHelpText("Toggles the calibration grid. Each grid should be 10mmx10mm in size. Use the grid to ensure the projected size is correct. See also the help for the ProjectedX field.")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
389 displaysizer.Add(self.calibrate, pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
390
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
391 displaysizer.Add(wx.StaticText(self.panel, -1, "1st Layer:"), pos = (0, 4), flag = wx.ALIGN_CENTER_VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
392
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
393 first_layer_boxer = wx.BoxSizer(wx.HORIZONTAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
394 self.first_layer = wx.CheckBox(self.panel, -1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
395 self.first_layer.Bind(wx.EVT_CHECKBOX, self.show_first_layer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
396 self.first_layer.SetHelpText("Displays the first layer of the model. Use this to project the first layer for longer so it holds to the base. Note: this value does not affect the first layer when the \"Present\" run is started, it should be used manually.")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
397
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
398 first_layer_boxer.Add(self.first_layer, flag = wx.ALIGN_CENTER_VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
399
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
400 first_layer_boxer.Add(wx.StaticText(self.panel, -1, " (s):"), flag = wx.ALIGN_CENTER_VERTICAL)
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
401 self.show_first_layer_timer = wx.SpinCtrlDouble(self.panel, -1, initial = -1, inc = 1, size = (125, -1))
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
402 self.show_first_layer_timer.SetDigits(1)
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
403 self.show_first_layer_timer.SetHelpText("How long to display the first layer for. -1 = unlimited.")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
404 first_layer_boxer.Add(self.show_first_layer_timer, flag = wx.ALIGN_CENTER_VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
405 displaysizer.Add(first_layer_boxer, pos = (0, 6), flag = wx.ALIGN_CENTER_VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
406
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
407 displaysizer.Add(wx.StaticText(self.panel, -1, "Red:"), pos = (0, 7), flag = wx.ALIGN_CENTER_VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
408 self.layer_red = wx.CheckBox(self.panel, -1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
409 self.layer_red.Bind(wx.EVT_CHECKBOX, self.show_layer_red)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
410 self.layer_red.SetHelpText("Toggles whether the image should be red. Useful for positioning whilst resin is in the printer as it should not cause a reaction.")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
411 displaysizer.Add(self.layer_red, pos = (0, 8), flag = wx.ALIGN_CENTER_VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
412
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
413 displayboxsizer.Add(displaysizer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
414
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
415 # Info
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
416 infosizer = wx.StaticBoxSizer(wx.StaticBox(self.panel, label = "Info"), wx.VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
417
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
418 infofieldsizer = wx.GridBagSizer(10, 10)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
419
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
420 filelabel = wx.StaticText(self.panel, -1, "File:")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
421 filelabel.SetHelpText("The name of the model currently loaded.")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
422 infofieldsizer.Add(filelabel, pos = (0, 0))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
423 self.filename = wx.StaticText(self.panel, -1, "")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
424
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
425 infofieldsizer.Add(self.filename, pos = (0, 1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
426
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
427 totallayerslabel = wx.StaticText(self.panel, -1, "Total Layers:")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
428 totallayerslabel.SetHelpText("The total number of layers found in the model.")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
429 infofieldsizer.Add(totallayerslabel, pos = (1, 0))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
430 self.total_layers = wx.StaticText(self.panel, -1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
431
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
432 infofieldsizer.Add(self.total_layers, pos = (1, 1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
433
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
434 currentlayerlabel = wx.StaticText(self.panel, -1, "Current Layer:")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
435 currentlayerlabel.SetHelpText("The current layer being displayed.")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
436 infofieldsizer.Add(currentlayerlabel, pos = (2, 0))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
437 self.current_layer = wx.StaticText(self.panel, -1, "0")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
438 infofieldsizer.Add(self.current_layer, pos = (2, 1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
439
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
440 estimatedtimelabel = wx.StaticText(self.panel, -1, "Estimated Time:")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
441 estimatedtimelabel.SetHelpText("An estimate of the remaining time until print completion.")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
442 infofieldsizer.Add(estimatedtimelabel, pos = (3, 0))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
443 self.estimated_time = wx.StaticText(self.panel, -1, "")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
444 infofieldsizer.Add(self.estimated_time, pos = (3, 1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
445
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
446 infosizer.Add(infofieldsizer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
447
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
448 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
449
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
450 vbox.Add(buttonbox, flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP | wx.BOTTOM, border = 10)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
451 vbox.Add(fieldboxsizer, flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 10)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
452 vbox.Add(displayboxsizer, flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 10)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
453 vbox.Add(infosizer, flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 10)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
454
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
455 self.panel.SetSizer(vbox)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
456 self.panel.Fit()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
457 self.Fit()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
458 self.SetPosition((0, 0))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
459 self.Show()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
460
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
461 def __del__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
462 if hasattr(self, 'image_dir') and self.image_dir != '':
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
463 shutil.rmtree(self.image_dir)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
464 if self.display_frame:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
465 self.display_frame.Destroy()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
466
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
467 def set_total_layers(self, total):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
468 self.total_layers.SetLabel(str(total))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
469 self.set_estimated_time()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
470
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
471 def set_current_layer(self, index):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
472 self.current_layer.SetLabel(str(index))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
473 self.set_estimated_time()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
474
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
475 def display_filename(self, name):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
476 self.filename.SetLabel(name)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
477
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
478 def set_estimated_time(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
479 if not hasattr(self, 'layers'):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
480 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
481
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
482 current_layer = int(self.current_layer.GetLabel())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
483 remaining_layers = len(self.layers[0]) - current_layer
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
484 # 0.5 for delay between hide and rise
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
485 estimated_time = remaining_layers * (float(self.interval.GetValue()) + float(self.pause.GetValue()) + 0.5)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
486 self.estimated_time.SetLabel(time.strftime("%H:%M:%S", time.gmtime(estimated_time)))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
487
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
488 def parse_svg(self, name):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
489 et = xml.etree.ElementTree.ElementTree(file = name)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
490 # xml.etree.ElementTree.dump(et)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
491
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
492 slicer = 'Slic3r' if et.getroot().find('{http://www.w3.org/2000/svg}metadata') is None else 'Skeinforge'
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
493 zlast = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
494 zdiff = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
495 ol = []
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
496 if (slicer == 'Slic3r'):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
497 height = et.getroot().get('height').replace('m', '')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
498 width = et.getroot().get('width').replace('m', '')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
499
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
500 for i in et.findall("{http://www.w3.org/2000/svg}g"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
501 z = float(i.get('{http://slic3r.org/namespaces/slic3r}z'))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
502 zdiff = z - zlast
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
503 zlast = z
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
504
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
505 svgSnippet = xml.etree.ElementTree.Element('{http://www.w3.org/2000/svg}svg')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
506 svgSnippet.set('height', height + 'mm')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
507 svgSnippet.set('width', width + 'mm')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
508
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
509 svgSnippet.set('viewBox', '0 0 ' + width + ' ' + height)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
510 svgSnippet.set('style', 'background-color:black;fill:white;')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
511 svgSnippet.append(i)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
512
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
513 ol += [svgSnippet]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
514 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
515
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
516 slice_layers = et.findall("{http://www.w3.org/2000/svg}metadata")[0].findall("{http://www.reprap.org/slice}layers")[0]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
517 minX = slice_layers.get('minX')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
518 maxX = slice_layers.get('maxX')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
519 minY = slice_layers.get('minY')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
520 maxY = slice_layers.get('maxY')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
521
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
522 height = str(abs(float(minY)) + abs(float(maxY)))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
523 width = str(abs(float(minX)) + abs(float(maxX)))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
524
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
525 for g in et.findall("{http://www.w3.org/2000/svg}g")[0].findall("{http://www.w3.org/2000/svg}g"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
526
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
527 g.set('transform', '')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
528
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
529 text_element = g.findall("{http://www.w3.org/2000/svg}text")[0]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
530 g.remove(text_element)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
531
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
532 path_elements = g.findall("{http://www.w3.org/2000/svg}path")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
533 for p in path_elements:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
534 p.set('transform', 'translate(' + maxX + ',' + maxY + ')')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
535 p.set('fill', 'white')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
536
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
537 z = float(g.get('id').split("z:")[-1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
538 zdiff = z - zlast
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
539 zlast = z
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
540
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
541 svgSnippet = xml.etree.ElementTree.Element('{http://www.w3.org/2000/svg}svg')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
542 svgSnippet.set('height', height + 'mm')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
543 svgSnippet.set('width', width + 'mm')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
544
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
545 svgSnippet.set('viewBox', '0 0 ' + width + ' ' + height)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
546 svgSnippet.set('style', 'background-color:black;fill:white;')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
547 svgSnippet.append(g)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
548
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
549 ol += [svgSnippet]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
550 return ol, zdiff, slicer
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
551
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
552 def parse_3DLP_zip(self, name):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
553 if not zipfile.is_zipfile(name):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
554 raise Exception(name + " is not a zip file!")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
555 accepted_image_types = ['gif', 'tiff', 'jpg', 'jpeg', 'bmp', 'png']
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
556 zipFile = zipfile.ZipFile(name, 'r')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
557 self.image_dir = tempfile.mkdtemp()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
558 zipFile.extractall(self.image_dir)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
559 ol = []
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
560
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
561 # Note: the following funky code extracts any numbers from the filenames, matches
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
562 # them with the original then sorts them. It allows for filenames of the
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
563 # format: abc_1.png, which would be followed by abc_10.png alphabetically.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
564 os.chdir(self.image_dir)
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
565 vals = [f for f in os.listdir('.') if os.path.isfile(f)]
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
566 keys = (int(re.search('\d+', p).group()) for p in vals)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
567 imagefilesDict = dict(zip(keys, vals))
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
568 imagefilesOrderedDict = OrderedDict(sorted(imagefilesDict.items(), key = lambda t: t[0]))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
569
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
570 for f in imagefilesOrderedDict.values():
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
571 path = os.path.join(self.image_dir, f)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
572 if os.path.isfile(path) and imghdr.what(path) in accepted_image_types:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
573 ol.append(path)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
574
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
575 return ol, -1, "bitmap"
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
576
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
577 def load_file(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
578 dlg = wx.FileDialog(self, ("Open file to print"), style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
579 dlg.SetWildcard(("Slic3r or Skeinforge svg files (;*.svg;*.SVG;);3DLP Zip (;*.3dlp.zip;)"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
580 if dlg.ShowModal() == wx.ID_OK:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
581 name = dlg.GetPath()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
582 if not(os.path.exists(name)):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
583 self.status.SetStatusText(("File not found!"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
584 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
585 if name.endswith(".3dlp.zip"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
586 layers = self.parse_3DLP_zip(name)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
587 layerHeight = float(self.thickness.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
588 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
589 layers = self.parse_svg(name)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
590 layerHeight = layers[1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
591 self.thickness.SetValue(str(layers[1]))
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
592 print("Layer thickness detected:", layerHeight, "mm")
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
593 print(len(layers[0]), "layers found, total height", layerHeight * len(layers[0]), "mm")
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
594 self.layers = layers
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
595 self.set_total_layers(len(layers[0]))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
596 self.set_current_layer(0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
597 self.current_filename = os.path.basename(name)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
598 self.display_filename(self.current_filename)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
599 self.slicer = layers[2]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
600 self.display_frame.slicer = self.slicer
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
601 dlg.Destroy()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
602
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
603 def show_calibrate(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
604 if self.calibrate.IsChecked():
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
605 self.present_calibrate(event)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
606 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
607 if hasattr(self, 'layers'):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
608 self.display_frame.slicer = self.layers[2]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
609 self.display_frame.scale = float(self.scale.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
610 self.display_frame.clear_layer()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
611
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
612 def show_first_layer(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
613 if self.first_layer.IsChecked():
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
614 self.present_first_layer(event)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
615 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
616 if hasattr(self, 'layers'):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
617 self.display_frame.slicer = self.layers[2]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
618 self.display_frame.scale = float(self.scale.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
619 self.display_frame.clear_layer()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
620
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
621 def show_layer_red(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
622 self.display_frame.layer_red = self.layer_red.IsChecked()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
623
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
624 def present_calibrate(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
625 if self.calibrate.IsChecked():
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
626 self.display_frame.Raise()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
627 self.display_frame.offset = (float(self.offset_X.GetValue()), -float(self.offset_Y.GetValue()))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
628 self.display_frame.scale = 1.0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
629 resolution_x_pixels = int(self.X.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
630 resolution_y_pixels = int(self.Y.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
631
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
632 gridBitmap = wx.Bitmap(resolution_x_pixels, resolution_y_pixels)
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
633 dc = wx.MemoryDC()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
634 dc.SelectObject(gridBitmap)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
635 dc.SetBackground(wx.Brush("black"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
636 dc.Clear()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
637
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
638 dc.SetPen(wx.Pen("red", 7))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
639 dc.DrawLine(0, 0, resolution_x_pixels, 0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
640 dc.DrawLine(0, 0, 0, resolution_y_pixels)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
641 dc.DrawLine(resolution_x_pixels, 0, resolution_x_pixels, resolution_y_pixels)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
642 dc.DrawLine(0, resolution_y_pixels, resolution_x_pixels, resolution_y_pixels)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
643
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
644 dc.SetPen(wx.Pen("red", 2))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
645 aspectRatio = float(resolution_x_pixels) / float(resolution_y_pixels)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
646
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
647 projectedXmm = float(self.projected_X_mm.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
648 projectedYmm = round(projectedXmm / aspectRatio)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
649
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
650 pixelsXPerMM = resolution_x_pixels / projectedXmm
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
651 pixelsYPerMM = resolution_y_pixels / projectedYmm
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
652
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
653 gridCountX = int(projectedXmm / 10)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
654 gridCountY = int(projectedYmm / 10)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
655
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
656 for y in range(0, gridCountY + 1):
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
657 for x in range(0, gridCountX + 1):
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
658 dc.DrawLine(0, y * (pixelsYPerMM * 10), resolution_x_pixels, y * (pixelsYPerMM * 10))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
659 dc.DrawLine(x * (pixelsXPerMM * 10), 0, x * (pixelsXPerMM * 10), resolution_y_pixels)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
660
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
661 self.first_layer.SetValue(False)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
662 self.display_frame.slicer = 'bitmap'
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
663 self.display_frame.draw_layer(gridBitmap.ConvertToImage())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
664
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
665 def present_first_layer(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
666 if (self.first_layer.GetValue()):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
667 if not hasattr(self, "layers"):
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
668 print("No model loaded!")
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
669 self.first_layer.SetValue(False)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
670 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
671 self.display_frame.offset = (float(self.offset_X.GetValue()), float(self.offset_Y.GetValue()))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
672 self.display_frame.scale = float(self.scale.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
673
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
674 self.display_frame.slicer = self.layers[2]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
675 self.display_frame.dpi = self.get_dpi()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
676 self.display_frame.draw_layer(copy.deepcopy(self.layers[0][0]))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
677 self.calibrate.SetValue(False)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
678 if self.show_first_layer_timer != -1.0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
679 def unpresent_first_layer():
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
680 self.display_frame.clear_layer()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
681 self.first_layer.SetValue(False)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
682 wx.CallLater(self.show_first_layer_timer.GetValue() * 1000, unpresent_first_layer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
683
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
684 def update_offset(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
685
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
686 offset_x = float(self.offset_X.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
687 offset_y = float(self.offset_Y.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
688 self.display_frame.offset = (offset_x, offset_y)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
689
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
690 self._set_setting('project_offset_x', offset_x)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
691 self._set_setting('project_offset_y', offset_y)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
692
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
693 self.refresh_display(event)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
694
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
695 def refresh_display(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
696 self.present_calibrate(event)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
697 self.present_first_layer(event)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
698
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
699 def update_thickness(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
700 self._set_setting('project_layer', self.thickness.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
701 self.refresh_display(event)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
702
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
703 def update_projected_Xmm(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
704 self._set_setting('project_projected_x', self.projected_X_mm.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
705 self.refresh_display(event)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
706
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
707 def update_scale(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
708 scale = float(self.scale.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
709 self.display_frame.scale = scale
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
710 self._set_setting('project_scale', scale)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
711 self.refresh_display(event)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
712
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
713 def update_interval(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
714 interval = float(self.interval.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
715 self.display_frame.interval = interval
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
716 self._set_setting('project_interval', interval)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
717 self.set_estimated_time()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
718 self.refresh_display(event)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
719
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
720 def update_pause(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
721 pause = float(self.pause.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
722 self.display_frame.pause = pause
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
723 self._set_setting('project_pause', pause)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
724 self.set_estimated_time()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
725 self.refresh_display(event)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
726
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
727 def update_overshoot(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
728 overshoot = float(self.overshoot.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
729 self.display_frame.pause = overshoot
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
730 self._set_setting('project_overshoot', overshoot)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
731
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
732 def update_prelift_gcode(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
733 prelift_gcode = self.prelift_gcode.GetValue().replace('\n', "\\n")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
734 self.display_frame.prelift_gcode = prelift_gcode
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
735 self._set_setting('project_prelift_gcode', prelift_gcode)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
736
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
737 def update_postlift_gcode(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
738 postlift_gcode = self.postlift_gcode.GetValue().replace('\n', "\\n")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
739 self.display_frame.postlift_gcode = postlift_gcode
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
740 self._set_setting('project_postlift_gcode', postlift_gcode)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
741
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
742 def update_z_axis_rate(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
743 z_axis_rate = int(self.z_axis_rate.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
744 self.display_frame.z_axis_rate = z_axis_rate
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
745 self._set_setting('project_z_axis_rate', z_axis_rate)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
746
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
747 def update_direction(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
748 direction = self.direction.GetValue()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
749 self.display_frame.direction = direction
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
750 self._set_setting('project_direction', direction)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
751
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
752 def update_fullscreen(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
753 if (self.fullscreen.GetValue()):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
754 self.display_frame.ShowFullScreen(1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
755 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
756 self.display_frame.ShowFullScreen(0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
757 self.refresh_display(event)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
758
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
759 def update_resolution(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
760 x = int(self.X.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
761 y = int(self.Y.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
762 self.display_frame.resize((x, y))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
763 self._set_setting('project_x', x)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
764 self._set_setting('project_y', y)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
765 self.refresh_display(event)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
766
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
767 def get_dpi(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
768 resolution_x_pixels = int(self.X.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
769 projected_x_mm = float(self.projected_X_mm.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
770 projected_x_inches = projected_x_mm / 25.4
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
771
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
772 return resolution_x_pixels / projected_x_inches
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
773
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
774 def start_present(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
775 if not hasattr(self, "layers"):
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
776 print("No model loaded!")
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
777 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
778
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
779 self.pause_button.SetLabel("Pause")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
780 self.set_current_layer(0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
781 self.display_frame.Raise()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
782 if (self.fullscreen.GetValue()):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
783 self.display_frame.ShowFullScreen(1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
784 self.display_frame.slicer = self.layers[2]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
785 self.display_frame.dpi = self.get_dpi()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
786 self.display_frame.present(self.layers[0][:],
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
787 thickness = float(self.thickness.GetValue()),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
788 interval = float(self.interval.GetValue()),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
789 scale = float(self.scale.GetValue()),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
790 pause = float(self.pause.GetValue()),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
791 overshoot = float(self.overshoot.GetValue()),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
792 z_axis_rate = int(self.z_axis_rate.GetValue()),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
793 prelift_gcode = self.prelift_gcode.GetValue(),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
794 postlift_gcode = self.postlift_gcode.GetValue(),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
795 direction = self.direction.GetValue(),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
796 size = (float(self.X.GetValue()), float(self.Y.GetValue())),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
797 offset = (float(self.offset_X.GetValue()), float(self.offset_Y.GetValue())),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
798 layer_red = self.layer_red.IsChecked())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
799
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
800 def stop_present(self, event):
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
801 print("Stop")
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
802 self.pause_button.SetLabel("Pause")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
803 self.set_current_layer(0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
804 self.display_frame.running = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
805
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
806 def pause_present(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
807 if self.pause_button.GetLabel() == 'Pause':
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
808 print("Pause")
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
809 self.pause_button.SetLabel("Continue")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
810 self.display_frame.running = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
811 else:
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
812 print("Continue")
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
813 self.pause_button.SetLabel("Pause")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
814 self.display_frame.running = True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
815 self.display_frame.next_img()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
816
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
817 if __name__ == "__main__":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
818 provider = wx.SimpleHelpProvider()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
819 wx.HelpProvider_Set(provider)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
820 a = wx.App()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
821 SettingsFrame(None).Show()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
822 a.MainLoop()

mercurial