def deriveIntroLine( self, line, splitG1Line, introX, introY, introFeed ): "Creates a new linear gcode movement, derived from self.firstLinearGcodeMovement." roundedXString = 'X' + self.distanceFeedRate.getRounded( introX ) roundedYString = 'Y' + self.distanceFeedRate.getRounded( introY ) roundedFString = 'F' + self.distanceFeedRate.getRounded( introFeed ) indexOfX = gcodec.indexOfStartingWithSecond( 'X', splitG1Line ) introLine = line if indexOfX == -1: introLine = introLine + ' ' + roundedXString; else: word = splitG1Line[ indexOfX ] introLine = introLine.replace( word, roundedXString ) indexOfY = gcodec.indexOfStartingWithSecond( 'Y', splitG1Line ) if indexOfY == -1: introLine = introLine + ' ' + roundedYString; else: word = splitG1Line[ indexOfY ] introLine = introLine.replace( word, roundedYString ) indexOfF = gcodec.indexOfStartingWithSecond( 'F', splitG1Line ) if indexOfF == -1: introLine = introLine + ' ' + roundedFString; else: word = splitG1Line[ indexOfF ] introLine = introLine.replace( word, roundedFString ) return introLine;
def deriveIntroLine(self, line, splitG1Line, introX, introY, introFeed): "Creates a new linear gcode movement, derived from self.firstLinearGcodeMovement." roundedXString = 'X' + self.distanceFeedRate.getRounded(introX) roundedYString = 'Y' + self.distanceFeedRate.getRounded(introY) roundedFString = 'F' + self.distanceFeedRate.getRounded(introFeed) indexOfX = gcodec.indexOfStartingWithSecond('X', splitG1Line) introLine = line if indexOfX == -1: introLine = introLine + ' ' + roundedXString else: word = splitG1Line[indexOfX] introLine = introLine.replace(word, roundedXString) indexOfY = gcodec.indexOfStartingWithSecond('Y', splitG1Line) if indexOfY == -1: introLine = introLine + ' ' + roundedYString else: word = splitG1Line[indexOfY] introLine = introLine.replace(word, roundedYString) indexOfF = gcodec.indexOfStartingWithSecond('F', splitG1Line) if indexOfF == -1: introLine = introLine + ' ' + roundedFString else: word = splitG1Line[indexOfF] introLine = introLine.replace(word, roundedFString) return introLine
def getHopLine( self, line ): "Get hopped gcode line." splitLine = line.split( ' ' ) indexOfF = gcodec.indexOfStartingWithSecond( "F", splitLine ) if indexOfF > 0: self.feedrateString = splitLine[ indexOfF ] if self.extruderActive: return line location = gcodec.getLocationFromSplitLine( self.oldLocation, splitLine ) highestZ = location.z if self.oldLocation != None: highestZ = max( highestZ, self.oldLocation.z ) locationComplex = location.dropAxis( 2 ) if self.justDeactivated: oldLocationComplex = self.oldLocation.dropAxis( 2 ) distance = abs( locationComplex - oldLocationComplex ) if distance < self.minimumDistance: if self.isNextTravel(): return self.getMovementLineWithHop( locationComplex, highestZ ) alongRatio = min( 0.41666666, self.hopDistance / distance ) oneMinusAlong = 1.0 - alongRatio closeLocation = oldLocationComplex * oneMinusAlong + locationComplex * alongRatio self.addLine( self.getMovementLineWithHop( locationComplex, highestZ ) ) if self.isNextTravel(): return self.getMovementLineWithHop( locationComplex, highestZ ) farLocation = oldLocationComplex * alongRatio + locationComplex * oneMinusAlong self.addLine( self.getMovementLineWithHop( farLocation, highestZ ) ) return line if self.isNextTravel(): return self.getMovementLineWithHop( locationComplex, highestZ ) return line
def getUnpausedArcMovement( self, line, splitLine ): "Get an unpaused arc movement." if self.oldLocation == None: return line self.feedRateMinute = gcodec.getFeedRateMinute( self.feedRateMinute, splitLine ) relativeLocation = gcodec.getLocationFromSplitLine( self.oldLocation, splitLine ) location = self.oldLocation + relativeLocation self.oldLocation = location halfPlaneLineDistance = 0.5 * abs( relativeLocation.dropAxis( 2 ) ) radius = gcodec.getDoubleFromCharacterSplitLine( 'R', splitLine ) if radius == None: relativeCenter = complex( gcodec.getDoubleFromCharacterSplitLine( 'I', splitLine ), gcodec.getDoubleFromCharacterSplitLine( 'J', splitLine ) ) radius = abs( relativeCenter ) angle = 0.0 if radius > 0.0: angle = math.pi if halfPlaneLineDistance < radius: angle = 2.0 * math.asin( halfPlaneLineDistance / radius ) else: angle *= halfPlaneLineDistance / radius deltaZ = abs( relativeLocation.z ) arcDistanceZ = complex( abs( angle ) * radius, relativeLocation.z ) distance = abs( arcDistanceZ ) if distance <= 0.0: return '' feedRateMinute = self.distanceFeedRate.getZLimitedFeedRate( deltaZ, distance, self.feedRateMinute ) indexOfF = gcodec.indexOfStartingWithSecond( "F", splitLine ) if indexOfF > 0 and feedRateMinute != self.feedRateMinute: feedRateStringOriginal = splitLine[ indexOfF ] feedRateStringReplacement = 'F' + self.distanceFeedRate.getRounded( feedRateMinute ) return line.replace( feedRateStringOriginal, feedRateStringReplacement ) return line
def getHopLine(self, line): "Get hopped gcode line." splitLine = line.split(' ') indexOfF = gcodec.indexOfStartingWithSecond("F", splitLine) if indexOfF > 0: self.feedrateString = splitLine[indexOfF] if self.extruderActive: return line location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) highestZ = location.z if self.oldLocation != None: highestZ = max(highestZ, self.oldLocation.z) locationComplex = location.dropAxis(2) if self.justDeactivated: oldLocationComplex = self.oldLocation.dropAxis(2) distance = abs(locationComplex - oldLocationComplex) if distance < self.minimumDistance: if self.isNextTravel(): return self.getMovementLineWithHop(locationComplex, highestZ) alongRatio = min(0.41666666, self.hopDistance / distance) oneMinusAlong = 1.0 - alongRatio closeLocation = oldLocationComplex * oneMinusAlong + locationComplex * alongRatio self.addLine(self.getMovementLineWithHop(locationComplex, highestZ)) if self.isNextTravel(): return self.getMovementLineWithHop(locationComplex, highestZ) farLocation = oldLocationComplex * alongRatio + locationComplex * oneMinusAlong self.addLine(self.getMovementLineWithHop(farLocation, highestZ)) return line if self.isNextTravel(): return self.getMovementLineWithHop(locationComplex, highestZ) return line
def getLocationSetFeedRateToSplitLine(self, splitLine): location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) indexOfF = gcodec.indexOfStartingWithSecond("F", splitLine) if indexOfF > 0: self.feedRateMinute = gcodec.getDoubleAfterFirstLetter( splitLine[indexOfF]) return location
def getRaftlessSpeededLine( self, line, splitLine ): "Get gcode line with raftless feed rate." roundedFString = 'F' + self.distanceFeedRate.getRounded( self.feedRateMinute ) indexOfF = gcodec.indexOfStartingWithSecond( 'F', splitLine ) if indexOfF == - 1: return line + ' ' + roundedFString word = splitLine[ indexOfF ] return line.replace( word, roundedFString )
def getRaftlessSpeededLine(self, line, splitLine): "Get gcode line with raftless feed rate." roundedFString = 'F' + self.distanceFeedRate.getRounded( self.feedRateMinute) indexOfF = gcodec.indexOfStartingWithSecond('F', splitLine) if indexOfF == -1: return line + ' ' + roundedFString word = splitLine[indexOfF] return line.replace(word, roundedFString)
def helicalMove(self, isCounterclockwise, splitLine): "Get statistics for a helical move." if self.oldLocation == None: return location = self.getLocationSetFeedRateToSplitLine(splitLine) location += self.oldLocation center = self.oldLocation.copy() indexOfR = gcodec.indexOfStartingWithSecond("R", splitLine) if indexOfR > 0: radius = gcodec.getDoubleAfterFirstLetter(splitLine[indexOfR]) halfLocationMinusOld = location - self.oldLocation halfLocationMinusOld *= 0.5 halfLocationMinusOldLength = halfLocationMinusOld.magnitude() centerMidpointDistanceSquared = radius * radius - halfLocationMinusOldLength * halfLocationMinusOldLength centerMidpointDistance = math.sqrt( max(centerMidpointDistanceSquared, 0.0)) centerMinusMidpoint = euclidean.getRotatedWiddershinsQuarterAroundZAxis( halfLocationMinusOld) centerMinusMidpoint.normalize() centerMinusMidpoint *= centerMidpointDistance if isCounterclockwise: center.setToVector3(halfLocationMinusOld + centerMinusMidpoint) else: center.setToVector3(halfLocationMinusOld - centerMinusMidpoint) else: center.x = gcodec.getDoubleForLetter("I", splitLine) center.y = gcodec.getDoubleForLetter("J", splitLine) curveSection = 0.5 center += self.oldLocation afterCenterSegment = location - center beforeCenterSegment = self.oldLocation - center afterCenterDifferenceAngle = euclidean.getAngleAroundZAxisDifference( afterCenterSegment, beforeCenterSegment) absoluteDifferenceAngle = abs(afterCenterDifferenceAngle) steps = int( round(0.5 + max( absoluteDifferenceAngle * 2.4, absoluteDifferenceAngle * beforeCenterSegment.magnitude() / curveSection))) stepPlaneAngle = euclidean.getUnitPolar( afterCenterDifferenceAngle / steps, 1.0) zIncrement = (afterCenterSegment.z - beforeCenterSegment.z) / float(steps) for step in xrange(1, steps): beforeCenterSegment = euclidean.getRoundZAxisByPlaneAngle( stepPlaneAngle, beforeCenterSegment) beforeCenterSegment.z += zIncrement arcPoint = center + beforeCenterSegment self.addToPath(arcPoint) self.addToPath(location)
def helicalMove(self, isCounterclockwise, splitLine): "Get statistics for a helical move." if self.oldLocation == None: return location = self.getLocationSetFeedRateToSplitLine(splitLine) location += self.oldLocation center = self.oldLocation.copy() indexOfR = gcodec.indexOfStartingWithSecond("R", splitLine) if indexOfR > 0: radius = gcodec.getDoubleAfterFirstLetter(splitLine[indexOfR]) halfLocationMinusOld = location - self.oldLocation halfLocationMinusOld *= 0.5 halfLocationMinusOldLength = halfLocationMinusOld.magnitude() centerMidpointDistanceSquared = radius * radius - halfLocationMinusOldLength * halfLocationMinusOldLength centerMidpointDistance = math.sqrt(max(centerMidpointDistanceSquared, 0.0)) centerMinusMidpoint = euclidean.getRotatedWiddershinsQuarterAroundZAxis(halfLocationMinusOld) centerMinusMidpoint.normalize() centerMinusMidpoint *= centerMidpointDistance if isCounterclockwise: center.setToVector3(halfLocationMinusOld + centerMinusMidpoint) else: center.setToVector3(halfLocationMinusOld - centerMinusMidpoint) else: center.x = gcodec.getDoubleForLetter("I", splitLine) center.y = gcodec.getDoubleForLetter("J", splitLine) curveSection = 0.5 center += self.oldLocation afterCenterSegment = location - center beforeCenterSegment = self.oldLocation - center afterCenterDifferenceAngle = euclidean.getAngleAroundZAxisDifference(afterCenterSegment, beforeCenterSegment) absoluteDifferenceAngle = abs(afterCenterDifferenceAngle) steps = int( round( 0.5 + max( absoluteDifferenceAngle * 2.4, absoluteDifferenceAngle * beforeCenterSegment.magnitude() / curveSection, ) ) ) stepPlaneAngle = euclidean.getPolar(afterCenterDifferenceAngle / steps, 1.0) zIncrement = (afterCenterSegment.z - beforeCenterSegment.z) / float(steps) for step in xrange(1, steps): beforeCenterSegment = euclidean.getRoundZAxisByPlaneAngle(stepPlaneAngle, beforeCenterSegment) beforeCenterSegment.z += zIncrement arcPoint = center + beforeCenterSegment self.addToPath(arcPoint) self.addToPath(location)
def getLocationSetFeedRateToSplitLine( self, splitLine ): location = gcodec.getLocationFromSplitLine( self.oldLocation, splitLine ) indexOfF = gcodec.indexOfStartingWithSecond( "F", splitLine ) if indexOfF > 0: self.feedRateMinute = gcodec.getDoubleAfterFirstLetter( splitLine[ indexOfF ] ) return location