public override bool CanActionBeLinked(TaskID act) { if (act.Action != null) { ClassPointer cpr = this.RootPointer.GetExternalExecuterClass(act.Action); if (cpr != null) { return(false); } DataTypePointer dtp = act.Action.ActionMethod.Owner as DataTypePointer; if (dtp != null) { return(false); } SetterPointer sp = act.Action.ActionMethod as SetterPointer; if (sp != null) { CustomPropertyPointer cpp = sp.SetProperty as CustomPropertyPointer; if (cpp != null) { return(cpp.MemberId == this.PropertyId); } } } return(false); }
public override bool CanActionBeLinked(TaskID act) { if (act.Action == null) { act.LoadActionInstance(this.RootPointer); } ActionAttachEvent aae = act.Action as ActionAttachEvent; if (aae != null) { return(aae.ExecuterMemberId == ActionExecuterId); } if (act.Action != null && act.Action.ActionMethod != null) { ClassPointer cpr = this.RootPointer.GetExternalExecuterClass(act.Action); if (cpr != null) { return(false); } DataTypePointer dtp = act.Action.ActionMethod.Owner as DataTypePointer; if (dtp != null) { return(false); } CustomMethodPointer cp = act.Action.ActionMethod as CustomMethodPointer; if (cp != null) { if (cp.ClassId != act.ClassId) { if (act.Action.ExecuterMemberId == ActionExecuterId) { return(true); } } } else { SetterPointer sp = act.Action.ActionMethod as SetterPointer; if (sp != null) { CustomPropertyPointer cpp = sp.SetProperty as CustomPropertyPointer; if (cpp == null || cpp.ClassId != act.ClassId) { if (act.Action.ExecuterMemberId == ActionExecuterId) { return(true); } } } else { if (act.Action.ExecuterMemberId == ActionExecuterId) { return(true); } } } } return(false); }
public IList <DataTypePointer> GetGenericTypes() { CustomPropertyPointer cpp = _owner as CustomPropertyPointer; if (cpp != null) { return(cpp.GetGenericTypes()); } return(null); }
public CodeTypeReference GetCodeTypeReference() { CustomPropertyPointer cpp = _owner as CustomPropertyPointer; if (cpp != null) { return(cpp.GetCodeTypeReference()); } return(null); }
public DataTypePointer GetConcreteType(Type typeParameter) { CustomPropertyPointer cpp = _owner as CustomPropertyPointer; if (cpp != null) { return(cpp.GetConcreteType(typeParameter)); } return(null); }
public DataTypePointer[] GetConcreteTypes() { CustomPropertyPointer cpp = _owner as CustomPropertyPointer; if (cpp != null) { return(cpp.GetConcreteTypes()); } return(null); }
public override bool IsActionExecuter(IAction act, ClassPointer root) { SetterPointer sp = act.ActionMethod as SetterPointer; if (sp != null) { CustomPropertyPointer cpp = sp.SetProperty as CustomPropertyPointer; if (cpp != null) { return(cpp.MemberId == this.PropertyId); } } return(false); }
/// <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) { } else { tid.LoadActionInstance(root); IAction a = tid.Action; if (a != null) { SetterPointer cmp = a.ActionMethod as SetterPointer; if (cmp != null) { CustomPropertyPointer cpp = cmp.SetProperty as CustomPropertyPointer; if (cpp != null) { if (cpp.MemberId == this.PropertyId) { 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) { if (!tid.IsEmbedded) { IAction a = tid.LoadActionInstance(root); if (a == null) { MathNode.LogError(string.Format(System.Globalization.CultureInfo.InvariantCulture, "Action [{0}] not found", tid)); } else { SetterPointer cmp = a.ActionMethod as SetterPointer; if (cmp != null) { CustomPropertyPointer cpp = cmp.SetProperty as CustomPropertyPointer; if (cpp != null && cpp.MemberId == this.PropertyId) { 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> /// check whether the action is executed by the owner of this icon /// </summary> /// <param name="act"></param> /// <param name="root"></param> /// <returns></returns> public virtual bool IsActionExecuter(IAction act, ClassPointer root) { FireEventMethod fe = act.ActionMethod as FireEventMethod; if (fe != null) { } else if (act.ActionMethod != null) { DataTypePointer dtp = act.ActionMethod.Owner as DataTypePointer; if (dtp != null) { return(false); } ClassPointer cpa = root.GetExternalExecuterClass(act); if (cpa != null) { MemberComponentIdCustom idc = this.ClassPointer as MemberComponentIdCustom; if (idc != null) { return(act.ExecuterClassId == idc.DefinitionClassId); } return(false); } CustomMethodPointer cmp = act.ActionMethod as CustomMethodPointer; if (cmp != null) { //for the same class, ComponentIconMethod is used if (act.ExecuterClassId != this.ClassPointer.ClassId) { MemberComponentIdCustom idc = this.ClassPointer as MemberComponentIdCustom; if (idc != null) { return(act.ExecuterClassId == idc.DefinitionClassId); } } return(false); } else { SetterPointer sp = act.ActionMethod as SetterPointer; if (sp != null) { CustomPropertyPointer cpp = sp.SetProperty as CustomPropertyPointer; if (cpp != null) { //for the same class ComponentIconProperty is used if (act.ExecuterClassId != this.ClassPointer.ClassId) { MemberComponentIdCustom idc = this.ClassPointer as MemberComponentIdCustom; if (idc != null) { return(act.ExecuterClassId == idc.DefinitionClassId); } } return(false); } } return(act.ExecuterMemberId == this.ClassPointer.MemberId); } } else { ActionAttachEvent aae = act as ActionAttachEvent; if (aae != null) { if (aae.ClassId == this.ClassId && aae.ExecuterMemberId == this.ClassPointer.MemberId) { return(true); } } } return(false); }
public void ReloadActions() { ActionGroupDesignerHolder holder = DesignerHolder as ActionGroupDesignerHolder; AB_Squential actions = holder.Actions; bool b = holder.DisableUndo; holder.DisableUndo = true; holder.ClearAllComponent(); Controls.Clear(); BranchList bl = actions.ActionList; LoadActions(bl); //load component icons List <ComponentIcon> iconList = IconList; if (iconList == null) { iconList = new List <ComponentIcon>(); } List <ComponentIcon> invalids = new List <ComponentIcon>(); foreach (ComponentIcon ci in iconList) { if (ci.ClassPointer == null) { invalids.Add(ci); } } foreach (ComponentIcon ci in invalids) { iconList.Remove(ci); } //find root ClassPointer root = holder.Designer.GetRootId(); List <IClass> objList; if (Method.IsStatic) { objList = new List <IClass>(); } else { objList = root.GetClassList(); } SubMethodInfoPointer smi = null; if (Method.SubMethod.Count > 0) { smi = Method.SubMethod.Peek() as SubMethodInfoPointer; } //initialize existing icons, creating ComponentIcon.ClassPointer foreach (ComponentIcon ic in iconList) { ic.SetDesigner(holder.Designer); ComponentIconPublic cip = ic as ComponentIconPublic; if (cip == null) { ComponentIconLocal lv = ic as ComponentIconLocal; if (lv != null) { lv.ReadOnly = true; if (!ParentEditor.LocalVariableDeclared(lv)) { lv.ScopeGroupId = actions.BranchId; } } else { } if (smi != null) { ParameterClassSubMethod sm = ic.ClassPointer as ParameterClassSubMethod; if (sm != null) { if (sm.ActionId == 0) { sm.ActionId = smi.ActionOwner.ActionId; } ParameterClass pc = ic.ClassPointer as ParameterClass; if (pc != null && pc.ObjectType != null) { if (pc.ObjectType.IsGenericParameter) { if (pc.ConcreteType == null) { if (smi.ActionOwner.MethodOwner != null) { CustomPropertyPointer cpp = smi.ActionOwner.MethodOwner.Owner as CustomPropertyPointer; if (cpp != null) { pc.ConcreteType = cpp.GetConcreteType(pc.ObjectType); } } } } } } } } else { } } //add new public component icons int x0 = 10; int y0 = 30; int x = x0; int y = y0; int dx = 10; int dy = 10; foreach (IClass c in objList) { bool bFound = false; foreach (ComponentIcon ic in iconList) { if (ic.ClassPointer == null) { } else { if (ic.ClassPointer.IsSameObjectRef(c)) { bFound = true; break; } } } if (!bFound) { ComponentIconPublic cip = new ComponentIconPublic(holder.Designer, c, Method); cip.Location = new Point(x, y); y += dy; y += cip.Height; if (y >= this.Height) { y = y0; x += dx; x += cip.Width; } iconList.Add(cip); } } //add new local component icons List <ComponentIcon> picons = ParentEditor.IconList; foreach (ComponentIcon lv in picons) { ComponentIconPublic cip0 = lv as ComponentIconPublic; if (cip0 == null) { bool bFound = false; foreach (ComponentIcon ic in iconList) { if (ic.ClassPointer.IsSameObjectRef(lv.ClassPointer)) { bFound = true; break; } } if (!bFound) { ComponentIcon cip = (ComponentIcon)lv.Clone(); cip.SetDesigner(holder.Designer); cip.ReadOnly = true; cip.Location = new Point(x, y); y += dy; y += cip.Height; if (y >= this.Height) { y = y0; x += dx; x += cip.Width; } iconList.Add(cip); } } } //add parameters if (Method.ParameterCount > 0) { foreach (ParameterClass c in Method.Parameters) { bool bFound = false; foreach (ComponentIcon ic in iconList) { if (ic.ClassPointer.IsSameObjectRef(c)) { bFound = true; break; } } if (!bFound) { ComponentIconParameter cip = new ComponentIconParameter(holder.Designer, c, Method); cip.Location = new Point(x, y); y += dy; y += cip.Height; if (y >= this.Height) { y = y0; x += dx; x += cip.Width; } iconList.Add(cip); } } } //add action parameters ISingleAction sa = actions as ISingleAction; if (sa != null && sa.ActionData != null && sa.ActionData.ActionMethod != null && sa.ActionData.ActionMethod.MethodPointed.MethodParameterTypes != null) { List <ParameterClass> plist = new List <ParameterClass>(); SubMethodInfoPointer smp = sa.ActionData.ActionMethod.MethodPointed as SubMethodInfoPointer; if (smp != null) { foreach (ParameterClassSubMethod p in smp.Parameters) { plist.Add(p); } } else { foreach (IParameter p in sa.ActionData.ActionMethod.MethodPointed.MethodParameterTypes) { ParameterClass c = p as ParameterClass; if (c == null) { try { c = sa.ActionData.ActionMethod.MethodPointed.GetParameterType(p.ParameterID) as ParameterClass; if (c == null) { DesignUtil.WriteToOutputWindowAndLog("Cannot get ParameterClass {0} for method {1} of {2}.", p.Name, sa.ActionData.ActionMethod.MethodName, sa.ActionData.ActionMethod.MethodPointed.GetType()); continue; } } catch (Exception errp) { DesignUtil.WriteToOutputWindowAndLog(errp, "Cannot get ParameterClass {0} for method {1} of {2}", p.Name, sa.ActionData.ActionMethod.MethodName, sa.ActionData.ActionMethod.MethodPointed.GetType()); continue; } } if (c != null) { plist.Add(c); } } } foreach (ParameterClass c in plist) { bool bFound = false; foreach (ComponentIcon ic in iconList) { if (ic.ClassPointer.IsSameObjectRef(c)) { ParameterClass c0 = ic.ClassPointer as ParameterClass; c0.ReadOnly = true; c0.Description = c.Description; bFound = true; break; } } if (!bFound) { ComponentIcon cip; ActionBranchParameter abp = c as ActionBranchParameter; if (abp != null) { cip = new ComponentIconActionBranchParameter(actions); cip.ClassPointer = abp; cip.SetDesigner(holder.Designer); } else { cip = new ComponentIconParameter(holder.Designer, c, Method); } cip.Location = new Point(x, y); y += dy; y += cip.Height; if (y >= this.Height) { y = y0; x += dx; x += cip.Width; } iconList.Add(cip); } } } //add icons holder.AddControlsToIconsHolder(iconList.ToArray()); foreach (ComponentIcon ic in iconList) { ComponentIconPublic cip = ic as ComponentIconPublic; if (cip == null) { if (ic.Left < 0) { ic.Left = 2; } if (ic.Top < 0) { ic.Top = 2; } ic.BringToFront(); ic.RefreshLabelPosition(); ic.RefreshLabelText(); ComponentIconLocal cil = ic as ComponentIconLocal; if (cil != null) { cil.HookNameChecker(); } } } //} InitializeInputTypes(); ValidateControlPositions(); holder.DisableUndo = b; }
public override bool OnExportCode(ActionBranch previousAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, CodeMemberMethod method, CodeStatementCollection statements) { bool bRet; if (_actionData == null) { _actionData = (ActionSubMethod)this.Method.GetActionInstance(_actId.ActionId); // (ActionSubMethod)compiler.ActionEventList.GetAction(_actId); } SubMethodInfoPointer smi = _actionData.ActionMethod as SubMethodInfoPointer; SubMethodInfo mi = smi.MethodInformation as SubMethodInfo; if (mi.IsForeach) { ParameterClassSubMethod p = mi.GetParameterType(0, smi, this); StringBuilder sb = new StringBuilder(); string s1 = smi.Owner.CodeName; CustomMethodParameterPointer cmpp = smi.Owner.Owner as CustomMethodParameterPointer; if (cmpp == null) { IObjectPointer op = smi.Owner; sb.Append(s1); while (!(op is ILocalvariable) && op.Owner != null && !(op.Owner is MethodClass) && op.Owner.Owner != null) { if (string.CompareOrdinal(s1, op.Owner.CodeName) != 0) { s1 = op.Owner.CodeName; sb.Insert(0, "."); sb.Insert(0, s1); } op = op.Owner; } s1 = sb.ToString(); } string itemTypeString = null; if (mi.ItemType.IsGenericParameter) { CollectionPointer cp = smi.Owner as CollectionPointer; if (cp != null) { CustomPropertyPointer cpp = cp.Owner as CustomPropertyPointer; if (cpp != null) { DataTypePointer dtp = cpp.GetConcreteType(mi.ItemType); if (dtp != null) { itemTypeString = dtp.TypeString; } } } } if (string.IsNullOrEmpty(itemTypeString)) { itemTypeString = VPLUtil.GetTypeCSharpName(mi.ItemType); } string s0 = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}foreach({1} {2} in {3}) {{", Indentation.GetIndent(), itemTypeString, p.CodeName, s1); CodeStatement cis0 = new CodeSnippetStatement(s0); statements.Add(cis0); // if (_iconList != null) { foreach (ComponentIcon ci in _iconList) { ComponentIconLocal cil = ci as ComponentIconLocal; if (cil != null && cil.ScopeGroupId == this.BranchId) { cil.LocalPointer.AddVariableDeclaration(statements); } } } // CodeStatementCollection sc = new CodeStatementCollection(); Method.SubMethod.Push(this); //smi); CompilerUtil.AddSubMethod(method, this); bRet = base.OnExportCode(previousAction, nextAction, compiler, method, sc); Method.SubMethod.Pop(); bRet = CompilerUtil.FinishSubMethod(method, this, sc, bRet); statements.AddRange(sc); // statements.Add(new CodeSnippetStatement(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}}}", Indentation.GetIndent()))); } else { CodeIterationStatement cis = new CodeIterationStatement(); cis.TestExpression = mi.GetTestExpression(smi, compiler, this.Method, method, statements, this.BranchId); cis.InitStatement = mi.GetInitStatement(smi, compiler, this.Method, method, statements, this.BranchId); cis.IncrementStatement = mi.GetIncrementalStatement(smi, compiler, this.Method, method, statements, this.BranchId); // Method.SubMethod.Push(this); //smi); CompilerUtil.AddSubMethod(method, this); if (_iconList != null) { foreach (ComponentIcon ci in _iconList) { ComponentIconLocal cil = ci as ComponentIconLocal; if (cil != null && cil.ScopeGroupId == this.BranchId) { cil.LocalPointer.AddVariableDeclaration(cis.Statements); } } } bRet = base.OnExportCode(previousAction, nextAction, compiler, method, cis.Statements); Method.SubMethod.Pop(); bRet = CompilerUtil.FinishSubMethod(method, this, cis.Statements, bRet); // // statements.Add(cis); } return(bRet); }
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); }