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