schema_definitions.py 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. import bpy
  2. from .base_definitions import SchemaNode
  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, SchemaNode):
  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. def init(self, context):
  32. self.outputs.new("IntSocket", "Index")
  33. self.outputs.new("IntSocket", "Schema Length")
  34. self.initialized = True
  35. class SchemaArrayInput(Node, SchemaNode):
  36. '''Array Inputs'''
  37. bl_idname = 'SchemaArrayInput'
  38. bl_label = "Array Input"
  39. bl_icon = 'GIZMO'
  40. initialized : bpy.props.BoolProperty(default = False)
  41. def init(self, context):
  42. self.update()
  43. def update(self):
  44. # self.initialized = False
  45. output_map = get_socket_maps(self)[1]
  46. self.outputs.clear()
  47. for item in self.id_data.interface.items_tree:
  48. if item.item_type == 'PANEL': continue
  49. if item.parent and item.in_out == 'INPUT' and item.parent.name == 'Array':
  50. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  51. if '__extend__' in output_map.keys() and output_map['__extend__']:
  52. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Array' )
  53. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  54. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  55. # self.initialized = True
  56. class SchemaArrayInputGet(Node, SchemaNode):
  57. '''Array Inputs'''
  58. bl_idname = 'SchemaArrayInputGet'
  59. bl_label = "Array Input at Index"
  60. bl_icon = 'GIZMO'
  61. initialized : bpy.props.BoolProperty(default = False)
  62. def init(self, context):
  63. self.inputs.new('EnumArrayGetOptions', 'OoB Behaviour')
  64. self.inputs.new("IntSocket", "Index")
  65. self.update()
  66. def update(self):
  67. # self.initialized = False
  68. output_map = get_socket_maps(self)[1]
  69. self.outputs.clear()
  70. for item in self.id_data.interface.items_tree:
  71. if item.item_type == 'PANEL': continue
  72. if item.parent and item.in_out == 'INPUT' and item.parent.name == 'Array':
  73. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  74. if '__extend__' in output_map.keys() and output_map['__extend__']:
  75. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Array' )
  76. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  77. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  78. # self.initialized = True
  79. class SchemaArrayOutput(Node, SchemaNode):
  80. '''Array Inputs'''
  81. bl_idname = 'SchemaArrayOutput'
  82. bl_label = "Array Output"
  83. bl_icon = 'GIZMO'
  84. initialized : bpy.props.BoolProperty(default = False)
  85. def init(self, context):
  86. self.update()
  87. def update(self):
  88. self.initialized = False
  89. input_map = get_socket_maps(self)[0]
  90. self.inputs.clear()
  91. for item in self.id_data.interface.items_tree:
  92. if item.item_type == 'PANEL': continue
  93. if item.parent and item.in_out == 'OUTPUT' and item.parent.name == 'Array':
  94. relink_socket_map(self, self.inputs, input_map, item, in_out='INPUT')
  95. if '__extend__' in input_map.keys() and input_map['__extend__']:
  96. do_relink(self, None, input_map, in_out='INPUT', parent_name='Array' )
  97. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  98. self.inputs.new('WildcardSocket', '', identifier='__extend__')
  99. for s in self.outputs:
  100. s.input= True
  101. self.initialized = True
  102. class SchemaConstInput(Node, SchemaNode):
  103. '''Constant Inputs'''
  104. bl_idname = 'SchemaConstInput'
  105. bl_label = "Constant Input"
  106. bl_icon = 'GIZMO'
  107. initialized : bpy.props.BoolProperty(default = False)
  108. def init(self, context):
  109. self.update()
  110. def update(self):
  111. self.initialized = False
  112. output_map = get_socket_maps(self)[1]
  113. self.outputs.clear()
  114. for item in self.id_data.interface.items_tree:
  115. if item.item_type == 'PANEL': continue
  116. if item.parent and item.in_out == 'INPUT' and item.parent.name == 'Constant':
  117. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  118. if '__extend__' in output_map.keys() and output_map['__extend__']:
  119. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Constant' )
  120. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  121. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  122. self.initialized = True
  123. class SchemaConstOutput(Node, SchemaNode):
  124. '''Constant Outputs'''
  125. bl_idname = 'SchemaConstOutput'
  126. bl_label = "Constant Output"
  127. bl_icon = 'GIZMO'
  128. initialized : bpy.props.BoolProperty(default = False)
  129. def init(self, context):
  130. self.update()
  131. def update(self):
  132. self.initialized = False
  133. input_map = get_socket_maps(self)[0]
  134. self.inputs.clear()
  135. s = self.inputs.new('IntSocket', "Expose when N==")
  136. for item in self.id_data.interface.items_tree:
  137. if item.item_type == 'PANEL': continue
  138. if item.parent and item.in_out == 'OUTPUT' and item.parent.name == 'Constant':
  139. relink_socket_map(self, self.inputs, input_map, item, in_out='INPUT')
  140. if '__extend__' in input_map.keys() and input_map['__extend__']:
  141. do_relink(self, None, input_map, in_out='INPUT', parent_name='Constant' )
  142. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  143. self.inputs.new('WildcardSocket', '', identifier='__extend__')
  144. do_relink(self, s, input_map, in_out='INPUT')
  145. for s in self.outputs:
  146. s.input= True
  147. self.initialized = True
  148. class SchemaOutgoingConnection(Node, SchemaNode):
  149. '''Outgoing Connections'''
  150. bl_idname = 'SchemaOutgoingConnection'
  151. bl_label = "Outgoing Connection"
  152. bl_icon = 'GIZMO'
  153. initialized : bpy.props.BoolProperty(default = False)
  154. def init(self, context):
  155. # self.inputs.new('IntSocket', 'Valid From')
  156. # self.inputs.new('IntSocket', 'Valid Until')
  157. self.update()
  158. def update(self):
  159. self.initialized = False
  160. input_map = get_socket_maps(self)[0]
  161. self.inputs.clear()
  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 == 'Connection':
  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='Connection' )
  168. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  169. self.inputs.new('WildcardSocket', '', identifier='__extend__')
  170. for s in self.outputs:
  171. s.input= True
  172. self.initialized = True
  173. class SchemaIncomingConnection(Node, SchemaNode):
  174. '''Incoming Connections'''
  175. bl_idname = 'SchemaIncomingConnection'
  176. bl_label = "Incoming Connection"
  177. bl_icon = 'GIZMO'
  178. initialized : bpy.props.BoolProperty(default = False)
  179. def init(self, context):
  180. self.update()
  181. def update(self):
  182. self.initialized = False
  183. output_map = get_socket_maps(self)[1]
  184. self.outputs.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 == 'INPUT' and item.parent.name == 'Connection':
  188. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  189. if '__extend__' in output_map.keys() and output_map['__extend__']:
  190. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Connection' )
  191. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  192. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  193. self.initialized = True