Example #1
0
def getRotationMatrix(arrayDictionary, derivation, path, point, pointIndex):
    'Get rotationMatrix.'
    if len(path) < 2 or not derivation.track:
        return matrix.Matrix()
    point = point.dropAxis()
    begin = path[(pointIndex + len(path) - 1) % len(path)].dropAxis()
    end = path[(pointIndex + 1) % len(path)].dropAxis()
    pointMinusBegin = point - begin
    pointMinusBeginLength = abs(pointMinusBegin)
    endMinusPoint = end - point
    endMinusPointLength = abs(endMinusPoint)
    if not derivation.closed:
        if pointIndex == 0 and endMinusPointLength > 0.0:
            return getRotationMatrixByPolar(arrayDictionary, endMinusPoint,
                                            endMinusPointLength)
        elif pointIndex == len(path) - 1 and pointMinusBeginLength > 0.0:
            return getRotationMatrixByPolar(arrayDictionary, pointMinusBegin,
                                            pointMinusBeginLength)
    if pointMinusBeginLength <= 0.0:
        print(
            'Warning, point equals previous point in getRotationMatrix in array for:'
        )
        print(path)
        print(pointIndex)
        print(derivation.elementNode)
        return matrix.Matrix()
    pointMinusBegin /= pointMinusBeginLength
    if endMinusPointLength <= 0.0:
        print(
            'Warning, point equals next point in getRotationMatrix in array for:'
        )
        print(path)
        print(pointIndex)
        print(derivation.elementNode)
        return matrix.Matrix()
    endMinusPoint /= endMinusPointLength
    averagePolar = pointMinusBegin + endMinusPoint
    averagePolarLength = abs(averagePolar)
    if averagePolarLength <= 0.0:
        print(
            'Warning, averagePolarLength is zero in getRotationMatrix in array for:'
        )
        print(path)
        print(pointIndex)
        print(derivation.elementNode)
        return matrix.Matrix()
    return getRotationMatrixByPolar(arrayDictionary, averagePolar,
                                    averagePolarLength)
Example #2
0
 def __init__(self):
     'Add empty lists.'
     dictionary.Dictionary.__init__(self)
     self.matrix4X4 = matrix.Matrix()
     self.oldChainTetragrid = None
     self.transformedPath = None
     self.vertexes = []
Example #3
0
def writeXMLObject(absoluteFolderDirectory, derivation, fileNames, target,
                   xmlObject):
    "Write one instance of the xmlObject."
    extension = evaluate.getEvaluatedString(
        xmlObject.getFabricationExtension(), derivation.elementNode,
        'extension')
    fileNameRoot = derivation.fileName
    if fileNameRoot == '':
        fileNameRoot = evaluate.getEvaluatedString('', target, 'name')
        fileNameRoot = evaluate.getEvaluatedString(fileNameRoot, target, 'id')
        fileNameRoot += derivation.suffix
    fileName = '%s.%s' % (fileNameRoot, extension)
    suffixIndex = 2
    while fileName in fileNames:
        fileName = '%s_%s.%s' % (fileNameRoot, suffixIndex, extension)
        suffixIndex += 1
    absoluteFileName = os.path.join(absoluteFolderDirectory, fileName)
    fileNames.append(fileName)
    archive.makeDirectory(absoluteFolderDirectory)
    if not derivation.writeMatrix:
        xmlObject.matrix4X4 = matrix.Matrix()
    print('The write tool generated the file:')
    print(absoluteFileName)
    archive.writeFileText(
        absoluteFileName,
        xmlObject.getFabricationText(derivation.addLayerTemplate))
Example #4
0
def getRotationMatrixByPolar(arrayDictionary, polar, polarLength):
    'Get rotationMatrix by polar and polarLength.'
    polar /= polarLength
    arrayDictionary['_arrayRotation'] = math.degrees(
        math.atan2(polar.imag, polar.real))
    return matrix.Matrix(
        matrix.getDiagonalSwitchedTetragridByPolar([0, 1], polar))
