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 == '(</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 parseBoundaries(self): 'Parse the boundaries and add them to the boundary layers.' self.boundaryLayers = [] self.layerIndexTop = -1 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) self.layerIndexTop += 1 for boundaryLayerIndex, boundaryLayer in enumerate(self.boundaryLayers): if len(boundaryLayer.loops) > 0: self.layersFromBottom += boundaryLayerIndex 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()) 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 getLoopLayer(self): "Return the rotated loop layer." if self.z is not None: loopLayer = euclidean.LoopLayer(self.z) self.loopLayers.append(loopLayer) self.z = None return self.loopLayers[-1]
def getLoopLayersSetCopy(elementNode, geometryOutput, importRadius, radius): 'Get the loop layers and set the copyShallow.' halfLayerHeight = 0.5 * radius copyShallow = elementNode.getCopyShallow() processElementNodeByGeometry(copyShallow, geometryOutput) targetMatrix = matrix.getBranchMatrixSetElementNode(elementNode) matrix.setElementNodeDictionaryMatrix(copyShallow, targetMatrix) transformedVertexes = copyShallow.xmlObject.getTransformedVertexes() minimumZ = boolean_geometry.getMinimumZ(copyShallow.xmlObject) if minimumZ == None: copyShallow.parentNode.xmlObject.archivableObjects.remove( copyShallow.xmlObject) return [] maximumZ = euclidean.getTopPath(transformedVertexes) copyShallow.attributes['visible'] = True copyShallowObjects = [copyShallow.xmlObject] bottomLoopLayer = euclidean.LoopLayer(minimumZ) z = minimumZ + 0.1 * radius zoneArrangement = triangle_mesh.ZoneArrangement(radius, transformedVertexes) bottomLoopLayer.loops = boolean_geometry.getEmptyZLoops( copyShallowObjects, importRadius, False, z, zoneArrangement) loopLayers = [bottomLoopLayer] z = minimumZ + halfLayerHeight loopLayers += boolean_geometry.getLoopLayers(copyShallowObjects, importRadius, halfLayerHeight, maximumZ, False, z, zoneArrangement) copyShallow.parentNode.xmlObject.archivableObjects.remove( copyShallow.xmlObject) return loopLayers
def parseLine(self, line): 'Parse a gcode line and add it to the cool skein.' splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1': location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) self.highestZ = max(location.z, self.highestZ) if self.isExtruderActive: line = self.getCoolMove(line, location, splitLine) self.oldLocation = location elif firstWord == 'M101': self.isExtruderActive = True elif firstWord == 'M103': self.isExtruderActive = False elif firstWord == 'M104': self.oldTemperature = gcodec.getDoubleAfterFirstLetter( splitLine[1]) # elif firstWord == 'M108': # self.oldFlowRate = float(splitLine[1][1 :]) # self.addFlowRate(self.multiplier * self.oldFlowRate) # return elif firstWord == '(<boundaryPoint>': self.boundaryLoop.append( gcodec.getLocationFromSplitLine(None, splitLine).dropAxis()) elif firstWord == '(<layer>': self.layerCount.printProgressIncrement('cool') self.distanceFeedRate.addLine(line) self.distanceFeedRate.addLinesSetAbsoluteDistanceMode( self.coolStartLines) layerTime = self.getLayerTime() remainingOrbitTime = max( self.repository.minimumLayerTime.value - layerTime, 0.0) self.addCoolTemperature(remainingOrbitTime) if self.repository.orbit.value: self.addOrbitsIfNecessary(remainingOrbitTime) else: self.setMultiplier(remainingOrbitTime) # self.addFlowRate(self.multiplier * self.oldFlowRate) z = float(splitLine[1]) self.boundaryLayer = euclidean.LoopLayer(z) self.highestZ = max(z, self.highestZ) self.distanceFeedRate.addLinesSetAbsoluteDistanceMode( self.coolEndLines) return elif firstWord == '(</layer>)': self.isBridgeLayer = False self.multiplier = 1.0 if self.coolTemperature is not None: self.addTemperature(self.oldTemperature) self.coolTemperature = None # self.addFlowRate(self.oldFlowRate) elif firstWord == '(<nestedRing>)': self.boundaryLoop = [] self.boundaryLayer.loops.append(self.boundaryLoop) self.distanceFeedRate.addLine(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) if len(self.boundaryLayers) < 2: return for boundaryLayer in self.boundaryLayers: boundaryLayer.innerOutsetLoops = intercircle.getInsetSeparateLoopsFromLoops( boundaryLayer.loops, -self.loopInnerOutset) boundaryLayer.outerOutsetLoops = intercircle.getInsetSeparateLoopsFromLoops( boundaryLayer.loops, -self.loopOuterOutset) 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 processContourLayers( self, file ): "Process a contour layer at a time until the top of the part." while True: minLayer = getLittleEndianFloatGivenFile( file ) numContours = getLittleEndianUnsignedLongGivenFile( file ) if numContours == 0xFFFFFFFF: return loopLayer = euclidean.LoopLayer( minLayer ) self.loopLayers.append( loopLayer ) for contourIndex in xrange( numContours ): numPoints = getLittleEndianUnsignedLongGivenFile( file ) numGaps = getLittleEndianUnsignedLongGivenFile( file ) if numPoints > 2: loopLayer.loops.append( getPointsFromFile( numPoints, file ) )
def parseLine(self, line): "Parse a gcode line and add it to the cool skein." splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1': location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) line = self.getCoolMove(line, location, splitLine) self.oldLocation = location elif firstWord == '(<boundaryPoint>': self.boundaryLoop.append( gcodec.getLocationFromSplitLine(None, splitLine).dropAxis(2)) elif firstWord == '(<layer>': self.layerCount.printProgressIncrement('cool') self.distanceFeedRate.addLine(line) self.distanceFeedRate.addLinesSetAbsoluteDistanceMode( self.coolStartLines) layerTime = self.getLayerTime() remainingOrbitTime = max( self.coolRepository.minimumLayerTime.value - layerTime, 0.0) self.addCoolTemperature(remainingOrbitTime) if self.coolRepository.orbit.value: self.addOrbitsIfNecessary(remainingOrbitTime) else: self.setMultiplier(layerTime) z = float(splitLine[1]) self.boundaryLayer = euclidean.LoopLayer(z) self.highestZ = max(z, self.highestZ) self.distanceFeedRate.addLinesSetAbsoluteDistanceMode( self.coolEndLines) return elif firstWord == '(</layer>)': self.multiplier = 1.0 if self.coolTemperature != None: self.addTemperature(self.oldTemperature) self.coolTemperature = None self.addFlowRateLineIfNecessary(self.oldFlowRate) elif firstWord == 'M104': self.oldTemperature = gcodec.getDoubleAfterFirstLetter( splitLine[1]) elif firstWord == 'M108': self.setOperatingFlowString(splitLine) self.addFlowRateMultipliedLineIfNecessary(self.oldFlowRate) return elif firstWord == '(<surroundingLoop>)': self.boundaryLoop = [] self.boundaryLayer.loops.append(self.boundaryLoop) self.distanceFeedRate.addLine(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 processSVGElement(self, fileName): 'Parse SVG element and store the layers.' self.fileName = fileName paths = self.elementNode.xmlObject.getPaths() oldZ = None self.loopLayers = [] loopLayer = None for path in paths: if len(path) > 0: z = path[0].z if z != oldZ: loopLayer = euclidean.LoopLayer(z) self.loopLayers.append(loopLayer) oldZ = z loopLayer.loops.append(euclidean.getComplexPath(path)) if len(self.loopLayers) < 1: return self.cornerMaximum = Vector3(-987654321.0, -987654321.0, -987654321.0) self.cornerMinimum = Vector3(987654321.0, 987654321.0, 987654321.0) svg_writer.setSVGCarvingCorners(self.cornerMaximum, self.cornerMinimum, self.layerThickness, self.loopLayers)
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 getLoopLayerAppend(loopLayers, z): 'Get next z and add extruder loops.' settings.printProgress(len(loopLayers), 'slice') loopLayer = euclidean.LoopLayer(z) loopLayers.append(loopLayer) return loopLayer
def getManipulatedGeometryOutput(elementNode, geometryOutput, prefix): 'Get inset geometryOutput.' derivation = InsetDerivation(elementNode, prefix) if derivation.radius == 0.0: return geometryOutput copyShallow = elementNode.getCopyShallow() solid.processElementNodeByGeometry(copyShallow, geometryOutput) targetMatrix = matrix.getBranchMatrixSetElementNode(elementNode) matrix.setElementNodeDictionaryMatrix(copyShallow, targetMatrix) transformedVertexes = copyShallow.xmlObject.getTransformedVertexes() minimumZ = boolean_geometry.getMinimumZ(copyShallow.xmlObject) maximumZ = euclidean.getTopPath(transformedVertexes) layerThickness = setting.getLayerThickness(elementNode) importRadius = setting.getImportRadius(elementNode) zoneArrangement = triangle_mesh.ZoneArrangement(layerThickness, transformedVertexes) copyShallow.attributes['visible'] = True copyShallowObjects = [copyShallow.xmlObject] bottomLoopLayer = euclidean.LoopLayer(minimumZ) z = minimumZ + 0.1 * layerThickness bottomLoopLayer.loops = boolean_geometry.getEmptyZLoops( copyShallowObjects, importRadius, False, z, zoneArrangement) loopLayers = [bottomLoopLayer] z = minimumZ + layerThickness loopLayers += boolean_geometry.getLoopLayers(copyShallowObjects, importRadius, layerThickness, maximumZ, False, z, zoneArrangement) copyShallow.parentNode.xmlObject.archivableObjects.remove( copyShallow.xmlObject) belowLoop = [] diagonalRadius = math.sqrt(0.5) * derivation.radius insetDiagonalLoops = [] loops = [] vertexes = [] for loopLayer in loopLayers: insetDiagonalLoops.append( intercircle.getLargestInsetLoopFromLoop(loopLayer.loops[0], diagonalRadius)) for loopLayerIndex, loopLayer in enumerate(loopLayers): vector3Loop = [] insetLoop = intercircle.getLargestInsetLoopFromLoop( loopLayer.loops[0], derivation.radius) loopLists = [[getLoopOrEmpty(loopLayerIndex - 1, insetDiagonalLoops)], [insetLoop]] largestLoop = euclidean.getLargestLoop( boolean_solid.getLoopsIntersection(importRadius, loopLists)) if evaluate.getEvaluatedBoolean(True, elementNode, prefix + 'insetTop'): loopLists = [[ getLoopOrEmpty(loopLayerIndex + 1, insetDiagonalLoops) ], [largestLoop]] largestLoop = euclidean.getLargestLoop( boolean_solid.getLoopsIntersection(importRadius, loopLists)) for point in largestLoop: vector3Index = Vector3Index(len(vertexes), point.real, point.imag, loopLayer.z) vector3Loop.append(vector3Index) vertexes.append(vector3Index) if len(vector3Loop) > 0: loops.append(vector3Loop) if evaluate.getEvaluatedBoolean(False, elementNode, prefix + 'addExtraTopLayer') and len(loops) > 0: topLoop = loops[-1] vector3Loop = [] loops.append(vector3Loop) z = topLoop[0].z + layerThickness for point in topLoop: vector3Index = Vector3Index(len(vertexes), point.x, point.y, z) vector3Loop.append(vector3Index) vertexes.append(vector3Index) geometryOutput = triangle_mesh.getMeldedPillarOutput(loops) return geometryOutput
def parseLine(self, line): 'Parse a gcode line and add it to the cool skein.' splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1': location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) self.highestZ = max(location.z, self.highestZ) if self.isExtruderActive: line = self.getCoolMove(line, location, splitLine) self.oldLocation = location elif firstWord == 'M101': self.isExtruderActive = True elif firstWord == 'M103': self.isExtruderActive = False elif firstWord == 'M104': self.oldTemperature = gcodec.getDoubleAfterFirstLetter( splitLine[1]) elif firstWord == 'M108': self.oldFlowRate = float(splitLine[1][1:]) self.addFlowRate(self.multiplier * self.oldFlowRate) return elif firstWord == '(<boundaryPoint>': self.boundaryLoop.append( gcodec.getLocationFromSplitLine(None, splitLine).dropAxis()) elif firstWord == '(<layer>': self.layerCount.printProgressIncrement('cool') "print 'Layer %d' % (self.layerCount.layerIndex)" self.distanceFeedRate.addLine(line) self.distanceFeedRate.addLinesSetAbsoluteDistanceMode( self.coolStartLines) layerTime = self.getLayerTime() "print 'Layer time : %5.3f' % (layerTime)" if not self.repository.turnFanOnAtBeginning.value and self.layerCount.layerIndex >= self.repository.fanFirstLayer.value: if (self.repository.bridgeFan.value and self.isBridgeLayer ) or layerTime <= self.repository.fullFanLayerTime.value: self.distanceFeedRate.addLine( 'M106 S%d' % (self.repository.fanmaxPWM.value)) "print 'Full Fan Speed ! (Layer time is under %5.3f' % (self.repository.fullFanLayerTime.value)" elif layerTime <= self.repository.maximumFanLayerTime.value: fanPWMArea = (self.repository.maximumFanLayerTime.value - self.repository.fullFanLayerTime.value) fanPWM = round( ((self.repository.maximumFanLayerTime.value - layerTime) / fanPWMArea) * self.repository.fanmaxPWM.value) self.distanceFeedRate.addLine('M106 S%d' % (fanPWM)) "print 'PWM Fan Speed (fanPWMArea : %5.3f / fanPWM : %d)' % (fanPWMArea, fanPWM)" else: self.distanceFeedRate.addLine('M107') "print 'Fan Off (Layer time is above %5.3f)' % (self.repository.maximumFanLayerTime.value)" remainingOrbitTime = max( self.repository.minimumLayerTime.value - layerTime, 0.0) self.addCoolTemperature(remainingOrbitTime) if self.repository.orbit.value: self.addOrbitsIfNecessary(remainingOrbitTime) else: self.setMultiplier(remainingOrbitTime) self.addFlowRate(self.multiplier * self.oldFlowRate) z = float(splitLine[1]) self.boundaryLayer = euclidean.LoopLayer(z) self.highestZ = max(z, self.highestZ) self.distanceFeedRate.addLinesSetAbsoluteDistanceMode( self.coolEndLines) return elif firstWord == '(</layer>)': self.isBridgeLayer = False self.multiplier = 1.0 if self.coolTemperature != None: self.addTemperature(self.oldTemperature) self.coolTemperature = None self.addFlowRate(self.oldFlowRate) elif firstWord == '(<nestedRing>)': self.boundaryLoop = [] self.boundaryLayer.loops.append(self.boundaryLoop) self.distanceFeedRate.addLine(line)