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.speedRepository.addFlowRate.value: self.distanceFeedRate.addTagBracketedLine( "operatingFlowRate", self.speedRepository.flowRateSetting.value ) orbitalFeedRatePerSecond = ( self.feedRatePerSecond * self.speedRepository.orbitalFeedRateOverOperatingFeedRate.value ) self.distanceFeedRate.addTagBracketedLine("orbitalFeedRatePerSecond", orbitalFeedRatePerSecond) self.distanceFeedRate.addTagBracketedLine( "travelFeedRatePerSecond", self.speedRepository.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 = line.split() 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 setLayerPixelTable(self): "Parse a gcode line and add it to the clip skein." boundaryLoop = None extruderActive = False maskPixelTable = {} self.boundaryLoops = [] self.maskPixelTableTable = {} 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) oldLocation = location elif firstWord == 'M101': extruderActive = True elif firstWord == 'M103': 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 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(2)) elif firstWord == '(<layer>': boundaryLayer = euclidean.LoopLayer(float(splitLine[1])) self.boundaryLayers.append(boundaryLayer) elif firstWord == '(</extrusion>)': 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." 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' ) # print( 'xInteger' ) # print( xInteger ) 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 ): "Parse a gcode line and add it to the clip skein." boundaryLoop = None extruderActive = False maskPixelTable = {} self.boundaryLoops = [] self.maskPixelTableTable = {} 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 ) oldLocation = location elif firstWord == 'M101': extruderActive = True elif firstWord == 'M103': 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 getTransferClosestSurroundingLoopLines( self, oldOrderedLocation, remainingSurroundingLoops ): "Get and transfer the closest remaining surrounding loop." if len( remainingSurroundingLoops ) > 0: oldOrderedLocation.z = remainingSurroundingLoops[ 0 ].z closestDistance = 999999999999999999.0 closestSurroundingLoop = None for remainingSurroundingLoop in remainingSurroundingLoops: distance = euclidean.getNearestDistanceIndex( oldOrderedLocation.dropAxis( 2 ), remainingSurroundingLoop.boundary ).distance if distance < closestDistance: closestDistance = distance closestSurroundingLoop = remainingSurroundingLoop remainingSurroundingLoops.remove( closestSurroundingLoop ) hasTravelledHighRoad = False for line in closestSurroundingLoop.lines: splitLine = gcodec.getSplitLineBeforeBracketSemicolon( line ) firstWord = gcodec.getFirstWord( splitLine ) if firstWord == 'G1': location = gcodec.getLocationFromSplitLine( self.oldLocation, splitLine ) if not hasTravelledHighRoad: hasTravelledHighRoad = True self.addHighThread( location ) if location.z > self.highestZ: self.highestZ = location.z self.oldLocation = location self.distanceFeedRate.addLine( line ) return closestSurroundingLoop
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> feed </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) self.distanceFeedRate.addTagBracketedLine( 'travelFeedRatePerSecond', self.feedRepository.travelFeedRatePerSecond.value) 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 = line.split() firstWord = gcodec.getFirstWord( splitLine ) self.distanceFeedRate.parseSplitLine( firstWord, splitLine ) if firstWord == 'M108': self.setOperatingFlowString( splitLine ) elif firstWord == '(</extruderInitialization>)': self.distanceFeedRate.addLine( '(<procedureDone> raft </procedureDone>)' ) elif firstWord == '(<layer>': return elif firstWord == '(<layerThickness>': self.layerThickness = float( splitLine[ 1 ] ) elif firstWord == '(<orbitalFeedRatePerSecond>': self.orbitalFeedRatePerSecond = float( splitLine[ 1 ] ) elif firstWord == '(<operatingFeedRatePerSecond>': self.feedRateMinute = 60.0 * float( splitLine[ 1 ] ) elif firstWord == '(<perimeterWidth>': self.perimeterWidth = float( splitLine[ 1 ] ) self.supportOutset = self.perimeterWidth + self.perimeterWidth * self.raftRepository.supportGapOverPerimeterExtrusionWidth.value elif firstWord == '(<travelFeedRatePerSecond>': self.travelFeedRatePerMinute = 60.0 * float( splitLine[ 1 ] ) self.distanceFeedRate.addLine( line )
def parseLine( self, line ): "Parse a gcode line." splitLine = gcodec.getSplitLineBeforeBracketSemicolon( line ) firstWord = gcodec.getFirstWord( splitLine ) if len( firstWord ) < 1: return firstLetter = firstWord[ 0 ] if firstLetter == '(': return if firstWord != 'G1' and firstWord != 'G2' and firstWord != 'G3': self.addLine( line ) return lineStringIO = cStringIO.StringIO() lineStringIO.write( firstWord ) self.addCharacterInteger( 'I', lineStringIO, 0.0, splitLine, self.gcodeStepRepository.xStepLength.value ) self.addCharacterInteger( 'J', lineStringIO, 0.0, splitLine, self.gcodeStepRepository.yStepLength.value ) self.addCharacterInteger( 'R', lineStringIO, 0.0, splitLine, self.gcodeStepRepository.radiusStepLength.value ) self.addCharacterInteger( 'X', lineStringIO, self.gcodeStepRepository.xOffset.value, splitLine, self.gcodeStepRepository.xStepLength.value ) self.addCharacterInteger( 'Y', lineStringIO, self.gcodeStepRepository.yOffset.value, splitLine, self.gcodeStepRepository.yStepLength.value ) zString = getCharacterIntegerString( 'Z', self.gcodeStepRepository.zOffset.value, splitLine, self.gcodeStepRepository.zStepLength.value ) feedRateString = getCharacterIntegerString( 'F', 0.0, splitLine, self.gcodeStepRepository.feedRateStepLength.value ) if zString != None: if zString != self.oldZString or self.gcodeStepRepository.addZEvenWhenUnchanging.value: self.addStringToLine( lineStringIO, zString ) if feedRateString != None: if feedRateString != self.oldFeedRateString or self.gcodeStepRepository.addFeedRateEvenWhenUnchanging.value: self.addStringToLine( lineStringIO, feedRateString ) self.addLine( lineStringIO.getvalue() ) self.oldFeedRateString = feedRateString self.oldZString = zString
def getTransferClosestSurroundingLoopLines(self, oldOrderedLocation, remainingSurroundingLoops): "Get and transfer the closest remaining surrounding loop." if len(remainingSurroundingLoops) > 0: oldOrderedLocation.z = remainingSurroundingLoops[0].z closestDistance = 999999999999999999.0 closestSurroundingLoop = None for remainingSurroundingLoop in remainingSurroundingLoops: distance = euclidean.getNearestDistanceIndex( oldOrderedLocation.dropAxis(2), remainingSurroundingLoop.boundary).distance if distance < closestDistance: closestDistance = distance closestSurroundingLoop = remainingSurroundingLoop remainingSurroundingLoops.remove(closestSurroundingLoop) hasTravelledHighRoad = False for line in closestSurroundingLoop.lines: splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) if firstWord == 'G1': location = gcodec.getLocationFromSplitLine( self.oldLocation, splitLine) if not hasTravelledHighRoad: hasTravelledHighRoad = True self.addHighThread(location) if location.z > self.highestZ: self.highestZ = location.z self.oldLocation = location self.distanceFeedRate.addLine(line) return closestSurroundingLoop
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( 2 ) ) elif firstWord == '(<layer>': boundaryLayer = euclidean.LoopLayer( float( splitLine[ 1 ] ) ) self.boundaryLayers.append( boundaryLayer ) elif firstWord == '(</extrusion>)': 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 parseInitialization( self ): "Parse gcode initialization and store the parameters." for self.lineIndex in xrange( len( self.lines ) ): line = self.lines[ self.lineIndex ].lstrip() splitLine = line.split() firstWord = gcodec.getFirstWord( splitLine ) self.distanceFeedRate.parseSplitLine( firstWord, splitLine ) if firstWord == '(<decimalPlacesCarried>': self.addInitializationToOutput() elif firstWord == '(</extruderInitialization>)': self.distanceFeedRate.addTagBracketedLine( 'procedureDone', 'inset' ) elif firstWord == '(<perimeterWidth>': self.perimeterWidth = float( splitLine[ 1 ] ) self.halfPerimeterWidth = 0.5 * self.perimeterWidth self.fromExtrusionFillInset = self.perimeterWidth - self.perimeterWidth * self.insetPreferences.infillPerimeterOverlap.value if self.insetPreferences.perimeterInfillPreference.value: self.fromExtrusionFillInset = self.halfPerimeterWidth + 0.5 * self.extrusionWidth - self.extrusionWidth * self.insetPreferences.infillPerimeterOverlap.value self.distanceFeedRate.addTagBracketedLine( 'fillInset', self.fromExtrusionFillInset ) # Set bridge extrusion width elif firstWord == '(<layer>': self.lineIndex -= 1 return elif firstWord == '(<layerThickness>': self.layerThickness = float( splitLine[ 1 ] ) self.extrusionWidth = self.insetPreferences.extrusionWidthOverThickness.value * self.layerThickness self.distanceFeedRate.addTagBracketedLine( 'extrusionWidth', self.distanceFeedRate.getRounded( self.extrusionWidth ) ) # Set extrusion width. self.distanceFeedRate.addTagBracketedLine( 'infillBridgeWidthOverExtrusionWidth', self.distanceFeedRate.getRounded( self.insetPreferences.infillBridgeWidthOverExtrusionWidth.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 parseInitialization( self ): "Parse gcode initialization and store the parameters." for self.lineIndex in xrange( len( self.lines ) ): line = self.lines[ self.lineIndex ] splitLine = line.split() firstWord = gcodec.getFirstWord( splitLine ) if firstWord == 'M108': self.setOperatingFlowString( splitLine ) elif firstWord == '(<decimalPlacesCarried>': self.decimalPlacesCarried = int( splitLine[ 1 ] ) elif firstWord == '(<extrusionPerimeterWidth>': self.extrusionPerimeterWidth = float( splitLine[ 1 ] ) self.supportOutset = self.extrusionPerimeterWidth - self.extrusionPerimeterWidth * self.raftPreferences.supportInsetOverPerimeterExtrusionWidth.value elif firstWord == '(<extrusionWidth>': self.extrusionWidth = float( splitLine[ 1 ] ) elif firstWord == '(</extruderInitialization>)': self.addLine( '(<procedureDone> raft /<procedureDone>)' ) elif firstWord == '(<feedrateMinute>': self.feedrateMinute = float( splitLine[ 1 ] ) elif firstWord == '(<layer>': return elif firstWord == '(<layerThickness>': self.layerThickness = float( splitLine[ 1 ] ) elif firstWord == '(<orbitalFeedratePerSecond>': self.orbitalFeedratePerSecond = float( splitLine[ 1 ] ) elif firstWord == '(<supportFlowrate>': self.supportFlowrateString = splitLine[ 1 ] elif firstWord == '(<travelFeedratePerSecond>': self.travelFeedratePerMinute = 60.0 * float( splitLine[ 1 ] ) self.addLine( line )
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 parseCorner(self, line): "Parse a gcode line and use the location to update the bounding corners." splitLine = line.split() firstWord = gcodec.getFirstWord(splitLine) if firstWord == "(<boundaryPoint>": locationComplex = gcodec.getLocationFromSplitLine(None, splitLine).dropAxis(2) self.cornerMaximum = euclidean.getMaximum(self.cornerMaximum, locationComplex) self.cornerMinimum = euclidean.getMinimum(self.cornerMinimum, locationComplex)
def getParameterFromJavascript( lines, parameterName, parameterValue ): "Get a parameter from lines of javascript." for line in lines: strippedLine = line.replace( ';', ' ' ).lstrip() splitLine = strippedLine.split() firstWord = gcodec.getFirstWord( splitLine ) if firstWord == parameterName: return float( splitLine[ 2 ] ) return parameterValue
def parseUntilOperatingLayer( self ): "Parse gcode until the operating layer if there is one." for self.lineIndex in xrange( self.lineIndex, len( self.lines ) ): line = self.lines[ self.lineIndex ] splitLine = line.split() firstWord = gcodec.getFirstWord( splitLine ) self.addLine( line ) if firstWord == '(<operatingLayerEnd>': return
def getParameterFromJavascript(lines, parameterName, parameterValue): "Get a paramater from lines of javascript." for line in lines: strippedLine = line.replace(';', ' ').lstrip() splitLine = strippedLine.split() firstWord = gcodec.getFirstWord(splitLine) if firstWord == parameterName: return float(splitLine[2]) return parameterValue
def getNextLocation( self ): "Get the next linear move. Return none is none is found." for afterIndex in xrange( self.lineIndex + 1, len( self.lines ) ): line = self.lines[ afterIndex ] splitLine = line.split( ' ' ) if gcodec.getFirstWord( splitLine ) == 'G1': nextLocation = gcodec.getLocationFromSplitLine( self.oldLocation, splitLine ) return nextLocation return None
def getNextLocation( self ): "Get the next linear move. Return none is none is found." for afterIndex in xrange( self.lineIndex + 1, len( self.lines ) ): line = self.lines[ afterIndex ] splitLine = gcodec.getSplitLineBeforeBracketSemicolon( line ) if gcodec.getFirstWord( splitLine ) == 'G1': nextLocation = gcodec.getLocationFromSplitLine( self.oldLocation, splitLine ) return nextLocation return None
def parseUntilOperatingLayer( self ): "Parse gcode until the operating layer if there is one." for self.lineIndex in xrange( self.lineIndex, len( self.lines ) ): line = self.lines[ self.lineIndex ] splitLine = line.split() firstWord = gcodec.getFirstWord( splitLine ) self.distanceFeedRate.addLine( line ) if firstWord == '(<operatingLayerEnd>': return
def addFacesGivenText(objText, triangleMesh): "Add faces given obj text." lines = gcodec.getTextLines(objText) for line in lines: splitLine = line.split() firstWord = gcodec.getFirstWord(splitLine) if firstWord == 'v': triangleMesh.vertices.append(getVertexGivenLine(line)) elif firstWord == 'f': triangleMesh.faces.append(getFaceGivenLine(line, triangleMesh))
def addRemoveThroughLayer(self): "Parse gcode initialization and store the parameters." for layerLineIndex in xrange(len(self.layerLines)): line = self.layerLines[layerLineIndex] splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) self.distanceFeedRate.addLine(line) if firstWord == '(<layer>': self.layerLines = self.layerLines[layerLineIndex + 1:] return
def addRemoveThroughLayer( self ): "Parse gcode initialization and store the parameters." for layerLineIndex in xrange( len( self.layerLines ) ): line = self.layerLines[ layerLineIndex ] splitLine = line.split() firstWord = gcodec.getFirstWord( splitLine ) self.distanceFeedRate.addLine( line ) if firstWord == '(<layer>': self.layerLines = self.layerLines[ layerLineIndex + 1 : ] return
def parseUntilLayer( self ): "Parse until the layer line and add it to the coil skein." for self.lineIndex in xrange( self.lineIndex, len( self.lines ) ): line = self.lines[ self.lineIndex ] splitLine = gcodec.getSplitLineBeforeBracketSemicolon( line ) firstWord = gcodec.getFirstWord( splitLine ) self.distanceFeedRate.parseSplitLine( firstWord, splitLine ) if firstWord == '(<layer>': return 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 ) if firstWord == '(</extruderInitialization>)': return elif firstWord == '(<operatingFeedRatePerSecond>': self.feedRateMinute = 60.0 * float( 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) if firstWord == '(</extruderInitialization>)': return elif firstWord == '(<operatingFeedRatePerSecond>': self.feedRateMinute = 60.0 * float(splitLine[1])
def setMaximumZ( self ): "Set maximum z." localOldLocation = None for line in self.lines[ self.lineIndex : ]: splitLine = gcodec.getSplitLineBeforeBracketSemicolon( line ) firstWord = gcodec.getFirstWord( splitLine ) if firstWord == 'G1': location = gcodec.getLocationFromSplitLine( localOldLocation, splitLine ) self.maximumZ = max( self.maximumZ, location.z ) localOldLocation = location
def getIndexJustAfterActivate( self ): "Get index just after the activate command." for lineIndex in xrange( self.lineIndex - 1, 3, - 1 ): line = self.lines[ lineIndex ] splitLine = gcodec.getSplitLineBeforeBracketSemicolon( line ) firstWord = gcodec.getFirstWord( splitLine ) if firstWord == 'M101': return lineIndex + 1 print( 'This should never happen in stretch, no activate command was found for this thread.' ) raise StopIteration, "You've reached the end of the line."
def parseUntilLayer(self): "Parse until the layer line and add it to the coil skein." for self.lineIndex in xrange(self.lineIndex, len(self.lines)): line = self.lines[self.lineIndex] splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) self.distanceFeedRate.parseSplitLine(firstWord, splitLine) if firstWord == '(<layer>': return self.distanceFeedRate.addLine(line)
def addFacesGivenText( objText, triangleMesh ): "Add faces given obj text." lines = gcodec.getTextLines( objText ) for line in lines: splitLine = line.split() firstWord = gcodec.getFirstWord( splitLine ) if firstWord == 'v': triangleMesh.vertices.append( getVertexGivenLine( line ) ) elif firstWord == 'f': triangleMesh.faces.append( getFaceGivenLine( line, triangleMesh ) )
def getIndexBeforeNextDeactivate( self ): "Get index two lines before the deactivate command." for lineIndex in xrange( self.lineIndex + 1, len( self.lines ) ): line = self.lines[ lineIndex ] splitLine = gcodec.getSplitLineBeforeBracketSemicolon( line ) firstWord = gcodec.getFirstWord( splitLine ) if firstWord == 'M103': return lineIndex - 2 print( 'This should never happen in stretch, no deactivate command was found for this thread.' ) raise StopIteration, "You've reached the end of the 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(2)) elif firstWord == '(<layer>': boundaryLayer = euclidean.LoopLayer(float(splitLine[1])) self.boundaryLayers.append(boundaryLayer) if len(self.boundaryLayers) < 2: return for boundaryLayer in self.boundaryLayers: boundaryLayer.innerOutsetLoops = intercircle.getInsetSeparateLoopsFromLoops( -self.loopInnerOutset, boundaryLayer.loops) boundaryLayer.outerOutsetLoops = intercircle.getInsetSeparateLoopsFromLoops( -self.loopOuterOutset, boundaryLayer.loops) boundaryLayer.innerHorizontalTable = self.getHorizontalXIntersectionsTable( boundaryLayer.innerOutsetLoops) boundaryLayer.outerHorizontalTable = self.getHorizontalXIntersectionsTable( boundaryLayer.outerOutsetLoops) boundaryLayer.innerVerticalTable = self.getHorizontalXIntersectionsTable( euclidean.getDiagonalFlippedLoops( boundaryLayer.innerOutsetLoops)) boundaryLayer.outerVerticalTable = self.getHorizontalXIntersectionsTable( euclidean.getDiagonalFlippedLoops( boundaryLayer.outerOutsetLoops)) for boundaryLayerIndex in xrange(len(self.boundaryLayers) - 2, -1, -1): boundaryLayer = self.boundaryLayers[boundaryLayerIndex] boundaryLayerBelow = self.boundaryLayers[boundaryLayerIndex + 1] euclidean.joinXIntersectionsTables( boundaryLayerBelow.outerHorizontalTable, boundaryLayer.outerHorizontalTable) euclidean.joinXIntersectionsTables( boundaryLayerBelow.outerVerticalTable, boundaryLayer.outerVerticalTable) for boundaryLayerIndex in xrange(1, len(self.boundaryLayers)): boundaryLayer = self.boundaryLayers[boundaryLayerIndex] boundaryLayerAbove = self.boundaryLayers[boundaryLayerIndex - 1] euclidean.joinXIntersectionsTables( boundaryLayerAbove.innerHorizontalTable, boundaryLayer.innerHorizontalTable) euclidean.joinXIntersectionsTables( boundaryLayerAbove.innerVerticalTable, boundaryLayer.innerVerticalTable) for boundaryLayerIndex in xrange(len(self.boundaryLayers)): self.addSegmentTableLoops(boundaryLayerIndex)
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> lash </procedureDone>)' ) return self.distanceFeedRate.addLine( line )
def isNextExtruderOn( self ): "Determine if there is an extruder on command before a move command." 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 setMaximumZ(self): "Set maximum z." localOldLocation = None for line in self.lines[self.lineIndex:]: splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) if firstWord == 'G1': location = gcodec.getLocationFromSplitLine( localOldLocation, splitLine) self.maximumZ = max(self.maximumZ, location.z) localOldLocation = location
def parseInitialization( self ): "Parse gcode initialization and store the parameters." for self.lineIndex in xrange( len( self.lines ) ): line = self.lines[ self.lineIndex ] splitLine = line.split() firstWord = gcodec.getFirstWord( splitLine ) self.distanceFeedRate.parseSplitLine( firstWord, splitLine ) if firstWord == '(</extruderInitialization>)': self.distanceFeedRate.addLine( '(<procedureDone> flow </procedureDone>)' ) return self.distanceFeedRate.addLine( line )
def isNextExtruderOn(self): "Determine if there is an extruder on command before a move command." 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 parseInitialization(self): "Parse gcode initialization and store the parameters." for self.lineIndex in xrange(len(self.lines)): line = self.lines[self.lineIndex] splitLine = line.split() firstWord = gcodec.getFirstWord(splitLine) if firstWord == '(<decimalPlacesCarried>': self.decimalPlacesCarried = int(splitLine[1]) elif firstWord == '(</extruderInitialization>)': self.addLine('(<procedureDone> unpause </procedureDone>)') return self.addLine(line)
def getIndexBeforeNextDeactivate(self): "Get index two lines before the deactivate command." for lineIndex in xrange(self.lineIndex + 1, len(self.lines)): line = self.lines[lineIndex] splitLine = line.split() firstWord = gcodec.getFirstWord(splitLine) if firstWord == 'M103': return lineIndex - 2 print( 'This should never happen in stretch, no deactivate command was found for this thread.' ) raise StopIteration, "You've reached the end of the 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 = line.split() firstWord = gcodec.getFirstWord( splitLine ) if firstWord == '(<decimalPlacesCarried>': self.decimalPlacesCarried = int( splitLine[ 1 ] ) elif firstWord == '(</extruderInitialization>)': self.addLine( '(<procedureDone> unpause </procedureDone>)' ) return self.addLine( line )
def addElement( self, offset ): "Add moved element to the output." for line in self.layerLines: splitLine = line.split() firstWord = gcodec.getFirstWord( splitLine ) if firstWord == 'G1': movedLocation = self.getMovedLocationSetOldLocation( offset, splitLine ) line = self.getGcodeFromMovementZ( movedLocation, self.oldLocation.z ) elif firstWord == '(<boundaryPoint>': movedLocation = self.getMovedLocationSetOldLocation( offset, splitLine ) line = '(<boundaryPoint> X%s Y%s Z%s )' % ( self.getRounded( movedLocation.real ), self.getRounded( movedLocation.imag ), self.getRounded( self.oldLocation.z ) ) self.addLine( line )
def addElement( self, offset ): "Add moved element to the output." for line in self.layerLines: splitLine = line.split() firstWord = gcodec.getFirstWord( splitLine ) if firstWord == 'G1': movedLocation = self.getMovedLocationSetOldLocation( offset, splitLine ) line = self.distanceFeedRate.getLinearGcodeMovement( movedLocation.dropAxis( 2 ), movedLocation.z ) elif firstWord == '(<boundaryPoint>': movedLocation = self.getMovedLocationSetOldLocation( offset, splitLine ) line = self.distanceFeedRate.getBoundaryLine( movedLocation ) self.distanceFeedRate.addLine( line )
def getIndexJustAfterActivate(self): "Get index just after the activate command." for lineIndex in xrange(self.lineIndex - 1, 3, -1): line = self.lines[lineIndex] splitLine = line.split() firstWord = gcodec.getFirstWord(splitLine) if firstWord == 'M101': return lineIndex + 1 print( 'This should never happen in stretch, no activate command was found for this thread.' ) raise StopIteration, "You've reached the end of the line."
def isJustBeforeExtrusion( self ): "Determine if activate command is before linear move command." for lineIndex in xrange( self.lineIndex + 1, len( self.lines ) ): line = self.lines[ lineIndex ] splitLine = gcodec.getSplitLineBeforeBracketSemicolon( line ) firstWord = gcodec.getFirstWord( splitLine ) if firstWord == 'G1' or firstWord == 'M103': return False if firstWord == 'M101': return True print( 'This should never happen in isJustBeforeExtrusion in splodge, no activate or deactivate command was found for this thread.' ) return False
def getNextActiveLocationComplex( self ): "Get the next active line." isActive = False for lineIndex in xrange( self.lineIndex + 1, len( self.lines ) ): line = self.lines[ lineIndex ] splitLine = gcodec.getSplitLineBeforeBracketSemicolon( line ) firstWord = gcodec.getFirstWord( splitLine ) if firstWord == 'M101': isActive = True if firstWord == 'G1' and isActive: return gcodec.getLocationFromSplitLine( self.oldLocation, splitLine ).dropAxis( 2 ) return None
def isJustBeforeExtrusion( self ): "Determine if activate command is before linear move command." for lineIndex in xrange( self.lineIndex + 1, len( self.lines ) ): line = self.lines[ lineIndex ] splitLine = gcodec.getSplitLineBeforeBracketSemicolon( line ) firstWord = gcodec.getFirstWord( splitLine ) if firstWord == 'G1' or firstWord == 'M103': return False if firstWord == 'M101': return True print( 'This should never happen in isJustBeforeExtrusion in stretch, no activate or deactivate command was found for this thread.' ) return False
def parseInitialization(self): "Parse gcode initialization and store the parameters." for self.lineIndex in xrange(len(self.lines)): line = self.lines[self.lineIndex].lstrip() splitLine = gcodec.getWithoutBracketsEqualTab(line).split() firstWord = gcodec.getFirstWord(splitLine) self.distanceFeedRate.parseSplitLine(firstWord, splitLine) if firstWord == 'layerThickness': self.layerThickness = float(splitLine[1]) elif firstWord == 'extrusionStart': return elif firstWord == 'perimeterWidth': self.perimeterWidth = float(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 ].lstrip() splitLine = gcodec.getWithoutBracketsEqualTab( line ).split() firstWord = gcodec.getFirstWord( splitLine ) self.distanceFeedRate.parseSplitLine( firstWord, splitLine ) if firstWord == 'layerThickness': self.layerThickness = float( splitLine[ 1 ] ) elif firstWord == 'extrusionStart': return elif firstWord == 'perimeterWidth': self.perimeterWidth = float( splitLine[ 1 ] )
def parseUntilOperatingLayer(self): "Parse gcode until the operating layer if there is one." for self.lineIndex in xrange(self.lineIndex, len(self.lines)): line = self.lines[self.lineIndex] splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) self.distanceFeedRate.addLine(line) if firstWord == 'G1': self.oldLocation = gcodec.getLocationFromSplitLine( self.oldLocation, splitLine) if self.oldLocation.z > self.highestZ: self.highestZ = self.oldLocation.z if firstWord == '(<operatingLayerEnd>': return
def parseInitialization( self ): "Parse gcode initialization and store the parameters." for self.lineIndex in xrange( len( self.lines ) ): line = self.lines[ self.lineIndex ].lstrip() splitLine = gcodec.getSplitLineBeforeBracketSemicolon( line ) firstWord = gcodec.getFirstWord( splitLine ) self.distanceFeedRate.parseSplitLine( firstWord, splitLine ) if firstWord == '(</extruderInitialization>)': self.distanceFeedRate.addTagBracketedLine( 'procedureDone', 'whittle' ) return elif firstWord == '(<layerThickness>': self.setLayerThinknessVerticalDeltas( splitLine ) self.distanceFeedRate.addTagBracketedLine( 'layerStep', self.layerStep ) 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) if firstWord == '(<decimalPlacesCarried>': self.decimalPlacesCarried = int(splitLine[1]) elif firstWord == '(<layerThickness>': self.layerThickness = float(splitLine[1]) elif firstWord == '(<extrusion>)': return elif firstWord == '(<perimeterWidth>': self.perimeterWidth = float(splitLine[1])
def getActiveFeedRateRatio( self ): "Get the feed rate of the first active move over the operating feed rate." isSearchExtruderActive = self.isExtruderActive for afterIndex in xrange( self.lineIndex, len( self.lines ) ): line = self.lines[ afterIndex ] splitLine = gcodec.getSplitLineBeforeBracketSemicolon( line ) firstWord = gcodec.getFirstWord( splitLine ) if firstWord == 'G1': if isSearchExtruderActive: return gcodec.getFeedRateMinute( self.feedRateMinute, splitLine ) / self.operatingFeedRateMinute elif firstWord == 'M101': isSearchExtruderActive = True print( 'active feed rate ratio was not found in oozebane.' ) return 1.0
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 == 'G1': movedLocation = self.getMovedLocationSetOldLocation( offset, splitLine) line = self.distanceFeedRate.getLinearGcodeMovement( movedLocation.dropAxis(2), movedLocation.z) elif firstWord == '(<boundaryPoint>': movedLocation = self.getMovedLocationSetOldLocation( offset, splitLine) line = self.distanceFeedRate.getBoundaryLine(movedLocation) self.distanceFeedRate.addLine(line)