Browse Source

Fix: parse error when autogen-input is deleted

Joseph Brandenburg 5 months ago
parent
commit
686e43b6d4
3 changed files with 28 additions and 16 deletions
  1. 4 1
      base_definitions.py
  2. 10 1
      internal_containers.py
  3. 14 14
      readtree.py

+ 4 - 1
base_definitions.py

@@ -113,7 +113,7 @@ class MantisTree(NodeTree):
         if self.is_exporting:
             return
         my_hash = str( hash_tree(self) )
-        if my_hash != self.hash or force:
+        if (my_hash != self.hash) or force:
             self.hash = my_hash
             self.is_executing = True
             from . import readtree
@@ -647,6 +647,9 @@ def can_remove_socket_for_autogen(node, socket) -> bool:
     """ Whether to enable socket removal optimization for the socket
         This should be disallowed if e.g. it is a custom property.
     """
+    return False # for now! This doesn't seem to be working...
+    # the problem is that Schema does this, and so does Readtree
+    # and they can try and both do it. That's bad.
     if node.socket_templates:
         for s_template in node.socket_templates:
             if s_template.name == socket:

+ 10 - 1
internal_containers.py

@@ -43,5 +43,14 @@ class NoOpNode(MantisNode):
         self.node_type = 'UTILITY'
         self.prepared = True
         self.executed = True
-    
     # this node is useful for me to insert in the tree and use for debugging especially connections.
+
+class AutoGenNode(MantisNode):
+    def __init__(self, signature, base_tree):
+        super().__init__(signature, base_tree)
+        self.node_type = 'UTILITY'
+        self.prepared, self.executed = True, True
+    
+    def reset_execution(self):
+        super().reset_execution()
+        self.prepared, self.executed = True, True

+ 14 - 14
readtree.py

@@ -98,39 +98,39 @@ from .base_definitions import replace_types, NodeSocket
 def autogen_node(base_tree, ui_socket, signature, mContext):
     mantis_node=None
     from .utilities import  gen_nc_input_for_data
-    nc_cls = gen_nc_input_for_data(ui_socket)
-    if (nc_cls):
-        mantis_node = nc_cls(signature, base_tree)
-        mantis_node.mContext = mContext
-        mantis_node.execution_prepared=True
-        mantis_node.outputs.init_sockets([ui_socket.name])
-        mantis_node.ui_signature = None # does not exist in the UI
+    # nc_cls = gen_nc_input_for_data(ui_socket)
+    # if (nc_cls):
+    from .internal_containers import AutoGenNode
+    mantis_node = AutoGenNode(signature, base_tree)
+    mantis_node.mContext = mContext
+    mantis_node.outputs.init_sockets([ui_socket.name])
+    mantis_node.ui_signature = None # does not exist in the UI
     return mantis_node
 
 # TODO: investigate whether I can set the properties in the downstream nodes directly.
 #       I am doing this in Schema Solver and it seems to work quite efficiently.
 def make_connections_to_ng_dummy(base_tree, tree_path_names, local_nc, all_nc, nc_to):
-    np = nc_to.prototype
-    for inp in np.inputs:
+    from .socket_definitions import no_default_value
+    for inp in nc_to.prototype.inputs:
+        if inp.bl_idname in no_default_value:
+            continue
         nc_from = None
-        if inp.bl_idname in  ['WildcardSocket']:
-            continue # it isn't a real input so I don't think it is good to check it.
         to_s = inp.identifier
         if not inp.is_linked: # make an autogenerated NC for the inputs of the group node
             # This can be run inside schema. Make it unique with uuid() to be safe.
             from uuid import uuid4
-            signature = ("MANTIS_AUTOGENERATED", *tree_path_names, np.name, inp.name, inp.identifier, str(uuid4()))
+            signature = ("MANTIS_AUTOGENERATED", *tree_path_names, nc_to.ui_signature[-1], inp.name, inp.identifier, str(uuid4()))
             nc_from = all_nc.get(signature) # creating this without checking and
             #  using UUID signature leads to TERRIBLE CONFUSING BUGS.
             if nc_from is None: 
                 nc_from = autogen_node(base_tree, inp, signature, nc_to.mContext)
+            from .node_container_common import get_socket_value
             if nc_from: # autogen can fail and we should catch it.
-                from .node_container_common import get_socket_value
                 nc_from.parameters = {inp.name:get_socket_value(inp)}
                 local_nc[signature] = nc_from; all_nc[signature] = nc_from
                 nc_from.outputs[inp.name].connect(node=nc_to, socket=to_s, sort_id=0)
             else:
-                prRed("No available auto-generated class for input", *tree_path_names, inp.name, np.name)
+                prRed("No available auto-generated class for input %s in %s" % (inp.name, np.name))
 
 def gen_node_containers(base_tree, current_tree, tree_path_names, all_nc, local_nc, dummy_nodes, group_nodes, schema_nodes ):
     from .internal_containers import DummyNode