示例#1
0
        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);
        }
示例#2
0
        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);
            link.Refresh();
            targetPort.Refresh();
            LinkAttached?.Invoke(link);
        }
示例#3
0
        public T AddLink <T>(PortModel source, PortModel?target = null) where T : LinkModel
        {
            var link = (T)Activator.CreateInstance(typeof(T), source, target);

            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();
            LinkAdded?.Invoke(link);
            Changed?.Invoke();
            return(link);
        }