Ejemplo n.º 1
0
	def getCraftedGcode(self, fileName, repository, svgText):
		"Parse svgText and store the scale svgText."
		svgReader = SVGReader()
		svgReader.parseSVG('', svgText)
		if svgReader.sliceDictionary == None:
			print('Warning, nothing will be done because the sliceDictionary could not be found getCraftedGcode in preface.')
			return ''
		xyPlaneScale = repository.xyPlaneScale.value
		zAxisScale = repository.zAxisScale.value
		decimalPlacesCarried = int(svgReader.sliceDictionary['decimalPlacesCarried'])
		layerHeight = zAxisScale * float(svgReader.sliceDictionary['layerHeight'])
		edgeWidth = float(svgReader.sliceDictionary['edgeWidth'])
		loopLayers = svgReader.loopLayers
		for loopLayer in loopLayers:
			setLoopLayerScale(loopLayer, xyPlaneScale, zAxisScale)
		cornerMaximum = Vector3(-912345678.0, -912345678.0, -912345678.0)
		cornerMinimum = Vector3(912345678.0, 912345678.0, 912345678.0)
		svg_writer.setSVGCarvingCorners(cornerMaximum, cornerMinimum, layerHeight, loopLayers)
		svgWriter = svg_writer.SVGWriter(
			True,
			cornerMaximum,
			cornerMinimum,
			decimalPlacesCarried,
			layerHeight,
			edgeWidth)
		commentElement = svg_writer.getCommentElement(svgReader.documentElement)
		procedureNameString = svgReader.sliceDictionary['procedureName'] + ',scale'
		return svgWriter.getReplacedSVGTemplate(fileName, loopLayers, procedureNameString, commentElement)
Ejemplo n.º 2
0
 def getCraftedGcode(self, fileName, repository, svgText):
     "Parse svgText and store the bottom svgText."
     svgReader = SVGReader()
     svgReader.parseSVG('', svgText)
     if svgReader.sliceDictionary == None:
         print(
             'Warning, nothing will be done because the sliceDictionary could not be found getCraftedGcode in preface.'
         )
         return ''
     decimalPlacesCarried = int(
         svgReader.sliceDictionary['decimalPlacesCarried'])
     layerThickness = float(svgReader.sliceDictionary['layerThickness'])
     perimeterWidth = float(svgReader.sliceDictionary['perimeterWidth'])
     loopLayers = svgReader.loopLayers
     zMinimum = 987654321.0
     for loopLayer in loopLayers:
         zMinimum = min(loopLayer.z, zMinimum)
     deltaZ = repository.altitude.value + repository.additionalHeightOverLayerThickness.value * layerThickness - zMinimum
     for loopLayer in loopLayers:
         loopLayer.z += deltaZ
     cornerMaximum = Vector3(-912345678.0, -912345678.0, -912345678.0)
     cornerMinimum = Vector3(912345678.0, 912345678.0, 912345678.0)
     svg_writer.setSVGCarvingCorners(cornerMaximum, cornerMinimum,
                                     layerThickness, loopLayers)
     svgWriter = svg_writer.SVGWriter(True, cornerMaximum, cornerMinimum,
                                      decimalPlacesCarried, layerThickness,
                                      perimeterWidth)
     commentElement = svg_writer.getCommentElement(
         svgReader.documentElement)
     procedureNameString = svgReader.sliceDictionary[
         'procedureName'] + ',bottom'
     return svgWriter.getReplacedSVGTemplate(fileName, loopLayers,
                                             procedureNameString,
                                             commentElement)
Ejemplo n.º 3
0
 def getCarvedSVG(self, carving, fileName, repository):
     "Parse gnu triangulated surface text and store the carved gcode."
     layerThickness = repository.layerThickness.value
     perimeterWidth = repository.perimeterWidthOverThickness.value * layerThickness
     carving.setCarveLayerThickness(layerThickness)
     importRadius = 0.5 * repository.importCoarseness.value * abs(
         perimeterWidth)
     carving.setCarveImportRadius(max(importRadius, 0.001 * layerThickness))
     carving.setCarveIsCorrectMesh(repository.correctMesh.value)
     loopLayers = carving.getCarveBoundaryLayers()
     if len(loopLayers) < 1:
         print(
             'Warning, there are no slices for the model, this could be because the model is too small for the Layer Thickness.'
         )
         return ''
     layerThickness = carving.getCarveLayerThickness()
     decimalPlacesCarried = euclidean.getDecimalPlacesCarried(
         repository.extraDecimalPlaces.value, layerThickness)
     perimeterWidth = repository.perimeterWidthOverThickness.value * layerThickness
     svgWriter = svg_writer.SVGWriter(
         repository.addLayerTemplateToSVG.value,
         carving.getCarveCornerMaximum(),
         carving.getCarveCornerMinimum(), decimalPlacesCarried,
         carving.getCarveLayerThickness(), perimeterWidth)
     truncatedRotatedBoundaryLayers = svg_writer.getTruncatedRotatedBoundaryLayers(
         loopLayers, repository)
     return svgWriter.getReplacedSVGTemplate(
         fileName, truncatedRotatedBoundaryLayers, 'carve',
         carving.getFabmetheusXML())
