schema_definitions.py 9.1 KB

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