protected override void OnApply(LinkLineNode node)
        {
            LinkLineNode node1 = GetLineNode(_node1);
            LinkLineNode node2 = GetLineNode(_node2);
            LinkLineNode start = (LinkLineNode)node1.PrevNode;
            LinkLineNode end   = (LinkLineNode)node2.NextNode;

            node1.ClearLine();
            node2.ClearLine();
            node.Parent.Controls.Remove(node1);
            node.Parent.Controls.Remove(node2);
            start.SetNext(end);
            end.SetPrevious(start);
            if (start.Line == null)
            {
                start.CreateForwardLine();
            }
            else
            {
                end.CreateBackwardLine();
            }
            if (start.LinkedOutPort != null)
            {
                if (end.LinkedInPort != null)
                {
                    start.LinkedOutPort.LinkedPortID = end.LinkedInPort.PortID;
                    end.LinkedInPort.LinkedPortID    = start.LinkedOutPort.PortID;
                }
            }
            ActiveDrawing.RefreshControl(node.Parent);
        }
Пример #2
0
 /// <summary>
 /// create action components and make port links
 /// </summary>
 /// <param name="designer"></param>
 public override bool LoadToDesigner(List <UInt32> used, MethodDiagramViewer designer)
 {
     if (designer.LoadAction(this))
     {
         if (_ifActions != null)
         {
             if (_ifActions.LoadToDesigner(used, designer))
             {
                 //make port link
                 if (this.OutPortList[0].LinkedInPort == null)
                 {
                     LinkLineNode end = this.OutPortList[0].End;
                     ActionPortIn pi  = _ifActions.GetInPort(this.OutPortList[0].LinkedPortID, this.OutPortList[0].LinkedPortInstanceID);
                     if (pi == null)
                     {
                         throw new MathException("Out port {0} is linked to [{1},{2}] of Branch {3}; but [{1},{2}] is not among the in-ports of the branch", this.OutPortList[0].PortID, this.OutPortList[0].LinkedPortID, this.OutPortList[0].LinkedPortInstanceID, _ifActions.BranchId);
                     }
                     LinkLineNode start = pi.Start;
                     end.SetNext(start);
                     start.SetPrevious(end);
                 }
             }
         }
         if (_elseActions != null)
         {
             if (_elseActions.LoadToDesigner(used, designer))
             {
                 //make port link
                 if (this.OutPortList[1].LinkedInPort == null)
                 {
                     LinkLineNode end = this.OutPortList[1].End;
                     ActionPortIn pi  = _elseActions.GetInPort(this.OutPortList[1].LinkedPortID, this.OutPortList[1].LinkedPortInstanceID);
                     if (pi == null)
                     {
                         throw new MathException("Out port {0} is linked to [{1},{2}] of Branch {3}; but [{1},{2}] is not among the in-ports of the branch", this.OutPortList[1].PortID, this.OutPortList[1].LinkedPortID, this.OutPortList[1].LinkedPortInstanceID, _elseActions.BranchId);
                     }
                     LinkLineNode start = pi.Start;
                     end.SetNext(start);
                     start.SetPrevious(end);
                 }
             }
         }
         return(true);
     }
     return(false);
 }
Пример #3
0
 public override void LinkJumpBranches()
 {
     if (_jumpToId != 0)
     {
         if (_jumpToActionBranch == null)
         {
             throw new DesignerException("Cannot set portlink from {0} to {1}. Linked actions not set", this.BranchId, _jumpToId);
         }
         ActionPortOut po = this.OutPortList[0];
         ActionPortIn  pi = _jumpToActionBranch.GetInPort(po.LinkedPortID, po.LinkedPortInstanceID);               //.InPortList[po.LinkedPortIndex];
         if (pi == null)
         {
             throw new DesignerException("out-port {0} is linked to [{1},{2}] of the jump-to-branch {3}, but in-port [{1},{2}] is not among the in-port list of the branch",
                                         po.PortID, po.LinkedPortID, po.LinkedPortInstanceID, _jumpToActionBranch.BranchId);
         }
         LinkLineNode        start = po.End;
         LinkLineNode        end;
         LinkLineNodeOutPort pipo = pi.Start as LinkLineNodeOutPort;
         if (pipo != null)
         {
             if (pipo.LinkedPortID != pi.PortID || pipo.LinkedPortInstanceID != pi.PortInstanceID)
             {
                 throw new DesignerException("Input [{0},{1}] is already linked to [{2},{3}], cannot link it to [{4},{5}]",
                                             pi.PortID, pi.PortInstanceID, pipo.PortID, pipo.PortInstanceID, po.PortID, po.PortInstanceID);
             }
         }
         else
         {
             end = pi.Start;
             if (end != start)
             {
                 start.SetNext(end);
                 end.SetPrevious(start);
                 po.LinkedPortID = pi.PortID;
                 pi.LinkedPortID = po.PortID;
             }
             else
             {
                 //it is not an error, it is already linked
             }
         }
     }
     base.LinkJumpBranches();
 }
Пример #4
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();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }