public override LinkLineNodeOutPort CreateDuplicateOutPort() { EventPortOut po = (EventPortOut)base.CreateDuplicateOutPort(); EventIcon ei = (EventIcon)po.PortOwner; ei.AddOutPort(po); return(po); }
public void OnLineSelectionChanged(EventPortOut port) { listBoxActions.Items.Clear(); List <TaskID> lst = port.Actions; if (lst != null && lst.Count > 0) { foreach (TaskID a in lst) { listBoxActions.Items.Add(a); } } }
public void AddOutPort(LinkLineNodeOutPort port) { EventPortOut po = port as EventPortOut; if (po == null) { throw new DesignerException("Cannot add non-EventPortOut to EventIcon"); } if (_outPortList == null) { _outPortList = new List <EventPortOut>(); } _outPortList.Add(po); }
private void onActionAssignmentChange(IEvent e) { if (this._eventPath.SelectedLinkLine != null) { EventPortOut po = this._eventPath.SelectedLinkLine.StartNode as EventPortOut; if (po != null) { if (po.Event.IsSameObjectRef(e)) { listBoxActions.Items.Clear(); List <TaskID> lst = po.Actions; if (lst != null && lst.Count > 0) { foreach (TaskID a in lst) { listBoxActions.Items.Add(a); } } } } } else if (this._eventPath.SelectedEvent != null) { if (e.IsSameObjectRef(_eventPath.SelectedEvent.Event)) { listBoxActions.Items.Clear(); ClassPointer root = _panes.Loader.GetRootId(); List <EventAction> eas = root.EventHandlers; if (eas != null) { foreach (EventAction ea in eas) { if (ea.Event.IsSameObjectRef(e)) { if (ea.TaskIDList != null) { foreach (TaskID tid in ea.TaskIDList) { listBoxActions.Items.Add(tid); } } break; } } } } } }
public void OnRemoveAllEventHandlers(IEvent e) { if (_eventPath.SelectedLinkLine != null) { EventPortOut po = _eventPath.SelectedLinkLine.StartNode as EventPortOut; if (po != null) { if (e.IsSameObjectRef(po.Event)) { listBoxActions.Items.Clear(); _eventPath.ClearLineSelection(); } } } else if (_eventPath.SelectedEvent != null) { if (e.IsSameObjectRef(_eventPath.SelectedEvent.Event)) { listBoxActions.Items.Clear(); _eventPath.ClearEventIconSelection(); } } _eventPath.OnRemoveAllEventHandlers(e); }
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); } } }
/// <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); }
protected override List <Control> GetRelatedControls() { List <Control> lst = base.GetRelatedControls(); if (_inPortList != null && _inPortList.Count > 0) { foreach (EventPortIn pi in _inPortList) { lst.Add(pi); if (pi.Label != null) { lst.Add(pi.Label); } ILinkLineNode l = pi.PrevNode; while (l != null && l.PrevNode != null) { Control c = l as Control; if (c != null) { lst.Add(c); } l = l.PrevNode; } EventPortOut po = l as EventPortOut; if (po != null) { EventIcon ei = po.Owner as EventIcon; if (ei != null) { if (ei.SourcePorts.Count == 1) { lst.Add(po); if (po.Label != null) { lst.Add(po.Label); } lst.Add(ei); if (ei.Label != null) { lst.Add(ei.Label); } ComponentIconEvent cie = ei.RelativeOwner as ComponentIconEvent; if (cie != null) { if (cie._events != null && cie._events.Contains(ei)) { cie._events.Remove(ei); } } } } } } } if (_events != null && _events.Count > 0) { foreach (EventIcon ei in _events) { lst.AddRange(ei.GetRelatedControls()); } } return(lst); }
private void mi_moveActionDown(object sender, EventArgs e) { MenuItem mi = sender as MenuItem; if (mi != null) { IAction act = mi.Tag as IAction; TaskID tid = mi.Tag as TaskID; if (act != null || tid != null) { IEvent ie = null; if (this._eventPath.SelectedLinkLine != null) { EventPortOut po = this._eventPath.SelectedLinkLine.StartNode as EventPortOut; if (po != null) { ie = po.Event; } } else if (_eventPath.SelectedEvent != null) { ie = _eventPath.SelectedEvent.Event; } if (ie != null) { ClassPointer root = _panes.Loader.GetRootId(); List <EventAction> eas = root.EventHandlers; if (eas != null) { foreach (EventAction ea in eas) { if (ea.Event.IsSameObjectRef(ie)) { if (ea.TaskIDList != null) { foreach (TaskID tid0 in ea.TaskIDList) { if (act != null) { if (!tid0.IsEmbedded) { if (tid0.ActionId == act.ActionId) { ea.MoveActionDown(tid0); _panes.Loader.NotifyChanges(); _panes.OnActionListOrderChanged(this, ea); break; } } } else { if (tid0.IsSameTask(tid)) { ea.MoveActionDown(tid0); _panes.Loader.NotifyChanges(); _panes.OnActionListOrderChanged(this, ea); break; } } } } break; } } } } } } }
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; } } } } }
public static EventPortOut CreateOutPort(TaskID a, EventIcon owner) { EventPortOut po = null; CustomMethodPointer cmp = null; HandlerMethodID hid = a as HandlerMethodID; if (hid != null) { EventPortOutExecuteMethod em = new EventPortOutExecuteMethod(owner); em.SetMethod(hid.HandlerMethod); po = em; } else { if (a.Action == null) { } else { IEventMapSource eir = owner as IEventMapSource; ClassPointer root = eir.RootPointer; ClassPointer cpre = root.GetExternalExecuterClass(a.Action); if (a.Action.IsStatic && cpre != null) { EventPortOutClassTypeAction pct = new EventPortOutClassTypeAction(owner); pct.SetOwnerClassPointer(cpre); po = pct; } else if (a.Action.ActionMethod != null) { DataTypePointer dtp = a.Action.ActionMethod.Owner as DataTypePointer; if (dtp != null) { EventPortOutTypeAction pot = new EventPortOutTypeAction(owner); pot.SetOwnerType(dtp.BaseClassType); po = pot; } else { cmp = a.Action.ActionMethod as CustomMethodPointer; if (cmp != null && cmp.Holder.DefinitionClassId == a.ClassId) { EventPortOutExecuteMethod em = new EventPortOutExecuteMethod(owner); MethodClass mc = cmp.MethodPointed as MethodClass; if (mc != null) { em.SetMethod(mc); } po = em; } else { po = null; SetterPointer sp = a.Action.ActionMethod as SetterPointer; if (sp != null) { CustomPropertyPointer cpp = sp.SetProperty as CustomPropertyPointer; if (cpp != null) { EventPortOutSetProperty posp = new EventPortOutSetProperty(owner); posp.SetProperty(cpp.Property); posp.PropertyId = cpp.MemberId; po = posp; } } if (po == null) { EventPortOutExecuter pe = new EventPortOutExecuter(owner); pe.ActionExecuterId = a.Action.ExecuterMemberId; po = pe; } } } } else { ActionAttachEvent aae = a.Action as ActionAttachEvent; if (aae != null) { EventPortOutExecuter pe = new EventPortOutExecuter(owner); pe.ActionExecuterId = a.Action.ExecuterMemberId; po = pe; } } } } if (po != null) { po.AddAction(a); ActiveDrawing ei = owner as ActiveDrawing; double x, y; ComponentIconEvent.CreateRandomPoint(ei.Width + ComponentIconEvent.PortSize, out x, out y); po.Location = new Point((int)(ei.Center.X + x), (int)(ei.Center.Y + y)); po.SetLoaded(); po.SaveLocation(); } return(po); }