schema_containers.py 4.7 KB

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