Example #5
0
def processXMLElementByDerivation(derivation, xmlElement):
	'Process the xml element by derivation.'
	if derivation == None:
		derivation = DisjoinDerivation(xmlElement)
	targetXMLElement = derivation.targetXMLElement
	if targetXMLElement == None:
		print('Warning, disjoin could not get target for:')
		print(xmlElement)
		return
	xmlObject = targetXMLElement.xmlObject
	if xmlObject == None:
		print('Warning, processXMLElementByDerivation in disjoin could not get xmlObject for:')
		print(targetXMLElement)
		print(derivation.xmlElement)
		return
	transformedVertexes = xmlObject.getTransformedVertexes()
	if len(transformedVertexes) < 1:
		print('Warning, transformedVertexes is zero in processXMLElementByDerivation in disjoin for:')
		print(xmlObject)
		print(targetXMLElement)
		print(derivation.xmlElement)
		return
	xmlElement.localName = 'group'
	xmlElement.getXMLProcessor().processXMLElement(xmlElement)
	matrix.getBranchMatrixSetXMLElement(targetXMLElement)
	targetChainMatrix = matrix.Matrix(xmlObject.getMatrixChainTetragrid())
	minimumZ = boolean_geometry.getMinimumZ(xmlObject)
	z = minimumZ + 0.5 * derivation.sheetThickness
	zoneArrangement = triangle_mesh.ZoneArrangement(derivation.layerThickness, transformedVertexes)
	oldVisibleString = targetXMLElement.attributeDictionary['visible']
	targetXMLElement.attributeDictionary['visible'] = True
	loops = boolean_geometry.getEmptyZLoops([xmlObject], derivation.importRadius, False, z, zoneArrangement)
	targetXMLElement.attributeDictionary['visible'] = oldVisibleString
	vector3Loops = euclidean.getVector3Paths(loops, z)
	pathElement = getLinkedXMLElement('_sheet', xmlElement, targetXMLElement)
	path.convertXMLElement(vector3Loops, pathElement)
	targetOutput = xmlObject.getGeometryOutput()
	differenceElement = getLinkedXMLElement('_solid', xmlElement, targetXMLElement)
	targetElementCopy = targetXMLElement.getCopy('_positive', differenceElement)
	targetElementCopy.attributeDictionary['visible'] = True
	targetElementCopy.attributeDictionary.update(targetChainMatrix.getAttributeDictionary('matrix.'))
	complexMaximum = euclidean.getMaximumByVector3Path(transformedVertexes).dropAxis()
	complexMinimum = euclidean.getMinimumByVector3Path(transformedVertexes).dropAxis()
	centerComplex = 0.5 * (complexMaximum + complexMinimum)
	centerVector3 = Vector3(centerComplex.real, centerComplex.imag, minimumZ)
	slightlyMoreThanHalfExtent = 0.501 * (complexMaximum - complexMinimum)
	inradius = Vector3(slightlyMoreThanHalfExtent.real, slightlyMoreThanHalfExtent.imag, derivation.sheetThickness)
	cubeElement = xml_simple_reader.XMLElement()
	cubeElement.attributeDictionary['inradius'] = str(inradius)
	if not centerVector3.getIsDefault():
		cubeElement.attributeDictionary['translate.'] = str(centerVector3)
	cubeElement.localName = 'cube'
	cubeElement.importName = differenceElement.importName
	cubeElement.setParentAddToChildNodes(differenceElement)
	difference.processXMLElement(differenceElement)
Example #6
0
def addPathToGroup(derivation, groupDictionaryCopy, path, targetMatrix, totalIndex):
	'Add path to the array group.'
	for pointIndex, point in enumerate(path):
		arrayElement = derivation.target.getCopy(derivation.elementNode.getIDSuffix(totalIndex), derivation.elementNode)
		arrayDictionary = arrayElement.attributes
		arrayDictionary['visible'] = str(derivation.visible).lower()
		arrayDictionary.update(groupDictionaryCopy)
		euclidean.removeTrueFromDictionary(arrayDictionary, 'visible')
		vertexMatrix = matrix.Matrix(matrix.getTranslateTetragridByTranslation(point))
		zAngle = totalIndex * 50.0
		rotationMatrix = getRotationMatrix(arrayDictionary, derivation, path, point, pointIndex)
		arrayElementMatrix = vertexMatrix.getSelfTimesOther(rotationMatrix.getSelfTimesOther(targetMatrix.tetragrid).tetragrid)
		arrayDictionary.update(arrayElementMatrix.getAttributes('matrix.'))
		arrayDictionary['_arrayIndex'] = totalIndex
		arrayDictionary['_arrayPoint'] = point
		totalIndex += 1
Example #7
0
	def __init__(self):
		"Add empty lists."
		dictionary.Dictionary.__init__(self)
		self.matrix4X4 = matrix.Matrix()