schema_definitions.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. # self.initialized = False
  48. socket_maps = get_socket_maps(self)
  49. if socket_maps is None:
  50. return
  51. output_map = socket_maps[1]
  52. self.outputs.clear()
  53. for item in self.id_data.interface.items_tree:
  54. if item.item_type == 'PANEL': continue
  55. if item.parent and item.in_out == 'INPUT' and item.parent.name == 'Array':
  56. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  57. if '__extend__' in output_map.keys() and output_map['__extend__']:
  58. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Array' )
  59. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  60. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  61. # self.initialized = True
  62. class SchemaArrayInputAll(Node, SchemaUINode):
  63. '''Array Inputs'''
  64. bl_idname = 'SchemaArrayInputAll'
  65. bl_label = "Get entire Array Input"
  66. bl_icon = 'GIZMO'
  67. initialized : bpy.props.BoolProperty(default = False)
  68. mantis_node_class_name=bl_idname
  69. def init(self, context):
  70. self.update()
  71. def update(self):
  72. # self.initialized = False
  73. socket_maps = get_socket_maps(self)
  74. if socket_maps is None:
  75. return
  76. output_map = socket_maps[1]
  77. self.outputs.clear()
  78. for item in self.id_data.interface.items_tree:
  79. if item.item_type == 'PANEL': continue
  80. if item.parent and item.in_out == 'INPUT' and item.parent.name == 'Array':
  81. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  82. if '__extend__' in output_map.keys() and output_map['__extend__']:
  83. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Array' )
  84. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  85. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  86. class SchemaArrayInputGet(Node, SchemaUINode):
  87. '''Array Inputs'''
  88. bl_idname = 'SchemaArrayInputGet'
  89. bl_label = "Array Input at Index"
  90. bl_icon = 'GIZMO'
  91. initialized : bpy.props.BoolProperty(default = False)
  92. mantis_node_class_name=bl_idname
  93. def init(self, context):
  94. self.inputs.new('EnumArrayGetOptions', 'OoB Behaviour')
  95. self.inputs.new("IntSocket", "Index")
  96. self.update()
  97. def update(self):
  98. # self.initialized = False
  99. socket_maps = get_socket_maps(self)
  100. if socket_maps is None:
  101. return
  102. output_map = socket_maps[1]
  103. self.outputs.clear()
  104. for item in self.id_data.interface.items_tree:
  105. if item.item_type == 'PANEL': continue
  106. if item.parent and item.in_out == 'INPUT' and item.parent.name == 'Array':
  107. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  108. if '__extend__' in output_map.keys() and output_map['__extend__']:
  109. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Array' )
  110. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  111. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  112. # self.initialized = True
  113. class SchemaArrayOutput(Node, SchemaUINode):
  114. '''Array Inputs'''
  115. bl_idname = 'SchemaArrayOutput'
  116. bl_label = "Array Output"
  117. bl_icon = 'GIZMO'
  118. initialized : bpy.props.BoolProperty(default = False)
  119. mantis_node_class_name=bl_idname
  120. def init(self, context):
  121. self.update()
  122. def update(self):
  123. self.initialized = False
  124. socket_maps = get_socket_maps(self)
  125. if socket_maps is None:
  126. return
  127. input_map = socket_maps[0]
  128. self.inputs.clear()
  129. for item in self.id_data.interface.items_tree:
  130. if item.item_type == 'PANEL': continue
  131. if item.parent and item.in_out == 'OUTPUT' and item.parent.name == 'Array':
  132. relink_socket_map(self, self.inputs, input_map, item, in_out='INPUT')
  133. if '__extend__' in input_map.keys() and input_map['__extend__']:
  134. do_relink(self, None, input_map, in_out='INPUT', parent_name='Array' )
  135. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  136. self.inputs.new('WildcardSocket', '', identifier='__extend__')
  137. for s in self.outputs:
  138. s.input= True
  139. self.initialized = True
  140. class SchemaConstInput(Node, SchemaUINode):
  141. '''Constant Inputs'''
  142. bl_idname = 'SchemaConstInput'
  143. bl_label = "Constant Input"
  144. bl_icon = 'GIZMO'
  145. initialized : bpy.props.BoolProperty(default = False)
  146. mantis_node_class_name=bl_idname
  147. def init(self, context):
  148. self.update()
  149. def update(self):
  150. self.initialized = False
  151. socket_maps = get_socket_maps(self)
  152. if socket_maps is None:
  153. return
  154. output_map = socket_maps[1]
  155. self.outputs.clear()
  156. for item in self.id_data.interface.items_tree:
  157. if item.item_type == 'PANEL': continue
  158. if item.parent and item.in_out == 'INPUT' and item.parent.name == 'Constant':
  159. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  160. if '__extend__' in output_map.keys() and output_map['__extend__']:
  161. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Constant' )
  162. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  163. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  164. self.initialized = True
  165. class SchemaConstOutput(Node, SchemaUINode):
  166. '''Constant Outputs'''
  167. bl_idname = 'SchemaConstOutput'
  168. bl_label = "Constant Output"
  169. bl_icon = 'GIZMO'
  170. initialized : bpy.props.BoolProperty(default = False)
  171. mantis_node_class_name=bl_idname
  172. def init(self, context):
  173. self.update()
  174. def update(self):
  175. self.initialized = False
  176. socket_maps = get_socket_maps(self)
  177. if socket_maps is None:
  178. return
  179. input_map = socket_maps[0]
  180. self.inputs.clear()
  181. s = self.inputs.new('UnsignedIntSocket', "Expose at Index")
  182. for item in self.id_data.interface.items_tree:
  183. if item.item_type == 'PANEL': continue
  184. if item.parent and item.in_out == 'OUTPUT' and item.parent.name == 'Constant':
  185. relink_socket_map(self, self.inputs, input_map, item, in_out='INPUT')
  186. if '__extend__' in input_map.keys() and input_map['__extend__']:
  187. do_relink(self, None, input_map, in_out='INPUT', parent_name='Constant' )
  188. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  189. self.inputs.new('WildcardSocket', '', identifier='__extend__')
  190. do_relink(self, s, input_map, in_out='INPUT')
  191. for s in self.outputs:
  192. s.input= True
  193. self.initialized = True
  194. class SchemaOutgoingConnection(Node, SchemaUINode):
  195. '''Outgoing Connections'''
  196. bl_idname = 'SchemaOutgoingConnection'
  197. bl_label = "Outgoing Connection"
  198. bl_icon = 'GIZMO'
  199. initialized : bpy.props.BoolProperty(default = False)
  200. mantis_node_class_name=bl_idname
  201. def init(self, context):
  202. self.update()
  203. def update(self):
  204. self.initialized = False
  205. socket_maps = get_socket_maps(self)
  206. if socket_maps is None:
  207. return
  208. input_map = socket_maps[0]
  209. self.inputs.clear()
  210. for item in self.id_data.interface.items_tree:
  211. if item.item_type == 'PANEL': continue
  212. if item.parent and item.in_out == 'OUTPUT' and item.parent.name == 'Connection':
  213. relink_socket_map(self, self.inputs, input_map, item, in_out='INPUT')
  214. if '__extend__' in input_map.keys() and input_map['__extend__']:
  215. do_relink(self, None, input_map, in_out='INPUT', parent_name='Connection' )
  216. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  217. self.inputs.new('WildcardSocket', '', identifier='__extend__')
  218. for s in self.outputs:
  219. s.input= True
  220. self.initialized = True
  221. class SchemaIncomingConnection(Node, SchemaUINode):
  222. '''Incoming Connections'''
  223. bl_idname = 'SchemaIncomingConnection'
  224. bl_label = "Incoming Connection"
  225. bl_icon = 'GIZMO'
  226. initialized : bpy.props.BoolProperty(default = False)
  227. mantis_node_class_name=bl_idname
  228. def init(self, context):
  229. self.update()
  230. def update(self):
  231. self.initialized = False
  232. socket_maps = get_socket_maps(self)
  233. if socket_maps is None:
  234. return
  235. output_map = socket_maps[1]
  236. self.outputs.clear()
  237. for item in self.id_data.interface.items_tree:
  238. if item.item_type == 'PANEL': continue
  239. if item.parent and item.in_out == 'INPUT' and item.parent.name == 'Connection':
  240. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  241. if '__extend__' in output_map.keys() and output_map['__extend__']:
  242. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Connection' )
  243. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  244. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  245. self.initialized = True
  246. for cls in TellClasses():
  247. cls.set_mantis_class()