chiark / gitweb /
Merge branch 'SteamEngine' of github.com:daid/Cura into SteamEngine
authordaid303 <daid303@gmail.com>
Thu, 18 Apr 2013 14:02:35 +0000 (16:02 +0200)
committerdaid303 <daid303@gmail.com>
Thu, 18 Apr 2013 14:02:35 +0000 (16:02 +0200)
Cura/gui/sceneView.py
Cura/gui/util/opengl.py
Cura/util/gcodeInterpreter.py
Cura/util/sliceEngine.py

index c50b6091577d5bda1a86ec43bfb3cf616d0d04e7..59ee0e09469d2f8107bdce6b32e5454b08eb4349 100644 (file)
@@ -34,6 +34,7 @@ class SceneView(openglGui.glGuiPanel):
                self._zoom = 300
                self._scene = objectScene.Scene()
                self._gcode = None
+               self._gcodeVBOs = []
                self._objectShader = None
                self._focusObj = None
                self._selectedObj = None
@@ -309,11 +310,15 @@ class SceneView(openglGui.glGuiPanel):
        def _updateSliceProgress(self, progressValue, ready):
                self.printButton.setDisabled(not ready)
                self.printButton.setProgressBar(progressValue)
+               if self._gcode is not None:
+                       self._gcode = None
+                       for layerVBOlist in self._gcodeVBOs:
+                               for vbo in layerVBOlist:
+                                       self.glReleaseList.append(vbo)
+                       self._gcodeVBOs = []
                if ready:
                        self._gcode = gcodeInterpreter.gcode()
                        self._gcode.load(self._slicer.getGCodeFilename())
-               else:
-                       self._gcode = None
                self.QueueRefresh()
 
        def loadScene(self, fileList):
@@ -658,8 +663,23 @@ void main(void)
 
                                glPushMatrix()
                                glTranslate(-self._machineSize[0] / 2, -self._machineSize[1] / 2, 0)
+                               t = time.time()
                                for n in xrange(0, self.layerSelect.getValue() + 1):
-                                       opengl.DrawGCodeLayer(self._gcode.layerList[n])
+                                       if len(self._gcodeVBOs) < n + 1:
+                                               self._gcodeVBOs.append(self._generateGCodeVBOs(self._gcode.layerList[n]))
+                                               if time.time() - t > 0.5:
+                                                       self.QueueRefresh()
+                                                       break
+                                       #['WALL-OUTER', 'WALL-INNER', 'FILL', 'SUPPORT', 'SKIRT']
+                                       glColor3f(1, 0, 0)
+                                       self._gcodeVBOs[n][0].render(GL_LINES)
+                                       glColor3f(0, 1, 0)
+                                       self._gcodeVBOs[n][1].render(GL_LINES)
+                                       glColor3f(0.5, 0.5, 0.0)
+                                       self._gcodeVBOs[n][2].render(GL_LINES)
+                                       glColor3f(0, 1, 1)
+                                       self._gcodeVBOs[n][3].render(GL_LINES)
+                                       self._gcodeVBOs[n][4].render(GL_LINES)
                                glPopMatrix()
                else:
                        glStencilFunc(GL_ALWAYS, 1, 1)
@@ -829,6 +849,19 @@ void main(void)
                glDisable(GL_BLEND)
                glDisable(GL_CULL_FACE)
 
+       def _generateGCodeVBOs(self, layer):
+               ret = []
+               for extrudeType in ['WALL-OUTER', 'WALL-INNER', 'FILL', 'SUPPORT', 'SKIRT']:
+                       pointList = numpy.zeros((0,3), numpy.float32)
+                       for path in layer:
+                               if path.type == 'extrude' and path.pathType == extrudeType:
+                                       a = numpy.array(path.points, numpy.float32)
+                                       a = numpy.concatenate((a[:-1], a[1:]), 1)
+                                       a = a.reshape((len(a) * 2, 3))
+                                       pointList = numpy.concatenate((pointList, a))
+                       ret.append(opengl.GLVBO(pointList))
+               return ret
+
        def getObjectCenterPos(self):
                if self._selectedObj is None:
                        return [0.0, 0.0, 0.0]
index cb86cde5c1a08f1ba80252727a369ceab854b2c3..ae9b64f17c04f6106c7d38d65ad4f959b83099bb 100644 (file)
@@ -78,22 +78,30 @@ class GLShader(GLReferenceCounter):
                        print "Shader was not properly released!"
 
 class GLVBO(GLReferenceCounter):