Ejemplo n.º 4
0
 def getCarvedSVG(self, carving, fileName, repository):
     "Parse gnu triangulated surface text and store the chopped gcode."
     layerHeight = repository.layerHeight.value
     edgeWidth = repository.edgeWidth.value
     carving.setCarveLayerHeight(layerHeight)
     importRadius = 0.5 * repository.importCoarseness.value * abs(edgeWidth)
     carving.setCarveImportRadius(max(importRadius, 0.001 * layerHeight))
     carving.setCarveIsCorrectMesh(repository.correctMesh.value)
     loopLayers = carving.getCarveBoundaryLayers()
     if len(loopLayers) < 1:
         print(
             'Warning, there are no slices for the model, this could be because the model is too small for the Layer Height.'
         )
         return ''
     if repository.addExtraTopLayerIfNecessary.value:
         self.addExtraTopLayerIfNecessary(carving, layerHeight, loopLayers)
     loopLayers.reverse()
     layerHeight = carving.getCarveLayerHeight()
     decimalPlacesCarried = euclidean.getDecimalPlacesCarried(
         repository.extraDecimalPlaces.value, layerHeight)
     svgWriter = svg_writer.SVGWriter(
         repository.addLayerTemplateToSVG.value,
         carving.getCarveCornerMaximum(), carving.getCarveCornerMinimum(),
         decimalPlacesCarried, carving.getCarveLayerHeight(), edgeWidth)
     truncatedRotatedBoundaryLayers = svg_writer.getTruncatedRotatedBoundaryLayers(
         loopLayers, repository)
     return svgWriter.getReplacedSVGTemplate(
         fileName, truncatedRotatedBoundaryLayers, 'chop',
         carving.getFabmetheusXML())
Ejemplo n.º 5
0
	def getCarvedSVG(self):
		"Get the carved svg text."
		if len(self.rotatedLoopLayers) < 1:
			return ''
		decimalPlaces = max(0, 2 - int(math.floor(math.log10(self.layerThickness))))
		self.svgWriter = svg_writer.SVGWriter(True, self.cornerMaximum, self.cornerMinimum, decimalPlaces, self.layerThickness)
		return self.svgWriter.getReplacedSVGTemplate(self.fileName, 'basic', self.rotatedLoopLayers)
Ejemplo n.º 6
0
 def getCarvedSVG(self, carving, fileName, repository):
     "Parse gnu triangulated surface text and store the chopped gcode."
     layerThickness = repository.layerThickness.value
     perimeterWidth = repository.perimeterWidth.value
     carving.setCarveLayerThickness(layerThickness)
     importRadius = 0.5 * repository.importCoarseness.value * abs(
         perimeterWidth)
     carving.setCarveImportRadius(max(importRadius, 0.01 * layerThickness))
     carving.setCarveIsCorrectMesh(repository.correctMesh.value)
     rotatedBoundaryLayers = carving.getCarveRotatedBoundaryLayers()
     if len(rotatedBoundaryLayers) < 1:
         print(
             'There are no slices for the model, this could be because the model is too small.'
         )
         return ''
     if repository.addExtraTopLayerIfNecessary.value:
         self.addExtraTopLayerIfNecessary(carving, layerThickness,
                                          rotatedBoundaryLayers)
     rotatedBoundaryLayers.reverse()
     layerThickness = carving.getCarveLayerThickness()
     decimalPlacesCarried = euclidean.getDecimalPlacesCarried(
         repository.extraDecimalPlaces.value, layerThickness)
     svgWriter = svg_writer.SVGWriter(
         repository.addLayerTemplateToSVG.value, carving,
         decimalPlacesCarried, perimeterWidth)
     truncatedRotatedBoundaryLayers = svg_writer.getTruncatedRotatedBoundaryLayers(
         repository, rotatedBoundaryLayers)
     return svgWriter.getReplacedSVGTemplate(
         fileName, 'chop', truncatedRotatedBoundaryLayers,
         carving.getFabmetheusXML())
