schema_definitions.py 11 KB

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