printrun-src/printrun/projectlayer.py

Thu, 30 May 2019 19:02:52 +0200

author
mdd
date
Thu, 30 May 2019 19:02:52 +0200
changeset 42
ea4c43494a19
parent 15
0bbb006204fc
child 46
cce0af6351f0
permissions
-rw-r--r--

bugfixes on rastered image column endings, force laser off with G0 + little offset

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

mercurial