schema_nodes.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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.init_sockets([item.name])
  30. mantis_node.init_parameters()
  31. class SchemaNode(MantisNode):
  32. def __init__(self, signature, base_tree, socket_templates=[]):
  33. super().__init__(signature, base_tree, socket_templates)
  34. self.node_type = 'SCHEMA'
  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. def __init__(self, signature, base_tree):
  44. super().__init__(signature, base_tree, SchemaIndexSockets)
  45. self.init_parameters()
  46. class SchemaArrayInput(SchemaNode):
  47. def __init__(self, signature, base_tree):
  48. super().__init__(signature, base_tree)
  49. schema_init_sockets(self, is_input=False, in_out='INPUT', category='Array')
  50. class SchemaArrayInputGet(SchemaNode):
  51. def __init__(self, signature, base_tree):
  52. super().__init__(signature, base_tree, SchemaArrayInputGetSockets)
  53. schema_init_sockets(self, is_input=False, in_out='INPUT', category='Array')
  54. class SchemaArrayInputAll(SchemaNode):
  55. def __init__(self, signature, base_tree):
  56. super().__init__(signature, base_tree)
  57. schema_init_sockets(self, is_input=False, in_out='INPUT', category='Array')
  58. class SchemaArrayOutput(SchemaNode):
  59. def __init__(self, signature, base_tree):
  60. super().__init__(signature, base_tree)
  61. schema_init_sockets(self, is_input=True, in_out='OUTPUT', category='Array')
  62. class SchemaConstInput(SchemaNode):
  63. def __init__(self, signature, base_tree, parent_schema_node=None):
  64. super().__init__(signature, base_tree)
  65. if parent_schema_node:
  66. # this allows us to generate the Constant Input from a normal Node Group
  67. # and treat the node group as a schema
  68. parent_tree = parent_schema_node.ui_node.node_tree
  69. sockets=self.outputs
  70. for item in parent_tree.interface.items_tree:
  71. if item.item_type == 'PANEL': continue
  72. if item.in_out == 'INPUT':
  73. sockets.init_sockets([item.name])
  74. self.init_parameters()
  75. else:
  76. schema_init_sockets(self, is_input=False, in_out='INPUT', category='Constant')
  77. class SchemaConstOutput(SchemaNode):
  78. def __init__(self, signature, base_tree, parent_schema_node=None):
  79. super().__init__(signature, base_tree)
  80. inputs = [
  81. "Expose at Index",
  82. ]
  83. self.inputs.init_sockets(inputs)
  84. if parent_schema_node:
  85. # this allows us to generate the Constant Input from a normal Node Group
  86. # and treat the node group as a schema
  87. parent_tree = parent_schema_node.ui_node.node_tree
  88. sockets=self.inputs
  89. for item in parent_tree.interface.items_tree:
  90. if item.item_type == 'PANEL': continue
  91. if item.in_out == 'OUTPUT':
  92. sockets.init_sockets([item.name, "Expose at Index",])
  93. self.init_parameters()
  94. self.parameters['Expose at Index"']=1
  95. else:
  96. schema_init_sockets(self, is_input=True, in_out='OUTPUT', category='Constant')
  97. class SchemaOutgoingConnection(SchemaNode):
  98. def __init__(self, signature, base_tree):
  99. super().__init__(signature, base_tree)
  100. schema_init_sockets(self, is_input=True, in_out='INPUT', category='Connection')
  101. class SchemaIncomingConnection(SchemaNode):
  102. def __init__(self, signature, base_tree):
  103. super().__init__(signature, base_tree)
  104. schema_init_sockets(self, is_input=False, in_out='OUTPUT', category='Connection')