chiark / gitweb /
Add uppercase STL and HEX to file dialog filters for linux/MacOS
[cura.git] / Cura / fabmetheus_utilities / geometry / manipulation_meta / _copy.py
1 """
2 Boolean geometry copy.
3
4 """
5
6 from __future__ import absolute_import
7 #Init has to be imported first because it has code to workaround the python bug where relative imports don't work if the module is imported as a main module.
8 import __init__
9
10 from fabmetheus_utilities.geometry.creation import lineation
11 from fabmetheus_utilities.geometry.creation import solid
12 from fabmetheus_utilities.geometry.geometry_utilities import evaluate
13 from fabmetheus_utilities.geometry.geometry_utilities import matrix
14 from fabmetheus_utilities import euclidean
15
16
17 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
18 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
19 __date__ = '$Date: 2008/02/05 $'
20 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
21
22
23 def getNewDerivation(elementNode):
24         'Get new derivation.'
25         return CopyDerivation(elementNode)
26
27 def processElementNode(elementNode):
28         'Process the xml element.'
29         processElementNodeByDerivation(None, elementNode)
30
31 def processElementNodeByDerivation(derivation, elementNode):
32         'Process the xml element by derivation.'
33         if derivation == None:
34                 derivation = CopyDerivation(elementNode)
35         if derivation.target == None:
36                 print('Warning, copy could not get target for:')
37                 print(elementNode)
38                 return
39         del elementNode.attributes['target']
40         copyMatrix = matrix.getBranchMatrixSetElementNode(elementNode)
41         targetMatrix = matrix.getBranchMatrixSetElementNode(derivation.target)
42         targetDictionaryCopy = evaluate.removeIdentifiersFromDictionary(derivation.target.attributes.copy())
43         targetDictionaryCopy.update(elementNode.attributes)
44         elementNode.attributes = targetDictionaryCopy
45         euclidean.removeTrueFromDictionary(elementNode.attributes, 'visible')
46         elementNode.localName = derivation.target.localName
47         derivation.target.copyXMLChildNodes(elementNode.getIDSuffix(), elementNode)
48         elementNode.getXMLProcessor().processElementNode(elementNode)
49         if copyMatrix != None and targetMatrix != None:
50                 elementNode.xmlObject.matrix4X4 = copyMatrix.getSelfTimesOther(targetMatrix.tetragrid)
51         if elementNode.xmlObject == None:
52                 return
53         if len(elementNode.xmlObject.getPaths()) > 0:
54                 lineation.processElementNode(elementNode)
55                 return
56         geometryOutput = elementNode.xmlObject.getGeometryOutput()
57         if geometryOutput == None:
58                 return
59         solidMatchingPlugins = solid.getSolidMatchingPlugins(elementNode)
60         if len(solidMatchingPlugins) == 0:
61                 return
62         geometryOutput = solid.getGeometryOutputByManipulation(elementNode, geometryOutput)
63         elementNode.xmlObject.transformGeometryOutput(geometryOutput)
64         lineation.removeChildNodesFromElementObject(elementNode)
65         elementNode.getXMLProcessor().convertElementNode(elementNode, geometryOutput)
66
67
68 class CopyDerivation:
69         "Class to hold copy variables."
70         def __init__(self, elementNode):
71                 'Set defaults.'
72                 self.target = evaluate.getElementNodeByKey(elementNode, 'target')