schema_containers.py 4.6 KB

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