-       def __init__(self, vertexArray, normalArray):
+       def __init__(self, vertexArray, normalArray = None):
                super(GLVBO, self).__init__()
                self._buffer = glGenBuffers(1)
                self._size = len(vertexArray)
+               self._hasNormals = normalArray is not None
                glBindBuffer(GL_ARRAY_BUFFER, self._buffer)
-               glBufferData(GL_ARRAY_BUFFER, numpy.concatenate((vertexArray, normalArray), 1), GL_STATIC_DRAW)
+               if self._hasNormals:
+                       glBufferData(GL_ARRAY_BUFFER, numpy.concatenate((vertexArray, normalArray), 1), GL_STATIC_DRAW)
+               else:
+                       glBufferData(GL_ARRAY_BUFFER, vertexArray, GL_STATIC_DRAW)
                glBindBuffer(GL_ARRAY_BUFFER, 0)
 
        def render(self, render_type = GL_TRIANGLES):
                glEnableClientState(GL_VERTEX_ARRAY)
-               glEnableClientState(GL_NORMAL_ARRAY)
                glBindBuffer(GL_ARRAY_BUFFER, self._buffer)
-               glVertexPointer(3, GL_FLOAT, 2*3*4, c_void_p(0))
-               glNormalPointer(GL_FLOAT, 2*3*4, c_void_p(3 * 4))
 
-               batchSize = 999    #Warning, batchSize needs to be dividable by 3
+               if self._hasNormals:
+                       glEnableClientState(GL_NORMAL_ARRAY)
+                       glVertexPointer(3, GL_FLOAT, 2*3*4, c_void_p(0))
+                       glNormalPointer(GL_FLOAT, 2*3*4, c_void_p(3 * 4))
+               else:
+                       glVertexPointer(3, GL_FLOAT, 3*4, c_void_p(0))
+
+               batchSize = 1002    #Warning, batchSize needs to be dividable by 3 and 2
                extraStartPos = int(self._size / batchSize) * batchSize
                extraCount = self._size - extraStartPos
 
@@ -101,8 +109,10 @@ class GLVBO(GLReferenceCounter):
                        glDrawArrays(render_type, i * batchSize, batchSize)
                glDrawArrays(render_type, extraStartPos, extraCount)
                glBindBuffer(GL_ARRAY_BUFFER, 0)
+
                glDisableClientState(GL_VERTEX_ARRAY)
-               glDisableClientState(GL_NORMAL_ARRAY)
+               if self._hasNormals:
+                       glDisableClientState(GL_NORMAL_ARRAY)
 
        def release(self):
                if self._buffer is not None:
@@ -581,7 +591,6 @@ def DrawMeshSteep(mesh, matrix, angle):
                        glEnd()
        glDepthFunc(GL_LESS)
 
-
 def DrawGCodeLayer(layer, drawQuick = True):
        filamentRadius = profile.getProfileSettingFloat('filament_diameter') / 2
        filamentArea = math.pi * filamentRadius * filamentRadius
@@ -625,9 +634,9 @@ def DrawGCodeLayer(layer, drawQuick = True):
                if path.type == 'extrude' and not drawQuick:
                        drawLength = 0.0
                        prevNormal = None
-                       for i in xrange(0, len(path.list) - 1):
-                               v0 = path.list[i]
-                               v1 = path.list[i + 1]
+                       for i in xrange(0, len(path.points) - 1):
+                               v0 = path.points[i]
+                               v1 = path.points[i + 1]
 
                                # Calculate line width from ePerDistance (needs layer thickness and filament diameter)
                                dist = (v0 - v1).vsize()
@@ -673,13 +682,14 @@ def DrawGCodeLayer(layer, drawQuick = True):
                                prevVv1 = vv1
                                prevVv3 = vv3
                else:
-                       glBegin(GL_LINE_STRIP)
                        glColor4fv(c)
-                       for v in path.list:
-                               glVertex3f(v.x, v.y, v.z)
+                       glBegin(GL_TRIANGLES)
+                       for v in path.points:
+                               glVertex3f(v[0], v[1], v[2])
                        glEnd()
+
                if not path.type == 'move':
                        prevPathWasRetract = False
-               if path.type == 'retract' and path.list[0].almostEqual(path.list[-1]):
-                       prevPathWasRetract = True
+               #if path.type == 'retract' and path.points[0].almostEqual(path.points[-1]):
+               #       prevPathWasRetract = True
        glEnable(GL_CULL_FACE)
index 638645136979f3f8aebbd5b511652ee0865fd4c8..5348c3cef010ff5fd0d19804b70d6720bc4e9134 100644 (file)
@@ -5,7 +5,6 @@ import math
 import os
 import time
 
