schema_definitions.py 10 KB

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