Exemplo n.º 1
0
        void componentChangeService_ComponentRemoving(object sender, ComponentEventArgs e)
        {
            if (bLoading)
            {
                return;
            }

            MathExpViewer mv = e.Component as MathExpViewer;

            if (mv != null)
            {
                List <LinkLineNodePort> ports = mv.GetPorts();
                for (int i = 0; i < ports.Count; i++)
                {
                    LinkLineNode l = ports[i];
                    l.ClearLine();
                    root.Controls.Remove(ports[i]);
                    root.Controls.Remove(ports[i].Label);
                    if (l is LinkLineNodeInPort)
                    {
                        if (l.LinkedOutPort == null)
                        {
                            //it is not linked to an output, remove all nodes
                            l = (LinkLineNode)l.PrevNode;
                            while (l != null)
                            {
                                root.Controls.Remove(l);
                                l = (LinkLineNode)l.PrevNode;
                            }
                        }
                        else
                        {
                            l.LinkedOutPort.LinkedPortID = 0;
                            //replace this port with a node
                            LinkLineNode prev = (LinkLineNode)l.PrevNode;
                            LinkLineNode end  = new LinkLineNode(null, prev);
                            end.Location = l.Location;
                            root.Controls.Add(end);
                            prev.SetNext(end);
                            if (prev.Line == null)
                            {
                                prev.CreateForwardLine();
                            }
                            else
                            {
                                if (prev.Line.EndPoint == l)
                                {
                                    prev.Line.SetEnd(end);
                                }
                                else
                                {
                                    end.CreateBackwardLine();
                                }
                            }
                        }
                    }
                    else if (l is LinkLineNodeOutPort)
                    {
                        if (l.LinkedInPort == null)
                        {
                            //it is not linked to an input, remove all nodes
                            l = (LinkLineNode)l.NextNode;
                            while (l != null)
                            {
                                root.Controls.Remove(l);
                                l = (LinkLineNode)l.NextNode;
                            }
                        }
                        else
                        {
                            l.LinkedInPort.LinkedPortID = 0;
                            //replace this port with a node
                            LinkLineNode next = (LinkLineNode)l.NextNode;
                            if (next.Parent != null)
                            {
                                LinkLineNode end = new LinkLineNode(next, null);
                                end.Location = l.Location;
                                next.Parent.Controls.Add(end);
                                next.SetPrevious(end);
                                if (next.Line == null)
                                {
                                    next.CreateBackwardLine();
                                }
                                else
                                {
                                    if (next.Line.StartPoint == l)
                                    {
                                        next.Line.SetStart(end);
                                    }
                                    else
                                    {
                                        end.CreateForwardLine();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }