Exemple #1
0
 public GraphNode(int GUID, string searchString, GraphNodeView view)
 {
     Type                 = NodeType.Link;
     View                 = view;
     LinkGUID             = GUID;
     OriginalSearchString = searchString;
     MDDocument           = new FlowDocument();
     Ref = null;
 }
Exemple #2
0
 public GraphNode(GraphNode refNode, GraphNodeView view)
 {
     Type       = NodeType.Jumper;
     Title      = string.Empty;
     View       = view;
     Content    = string.Empty;
     MDDocument = new FlowDocument();    // Notice the default value for this variable isn't null which isn't very economical
     Ref        = refNode;
 }
Exemple #3
0
 public GraphNode(string title, GraphNodeView view)
 {
     Type       = NodeType.SimpleText;
     Title      = title;
     View       = view;
     Content    = string.Empty;
     MDDocument = new FlowDocument();
     Ref        = null;
 }
Exemple #4
0
        internal GraphNodeControl(GraphNodeView view, GraphLayer manager)
        {
            View             = view; // The visual element of the view is this
            Node             = view.Node;
            _OwnerGraphLayer = manager;
            InitializeComponent();

            // Initialize resources
            if (bResourceInitialized == false)
            {
                JumperImageStyle         = NodeImage.FindResource("JumperStyleImage") as Style;
                TextNodeStyle            = this.FindResource("TextNode") as Style;
                TextNodeHighLightStyle   = this.FindResource("TextNodeHighlight") as Style;
                ImageNodeStyle           = this.FindResource("ImageNode") as Style;
                ImageNodeHighLightStyle  = this.FindResource("ImageNodeHighlight") as Style;
                JumperNodeStyle          = this.FindResource("JumperNode") as Style;
                JumperNodeHighlightStyle = this.FindResource("JumperNodeHighlight") as Style;
                bResourceInitialized     = true;
            }

            // Switch Style
            switch (Node.Type)
            {
            case NodeType.SimpleText:
                // Do nothing more setup, default assumed
                // Show
                NodeTextExpander.Visibility = Visibility.Visible;
                break;

            case NodeType.Link:
                SetupInterfaceForLink();
                break;

            case NodeType.RichFlowText:
                SetupInterfaceForFlowText();
                break;

            case NodeType.Jumper:
                SetupInterfaceForJumper();
                break;
            }
        }
Exemple #5
0
        protected virtual void RemoveNodeWithEdges(GraphNodeView nodeView)
        {
            var inputPortViews  = nodeView.inputPortViews;
            var outputPortViews = nodeView.outputPortViews;

            for (int i = 0; i < inputPortViews.Count; i++)
            {
                var edges = inputPortViews[i].GetEdges();
                for (int j = 0; j < edges.Count; j++)
                {
                    RemoveElement(edges[j]);
                }
            }
            for (int i = 0; i < outputPortViews.Count; i++)
            {
                var edges = outputPortViews[i].GetEdges();
                for (int j = 0; j < edges.Count; j++)
                {
                    RemoveElement(edges[j]);
                }
            }
            graph.RemoveNode(nodeView.nodeTarget);
            RemoveElement(nodeView);
        }
Exemple #6
0
        public GraphNode(GraphNodeView view, NodeType type = NodeType.RichFlowText)
        {
            Type = type;
            switch (type)
            {
            case NodeType.SimpleText:
                Title   = "Default Node";
                Content = string.Empty;
                break;

            case NodeType.Link:
                throw new InvalidOperationException("Link type graph nodes should call another constructor.");

            case NodeType.RichFlowText:
                MDDocument = new FlowDocument();
                break;

            case NodeType.Jumper:
                throw new InvalidOperationException("Jumper type graph nodes should call another constructor.");
            }
            MDDocument = new FlowDocument();
            Ref        = null;
            View       = view;
        }
