schema_nodes_ui.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. def init(self, context):
  36. self.init_sockets(SchemaIndexSockets)
  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.init_sockets(SchemaArrayInputGetSockets)
  107. self.update()
  108. def update(self):
  109. if self.is_updating:
  110. return
  111. self.is_updating = True
  112. self.initialized = False
  113. socket_maps = get_socket_maps(self)
  114. if socket_maps is None:
  115. return
  116. output_map = socket_maps[1]
  117. self.outputs.clear()
  118. for item in self.id_data.interface.items_tree:
  119. if item.item_type == 'PANEL': continue
  120. parent_name = read_schema_type(item)
  121. if item.in_out == 'INPUT' and parent_name == 'Array':
  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='Array' )
  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. self.is_updating = False
  129. class SchemaArrayOutput(Node, SchemaUINode):
  130. '''Array Inputs'''
  131. bl_idname = 'SchemaArrayOutput'
  132. bl_label = "Array Output"
  133. bl_icon = 'GIZMO'
  134. initialized : bpy.props.BoolProperty(default = False)
  135. mantis_node_class_name=bl_idname
  136. def init(self, context):
  137. self.update()
  138. def update(self):
  139. if self.is_updating:
  140. return
  141. self.is_updating = True
  142. self.initialized = False
  143. socket_maps = get_socket_maps(self)
  144. if socket_maps is None:
  145. return
  146. input_map = socket_maps[0]
  147. self.inputs.clear()
  148. for item in self.id_data.interface.items_tree:
  149. if item.item_type == 'PANEL': continue
  150. parent_name = read_schema_type(item)
  151. if item.in_out == 'OUTPUT' and parent_name == 'Array':
  152. relink_socket_map(self, self.inputs, input_map, item, in_out='INPUT')
  153. if '__extend__' in input_map.keys() and input_map['__extend__']:
  154. do_relink(self, None, input_map, in_out='INPUT', parent_name='Array' )
  155. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  156. self.inputs.new('WildcardSocket', '', identifier='__extend__')
  157. for s in self.outputs:
  158. s.input= True
  159. self.initialized = True
  160. self.is_updating = False
  161. class SchemaConstInput(Node, SchemaUINode):
  162. '''Constant Inputs'''
  163. bl_idname = 'SchemaConstInput'
  164. bl_label = "Constant Input"
  165. bl_icon = 'GIZMO'
  166. initialized : bpy.props.BoolProperty(default = False)
  167. mantis_node_class_name=bl_idname
  168. def init(self, context):
  169. self.update()
  170. def update(self):
  171. if self.is_updating:
  172. return
  173. self.is_updating = True
  174. self.initialized = False
  175. socket_maps = get_socket_maps(self)
  176. if socket_maps is None:
  177. return
  178. output_map = socket_maps[1]
  179. self.outputs.clear()
  180. for item in self.id_data.interface.items_tree:
  181. if item.item_type == 'PANEL': continue
  182. parent_name = read_schema_type(item)
  183. if item.in_out == 'INPUT' and parent_name == 'Constant':
  184. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  185. if '__extend__' in output_map.keys() and output_map['__extend__']:
  186. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Constant' )
  187. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  188. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  189. self.initialized = True
  190. self.is_updating = False
  191. class SchemaConstOutput(Node, SchemaUINode):
  192. '''Constant Outputs'''
  193. bl_idname = 'SchemaConstOutput'
  194. bl_label = "Constant Output"
  195. bl_icon = 'GIZMO'
  196. initialized : bpy.props.BoolProperty(default = False)
  197. mantis_node_class_name=bl_idname
  198. def init(self, context):
  199. self.update()
  200. def update(self):
  201. if self.is_updating:
  202. return
  203. self.is_updating = True
  204. self.initialized = False
  205. socket_maps = get_socket_maps(self)
  206. if socket_maps is None:
  207. return
  208. input_map = socket_maps[0]
  209. self.inputs.clear()
  210. s = self.inputs.new('UnsignedIntSocket', "Expose at Index")
  211. for item in self.id_data.interface.items_tree:
  212. if item.item_type == 'PANEL': continue
  213. parent_name = read_schema_type(item)
  214. if item.in_out == 'OUTPUT' and parent_name == 'Constant':
  215. relink_socket_map(self, self.inputs, input_map, item, in_out='INPUT')
  216. if '__extend__' in input_map.keys() and input_map['__extend__']:
  217. do_relink(self, None, input_map, in_out='INPUT', parent_name='Constant' )
  218. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  219. self.inputs.new('WildcardSocket', '', identifier='__extend__')
  220. do_relink(self, s, input_map, in_out='INPUT')
  221. for s in self.outputs:
  222. s.input= True
  223. self.initialized = True
  224. self.is_updating = False
  225. class SchemaOutgoingConnection(Node, SchemaUINode):
  226. '''Outgoing Connections'''
  227. bl_idname = 'SchemaOutgoingConnection'
  228. bl_label = "Outgoing Connection"
  229. bl_icon = 'GIZMO'
  230. initialized : bpy.props.BoolProperty(default = False)
  231. mantis_node_class_name=bl_idname
  232. def init(self, context):
  233. self.update()
  234. def update(self):
  235. if self.is_updating:
  236. return
  237. self.is_updating = True
  238. self.initialized = False
  239. socket_maps = get_socket_maps(self)
  240. if socket_maps is None:
  241. return
  242. input_map = socket_maps[0]
  243. self.inputs.clear()
  244. for item in self.id_data.interface.items_tree:
  245. if item.item_type == 'PANEL': continue
  246. parent_name = read_schema_type(item)
  247. if item.in_out == 'OUTPUT' and parent_name == 'Connection':
  248. relink_socket_map(self, self.inputs, input_map, item, in_out='INPUT')
  249. if '__extend__' in input_map.keys() and input_map['__extend__']:
  250. do_relink(self, None, input_map, in_out='INPUT', parent_name='Connection' )
  251. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  252. self.inputs.new('WildcardSocket', '', identifier='__extend__')
  253. for s in self.outputs:
  254. s.input= True
  255. self.initialized = True
  256. self.is_updating = False
  257. class SchemaIncomingConnection(Node, SchemaUINode):
  258. '''Incoming Connections'''
  259. bl_idname = 'SchemaIncomingConnection'
  260. bl_label = "Incoming Connection"
  261. bl_icon = 'GIZMO'
  262. initialized : bpy.props.BoolProperty(default = False)
  263. mantis_node_class_name=bl_idname
  264. def init(self, context):
  265. self.update()
  266. def update(self):
  267. if self.is_updating:
  268. return
  269. self.is_updating = True
  270. self.initialized = False
  271. socket_maps = get_socket_maps(self)
  272. if socket_maps is None:
  273. return
  274. output_map = socket_maps[1]
  275. self.outputs.clear()
  276. for item in self.id_data.interface.items_tree:
  277. if item.item_type == 'PANEL': continue
  278. parent_name = read_schema_type(item)
  279. if item.in_out == 'INPUT' and parent_name == 'Connection':
  280. relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
  281. if '__extend__' in output_map.keys() and output_map['__extend__']:
  282. do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Connection' )
  283. if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
  284. self.outputs.new('WildcardSocket', '', identifier='__extend__')
  285. self.initialized = True
  286. self.is_updating = False
  287. for cls in TellClasses():
  288. cls.set_mantis_class()