-from Cura.util import util3d
 from Cura.util import profile
 
 class gcodePath(object):
@@ -13,7 +12,8 @@ class gcodePath(object):
                self.type = newType
                self.pathType = pathType
                self.layerThickness = layerThickness
-               self.list = [startPoint]
+               self.points = [startPoint]
+               self.extrusion = [0]
 
 class gcode(object):
        def __init__(self):
@@ -51,8 +51,8 @@ class gcode(object):
                return None
        
        def _load(self, gcodeFile):
-               pos = util3d.Vector3()
-               posOffset = util3d.Vector3()
+               pos = [0.0, 0.0, 0.0]
+               posOffset = [0.0, 0.0, 0.0]
                currentE = 0.0
                totalExtrusion = 0.0
                maxExtrusion = 0.0
@@ -62,14 +62,13 @@ class gcode(object):
                absoluteE = True
                scale = 1.0
                posAbs = True
-               feedRate = 3600
+               feedRate = 3600.0
                layerThickness = 0.1
                pathType = 'CUSTOM';
                currentLayer = []
-               currentPath = gcodePath('move', pathType, layerThickness, pos.copy())
+               currentPath = gcodePath('move', pathType, layerThickness, pos[:])
                currentPath.extruder = currentExtruder
-               currentPath.list[0].e = totalExtrusion
-               currentPath.list[0].extrudeAmountMultiply = extrudeAmountMultiply
+
                currentLayer.append(currentPath)
                for line in gcodeFile:
                        if type(line) is tuple:
@@ -100,12 +99,12 @@ class gcode(object):
                        T = getCodeInt(line, 'T')
                        if T is not None:
                                if currentExtruder > 0:
-                                       posOffset.x -= profile.getPreferenceFloat('extruder_offset_x%d' % (currentExtruder))
-                                       posOffset.y -= profile.getPreferenceFloat('extruder_offset_y%d' % (currentExtruder))
+                                       posOffset[0] -= profile.getPreferenceFloat('extruder_offset_x%d' % (currentExtruder))
+                                       posOffset[1] -= profile.getPreferenceFloat('extruder_offset_y%d' % (currentExtruder))
                                currentExtruder = T
                                if currentExtruder > 0:
-                                       posOffset.x += profile.getPreferenceFloat('extruder_offset_x%d' % (currentExtruder))
-                                       posOffset.y += profile.getPreferenceFloat('extruder_offset_y%d' % (currentExtruder))
+                                       posOffset[0] += profile.getPreferenceFloat('extruder_offset_x%d' % (currentExtruder))
+                                       posOffset[1] += profile.getPreferenceFloat('extruder_offset_y%d' % (currentExtruder))
                        
                        G = getCodeInt(line, 'G')
                        if G is not None:
@@ -115,56 +114,59 @@ class gcode(object):
                                        z = getCodeFloat(line, 'Z')
                                        e = getCodeFloat(line, 'E')
                                        f = getCodeFloat(line, 'F')
-                                       oldPos = pos.copy()
+                                       oldPos = pos[:]
                                        if posAbs:
                                                if x is not None:
-                                                       pos.x = x * scale + posOffset.x
+                                                       pos[0] = x * scale + posOffset[0]
                                                if y is not None:
-                                                       pos.y = y * scale + posOffset.y
+                                                       pos[1] = y * scale + posOffset[1]
                                                if z is not None:
-                                                       pos.z = z * scale + posOffset.z
+                                                       pos[2] = z * scale + posOffset[2]
                                        else:
                                                if x is not None:
-                                                       pos.x += x * scale
+                                                       pos[0] += x * scale
                                                if y is not None:
-                                                       pos.y += y * scale
+                                                       pos[1] += y * scale
                                                if z is not None:
-                                                       pos.z += z * scale
+                                                       pos[2] += z * scale
                                        if f is not None:
                                                feedRate = f
-                                       if x is not None or y is not None or z is not None:
-                                               totalMoveTimeMinute += math.sqrt((oldPos.x - pos.x) * (oldPos.x - pos.x) + (oldPos.y - pos.y) * (oldPos.y - pos.y)) / feedRate
+                                       #if x is not None or y is not None or z is not None:
+                                       #       diffX = oldPos[0] - pos[0]
+                                       #       diffY = oldPos[1] - pos[1]
+                                       #       totalMoveTimeMinute += math.sqrt(diffX * diffX + diffY * diffY) / feedRate
                                        moveType = 'move'
                                        if e is not None:
-                                               if not absoluteE:
-                                                       e += currentE
-                                               if e > currentE:
+                                               if absoluteE:
+                                                       e -= currentE
+                                               if e > 0:
                                                        moveType = 'extrude'
