36 panel = wx.Panel(hpanel, -1) |
36 panel = wx.Panel(hpanel, -1) |
37 vbox = wx.BoxSizer(wx.VERTICAL) |
37 vbox = wx.BoxSizer(wx.VERTICAL) |
38 |
38 |
39 vbox = wx.BoxSizer(wx.VERTICAL) |
39 vbox = wx.BoxSizer(wx.VERTICAL) |
40 self.toolbar = wx.ToolBar(panel, -1, style = wx.TB_HORIZONTAL | wx.NO_BORDER | wx.TB_HORZ_TEXT) |
40 self.toolbar = wx.ToolBar(panel, -1, style = wx.TB_HORIZONTAL | wx.NO_BORDER | wx.TB_HORZ_TEXT) |
41 self.toolbar.AddSimpleTool(1, wx.Image(imagefile('zoom_in.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _("Zoom In [+]"), '') |
41 self.toolbar.AddTool(1, '', wx.Image(imagefile('zoom_in.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _("Zoom In [+]"),) |
42 self.toolbar.AddSimpleTool(2, wx.Image(imagefile('zoom_out.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _("Zoom Out [-]"), '') |
42 self.toolbar.AddTool(2, '', wx.Image(imagefile('zoom_out.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _("Zoom Out [-]")) |
43 self.toolbar.AddSeparator() |
43 self.toolbar.AddSeparator() |
44 self.toolbar.AddSimpleTool(3, wx.Image(imagefile('arrow_up.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _("Move Up a Layer [U]"), '') |
44 self.toolbar.AddTool(3, '', wx.Image(imagefile('arrow_up.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _("Move Up a Layer [U]")) |
45 self.toolbar.AddSimpleTool(4, wx.Image(imagefile('arrow_down.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _("Move Down a Layer [D]"), '') |
45 self.toolbar.AddTool(4, '', wx.Image(imagefile('arrow_down.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _("Move Down a Layer [D]")) |
46 self.toolbar.AddLabelTool(5, " " + _("Reset view"), wx.Image(imagefile('reset.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), shortHelp = _("Reset view"), longHelp = '') |
46 self.toolbar.AddTool(5, " " + _("Reset view"), wx.Image(imagefile('reset.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), shortHelp = _("Reset view")) |
47 self.toolbar.AddSeparator() |
47 self.toolbar.AddSeparator() |
48 self.toolbar.AddSimpleTool(6, wx.Image(imagefile('inject.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), shortHelpString = _("Inject G-Code"), longHelpString = _("Insert code at the beginning of this layer")) |
48 self.toolbar.AddTool(6, '', wx.Image(imagefile('inject.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), wx.NullBitmap, shortHelp = _("Inject G-Code"), longHelp = _("Insert code at the beginning of this layer")) |
49 self.toolbar.AddSimpleTool(7, wx.Image(imagefile('edit.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), shortHelpString = _("Edit layer"), longHelpString = _("Edit the G-Code of this layer")) |
49 self.toolbar.AddTool(7, '', wx.Image(imagefile('edit.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), wx.NullBitmap, shortHelp = _("Edit layer"), longHelp = _("Edit the G-Code of this layer")) |
50 |
50 |
51 vbox.Add(self.toolbar, 0, border = 5) |
51 vbox.Add(self.toolbar, 0, border = 5) |
52 |
52 |
53 panel.SetSizer(vbox) |
53 panel.SetSizer(vbox) |
54 |
54 |
118 def mouse(self, event): |
118 def mouse(self, event): |
119 if event.ButtonUp(wx.MOUSE_BTN_LEFT) or event.ButtonUp(wx.MOUSE_BTN_RIGHT): |
119 if event.ButtonUp(wx.MOUSE_BTN_LEFT) or event.ButtonUp(wx.MOUSE_BTN_RIGHT): |
120 if self.initpos is not None: |
120 if self.initpos is not None: |
121 self.initpos = None |
121 self.initpos = None |
122 elif event.Dragging(): |
122 elif event.Dragging(): |
123 e = event.GetPositionTuple() |
123 e = event.GetPosition() |
124 if self.initpos is None: |
124 if self.initpos is None: |
125 self.initpos = e |
125 self.initpos = e |
126 self.basetrans = self.p.translate |
126 self.basetrans = self.p.translate |
127 self.p.translate = [self.basetrans[0] + (e[0] - self.initpos[0]), |
127 self.p.translate = [self.basetrans[0] + (e[0] - self.initpos[0]), |
128 self.basetrans[1] + (e[1] - self.initpos[1])] |
128 self.basetrans[1] + (e[1] - self.initpos[1])] |
155 elif z < 0: self.p.layerup() |
155 elif z < 0: self.p.layerup() |
156 else: |
156 else: |
157 if z > 0: self.p.zoom(event.GetX(), event.GetY(), 1.2) |
157 if z > 0: self.p.zoom(event.GetX(), event.GetY(), 1.2) |
158 elif z < 0: self.p.zoom(event.GetX(), event.GetY(), 1 / 1.2) |
158 elif z < 0: self.p.zoom(event.GetX(), event.GetY(), 1 / 1.2) |
159 |
159 |
160 class Gviz(wx.Panel): |
160 from printrun.gui.viz import BaseViz |
|
161 class Gviz(wx.Panel, BaseViz): |
161 |
162 |
162 # Mark canvas as dirty when setting showall |
163 # Mark canvas as dirty when setting showall |
163 _showall = 0 |
164 _showall = 0 |
164 |
165 |
165 def _get_showall(self): |
166 def _get_showall(self): |
195 self.translate = [0.0, 0.0] |
196 self.translate = [0.0, 0.0] |
196 self.mainpen = wx.Pen(wx.Colour(0, 0, 0), penwidth) |
197 self.mainpen = wx.Pen(wx.Colour(0, 0, 0), penwidth) |
197 self.arcpen = wx.Pen(wx.Colour(255, 0, 0), penwidth) |
198 self.arcpen = wx.Pen(wx.Colour(255, 0, 0), penwidth) |
198 self.travelpen = wx.Pen(wx.Colour(10, 80, 80), penwidth) |
199 self.travelpen = wx.Pen(wx.Colour(10, 80, 80), penwidth) |
199 self.hlpen = wx.Pen(wx.Colour(200, 50, 50), penwidth) |
200 self.hlpen = wx.Pen(wx.Colour(200, 50, 50), penwidth) |
200 self.fades = [wx.Pen(wx.Colour(250 - 0.6 ** i * 100, 250 - 0.6 ** i * 100, 200 - 0.4 ** i * 50), penwidth) for i in xrange(6)] |
201 self.fades = [wx.Pen(wx.Colour(int(250 - 0.6 ** i * 100), int(250 - 0.6 ** i * 100), int(200 - 0.4 ** i * 50)), penwidth) for i in range(6)] |
201 self.penslist = [self.mainpen, self.travelpen, self.hlpen] + self.fades |
202 self.penslist = [self.mainpen, self.arcpen, self.travelpen, self.hlpen] + self.fades |
202 self.bgcolor = wx.Colour() |
203 self.bgcolor = wx.Colour() |
203 self.bgcolor.SetFromName(bgcolor) |
204 self.bgcolor.Set(bgcolor) |
204 self.blitmap = wx.EmptyBitmap(self.GetClientSize()[0], self.GetClientSize()[1], -1) |
205 self.blitmap = wx.Bitmap(self.GetClientSize()[0], self.GetClientSize()[1], -1) |
205 self.paint_overlay = None |
206 self.paint_overlay = None |
206 |
207 |
207 def inject(self): |
208 def inject(self): |
208 layer = self.layers.index(self.layerindex) |
209 layer = self.layers[self.layerindex] |
209 injector(self.gcode, self.layerindex, layer) |
210 injector(self.gcode, self.layerindex, layer) |
210 |
211 |
211 def editlayer(self): |
212 def editlayer(self): |
212 layer = self.layers.index(self.layerindex) |
213 layer = self.layers[self.layerindex] |
213 injector_edit(self.gcode, self.layerindex, layer) |
214 injector_edit(self.gcode, self.layerindex, layer) |
214 |
215 |
215 def clearhilights(self): |
216 def clearhilights(self): |
216 self.hilight.clear() |
217 self.hilight.clear() |
217 self.hilightarcs.clear() |
218 self.hilightarcs.clear() |
273 self.basescale = 2 * [min(float(self.size[0] - 1) / self.build_dimensions[0], |
274 self.basescale = 2 * [min(float(self.size[0] - 1) / self.build_dimensions[0], |
274 float(self.size[1] - 1) / self.build_dimensions[1])] |
275 float(self.size[1] - 1) / self.build_dimensions[1])] |
275 |
276 |
276 def resize(self, event): |
277 def resize(self, event): |
277 old_basescale = self.basescale |
278 old_basescale = self.basescale |
278 width, height = self.GetClientSizeTuple() |
279 width, height = self.GetClientSize() |
279 if width < 1 or height < 1: |
280 if width < 1 or height < 1: |
280 return |
281 return |
281 self.size = (width, height) |
282 self.size = (width, height) |
282 self.update_basescale() |
283 self.update_basescale() |
283 zoomratio = float(self.basescale[0]) / old_basescale[0] |
284 zoomratio = float(self.basescale[0]) / old_basescale[0] |
310 self.scale[1] * x[3], |
311 self.scale[1] * x[3], |
311 self.scale[0] * x[4], |
312 self.scale[0] * x[4], |
312 self.scale[1] * x[5],) |
313 self.scale[1] * x[5],) |
313 |
314 |
314 def _drawlines(self, dc, lines, pens): |
315 def _drawlines(self, dc, lines, pens): |
315 scaled_lines = map(self._line_scaler, lines) |
316 scaled_lines = [self._line_scaler(l) for l in lines] |
316 dc.DrawLineList(scaled_lines, pens) |
317 dc.DrawLineList(scaled_lines, pens) |
317 |
318 |
318 def _drawarcs(self, dc, arcs, pens): |
319 def _drawarcs(self, dc, arcs, pens): |
319 scaled_arcs = map(self._arc_scaler, arcs) |
320 scaled_arcs = [self._arc_scaler(a) for a in arcs] |
320 dc.SetBrush(wx.TRANSPARENT_BRUSH) |
321 dc.SetBrush(wx.TRANSPARENT_BRUSH) |
321 for i in range(len(scaled_arcs)): |
322 for i in range(len(scaled_arcs)): |
322 dc.SetPen(pens[i] if type(pens) == list else pens) |
323 dc.SetPen(pens[i] if isinstance(pens, numpy.ndarray) else pens) |
323 dc.DrawArc(*scaled_arcs[i]) |
324 dc.DrawArc(*scaled_arcs[i]) |
324 |
325 |
325 def repaint_everything(self): |
326 def repaint_everything(self): |
326 width = self.scale[0] * self.build_dimensions[0] |
327 width = self.scale[0] * self.build_dimensions[0] |
327 height = self.scale[1] * self.build_dimensions[1] |
328 height = self.scale[1] * self.build_dimensions[1] |
328 self.blitmap = wx.EmptyBitmap(width + 1, height + 1, -1) |
329 self.blitmap = wx.Bitmap(width + 1, height + 1, -1) |
329 dc = wx.MemoryDC() |
330 dc = wx.MemoryDC() |
330 dc.SelectObject(self.blitmap) |
331 dc.SelectObject(self.blitmap) |
331 dc.SetBackground(wx.Brush((250, 250, 200))) |
332 dc.SetBackground(wx.Brush((250, 250, 200))) |
332 dc.Clear() |
333 dc.Clear() |
333 dc.SetPen(wx.Pen(wx.Colour(180, 180, 150))) |
334 dc.SetPen(wx.Pen(wx.Colour(180, 180, 150))) |
334 for grid_unit in self.grid: |
335 for grid_unit in self.grid: |
335 if grid_unit > 0: |
336 if grid_unit > 0: |
336 for x in xrange(int(self.build_dimensions[0] / grid_unit) + 1): |
337 for x in range(int(self.build_dimensions[0] / grid_unit) + 1): |
337 draw_x = self.scale[0] * x * grid_unit |
338 draw_x = self.scale[0] * x * grid_unit |
338 dc.DrawLine(draw_x, 0, draw_x, height) |
339 dc.DrawLine(draw_x, 0, draw_x, height) |
339 for y in xrange(int(self.build_dimensions[1] / grid_unit) + 1): |
340 for y in range(int(self.build_dimensions[1] / grid_unit) + 1): |
340 draw_y = self.scale[1] * (self.build_dimensions[1] - y * grid_unit) |
341 draw_y = self.scale[1] * (self.build_dimensions[1] - y * grid_unit) |
341 dc.DrawLine(0, draw_y, width, draw_y) |
342 dc.DrawLine(0, draw_y, width, draw_y) |
342 dc.SetPen(wx.Pen(wx.Colour(0, 0, 0))) |
343 dc.SetPen(wx.Pen(wx.Colour(0, 0, 0))) |
343 |
344 |
344 if not self.showall: |
345 if not self.showall: |
416 def addfile_perlayer(self, gcode, showall = False): |
417 def addfile_perlayer(self, gcode, showall = False): |
417 self.clear() |
418 self.clear() |
418 self.gcode = gcode |
419 self.gcode = gcode |
419 self.showall = showall |
420 self.showall = showall |
420 generator = self.add_parsed_gcodes(gcode) |
421 generator = self.add_parsed_gcodes(gcode) |
421 generator_output = generator.next() |
422 generator_output = next(generator) |
422 while generator_output is not None: |
423 while generator_output is not None: |
423 yield generator_output |
424 yield generator_output |
424 generator_output = generator.next() |
425 generator_output = next(generator) |
425 max_layers = len(self.layers) |
426 max_layers = len(self.layers) |
426 if hasattr(self.parent, "layerslider"): |
427 if hasattr(self.parent, "layerslider"): |
427 self.parent.layerslider.SetRange(0, max_layers - 1) |
428 self.parent.layerslider.SetRange(0, max_layers - 1) |
428 self.parent.layerslider.SetValue(0) |
429 self.parent.layerslider.SetValue(0) |
429 yield None |
430 yield None |
430 |
431 |
431 def addfile(self, gcode = None, showall = False): |
432 def addfile(self, gcode = None, showall = False): |
432 generator = self.addfile_perlayer(gcode, showall) |
433 generator = self.addfile_perlayer(gcode, showall) |
433 while generator.next() is not None: |
434 while next(generator) is not None: |
434 continue |
435 continue |
435 |
436 |
436 def _get_movement(self, start_pos, gline): |
437 def _get_movement(self, start_pos, gline): |
437 """Takes a start position and a gcode, and returns a 3-uple containing |
438 """Takes a start position and a gcode, and returns a 3-uple containing |
438 (final position, line, arc), with line and arc being None if not |
439 (final position, line, arc), with line and arc being None if not |
499 |
500 |
500 target, line, arc = self._get_movement(self.lastpos[:], gline) |
501 target, line, arc = self._get_movement(self.lastpos[:], gline) |
501 |
502 |
502 if line is not None: |
503 if line is not None: |
503 self.lines[viz_layer].append(line) |
504 self.lines[viz_layer].append(line) |
504 self.pens[viz_layer].append(self.mainpen if target[3] != self.lastpos[3] else self.travelpen) |
505 self.pens[viz_layer].append(self.mainpen if target[3] != self.lastpos[3] or gline.extruding else self.travelpen) |
505 elif arc is not None: |
506 elif arc is not None: |
506 self.arcs[viz_layer].append(arc) |
507 self.arcs[viz_layer].append(arc) |
507 self.arcpens[viz_layer].append(self.arcpen) |
508 self.arcpens[viz_layer].append(self.arcpen) |
508 |
509 |
509 self.lastpos = target |
510 self.lastpos = target |