schema_nodes_ui.py 12 KB

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