def parseLine( self, line ): "Parse a gcode line and add it to the commented gcode." self.characters += len( line ) self.numberOfLines += 1 splitLine = line.split( ' ' ) if len( splitLine ) < 1: return firstWord = splitLine[ 0 ] if firstWord == 'G1': self.linearMove( splitLine ) elif firstWord == 'G2': self.helicalMove( False, splitLine ) elif firstWord == 'G3': self.helicalMove( True, splitLine ) elif firstWord == 'M100': self.extruderSpeed = gcodec.getDoubleAfterFirstLetter( splitLine[ 1 ] ) elif firstWord == 'M101': self.extruderSet( True ) elif firstWord == 'M103': self.extruderSet( False ) elif firstWord == '(<extrusionDiameter>': self.extrusionDiameter = gcodec.getDoubleAfterFirstLetter( splitLine[ 1 ] ) elif firstWord == '(<extrusionWidth>': self.extrusionWidth = gcodec.getDoubleAfterFirstLetter( splitLine[ 1 ] ) elif firstWord == '(<layerThickness>': self.layerThickness = gcodec.getDoubleAfterFirstLetter( splitLine[ 1 ] ) elif firstWord == '(<procedureDone>': self.procedures.append( splitLine[ 1 ][ 1 : ] )
def parseLine(self, line): "Parse a gcode line and add it to the commented gcode." self.characters += len(line) self.numberOfLines += 1 splitLine = line.split(' ') if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1': self.linearMove(splitLine) elif firstWord == 'G2': self.helicalMove(False, splitLine) elif firstWord == 'G3': self.helicalMove(True, splitLine) elif firstWord == 'M100': self.extruderSpeed = gcodec.getDoubleAfterFirstLetter(splitLine[1]) elif firstWord == 'M101': self.extruderSet(True) elif firstWord == 'M103': self.extruderSet(False) elif firstWord == '(<extrusionDiameter>': self.extrusionDiameter = gcodec.getDoubleAfterFirstLetter( splitLine[1]) elif firstWord == '(<extrusionWidth>': self.extrusionWidth = gcodec.getDoubleAfterFirstLetter( splitLine[1]) elif firstWord == '(<layerThickness>': self.layerThickness = gcodec.getDoubleAfterFirstLetter( splitLine[1]) elif firstWord == '(<procedureDone>': self.procedures.append(splitLine[1][1:])
def parseLine( self, line ): "Parse a gcode line." self.shouldAddLine = True splitLine = line.split( ' ' ) if len( splitLine ) < 1: return 0 firstWord = splitLine[ 0 ] if firstWord == 'G1': self.linearMove( splitLine ) if firstWord == 'M101': self.extruderActive = True if firstWord == 'M103': self.extruderActive = False self.loop = None elif firstWord == 'M109': self.halfExtrusionWidth = 0.5 * gcodec.getDoubleAfterFirstLetter( splitLine[ 1 ] ) elif firstWord == 'M115': self.layer = None self.loop = None elif firstWord == 'M117': if len( splitLine ) > 1: if splitLine[ 1 ][ 1 : ] == 'edge': self.isLoop = True elif firstWord == 'M118': self.fillInset = gcodec.getDoubleAfterFirstLetter( splitLine[ 1 ] )
def parseLine(self, line): "Parse a gcode line." self.shouldAddLine = True splitLine = line.split(' ') if len(splitLine) < 1: return 0 firstWord = splitLine[0] if firstWord == 'G1': self.linearMove(splitLine) if firstWord == 'M101': self.extruderActive = True if firstWord == 'M103': self.extruderActive = False self.loop = None elif firstWord == 'M109': self.halfExtrusionWidth = 0.5 * gcodec.getDoubleAfterFirstLetter( splitLine[1]) elif firstWord == 'M115': self.layer = None self.loop = None elif firstWord == 'M117': if len(splitLine) > 1: if splitLine[1][1:] == 'edge': self.isLoop = True elif firstWord == 'M118': self.fillInset = gcodec.getDoubleAfterFirstLetter(splitLine[1])
def parseLine( self, line ): "Parse a gcode line and add it to the commented gcode." splitLine = line.split( ' ' ) if len( splitLine ) < 1: return firstWord = splitLine[ 0 ] if firstWord == 'G1': self.linearMove( splitLine ) elif firstWord == 'G2': self.setHelicalMoveEndpoint( splitLine ) self.addComment( "Helical clockwise move to " + str( self.oldLocation ) + "." ) elif firstWord == 'G3': self.setHelicalMoveEndpoint( splitLine ) self.addComment( "Helical counterclockwise move to " + str( self.oldLocation ) + "." ) elif firstWord == 'G21': self.addComment( "Set units to mm." ) elif firstWord == 'G28': self.addComment( "Start at home." ) elif firstWord == 'G90': self.addComment( "Set positioning to absolute." ) elif firstWord == 'M100': self.addComment( "Set extruder speed to " + str( gcodec.getDoubleAfterFirstLetter( splitLine[ 1 ] ) ) + "." ) elif firstWord == 'M101': self.addComment( "Turn extruder on." ); elif firstWord == 'M103': self.addComment( "Turn extruder off." ) elif firstWord == 'M104': self.addComment( "Set temperature to " + str( gcodec.getDoubleAfterFirstLetter( splitLine[ 1 ] ) ) + " C." ) elif firstWord == 'M105': self.addComment( "Custom code for temperature reading." ) elif firstWord == 'M106': self.addComment( "Turn fan on." ) elif firstWord == 'M107': self.addComment( "Turn fan off." ) elif firstWord == '(<extrusionDiameter>': self.addComment( "Set extrusion diameter to " + str( gcodec.getDoubleAfterFirstLetter( splitLine[ 1 ] ) ) + " mm." ) elif firstWord == '(<extrusionWidth>': self.addComment( "Set extrusion width to " + str( gcodec.getDoubleAfterFirstLetter( splitLine[ 1 ] ) ) + " mm." ) elif firstWord == '(<layerThickness>': self.addComment( "Set layer thickness to " + str( gcodec.getDoubleAfterFirstLetter( splitLine[ 1 ] ) ) + " mm." ) elif firstWord == '(<procedureDone>': self.addComment( "The " + splitLine[ 1 ][ 1 : ] + " procedure has been performed." ) elif firstWord == '(<extrusionStart>': self.addComment( "Initialization is finished, extrusion is starting." ) elif firstWord == '(<layerStart>': self.addComment( "New layer is starting." ) elif firstWord == '(<loop>': self.addComment( "Loop is starting." ) self.output.write( line + "\n" )
def parseLine(self, lineIndex): "Parse a gcode line." line = self.lines[lineIndex] splitLine = line.split(' ') if len(splitLine) < 1: return 0 firstWord = splitLine[0] if firstWord == 'G1': self.linearMove(splitLine) self.lastBeforeExtrusionLines = self.beforeExtrusionLines self.beforeExtrusionLines = None if firstWord == 'M101': self.extruderActive = True elif firstWord == 'M103': self.extruderActive = False self.thread = None elif firstWord == '(<extrusionWidth>': self.extrusionWidth = gcodec.getDoubleAfterFirstLetter( splitLine[1]) elif firstWord == '(<layerStart>': self.beforeExtrusionLines = [] self.threadLayer = None self.thread = None elif firstWord == '(<loop>': self.isLoop = True if len(splitLine) > 1: if splitLine[1] == 'edge': self.isEdge = True elif firstWord == '(<extruderShutDown>': self.shutdownLineIndex = lineIndex if self.beforeExtrusionLines != None: self.beforeExtrusionLines.append(line)
def getLocationSetFeedrateToSplitLine(self, splitLine): location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) indexOfF = gcodec.indexOfStartingWithSecond("F", splitLine) if indexOfF > 0: self.feedrateMinute = gcodec.getDoubleAfterFirstLetter( splitLine[indexOfF]) return location
def parseLine( self, lineIndex ): "Parse a gcode line." line = self.lines[ lineIndex ] splitLine = line.split( ' ' ) if len( splitLine ) < 1: return 0 firstWord = splitLine[ 0 ] if firstWord == 'G1': self.linearMove( splitLine ) self.lastBeforeExtrusionLines = self.beforeExtrusionLines self.beforeExtrusionLines = None if firstWord == 'M101': self.extruderActive = True elif firstWord == 'M103': self.extruderActive = False self.thread = None elif firstWord == '(<extrusionWidth>': self.extrusionWidth = gcodec.getDoubleAfterFirstLetter( splitLine[ 1 ] ) elif firstWord == '(<layerStart>': self.beforeExtrusionLines = [] self.threadLayer = None self.thread = None elif firstWord == '(<loop>': self.isLoop = True if len( splitLine ) > 1: if splitLine[ 1 ] == 'edge': self.isEdge = True elif firstWord == '(<extruderShutDown>': self.shutdownLineIndex = lineIndex if self.beforeExtrusionLines != None: self.beforeExtrusionLines.append( line )
def helicalMove(self, isCounterclockwise, splitLine): "Get statistics for a helical move." if self.oldLocation == None: return location = self.getLocationSetFeedrateToSplitLine(splitLine) location.add(self.oldLocation) center = Vec3().getFromVec3(self.oldLocation) indexOfR = gcodec.indexOfStartingWithSecond("R", splitLine) if indexOfR > 0: radius = gcodec.getDoubleAfterFirstLetter(splitLine[indexOfR]) halfLocationMinusOld = location.minus(self.oldLocation) halfLocationMinusOld.scale(0.5) halfLocationMinusOldLength = halfLocationMinusOld.length() centerMidpointDistance = math.sqrt(radius * radius - halfLocationMinusOldLength * halfLocationMinusOldLength) centerMinusMidpoint = euclidean.getRotatedWiddershinsQuarterAroundZAxis( halfLocationMinusOld) centerMinusMidpoint.normalize() centerMinusMidpoint.scale(centerMidpointDistance) if isCounterclockwise: center.setToVec3( halfLocationMinusOld.plus(centerMinusMidpoint)) else: center.setToVec3( halfLocationMinusOld.minus(centerMinusMidpoint)) else: center.x = gcodec.getDoubleForLetter("I", splitLine) center.y = gcodec.getDoubleForLetter("J", splitLine) curveSection = 0.5 center.add(self.oldLocation) afterCenterSegment = location.minus(center) beforeCenterSegment = self.oldLocation.minus(center) afterCenterDifferenceAngle = euclidean.getAngleAroundZAxisDifference( afterCenterSegment, beforeCenterSegment) absoluteDifferenceAngle = abs(afterCenterDifferenceAngle) steps = int( round(0.5 + max( absoluteDifferenceAngle * 2.4, absoluteDifferenceAngle * beforeCenterSegment.length() / curveSection))) stepPlaneAngle = euclidean.getPolar(afterCenterDifferenceAngle / steps, 1.0) zIncrement = (afterCenterSegment.z - beforeCenterSegment.z) / float(steps) for step in range(1, steps): beforeCenterSegment = euclidean.getRoundZAxisByPlaneAngle( stepPlaneAngle, beforeCenterSegment) beforeCenterSegment.z += zIncrement arcPoint = center.plus(beforeCenterSegment) self.addToPath(arcPoint) self.addToPath(location)
def parseCorner( self, line ): "Parse a gcode line and use the location to update the bounding corners." splitLine = line.split( ' ' ) if len( splitLine ) < 1: return firstWord = splitLine[ 0 ] if firstWord == 'G1': self.linearCorner( splitLine ) elif firstWord == 'M101': self.extruderActive = True elif firstWord == 'M103': self.extruderActive = False elif firstWord == '(<extrusionWidth>': self.extrusionWidth = gcodec.getDoubleAfterFirstLetter( splitLine[ 1 ] )
def helicalMove( self, isCounterclockwise, splitLine ): "Get statistics for a helical move." if self.oldLocation == None: return location = self.getLocationSetFeedrateToSplitLine( splitLine ) location.add( self.oldLocation ) center = Vec3().getFromVec3( self.oldLocation ) indexOfR = gcodec.indexOfStartingWithSecond( "R", splitLine ) if indexOfR > 0: radius = gcodec.getDoubleAfterFirstLetter( splitLine[ indexOfR ] ) halfLocationMinusOld = location.minus( self.oldLocation ) halfLocationMinusOld.scale( 0.5 ) halfLocationMinusOldLength = halfLocationMinusOld.length() centerMidpointDistance = math.sqrt( radius * radius - halfLocationMinusOldLength * halfLocationMinusOldLength ) centerMinusMidpoint = euclidean.getRotatedWiddershinsQuarterAroundZAxis( halfLocationMinusOld ) centerMinusMidpoint.normalize() centerMinusMidpoint.scale( centerMidpointDistance ) if isCounterclockwise: center.setToVec3( halfLocationMinusOld.plus( centerMinusMidpoint ) ) else: center.setToVec3( halfLocationMinusOld.minus( centerMinusMidpoint ) ) else: center.x = gcodec.getDoubleForLetter( "I", splitLine ) center.y = gcodec.getDoubleForLetter( "J", splitLine ) curveSection = 0.5 center.add( self.oldLocation ) afterCenterSegment = location.minus( center ) beforeCenterSegment = self.oldLocation.minus( center ) afterCenterDifferenceAngle = euclidean.getAngleAroundZAxisDifference( afterCenterSegment, beforeCenterSegment ) absoluteDifferenceAngle = abs( afterCenterDifferenceAngle ) steps = int( round( 0.5 + max( absoluteDifferenceAngle * 2.4, absoluteDifferenceAngle * beforeCenterSegment.length() / curveSection ) ) ) stepPlaneAngle = euclidean.getPolar( afterCenterDifferenceAngle / steps, 1.0 ) zIncrement = ( afterCenterSegment.z - beforeCenterSegment.z ) / float( steps ) for step in range( 1, steps ): beforeCenterSegment = euclidean.getRoundZAxisByPlaneAngle( stepPlaneAngle, beforeCenterSegment ) beforeCenterSegment.z += zIncrement arcPoint = center.plus( beforeCenterSegment ) self.addToPath( arcPoint ) self.addToPath( location )
def getLocationSetFeedrateToSplitLine( self, splitLine ): location = gcodec.getLocationFromSplitLine( self.oldLocation, splitLine ) indexOfF = gcodec.indexOfStartingWithSecond( "F", splitLine ) if indexOfF > 0: self.feedrateMinute = gcodec.getDoubleAfterFirstLetter( splitLine[ indexOfF ] ) return location
def parseLine(self, line): "Parse a gcode line and add it to the commented gcode." splitLine = line.split(' ') if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1': self.linearMove(splitLine) elif firstWord == 'G2': self.setHelicalMoveEndpoint(splitLine) self.addComment("Helical clockwise move to " + str(self.oldLocation) + ".") elif firstWord == 'G3': self.setHelicalMoveEndpoint(splitLine) self.addComment("Helical counterclockwise move to " + str(self.oldLocation) + ".") elif firstWord == 'G21': self.addComment("Set units to mm.") elif firstWord == 'G28': self.addComment("Start at home.") elif firstWord == 'G90': self.addComment("Set positioning to absolute.") elif firstWord == 'M100': self.addComment( "Set extruder speed to " + str(gcodec.getDoubleAfterFirstLetter(splitLine[1])) + ".") elif firstWord == 'M101': self.addComment("Turn extruder on.") elif firstWord == 'M103': self.addComment("Turn extruder off.") elif firstWord == 'M104': self.addComment( "Set temperature to " + str(gcodec.getDoubleAfterFirstLetter(splitLine[1])) + " C.") elif firstWord == 'M105': self.addComment("Custom code for temperature reading.") elif firstWord == 'M106': self.addComment("Turn fan on.") elif firstWord == 'M107': self.addComment("Turn fan off.") elif firstWord == '(<extrusionDiameter>': self.addComment( "Set extrusion diameter to " + str(gcodec.getDoubleAfterFirstLetter(splitLine[1])) + " mm.") elif firstWord == '(<extrusionWidth>': self.addComment( "Set extrusion width to " + str(gcodec.getDoubleAfterFirstLetter(splitLine[1])) + " mm.") elif firstWord == '(<layerThickness>': self.addComment( "Set layer thickness to " + str(gcodec.getDoubleAfterFirstLetter(splitLine[1])) + " mm.") elif firstWord == '(<procedureDone>': self.addComment("The " + splitLine[1][1:] + " procedure has been performed.") elif firstWord == '(<extrusionStart>': self.addComment( "Initialization is finished, extrusion is starting.") elif firstWord == '(<layerStart>': self.addComment("New layer is starting.") elif firstWord == '(<loop>': self.addComment("Loop is starting.") self.output.write(line + "\n")