public void GhostEdgeHasExpectedClass() { GraphView graphView = new GraphView(null, null, ""); var model = new GhostEdgeModel(null); var edge = new Edge(); edge.SetupBuildAndUpdate(model, null, graphView); Assert.IsTrue(edge.ClassListContains(Edge.ghostModifierUssClassName)); }
Edge CreateGhostEdge(IGraphModel graphModel) { GhostEdgeModel ghostEdge; if (m_GhostEdgeViewModelCreator != null) { ghostEdge = m_GhostEdgeViewModelCreator.Invoke(graphModel); } else { ghostEdge = new GhostEdgeModel(graphModel); } var ui = GraphElementFactory.CreateUI <Edge>(GraphView, m_CommandDispatcher, ghostEdge); return(ui); }
void ClearEdgeCandidate() { m_EdgeCandidateModel = null; m_EdgeCandidate = null; }
public void CreateEdgeCandidate(IGraphModel graphModel) { m_EdgeCandidate = CreateGhostEdge(graphModel); m_EdgeCandidateModel = m_EdgeCandidate.EdgeModel as GhostEdgeModel; }
public void HandleMouseUp(MouseUpEvent evt, bool isFirstEdge, IEnumerable <Edge> otherEdges, IEnumerable <IPortModel> otherPorts) { 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 && isFirstEdge) { m_Listener.OnDropOutsidePort(m_CommandDispatcher, Enumerable.Repeat(originalEdge, 1).Concat(otherEdges), Enumerable.Repeat(draggedPort, 1).Concat(otherPorts), 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) { GraphView.RemoveElement(m_EdgeCandidate); } if (endPort != null) { if (edgeCandidateModel != null) { if (endPort.PortModel.Direction == PortDirection.Output) { edgeCandidateModel.FromPort = endPort.PortModel; } else { edgeCandidateModel.ToPort = endPort.PortModel; } } m_Listener.OnDrop(m_CommandDispatcher, 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; } }