public void AddEdge(EdgeView edgeView)
 {
     if (edgeView.FirstPort.Node == this)
     {
         SerializedProperty outportsProp   = SerializedNode.FindPropertyRelative(ANode.OutportsVarName);
         SerializedProperty newOutportProp = outportsProp.GetArrayElementAtIndex(edgeView.FirstPort.PortIndex);
         newOutportProp.FindPropertyRelative(OutportEdge.ConnectedNodeIdVarName).stringValue = edgeView.SecondPort.Node.NodeId;
         newOutportProp.serializedObject.ApplyModifiedProperties();
         edgeView.OutportEdgeProp = newOutportProp;
     }
     AddEdgeView(edgeView);
 }
        public EdgeView GetEdgeViewById(string id)
        {
            EdgeView edgeView = null;

            foreach (NodeView nodeView in m_nodeViews.Values)
            {
                edgeView = nodeView.GetEdgeViewById(id);
                if (edgeView != null)
                {
                    return(edgeView);
                }
            }
            return(null);
        }
 public void AddEdgeView(EdgeView edgeView)
 {
     if (edgeView.FirstPort.Node == this)
     {
         m_edgeViews.Add(edgeView.EdgeId, edgeView);
         edgeView.FirstPort.Connect(edgeView);
         edgeView.SecondPort.Node.AddEdgeView(edgeView);
         m_nodeGraphView.Add(edgeView);
     }
     else if (edgeView.SecondPort.Node == this)
     {
         edgeView.SecondPort.Connect(edgeView);
     }
 }
 public void RemoveEdge(EdgeView edgeView)
 {
     if (edgeView.FirstPort.Node == this)
     {
         edgeView.FirstPort.Disconnect(edgeView);
         edgeView.SecondPort.Node.RemoveEdge(edgeView);
         m_nodeGraphView.RemoveElement(edgeView);
         m_edgeViews.Remove(edgeView.EdgeId);
         OutportEdge.SetInvalid(SerializedNode.FindPropertyRelative(ANode.OutportsVarName)
                                .GetArrayElementAtIndex(edgeView.FirstPort.PortIndex));
     }
     else if (edgeView.SecondPort.Node == this)
     {
         edgeView.SecondPort.Disconnect(edgeView);
     }
 }
        public void CreateEdgeView(EdgeView edgeView)
        {
            if (edgeView?.input == null || edgeView?.output == null)
            {
                return;
            }

            Undo.RegisterCompleteObjectUndo(NodeGraph, "Created New Edge");
            edgeView.Setup();

            NodeView firstNode = edgeView.FirstPort.Node;

            // Outports can only have one edge connected to them.
            if (firstNode.OutportHasEdge(edgeView.FirstPort.PortIndex))
            {
                firstNode.RemoveEdge(firstNode.GetEdgeViewByPortIndex(edgeView.FirstPort.PortIndex));
            }

            edgeView.FirstPort.Node.AddEdge(edgeView);
            m_nodeListProp.serializedObject.Update();
        }
 public void SetSelection(List <string> graphElementIds)
 {
     ClearSelection();
     for (int i = 0; i < graphElementIds.Count; i++)
     {
         NodeView nodeView = GetNodeViewById(graphElementIds[i]);
         if (nodeView != null)
         {
             AddToSelection(nodeView);
         }
         else
         {
             //its an edge
             EdgeView edgeView = GetEdgeViewById(graphElementIds[i]);
             if (edgeView != null)
             {
                 AddToSelection(edgeView);
                 edgeView.RetainSelected = true; // Bandaid to Unity bug. See EdgeView.cs
             }
         }
     }
 }
        public void OnLoadView()
        {
            m_nodeGraphView.OnBlackboardElementChanged += HandleOnBlackboardElementChanged;

            SerializedProperty outports = SerializedNode.FindPropertyRelative(ANode.OutportsVarName);

            for (int k = 0; k < outports.arraySize; k++)
            {
                SerializedProperty outportProp = outports.GetArrayElementAtIndex(k);
                if (!OutportEdge.IsValid(outportProp))
                {
                    continue;
                }
                EdgeView edgeView = new EdgeView()
                {
                    OutportEdgeProp = outportProp,
                    input           = m_nodeGraphView.GetNodeViewById(outportProp.FindPropertyRelative(OutportEdge.ConnectedNodeIdVarName).stringValue).m_inport,
                    output          = m_outports[k],
                };
                edgeView.Setup();
                AddEdgeView(edgeView);
            }
        }
 private GraphViewChange OnGraphViewChanged(GraphViewChange graphViewChange)
 {
     if (graphViewChange.elementsToRemove != null)
     {
         int group = Undo.GetCurrentGroup();
         Undo.RegisterCompleteObjectUndo(NodeGraph, "Deleted Graph Elements");
         List <NodeView> nodeViewsToDelete = new List <NodeView>();
         for (int i = graphViewChange.elementsToRemove.Count - 1; i >= 0; i--)
         {
             if (graphViewChange.elementsToRemove[i] is NodeView)
             {
                 nodeViewsToDelete.Add(graphViewChange.elementsToRemove[i] as NodeView);
             }
             else if (graphViewChange.elementsToRemove[i] is EdgeView)
             {
                 EdgeView edgeView = graphViewChange.elementsToRemove[i] as EdgeView;
                 edgeView.FirstPort.Node.RemoveEdge(edgeView);
             }
         }
         DeleteNodes(nodeViewsToDelete);
         Undo.CollapseUndoOperations(group);
     }
     else if (graphViewChange.movedElements != null)
     {
         int group = Undo.GetCurrentGroup();
         Undo.RegisterCompleteObjectUndo(NodeGraph, "Moved Graph Elements");
         for (int k = 0; k < graphViewChange.movedElements.Count; k++)
         {
             if (graphViewChange.movedElements[k] is NodeView)
             {
                 (graphViewChange.movedElements[k] as NodeView).UpdateNodeDataPosition();
             }
         }
         Undo.CollapseUndoOperations(group);
     }
     return(graphViewChange);
 }