Commit f2ae0f22 authored by D1plo1d's avatar D1plo1d

Merge branch 'master' of github.com:kliment/Printrun

parents ebab8d6c 02d41450
...@@ -67,6 +67,9 @@ class GcodeViewPanel(wxGLPanel): ...@@ -67,6 +67,9 @@ class GcodeViewPanel(wxGLPanel):
self.create_objects() self.create_objects()
glPushMatrix() glPushMatrix()
if self.orthographic:
glTranslatef(0, 0, -3 * self.dist) # Move back
else:
glTranslatef(0, 0, -self.dist) # Move back glTranslatef(0, 0, -self.dist) # Move back
glMultMatrixd(build_rotmatrix(self.basequat)) # Rotate according to trackball glMultMatrixd(build_rotmatrix(self.basequat)) # Rotate according to trackball
glTranslatef(- self.build_dimensions[3] - self.parent.platform.width/2, glTranslatef(- self.build_dimensions[3] - self.parent.platform.width/2,
...@@ -171,10 +174,10 @@ class GcodeViewPanel(wxGLPanel): ...@@ -171,10 +174,10 @@ class GcodeViewPanel(wxGLPanel):
if event.ShiftDown(): if event.ShiftDown():
if not self.parent.model: if not self.parent.model:
return return
if delta > 0: count = 1 if not event.ControlDown() else 10
self.layerup() for i in range(count):
else: if delta > 0: self.layerup()
self.layerdown() else: self.layerdown()
return return
x, y = event.GetPositionTuple() x, y = event.GetPositionTuple()
x, y, _ = self.mouse_to_3d(x, y) x, y, _ = self.mouse_to_3d(x, y)
...@@ -207,6 +210,7 @@ class GcodeViewPanel(wxGLPanel): ...@@ -207,6 +210,7 @@ class GcodeViewPanel(wxGLPanel):
kzi = [wx.WXK_PAGEDOWN, 388, 316, 61] # Zoom In Keys kzi = [wx.WXK_PAGEDOWN, 388, 316, 61] # Zoom In Keys
kzo = [wx.WXK_PAGEUP, 390, 314, 45] # Zoom Out Keys kzo = [wx.WXK_PAGEUP, 390, 314, 45] # Zoom Out Keys
kfit = [70] # Fit to print keys kfit = [70] # Fit to print keys
kshowcurrent = [67] # Show only current layer keys
kreset = [82] # Reset keys kreset = [82] # Reset keys
key = event.GetKeyCode() key = event.GetKeyCode()
if key in kup: if key in kup:
...@@ -220,6 +224,10 @@ class GcodeViewPanel(wxGLPanel): ...@@ -220,6 +224,10 @@ class GcodeViewPanel(wxGLPanel):
self.zoom(1 / step, (x, y)) self.zoom(1 / step, (x, y))
if key in kfit: if key in kfit:
self.fit() self.fit()
if key in kshowcurrent:
if not self.parent.model or not self.parent.model.loaded:
return
self.parent.model.only_current = not self.parent.model.only_current
if key in kreset: if key in kreset:
self.reset_mview(0.9) self.reset_mview(0.9)
self.basequat = [0, 0, 0, 1] self.basequat = [0, 0, 0, 1]
......
...@@ -242,9 +242,9 @@ class GcodeModel(Model): ...@@ -242,9 +242,9 @@ class GcodeModel(Model):
color_travel = (0.6, 0.6, 0.6, 0.6) color_travel = (0.6, 0.6, 0.6, 0.6)
color_tool0 = (1.0, 0.0, 0.0, 0.6) color_tool0 = (1.0, 0.0, 0.0, 0.6)
color_tool1 = (0.0, 0.0, 1.0, 0.6) color_tool1 = (0.31, 0.05, 0.9, 0.6)
color_printed = (0.2, 0.75, 0, 0.6) color_printed = (0.2, 0.75, 0, 0.6)
color_current = (0.6, 0.3, 0, 0.8) color_current = (0, 0.9, 1.0, 0.8)
color_current_printed = (0.1, 0.4, 0, 0.8) color_current_printed = (0.1, 0.4, 0, 0.8)
use_vbos = True use_vbos = True
...@@ -289,6 +289,7 @@ class GcodeModel(Model): ...@@ -289,6 +289,7 @@ class GcodeModel(Model):
self.max_layers = len(self.layer_stops) - 1 self.max_layers = len(self.layer_stops) - 1
self.num_layers_to_draw = self.max_layers self.num_layers_to_draw = self.max_layers
self.printed_until = -1 self.printed_until = -1
self.only_current = False
self.initialized = False self.initialized = False
self.loaded = True self.loaded = True
...@@ -299,7 +300,7 @@ class GcodeModel(Model): ...@@ -299,7 +300,7 @@ class GcodeModel(Model):
def copy(self): def copy(self):
copy = GcodeModel() copy = GcodeModel()
for var in ["vertices", "colors", "max_layers", "num_layers_to_draw", "printed_until", "layer_stops", "dims"]: for var in ["vertices", "colors", "max_layers", "num_layers_to_draw", "printed_until", "layer_stops", "dims", "only_current"]:
setattr(copy, var, getattr(self, var)) setattr(copy, var, getattr(self, var))
copy.loaded = True copy.loaded = True
copy.initialized = False copy.initialized = False
...@@ -365,6 +366,7 @@ class GcodeModel(Model): ...@@ -365,6 +366,7 @@ class GcodeModel(Model):
# Draw printed stuff until end or end_prev_layer # Draw printed stuff until end or end_prev_layer
cur_end = min(self.printed_until, end) cur_end = min(self.printed_until, end)
if not self.only_current:
if 0 <= end_prev_layer <= cur_end: if 0 <= end_prev_layer <= cur_end:
glDrawArrays(GL_LINES, start, end_prev_layer) glDrawArrays(GL_LINES, start, end_prev_layer)
elif cur_end >= 0: elif cur_end >= 0:
...@@ -375,6 +377,7 @@ class GcodeModel(Model): ...@@ -375,6 +377,7 @@ class GcodeModel(Model):
# Draw nonprinted stuff until end_prev_layer # Draw nonprinted stuff until end_prev_layer
start = max(cur_end, 0) start = max(cur_end, 0)
if end_prev_layer >= start: if end_prev_layer >= start:
if not self.only_current:
glDrawArrays(GL_LINES, start, end_prev_layer - start) glDrawArrays(GL_LINES, start, end_prev_layer - start)
cur_end = end_prev_layer cur_end = end_prev_layer
...@@ -405,7 +408,7 @@ class GcodeModel(Model): ...@@ -405,7 +408,7 @@ class GcodeModel(Model):
# Draw non printed stuff until end (if not ending at a given layer) # Draw non printed stuff until end (if not ending at a given layer)
start = max(self.printed_until, 0) start = max(self.printed_until, 0)
end = end - start end = end - start
if end_prev_layer < 0 and end > 0: if end_prev_layer < 0 and end > 0 and not self.only_current:
glDrawArrays(GL_LINES, start, end) glDrawArrays(GL_LINES, start, end)
self.vertex_buffer.unbind() self.vertex_buffer.unbind()
......
...@@ -44,6 +44,9 @@ class wxGLPanel(wx.Panel): ...@@ -44,6 +44,9 @@ class wxGLPanel(wx.Panel):
glcanvas.WX_GL_DOUBLEBUFFER, # Double Buffered glcanvas.WX_GL_DOUBLEBUFFER, # Double Buffered
glcanvas.WX_GL_DEPTH_SIZE, 24) # 24 bit glcanvas.WX_GL_DEPTH_SIZE, 24) # 24 bit
self.width = None
self.height = None
self.sizer = wx.BoxSizer(wx.HORIZONTAL) self.sizer = wx.BoxSizer(wx.HORIZONTAL)
self.canvas = glcanvas.GLCanvas(self, attribList = attribList) self.canvas = glcanvas.GLCanvas(self, attribList = attribList)
self.context = glcanvas.GLContext(self.canvas) self.context = glcanvas.GLContext(self.canvas)
...@@ -61,12 +64,10 @@ class wxGLPanel(wx.Panel): ...@@ -61,12 +64,10 @@ class wxGLPanel(wx.Panel):
def processSizeEvent(self, event): def processSizeEvent(self, event):
'''Process the resize event.''' '''Process the resize event.'''
size = self.GetClientSize()
self.width, self.height = size.width, size.height
if (wx.VERSION > (2,9) and self.canvas.IsShownOnScreen()) or self.canvas.GetContext(): if (wx.VERSION > (2,9) and self.canvas.IsShownOnScreen()) or self.canvas.GetContext():
# Make sure the frame is shown before calling SetCurrent. # Make sure the frame is shown before calling SetCurrent.
self.canvas.SetCurrent(self.context) self.canvas.SetCurrent(self.context)
self.OnReshape(size.width, size.height) self.OnReshape()
self.canvas.Refresh(False) self.canvas.Refresh(False)
event.Skip() event.Skip()
...@@ -74,24 +75,24 @@ class wxGLPanel(wx.Panel): ...@@ -74,24 +75,24 @@ class wxGLPanel(wx.Panel):
'''Process the drawing event.''' '''Process the drawing event.'''
self.canvas.SetCurrent(self.context) self.canvas.SetCurrent(self.context)
if not self.GLinitialized:
self.OnInitGL() self.OnInitGL()
self.GLinitialized = True
self.OnDraw() self.OnDraw()
event.Skip() event.Skip()
def Destroy(self): def Destroy(self):
#clean up the pyglet OpenGL context # clean up the pyglet OpenGL context
self.pygletcontext.destroy() self.pygletcontext.destroy()
#call the super method # call the super method
super(wx.Panel, self).Destroy() super(wxGLPanel, self).Destroy()
#========================================================================== #==========================================================================
# GLFrame OpenGL Event Handlers # GLFrame OpenGL Event Handlers
#========================================================================== #==========================================================================
def OnInitGL(self): def OnInitGL(self, call_reshape = True):
'''Initialize OpenGL for use in the window.''' '''Initialize OpenGL for use in the window.'''
if self.GLinitialized:
return
self.GLinitialized = True
#create a pyglet context for this panel #create a pyglet context for this panel
self.pygletcontext = gl.Context(gl.current_context) self.pygletcontext = gl.Context(gl.current_context)
self.pygletcontext.canvas = self self.pygletcontext.canvas = self
...@@ -105,24 +106,33 @@ class wxGLPanel(wx.Panel): ...@@ -105,24 +106,33 @@ class wxGLPanel(wx.Panel):
glEnable(GL_CULL_FACE) glEnable(GL_CULL_FACE)
glEnable(GL_BLEND) glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
self.OnReshape(*self.GetClientSize()) if call_reshape:
self.OnReshape()
def OnReshape(self, width, height): def OnReshape(self):
'''Reshape the OpenGL viewport based on the dimensions of the window.''' '''Reshape the OpenGL viewport based on the dimensions of the window.'''
if not self.GLinitialized: size = self.GetClientSize()
self.GLinitialized = True oldwidth, oldheight = self.width, self.height
self.OnInitGL() width, height = size.width, size.height
self.width = max(float(width), 1.0)
self.height = max(float(height), 1.0)
self.OnInitGL(call_reshape = False)
glViewport(0, 0, width, height) glViewport(0, 0, width, height)
glMatrixMode(GL_PROJECTION) glMatrixMode(GL_PROJECTION)
glLoadIdentity() glLoadIdentity()
if self.orthographic: if self.orthographic:
glOrtho(-width / 2, width / 2, -height / 2, height / 2, 0.1, 3 * self.dist) glOrtho(-width / 2, width / 2, -height / 2, height / 2, 0.1, 5 * self.dist)
else: else:
gluPerspective(60., float(width) / height, 10.0, 3 * self.dist) gluPerspective(60., float(width) / height, 10.0, 3 * self.dist)
glMatrixMode(GL_MODELVIEW)
if not self.mview_initialized: if not self.mview_initialized:
self.reset_mview(0.9) self.reset_mview(0.9)
self.mview_initialized = True self.mview_initialized = True
elif oldwidth is not None and oldheight is not None:
factor = min(self.width / oldwidth, self.height / oldheight)
x, y, _ = self.mouse_to_3d(self.width / 2, self.height / 2)
self.zoom(factor, (x, y))
# Wrap text to the width of the window # Wrap text to the width of the window
if self.GLinitialized: if self.GLinitialized:
......
...@@ -81,17 +81,20 @@ class StlViewPanel(wxGLPanel): ...@@ -81,17 +81,20 @@ class StlViewPanel(wxGLPanel):
wx.CallAfter(self.forceresize) wx.CallAfter(self.forceresize)
self.mousepos = (0, 0) self.mousepos = (0, 0)
def OnReshape(self, width, height): def OnReshape(self):
self.mview_initialized = False self.mview_initialized = False
super(StlViewPanel, self).OnReshape(width, height) super(StlViewPanel, self).OnReshape()
#========================================================================== #==========================================================================
# GLFrame OpenGL Event Handlers # GLFrame OpenGL Event Handlers
#========================================================================== #==========================================================================
def OnInitGL(self): def OnInitGL(self, call_reshape = True):
'''Initialize OpenGL for use in the window.''' '''Initialize OpenGL for use in the window.'''
if self.GLinitialized:
return
self.GLinitialized = True
#create a pyglet context for this panel #create a pyglet context for this panel
self.pygletcontext = Context(current_context) self.pygletcontext = gl.Context(gl.current_context)
self.pygletcontext.canvas = self self.pygletcontext.canvas = self
self.pygletcontext.set_current() self.pygletcontext.set_current()
#normal gl init #normal gl init
...@@ -124,6 +127,8 @@ class StlViewPanel(wxGLPanel): ...@@ -124,6 +127,8 @@ class StlViewPanel(wxGLPanel):
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, vec(1, 1, 1, 1)) glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, vec(1, 1, 1, 1))
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50) glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50)
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, vec(0, 0.1, 0, 0.9)) glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, vec(0, 0.1, 0, 0.9))
if call_reshape:
self.OnReshape()
if self.parent.filenames: if self.parent.filenames:
for filename in self.parent.filenames: for filename in self.parent.filenames:
self.parent.load_file(None, filename) self.parent.load_file(None, filename)
......
...@@ -402,16 +402,12 @@ class EventEmitter(object): ...@@ -402,16 +402,12 @@ class EventEmitter(object):
continue continue
# Fast GCode. Because the GCode class is slow. # Faster GCoder implementation without any parsing
# ------------------------------------------------- # -------------------------------------------------
class PyLine(object): class Line(object):
__slots__ = ('x','y','z','e','f','i','j', __slots__ = ('raw', 'command', 'is_move')
'raw', 'command', 'is_move',
'relative','relative_e',
'current_x', 'current_y', 'current_z', 'extruding', 'current_tool',
'gcview_end_vertex')
def __init__(self, l): def __init__(self, l):
self.raw = l self.raw = l
...@@ -419,12 +415,6 @@ class PyLine(object): ...@@ -419,12 +415,6 @@ class PyLine(object):
def __getattr__(self, name): def __getattr__(self, name):
return None return None
try:
from printrun import gcoder_line
Line = gcoder_line.GLine
except ImportError:
Line = PyLine
class FastGCode(object): class FastGCode(object):
def __init__(self,data): def __init__(self,data):
self.lines = [Line(l2) for l2 in self.lines = [Line(l2) for l2 in
......
...@@ -24,8 +24,10 @@ from distutils.command.install_data import install_data as _install_data ...@@ -24,8 +24,10 @@ from distutils.command.install_data import install_data as _install_data
try: try:
from Cython.Build import cythonize from Cython.Build import cythonize
extensions = cythonize("printrun/gcoder_line.pyx") extensions = cythonize("printrun/gcoder_line.pyx")
from Cython.Distutils import build_ext
except ImportError: except ImportError:
extensions = None extensions = None
build_ext = None
INSTALLED_FILES = "installed_files" INSTALLED_FILES = "installed_files"
...@@ -142,6 +144,12 @@ for extra_data_dir in extra_data_dirs: ...@@ -142,6 +144,12 @@ for extra_data_dir in extra_data_dirs:
destpath = os.path.join("share", "pronterface", basedir) destpath = os.path.join("share", "pronterface", basedir)
data_files.append ((destpath, files)) data_files.append ((destpath, files))
cmdclass = {"uninstall" : uninstall,
"install" : install,
"install_data" : install_data}
if build_ext:
cmdclass['build_ext'] = build_ext
setup ( setup (
name = "Printrun", name = "Printrun",
description = "Host software for 3D printers", description = "Host software for 3D printers",
...@@ -151,8 +159,6 @@ setup ( ...@@ -151,8 +159,6 @@ setup (
data_files = data_files, data_files = data_files,
packages = ["printrun", "printrun.cairosvg", "printrun.server", "printrun.gl", "printrun.gl.libtatlin"], packages = ["printrun", "printrun.cairosvg", "printrun.server", "printrun.gl", "printrun.gl.libtatlin"],
scripts = ["pronsole.py", "pronterface.py", "plater.py", "printcore.py", "prontserve.py"], scripts = ["pronsole.py", "pronterface.py", "plater.py", "printcore.py", "prontserve.py"],
cmdclass = {"uninstall" : uninstall, cmdclass = cmdclass,
"install" : install,
"install_data" : install_data},
ext_modules = extensions, ext_modules = extensions,
) )
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