Exemple #7
0
        private void AddSelectionsToSubGraph(Vector2 position)
        {
            RegisterCompleteObjectUndo("SubGraph");

            var cGraph = graph as ConvertGraph;

            var newGraph = ScriptableObject.CreateInstance <SubGraph>();
            var newNode  = BaseNode.CreateFromType(typeof(SubGraphNode), position) as SubGraphNode;

            var selectedNodeSet   = new HashSet <string>();
            var selectedNodeViews = new List <GraphNodeView>();

            int inputIndex = 0, outputIndex = 0;
            var inputEdges  = new List <Tuple <SerializableEdge, string> >();
            var outputEdges = new List <Tuple <SerializableEdge, string> >();
            var edgeMap     = new Dictionary <string, List <SerializableEdge> >();

            for (int i = 0; i < selection.Count; i++)
            {
                ISelectable selectItem = selection[i];
                if (selectItem is ConvertNodeView graphNodeView)
                {
                    selectedNodeViews.Add(graphNodeView);
                    selectedNodeSet.Add(graphNodeView.nodeTarget.GUID);
                }
                else if (selectItem is SourceNodeView sourceNodeView)
                {
                    Debug.LogWarning("You can't subgraph your source node");
                    selection.Clear();
                    return;
                }
            }

            for (int i = 0; i < selectedNodeViews.Count; i++)
            {
                GraphNodeView selectItem = selectedNodeViews[i];
                var           cNode      = selectItem.nodeTarget as ConvertNode;

                edgeMap.Clear();
                var iEdges = cNode.GetInputEdges();
                foreach (var edge in iEdges)
                {
                    if (!edgeMap.ContainsKey(edge.outputNodeGUID))
                    {
                        edgeMap[edge.outputNodeGUID] = new List <SerializableEdge>();
                    }
                    edgeMap[edge.outputNodeGUID].Add(edge);
                }


                var inputNodes = cNode.GetInputNodes();
                foreach (var inputNode in inputNodes)
                {
                    if (!selectedNodeSet.Contains(inputNode.GUID))
                    {
                        var parameterInfos = cNode.ParameterInfos;
                        var index          = inputIndex;
                        foreach (var parameterInfo in parameterInfos)
                        {
                            if (!parameterInfo.IsOut)
                            {
                                newNode.AddInputPorData(new SerialPortData
                                {
                                    displayName = parameterInfo.Name,
                                    displayType = new TypeInfo(parameterInfo.ParameterType),
                                    identifier  = inputIndex.ToString(),
                                    guid        = $"{inputNode.GUID}-{(inputIndex - index).ToString()}",
                                    position    = new Vector2(cNode.position.x - (24 + 8) * 10, cNode.position.y + inputIndex * 24 * 10),
                                });
                                inputIndex++;
                            }
                        }

                        var list = edgeMap[inputNode.GUID];
                        for (int j = 0; j < list.Count; j++)
                        {
                            inputEdges.Add(new Tuple <SerializableEdge, string>(list[j], (Convert.ToInt32(list[j].inputPortIdentifier) + index).ToString()));
                        }

                        // PLAN Default Nodes (empty input)
                    }
                }


                edgeMap.Clear();
                var oEdges = cNode.GetOutputEdges();
                foreach (var edge in oEdges)
                {
                    if (!edgeMap.ContainsKey(edge.inputNodeGUID))
                    {
                        edgeMap[edge.inputNodeGUID] = new List <SerializableEdge>();
                    }
                    edgeMap[edge.inputNodeGUID].Add(edge);
                }

                var outputNodes = cNode.GetOutputNodes();
                foreach (var outputNode in outputNodes)
                {
                    if (!selectedNodeSet.Contains(outputNode.GUID))
                    {
                        int index          = outputIndex;
                        var parameterInfos = cNode.ParameterInfos;
                        foreach (var parameterInfo in parameterInfos)
                        {
                            if (parameterInfo.IsOut)
                            {
                                newNode.AddOutputPorData(new SerialPortData
                                {
                                    displayName = parameterInfo.Name,
                                    displayType = new TypeInfo(parameterInfo.ParameterType.GetElementType()),
                                    identifier  = outputIndex.ToString(),
                                    guid        = $"{outputNode.GUID}-{(outputIndex - index).ToString()}",
                                    position    = new Vector2(cNode.position.x + (24 + 8 * 10), cNode.position.y + outputIndex * 24 * 10),
                                });
                                outputIndex++;
                            }
                        }
                        var list = edgeMap[outputNode.GUID];
                        for (int j = 0; j < list.Count; j++)
                        {
                            outputEdges.Add(new Tuple <SerializableEdge, string>(list[j], (Convert.ToInt32(list[j].outputPortIdentifier) + index).ToString()));
                        }
                    }
                }
            }

            string path = EditorUtility.SaveFilePanel(
                "Save your convert graph",
                "",
                "NewConverterSubGraph",
                "asset"
                );

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            path = $"Assets{path.Substring(Application.dataPath.Length)}";
            AssetDatabase.CreateAsset(newGraph, path);

            newNode.subGraphGUID = AssetDatabase.AssetPathToGUID(path);
            AddNode(newNode);

            var delayConnectEdgeViews = new List <EdgeView>();

            for (int i = 0; i < inputEdges.Count; i++)
            {
                var inputEdge     = inputEdges[i].Item1;
                var oldOutputNode = inputEdge.outputNode;
                var outputPort    = oldOutputNode.GetPort(inputEdge.outputPort.fieldName, inputEdge.outputPortIdentifier);
                var inputPort     = newNode.GetPort(nameof(newNode.inputValue), inputEdges[i].Item2.ToString());
                var newEdge       = SerializableEdge.CreateNewEdge(newGraph, inputPort, outputPort);

                if (nodeViewsPerNode.ContainsKey(oldOutputNode) && nodeViewsPerNode.ContainsKey(newNode))
                {
                    var edgeView = new EdgeView()
                    {
                        userData = newEdge,
                        input    = nodeViewsPerNode[newNode].GetPortViewFromFieldName(newEdge.inputFieldName, newEdge.inputPortIdentifier),
                        output   = nodeViewsPerNode[oldOutputNode].GetPortViewFromFieldName(newEdge.outputFieldName, newEdge.outputPortIdentifier)
                    };
                    Connect(edgeView);
                }
            }

            for (int i = 0; i < outputEdges.Count; i++)
            {
                var outputEdge   = outputEdges[i].Item1;
                var oldInputNode = outputEdge.inputNode;
                var inputPort    = oldInputNode.GetPort(outputEdge.inputPort.fieldName, outputEdge.inputPortIdentifier);
                var outputPort   = newNode.GetPort(nameof(newNode.outputValue), outputEdges[i].Item2.ToString());
                var newEdge      = SerializableEdge.CreateNewEdge(newGraph, inputPort, outputPort);

                if (nodeViewsPerNode.ContainsKey(oldInputNode) && nodeViewsPerNode.ContainsKey(newNode))
                {
                    var edgeView = new EdgeView()
                    {
                        userData = newEdge,
                        input    = nodeViewsPerNode[oldInputNode].GetPortViewFromFieldName(newEdge.inputFieldName, newEdge.inputPortIdentifier),
                        output   = nodeViewsPerNode[newNode].GetPortViewFromFieldName(newEdge.outputFieldName, newEdge.outputPortIdentifier)
                    };
                    delayConnectEdgeViews.Add(edgeView);
                }
            }

            string copyDatas = SerialzieSubGraphElements(selection.OfType <GraphElement>(), inputEdges.Select(v => v.Item1).Concat(outputEdges.Select(v => v.Item1)));

            for (int i = 0; i < selectedNodeViews.Count; i++)
            {
                RemoveNodeWithEdges(selectedNodeViews[i]);
            }

            // Reconnect
            for (int i = 0; i < delayConnectEdgeViews.Count; i++)
            {
                Connect(delayConnectEdgeViews[i]);
            }

            if (CanPasteSerializedDataCallback(copyDatas))
            {
                var subGraphWindow = EditorWindow.GetWindow <SubGraphWindow>();
                subGraphWindow.serialData   = copyDatas;
                subGraphWindow.oldGUIDs     = selectedNodeViews.Select(s => s.nodeTarget.GUID).ToList();
                subGraphWindow.subGraphNode = newNode;
                subGraphWindow.InitializeGraph(newGraph);
            }
        }