public void SetData(List <EventAction> eas, EventPathData eventPathData) { _eventActionList = eas; _data = eventPathData; _event = eas[0].Event; _label.Text = eas[0].Event.ShortDisplayName; }
/// <summary> /// get the EventIcon for the event. /// create it if it does not exist. /// </summary> /// <param name="ea"></param> /// <param name="eventData"></param> /// <returns></returns> public EventIcon ValidateEventFirer(List <EventAction> eas, EventPathData eventData) { EventIcon ei = null; if (_events == null) { _events = new List <EventIcon>(); } foreach (EventIcon e in _events) { if (e.Event.IsSameObjectRef(eas[0].Event)) { ei = e; ei.SetData(eas, eventData); break; } } if (ei == null) { ei = new EventIcon(this, eas, eventData); _events.Add(ei); } return(ei); }
public EventIconCustom(Control owner, EventAction ea, EventPathData eventPathData) : base(owner, ea, eventPathData) { }
public EventIcon(Control owner, List <EventAction> ea, EventPathData eventPathData) : base(owner) { init(); SetData(ea, eventPathData); }
/// <summary> /// remove invalid outports /// add missing outports /// </summary> /// <returns>missing outports added</returns> public List <EventPortOut> Initialize() { if (_inPortList != null && _inPortList.Count > 0) { foreach (EventPortIn epi in _inPortList) { epi.RestoreLocation(); } } List <EventPortOut> missing = new List <EventPortOut>(); if (_data != null && _data.Owner != null && _data.Owner.Loader != null) { ClassPointer root = _data.Owner.Loader.GetRootId(); Dictionary <string, List <EventAction> > eaGroup = EventPathData.CreateHandlerGroup(root.EventHandlers); bool hasAction = false; if (eaGroup.TryGetValue(_event.ObjectKey, out _eventActionList)) { foreach (EventAction ea in _eventActionList) { if (ea.TaskIDList.Count > 0) { hasAction = true; break; } } } else { _eventActionList = new List <EventAction>(); } if (!hasAction) { _outPortList.Clear(); } else { foreach (EventAction ea in _eventActionList) { for (int i = 0; i < ea.TaskIDList.Count; i++) { if (ea.TaskIDList[i].Action == null) { ea.TaskIDList[i].LoadActionInstance(root); } } } //remove invalid out ports=============================== if (_outPortList == null) { _outPortList = new List <EventPortOut>(); } else { if (_outPortList.Count > 0) { List <EventPortOut> invalidPorts = new List <EventPortOut>(); foreach (EventPortOut po in _outPortList) { bool bLinked = false; //for all actions for this event, find one that is for this port foreach (EventAction ea in _eventActionList) { for (int i = 0; i < ea.TaskIDList.Count; i++) { bLinked = po.CanActionBeLinked(ea.TaskIDList[i]); if (bLinked) { break; } } if (bLinked) { break; } } if (!bLinked) { invalidPorts.Add(po); } } if (invalidPorts.Count > 0) { foreach (EventPortOut po in invalidPorts) { _outPortList.Remove(po); } } } } //===add missing ports======================================= foreach (EventAction ea in _eventActionList) { if (ea.TaskIDList.Count > 0) { // //add missing outports, generate EventPortOut instances to link to EventPortIn instances // for (int i = 0; i < ea.TaskIDList.Count; i++) { EventPortOut po = null; bool bLinked = false; foreach (EventPortOut eo in _outPortList) { bLinked = eo.IsForTheAction(ea.TaskIDList[i]); if (bLinked) { break; } if (po == null) { if (eo.CanActionBeLinked(ea.TaskIDList[i])) { po = eo; } } } if (!bLinked) { if (po != null) { po.AddAction(ea.TaskIDList[i]); } else { po = EventPortOut.CreateOutPort(ea.TaskIDList[i], this); if (po != null) { po.Event = _event; _outPortList.Add(po); missing.Add(po); } } } } } } } } return(missing); }
/// <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); } } } } } } } } } }
/// <summary> /// this control is already added to Parent.Controls /// 1. remove invalid inports /// 2. remove invalid EventIcon /// 3. add missed EventIcon /// 4. add missed EventPortIn /// 4. add EventIcon objects to Parent.Controls /// 5. initialize EventIcon /// </summary> /// <param name="viewer"></param> public virtual void Initialize(EventPathData eventData) { bool isRoot = this.IsRootClass; //validate events ClassPointer root = RootClassPointer; Dictionary <string, EventClass> events = root.CustomEvents; List <EventAction> ehs = root.EventHandlers; if (ehs != null && ehs.Count > 0) { if (_inPortList == null) { _inPortList = new List <EventPortIn>(); } else { //remove invalid inport List <EventPortIn> invalidInports = new List <EventPortIn>(); foreach (EventPortIn pi in _inPortList) { bool bFound = false; foreach (EventAction ea in ehs) { if (pi.Event.IsSameObjectRef(ea.Event)) { if (ea.TaskIDList != null && ea.TaskIDList.Count > 0) { foreach (TaskID tid in ea.TaskIDList) { if (this.IsActionExecuter(tid, root)) { bFound = true; break; } } } if (bFound) { break; } } } if (!bFound) { invalidInports.Add(pi); } } if (invalidInports.Count > 0) { foreach (EventPortIn pi in invalidInports) { _inPortList.Remove(pi); } } } //remove invalid EventIcon objects if (_events != null) { List <EventIcon> invalid = new List <EventIcon>(); foreach (EventIcon ei in _events) { bool bFound = false; if (ei.Event != null) { EventClass eic = ei.CustomEvent; if (eic != null) { if (isRoot) { if (this.ClassId == eic.ClassId) { foreach (EventClass ec in events.Values) { if (ec.IsSameObjectRef(eic)) { bFound = true; break; } } } } } if (!bFound) { foreach (EventAction ea in ehs) { if (ei.Event.IsSameObjectRef(ea.Event)) { bFound = true; break; } } } } if (!bFound) { invalid.Add(ei); } } foreach (EventIcon ei in invalid) { _events.Remove(ei); } //remove duplicated ports foreach (EventIcon ei in _events) { ei.ValidateSourcePorts(); } } //add missed EventIcon //add missed EventPortIn Dictionary <string, List <EventAction> > eaGroup = EventPathData.CreateHandlerGroup(ehs); foreach (EventAction ea in ehs) { IClass ic = EventPathData.GetEventFirerRef(ea.Event.Holder); if (ic != null) { if (ea.TaskIDList != null && ea.TaskIDList.Count > 0) { if (ic.IsSameObjectRef(this.ClassPointer)) { List <EventAction> eas; if (eaGroup.TryGetValue(ea.Event.ObjectKey, out eas)) { ValidateEventFirer(eas, eventData); } } ValidateActionExecuter(ea, root); } } } } if (isRoot) { foreach (EventClass ec in events.Values) { bool bFound = false; if (_events != null) { foreach (EventIcon ei in _events) { if (ec.IsSameObjectRef(ei.CustomEvent)) { ei.SetMoveUnLink(true); bFound = true; break; } } } if (!bFound) { if (_events == null) { _events = new List <EventIcon>(); } EventIcon ei = new EventIcon(this); ei.Event = new CustomEventPointer(ec, root); ei.SetMoveUnLink(true); _events.Add(ei); } } } //add EventIcon objects to Parent.Controls //initialize EventIcon if (_events != null) { Parent.Controls.AddRange(_events.ToArray()); foreach (EventIcon ei in _events) { ei.AdjustPosition(); ei.Initialize(); } } else { _events = new List <EventIcon>(); } }