schema_nodes_ui.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. import bpy
  2. from .base_definitions import SchemaUINode
  3. from bpy.types import Node
  4. from .utilities import (prRed, prGreen, prPurple, prWhite,
  5. prOrange,
  6. wrapRed, wrapGreen, wrapPurple, wrapWhite,
  7. wrapOrange,)
  8. from bpy.props import BoolProperty
  9. from .utilities import get_socket_maps, relink_socket_map, do_relink
  10. def TellClasses():
  11. return [
  12. # tree i/o
  13. SchemaIndex,
  14. SchemaArrayInput,
  15. SchemaArrayInputGet,
  16. SchemaArrayInputAll,
  17. SchemaArrayOutput,
  18. SchemaConstInput,
  19. SchemaConstOutput,
  20. SchemaOutgoingConnection,
  21. SchemaIncomingConnection,
  22. ]
  23. # IMPORTANT TODO:
  24. # - check what happens when these get plugged into each other
  25. # - probably disallow all or most of these connections in insert_link or update
  26. class SchemaIndex(Node, SchemaUINode):
  27. '''The current index of the schema execution'''
  28. bl_idname = 'SchemaIndex'
  29. bl_label = "Index"
  30. bl_icon = 'GIZMO'
  31. initialized : bpy.props.BoolProperty(default = False)
  32. mantis_node_class_name=bl_idname
  33. def init(self, context):
  34. self.outputs.new("IntSocket", "Index")
  35. self.outputs.new("IntSocket", "Schema Length")
  36. self.initialized = True
  37. class SchemaArrayInput(Node, SchemaUINode):
  38. '''Array Inputs'''
  39. bl_idname = 'SchemaArrayInput'
  40. bl_label = "Array Input at Current Index"
  41. bl_icon = 'GIZMO'
  42. initialized : bpy.props.BoolProperty(default = False)
  43. mantis_node_class_name=bl_idname
  44. def init(self, context):
  45. self.update()
  46. def update(self):
  47. if self.is_updating:
  48. return
  49. self.is_updating = True
  50. # self.initialized = False
  51. socket_maps = get_socket_maps(self)
  52. if socket_maps is None:
  53. return
  54. output_map = socket_maps[1]
  55. self.outputs.clear()
  56. for item in self.id_data.interface.items_tree:
  57. if item.item_type == 'PANEL': continue
  58. if item.parent and item.in_out == 'INPUT' and item.parent.name == 'Array':
  59. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  60. if '__extend__' in output_map.keys() and output_map['__extend__']:
  61. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Array' )
  62. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  63. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  64. # self.initialized = True
  65. self.is_updating = False
  66. class SchemaArrayInputAll(Node, SchemaUINode):
  67. '''Array Inputs'''
  68. bl_idname = 'SchemaArrayInputAll'
  69. bl_label = "Get entire Array Input"
  70. bl_icon = 'GIZMO'
  71. initialized : bpy.props.BoolProperty(default = False)
  72. mantis_node_class_name=bl_idname
  73. def init(self, context):
  74. self.update()
  75. def update(self):
  76. if self.is_updating:
  77. return
  78. self.is_updating = True
  79. self.initialized = False
  80. socket_maps = get_socket_maps(self)
  81. if socket_maps is None:
  82. return
  83. output_map = socket_maps[1]
  84. self.outputs.clear()
  85. for item in self.id_data.interface.items_tree:
  86. if item.item_type == 'PANEL': continue
  87. if item.parent and item.in_out == 'INPUT' and item.parent.name == 'Array':
  88. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  89. if '__extend__' in output_map.keys() and output_map['__extend__']:
  90. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Array' )
  91. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  92. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  93. self.initialized = True
  94. self.is_updating = False
  95. class SchemaArrayInputGet(Node, SchemaUINode):
  96. '''Array Inputs'''
  97. bl_idname = 'SchemaArrayInputGet'
  98. bl_label = "Array Input at Index"
  99. bl_icon = 'GIZMO'
  100. initialized : bpy.props.BoolProperty(default = False)
  101. mantis_node_class_name=bl_idname
  102. def init(self, context):
  103. self.inputs.new('EnumArrayGetOptions', 'OoB Behaviour')
  104. self.inputs.new("IntSocket", "Index")
  105. self.update()
  106. def update(self):
  107. if self.is_updating:
  108. return
  109. self.is_updating = True
  110. self.initialized = False
  111. socket_maps = get_socket_maps(self)
  112. if socket_maps is None:
  113. return
  114. output_map = socket_maps[1]
  115. self.outputs.clear()
  116. for item in self.id_data.interface.items_tree:
  117. if item.item_type == 'PANEL': continue
  118. if item.parent and item.in_out == 'INPUT' and item.parent.name == 'Array':
  119. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  120. if '__extend__' in output_map.keys() and output_map['__extend__']:
  121. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Array' )
  122. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  123. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  124. self.initialized = True
  125. self.is_updating = False
  126. class SchemaArrayOutput(Node, SchemaUINode):
  127. '''Array Inputs'''
  128. bl_idname = 'SchemaArrayOutput'
  129. bl_label = "Array Output"
  130. bl_icon = 'GIZMO'
  131. initialized : bpy.props.BoolProperty(default = False)
  132. mantis_node_class_name=bl_idname
  133. def init(self, context):
  134. self.update()
  135. def update(self):
  136. if self.is_updating:
  137. return
  138. self.is_updating = True
  139. self.initialized = False
  140. socket_maps = get_socket_maps(self)
  141. if socket_maps is None:
  142. return
  143. input_map = socket_maps[0]
  144. self.inputs.clear()
  145. for item in self.id_data.interface.items_tree:
  146. if item.item_type == 'PANEL': continue
  147. if item.parent and item.in_out == 'OUTPUT' and item.parent.name == 'Array':
  148. relink_socket_map(self, self.inputs, input_map, item, in_out='INPUT')
  149. if '__extend__' in input_map.keys() and input_map['__extend__']:
  150. do_relink(self, None, input_map, in_out='INPUT', parent_name='Array' )
  151. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  152. self.inputs.new('WildcardSocket', '', identifier='__extend__')
  153. for s in self.outputs:
  154. s.input= True
  155. self.initialized = True
  156. self.is_updating = False
  157. class SchemaConstInput(Node, SchemaUINode):
  158. '''Constant Inputs'''
  159. bl_idname = 'SchemaConstInput'
  160. bl_label = "Constant Input"
  161. bl_icon = 'GIZMO'
  162. initialized : bpy.props.BoolProperty(default = False)
  163. mantis_node_class_name=bl_idname
  164. def init(self, context):
  165. self.update()
  166. def update(self):
  167. if self.is_updating:
  168. return
  169. self.is_updating = True
  170. self.initialized = False
  171. socket_maps = get_socket_maps(self)
  172. if socket_maps is None:
  173. return
  174. output_map = socket_maps[1]
  175. self.outputs.clear()
  176. for item in self.id_data.interface.items_tree:
  177. if item.item_type == 'PANEL': continue
  178. if item.parent and item.in_out == 'INPUT' and item.parent.name == 'Constant':
  179. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  180. if '__extend__' in output_map.keys() and output_map['__extend__']:
  181. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Constant' )
  182. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  183. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  184. self.initialized = True
  185. self.is_updating = False
  186. class SchemaConstOutput(Node, SchemaUINode):
  187. '''Constant Outputs'''
  188. bl_idname = 'SchemaConstOutput'
  189. bl_label = "Constant Output"
  190. bl_icon = 'GIZMO'
  191. initialized : bpy.props.BoolProperty(default = False)
  192. mantis_node_class_name=bl_idname
  193. def init(self, context):
  194. self.update()
  195. def update(self):
  196. if self.is_updating:
  197. return
  198. self.is_updating = True
  199. self.initialized = False
  200. socket_maps = get_socket_maps(self)
  201. if socket_maps is None:
  202. return
  203. input_map = socket_maps[0]
  204. self.inputs.clear()
  205. s = self.inputs.new('UnsignedIntSocket', "Expose at Index")
  206. for item in self.id_data.interface.items_tree:
  207. if item.item_type == 'PANEL': continue
  208. if item.parent and item.in_out == 'OUTPUT' and item.parent.name == 'Constant':
  209. relink_socket_map(self, self.inputs, input_map, item, in_out='INPUT')
  210. if '__extend__' in input_map.keys() and input_map['__extend__']:
  211. do_relink(self, None, input_map, in_out='INPUT', parent_name='Constant' )
  212. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  213. self.inputs.new('WildcardSocket', '', identifier='__extend__')
  214. do_relink(self, s, input_map, in_out='INPUT')
  215. for s in self.outputs:
  216. s.input= True
  217. self.initialized = True
  218. self.is_updating = False
  219. class SchemaOutgoingConnection(Node, SchemaUINode):
  220. '''Outgoing Connections'''
  221. bl_idname = 'SchemaOutgoingConnection'
  222. bl_label = "Outgoing Connection"
  223. bl_icon = 'GIZMO'
  224. initialized : bpy.props.BoolProperty(default = False)
  225. mantis_node_class_name=bl_idname
  226. def init(self, context):
  227. self.update()
  228. def update(self):
  229. if self.is_updating:
  230. return
  231. self.is_updating = True
  232. self.initialized = False
  233. socket_maps = get_socket_maps(self)
  234. if socket_maps is None:
  235. return
  236. input_map = socket_maps[0]
  237. self.inputs.clear()
  238. for item in self.id_data.interface.items_tree:
  239. if item.item_type == 'PANEL': continue
  240. if item.parent and item.in_out == 'OUTPUT' and item.parent.name == 'Connection':
  241. relink_socket_map(self, self.inputs, input_map, item, in_out='INPUT')
  242. if '__extend__' in input_map.keys() and input_map['__extend__']:
  243. do_relink(self, None, input_map, in_out='INPUT', parent_name='Connection' )
  244. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  245. self.inputs.new('WildcardSocket', '', identifier='__extend__')
  246. for s in self.outputs:
  247. s.input= True
  248. self.initialized = True
  249. self.is_updating = False
  250. class SchemaIncomingConnection(Node, SchemaUINode):
  251. '''Incoming Connections'''
  252. bl_idname = 'SchemaIncomingConnection'
  253. bl_label = "Incoming Connection"
  254. bl_icon = 'GIZMO'
  255. initialized : bpy.props.BoolProperty(default = False)
  256. mantis_node_class_name=bl_idname
  257. def init(self, context):
  258. self.update()
  259. def update(self):
  260. if self.is_updating:
  261. return
  262. self.is_updating = True
  263. self.initialized = False
  264. socket_maps = get_socket_maps(self)
  265. if socket_maps is None:
  266. return
  267. output_map = socket_maps[1]
  268. self.outputs.clear()
  269. for item in self.id_data.interface.items_tree:
  270. if item.item_type == 'PANEL': continue
  271. if item.parent and item.in_out == 'INPUT' and item.parent.name == 'Connection':
  272. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  273. if '__extend__' in output_map.keys() and output_map['__extend__']:
  274. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Connection' )
  275. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  276. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  277. self.initialized = True
  278. self.is_updating = False
  279. for cls in TellClasses():
  280. cls.set_mantis_class()