public override void OnReadFromXmlNode(IXmlCodeReader reader, XmlNode node)
        {
            base.OnReadFromXmlNode(reader, node);
            XmlNodeList nodes = node.SelectNodes(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}/{1}", XML_EVENTS, XmlTags.XML_Item));

            if (nodes != null && nodes.Count > 0)
            {
                _events = new List <EventIcon>();
                foreach (XmlNode eNode in nodes)
                {
                    EventIcon ei = new EventIcon(this);
                    ei.ReadFromXmlNode((XmlObjectReader)reader, eNode);
                    _events.Add(ei);
                }
            }
            //
            _inPortList = new List <EventPortIn>();
            XmlNodeList nds = node.SelectNodes(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}/{1}", XML_INPORTS, XmlTags.XML_Item));

            foreach (XmlNode n in nds)
            {
                EventPortIn pi = new EventPortIn(this);
                pi.OnReadFromXmlNode(reader, n);
                _inPortList.Add(pi);
            }
        }
 public void RemoveDestinationIcon(EventPortIn pi)
 {
     if (_inPortList != null)
     {
         foreach (EventPortIn p in _inPortList)
         {
             if (p.Event.IsSameObjectRef(pi.Event))
             {
                 _inPortList.Remove(p);
                 break;
             }
         }
     }
 }
Exemple #3
0
        public void AddInPort(LinkLineNodeInPort port)
        {
            if (_inPortList == null)
            {
                _inPortList = new List <EventPortIn>();
            }
            EventPortIn epi = port as EventPortIn;

            if (epi == null)
            {
                throw new DesignerException("Cannot add non-EventPortIn to EventIcon");
            }
            else
            {
                _inPortList.Add(epi);
            }
        }
        public void AddInPort(LinkLineNodeInPort port)
        {
            if (port == null)
            {
                throw new DesignerException("Cannot add null to inports for {1}", this.GetType().Name);
            }
            EventPortIn epi = port as EventPortIn;

            if (epi == null)
            {
                throw new DesignerException("Cannot add {0} to inports for {1}", port.GetType().Name, this.GetType().Name);
            }
            if (_inPortList == null)
            {
                _inPortList = new List <EventPortIn>();
            }
            _inPortList.Add(epi);
        }
        public EventPortIn ValidateActionExecuter(EventAction ea, ClassPointer root)
        {
            EventPortIn missing = null;

            if (_inPortList == null)
            {
                _inPortList = new List <EventPortIn>();
            }
            foreach (TaskID tid in ea.TaskIDList)
            {
                if (this.IsActionExecuter(tid, root))
                {
                    bool bFound = false;
                    foreach (EventPortIn pi in _inPortList)
                    {
                        if (pi.Event.IsSameObjectRef(ea.Event))
                        {
                            bFound = true;
                            break;
                        }
                    }
                    if (!bFound)
                    {
                        EventPortIn pi = new EventPortIn(this);
                        pi.Event = ea.Event;
                        _inPortList.Add(pi);
                        double x, y;
                        ComponentIconEvent.CreateRandomPoint(Width + ComponentIconEvent.PortSize, out x, out y);
                        pi.Location = new Point((int)(Center.X + x), (int)(Center.Y + y));
                        pi.SetLoaded();
                        pi.SaveLocation();
                        //
                        missing = pi;
                    }
                    break;
                }
            }
            return(missing);
        }
Exemple #6
0
        public void ReadFromXmlNode(XmlObjectReader reader, XmlNode node)
        {
            XmlNode nd;
            object  v;

            if (_label == null)
            {
                _label = new DrawingLabel(this);
            }
            if (XmlSerialization.ReadValueFromChildNode(node, XML_RelativePosition, out v))
            {
                _label.RelativePosition.Location = (Point)v;
                nd = node.SelectSingleNode(XML_RelativePosition);
                _label.RelativePosition.IsXto0 = XmlSerialization.GetAttributeBool(nd, "xTo0", true);
                _label.RelativePosition.IsYto0 = XmlSerialization.GetAttributeBool(nd, "yTo0", true);
            }
            //
            XmlNode eNode = node.SelectSingleNode(XML_Event);

            try
            {
                _event      = (IEvent)reader.ReadObject(eNode, null);
                _label.Text = _event.ShortDisplayName;
            }
            catch (Exception err)
            {
                MathNode.Log(TraceLogClass.MainForm, err);
            }
            //
            XmlNode ndPos = node.SelectSingleNode(XML_Position);

            if (ndPos != null)
            {
                if (XmlSerialization.ReadValueFromChildNode(ndPos, XML_RelativePosition, out v))
                {
                    RelativePosition.Location = (Point)v;
                    nd = ndPos.SelectSingleNode(XML_RelativePosition);
                    RelativePosition.IsXto0 = XmlSerialization.GetAttributeBool(nd, "xTo0", true);
                    RelativePosition.IsYto0 = XmlSerialization.GetAttributeBool(nd, "yTo0", true);
                }
            }
            //
            _outPortList = new List <EventPortOut>();
            XmlNodeList nds = node.SelectNodes(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}/{1}", XML_OutPorts, XmlTags.XML_Item));

            foreach (XmlNode n in nds)
            {
                Type         t  = XmlUtil.GetLibTypeAttribute(n);
                EventPortOut po = (EventPortOut)Activator.CreateInstance(t, this);
                po.Event = this.Event;
                po.OnReadFromXmlNode(reader, n);
                _outPortList.Add(po);
            }
            nds = node.SelectNodes(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}/{1}", XML_InPorts, XmlTags.XML_Item));
            if (nds != null && nds.Count > 0)
            {
                _inPortList = new List <EventPortIn>();
                foreach (XmlNode n in nds)
                {
                    Type        t  = XmlUtil.GetLibTypeAttribute(n);
                    EventPortIn po = (EventPortIn)Activator.CreateInstance(t, this);
                    po.Event = this.Event;
                    po.OnReadFromXmlNode(reader, n);
                    _inPortList.Add(po);
                }
            }
        }
