schema_nodes.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. from .utilities.node_common import *
  2. from math import pi, tau
  3. from .base_definitions import MantisNode
  4. from .schema_nodes_socket_templates import *
  5. def TellClasses():
  6. return [
  7. SchemaIndex,
  8. SchemaArrayInput,
  9. SchemaArrayInputGet,
  10. SchemaArrayInputAll,
  11. SchemaArrayOutput,
  12. SchemaConstInput,
  13. SchemaConstOutput,
  14. SchemaOutgoingConnection,
  15. SchemaIncomingConnection,
  16. ]
  17. def schema_init_sockets(mantis_node, is_input = True, in_out='INPUT', category=''):
  18. from .utilities.utilities import tree_from_mantis_node, read_schema_type
  19. parent_tree = tree_from_mantis_node(mantis_node.signature, mantis_node.base_tree)
  20. if is_input:
  21. sockets=mantis_node.inputs
  22. else:
  23. sockets=mantis_node.outputs
  24. if category in ['Constant', 'Array', 'Connection']:
  25. for item in parent_tree.interface.items_tree:
  26. if item.item_type == 'PANEL': continue
  27. if item.parent and read_schema_type(item) == category:
  28. if item.in_out == in_out:
  29. sockets[item.name] = NodeSocket(is_input=is_input, name=item.name, node=mantis_node)
  30. class SchemaNode(MantisNode):
  31. __slots__ = ()
  32. node_type = 'SCHEMA'
  33. def __init__(self, signature, base_tree, socket_templates=[]):
  34. super().__init__(signature, base_tree, socket_templates)
  35. self.prepared = True; self.executed = True
  36. self.execution_prepared = True # should not affect execution!
  37. def reset_execution(self):
  38. super().reset_execution()
  39. self.prepared, self.executed = True, True
  40. raise RuntimeError( "43 Code thought to unreachable has been reached."
  41. f"Please report this as a bug. {self}")
  42. class SchemaIndex(SchemaNode):
  43. __slots__ = ()
  44. socket_templates = SchemaIndexSockets
  45. class SchemaArrayInput(SchemaNode):
  46. __slots__ = ()
  47. socket_templates = None
  48. def __init__(self, signature, base_tree):
  49. super().__init__(signature, base_tree)
  50. schema_init_sockets(self, is_input=False, in_out='INPUT', category='Array')
  51. class SchemaArrayInputGet(SchemaNode):
  52. __slots__ = ()
  53. socket_templates = None
  54. def __init__(self, signature, base_tree):
  55. super().__init__(signature, base_tree, SchemaArrayInputGetSockets)
  56. schema_init_sockets(self, is_input=False, in_out='INPUT', category='Array')
  57. class SchemaArrayInputAll(SchemaNode):
  58. __slots__ = ()
  59. socket_templates = None
  60. def __init__(self, signature, base_tree):
  61. super().__init__(signature, base_tree)
  62. schema_init_sockets(self, is_input=False, in_out='INPUT', category='Array')
  63. class SchemaArrayOutput(SchemaNode):
  64. __slots__ = ()
  65. socket_templates = None
  66. def __init__(self, signature, base_tree):
  67. super().__init__(signature, base_tree)
  68. schema_init_sockets(self, is_input=True, in_out='OUTPUT', category='Array')
  69. class SchemaConstInput(SchemaNode):
  70. __slots__ = ()
  71. socket_templates = None
  72. def __init__(self, signature, base_tree, parent_schema_node=None):
  73. super().__init__(signature, base_tree)
  74. if parent_schema_node:
  75. # this allows us to generate the Constant Input from a normal Node Group
  76. # and treat the node group as a schema
  77. parent_tree = parent_schema_node.ui_node.node_tree
  78. sockets=self.outputs
  79. for item in parent_tree.interface.items_tree:
  80. if item.item_type == 'PANEL': continue
  81. if item.in_out == 'INPUT':
  82. sockets[item.name] = NodeSocket(is_input=False, node=self, name=item.name)
  83. else:
  84. schema_init_sockets(self, is_input=False, in_out='INPUT', category='Constant')
  85. class SchemaConstOutput(SchemaNode):
  86. __slots__ = ()
  87. socket_templates = None
  88. def __init__(self, signature, base_tree, parent_schema_node=None):
  89. super().__init__(signature, base_tree)
  90. sockets=self.inputs
  91. sockets["Expose at Index"] = NodeSocket(is_input=False, node=self, name="Expose at Index")
  92. if parent_schema_node:
  93. # this allows us to generate the Constant Input from a normal Node Group
  94. # and treat the node group as a schema
  95. parent_tree = parent_schema_node.ui_node.node_tree
  96. for item in parent_tree.interface.items_tree:
  97. if item.item_type == 'PANEL': continue
  98. if item.in_out == 'OUTPUT':
  99. sockets[item.name] = NodeSocket(is_input=False, node=self, name=item.name)
  100. self.parameters['Expose at Index"']=1
  101. else:
  102. schema_init_sockets(self, is_input=True, in_out='OUTPUT', category='Constant')
  103. class SchemaOutgoingConnection(SchemaNode):
  104. __slots__ = ()
  105. socket_templates = None
  106. def __init__(self, signature, base_tree):
  107. super().__init__(signature, base_tree)
  108. schema_init_sockets(self, is_input=True, in_out='INPUT', category='Connection')
  109. class SchemaIncomingConnection(SchemaNode):
  110. __slots__ = ()
  111. def __init__(self, signature, base_tree):
  112. super().__init__(signature, base_tree)
  113. schema_init_sockets(self, is_input=False, in_out='OUTPUT', category='Connection')