public Edge CreateGhostEdge(IGTFGraphModel graphModel) { GhostEdgeModel ghostEdge; if (m_GhostEdgeViewModelCreator != null) { ghostEdge = m_GhostEdgeViewModelCreator.Invoke(graphModel); } else { ghostEdge = new GhostEdgeModel(graphModel); } var ui = ghostEdge.CreateUI <Edge>(GraphView, m_Store); return(ui); }
void ClearEdgeCandidate() { m_EdgeCandidateModel = null; m_EdgeCandidate = null; }
public void CreateEdgeCandidate(IGTFGraphModel graphModel) { m_EdgeCandidate = CreateGhostEdge(graphModel); m_EdgeCandidateModel = m_EdgeCandidate.EdgeModel as GhostEdgeModel; }
public void HandleMouseUp(MouseUpEvent evt) { bool didConnect = false; Vector2 mousePosition = evt.mousePosition; // Reset the highlights. GraphView.ports.ForEach((p) => { p.SetEnabled(true); p.Highlighted = false; }); Port portUI; // Clean up ghost edges. if (m_GhostEdgeModel != null) { portUI = m_GhostEdgeModel.ToPort?.GetUI <Port>(GraphView); if (portUI != null) { portUI.WillConnect = false; } portUI = m_GhostEdgeModel.FromPort?.GetUI <Port>(GraphView); if (portUI != null) { portUI.WillConnect = false; } GraphView.RemoveElement(m_GhostEdge); m_GhostEdgeModel.ToPort = null; m_GhostEdgeModel.FromPort = null; m_GhostEdgeModel = null; m_GhostEdge = null; } Port endPort = GetEndPort(mousePosition); if (endPort == null && m_Listener != null) { m_Listener.OnDropOutsidePort(m_Store, m_EdgeCandidate, mousePosition, originalEdge); } m_EdgeCandidate.SetEnabled(true); portUI = edgeCandidateModel?.ToPort?.GetUI <Port>(GraphView); if (portUI != null) { portUI.WillConnect = false; } portUI = edgeCandidateModel?.FromPort?.GetUI <Port>(GraphView); if (portUI != null) { portUI.WillConnect = false; } // If it is an existing valid edge then delete and notify the model (using DeleteElements()). if (edgeCandidateModel?.ToPort != null && edgeCandidateModel?.FromPort != null) { // Save the current input and output before deleting the edge as they will be reset var oldInput = edgeCandidateModel.ToPort; var oldOutput = edgeCandidateModel.FromPort; GraphView.DeleteElements(new[] { m_EdgeCandidate as GraphElement }); // Restore the previous input and output edgeCandidateModel.ToPort = oldInput; edgeCandidateModel.FromPort = oldOutput; } // otherwise, if it is an temporary edge then just remove it as it is not already known my the model else { GraphView.RemoveElement(m_EdgeCandidate); } if (endPort != null) { if (edgeCandidateModel != null) { if (endPort.PortModel.Direction == Direction.Output) { edgeCandidateModel.FromPort = endPort.PortModel; } else { edgeCandidateModel.ToPort = endPort.PortModel; } } m_Listener.OnDrop(m_Store, m_EdgeCandidate, originalEdge); didConnect = true; } else if (edgeCandidateModel != null) { edgeCandidateModel.FromPort = null; edgeCandidateModel.ToPort = null; } m_EdgeCandidate?.ResetLayer(); ClearEdgeCandidate(); m_CompatiblePorts = null; Reset(didConnect); originalEdge = null; }
public void HandleMouseMove(MouseMoveEvent evt) { var ve = (VisualElement)evt.target; Vector2 gvMousePos = ve.ChangeCoordinatesTo(GraphView.contentContainer, evt.localMousePosition); m_PanDiff = GetEffectivePanSpeed(gvMousePos); if (m_PanDiff != Vector3.zero) { m_PanSchedule.Resume(); } else { m_PanSchedule.Pause(); } Vector2 mousePosition = evt.mousePosition; edgeCandidateModel.EndPoint = mousePosition; m_EdgeCandidate.UpdateFromModel(); // Draw ghost edge if possible port exists. Port endPort = GetEndPort(mousePosition); if (endPort != null) { if (m_GhostEdge == null) { m_GhostEdge = CreateGhostEdge(endPort.PortModel.GraphModel); m_GhostEdgeModel = m_GhostEdge.EdgeModel as GhostEdgeModel; m_GhostEdge.pickingMode = PickingMode.Ignore; GraphView.AddElement(m_GhostEdge); } Debug.Assert(m_GhostEdgeModel != null); if (edgeCandidateModel.FromPort == null) { m_GhostEdgeModel.ToPort = edgeCandidateModel.ToPort; var portUI = m_GhostEdgeModel?.FromPort?.GetUI <Port>(GraphView); if (portUI != null) { portUI.WillConnect = false; } m_GhostEdgeModel.FromPort = endPort.PortModel; endPort.WillConnect = true; } else { var portUI = m_GhostEdgeModel?.ToPort?.GetUI <Port>(GraphView); if (portUI != null) { portUI.WillConnect = false; } m_GhostEdgeModel.ToPort = endPort.PortModel; endPort.WillConnect = true; m_GhostEdgeModel.FromPort = edgeCandidateModel.FromPort; } m_GhostEdge.UpdateFromModel(); } else if (m_GhostEdge != null && m_GhostEdgeModel != null) { if (edgeCandidateModel.ToPort == null) { var portUI = m_GhostEdgeModel?.ToPort?.GetUI <Port>(GraphView); if (portUI != null) { portUI.WillConnect = false; } } else { var portUI = m_GhostEdgeModel?.FromPort?.GetUI <Port>(GraphView); if (portUI != null) { portUI.WillConnect = false; } } GraphView.RemoveElement(m_GhostEdge); m_GhostEdgeModel.ToPort = null; m_GhostEdgeModel.FromPort = null; m_GhostEdgeModel = null; m_GhostEdge = null; } }