Пример #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 SetTargetPort(PortModel?port)
        {
            if (TargetPort == port)
            {
                return;
            }

            var old = TargetPort;

            TargetPort?.RemoveLink(this);
            TargetPort = port;
            TargetPort?.AddLink(this);
            TargetPortChanged?.Invoke(this, old, TargetPort);
        }
Пример #3
0
        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);
        }
Пример #4
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);
            targetPort.AddLink(link);
            link.Refresh();
            LinkAttached?.Invoke(link);
        }
Пример #5
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.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);
        }