Ejemplo n.º 7
0
 def getCarvedSVG(self, carving, fileName, repository):
     "Parse gnu triangulated surface text and store the carved gcode."
     layerThickness = repository.layerThickness.value
     bridgeLayerThickness = layerThickness * repository.bridgeThicknessMultiplier.value
     perimeterWidth = repository.perimeterWidthOverThickness.value * layerThickness
     if repository.infillDirectionBridge.value:
         carving.setCarveBridgeLayerThickness(bridgeLayerThickness)
     carving.setCarveLayerThickness(layerThickness)
     importRadius = 0.5 * repository.importCoarseness.value * abs(
         perimeterWidth)
     carving.setCarveImportRadius(max(importRadius, 0.01 * layerThickness))
     carving.setCarveIsCorrectMesh(repository.correctMesh.value)
     rotatedBoundaryLayers = carving.getCarveRotatedBoundaryLayers()
     if len(rotatedBoundaryLayers) < 1:
         print(
             'There are no slices for the model, this could be because the model is too small.'
         )
         return ''
     layerThickness = carving.getCarveLayerThickness()
     decimalPlacesCarried = max(
         0, 1 + repository.extraDecimalPlaces.value -
         int(math.floor(math.log10(layerThickness))))
     perimeterWidth = repository.perimeterWidthOverThickness.value * layerThickness
     svgWriter = svg_writer.SVGWriter(
         repository.addLayerTemplateToSVG.value, carving,
         decimalPlacesCarried, perimeterWidth)
     truncatedRotatedBoundaryLayers = svg_writer.getTruncatedRotatedBoundaryLayers(
         repository, rotatedBoundaryLayers)
     return svgWriter.getReplacedSVGTemplate(
         fileName, 'carve', truncatedRotatedBoundaryLayers,
         carving.getFabmetheusXML())
Ejemplo n.º 8
0
 def getCarvedSVG(self):
     "Get the carved svg text."
     if len(self.rotatedBoundaryLayers) < 1:
         return ''
     decimalPlacesCarried = max(
         0, 2 - int(math.floor(math.log10(self.layerThickness))))
     self.svgWriter = svg_writer.SVGWriter(self, decimalPlacesCarried)
     return self.svgWriter.getReplacedSVGTemplate(
         self.fileName, 'basic', self.rotatedBoundaryLayers)
Ejemplo n.º 9
0
    def carve(self, carving):
        "Parse 3D model file and store the carved slicedModel."

        carving.setCarveInfillInDirectionOfBridge(self.infillBridgeDirection)
        carving.setCarveLayerThickness(self.layerHeight)
        importRadius = 0.5 * self.importCoarsenessRatio * abs(
            self.extrusionWidth)
        carving.setCarveImportRadius(
            max(importRadius, 0.001 * self.layerHeight))
        carving.setCarveIsCorrectMesh(self.correctMesh)

        rotatedLoopLayers = carving.getCarveRotatedBoundaryLayers()

        if len(rotatedLoopLayers) < 1:
            logger.warning(
                'There are no slices for the model, this could be because the model is too small for the Layer Thickness.'
            )
            return

        self.slicedModel.carvingCornerMaximum = carving.getCarveCornerMaximum()
        self.slicedModel.carvingCornerMinimum = carving.getCarveCornerMinimum()

        toBePrintedLayers = rotatedLoopLayers[self.layerPrintFrom:self.
                                              layerPrintTo]
        for toBePrintedLayer in toBePrintedLayers:
            sortedLoops = []
            for toBePrintedLayerLoop in toBePrintedLayer.loops:
                lowerLeftPoint = self.getLowerLeftCorner(toBePrintedLayerLoop)
                lowerLeftIndex = toBePrintedLayerLoop.index(lowerLeftPoint)
                sortedLoops.append(toBePrintedLayerLoop[lowerLeftIndex:] +
                                   toBePrintedLayerLoop[:lowerLeftIndex])
            toBePrintedLayer.loops = sortedLoops

        self.slicedModel.rotatedLoopLayers = toBePrintedLayers

        if config.getboolean(name, 'debug'):
            filename = self.slicedModel.runtimeParameters.inputFilename
            svgFilename = filename[:filename.rfind('.')] + '.svg'
            svgWriter = svg_writer.SVGWriter(
                True, self.slicedModel.carvingCornerMaximum,
                self.slicedModel.carvingCornerMinimum,
                self.slicedModel.runtimeParameters.decimalPlaces,
                self.slicedModel.runtimeParameters.layerHeight,
                self.slicedModel.runtimeParameters.layerThickness)
            archive.writeFileText(
                svgFilename,
                svgWriter.getReplacedSVGTemplate(
                    self.slicedModel.runtimeParameters.inputFilename, '',
                    self.slicedModel.rotatedLoopLayers))
            logger.info("Carving SVG written to %s", svgFilename)
