internal_containers.py 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. from .node_container_common import *
  2. from bpy.types import Node
  3. from .base_definitions import MantisNode, MantisSocketTemplate
  4. from uuid import uuid4
  5. class DummyNode(MantisNode):
  6. def __init__(self, signature, base_tree, prototype = None, ui_signature=None):
  7. super().__init__(signature, base_tree)
  8. self.prototype = prototype
  9. self.node_type = 'DUMMY'
  10. self.prepared = True
  11. self.uuid = uuid4()
  12. self.solver = None
  13. self.did_set_variables = False
  14. if prototype:
  15. if prototype.bl_idname in ["MantisSchemaGroup"]:
  16. self.node_type = 'DUMMY_SCHEMA'
  17. self.prepared = False
  18. for sock in prototype.inputs:
  19. if sock.identifier == "__extend__" or sock.name == "__extend__":
  20. continue
  21. self.inputs[sock.identifier] = NodeSocket(is_input = True, name = sock.identifier, node = self)
  22. for sock in prototype.outputs:
  23. if sock.identifier == "__extend__" or sock.name == "__extend__":
  24. continue
  25. self.outputs[sock.identifier] = NodeSocket(is_input = False, name = sock.identifier, node = self)
  26. self.parameters[sock.identifier]=None
  27. # keep track of the "natural signature" of Schema nodes - so that they are unambiguous
  28. self.ui_signature=self.signature
  29. if ui_signature:
  30. self.ui_signature=ui_signature
  31. # This is necessary for Schema to work if there are multiple Schema nodes using the same Schema tree.
  32. # this is ugly and I hate it.
  33. self.execution_prepared=True # in case it gets left behind in the tree as a dependency
  34. def bPrepare(self, bContext=None):
  35. from .utilities import set_string_variables_during_exec
  36. set_string_variables_during_exec(self, self.mContext)
  37. self.did_set_variables = True # I just need to know if this is getting them all
  38. def __del__(self):
  39. print (self, self.did_set_variables)
  40. class NoOpNode(MantisNode):
  41. def __init__(self, signature, base_tree):
  42. super().__init__(signature, base_tree)
  43. self.inputs.init_sockets(["Input"])
  44. self.outputs.init_sockets(["Output"])
  45. self.init_parameters()
  46. self.set_traverse([("Input", "Output")])
  47. self.node_type = 'UTILITY'
  48. self.prepared, self.executed = True, True
  49. self.execution_prepared=True
  50. # this node is useful for me to insert in the tree and use for debugging especially connections.
  51. class AutoGenNode(MantisNode):
  52. def __init__(self, signature, base_tree):
  53. super().__init__(signature, base_tree)
  54. self.node_type = 'UTILITY'
  55. self.prepared, self.executed = True, True
  56. self.execution_prepared=True
  57. def reset_execution(self):
  58. super().reset_execution()
  59. self.prepared, self.executed = True, True
  60. # The Group Interface node is responsible for gathering node connections
  61. # going in or out of the group and connecting back out the other side
  62. # this is also where caching and overlays live
  63. class GroupInterface(MantisNode):
  64. def __init__(self, signature, base_tree, prototype, in_out):
  65. super().__init__(signature, base_tree)
  66. self.node_type = 'UTILITY'
  67. self.prepared, self.executed = True, True; sockets = []
  68. self.in_out = in_out
  69. # init the sockets based on in/out, then set up traversal
  70. collection = prototype.inputs if in_out == 'INPUT' else prototype.outputs
  71. for socket in collection: sockets.append(socket.identifier)
  72. self.inputs.init_sockets(sockets); self.outputs.init_sockets(sockets)
  73. for socket in self.inputs.keys(): self.set_traverse( [(socket, socket)] )
  74. self.execution_prepared=True