schema_nodes_ui.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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,
  10. do_relink, read_schema_type)
  11. def TellClasses():
  12. return [
  13. # tree i/o
  14. SchemaIndex,
  15. SchemaArrayInput,
  16. SchemaArrayInputGet,
  17. SchemaArrayInputAll,
  18. SchemaArrayOutput,
  19. SchemaConstInput,
  20. SchemaConstOutput,
  21. SchemaOutgoingConnection,
  22. SchemaIncomingConnection,
  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. if self.is_updating:
  49. return
  50. self.is_updating = True
  51. # self.initialized = False
  52. socket_maps = get_socket_maps(self)
  53. if socket_maps is None:
  54. return
  55. output_map = socket_maps[1]
  56. self.outputs.clear()
  57. for item in self.id_data.interface.items_tree:
  58. if item.item_type == 'PANEL': continue
  59. parent_name = read_schema_type(item)
  60. if item.in_out == 'INPUT' and parent_name == 'Array':
  61. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  62. if '__extend__' in output_map.keys() and output_map['__extend__']:
  63. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Array' )
  64. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  65. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  66. # self.initialized = True
  67. self.is_updating = False
  68. class SchemaArrayInputAll(Node, SchemaUINode):
  69. '''Array Inputs'''
  70. bl_idname = 'SchemaArrayInputAll'
  71. bl_label = "Get entire Array Input"
  72. bl_icon = 'GIZMO'
  73. initialized : bpy.props.BoolProperty(default = False)
  74. mantis_node_class_name=bl_idname
  75. def init(self, context):
  76. self.update()
  77. def update(self):
  78. if self.is_updating:
  79. return
  80. self.is_updating = True
  81. self.initialized = False
  82. socket_maps = get_socket_maps(self)
  83. if socket_maps is None:
  84. return
  85. output_map = socket_maps[1]
  86. self.outputs.clear()
  87. for item in self.id_data.interface.items_tree:
  88. if item.item_type == 'PANEL': continue
  89. parent_name = read_schema_type(item)
  90. if item.in_out == 'INPUT' and parent_name == 'Array':
  91. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  92. if '__extend__' in output_map.keys() and output_map['__extend__']:
  93. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Array' )
  94. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  95. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  96. self.initialized = True
  97. self.is_updating = False
  98. class SchemaArrayInputGet(Node, SchemaUINode):
  99. '''Array Inputs'''
  100. bl_idname = 'SchemaArrayInputGet'
  101. bl_label = "Array Input at Index"
  102. bl_icon = 'GIZMO'
  103. initialized : bpy.props.BoolProperty(default = False)
  104. mantis_node_class_name=bl_idname
  105. def init(self, context):
  106. self.inputs.new('EnumArrayGetOptions', 'OoB Behaviour')
  107. self.inputs.new("IntSocket", "Index")
  108. self.update()
  109. def update(self):
  110. if self.is_updating:
  111. return
  112. self.is_updating = True
  113. self.initialized = False
  114. socket_maps = get_socket_maps(self)
  115. if socket_maps is None:
  116. return
  117. output_map = socket_maps[1]
  118. self.outputs.clear()
  119. for item in self.id_data.interface.items_tree:
  120. if item.item_type == 'PANEL': continue
  121. parent_name = read_schema_type(item)
  122. if item.in_out == 'INPUT' and parent_name == 'Array':
  123. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  124. if '__extend__' in output_map.keys() and output_map['__extend__']:
  125. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Array' )
  126. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  127. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  128. self.initialized = True
  129. self.is_updating = False
  130. class SchemaArrayOutput(Node, SchemaUINode):
  131. '''Array Inputs'''
  132. bl_idname = 'SchemaArrayOutput'
  133. bl_label = "Array Output"
  134. bl_icon = 'GIZMO'
  135. initialized : bpy.props.BoolProperty(default = False)
  136. mantis_node_class_name=bl_idname
  137. def init(self, context):
  138. self.update()
  139. def update(self):
  140. if self.is_updating:
  141. return
  142. self.is_updating = True
  143. self.initialized = False
  144. socket_maps = get_socket_maps(self)
  145. if socket_maps is None:
  146. return
  147. input_map = socket_maps[0]
  148. self.inputs.clear()
  149. for item in self.id_data.interface.items_tree:
  150. if item.item_type == 'PANEL': continue
  151. parent_name = read_schema_type(item)
  152. if item.in_out == 'OUTPUT' and parent_name == 'Array':
  153. relink_socket_map(self, self.inputs, input_map, item, in_out='INPUT')
  154. if '__extend__' in input_map.keys() and input_map['__extend__']:
  155. do_relink(self, None, input_map, in_out='INPUT', parent_name='Array' )
  156. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  157. self.inputs.new('WildcardSocket', '', identifier='__extend__')
  158. for s in self.outputs:
  159. s.input= True
  160. self.initialized = True
  161. self.is_updating = False
  162. class SchemaConstInput(Node, SchemaUINode):
  163. '''Constant Inputs'''
  164. bl_idname = 'SchemaConstInput'
  165. bl_label = "Constant Input"
  166. bl_icon = 'GIZMO'
  167. initialized : bpy.props.BoolProperty(default = False)
  168. mantis_node_class_name=bl_idname
  169. def init(self, context):
  170. self.update()
  171. def update(self):
  172. if self.is_updating:
  173. return
  174. self.is_updating = True
  175. self.initialized = False
  176. socket_maps = get_socket_maps(self)
  177. if socket_maps is None:
  178. return
  179. output_map = socket_maps[1]
  180. self.outputs.clear()
  181. for item in self.id_data.interface.items_tree:
  182. if item.item_type == 'PANEL': continue
  183. parent_name = read_schema_type(item)
  184. if item.in_out == 'INPUT' and parent_name == 'Constant':
  185. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  186. if '__extend__' in output_map.keys() and output_map['__extend__']:
  187. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Constant' )
  188. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  189. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  190. self.initialized = True
  191. self.is_updating = False
  192. class SchemaConstOutput(Node, SchemaUINode):
  193. '''Constant Outputs'''
  194. bl_idname = 'SchemaConstOutput'
  195. bl_label = "Constant Output"
  196. bl_icon = 'GIZMO'
  197. initialized : bpy.props.BoolProperty(default = False)
  198. mantis_node_class_name=bl_idname
  199. def init(self, context):
  200. self.update()
  201. def update(self):
  202. if self.is_updating:
  203. return
  204. self.is_updating = True
  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. s = self.inputs.new('UnsignedIntSocket', "Expose at Index")
  212. for item in self.id_data.interface.items_tree:
  213. if item.item_type == 'PANEL': continue
  214. parent_name = read_schema_type(item)
  215. if item.in_out == 'OUTPUT' and parent_name == 'Constant':
  216. relink_socket_map(self, self.inputs, input_map, item, in_out='INPUT')
  217. if '__extend__' in input_map.keys() and input_map['__extend__']:
  218. do_relink(self, None, input_map, in_out='INPUT', parent_name='Constant' )
  219. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  220. self.inputs.new('WildcardSocket', '', identifier='__extend__')
  221. do_relink(self, s, input_map, in_out='INPUT')
  222. for s in self.outputs:
  223. s.input= True
  224. self.initialized = True
  225. self.is_updating = False
  226. class SchemaOutgoingConnection(Node, SchemaUINode):
  227. '''Outgoing Connections'''
  228. bl_idname = 'SchemaOutgoingConnection'
  229. bl_label = "Outgoing Connection"
  230. bl_icon = 'GIZMO'
  231. initialized : bpy.props.BoolProperty(default = False)
  232. mantis_node_class_name=bl_idname
  233. def init(self, context):
  234. self.update()
  235. def update(self):
  236. if self.is_updating:
  237. return
  238. self.is_updating = True
  239. self.initialized = False
  240. socket_maps = get_socket_maps(self)
  241. if socket_maps is None:
  242. return
  243. input_map = socket_maps[0]
  244. self.inputs.clear()
  245. for item in self.id_data.interface.items_tree:
  246. if item.item_type == 'PANEL': continue
  247. parent_name = read_schema_type(item)
  248. if item.in_out == 'OUTPUT' and parent_name == 'Connection':
  249. relink_socket_map(self, self.inputs, input_map, item, in_out='INPUT')
  250. if '__extend__' in input_map.keys() and input_map['__extend__']:
  251. do_relink(self, None, input_map, in_out='INPUT', parent_name='Connection' )
  252. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  253. self.inputs.new('WildcardSocket', '', identifier='__extend__')
  254. for s in self.outputs:
  255. s.input= True
  256. self.initialized = True
  257. self.is_updating = False
  258. class SchemaIncomingConnection(Node, SchemaUINode):
  259. '''Incoming Connections'''
  260. bl_idname = 'SchemaIncomingConnection'
  261. bl_label = "Incoming Connection"
  262. bl_icon = 'GIZMO'
  263. initialized : bpy.props.BoolProperty(default = False)
  264. mantis_node_class_name=bl_idname
  265. def init(self, context):
  266. self.update()
  267. def update(self):
  268. if self.is_updating:
  269. return
  270. self.is_updating = True
  271. self.initialized = False
  272. socket_maps = get_socket_maps(self)
  273. if socket_maps is None:
  274. return
  275. output_map = socket_maps[1]
  276. self.outputs.clear()
  277. for item in self.id_data.interface.items_tree:
  278. if item.item_type == 'PANEL': continue
  279. parent_name = read_schema_type(item)
  280. if item.in_out == 'INPUT' and parent_name == 'Connection':
  281. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  282. if '__extend__' in output_map.keys() and output_map['__extend__']:
  283. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Connection' )
  284. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  285. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  286. self.initialized = True
  287. self.is_updating = False
  288. for cls in TellClasses():
  289. cls.set_mantis_class()