Ejemplo n.º 10
0
	def getCarvedSVG( self, carving, fileName, repository ):
		"Parse gnu triangulated surface text and store the cleaved gcode."
		layerThickness = repository.layerThickness.value
		perimeterWidth = repository.perimeterWidth.value
		carving.setCarveLayerThickness( layerThickness )
		importRadius = 0.5 * repository.importCoarseness.value * abs( perimeterWidth )
		carving.setCarveImportRadius( max( importRadius, 0.01 * layerThickness ) )
		carving.setCarveIsCorrectMesh( repository.correctMesh.value )
		rotatedBoundaryLayers = carving.getCarveRotatedBoundaryLayers()
		if len( rotatedBoundaryLayers ) < 1:
			print( 'There are no slices for the model, this could be because the model is too small.' )
			return ''
		layerThickness = carving.getCarveLayerThickness()
		decimalPlacesCarried = max( 0, 1 + repository.extraDecimalPlaces.value - int( math.floor( math.log10( layerThickness ) ) ) )
		svgWriter = svg_writer.SVGWriter( carving, decimalPlacesCarried, perimeterWidth )
		return svgWriter.getReplacedSVGTemplate( fileName, 'cleave', svg_writer.getTruncatedRotatedBoundaryLayers( repository, rotatedBoundaryLayers ) )
Ejemplo n.º 11
0
    def getCarvedSVG(self, carving, fileName, repository):
        "Parse gnu triangulated surface text and store the carved gcode."

        scale = repository.scale.value
        rotate = repository.rotate.value / 180 * math.pi
        scaleX = scale
        scaleY = scale
        scaleZ = scale
        if repository.flipX.value == True:
            scaleX = -scaleX
        if repository.flipY.value == True:
            scaleY = -scaleY
        if repository.flipZ.value == True:
            scaleZ = -scaleZ
        swapXZ = repository.swapXZ.value
        swapYZ = repository.swapYZ.value
        mat00 = math.cos(rotate) * scaleX
        mat01 = -math.sin(rotate) * scaleY
        mat10 = math.sin(rotate) * scaleX
        mat11 = math.cos(rotate) * scaleY

        for i in xrange(0, len(carving.vertexes)):
            x = carving.vertexes[i].x
            y = carving.vertexes[i].y
            z = carving.vertexes[i].z
            if swapXZ:
                x, z = z, x
            if swapYZ:
                y, z = z, y
            carving.vertexes[i] = Vector3(x * mat00 + y * mat01,
                                          x * mat10 + y * mat11, z * scaleZ)

        if repository.alternativeCenter.value != '':
            carving2 = svg_writer.getCarving(
                repository.alternativeCenter.value)
            for i in xrange(0, len(carving2.vertexes)):
                x = carving2.vertexes[i].x
                y = carving2.vertexes[i].y
                z = carving2.vertexes[i].z
                if swapXZ:
                    x, z = z, x
                if swapYZ:
                    y, z = z, y
                carving2.vertexes[i] = Vector3(x * mat00 + y * mat01,
                                               x * mat10 + y * mat11,
                                               z * scaleZ)
            minZ = carving2.getMinimumZ()
            minSize = carving2.getCarveCornerMinimum()
            maxSize = carving2.getCarveCornerMaximum()
        else:
            minZ = carving.getMinimumZ()
            minSize = carving.getCarveCornerMinimum()
            maxSize = carving.getCarveCornerMaximum()
        for v in carving.vertexes:
            v.z -= minZ
            v.x -= minSize.x + (maxSize.x - minSize.x) / 2
            v.y -= minSize.y + (maxSize.y - minSize.y) / 2
            v.x += repository.centerX.value
            v.y += repository.centerY.value

        layerHeight = repository.layerHeight.value
        edgeWidth = repository.edgeWidth.value
        carving.setCarveLayerHeight(layerHeight)
        importRadius = 0.5 * repository.importCoarseness.value * abs(edgeWidth)
        carving.setCarveImportRadius(max(importRadius, 0.001 * layerHeight))
        carving.setCarveIsCorrectMesh(repository.correctMesh.value)
        loopLayers = carving.getCarveBoundaryLayers()
        if len(loopLayers) < 1:
            print(
                'Warning, there are no slices for the model, this could be because the model is too small for the Layer Height.'
            )
            return ''
        layerHeight = carving.getCarveLayerHeight()
        decimalPlacesCarried = euclidean.getDecimalPlacesCarried(
            repository.extraDecimalPlaces.value, layerHeight)
        edgeWidth = repository.edgeWidth.value
        svgWriter = svg_writer.SVGWriter(
            repository.addLayerTemplateToSVG.value,
            carving.getCarveCornerMaximum(), carving.getCarveCornerMinimum(),
            decimalPlacesCarried, carving.getCarveLayerHeight(), edgeWidth)
        truncatedRotatedBoundaryLayers = svg_writer.getTruncatedRotatedBoundaryLayers(
            loopLayers, repository)
        return svgWriter.getReplacedSVGTemplate(
            fileName, truncatedRotatedBoundaryLayers, 'carve',
            carving.getFabmetheusXML())