Exemple #7
0
        public List <Control> GetRelatedControls()
        {
            List <Control> lst = new List <Control>();

            lst.Add(this);
            lst.Add(_label);
            if (_outPortList != null && _outPortList.Count > 0)
            {
                foreach (EventPortOut po in _outPortList)
                {
                    lst.Add(po);
                    if (po.Label != null)
                    {
                        lst.Add(po.Label);
                    }
                    ILinkLineNode l = po.NextNode;
                    while (l != null && l.NextNode != null)
                    {
                        Control c = l as Control;
                        if (c != null)
                        {
                            lst.Add(c);
                        }
                        l = l.NextNode;
                    }
                    EventPortIn pi = l as EventPortIn;
                    if (pi != null)
                    {
                        lst.Add(pi);
                        if (pi.Label != null)
                        {
                            lst.Add(pi.Label);
                        }
                        ComponentIconEventhandle cieh = pi.Owner as ComponentIconEventhandle;
                        if (cieh != null)
                        {
                            if (cieh.Label != null)
                            {
                                lst.Add(cieh.Label);
                            }
                            lst.Add(cieh);
                        }
                        else
                        {
                            ComponentIconEvent cie = pi.Owner as ComponentIconEvent;
                            if (cie != null)
                            {
                                cie.RemoveDestinationIcon(pi);
                            }
                        }
                        if (this.Parent != null)
                        {
                            foreach (Control c in this.Parent.Controls)
                            {
                                ComponentIconEvent cie = c as ComponentIconEvent;
                                if (cie != null)
                                {
                                    List <EventPortIn> pis = cie.DestinationPorts;
                                    if (pis != null && pis.Count > 0)
                                    {
                                        bool b = false;
                                        foreach (EventPortIn p in pis)
                                        {
                                            if (p == pi)
                                            {
                                                b = true;
                                                break;
                                            }
                                        }
                                        if (b)
                                        {
                                            pis.Remove(pi);
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(lst);
        }
Exemple #8
0
        /// <summary>
        /// link: from this action to the event
        /// it does not have in-ports
        /// it has one out-port linking to the event
        /// </summary>
        /// <param name="eventData"></param>
        public override void Initialize(EventPathData eventData)
        {
            List <EventPortIn> inports = this.DestinationPorts;
            List <IEvent>      events  = new List <IEvent>();
            ClassPointer       root    = eventData.Owner.RootPointer;

            if (_firer != null)
            {
                List <EventAction> eas = root.EventHandlers;
                foreach (EventAction ea in eas)
                {
                    if (ea.TaskIDList != null && ea.TaskIDList.Count > 0)
                    {
                        //this event handling is not empty
                        //check to see if there is an event-firing action using this firer
                        //if there is one then this event should be linked to this firer
                        //that is, this ea causes the firer to fire another event
                        foreach (TaskID tid in ea.TaskIDList)
                        {
                            if (tid.Action == null)
                            {
                                tid.LoadActionInstance(root);
                            }
                            if (tid.Action != null)
                            {
                                FireEventMethod fe = tid.Action.ActionMethod as FireEventMethod;
                                if (fe != null)
                                {
                                    if (fe.EventId == _firer.EventId && fe.MemberId == _firer.MemberId)
                                    {
                                        events.Add(ea.Event);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            List <EventPortIn> invalid = new List <EventPortIn>();

            foreach (EventPortIn epi in inports)
            {
                bool found = false;
                foreach (IEvent e in events)
                {
                    if (e.IsSameObjectRef(epi.Event))
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    invalid.Add(epi);
                }
            }
            if (invalid.Count > 0)
            {
                foreach (EventPortIn epi in invalid)
                {
                    inports.Remove(epi);
                }
            }
            foreach (IEvent e in events)
            {
                bool found = false;
                foreach (EventPortIn epi in inports)
                {
                    if (e.IsSameObjectRef(epi.Event))
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    EventPortIn epi = new EventPortIn(this);
                    epi.Event = e;
                    epi.SetLoaded();
                    inports.Add(epi);
                }
            }
        }
        /// <summary>
        /// this control is already added to Parent.Controls.
        /// 1. remove invalid inports
        /// 2. add missed EventPortIn
        /// </summary>
        /// <param name="viewer"></param>
        public override void Initialize(EventPathData eventData)
        {
            ClassPointer       root = this.ClassPointer.RootPointer;
            List <EventAction> ehs  = root.EventHandlers;

            if (ehs != null && ehs.Count > 0)
            {
                if (DestinationPorts == null)
                {
                    DestinationPorts = new List <EventPortIn>();
                }
                else
                {
                    //remove invalid inport
                    List <EventPortIn> invalidInports = new List <EventPortIn>();
                    foreach (EventPortIn pi in DestinationPorts)
                    {
                        bool bFound = false;
                        foreach (EventAction ea in ehs)
                        {
                            if (pi.Event.IsSameObjectRef(ea.Event))
                            {
                                if (pi.Event.IsSameObjectRef(ea.Event))
                                {
                                    if (ea.TaskIDList != null && ea.TaskIDList.Count > 0)
                                    {
                                        foreach (TaskID tid in ea.TaskIDList)
                                        {
                                            if (tid.IsEmbedded)
                                            {
                                                HandlerMethodID hid = tid as HandlerMethodID;
                                                if (hid != null)
                                                {
                                                    if (hid.ActionId == this.MethodId)
                                                    {
                                                        bFound = true;
                                                        break;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                IAction a = root.GetActionInstance(tid.ActionId);                                                //only public actions in map
                                                if (a != null)
                                                {
                                                    CustomMethodPointer cmp = a.ActionMethod as CustomMethodPointer;
                                                    if (cmp != null)
                                                    {
                                                        if (cmp.MemberId == this.MethodId)
                                                        {
                                                            bFound = true;
                                                            break;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                if (bFound)
                                {
                                    break;
                                }
                            }
                        }
                        if (!bFound)
                        {
                            invalidInports.Add(pi);
                        }
                    }
                    if (invalidInports.Count > 0)
                    {
                        foreach (EventPortIn pi in invalidInports)
                        {
                            DestinationPorts.Remove(pi);
                        }
                    }
                }
                //add missed EventPortIn
                foreach (EventAction ea in ehs)
                {
                    if (ea.TaskIDList != null && ea.TaskIDList.Count > 0)
                    {
                        foreach (TaskID tid in ea.TaskIDList)
                        {
                            HandlerMethodID hid = tid as HandlerMethodID;
                            if (hid != null)
                            {
                                if (hid.ActionId == this.MethodId)
                                {
                                    bool bFound = false;
                                    foreach (EventPortIn pi in DestinationPorts)
                                    {
                                        if (pi.Event.IsSameObjectRef(ea.Event))
                                        {
                                            bFound = true;
                                            break;
                                        }
                                    }
                                    if (!bFound)
                                    {
                                        EventPortIn pi = new EventPortIn(this);

                                        pi.Event = ea.Event;
                                        double x, y;
                                        ComponentIconEvent.CreateRandomPoint(Width + ComponentIconEvent.PortSize, out x, out y);
                                        pi.Location = new Point((int)(Center.X + x), (int)(Center.Y + y));
                                        pi.SetLoaded();
                                        pi.SaveLocation();
                                        DestinationPorts.Add(pi);
                                    }
                                }
                            }
                            else
                            {
                                //it is a root scope action
                                IAction a = root.GetActionInstance(tid.ActionId);
                                if (a == null)
                                {
                                    MathNode.LogError(string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                                    "Action [{0}] not found", tid));
                                }
                                else
                                {
                                    CustomMethodPointer cmp = a.ActionMethod as CustomMethodPointer;
                                    if (cmp != null)
                                    {
                                        if (cmp.MemberId == this.MethodId)
                                        {
                                            bool bFound = false;
                                            foreach (EventPortIn pi in DestinationPorts)
                                            {
                                                if (pi.Event.IsSameObjectRef(ea.Event))
                                                {
                                                    bFound = true;
                                                    break;
                                                }
                                            }
                                            if (!bFound)
                                            {
                                                EventPortIn pi = new EventPortIn(this);
                                                pi.Event = ea.Event;
                                                double x, y;
                                                ComponentIconEvent.CreateRandomPoint(Width + ComponentIconEvent.PortSize, out x, out y);
                                                pi.Location = new Point((int)(Center.X + x), (int)(Center.Y + y));
                                                pi.SetLoaded();
                                                pi.SaveLocation();
                                                DestinationPorts.Add(pi);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #10
0
 public static void MakePortLinks(PortCollection ports)
 {
     foreach (LinkLineNodePort p in ports)
     {
         EventPortIn epi = p as EventPortIn;
         if (epi != null)
         {
             EventPortInFireEvent epife = epi as EventPortInFireEvent;
             //
             bool bLinked = false;
             foreach (LinkLineNodePort p2 in ports)
             {
                 bool bMatch = false;
                 if (epife != null)
                 {
                     EventPortOutFirer epof = p2 as EventPortOutFirer;
                     if (epof != null)
                     {
                         //it is a fire-event action
                         ComponentIconFireEvent cife = epof.PortOwner as ComponentIconFireEvent;
                         if (cife != null)
                         {
                             FireEventMethod fe1 = epife.FireEventMethod;
                             FireEventMethod fe2 = cife.Firer;
                             if (fe1 != null && fe2 != null && fe1.EventId == fe2.EventId && fe2.MemberId == fe2.MemberId)
                             {
                                 bMatch = true;
                             }
                         }
                     }
                 }
                 else
                 {
                     EventPortOut epo = p2 as EventPortOut;
                     if (epo != null)
                     {
                         if (epi.Event.IsSameObjectRef(epo.Event))
                         {
                             ComponentIconEvent cieDest = (ComponentIconEvent)(epi.PortOwner);
                             if (epo.IsActionExecuter(cieDest))
                             {
                                 bMatch = true;
                             }
                         }
                     }
                 }
                 if (bMatch)
                 {
                     if (p2.LinkedPortID == epi.PortID && p2.LinkedPortInstanceID == epi.PortInstanceID &&
                         epi.LinkedPortID == p2.PortID && epi.LinkedPortInstanceID == p2.PortInstanceID)
                     {
                         bLinked = true;
                         break;
                     }
                     else
                     {
                         //try to fix it
                         if (p2.LinkedPortID == 0 && epi.LinkedPortID == 0)
                         {
                             p2.LinkedPortID          = epi.PortID;
                             p2.LinkedPortInstanceID  = epi.PortInstanceID;
                             epi.LinkedPortID         = p2.PortID;
                             epi.LinkedPortInstanceID = p2.PortInstanceID;
                             bLinked = true;
                             break;
                         }
                         else
                         {
                             LinkLineNodePort lp;
                             lp = ports.GetPortByID(epi.LinkedPortID, epi.LinkedPortInstanceID);
                             if (lp == null)
                             {
                                 if (p2.LinkedPortID == 0)
                                 {
                                     p2.LinkedPortID          = epi.PortID;
                                     p2.LinkedPortInstanceID  = epi.PortInstanceID;
                                     epi.LinkedPortID         = p2.PortID;
                                     epi.LinkedPortInstanceID = p2.PortInstanceID;
                                     bLinked = true;
                                     break;
                                 }
                                 else
                                 {
                                     lp = ports.GetPortByID(p2.LinkedPortID, p2.LinkedPortInstanceID);
                                     if (lp == null)
                                     {
                                         p2.LinkedPortID          = epi.PortID;
                                         p2.LinkedPortInstanceID  = epi.PortInstanceID;
                                         epi.LinkedPortID         = p2.PortID;
                                         epi.LinkedPortInstanceID = p2.PortInstanceID;
                                         bLinked = true;
                                         break;
                                     }
                                 }
                             }
                             else
                             {
                                 if (lp.LinkedPortID == epi.PortID && lp.LinkedPortInstanceID == epi.PortInstanceID)
                                 {
                                     bLinked = true;
                                     break;
                                 }
                             }
                         }
                     }
                 }
             }
             if (!bLinked)
             {
                 if (epi.LinkedPortID != 0)
                 {
                     LinkLineNodePort lp;
                     lp = ports.GetPortByID(epi.LinkedPortID, epi.LinkedPortInstanceID);
                     if (lp == null || lp != epi)
                     {
                         epi.LinkedPortInstanceID = 0;
                         epi.LinkedPortID         = 0;
                     }
                 }
                 if (epi.LinkedPortID == 0)
                 {
                 }
             }
         }
     }
     foreach (LinkLineNodePort p in ports)
     {
         EventPortOut epo = p as EventPortOut;
         if (epo != null)
         {
             if (epo.LinkedPortID != 0)
             {
                 if (ports.GetPortByID(epo.LinkedPortID, epo.LinkedPortInstanceID) == null)
                 {
                     epo.LinkedPortInstanceID = 0;
                     epo.LinkedPortID         = 0;
                 }
             }
         }
     }
 }