schema_definitions.py 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. # self.initialized = False
  47. socket_maps = get_socket_maps(self)
  48. if socket_maps is None:
  49. return
  50. output_map = socket_maps[1]
  51. self.outputs.clear()
  52. for item in self.id_data.interface.items_tree:
  53. if item.item_type == 'PANEL': continue
  54. if item.parent and item.in_out == 'INPUT' and item.parent.name == 'Array':
  55. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  56. if '__extend__' in output_map.keys() and output_map['__extend__']:
  57. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Array' )
  58. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  59. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  60. # self.initialized = True
  61. class SchemaArrayInputGet(Node, SchemaUINode):
  62. '''Array Inputs'''
  63. bl_idname = 'SchemaArrayInputGet'
  64. bl_label = "Array Input at Index"
  65. bl_icon = 'GIZMO'
  66. initialized : bpy.props.BoolProperty(default = False)
  67. mantis_node_class_name=bl_idname
  68. def init(self, context):
  69. self.inputs.new('EnumArrayGetOptions', 'OoB Behaviour')
  70. self.inputs.new("IntSocket", "Index")
  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. # self.initialized = True
  88. class SchemaArrayOutput(Node, SchemaUINode):
  89. '''Array Inputs'''
  90. bl_idname = 'SchemaArrayOutput'
  91. bl_label = "Array Output"
  92. bl_icon = 'GIZMO'
  93. initialized : bpy.props.BoolProperty(default = False)
  94. mantis_node_class_name=bl_idname
  95. def init(self, context):
  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. input_map = socket_maps[0]
  103. self.inputs.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 == 'OUTPUT' and item.parent.name == 'Array':
  107. relink_socket_map(self, self.inputs, input_map, item, in_out='INPUT')
  108. if '__extend__' in input_map.keys() and input_map['__extend__']:
  109. do_relink(self, None, input_map, in_out='INPUT', parent_name='Array' )
  110. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  111. self.inputs.new('WildcardSocket', '', identifier='__extend__')
  112. for s in self.outputs:
  113. s.input= True
  114. self.initialized = True
  115. class SchemaConstInput(Node, SchemaUINode):
  116. '''Constant Inputs'''
  117. bl_idname = 'SchemaConstInput'
  118. bl_label = "Constant Input"
  119. bl_icon = 'GIZMO'
  120. initialized : bpy.props.BoolProperty(default = False)
  121. mantis_node_class_name=bl_idname
  122. def init(self, context):
  123. self.update()
  124. def update(self):
  125. self.initialized = False
  126. socket_maps = get_socket_maps(self)
  127. if socket_maps is None:
  128. return
  129. output_map = socket_maps[1]
  130. self.outputs.clear()
  131. for item in self.id_data.interface.items_tree:
  132. if item.item_type == 'PANEL': continue
  133. if item.parent and item.in_out == 'INPUT' and item.parent.name == 'Constant':
  134. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  135. if '__extend__' in output_map.keys() and output_map['__extend__']:
  136. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Constant' )
  137. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  138. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  139. self.initialized = True
  140. class SchemaConstOutput(Node, SchemaUINode):
  141. '''Constant Outputs'''
  142. bl_idname = 'SchemaConstOutput'
  143. bl_label = "Constant Output"
  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. input_map = socket_maps[0]
  155. self.inputs.clear()
  156. s = self.inputs.new('IntSocket', "Expose when N==")
  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 == 'OUTPUT' and item.parent.name == 'Constant':
  160. relink_socket_map(self, self.inputs, input_map, item, in_out='INPUT')
  161. if '__extend__' in input_map.keys() and input_map['__extend__']:
  162. do_relink(self, None, input_map, in_out='INPUT', parent_name='Constant' )
  163. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  164. self.inputs.new('WildcardSocket', '', identifier='__extend__')
  165. do_relink(self, s, input_map, in_out='INPUT')
  166. for s in self.outputs:
  167. s.input= True
  168. self.initialized = True
  169. class SchemaOutgoingConnection(Node, SchemaUINode):
  170. '''Outgoing Connections'''
  171. bl_idname = 'SchemaOutgoingConnection'
  172. bl_label = "Outgoing Connection"
  173. bl_icon = 'GIZMO'
  174. initialized : bpy.props.BoolProperty(default = False)
  175. mantis_node_class_name=bl_idname
  176. def init(self, context):
  177. self.update()
  178. def update(self):
  179. self.initialized = False
  180. socket_maps = get_socket_maps(self)
  181. if socket_maps is None:
  182. return
  183. input_map = socket_maps[0]
  184. self.inputs.clear()
  185. for item in self.id_data.interface.items_tree:
  186. if item.item_type == 'PANEL': continue
  187. if item.parent and item.in_out == 'OUTPUT' and item.parent.name == 'Connection':
  188. relink_socket_map(self, self.inputs, input_map, item, in_out='INPUT')
  189. if '__extend__' in input_map.keys() and input_map['__extend__']:
  190. do_relink(self, None, input_map, in_out='INPUT', parent_name='Connection' )
  191. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  192. self.inputs.new('WildcardSocket', '', identifier='__extend__')
  193. for s in self.outputs:
  194. s.input= True
  195. self.initialized = True
  196. class SchemaIncomingConnection(Node, SchemaUINode):
  197. '''Incoming Connections'''
  198. bl_idname = 'SchemaIncomingConnection'
  199. bl_label = "Incoming Connection"
  200. bl_icon = 'GIZMO'
  201. initialized : bpy.props.BoolProperty(default = False)
  202. mantis_node_class_name=bl_idname
  203. def init(self, context):
  204. self.update()
  205. def update(self):
  206. self.initialized = False
  207. socket_maps = get_socket_maps(self)
  208. if socket_maps is None:
  209. return
  210. output_map = socket_maps[1]
  211. self.outputs.clear()
  212. for item in self.id_data.interface.items_tree:
  213. if item.item_type == 'PANEL': continue
  214. if item.parent and item.in_out == 'INPUT' and item.parent.name == 'Connection':
  215. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  216. if '__extend__' in output_map.keys() and output_map['__extend__']:
  217. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Connection' )
  218. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  219. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  220. self.initialized = True
  221. for cls in TellClasses():
  222. cls.set_mantis_class()