forked from JacquesLucke/animation_nodes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblems.py
229 lines (174 loc) · 7.7 KB
/
problems.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import bpy
from . utils.nodes import idToNode
from . utils.layout import writeText
from . tree_info import getNodeByIdentifier
from . utils.blender_ui import getDpiFactor
currentProblems = []
def reset():
currentProblems.clear()
def canCreateExecutionUnits():
for problem in currentProblems:
if not problem.allowUnitCreation(): return False
return True
def canExecute():
for problem in currentProblems:
if not problem.allowExecution(): return False
return True
def canAutoExecute():
for problem in currentProblems:
if not problem.allowAutoExecution(): return False
return True
def getProblems():
return currentProblems
class Problem:
def allowUnitCreation(self):
return True
def allowExecution(self):
return self.allowUnitCreation()
def allowAutoExecution(self):
return self.allowExecution()
def draw(self, layout):
pass
def report(self):
currentProblems.append(self)
contactDeveloperMessage = (
"Please contact a developer in the forum or on Github. "
"If possible share your .blend file and the content of "
"the console/terminal with the developer.")
realBugMessage = "This is most likely a bug in the addon itself. " + contactDeveloperMessage
advancedSettingsFixMessage = (
"If you disabled certain problem-handling features in the "
"advanced settings of the 'Expression' or 'Script' nodes "
"try to enable them again.")
class NodeLinkRecursion(Problem):
def allowExecution(self):
return False
def draw(self, layout):
message = ("There is a cycle in your node tree. "
"You have to remove the cycle before you will "
"be able to execute the tree again.")
writeText(layout, message, autoWidth = True)
class InvalidNetworksExist(Problem):
def allowUnitCreation(self):
return False
def draw(self, layout):
message = ("There is at least one invalid node network. "
"Please make all networks valid again.\n\n"
"Reasons for invalid networks:\n\n"
" - a 'Invoke Subprogram' is in the same network that it calls\n\n"
" - a 'Group Output' node has no corresponding 'Group Input' node\n\n"
" - there are more than one 'Group Input', 'Group Output' or 'Loop Input' "
"nodes in the same network")
writeText(layout, message, autoWidth = True)
class InvalidSyntax(Problem):
def allowExecution(self):
return False
def draw(self, layout):
message = "The execution code has invalid syntax.\n\n" + \
realBugMessage + "\n\n" + advancedSettingsFixMessage
writeText(layout, message, autoWidth = True)
class ExceptionDuringExecution(Problem):
def allowExecution(self):
return False
def draw(self, layout):
message = "An exception was raised during the execution of a node tree.\n\n" + \
realBugMessage + "\n\n" + advancedSettingsFixMessage
writeText(layout, message, autoWidth = True)
class ExceptionDuringCodeCreation(Problem):
def allowExecution(self):
return False
def draw(self, layout):
message = ("An exception was raised during the creation "
"of the execution code.\n\n") + realBugMessage
writeText(layout, message, autoWidth = True)
class CouldNotSetupExecutionUnits(Problem):
def allowExecution(self):
return False
def draw(self, layout):
message = ("The Animation Nodes addon is not able to setup "
"the execution units for your node tree.\n\n") + realBugMessage
writeText(layout, message, autoWidth = True)
class NodeFailesToCreateExecutionCode(Problem):
def __init__(self, nodeIdentifier):
self.nodeIdentifier = nodeIdentifier
def allowUnitCreation(self):
return False
def draw(self, layout):
message = ("The node linked below is not able to create its "
"execution code. If this can happen when the node tree "
"has been created in another version of the addon. If that "
"is not the case it is most likely a bug in the addon itself.\n\n") + \
contactDeveloperMessage + "\n\n" + \
("If the problem is that you use an incompatible AN version, you "
"can also try to simply replace the not-working node with the same node. "
"Sometimes this error occures when the sockets of a node changes "
"between versions.")
writeText(layout, message, autoWidth = True)
node = getNodeByIdentifier(self.nodeIdentifier)
props = layout.operator("an.move_view_to_node", icon = "VIEWZOOM", text = "{} does not work".format(repr(node.name)))
props.nodeIdentifier = self.nodeIdentifier
class NodeShouldNotBeUsedInAutoExecution(Problem):
def __init__(self, nodeIdentifier):
self.nodeIdentifier = nodeIdentifier
def allowAutoExecution(self):
return False
def draw(self, layout):
node = getNodeByIdentifier(self.nodeIdentifier)
layout.label("{} should not be used with auto execution.".format(repr(node.name)))
class NodeMustNotBeInSubprogram(Problem):
def __init__(self, nodeIdentifier):
self.nodeIdentifier = nodeIdentifier
def allowUnitCreation(self):
return False
def draw(self, layout):
node = getNodeByIdentifier(self.nodeIdentifier)
layout.label("{} must not be in a subprogram".format(repr(node.name)))
class NodeDoesNotSupportExecution(Problem):
def __init__(self, nodeIdentifier):
self.nodeIdentifier = nodeIdentifier
def allowUnitCreation(self):
return False
def draw(self, layout):
node = getNodeByIdentifier(self.nodeIdentifier)
layout.label("{} does not support excecution".format(repr(node.name)))
class IdentifierExistsTwice(Problem):
def allowUnitCreation(self):
return False
def draw(self, layout):
message = ("At least one node identifier exists twice. "
"This can happen when you append a node tree "
"that is already in this file. \n"
"Solution: \n"
" 1. Select the NEW node tree \n"
" 2. Click on the button below")
col = layout.column()
writeText(col, message, autoWidth = True)
col.operator("an.replace_nodes_with_copies")
class LinkedAnimationNodeTreeExists(Problem):
def allowUnitCreation(self):
return False
def draw(self, layout):
layout.label("AN doesn't support linked node trees.")
class UndefinedNodeExists(Problem):
def __init__(self, nodes):
self.nodeIDs = [node.toID() for node in nodes]
def allowUnitCreation(self):
return False
def draw(self, layout):
message = ("There is at least one undefined node. "
"This happens when you open a .blend file uses "
"nodes which don't exist in your version of AN.\n"
"To fix this you can either install the AN version this "
"file has been created with or you try to replace/remove "
"the undefined nodes.")
writeText(layout, message, autoWidth = True)
col = layout.column(align = True)
for nodeID in self.nodeIDs:
node = idToNode(nodeID)
props = col.operator("an.move_view_to_node", icon = "VIEWZOOM", text = "{} is undefined".format(repr(node.name)))
props.treeName = nodeID[0]
props.nodeName = nodeID[1]
# Exceptions
########################################
class ExecutionUnitNotSetup(Exception):
pass