public T AddLink <T>(T link, PortModel source, PortModel?target = null) where T : LinkModel { link.Type = Options.Links.DefaultLinkType; source.AddLink(link); if (target == null) { link.OnGoingPosition = new Point(source.Position.X + source.Size.Width / 2, source.Position.Y + source.Size.Height / 2); } else { target.AddLink(link); } source.Refresh(); target?.Refresh(); source.Parent.Group?.Refresh(); target?.Parent.Group?.Refresh(); LinkAdded?.Invoke(link); Changed?.Invoke(); return(link); }
public void SetTargetPort(PortModel?port) { if (TargetPort == port) { return; } var old = TargetPort; TargetPort?.RemoveLink(this); TargetPort = port; TargetPort?.AddLink(this); TargetPortChanged?.Invoke(this, old, TargetPort); }
public void SetSourcePort(PortModel port) { if (SourcePort == port) { return; } var old = SourcePort; SourcePort?.RemoveLink(this); SourcePort = port; SourcePort.AddLink(this); SourcePortChanged?.Invoke(this, old, SourcePort); }
public void AttachLink(LinkModel link, PortModel targetPort) { if (link.IsAttached) { throw new Exception("Link already attached."); } if (!link.SourcePort.CanAttachTo(targetPort)) { return; } link.SetTargetPort(targetPort); targetPort.AddLink(link); link.Refresh(); LinkAttached?.Invoke(link); }
public T AddLink <T>(PortModel source, PortModel?target = null) where T : LinkModel { var link = (T)Activator.CreateInstance(typeof(T), source, target); link.Type = Options.DefaultLinkType; source.AddLink(link); if (target == null) { link.OnGoingPosition = new Point(source.Position.X + source.Size.Width / 2, source.Position.Y + source.Size.Height / 2); } else { target.AddLink(link); } LinkAdded?.Invoke(link); Changed?.Invoke(); return(link); }