schema_nodes.py 4.9 KB

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