private void CalculateLinkPositionInPorts(double height, IpFlowPortLabel label, List <IpFlowIpToPortLink> links, List <IpFlowPortLink> portLinks, Predicate <IpFlowPortLink> findPortLinkMatchPortLessThan200, Predicate <IpFlowPortLink> findPortLinkMatchPortGreaterThan200, Action <IpFlowPortLink, IpFlowPortLabel> setPortLinkPositionInPortLessThan200, Action <double, IpFlowPortLink, IpFlowPortLabel> setPortLinkPositionInPortGreaterThan200) { if (label.Port <= 200) { var segmentLinks = links.FindAll(l => l.Port == label.Port && !l.PositionInPortIsSetted); var findPortLinks = portLinks.FindAll(findPortLinkMatchPortLessThan200); foreach (var link in segmentLinks) { link.PositionInPorts = label.Y; link.PositionInPortIsSetted = true; } foreach (var link in findPortLinks) { setPortLinkPositionInPortLessThan200(link, label); } } else { var segmentLinks = links.FindAll(l => 200 < l.Port && l.Port <= label.Port && !l.PositionInPortIsSetted); var findPortLinks = portLinks.FindAll(findPortLinkMatchPortGreaterThan200); foreach (var link in segmentLinks) { link.PositionInPorts = ((double)link.Port / label.Port) * (label.Y + styleManager.LabelAdjustedY - height) + height; link.PositionInPortIsSetted = true; } foreach (var link in findPortLinks) { setPortLinkPositionInPortGreaterThan200(height, link, label); } } }
/// <summary> /// add label /// </summary> /// <returns>true means added</returns> private bool AddPortLabel(IpFlowPortLabel label, List <IpFlowPortLabel> labels) { if (label == null) { return(false); } if (labels.Exists(p => p.Port == label.Port)) { return(false); } labels.Add(label); return(true); }
private void SetPortLinkPositionInDestPortGreaterThan200(double height, IpFlowPortLink link, IpFlowPortLabel label) { link.PositionInDestinationPorts = ((double)link.DestinationPort / label.Port) * (label.Y + styleManager.LabelAdjustedY - height) + height; link.PositionInDestinationPortsIsSetted = true; }
private void SetPortLinkPositionInDestPortLessThan200(IpFlowPortLink link, IpFlowPortLabel label) { link.PositionInDestinationPorts = label.Y; link.PositionInDestinationPortsIsSetted = true; }
private void SetPortLinkPositionInSrcPortLessThan200(IpFlowPortLink link, IpFlowPortLabel label) { link.PositionInSourcePorts = label.Y; link.PositionInSourcePortsIsSetted = true; }
private IpFlowPortLabel CreatePortLabel(int port) { var containerHeight = SrcToDestPortContainer.ActualHeight; if (containerHeight <= 0) { return(null); } double y = -1; var value = port; var halfHeight = containerHeight / 2; if (port == 200) { y = halfHeight; } else if (0 <= port && port < 200) { y = (port / 200.0) * halfHeight; } else if (200 < port && port <= 60000) { value = (int)Math.Ceiling((double)port / 10000) * 10000; y = AdjustLabelYPosition(value, halfHeight); } else if (60000 < port && port <= 65535) { value = 65535; y = AdjustLabelYPosition(value, halfHeight); } else { return(null); } y = y - styleManager.LabelAdjustedY; if (y < 0) { y = 0; } var portLabel = new IpFlowPortLabel() { Port = value, Y = y, Label = new TextBlock() { Text = value.ToString() } }; if (diagram.NodeLabelStyle != null) { portLabel.Label.Style = diagram.NodeLabelStyle; } Canvas.SetTop(portLabel.Label, portLabel.Y); return(portLabel); }