def isNextMovementReversalWorthy(self, threshold, starttoken, endtoken): """ Returns True if we should activate reversal on the next movement, False otherwise. The given threshold defines the movement distance under which we don't reverse. starttoken,endtoken is the movement delimiter (M101,M103 for thread, M103,M101 for stop) """ line = self.lines[self.lineIndex] splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) lastThreadLocation = gcodec.getLocationFromSplitLine(self.newLocation, splitLine) startTokenReached = False endTokenReached = False totalDistance = 0.0 for afterIndex in xrange(self.lineIndex + 1, len(self.lines)): line = self.lines[afterIndex] splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) if firstWord == 'G1': location = gcodec.getLocationFromSplitLine(lastThreadLocation, splitLine) if startTokenReached: totalDistance += location.distance(lastThreadLocation) if totalDistance >= threshold: if DEBUG: self.distanceFeedRate.addLine("( Next movement worthy: " + str(totalDistance) + " )") return True lastThreadLocation = location elif firstWord == endtoken: endTokenReached = True if startTokenReached: return False elif firstWord == starttoken: startTokenReached = True return False
def getDistanceToThreadBeginningAfterThreadEnd( self, remainingDistance ): "Get the distance to the thread beginning after the end of this thread." extruderOnReached = False line = self.lines[self.lineIndex] splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) lastThreadLocation = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) threadEndReached = False totalDistance = 0.0 for afterIndex in xrange( self.lineIndex + 1, len(self.lines) ): line = self.lines[ afterIndex ] splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) if firstWord == 'G1': location = gcodec.getLocationFromSplitLine( lastThreadLocation, splitLine ) if threadEndReached: totalDistance += location.distance( lastThreadLocation ) if totalDistance >= remainingDistance: return None if extruderOnReached: return totalDistance lastThreadLocation = location elif firstWord == 'M101': extruderOnReached = True elif firstWord == 'M103': threadEndReached = True return None
def isNextExtruderOn( self ): "Determine if there is an extruder on command before a move command." line = self.lines[ self.lineIndex ] splitLine = gcodec.getSplitLineBeforeBracketSemicolon( line ) for afterIndex in xrange( self.lineIndex + 1, len( self.lines ) ): line = self.lines[ afterIndex ] splitLine = gcodec.getSplitLineBeforeBracketSemicolon( line ) firstWord = gcodec.getFirstWord( splitLine ) if firstWord == 'G1' or firstWord == 'M103': return False elif firstWord == 'M101': return True return False
def parseLine( self, line ): "Parse a gcode line and add it to the statistics." self.characters += len( line ) self.numberOfLines += 1 splitLine = gcodec.getSplitLineBeforeBracketSemicolon( line ) 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 == 'M101': self.extruderSet( True ) elif firstWord == 'M102': self.extruderSet( False ) elif firstWord == 'M103': self.extruderSet( False ) elif firstWord == 'M108': self.extruderSpeed = gcodec.getDoubleAfterFirstLetter( splitLine[ 1 ] ) elif firstWord == '(<layerThickness>': self.layerThickness = float( splitLine[ 1 ] ) self.extrusionDiameter = self.repository.extrusionDiameterOverThickness.value * self.layerThickness elif firstWord == '(<operatingFeedRatePerSecond>': self.operatingFeedRatePerSecond = float( splitLine[ 1 ] ) elif firstWord == '(<perimeterWidth>': self.absolutePerimeterWidth = abs( float( splitLine[ 1 ] ) ) elif firstWord == '(<procedureDone>': self.procedures.append( splitLine[ 1 ] ) elif firstWord == '(<version>': self.version = splitLine[ 1 ]
def getFirstValue(gcodeText, word): 'Get the value from the first line which starts with the given word.' for line in archive.getTextLines(gcodeText): splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if gcodec.getFirstWord(splitLine) == word: return splitLine[1] return ''
def getRelativeStretch( self, locationComplex, lineIterator ): "Get relative stretch for a location." lastLocationComplex = locationComplex oldTotalLength = 0.0 pointComplex = locationComplex totalLength = 0.0 while 1: try: line = lineIterator.getNext() except StopIteration: locationMinusPoint = locationComplex - pointComplex locationMinusPointLength = abs( locationMinusPoint ) if locationMinusPointLength > 0.0: return locationMinusPoint / locationMinusPointLength return complex() splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = splitLine[0] pointComplex = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine).dropAxis(2) locationMinusPoint = lastLocationComplex - pointComplex locationMinusPointLength = abs( locationMinusPoint ) totalLength += locationMinusPointLength if totalLength >= self.stretchFromDistance: distanceFromRatio = ( self.stretchFromDistance - oldTotalLength ) / locationMinusPointLength totalPoint = distanceFromRatio * pointComplex + ( 1.0 - distanceFromRatio ) * lastLocationComplex locationMinusTotalPoint = locationComplex - totalPoint return locationMinusTotalPoint / self.stretchFromDistance lastLocationComplex = pointComplex oldTotalLength = totalLength
def parseLine(self, line): "Parse a gcode line and add it to the speed skein." splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == '(<crafting>)': self.distanceFeedRate.addLine(line) self.addParameterString('M113', self.repository.dutyCycleAtBeginning.value ) # Set duty cycle . return elif firstWord == 'G1': line = self.getSpeededLine(line, splitLine) elif firstWord == 'M101': self.isExtruderActive = True elif firstWord == 'M103': self.isExtruderActive = False elif firstWord == '(<bridgeRotation>': self.isBridgeLayer = True elif firstWord == '(<layer>': self.layerIndex += 1 settings.printProgress(self.layerIndex, 'speed') self.isBridgeLayer = False self.addFlowRateLine() elif firstWord == '(<edge>' or firstWord == '(<edgePath>)': self.isEdgePath = True elif firstWord == '(</edge>)' or firstWord == '(</edgePath>)': self.isEdgePath = False self.distanceFeedRate.addLine(line)
def parseLine(self, line): "Parse a gcode line and add it to the clip skein." splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1': self.linearMove(splitLine) elif firstWord == '(<layer>': self.setLayerPixelTable() elif firstWord == '(<loop>': self.isLoop = True elif firstWord == '(</loop>)': self.isLoop = False elif firstWord == 'M101': self.extruderActive = True elif firstWord == 'M103': self.extruderActive = False if self.loopPath != None: self.addTailoredLoopPath(line) return elif firstWord == '(<edge>': self.isEdge = True elif firstWord == '(</edge>)': self.isEdge = False if self.loopPath == None: self.distanceFeedRate.addLine(line)
def getSplodgeLineGivenDistance( self, feedRateMinute, line, liftOverExtraThickness, location, startupDistance ): "Add the splodge line." locationComplex = location.dropAxis() relativeStartComplex = None nextLocationComplex = self.getNextActiveLocationComplex() if nextLocationComplex != None: if nextLocationComplex != locationComplex: relativeStartComplex = locationComplex - nextLocationComplex if relativeStartComplex == None: relativeStartComplex = complex( 19.9, 9.9 ) if self.oldLocation != None: oldLocationComplex = self.oldLocation.dropAxis() if oldLocationComplex != locationComplex: relativeStartComplex = oldLocationComplex - locationComplex relativeStartComplex *= startupDistance / abs( relativeStartComplex ) startComplex = self.getStartInsideBoundingRectangle( locationComplex, relativeStartComplex ) feedRateMultiplier = feedRateMinute / self.operatingFeedRatePerSecond / 60.0 splodgeLayerThickness = self.layerThickness / math.sqrt( feedRateMultiplier ) extraLayerThickness = splodgeLayerThickness - self.layerThickness lift = extraLayerThickness * liftOverExtraThickness startLine = self.distanceFeedRate.getLinearGcodeMovementWithFeedRate( self.feedRateMinute, startComplex, location.z + lift ) self.addLineUnlessIdenticalReactivate( startLine ) self.addLineUnlessIdenticalReactivate('M101') splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) lineLocation = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) self.distanceFeedRate.addGcodeMovementZWithFeedRate( feedRateMinute, locationComplex, lineLocation.z + lift ) return ''
def parseInitialization(self): 'Parse gcode initialization and store the parameters.' for self.lineIndex in xrange(len(self.lines)): line = self.lines[self.lineIndex] splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) self.distanceFeedRate.parseSplitLine(firstWord, splitLine) if firstWord == '(<decimalPlacesCarried>': self.addInitializationToOutput() self.distanceFeedRate.addTagBracketedLine('bridgeWidthMultiplier', self.distanceFeedRate.getRounded( self.repository.bridgeWidthMultiplier.value )) self.distanceFeedRate.addTagBracketedLine('scaledBridgeWidthMultiplier', self.distanceFeedRate.getRounded( self.scaledBridgeWidthMultiplier )) elif firstWord == '(</extruderInitialization>)': self.distanceFeedRate.addTagBracketedProcedure('inset') return elif firstWord == '(<layerHeight>': self.layerHeight = float(splitLine[1]) # self.infillWidth = self.repository.infillWidthOverThickness.value * self.layerHeight #moved dow so it is defined by edgeWidth # self.distanceFeedRate.addTagRoundedLine('infillWidth', self.infillWidth)#moved dow so it is defined by edgeWidth self.distanceFeedRate.addTagRoundedLine('volumeFraction', self.repository.volumeFraction.value) elif firstWord == '(<edgeWidth>': self.edgeWidth = float(splitLine[1]) self.infillWidth = self.edgeWidth self.halfEdgeWidth = 0.5 * self.edgeWidth self.overlapRemovalWidth = self.edgeWidth * euclidean.globalQuarterPi * self.repository.overlapRemovalWidthOverEdgeWidth.value self.distanceFeedRate.addTagBracketedLine('nozzleDiameter', self.repository.nozzleDiameter.value ) self.nozzleXsection = (self.repository.nozzleDiameter.value/2) ** 2 * math.pi self.extrusionXsection = ((self.edgeWidth + self.layerHeight)/4) ** 2 * math.pi self.distanceFeedRate.addTagBracketedLine('nozzleXsection', self.nozzleXsection) self.distanceFeedRate.addTagRoundedLine('infillWidth', self.infillWidth) self.distanceFeedRate.addLine(line)
def parseLine(self, line): """Parse a gcode line and add it to the statistics.""" self.characters += len(line) self.numberOfLines += 1 splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) 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 == 'M101': self.extruderSet( True ) elif firstWord == 'M102': self.extruderSet( False ) elif firstWord == 'M103': self.extruderSet( False ) elif firstWord == '(<extrusionHeight>': self.extrusionHeight = float(splitLine[1]) self.extrusionDiameter = self.repository.extrusionDiameterOverThickness.value * self.extrusionHeight elif firstWord == '(<operatingFeedRatePerSecond>': self.operatingFeedRatePerSecond = float(splitLine[1]) elif firstWord == '(<extrusionWidth>': self.absolutePerimeterWidth = abs(float(splitLine[1])) elif firstWord == '(<procedureName>': self.procedures.append(splitLine[1]) elif firstWord == '(<profileName>': self.profileName = line.replace('(<profileName>', '').replace('</profileName>)', '').strip() elif firstWord == '(<version>': self.version = splitLine[1]
def parseLine(self, line): "Parse a gcode line and add it to the inset skein." splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == '(<boundaryPoint>': location = gcodec.getLocationFromSplitLine(None, splitLine) self.boundary.append(location.dropAxis()) elif firstWord == '(<bridgeRotation>': self.loopLayer.rotation = gcodec.getRotationBySplitLine(splitLine) elif firstWord == '(</crafting>)': self.distanceFeedRate.addLine(line) if self.repository.turnExtruderHeaterOffAtShutDown.value: self.distanceFeedRate.addLine('M104 S0') # Turn extruder heater off. return elif firstWord == '(<layer>': self.layerCount.printProgressIncrement('inset') self.loopLayer = euclidean.LoopLayer(float(splitLine[1])) self.distanceFeedRate.addLine(line) elif firstWord == '(</layer>)': self.addInset(self.loopLayer) self.loopLayer = None elif firstWord == '(<nestedRing>)': self.boundary = [] self.loopLayer.loops.append(self.boundary) if self.loopLayer == None: self.distanceFeedRate.addLine(line)
def parseLine(self, line): "Parse a gcode line and add it to the speed skein." if not self.distanceFeedRate.absoluteDistanceMode: self.distanceFeedRate.addLine(line) return splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == "(<extrusion>)": self.distanceFeedRate.addLine(line) self.addParameterString("M113", self.repository.dutyCycleAtBeginning.value) # Set duty cycle . return elif firstWord == "G1": line = self.getSpeededLine(splitLine) elif firstWord == "M101": self.isExtruderActive = True elif firstWord == "M103": self.isPerimeter = False self.isExtruderActive = False elif firstWord == "(<bridgeRotation>": self.isBridgeLayer = True elif firstWord == "(<layer>": self.isBridgeLayer = False self.addFlowRateLineIfNecessary() elif firstWord == "(<perimeter>": self.isPerimeter = True self.distanceFeedRate.addLine(line)
def getHopLine(self, line): "Get hopped gcode line." splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) self.feedRateMinute = gcodec.getFeedRateMinute( self.feedRateMinute, splitLine ) if self.extruderActive: return line location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) highestZ = location.z if self.oldLocation is not None: highestZ = max( highestZ, self.oldLocation.z ) highestZHop = highestZ + self.hopHeight locationComplex = location.dropAxis() if self.justDeactivated: oldLocationComplex = self.oldLocation.dropAxis() distance = abs( locationComplex - oldLocationComplex ) if distance < self.minimumDistance: if self.isNextTravel() or distance == 0.0: return self.distanceFeedRate.getLineWithZ( line, splitLine, highestZHop ) alongRatio = min( 0.41666666, self.hopDistance / distance ) oneMinusAlong = 1.0 - alongRatio closeLocation = oldLocationComplex * oneMinusAlong + locationComplex * alongRatio self.distanceFeedRate.addLine( self.distanceFeedRate.getLineWithZ( line, splitLine, highestZHop ) ) if self.isNextTravel(): return self.distanceFeedRate.getLineWithZ( line, splitLine, highestZHop ) farLocation = oldLocationComplex * alongRatio + locationComplex * oneMinusAlong self.distanceFeedRate.addGcodeMovementZWithFeedRate( self.feedRateMinute, farLocation, highestZHop ) return line if self.isNextTravel(): return self.distanceFeedRate.getLineWithZ( line, splitLine, highestZHop ) return line
def parseLine(self, line): "Parse a gcode line and add it to the mill skein." splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1': location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) if self.isExtruderActive: self.average.addValue(location.z) if self.oldLocation != None: euclidean.addValueSegmentToPixelTable( self.oldLocation.dropAxis(), location.dropAxis(), self.aroundPixelTable, None, self.aroundWidth ) self.oldLocation = location elif firstWord == 'M101': self.isExtruderActive = True elif firstWord == 'M103': self.isExtruderActive = False elif firstWord == '(<layer>': self.layerCount.printProgressIncrement('mill') self.aroundPixelTable = {} self.average.reset() elif firstWord == '(</layer>)': if len( self.boundaryLayers ) > self.layerIndex: self.addMillThreads() self.layerIndex += 1 self.distanceFeedRate.addLine(line)
def parseLine(self, line): "Parse a gcode line and add it to the vector output." splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if self.isLayerStart( firstWord, splitLine ): self.extrusionNumber = 0 self.skeinPane = [] self.skeinPanes.append( self.skeinPane ) if firstWord == 'G1': location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) self.linearMove( line, location ) self.oldLocation = location elif firstWord == 'M101': self.extruderActive = True self.extrusionNumber += 1 elif firstWord == 'M103': self.extruderActive = False if firstWord == 'G2' or firstWord == 'G3': relativeLocation = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) relativeLocation.z = 0.0 location = self.oldLocation + relativeLocation self.linearMove( line, location ) self.oldLocation = location
def parseStretch(self, line): "Parse a gcode line and add it to the stretch skein." splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1': line = self.getStretchedLine(splitLine) elif firstWord == 'M101': self.extruderActive = True elif firstWord == 'M103': self.extruderActive = False self.setStretchToPath() elif firstWord == '(<loop>': self.isLoop = True self.threadMaximumAbsoluteStretch = self.loopMaximumAbsoluteStretch elif firstWord == '(</loop>)': self.setStretchToPath() elif firstWord == '(<perimeter>': self.isLoop = True self.threadMaximumAbsoluteStretch = self.perimeterInsideAbsoluteStretch if splitLine[1] == 'outer': self.threadMaximumAbsoluteStretch = self.perimeterOutsideAbsoluteStretch elif firstWord == '(</perimeter>)': self.setStretchToPath() self.distanceFeedRate.addLine(line)
def parseLine(self, line): "Parse a gcode line and add it to the dwindle skein." splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == "G1": self.feedRateMinute = gcodec.getFeedRateMinute(self.feedRateMinute, splitLine) location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) if self.isActive: self.threadSections.append( ThreadSection(self.feedRateMinute, self.oldFlowRate, location, self.oldLocation) ) self.oldLocation = location elif firstWord == "(<layer>": self.layerIndex += 1 settings.printProgress(self.layerIndex, "dwindle") elif firstWord == "M101": self.isActive = True elif firstWord == "M103": self.isActive = False self.addThread() elif firstWord == "M108": self.oldFlowRate = gcodec.getDoubleAfterFirstLetter(splitLine[1]) if len(self.threadSections) == 0: self.distanceFeedRate.addLine(line)
def getLayerTimeActive(self): 'Get the time the extruder spends on the layer while active.' feedRateMinute = self.feedRateMinute isExtruderActive = self.isExtruderActive layerTime = 0.0 lastThreadLocation = self.oldLocation for lineIndex in xrange(self.lineIndex, len(self.lines)): line = self.lines[lineIndex] splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) if firstWord == 'G1': location = gcodec.getLocationFromSplitLine(lastThreadLocation, splitLine) feedRateMinute = gcodec.getFeedRateMinute(feedRateMinute, splitLine) if lastThreadLocation != None and isExtruderActive: feedRateSecond = feedRateMinute / 60.0 layerTime += location.distance(lastThreadLocation) / feedRateSecond lastThreadLocation = location elif firstWord == 'M101': isExtruderActive = True elif firstWord == 'M103': isExtruderActive = False elif firstWord == '(<bridgeRotation>': self.isBridgeLayer = True elif firstWord == '(</layer>)': return layerTime return layerTime
def getDistanceToNextThread(self, lineIndex): 'Get the travel distance to the next thread.' if self.oldLocation == None: return None isActive = False location = self.oldLocation for afterIndex in xrange(lineIndex + 1, len(self.lines)): line = self.lines[afterIndex] splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) if firstWord == 'G1': if isActive: if not self.repository.retractWithinIsland.value: locationEnclosureIndex = self.getSmallestEnclosureIndex(location.dropAxis()) if locationEnclosureIndex != self.getSmallestEnclosureIndex(self.oldLocation.dropAxis()): return None locationMinusOld = location - self.oldLocation xyTravel = abs(locationMinusOld.dropAxis()) zTravelMultiplied = locationMinusOld.z * self.zDistanceRatio return math.sqrt(xyTravel * xyTravel + zTravelMultiplied * zTravelMultiplied) location = gcodec.getLocationFromSplitLine(location, splitLine) elif firstWord == 'M101': isActive = True elif firstWord == 'M103': isActive = False return None
def parseBoundaries(self): "Parse the boundaries and add them to the boundary layers." boundaryLoop = None boundaryLayer = None for line in self.lines[self.lineIndex :]: splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) if len(self.shutdownLines) > 0: self.shutdownLines.append(line) if firstWord == "(</boundaryPerimeter>)": boundaryLoop = None elif firstWord == "(<boundaryPoint>": location = gcodec.getLocationFromSplitLine(None, splitLine) if boundaryLoop == None: boundaryLoop = [] boundaryLayer.loops.append(boundaryLoop) boundaryLoop.append(location.dropAxis()) elif firstWord == "(<layer>": boundaryLayer = euclidean.LoopLayer(float(splitLine[1])) self.boundaryLayers.append(boundaryLayer) elif firstWord == "(</crafting>)": self.shutdownLines = [line] for boundaryLayer in self.boundaryLayers: if not euclidean.isWiddershins(boundaryLayer.loops[0]): boundaryLayer.loops[0].reverse() self.boundaryReverseLayers = self.boundaryLayers[:] self.boundaryReverseLayers.reverse()
def parseLine(self, line): "Parse a gcode line." splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == "(</crafting>)": self.crafting = False elif firstWord == "(<decimalPlacesCarried>": self.decimalPlacesExported = int(splitLine[1]) - 1 if self.repository.deleteAllComments.value or (self.repository.deleteCraftingComments.value and self.crafting): if firstWord[0] == "(": return else: line = line.split(";")[0].split("(")[0].strip() if firstWord == "(<crafting>)": self.crafting = True if firstWord == "(</extruderInitialization>)": self.addLine("(<procedureName> export </procedureName>)") if firstWord != "G1" and firstWord != "G2" and firstWord != "G3": self.addLine(line) return line = self.getLineWithTruncatedNumber("X", line, splitLine) line = self.getLineWithTruncatedNumber("Y", line, splitLine) line = self.getLineWithTruncatedNumber("Z", line, splitLine) line = self.getLineWithTruncatedNumber("I", line, splitLine) line = self.getLineWithTruncatedNumber("J", line, splitLine) line = self.getLineWithTruncatedNumber("R", line, splitLine) self.addLine(line)
def parseLine(self, line): "Parse a gcode line." binary16ByteRepository = self.binary16ByteRepository splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) if len(firstWord) < 1: return firstLetter = firstWord[0] if firstLetter == '(': return feedRateInteger = getIntegerFromCharacterLengthLineOffset('F', 0.0, splitLine, binary16ByteRepository.feedRateStepLength.value ) iInteger = getIntegerFromCharacterLengthLineOffset('I', 0.0, splitLine, binary16ByteRepository.xStepLength.value ) jInteger = getIntegerFromCharacterLengthLineOffset('J', 0.0, splitLine, binary16ByteRepository.yStepLength.value ) xInteger = getIntegerFromCharacterLengthLineOffset('X', binary16ByteRepository.xOffset.value, splitLine, binary16ByteRepository.xStepLength.value ) yInteger = getIntegerFromCharacterLengthLineOffset('Y', binary16ByteRepository.yOffset.value, splitLine, binary16ByteRepository.yStepLength.value ) zInteger = getIntegerFromCharacterLengthLineOffset('Z', binary16ByteRepository.zOffset.value, splitLine, binary16ByteRepository.zStepLength.value ) sixteenByteStruct = Struct('cBhhhhhhBc') flagInteger = getIntegerFlagFromCharacterSplitLine('X', splitLine ) flagInteger += 2 * getIntegerFlagFromCharacterSplitLine('Y', splitLine ) flagInteger += 4 * getIntegerFlagFromCharacterSplitLine('Z', splitLine ) flagInteger += 8 * getIntegerFlagFromCharacterSplitLine('I', splitLine ) flagInteger += 16 * getIntegerFlagFromCharacterSplitLine('J', splitLine ) flagInteger += 32 * getIntegerFlagFromCharacterSplitLine('F', splitLine ) packedString = sixteenByteStruct.pack( firstLetter, int( firstWord[1 :] ), xInteger, yInteger, zInteger, iInteger, jInteger, feedRateInteger, flagInteger, '#') self.output.write( packedString )
def parseLine( self, lineIndex ): 'Parse a gcode line and add it to the dimension skein.' line = self.lines[lineIndex].lstrip() splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G2' or firstWord == 'G3': line = self.getDimensionedArcMovement( line, splitLine ) if firstWord == 'G1': line = self.getDimensionedLinearMovement( line, splitLine ) if firstWord == 'G90': self.absoluteDistanceMode = True elif firstWord == 'G91': self.absoluteDistanceMode = False elif firstWord == '(<layer>': self.layerIndex += 1 settings.printProgress(self.layerIndex, 'dimension') elif firstWord == 'M101': self.addLinearMoveExtrusionDistanceLine(self.restartDistance * self.retractionRatio) if self.totalExtrusionDistance > self.repository.maximumEValueBeforeReset.value: if not self.repository.relativeExtrusionDistance.value: self.distanceFeedRate.addLine('G92 E0') self.totalExtrusionDistance = 0.0 self.isExtruderActive = True elif firstWord == 'M103': self.retractionRatio = self.getRetractionRatio(lineIndex) self.addLinearMoveExtrusionDistanceLine(-self.repository.retractionDistance.value * self.retractionRatio) self.isExtruderActive = False elif firstWord == 'M108': self.flowRate = float( splitLine[1][1 :] ) self.distanceFeedRate.addLine(line)
def parseInitialization(self): 'Parse gcode initialization and store the parameters.' for self.lineIndex in xrange(len(self.lines)): line = self.lines[self.lineIndex] splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) self.distanceFeedRate.parseSplitLine(firstWord, splitLine) if firstWord == '(</extruderInitialization>)': self.distanceFeedRate.addTagBracketedProcedure('dimension') return elif firstWord == '(<layerThickness>': self.layerThickness = float(splitLine[1]) elif firstWord == '(<maximumZDrillFeedRatePerSecond>': self.maximumZFeedRatePerSecond = float(splitLine[1]) elif firstWord == '(<maximumZFeedRatePerSecond>': self.maximumZFeedRatePerSecond = float(splitLine[1]) elif firstWord == '(<operatingFeedRatePerSecond>': self.feedRateMinute = 60.0 * float(splitLine[1]) elif firstWord == '(<operatingFlowRate>': self.operatingFlowRate = float(splitLine[1]) self.flowRate = self.operatingFlowRate elif firstWord == '(<perimeterWidth>': self.perimeterWidth = float(splitLine[1]) elif firstWord == '(<travelFeedRatePerSecond>': self.travelFeedRatePerSecond = float(splitLine[1]) self.distanceFeedRate.addLine(line)
def parseLine(self, line): 'Parse a gcode line.' splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == '(</crafting>)': self.crafting = False elif firstWord == '(<decimalPlacesCarried>': self.decimalPlacesExported = int(splitLine[1]) - 1 if self.repository.deleteAllComments.value or (self.repository.deleteCraftingComments.value and self.crafting): if firstWord[0] == '(': return else: line = line.split(';')[0].split('(')[0].strip() if firstWord == '(<crafting>)': self.crafting = True if firstWord == '(</extruderInitialization>)': self.addLine(gcodec.getTagBracketedProcedure('export')) if firstWord != 'G1' and firstWord != 'G2' and firstWord != 'G3' : self.addLine(line) return line = self.getLineWithTruncatedNumber('X', line, splitLine) line = self.getLineWithTruncatedNumber('Y', line, splitLine) line = self.getLineWithTruncatedNumber('Z', line, splitLine) line = self.getLineWithTruncatedNumber('I', line, splitLine) line = self.getLineWithTruncatedNumber('J', line, splitLine) line = self.getLineWithTruncatedNumber('R', line, splitLine) self.addLine(line)
def parseLine(self, lineIndex): "Parse a gcode line and add it to the dimension skein." line = self.lines[lineIndex].lstrip() splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == "G2" or firstWord == "G3": line = self.getDimensionedArcMovement(line, splitLine) if firstWord == "G1": line = self.getDimensionedLinearMovement(line, splitLine) if firstWord == "G90": self.absoluteDistanceMode = True elif firstWord == "G91": self.absoluteDistanceMode = False elif firstWord == "(<layer>": self.layerIndex += 1 elif firstWord == "M101": self.addLinearMoveExtrusionDistanceLine(self.restartDistance * self.retractionRatio) if self.totalExtrusionDistance > 999999.0: if not self.repository.relativeExtrusionDistance.value: self.distanceFeedRate.addLine("G92 E0") self.totalExtrusionDistance = 0.0 self.isExtruderActive = True elif firstWord == "M103": self.retractionRatio = self.getRetractionRatio(lineIndex) self.addLinearMoveExtrusionDistanceLine(-self.repository.retractionDistance.value * self.retractionRatio) self.isExtruderActive = False elif firstWord == "M108": self.flowRate = float(splitLine[1][1:]) self.distanceFeedRate.addLine(line)
def parseInitialization(self): "Parse gcode initialization and store the parameters." for self.lineIndex in xrange(len(self.lines)): line = self.lines[self.lineIndex] splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) self.distanceFeedRate.parseSplitLine(firstWord, splitLine) if firstWord == "(<layerThickness>": self.layerThickness = float(splitLine[1]) elif firstWord == "(</extruderInitialization>)": self.distanceFeedRate.addLine("(<procedureDone> speed </procedureDone>)") return elif firstWord == "(<perimeterWidth>": self.absolutePerimeterWidth = abs(float(splitLine[1])) self.distanceFeedRate.addTagBracketedLine( "maximumZDrillFeedRatePerSecond", self.distanceFeedRate.maximumZDrillFeedRatePerSecond ) self.distanceFeedRate.addTagBracketedLine( "maximumZTravelFeedRatePerSecond", self.distanceFeedRate.maximumZTravelFeedRatePerSecond ) self.distanceFeedRate.addTagBracketedLine("operatingFeedRatePerSecond", self.feedRatePerSecond) if self.repository.addFlowRate.value: self.distanceFeedRate.addTagBracketedLine( "operatingFlowRate", self.repository.flowRateSetting.value ) orbitalFeedRatePerSecond = ( self.feedRatePerSecond * self.repository.orbitalFeedRateOverOperatingFeedRate.value ) self.distanceFeedRate.addTagBracketedLine("orbitalFeedRatePerSecond", orbitalFeedRatePerSecond) self.distanceFeedRate.addTagBracketedLine( "travelFeedRatePerSecond", self.repository.travelFeedRatePerSecond.value ) self.distanceFeedRate.addLine(line)
def getNext(self): "Get next line going backward or raise exception." while self.lineIndex > 3: if self.lineIndex == self.firstLineIndex: raise StopIteration, "You've reached the end of the line." if self.firstLineIndex == None: self.firstLineIndex = self.lineIndex nextLineIndex = self.lineIndex - 1 line = self.lines[ self.lineIndex ] splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) if firstWord == 'M103': if self.isLoop: nextLineIndex = self.getIndexBeforeNextDeactivate() else: raise StopIteration, "You've reached the end of the line." if firstWord == 'G1': if self.isBeforeExtrusion(): if self.isLoop: nextLineIndex = self.getIndexBeforeNextDeactivate() else: raise StopIteration, "You've reached the end of the line." else: self.lineIndex = nextLineIndex return line self.lineIndex = nextLineIndex raise StopIteration, "You've reached the end of the line."
def getAddShutSlowDownLine(self, line): "Add the shutdown and slowdown lines." if self.shutdownStepIndex >= len( self.earlyShutdownDistances ): self.shutdownStepIndex = len( self.earlyShutdownDistances ) + 99999999 return False splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) distanceThreadEnd = self.getDistanceToExtruderOffCommand( self.earlyShutdownDistances[ self.shutdownStepIndex ] ) location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) if distanceThreadEnd == None: distanceThreadEnd = self.getDistanceToExtruderOffCommand( self.earlyShutdownDistances[0] ) if distanceThreadEnd != None: shutdownFlowRateMultiplier = self.getShutdownFlowRateMultiplier( 1.0 - distanceThreadEnd / self.earlyShutdownDistance, len( self.earlyShutdownDistances ) ) line = self.getLinearMoveWithFeedRate( self.feedRateMinute * shutdownFlowRateMultiplier, location ) self.distanceFeedRate.addLine(line) return False segment = self.oldLocation - location segmentLength = segment.magnitude() distanceBack = self.earlyShutdownDistances[ self.shutdownStepIndex ] - distanceThreadEnd locationBack = location if segmentLength > 0.0: locationBack = location + segment * distanceBack / segmentLength if self.shutdownStepIndex == 0: if not self.isCloseToEither( locationBack, location, self.oldLocation ): line = self.getLinearMoveWithFeedRate( self.feedRateMinute, locationBack ) self.distanceFeedRate.addLine(line) self.addLineSetShutdowns('M103') return True if self.isClose( locationBack, self.oldLocation ): return True feedRate = self.feedRateMinute * self.earlyShutdownFlowRates[ self.shutdownStepIndex ] line = self.getLinearMoveWithFeedRate( feedRate, locationBack ) if self.isClose( locationBack, location ): line = self.getLinearMoveWithFeedRate( feedRate, location ) self.distanceFeedRate.addLine(line) return True
def getAnimationLineDelay( self, coloredLine ): 'Get the animation line delay in milliseconds.' # maybe later, add animation along line # nextLayerIndex = self.repository.layer.value # nextLineIndex = self.repository.line.value + 1 # coloredLinesLength = len( self.getColoredLines() ) # self.skein.feedRateMinute # if nextLineIndex >= coloredLinesLength: # if nextLayerIndex + 1 < len( self.skeinPanes ): # nextLayerIndex += 1 # nextLineIndex = 0 # else: # nextLineIndex = self.repository.line.value splitLine = gcodec.getSplitLineBeforeBracketSemicolon( coloredLine.displayString ) self.skein.feedRateMinute = gcodec.getFeedRateMinute( self.skein.feedRateMinute, splitLine ) feedRateSecond = self.skein.feedRateMinute / 60.0 coloredLineLength = abs( coloredLine.end - coloredLine.begin ) / self.repository.scale.value duration = coloredLineLength / feedRateSecond animationLineDelay = int( round( 1000.0 * duration / self.repository.animationLineQuickening.value ) ) return max( animationLineDelay, 1 )
def getNext(self): "Get next line or raise exception." while self.lineIndex < len(self.lines): if self.lineIndex == self.firstLineIndex: raise StopIteration, "You've reached the end of the line." if self.firstLineIndex == None: self.firstLineIndex = self.lineIndex nextLineIndex = self.lineIndex + 1 line = self.lines[self.lineIndex] splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) if firstWord == 'M103': if self.isLoop: nextLineIndex = self.getIndexJustAfterActivate() else: raise StopIteration, "You've reached the end of the line." self.lineIndex = nextLineIndex if firstWord == 'G1': return line raise StopIteration, "You've reached the end of the line."
def parseLine(self, line): "Parse a gcode line and add it to the bevel gcode." splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1': self.addWipeTravel(splitLine) self.oldLocation = gcodec.getLocationFromSplitLine( self.oldLocation, splitLine) elif firstWord == '(<layer>': settings.printProgress(self.layerIndex, 'wipe') self.layerIndex += 1 if self.layerIndex % self.wipePeriod == 0: self.shouldWipe = True elif firstWord == 'M101': self.extruderActive = True elif firstWord == 'M103': self.extruderActive = False self.distanceFeedRate.addLine(line)
def parseLine(self, line): "Parse a gcode line and add it to the bevel gcode." splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if self.distanceFeedRate.getIsAlteration(line): return if firstWord == 'G1': line = self.getHopLine(line) self.oldLocation = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) self.justDeactivated = False elif firstWord == '(<layer>': self.layerCount.printProgressIncrement('hop') elif firstWord == 'M101': self.extruderActive = True elif firstWord == 'M103': self.extruderActive = False self.justDeactivated = True self.distanceFeedRate.addLineCheckAlteration(line)
def parseBoundaries(self): 'Parse the boundaries and add them to the boundary layers.' boundaryLoop = None boundaryLayer = None for line in self.lines[self.lineIndex:]: splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) if firstWord == '(</boundaryPerimeter>)': boundaryLoop = None elif firstWord == '(<boundaryPoint>': location = gcodec.getLocationFromSplitLine(None, splitLine) if boundaryLoop == None: boundaryLoop = [] boundaryLayer.loops.append(boundaryLoop) boundaryLoop.append(location.dropAxis()) elif firstWord == '(<layer>': boundaryLayer = euclidean.LoopLayer(float(splitLine[1])) self.boundaryLayers.append(boundaryLayer) for boundaryLayer in self.boundaryLayers: triangle_mesh.sortLoopsInOrderOfArea(False, boundaryLayer.loops)
def parseInitialization(self): 'Parse gcode initialization and store the parameters.' for self.lineIndex in xrange(len(self.lines)): line = self.lines[self.lineIndex] splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) self.distanceFeedRate.parseSplitLine(firstWord, splitLine) if firstWord == 'M108': self.setOperatingFlowString(splitLine) elif firstWord == '(<perimeterWidth>': self.perimeterWidth = float(splitLine[1]) if self.coolRepository.turnFanOnAtBeginning.value: self.distanceFeedRate.addLine('M106') elif firstWord == '(</extruderInitialization>)': self.distanceFeedRate.addLine( '(<procedureName> cool </procedureName>)') return elif firstWord == '(<orbitalFeedRatePerSecond>': self.orbitalFeedRatePerSecond = float(splitLine[1]) self.distanceFeedRate.addLine(line)
def parseLine(self, lineIndex): 'Parse a gcode line and add it to the limit skein.' line = self.lines[lineIndex].lstrip() splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = gcodec.getFirstWord(splitLine) if firstWord == 'G1': location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) line = self.getLimitedInitialMovement(line, splitLine) line = self.getZLimitedLineLinear(line, location, splitLine) self.oldLocation = location elif firstWord == 'G2' or firstWord == 'G3': line = self.getZLimitedLineArc(line, splitLine) elif firstWord == 'M101': self.maximumZFeedRatePerSecond = self.maximumZDrillFeedRatePerSecond elif firstWord == 'M103': self.maximumZFeedRatePerSecond = self.maximumZTravelFeedRatePerSecond self.distanceFeedRate.addLine(line)
def addElement(self, offset): 'Add moved element to the output.' for line in self.layerLines: splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) if firstWord == '(<boundaryPoint>': movedLocation = self.getMovedLocationSetOldLocation( offset, splitLine) line = self.distanceFeedRate.getBoundaryLine(movedLocation) elif firstWord == 'G1': movedLocation = self.getMovedLocationSetOldLocation( offset, splitLine) line = self.distanceFeedRate.getLinearGcodeMovement( movedLocation.dropAxis(), movedLocation.z) elif firstWord == '(<infillPoint>': movedLocation = self.getMovedLocationSetOldLocation( offset, splitLine) line = self.distanceFeedRate.getInfillBoundaryLine( movedLocation) self.distanceFeedRate.addLine(line)
def parseLine(self, lineIndex): 'Parse a gcode line and add it to the dimension skein.' line = self.lines[lineIndex].lstrip() splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) # self.newFlowrate = str (round(self.flowRate * self.flowScaleSixty,0) ) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G2' or firstWord == 'G3': line = self.getDimensionedArcMovement(line, splitLine) if firstWord == 'G1': line = self.getDimensionedLinearMovement(line, splitLine) if firstWord == 'G90': self.absoluteDistanceMode = True elif firstWord == 'G91': self.absoluteDistanceMode = False elif firstWord == '(<layer>': if not self.repository.relativeExtrusionDistance.value: self.distanceFeedRate.addLine('M82') else: self.distanceFeedRate.addLine('M83') self.layerIndex += 1 elif firstWord == 'M101': self.addLinearMoveExtrusionDistanceLine( (self.autoRetractDistance) ) #(self.restartDistance * self.retractionRatio))#* self.autoRetractDistance) if not self.repository.relativeExtrusionDistance.value: self.distanceFeedRate.addLine('G92 E0') self.totalExtrusionDistance = 0.0 self.isExtruderActive = True elif firstWord == 'M103': self.retractionRatio = self.getRetractionRatio(lineIndex) self.addLinearMoveExtrusionDistanceLine(-self.autoRetractDistance) #retractionDistance = -self.repository.retractionDistance.value * self.retractionRatio self.isExtruderActive = False #print('dtnt ttnt ted rr efr',self.distanceToNextThread , self.timeToNextThread , self.totalExtrusionDistance,self.retractionRatio , self.autoRetractDistance) elif firstWord == 'M108': self.flowRate = float(splitLine[1][1:]) #self.addFlowRateLineIfNecessary() #self.distanceFeedRate.addLine('M108 S' + newFlowrate) self.distanceFeedRate.addLine(line)
def parseLine(self, line): "Parse a gcode line." binary16ByteRepository = self.binary16ByteRepository splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) if len(firstWord) < 1: return firstLetter = firstWord[0] if firstLetter == '(': return feedRateInteger = getIntegerFromCharacterLengthLineOffset( 'F', 0.0, splitLine, binary16ByteRepository.feedRateStepLength.value) iInteger = getIntegerFromCharacterLengthLineOffset( 'I', 0.0, splitLine, binary16ByteRepository.xStepLength.value) jInteger = getIntegerFromCharacterLengthLineOffset( 'J', 0.0, splitLine, binary16ByteRepository.yStepLength.value) xInteger = getIntegerFromCharacterLengthLineOffset( 'X', binary16ByteRepository.xOffset.value, splitLine, binary16ByteRepository.xStepLength.value) yInteger = getIntegerFromCharacterLengthLineOffset( 'Y', binary16ByteRepository.yOffset.value, splitLine, binary16ByteRepository.yStepLength.value) zInteger = getIntegerFromCharacterLengthLineOffset( 'Z', binary16ByteRepository.zOffset.value, splitLine, binary16ByteRepository.zStepLength.value) sixteenByteStruct = Struct('cBhhhhhhBc') flagInteger = getIntegerFlagFromCharacterSplitLine('X', splitLine) flagInteger += 2 * getIntegerFlagFromCharacterSplitLine('Y', splitLine) flagInteger += 4 * getIntegerFlagFromCharacterSplitLine('Z', splitLine) flagInteger += 8 * getIntegerFlagFromCharacterSplitLine('I', splitLine) flagInteger += 16 * getIntegerFlagFromCharacterSplitLine( 'J', splitLine) flagInteger += 32 * getIntegerFlagFromCharacterSplitLine( 'F', splitLine) packedString = sixteenByteStruct.pack(firstLetter, int(firstWord[1:]), xInteger, yInteger, zInteger, iInteger, jInteger, feedRateInteger, flagInteger, '#') self.output.write(packedString)
def setLayerPixelTable(self): "Set the layer pixel table." boundaryLoop = None extruderActive = False maskPixelTable = {} self.boundaryLoops = [] self.maskPixelTableTable = {} self.lastInactiveLocation = None self.layerPixelTable = {} oldLocation = self.oldLocation for afterIndex in xrange(self.lineIndex + 1, len(self.lines)): line = self.lines[afterIndex] splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) if firstWord == 'G1': location = gcodec.getLocationFromSplitLine( oldLocation, splitLine) if extruderActive and oldLocation != None: self.addSegmentToPixelTables(location, maskPixelTable, oldLocation) if not extruderActive: self.lastInactiveLocation = location oldLocation = location elif firstWord == 'M101': extruderActive = True elif firstWord == 'M103': if extruderActive and self.lastInactiveLocation != None: self.addSegmentToPixelTables(self.lastInactiveLocation, maskPixelTable, oldLocation) extruderActive = False maskPixelTable = {} elif firstWord == '(</boundaryPerimeter>)': boundaryLoop = None elif firstWord == '(<boundaryPoint>': if boundaryLoop == None: boundaryLoop = [] self.boundaryLoops.append(boundaryLoop) location = gcodec.getLocationFromSplitLine(None, splitLine) boundaryLoop.append(location.dropAxis(2)) elif firstWord == '(</layer>)': return
def parseInitialization(self): "Parse gcode initialization and store the parameters." for self.lineIndex in xrange(len(self.lines)): line = self.lines[self.lineIndex] splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) self.distanceFeedRate.parseSplitLine(firstWord, splitLine) if firstWord == '(</extruderInitialization>)': self.distanceFeedRate.addLine( '(<procedureDone> temperature </procedureDone>)') return elif firstWord == '(<perimeterWidth>': self.distanceFeedRate.addTagBracketedLine( 'coolingRate', self.repository.coolingRate.value) self.distanceFeedRate.addTagBracketedLine( 'heatingRate', self.repository.heatingRate.value) if self.repository.initialCircling.value: self.distanceFeedRate.addTagBracketedLine( 'chamberTemperature', self.repository.chamberTemperature.value) self.distanceFeedRate.addTagBracketedLine( 'baseTemperature', self.repository.baseTemperature.value) self.distanceFeedRate.addTagBracketedLine( 'interfaceTemperature', self.repository.interfaceTemperature.value) self.distanceFeedRate.addTagBracketedLine( 'objectFirstLayerInfillTemperature', self.repository.objectFirstLayerInfillTemperature.value) self.distanceFeedRate.addTagBracketedLine( 'objectFirstLayerPerimeterTemperature', self.repository.objectFirstLayerPerimeterTemperature.value) self.distanceFeedRate.addTagBracketedLine( 'objectNextLayersTemperature', self.repository.objectNextLayersTemperature.value) self.distanceFeedRate.addTagBracketedLine( 'supportLayersTemperature', self.repository.supportLayersTemperature.value) self.distanceFeedRate.addTagBracketedLine( 'supportedLayersTemperature', self.repository.supportedLayersTemperature.value) self.distanceFeedRate.addLine(line)
def parseLine(self, lineIndex): 'Parse a gcode line and add it to the dimension skein.' line = self.lines[lineIndex].lstrip() splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G2' or firstWord == 'G3': line = self.getDimensionedArcMovement(line, splitLine) if firstWord == 'G1': line = self.getDimensionedLinearMovement(line, splitLine) if firstWord == 'G90': self.absoluteDistanceMode = True elif firstWord == 'G91': self.absoluteDistanceMode = False elif firstWord == '(<layer>': self.layerIndex += 1 settings.printProgress(self.layerIndex, 'dimension') elif firstWord == '(</layer>)' or firstWord == '(<supportLayer>)' or firstWord == '(</supportLayer>)': if self.totalExtrusionDistance > 0.0 and not self.repository.relativeExtrusionDistance.value: self.distanceFeedRate.addLine('G92 E0') self.totalExtrusionDistance = 0.0 elif firstWord == 'M101': if self.retractionRatio > 0.0: self.addLinearMoveExtrusionDistanceLine(self.restartDistance * self.retractionRatio) if self.totalExtrusionDistance > self.repository.maximumEValueBeforeReset.value: if not self.repository.relativeExtrusionDistance.value: self.distanceFeedRate.addLine('G92 E0') self.totalExtrusionDistance = 0.0 self.isExtruderActive = True elif firstWord == 'M103': self.retractionRatio = self.getRetractionRatio(lineIndex) if self.retractionRatio > 0.0: self.addLinearMoveExtrusionDistanceLine( -self.repository.retractionDistance.value * self.retractionRatio) self.isExtruderActive = False elif firstWord == 'M108': self.flowRate = float(splitLine[1][1:]) self.distanceFeedRate.addLine(line)
def parseLine(self, line): "Parse a gcode line and add it to the vector output." splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if tableau.getIsLayerStart(firstWord, self, splitLine): self.layerCount.printProgressIncrement('skeiniso') self.skeinPane = SkeinPane( len( self.skeinPanes ) ) self.skeinPanes.append( self.skeinPane ) if firstWord == 'G1': location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) self.linearMove( line, location ) self.oldLocation = location elif firstWord == 'M101': self.moveColoredThreadToSkeinPane() self.extruderActive = True elif firstWord == 'M103': self.moveColoredThreadToSkeinPane() self.extruderActive = False self.isLoop = False self.isPerimeter = False elif firstWord == '(<loop>': self.isLoop = True elif firstWord == '(</loop>)': self.moveColoredThreadToSkeinPane() self.isLoop = False elif firstWord == '(<perimeter>': self.isPerimeter = True self.isOuter = ( splitLine[1] == 'outer') elif firstWord == '(</perimeter>)': self.moveColoredThreadToSkeinPane() self.isPerimeter = False elif firstWord == '(<surroundingLoop>)': self.hasASurroundingLoopBeenReached = True if firstWord == 'G2' or firstWord == 'G3': relativeLocation = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) relativeLocation.z = 0.0 location = self.oldLocation + relativeLocation self.linearMove( line, location ) self.oldLocation = location
def parseInitialization(self, clipRepository): 'Parse gcode initialization and store the parameters.' for self.lineIndex in xrange(len(self.lines)): line = self.lines[self.lineIndex] splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) self.distanceFeedRate.parseSplitLine(firstWord, splitLine) if firstWord == '(</extruderInitialization>)': self.distanceFeedRate.addLine( '(<procedureDone> clip </procedureDone>)') return elif firstWord == '(<perimeterWidth>': self.perimeterWidth = float(splitLine[1]) absolutePerimeterWidth = abs(self.perimeterWidth) self.clipLength = clipRepository.clipOverPerimeterWidth.value * self.perimeterWidth self.connectingStepLength = 0.5 * absolutePerimeterWidth self.layerPixelWidth = 0.1 * absolutePerimeterWidth self.maximumConnectionDistance = clipRepository.maximumConnectionDistanceOverPerimeterWidth.value * absolutePerimeterWidth elif firstWord == '(<travelFeedRatePerSecond>': self.travelFeedRatePerMinute = 60.0 * float(splitLine[1]) self.distanceFeedRate.addLine(line)
def getLayerTime(self): 'Get the time the extruder spends on the layer.' feedRateMinute = self.feedRateMinute layerTime = 0.0 lastThreadLocation = self.oldLocation for lineIndex in xrange(self.lineIndex, len(self.lines)): line = self.lines[lineIndex] splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) if firstWord == 'G1': location = gcodec.getLocationFromSplitLine(lastThreadLocation, splitLine) feedRateMinute = gcodec.getFeedRateMinute(feedRateMinute, splitLine) if lastThreadLocation != None: feedRateSecond = feedRateMinute / 60.0 layerTime += location.distance(lastThreadLocation) / feedRateSecond lastThreadLocation = location elif firstWord == '(<bridgeRotation>': self.isBridgeLayer = True elif firstWord == '(</layer>)': return layerTime return layerTime
def parseInitialization(self): 'Parse gcode initialization and store the parameters.' for self.lineIndex in xrange(len(self.lines)): line = self.lines[self.lineIndex] splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) self.distanceFeedRate.parseSplitLine(firstWord, splitLine) if firstWord == '(</extruderInitialization>)': self.distanceFeedRate.addLine( '(<procedureName> dimension </procedureName>)') return elif firstWord == '(<layerThickness>': self.layerThickness = float(splitLine[1]) elif firstWord == '(<operatingFeedRatePerSecond>': self.feedRateMinute = 60.0 * float(splitLine[1]) elif firstWord == '(<operatingFlowRate>': self.operatingFlowRate = float(splitLine[1]) self.flowRate = self.operatingFlowRate elif firstWord == '(<perimeterWidth>': self.perimeterWidth = float(splitLine[1]) self.distanceFeedRate.addLine(line)
def parseInitialization(self, combRepository): "Parse gcode initialization and store the parameters." for self.lineIndex in xrange(len(self.lines)): line = self.lines[self.lineIndex] splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) self.distanceFeedRate.parseSplitLine(firstWord, splitLine) if firstWord == '(</extruderInitialization>)': self.distanceFeedRate.addLine( '(<procedureDone> comb </procedureDone>)') return elif firstWord == '(<perimeterWidth>': perimeterWidth = float(splitLine[1]) self.combInset = 1.2 * perimeterWidth self.betweenInset = 0.4 * perimeterWidth self.uTurnWidth = 0.5 * self.betweenInset self.minimumDepartureDistance = combRepository.minimumDepartureDistanceOverPerimeterWidth.value * perimeterWidth self.runningJumpSpace = combRepository.runningJumpSpaceOverPerimeterWidth.value * perimeterWidth elif firstWord == '(<travelFeedRatePerSecond>': self.travelFeedRatePerMinute = 60.0 * float(splitLine[1]) self.distanceFeedRate.addLine(line)
def parseLine(self, line): "Parse a gcode line and add it to the bevel gcode." splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1': line = self.getHopLine(line) self.oldLocation = gcodec.getLocationFromSplitLine( self.oldLocation, splitLine) self.justDeactivated = False elif firstWord == 'M101': self.extruderActive = True elif firstWord == 'M103': self.extruderActive = False self.justDeactivated = True elif firstWord == '(<alteration>)': self.isAlteration = True elif firstWord == '(</alteration>)': self.isAlteration = False self.distanceFeedRate.addLine(line)
def parseInitialization(self): 'Parse gcode initialization and store the parameters.' for self.lineIndex in xrange(len(self.lines)): line = self.lines[self.lineIndex] splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) self.distanceFeedRate.parseSplitLine(firstWord, splitLine) if firstWord == 'M108': self.oldFlowRate = float(splitLine[1][1:]) elif firstWord == '(<edgeWidth>': self.edgeWidth = float(splitLine[1]) if self.repository.turnFanOnAtBeginning.value: self.setFanSpeed(self.repository.fanSpeedMax.value) elif firstWord == '(</extruderInitialization>)': self.distanceFeedRate.addTagBracketedProcedure('cool') return elif firstWord == '(<operatingFlowRate>': self.oldFlowRate = float(splitLine[1]) elif firstWord == '(<orbitalFeedRatePerSecond>': self.orbitalFeedRatePerSecond = float(splitLine[1]) self.distanceFeedRate.addLine(line)
def parseLine(self, line): "Parse a gcode line and add it to the widen skein." splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == '(<boundaryPoint>': location = gcodec.getLocationFromSplitLine(None, splitLine) self.boundary.append(location.dropAxis(2)) elif firstWord == '(<layer>': self.rotatedBoundaryLayer = euclidean.RotatedLoopLayer( float(splitLine[1])) self.distanceFeedRate.addLine(line) elif firstWord == '(</layer>)': self.addWiden(self.rotatedBoundaryLayer) self.rotatedBoundaryLayer = None elif firstWord == '(<surroundingLoop>)': self.boundary = [] self.rotatedBoundaryLayer.loops.append(self.boundary) if self.rotatedBoundaryLayer == None: self.distanceFeedRate.addLine(line)
def parseLine(self, line): 'Parse a gcode line and add it to the widen skein.' splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == '(<boundaryPoint>': location = gcodec.getLocationFromSplitLine(None, splitLine) self.boundary.append(location.dropAxis()) elif firstWord == '(<layer>': self.layerCount.printProgressIncrement('widen') self.loopLayer = euclidean.LoopLayer(float(splitLine[1])) self.distanceFeedRate.addLine(line) elif firstWord == '(</layer>)': self.addWiden(self.loopLayer) self.loopLayer = None elif firstWord == '(<nestedRing>)': self.boundary = [] self.loopLayer.loops.append(self.boundary) if self.loopLayer == None: self.distanceFeedRate.addLine(line)
def parseLine(self, line): "Parse a gcode line and add it to the comb skein." splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if self.distanceFeedRate.getIsAlteration(line): return if firstWord == 'G1': self.addIfTravel(splitLine) self.layerZ = self.nextLayerZ elif firstWord == 'M101': self.extruderActive = True elif firstWord == 'M103': self.extruderActive = False elif firstWord == '(<layer>': self.layerCount.printProgressIncrement('comb') self.nextLayerZ = float(splitLine[1]) if self.layerZ == None: self.layerZ = self.nextLayerZ self.distanceFeedRate.addLineCheckAlteration(line)
def parseInitialization(self): 'Parse gcode initialization and store the parameters.' for self.lineIndex in xrange(len(self.lines)): line = self.lines[self.lineIndex] splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) self.distanceFeedRate.parseSplitLine(firstWord, splitLine) if firstWord == '(<layerThickness>': self.layerThickness = float(splitLine[1]) elif firstWord == '(</extruderInitialization>)': self.distanceFeedRate.addLine('(<procedureDone> speed </procedureDone>)') return elif firstWord == '(<perimeterWidth>': self.absolutePerimeterWidth = abs(float(splitLine[1])) self.distanceFeedRate.addTagBracketedLine('operatingFeedRatePerSecond', self.feedRatePerSecond ) if self.repository.addFlowRate.value: self.distanceFeedRate.addTagBracketedLine('operatingFlowRate', self.repository.flowRateSetting.value ) orbitalFeedRatePerSecond = self.feedRatePerSecond * self.repository.orbitalFeedRateOverOperatingFeedRate.value self.distanceFeedRate.addTagBracketedLine('orbitalFeedRatePerSecond', orbitalFeedRatePerSecond ) self.distanceFeedRate.addTagBracketedLine('travelFeedRatePerSecond', self.repository.travelFeedRatePerSecond.value ) self.distanceFeedRate.addLine(line)
def parseLine(self, line): 'Parse a gcode line and add it to the smooth skein.' splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == '(<boundaryPerimeter>)': if self.boundaryLayerIndex < 0: self.boundaryLayerIndex = 0 elif firstWord == 'G1': self.feedRateMinute = gcodec.getFeedRateMinute( self.feedRateMinute, splitLine) location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) self.oldLocation = location if self.infill != None: self.infill.append(location.dropAxis()) return elif firstWord == '(<infill>)': if self.boundaryLayerIndex >= self.layersFromBottom: self.infill = [] elif firstWord == '(</infill>)': self.infill = None elif firstWord == '(<layer>': self.layerCount.printProgressIncrement('smooth') if self.boundaryLayerIndex >= 0: self.boundaryLayerIndex += 1 elif firstWord == 'M101': if self.infill != None: if len(self.infill) > 1: self.infill = [self.infill[0]] return elif firstWord == 'M103': if self.infill != None: self.addSmoothedInfill() self.infill = [] return elif firstWord == '(<rotation>': self.rotation = gcodec.getRotationBySplitLine(splitLine) self.distanceFeedRate.addLine(line)
def parseLine(self, line): "Parse a gcode line and add it to the outset skein." splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1': self.linearMove(splitLine) elif firstWord == 'M101': self.extruderActive = True elif firstWord == 'M103': self.extruderActive = False if self.isLoop: self.addToLoops() return if self.isPerimeter: self.addToPerimeters() return self.rotatedBoundaryLayer.paths.append(self.thread) self.thread = [] elif firstWord == '(</boundaryPerimeter>)': self.boundaryLoop = None elif firstWord == '(<boundaryPoint>': location = gcodec.getLocationFromSplitLine(None, splitLine) if self.boundaryLoop == None: self.boundaryLoop = [] self.rotatedBoundaryLayer.boundaryLoops.append( self.boundaryLoop) self.boundaryLoop.append(location.dropAxis(2)) elif firstWord == '(<layer>': self.addRotatedLoopLayer(float(splitLine[1])) elif firstWord == '(</loop>)': self.addToLoops() elif firstWord == '(<loop>': self.isLoop = True elif firstWord == '(<perimeter>': self.isPerimeter = True self.isOuter = (splitLine[1] == 'outer') elif firstWord == '(</perimeter>)': self.addToPerimeters()
def parseLine(self, line): "Parse a gcode line and add it to the statistics." self.characters += len(line) self.numberOfLines += 1 splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) 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 == 'M101': self.extruderSet(True) elif firstWord == 'M102': self.extruderSet(False) elif firstWord == 'M103': self.extruderSet(False) elif firstWord == 'M108': self.extruderSpeed = gcodec.getDoubleAfterFirstLetter(splitLine[1]) elif firstWord == '(<layerThickness>': self.layerThickness = float(splitLine[1]) # self.extrusionDiameter = self.repository.extrusionDiameterOverThickness.value * self.layerThickness elif firstWord == '(<operatingFeedRatePerSecond>': self.operatingFeedRatePerSecond = float(splitLine[1]) elif firstWord == '(<perimeterWidth>': self.perimeterWidth = float(splitLine[1]) self.absolutePerimeterWidth = abs(float(splitLine[1])) elif firstWord == '(<procedureName>': self.procedures.append(splitLine[1]) elif firstWord == '(<profileName>': self.profileName = line.replace('(<profileName>', '').replace('</profileName>)', '').strip() elif firstWord == '(<version>': self.version = splitLine[1]
def parseInitialization(self): 'Parse gcode initialization and store the parameters.' for self.lineIndex in xrange(len(self.lines)): line = self.lines[self.lineIndex] splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) self.distanceFeedRate.parseSplitLine(firstWord, splitLine) if firstWord == '(</extruderInitialization>)': self.distanceFeedRate.addTagBracketedProcedure('dwindle') return elif firstWord == '(<infillWidth>': self.infillWidth = float(splitLine[1]) elif firstWord == '(<layerHeight>': self.layerHeight = float(splitLine[1]) elif firstWord == '(<operatingFeedRatePerSecond>': self.operatingFeedRateMinute = 60.0 * float(splitLine[1]) elif firstWord == '(<operatingFlowRate>': self.operatingFlowRate = float(splitLine[1]) self.oldFlowRate = self.operatingFlowRate elif firstWord == '(<volumeFraction>': self.volumeFraction = float(splitLine[1]) self.distanceFeedRate.addLine(line)
def parseLine(self, line): "Parse a gcode line and add it to the clip skein." splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1': self.linearMove(splitLine) elif firstWord == 'M101': self.extruderActive = True elif firstWord == 'M103': self.extruderActive = False self.isLoopPerimeter = False if self.loopPath != None: self.addTailoredLoopPath(line) return elif firstWord == '(<layer>': self.setLayerPixelTable() if firstWord == '(<loop>' or firstWord == '(<perimeter>': self.isLoopPerimeter = True if self.loopPath == None: self.distanceFeedRate.addLine(line)
def parseInitialization(self): 'Parse gcode initialization and store the parameters.' for self.lineIndex in xrange(len(self.lines)): line = self.lines[self.lineIndex] splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) self.distanceFeedRate.parseSplitLine(firstWord, splitLine) if firstWord == '(<decimalPlacesCarried>': self.addInitializationToOutput() self.distanceFeedRate.addTagBracketedLine( 'bridgeWidthMultiplier', self.distanceFeedRate.getRounded( self.repository.bridgeWidthMultiplier.value)) elif firstWord == '(</extruderInitialization>)': self.distanceFeedRate.addTagBracketedLine( 'procedureName', 'inset') return elif firstWord == '(<perimeterWidth>': self.perimeterWidth = float(splitLine[1]) self.halfPerimeterWidth = 0.5 * self.perimeterWidth self.overlapRemovalWidth = self.perimeterWidth * self.repository.overlapRemovalWidthOverPerimeterWidth.value self.distanceFeedRate.addLine(line)