forked from JacquesLucke/animation_nodes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.py
96 lines (78 loc) · 3.06 KB
/
update.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from . import problems
from . import tree_info
from . utils.timing import measureTime
from . ui.node_colors import colorNetworks
from . nodes.system import subprogram_sockets
from . execution.units import createExecutionUnits
from . node_link_conversion import correctForbiddenNodeLinks
from . utils.nodes import iterAnimationNodes, getAnimationNodeTrees, createNodeByIdDict
@measureTime
def updateEverything():
'''
Call when the node tree changed in a way that the execution code does
not work anymore.
'''
tree_info.update()
problems.reset()
enableUseFakeUser()
callNodeEditFunctions()
correctForbiddenNodeLinks()
# from now on no nodes will be created or removed
nodeByID = createNodeByIdDict()
subprogram_sockets.updateIfNecessary()
checkIfNodeTreeIsLinked()
checkUndefinedNodes(nodeByID)
nodesByNetwork = checkNetworks(nodeByID)
checkIdentifiers()
if problems.canCreateExecutionUnits():
createExecutionUnits(nodeByID)
colorNetworks(nodesByNetwork, nodeByID)
nodeByID.clear()
def enableUseFakeUser():
# Make sure the node trees will not be removed when closing the file.
for tree in getAnimationNodeTrees():
tree.use_fake_user = True
def callNodeEditFunctions():
tree_info.updateIfNecessary()
for node in iterAnimationNodes():
node.edit()
tree_info.updateIfNecessary()
def checkNetworks(nodeByID):
invalidNetworkExists = False
nodesByNetworkDict = {}
for network in tree_info.getNetworks():
if network.type == "Invalid":
invalidNetworkExists = True
nodes = network.getAnimationNodes(nodeByID)
markInvalidNodes(network, nodes)
checkNodeOptions(network, nodes)
nodesByNetworkDict[network] = nodes
if invalidNetworkExists:
problems.InvalidNetworksExist().report()
return nodesByNetworkDict
def markInvalidNodes(network, nodes):
isInvalid = network.type == "Invalid"
for node in nodes:
node.inInvalidNetwork = isInvalid
def checkNodeOptions(network, nodes):
for node in nodes:
if "No Execution" in node.options:
problems.NodeDoesNotSupportExecution(node.identifier).report()
if "No Subprogram" in node.options and network.type in ("Group", "Loop"):
problems.NodeMustNotBeInSubprogram(node.identifier).report()
if "No Auto Execution" in node.options:
problems.NodeShouldNotBeUsedInAutoExecution(node.identifier).report()
def checkIdentifiers():
identifierAmount = tree_info.getIdentifierAmount()
nodeAmount = len(list(iterAnimationNodes()))
if nodeAmount > identifierAmount:
problems.IdentifierExistsTwice().report()
def checkIfNodeTreeIsLinked():
for tree in getAnimationNodeTrees(skipLinkedTrees = False):
if tree.library is not None:
problems.LinkedAnimationNodeTreeExists().report()
break
def checkUndefinedNodes(nodeByID):
undefinedNodes = tree_info.getUndefinedNodes(nodeByID)
if len(undefinedNodes) > 0:
problems.UndefinedNodeExists(undefinedNodes).report()