Ejemplo n.º 12
0
    def getCarvedSVG(self, carving, fileName, repository):
        "Parse gnu triangulated surface text and store the carved gcode."

        matrix = map(float, repository.matrix.value.split(','))

        for i in xrange(0, len(carving.vertexes)):
            x = carving.vertexes[i].x
            y = carving.vertexes[i].y
            z = carving.vertexes[i].z
            carving.vertexes[i] = Vector3(
                x * matrix[0] + y * matrix[3] + z * matrix[6],
                x * matrix[1] + y * matrix[4] + z * matrix[7],
                x * matrix[2] + y * matrix[5] + z * matrix[8])

        if repository.alternativeCenter.value != '':
            carving2 = svg_writer.getCarving(
                repository.alternativeCenter.value)
            for i in xrange(0, len(carving2.vertexes)):
                x = carving2.vertexes[i].x
                y = carving2.vertexes[i].y
                z = carving2.vertexes[i].z
                carving2.vertexes[i] = Vector3(
                    x * matrix[0] + y * matrix[3] + z * matrix[6],
                    x * matrix[1] + y * matrix[4] + z * matrix[7],
                    x * matrix[2] + y * matrix[5] + z * matrix[8])
            minZ = carving2.getMinimumZ()
            minSize = carving2.getCarveCornerMinimum()
            maxSize = carving2.getCarveCornerMaximum()
        else:
            minZ = carving.getMinimumZ()
            minSize = carving.getCarveCornerMinimum()
            maxSize = carving.getCarveCornerMaximum()
        for v in carving.vertexes:
            v.z -= minZ
            v.x -= minSize.x + (maxSize.x - minSize.x) / 2
            v.y -= minSize.y + (maxSize.y - minSize.y) / 2
            v.x += repository.centerX.value
            v.y += repository.centerY.value

        layerHeight = repository.layerHeight.value
        edgeWidth = repository.edgeWidth.value
        carving.setCarveLayerHeight(layerHeight)
        importRadius = 0.5 * repository.importCoarseness.value * abs(edgeWidth)
        carving.setCarveImportRadius(max(importRadius, 0.001 * layerHeight))
        carving.setCarveIsCorrectMesh(repository.correctMesh.value)
        loopLayers = carving.getCarveBoundaryLayers()
        if len(loopLayers) < 1:
            print(
                'Warning, there are no slices for the model, this could be because the model is too small for the Layer Height.'
            )
            return ''
        layerHeight = carving.getCarveLayerHeight()
        decimalPlacesCarried = euclidean.getDecimalPlacesCarried(
            repository.extraDecimalPlaces.value, layerHeight)
        edgeWidth = repository.edgeWidth.value
        svgWriter = svg_writer.SVGWriter(
            repository.addLayerTemplateToSVG.value,
            carving.getCarveCornerMaximum(), carving.getCarveCornerMinimum(),
            decimalPlacesCarried, carving.getCarveLayerHeight(), edgeWidth)
        truncatedRotatedBoundaryLayers = svg_writer.getTruncatedRotatedBoundaryLayers(
            loopLayers, repository)
        return svgWriter.getReplacedSVGTemplate(
            fileName, truncatedRotatedBoundaryLayers, 'carve',
            carving.getFabmetheusXML())