Beispiel #1
0
        private void Iterate(MyNodeGroup group, bool recursive, bool includeIONodes, IteratorAction action)
        {
            if (includeIONodes)
            {
                foreach (MyNode inputNode in group.GroupInputNodes)
                {
                    action(inputNode);
                }

                foreach (MyNode outputNode in group.GroupOutputNodes)
                {
                    action(outputNode);
                }
            }

            foreach (MyNode childNode in group.Children)
            {
                action(childNode);

                if (recursive && childNode is MyNodeGroup)
                {
                    Iterate(childNode as MyNodeGroup, recursive, includeIONodes, action);
                }
            }
        }
Beispiel #2
0
        private void PrepareConnections(MyNodeGroup nodeGroup)
        {
            foreach (MyOutput outputNode in nodeGroup.GroupOutputNodes)
            {
                PrepareConnections(outputNode);
            }

            foreach (MyNode node in nodeGroup.Children)
            {
                PrepareConnections(node);
            }
        }
Beispiel #3
0
 private static void TrySetParent(MyNode node, MyNodeGroup nodeGroup, bool showWarning = true)
 {
     try
     {
         // Setting parent may fail since v0.4. Handle it to allow loading of old [incorrect] projects.
         node.Parent = nodeGroup;
     }
     catch (InvalidOperationException e)
     {
         // TODO(HonzaS): Remove the switch - this is here only for copy+paste to work with neural layers
         if (showWarning)
         {
             MyLog.ERROR.WriteLine("Unable to update node ({0}): {1}", node.Name, e.Message);
         }
     }
 }
Beispiel #4
0
        public void AppendGroupContent(MyNodeGroup group)
        {
            foreach (MyNode childNode in group.Children)
            {
                //take only non-IO nodes
                if (!(childNode is MyParentInput || childNode is MyOutput))
                {
                    //generate new ID
                    bool hasDefaultName = childNode.Name.Equals(childNode.DefaultName);

                    childNode.Id = Owner.GenerateNodeId();

                    if (hasDefaultName)
                    {
                        childNode.Name = childNode.DefaultName;
                    }

                    //disconnect possible group inputs
                    foreach (MyConnection c in childNode.InputConnections)
                    {
                        if (c != null && c.From is MyParentInput)
                        {
                            c.Disconnect();
                        }
                    }

                    //dive into child groups and correct IDs
                    if (childNode is MyNodeGroup)
                    {
                        (childNode as MyNodeGroup).Iterate(true, true, delegate(MyNode node)
                        {
                            node.Id = Owner.GenerateNodeId();
                        });
                    }

                    Children.Add(childNode);
                    childNode.Parent = this;
                    childNode.Owner  = this.Owner;
                }
            }
        }
Beispiel #5
0
        private int CollectNodesAndUpdate(MyNodeGroup nodeGroup, Dictionary <int, MyNode> nodes, int topId)
        {
            foreach (MyParentInput inputNode in nodeGroup.GroupInputNodes)
            {
                nodes[inputNode.Id] = inputNode;
                inputNode.Parent    = nodeGroup;
                inputNode.Owner     = Owner;

                if (topId < inputNode.Id)
                {
                    topId = inputNode.Id;
                }
            }

            foreach (MyOutput outputNode in nodeGroup.GroupOutputNodes)
            {
                nodes[outputNode.Id] = outputNode;
                outputNode.Parent    = nodeGroup;
                outputNode.Owner     = Owner;

                if (topId < outputNode.Id)
                {
                    topId = outputNode.Id;
                }
            }

            foreach (MyNode node in nodeGroup.Children)
            {
                nodes[node.Id] = node;

                //parent link
                node.Parent = nodeGroup;
                node.Owner  = Owner;
                //topId collect
                if (topId < node.Id)
                {
                    topId = node.Id;
                }

                //task owner update
                if (node is MyWorkingNode)
                {
                    (node as MyWorkingNode).FinalizeTasksDeserialization();
                }

                if (node is MyNodeGroup)
                {
                    topId = CollectNodesAndUpdate(node as MyNodeGroup, nodes, topId);
                }

                //obsolete check
                MyObsoleteAttribute obsolete = node.GetType().GetCustomAttribute <MyObsoleteAttribute>(true);
                if (obsolete != null)
                {
                    string message = "You are using obsolete node type (" + node.GetType().Name + ") ";
                    if (obsolete.ReplacedBy != null)
                    {
                        message += "Use " + obsolete.ReplacedBy.Name + " instead.";
                    }
                    MyLog.WARNING.WriteLine(message);
                }
            }
            return(topId);
        }