schema_nodes.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. mantis_node.init_parameters()
  31. class SchemaNode(MantisNode):
  32. __slots__ = ()
  33. node_type = 'SCHEMA'
  34. def __init__(self, signature, base_tree, socket_templates=[]):
  35. super().__init__(signature, base_tree, socket_templates)
  36. self.prepared = True; self.executed = True
  37. self.execution_prepared = True # should not affect execution!
  38. def reset_execution(self):
  39. super().reset_execution()
  40. self.prepared, self.executed = True, True
  41. raise RuntimeError( "43 Code thought to unreachable has been reached."
  42. f"Please report this as a bug. {self}")
  43. class SchemaIndex(SchemaNode):
  44. __slots__ = ()
  45. def __init__(self, signature, base_tree):
  46. super().__init__(signature, base_tree, SchemaIndexSockets)
  47. self.init_parameters()
  48. class SchemaArrayInput(SchemaNode):
  49. __slots__ = ()
  50. def __init__(self, signature, base_tree):
  51. super().__init__(signature, base_tree)
  52. schema_init_sockets(self, is_input=False, in_out='INPUT', category='Array')
  53. class SchemaArrayInputGet(SchemaNode):
  54. __slots__ = ()
  55. def __init__(self, signature, base_tree):
  56. super().__init__(signature, base_tree, SchemaArrayInputGetSockets)
  57. schema_init_sockets(self, is_input=False, in_out='INPUT', category='Array')
  58. class SchemaArrayInputAll(SchemaNode):
  59. __slots__ = ()
  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. def __init__(self, signature, base_tree):
  66. super().__init__(signature, base_tree)
  67. schema_init_sockets(self, is_input=True, in_out='OUTPUT', category='Array')
  68. class SchemaConstInput(SchemaNode):
  69. __slots__ = ()
  70. def __init__(self, signature, base_tree, parent_schema_node=None):
  71. super().__init__(signature, base_tree)
  72. if parent_schema_node:
  73. # this allows us to generate the Constant Input from a normal Node Group
  74. # and treat the node group as a schema
  75. parent_tree = parent_schema_node.ui_node.node_tree
  76. sockets=self.outputs
  77. for item in parent_tree.interface.items_tree:
  78. if item.item_type == 'PANEL': continue
  79. if item.in_out == 'INPUT':
  80. sockets[item.name] = NodeSocket(is_input=False, node=self, name=item.name)
  81. self.init_parameters()
  82. else:
  83. schema_init_sockets(self, is_input=False, in_out='INPUT', category='Constant')
  84. class SchemaConstOutput(SchemaNode):
  85. __slots__ = ()
  86. def __init__(self, signature, base_tree, parent_schema_node=None):
  87. super().__init__(signature, base_tree)
  88. sockets=self.inputs
  89. sockets["Expose at Index"] = NodeSocket(is_input=False, node=self, name="Expose at Index")
  90. if parent_schema_node:
  91. # this allows us to generate the Constant Input from a normal Node Group
  92. # and treat the node group as a schema
  93. parent_tree = parent_schema_node.ui_node.node_tree
  94. for item in parent_tree.interface.items_tree:
  95. if item.item_type == 'PANEL': continue
  96. if item.in_out == 'OUTPUT':
  97. sockets[item.name] = NodeSocket(is_input=False, node=self, name=item.name)
  98. self.init_parameters()
  99. self.parameters['Expose at Index"']=1
  100. else:
  101. schema_init_sockets(self, is_input=True, in_out='OUTPUT', category='Constant')
  102. class SchemaOutgoingConnection(SchemaNode):
  103. __slots__ = ()
  104. def __init__(self, signature, base_tree):
  105. super().__init__(signature, base_tree)
  106. schema_init_sockets(self, is_input=True, in_out='INPUT', category='Connection')
  107. class SchemaIncomingConnection(SchemaNode):
  108. __slots__ = ()
  109. def __init__(self, signature, base_tree):
  110. super().__init__(signature, base_tree)
  111. schema_init_sockets(self, is_input=False, in_out='OUTPUT', category='Connection')