Commit c2072b38 authored by Guillaume Seguin's avatar Guillaume Seguin

New feature: inject G-Code at beginning of layer in live

parent 77c4428e
images/inject.png

3.83 KB | W: | H:

images/inject.png

1.39 KB | W: | H:

images/inject.png
images/inject.png
images/inject.png
images/inject.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -219,6 +219,34 @@ class GCode(object):
def __iter__(self):
return self.lines.__iter__()
def prepend_to_layer(self, commands, layer_idx):
# Prepend commands in reverse order
commands = [c.strip() for c in commands[::-1] if c.strip()]
layer = self.all_layers[layer_idx]
# Find start index to append lines
# and end index to append new indices
start_index = self.layer_idxs.index(layer_idx)
for i in range(start_index, len(self.layer_idxs)):
if self.layer_idxs[i] != layer_idx:
end_index = i
break
else:
end_index = i + 1
end_line = self.line_idxs[end_index - 1]
for i, command in enumerate(commands):
gline = Line(command)
# Split to get command
split(gline)
# Force is_move to False
gline.is_move = False
# Insert gline at beginning of layer
layer.insert(0, gline)
# Insert gline at beginning of list
self.lines.insert(start_index, gline)
# Update indices arrays & global gcodes list
self.layer_idxs.insert(end_index + i, layer_idx)
self.line_idxs.insert(end_index + i, end_line + i + 1)
def append(self, command, store = True):
command = command.strip()
if not command:
......
......@@ -21,6 +21,7 @@ from . import gcoder
from .gl.panel import wxGLPanel
from .gl.trackball import build_rotmatrix
from .gl.libtatlin import actors
from .injectgcode import injector
from pyglet.gl import glPushMatrix, glPopMatrix, \
glTranslatef, glRotatef, glScalef, glMultMatrixd
......@@ -86,6 +87,14 @@ class GcodeViewPanel(wxGLPanel):
self.basequat = [0, 0, 0, 1]
self.mousepos = [0, 0]
def inject(self):
l = self.parent.model.num_layers_to_draw
filtered = [k for k, v in self.parent.model.layer_idxs_map.iteritems() if v == l]
if filtered:
injector(self.parent.model.gcode, l, filtered[0])
else:
print _("Invalid layer for injection")
def setlayercb(self, layer):
pass
......@@ -376,7 +385,7 @@ class GcodeViewFrame(GvizBaseFrame, GcodeViewLoader):
self.objects = [GCObject(self.platform), GCObject(None)]
fit_image = wx.Image(imagefile('fit.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap()
self.toolbar.AddLabelTool(6, " " + _("Fit to plate"), fit_image,
self.toolbar.InsertLabelTool(6, 6, " " + _("Fit to plate"), fit_image,
shortHelp = _("Fit to plate [F]"),
longHelp = '')
self.toolbar.Realize()
......@@ -391,7 +400,8 @@ class GcodeViewFrame(GvizBaseFrame, GcodeViewLoader):
self.Bind(wx.EVT_TOOL, lambda x: self.glpanel.layerup(), id = 3)
self.Bind(wx.EVT_TOOL, lambda x: self.glpanel.layerdown(), id = 4)
self.Bind(wx.EVT_TOOL, lambda x: self.glpanel.resetview(), id = 5)
self.Bind(wx.EVT_TOOL, lambda x: self.glpanel.fit(), id = 6)
self.Bind(wx.EVT_TOOL, lambda x: self.glpanel.fit(), id = 7)
self.Bind(wx.EVT_TOOL, lambda x: self.glpanel.inject(), id = 6)
def process_slider(self, event):
new_layer = self.layerslider.GetValue()
......
......@@ -17,7 +17,8 @@ from Queue import Queue
from collections import deque
import wx
import time
from printrun import gcoder
from . import gcoder
from .injectgcode import injector
from .utils import imagefile, install_locale, get_home_pos
install_locale('pronterface')
......@@ -42,6 +43,8 @@ class GvizBaseFrame(wx.Frame):
self.toolbar.AddSimpleTool(3, wx.Image(imagefile('arrow_up.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _("Move Up a Layer [U]"), '')
self.toolbar.AddSimpleTool(4, wx.Image(imagefile('arrow_down.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _("Move Down a Layer [D]"), '')
self.toolbar.AddLabelTool(5, " " + _("Reset view"), wx.Image(imagefile('reset.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), shortHelp = _("Reset view"), longHelp = '')
self.toolbar.AddSeparator()
self.toolbar.AddLabelTool(6, " " + _("Inject G-Code"), wx.Image(imagefile('inject.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), shortHelp = _("Inject G-Code"), longHelp = _("Insert code at the beginning of this layer"))
vbox.Add(self.toolbar, 0, border = 5)
......@@ -71,8 +74,6 @@ class GvizWindow(GvizBaseFrame):
self.p = Gviz(panel, size = size, build_dimensions = build_dimensions, grid = grid, extrusion_width = extrusion_width, bgcolor = bgcolor, realparent = self)
self.toolbar.AddSeparator()
# self.toolbar.AddSimpleTool(6, wx.Image(imagefile('inject.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _("Insert Code at start of this layer"), '')
self.toolbar.Realize()
vbox.Add(self.p, 1, wx.EXPAND)
......@@ -82,7 +83,7 @@ class GvizWindow(GvizBaseFrame):
self.Bind(wx.EVT_TOOL, lambda x: self.p.layerup(), id = 3)
self.Bind(wx.EVT_TOOL, lambda x: self.p.layerdown(), id = 4)
self.Bind(wx.EVT_TOOL, self.resetview, id = 5)
# self.Bind(wx.EVT_TOOL, lambda x:self.p.inject(), id = 6)
self.Bind(wx.EVT_TOOL, lambda x: self.p.inject(), id = 6)
self.initpos = None
self.p.Bind(wx.EVT_KEY_DOWN, self.key)
......@@ -201,9 +202,8 @@ class Gviz(wx.Panel):
self.paint_overlay = None
def inject(self):
# import pdb; pdb.set_trace()
print "Inject code here..."
print "Layer " + str(self.layerindex + 1) + " - Z = " + str(self.get_currentz()) + " mm"
layer = self.layers.index(self.layerindex)
injector(self.gcode, self.layerindex, layer)
def clearhilights(self):
self.hilight.clear()
......@@ -214,6 +214,7 @@ class Gviz(wx.Panel):
self.hilightarcsqueue.get_nowait()
def clear(self):
self.gcode = None
self.lastpos = [0, 0, 0, 0, 0, 0, 0]
self.hilightpos = self.lastpos[:]
self.gcoder = gcoder.GCode([], get_home_pos(self.build_dimensions))
......@@ -408,6 +409,7 @@ class Gviz(wx.Panel):
def addfile_perlayer(self, gcode, showall = False):
self.clear()
self.gcode = gcode
self.showall = showall
generator = self.add_parsed_gcodes(gcode)
generator_output = generator.next()
......
# This file is part of the Printrun suite.
#
# Printrun is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Printrun is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Printrun. If not, see <http://www.gnu.org/licenses/>.
from .gui.widgets import MacroEditor
def injector(gcode, viz_layer, layer_idx):
cb = lambda toadd: inject(gcode, layer_idx, toadd)
z = gcode.all_layers[layer_idx].z
z = z if z is not None else 0
MacroEditor(_("Inject G-Code at layer %d (Z = %.03f)") % (viz_layer, z), "", cb, True)
def inject(gcode, layer_idx, toadd):
# TODO: save modifier gcode after injection ?
gcode.prepend_to_layer(toadd, layer_idx)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment