schema_nodes_ui.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. import bpy
  2. from .base_definitions import SchemaUINode
  3. from bpy.types import Node
  4. from .utilities.utilities import (prRed, prGreen, prPurple, prWhite,
  5. prOrange,
  6. wrapRed, wrapGreen, wrapPurple, wrapWhite,
  7. wrapOrange,)
  8. from bpy.props import BoolProperty
  9. from .utilities.utilities import (get_socket_maps, relink_socket_map,
  10. do_relink, read_schema_type)
  11. from .schema_nodes_socket_templates import *
  12. def TellClasses():
  13. return [
  14. # tree i/o
  15. SchemaIndex,
  16. SchemaArrayInput,
  17. SchemaArrayInputGet,
  18. SchemaArrayInputAll,
  19. SchemaArrayOutput,
  20. SchemaConstInput,
  21. SchemaConstOutput,
  22. SchemaOutgoingConnection,
  23. SchemaIncomingConnection,
  24. ]
  25. # IMPORTANT TODO:
  26. # - check what happens when these get plugged into each other
  27. # - probably disallow all or most of these connections in insert_link or update
  28. class SchemaIndex(Node, SchemaUINode):
  29. '''The current index of the schema execution'''
  30. bl_idname = 'SchemaIndex'
  31. bl_label = "Index"
  32. bl_icon = 'GIZMO'
  33. mantis_node_class_name=bl_idname
  34. socket_templates = SchemaIndexSockets
  35. class SchemaArrayInput(Node, SchemaUINode):
  36. '''Array Inputs'''
  37. bl_idname = 'SchemaArrayInput'
  38. bl_label = "Array Input at Current Index"
  39. bl_icon = 'GIZMO'
  40. mantis_node_class_name=bl_idname
  41. def init(self, context):
  42. self.update()
  43. def update(self):
  44. if self.is_updating:
  45. return
  46. self.is_updating = True
  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. parent_name = read_schema_type(item)
  56. if item.in_out == 'INPUT' and parent_name == 'Array':
  57. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  58. if '__extend__' in output_map.keys() and output_map['__extend__']:
  59. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Array' )
  60. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  61. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  62. # self.initialized = True
  63. self.is_updating = False
  64. class SchemaArrayInputAll(Node, SchemaUINode):
  65. '''Array Inputs'''
  66. bl_idname = 'SchemaArrayInputAll'
  67. bl_label = "Get entire Array Input"
  68. bl_icon = 'GIZMO'
  69. mantis_node_class_name=bl_idname
  70. def init(self, context):
  71. self.update()
  72. def update(self):
  73. if self.is_updating:
  74. return
  75. self.is_updating = True
  76. self.initialized = False
  77. socket_maps = get_socket_maps(self)
  78. if socket_maps is None:
  79. return
  80. output_map = socket_maps[1]
  81. self.outputs.clear()
  82. for item in self.id_data.interface.items_tree:
  83. if item.item_type == 'PANEL': continue
  84. parent_name = read_schema_type(item)
  85. if item.in_out == 'INPUT' and parent_name == 'Array':
  86. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  87. if '__extend__' in output_map.keys() and output_map['__extend__']:
  88. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Array' )
  89. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  90. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  91. self.initialized = True
  92. self.is_updating = False
  93. class SchemaArrayInputGet(Node, SchemaUINode):
  94. '''Array Inputs'''
  95. bl_idname = 'SchemaArrayInputGet'
  96. bl_label = "Array Input at Index"
  97. bl_icon = 'GIZMO'
  98. mantis_node_class_name=bl_idname
  99. socket_templates = SchemaArrayInputGetSockets
  100. def init(self, context):
  101. self.init_sockets(SchemaArrayInputGetSockets)
  102. self.update()
  103. def update(self):
  104. if self.is_updating:
  105. return
  106. self.is_updating = True
  107. self.initialized = False
  108. socket_maps = get_socket_maps(self)
  109. if socket_maps is None:
  110. return
  111. output_map = socket_maps[1]
  112. self.outputs.clear()
  113. for item in self.id_data.interface.items_tree:
  114. if item.item_type == 'PANEL': continue
  115. parent_name = read_schema_type(item)
  116. if item.in_out == 'INPUT' and parent_name == 'Array':
  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='Array' )
  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. self.is_updating = False
  124. class SchemaArrayOutput(Node, SchemaUINode):
  125. '''Array Inputs'''
  126. bl_idname = 'SchemaArrayOutput'
  127. bl_label = "Array Output"
  128. bl_icon = 'GIZMO'
  129. mantis_node_class_name=bl_idname
  130. def init(self, context):
  131. self.update()
  132. def update(self):
  133. if self.is_updating:
  134. return
  135. self.is_updating = True
  136. self.initialized = False
  137. socket_maps = get_socket_maps(self)
  138. if socket_maps is None:
  139. return
  140. input_map = socket_maps[0]
  141. self.inputs.clear()
  142. for item in self.id_data.interface.items_tree:
  143. if item.item_type == 'PANEL': continue
  144. parent_name = read_schema_type(item)
  145. if item.in_out == 'OUTPUT' and parent_name == 'Array':
  146. relink_socket_map(self, self.inputs, input_map, item, in_out='INPUT')
  147. if '__extend__' in input_map.keys() and input_map['__extend__']:
  148. do_relink(self, None, input_map, in_out='INPUT', parent_name='Array' )
  149. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  150. self.inputs.new('WildcardSocket', '', identifier='__extend__')
  151. for s in self.outputs:
  152. s.input= True
  153. self.initialized = True
  154. self.is_updating = False
  155. class SchemaConstInput(Node, SchemaUINode):
  156. '''Constant Inputs'''
  157. bl_idname = 'SchemaConstInput'
  158. bl_label = "Constant Input"
  159. bl_icon = 'GIZMO'
  160. mantis_node_class_name=bl_idname
  161. def init(self, context):
  162. self.update()
  163. def update(self):
  164. if self.is_updating:
  165. return
  166. self.is_updating = True
  167. self.initialized = False
  168. socket_maps = get_socket_maps(self)
  169. if socket_maps is None:
  170. return
  171. output_map = socket_maps[1]
  172. self.outputs.clear()
  173. for item in self.id_data.interface.items_tree:
  174. if item.item_type == 'PANEL': continue
  175. parent_name = read_schema_type(item)
  176. if item.in_out == 'INPUT' and parent_name == 'Constant':
  177. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  178. if '__extend__' in output_map.keys() and output_map['__extend__']:
  179. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Constant' )
  180. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  181. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  182. self.initialized = True
  183. self.is_updating = False
  184. class SchemaConstOutput(Node, SchemaUINode):
  185. '''Constant Outputs'''
  186. bl_idname = 'SchemaConstOutput'
  187. bl_label = "Constant Output"
  188. bl_icon = 'GIZMO'
  189. mantis_node_class_name=bl_idname
  190. def init(self, context):
  191. self.update()
  192. def update(self):
  193. if self.is_updating:
  194. return
  195. self.is_updating = True
  196. self.initialized = False
  197. socket_maps = get_socket_maps(self)
  198. if socket_maps is None:
  199. return
  200. input_map = socket_maps[0]
  201. self.inputs.clear()
  202. s = self.inputs.new('UnsignedIntSocket', "Expose at Index")
  203. for item in self.id_data.interface.items_tree:
  204. if item.item_type == 'PANEL': continue
  205. parent_name = read_schema_type(item)
  206. if item.in_out == 'OUTPUT' and parent_name == 'Constant':
  207. relink_socket_map(self, self.inputs, input_map, item, in_out='INPUT')
  208. if '__extend__' in input_map.keys() and input_map['__extend__']:
  209. do_relink(self, None, input_map, in_out='INPUT', parent_name='Constant' )
  210. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  211. self.inputs.new('WildcardSocket', '', identifier='__extend__')
  212. do_relink(self, s, input_map, in_out='INPUT')
  213. for s in self.outputs:
  214. s.input= True
  215. self.initialized = True
  216. self.is_updating = False
  217. class SchemaOutgoingConnection(Node, SchemaUINode):
  218. '''Outgoing Connections'''
  219. bl_idname = 'SchemaOutgoingConnection'
  220. bl_label = "Outgoing Connection"
  221. bl_icon = 'GIZMO'
  222. mantis_node_class_name=bl_idname
  223. def init(self, context):
  224. self.update()
  225. def update(self):
  226. if self.is_updating:
  227. return
  228. self.is_updating = True
  229. self.initialized = False
  230. socket_maps = get_socket_maps(self)
  231. if socket_maps is None:
  232. return
  233. input_map = socket_maps[0]
  234. self.inputs.clear()
  235. for item in self.id_data.interface.items_tree:
  236. if item.item_type == 'PANEL': continue
  237. parent_name = read_schema_type(item)
  238. if item.in_out == 'OUTPUT' and parent_name == 'Connection':
  239. relink_socket_map(self, self.inputs, input_map, item, in_out='INPUT')
  240. if '__extend__' in input_map.keys() and input_map['__extend__']:
  241. do_relink(self, None, input_map, in_out='INPUT', parent_name='Connection' )
  242. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  243. self.inputs.new('WildcardSocket', '', identifier='__extend__')
  244. for s in self.outputs:
  245. s.input= True
  246. self.initialized = True
  247. self.is_updating = False
  248. class SchemaIncomingConnection(Node, SchemaUINode):
  249. '''Incoming Connections'''
  250. bl_idname = 'SchemaIncomingConnection'
  251. bl_label = "Incoming Connection"
  252. bl_icon = 'GIZMO'
  253. mantis_node_class_name=bl_idname
  254. def init(self, context):
  255. self.update()
  256. def update(self):
  257. if self.is_updating:
  258. return
  259. self.is_updating = True
  260. self.initialized = False
  261. socket_maps = get_socket_maps(self)
  262. if socket_maps is None:
  263. return
  264. output_map = socket_maps[1]
  265. self.outputs.clear()
  266. for item in self.id_data.interface.items_tree:
  267. if item.item_type == 'PANEL': continue
  268. parent_name = read_schema_type(item)
  269. if item.in_out == 'INPUT' and parent_name == 'Connection':
  270. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  271. if '__extend__' in output_map.keys() and output_map['__extend__']:
  272. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Connection' )
  273. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  274. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  275. self.initialized = True
  276. self.is_updating = False