schema_containers.py 4.3 KB

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