chiark / gitweb /
Modified gcodeInterperter to use an object for the path parts, instead of a dict...
authordaid <daid303@gmail.com>
Mon, 26 Mar 2012 15:14:31 +0000 (17:14 +0200)
committerdaid <daid303@gmail.com>
Mon, 26 Mar 2012 15:14:31 +0000 (17:14 +0200)
Cura/newui/gcodeInterpreter.py
Cura/newui/preview3d.py

index bc591cf96ba3354a7c1f2f379b0e5d4a4c4fe888..5424cfea3865e4f8e91ead8dcbc92c45408db10d 100644 (file)
@@ -9,6 +9,13 @@ import os
 
 from newui import util3d
 
+class gcodePath():
+       def __init__(self, newType, pathType, layerNr, startPoint):
+               self.type = newType
+               self.pathType = pathType
+               self.list = [startPoint]
+               self.layerNr = layerNr
+
 class gcode():
        def __init__(self):
                self.regMatch = {}
@@ -35,8 +42,9 @@ class gcode():
                pathType = 'CUSTOM';
                layerNr = 0;    #Note layer 0 will be the start code.
                startCodeDone = False
-               currentPath = {'type': 'move', 'pathType': pathType, 'list': [pos.copy()], 'layerNr': layerNr}
-               currentPath['list'][-1].e = totalExtrusion
+               currentPath = gcodePath('move', pathType, layerNr, pos.copy())
+               currentPath.list[0].e = totalExtrusion
+               pathList.append(currentPath)
                for line in gcodeFile:
                        if filePos != gcodeFile.tell():
                                filePos = gcodeFile.tell()
@@ -105,11 +113,12 @@ class gcode():
                                                        currentE += e
                                                if totalExtrusion > maxExtrusion:
                                                        maxExtrusion = totalExtrusion
-                                       if currentPath['type'] != moveType or currentPath['pathType'] != pathType:
+                                       if currentPath.type != moveType or currentPath.pathType != pathType:
+                                               currentPath = gcodePath(moveType, pathType, layerNr, currentPath.list[-1])
                                                pathList.append(currentPath)
-                                               currentPath = {'type': moveType, 'pathType': pathType, 'list': [currentPath['list'][-1]], 'layerNr': layerNr}
-                                       currentPath['list'].append(pos.copy())
-                                       currentPath['list'][-1].e = totalExtrusion
+                                       newPos = pos.copy()
+                                       newPos.e = totalExtrusion
+                                       currentPath.list.append(newPos)
                                elif G == 20:   #Units are inches
                                        scale = 25.4
                                elif G == 21:   #Units are mm
index 679f05b4a5f814f03de2c23e1921484c6a0ff7eb..e9421df80b3d2d83047f86a0db56a23963c0b201 100644 (file)
@@ -444,35 +444,35 @@ class PreviewGLCanvas(glcanvas.GLCanvas):
                                \r
                                curLayerNum = 0\r
                                for path in self.parent.gcode.pathList:\r
-                                       if path['layerNr'] != curLayerNum:\r
+                                       if path.layerNr != curLayerNum:\r
                                                prevLayerZ = curLayerZ\r
-                                               curLayerZ = path['list'][1].z\r
-                                               curLayerNum = path['layerNr']\r
+                                               curLayerZ = path.list[1].z\r
+                                               curLayerNum = path.layerNr\r
                                                layerThickness = curLayerZ - prevLayerZ\r
                                        \r
                                        c = 1.0\r
-                                       if path['layerNr'] != self.parent.layerSpin.GetValue():\r
-                                               if path['layerNr'] < self.parent.layerSpin.GetValue():\r
-                                                       c = 0.9 - (self.parent.layerSpin.GetValue() - path['layerNr']) * 0.1\r
+                                       if path.layerNr != self.parent.layerSpin.GetValue():\r
+                                               if path.layerNr < self.parent.layerSpin.GetValue():\r
+                                                       c = 0.9 - (self.parent.layerSpin.GetValue() - path.layerNr) * 0.1\r
                                                        if c < 0.4:\r
                                                                c = 0.4\r
                                                else:\r
                                                        break\r
-                                       if path['type'] == 'move':\r
+                                       if path.type == 'move':\r
                                                glColor3f(0,0,c)\r
-                                       if path['type'] == 'extrude':\r
-                                               if path['pathType'] == 'FILL':\r
+                                       if path.type == 'extrude':\r
+                                               if path.pathType == 'FILL':\r
                                                        glColor3f(c/2,c/2,0)\r
-                                               elif path['pathType'] == 'WALL-INNER':\r
+                                               elif path.pathType == 'WALL-INNER':\r
                                                        glColor3f(0,c,0)\r
                                                else:\r
                                                        glColor3f(c,0,0)\r
-                                       if path['type'] == 'retract':\r
+                                       if path.type == 'retract':\r
                                                glColor3f(0,c,c)\r
-                                       if c > 0.4 and path['type'] == 'extrude':\r
-                                               for i in xrange(0, len(path['list'])-1):\r
-                                                       v0 = path['list'][i]\r
-                                                       v1 = path['list'][i+1]\r
+                                       if c > 0.4 and path.type == 'extrude':\r
+                                               for i in xrange(0, len(path.list)-1):\r
+                                                       v0 = path.list[i]\r
+                                                       v1 = path.list[i+1]\r
 \r
                                                        # Calculate line width from ePerDistance (needs layer thickness and filament diameter)\r
                                                        dist = (v0 - v1).vsize()\r
@@ -488,7 +488,7 @@ class PreviewGLCanvas(glcanvas.GLCanvas):
                                                        v1 = v1 - normal * lineWidth\r
 \r
                                                        glBegin(GL_QUADS)\r
-                                                       if path['pathType'] == 'FILL':  #Remove depth buffer fighting on infill/wall overlap\r
+                                                       if path.pathType == 'FILL':     #Remove depth buffer fighting on infill/wall overlap\r
                                                                glVertex3f(v0.x, v0.y, v0.z - 0.02)\r
                                                                glVertex3f(v1.x, v1.y, v1.z - 0.02)\r
                                                                glVertex3f(v3.x, v3.y, v3.z - 0.02)\r
@@ -511,7 +511,7 @@ class PreviewGLCanvas(glcanvas.GLCanvas):
                                                #       glEnd()\r
                                        else:\r
                                                glBegin(GL_LINE_STRIP)\r
-                                               for v in path['list']:\r
+                                               for v in path.list:\r
                                                        glVertex3f(v.x, v.y, v.z)\r
                                                glEnd()\r
                                glEndList()\r