-                                               if e < currentE:
+                                               if e < 0:
                                                        moveType = 'retract'
-                                               totalExtrusion += e - currentE
-                                               currentE = e
+                                               totalExtrusion += e
+                                               currentE += e
                                                if totalExtrusion > maxExtrusion:
                                                        maxExtrusion = totalExtrusion
-                                       if moveType == 'move' and oldPos.z != pos.z:
-                                               if oldPos.z > pos.z and abs(oldPos.z - pos.z) > 5.0 and pos.z < 1.0:
-                                                       oldPos.z = 0.0
-                                               layerThickness = abs(oldPos.z - pos.z)
+                                       else:
+                                               e = 0.0
+                                       if moveType == 'move' and oldPos[2] != pos[2]:
+                                               if oldPos[2] > pos[2] and abs(oldPos[2] - pos[2]) > 5.0 and pos[2] < 1.0:
+                                                       oldPos[2] = 0.0
+                                               layerThickness = abs(oldPos[2] - pos[2])
                                        if currentPath.type != moveType or currentPath.pathType != pathType:
-                                               currentPath = gcodePath(moveType, pathType, layerThickness, currentPath.list[-1])
+                                               currentPath = gcodePath(moveType, pathType, layerThickness, currentPath.points[-1])
                                                currentPath.extruder = currentExtruder
                                                currentLayer.append(currentPath)
-                                       newPos = pos.copy()
-                                       newPos.e = totalExtrusion
-                                       newPos.extrudeAmountMultiply = extrudeAmountMultiply
-                                       currentPath.list.append(newPos)
+
+                                       currentPath.points.append(pos[:])
+                                       currentPath.extrusion.append(e * extrudeAmountMultiply)
                                elif G == 4:    #Delay
                                        S = getCodeFloat(line, 'S')
                                        if S is not None:
-                                               totalMoveTimeMinute += S / 60
+                                               totalMoveTimeMinute += S / 60.0
                                        P = getCodeFloat(line, 'P')
                                        if P is not None:
-                                               totalMoveTimeMinute += P / 60 / 1000
+                                               totalMoveTimeMinute += P / 60.0 / 1000.0
                                elif G == 20:   #Units are inches
                                        scale = 25.4
                                elif G == 21:   #Units are mm
@@ -174,14 +176,14 @@ class gcode(object):
                                        y = getCodeFloat(line, 'Y')
                                        z = getCodeFloat(line, 'Z')
                                        if x is None and y is None and z is None:
-                                               pos = util3d.Vector3()
+                                               pos = [0.0,0.0,0.0]
                                        else:
                                                if x is not None:
-                                                       pos.x = 0.0
+                                                       pos[0] = 0.0
                                                if y is not None:
-                                                       pos.y = 0.0
+                                                       pos[0] = 0.0
                                                if z is not None:
-                                                       pos.z = 0.0
+                                                       pos[0] = 0.0
                                elif G == 90:   #Absolute position
                                        posAbs = True
                                elif G == 91:   #Relative position
@@ -194,11 +196,11 @@ class gcode(object):
                                        if e is not None:
                                                currentE = e
                                        if x is not None:
-                                               posOffset.x = pos.x - x
+                                               posOffset[0] = pos[0] - x
                                        if y is not None:
-                                               posOffset.y = pos.y - y
+                                               posOffset[1] = pos[1] - y
                                        if z is not None:
-                                               posOffset.z = pos.z - z
+                                               posOffset[2] = pos[2] - z
                                else:
                                        print "Unknown G code:" + str(G)
                        else:
@@ -248,7 +250,7 @@ class gcode(object):
                                                pass
                                        elif M == 221:  #Extrude amount multiplier
                                                s = getCodeFloat(line, 'S')
-                                               if s != None:
+                                               if s is not None:
                                                        extrudeAmountMultiply = s / 100.0
                                        else:
                                                print "Unknown M code:" + str(M)
index 6281b57cf1412ec8f2c7933509c4916f9f0d7b4c..eafa941778824b088e1ae8abd9e89570fa8bb012 100644 (file)
@@ -100,7 +100,7 @@ class Slicer(object):
                                line = line.split(':')
                                if line[1] == 'process':
                                        objectNr += 1
-                               else:
+                               elif line[1] in self._progressSteps:
                                        progressValue = float(line[2]) / float(line[3])
                                        progressValue /= len(self._progressSteps)
                                        progressValue += 1.0 / len(self._progressSteps) * self._progressSteps.index(line[1])