public override object FromStringValue(List <Nodes.Node.ErrorCheck> result, DefaultObject node, object parentObject, Type type, string str) { if (type != typeof(RightValueDef)) { throw new Exception(Resources.ExceptionDesignerAttributeInvalidType); } if (str.Length == 0 || str.Length == 2 && str == "\"\"") { return(null); } if (!str.StartsWith("const")) { int pos = str.IndexOf('('); if (pos < 0) { VariableDef var = DesignerPropertyEnum.parsePropertyVar(result, node, str); return(new RightValueDef(var)); } else { Nodes.Behavior behavior = node.Behavior as Nodes.Behavior; AgentType agentType = (behavior != null) ? behavior.AgentType : null; string valueClass = VariableDef.kSelfMethod; MethodDef method = DesignerMethodEnum.parseMethodString(result, node, agentType, this.MethodType, str); if (method == null) { string className = Plugin.GetClassName(str); method = DesignerMethodEnum.parseMethodString(result, node, Plugin.GetInstanceAgentType(className, behavior, null), this.MethodType, str); valueClass = className + VariableDef.kMethod; } string instanceName = Plugin.GetInstanceName(str); if (!string.IsNullOrEmpty(instanceName)) { valueClass = instanceName + VariableDef.kMethod; } return(new RightValueDef(method, valueClass)); } } else { VariableDef var = this.parseConstVar(result, node, parentObject, str); if (var != null) { return(new RightValueDef(var)); } } return(null); }
private int getComboIndex(string valueType, string instanceName, string propertyName) { if (valueType == VariableDef.kConst) { return(0); } if (valueType == VariableDef.kSelf) { return(1); } if (string.IsNullOrEmpty(instanceName)) { instanceName = Plugin.GetClassName(propertyName); } Debug.Check(!string.IsNullOrEmpty(instanceName)); Nodes.Behavior behavior = GetBehavior(); int index = Plugin.InstanceNameIndex(instanceName, behavior); Debug.Check(index >= 0); return(index + 2); }
public override void SetParameter(MethodDef.Param param, object obj, bool bReadonly) { base.SetParameter(param, obj, bReadonly); _resetProperties = false; string selectionName = string.Empty; VariableDef variable = param.Value as VariableDef; if (variable != null) { _valueOwner = variable.ValueClass; selectionName = (variable.Property != null) ? variable.Property.DisplayName : variable.DisplayName; } else { RightValueDef variableRV = param.Value as RightValueDef; if (variableRV != null) { _valueOwner = variableRV.ValueClassReal; selectionName = variableRV.DisplayName; } } Nodes.Behavior behavior = GetBehavior(); _agentType = (behavior != null) ? behavior.AgentType : null; if (_valueOwner != VariableDef.kSelf) { _agentType = Plugin.GetInstanceAgentType(_valueOwner, behavior, _agentType); } setComboBox(selectionName); }
private string getValueType(MethodDef.Param param, string instanceName, string propertyName) { if (param.IsProperty) { if (instanceName == VariableDef.kSelf) { return(VariableDef.kSelf); } Nodes.Behavior behavior = GetBehavior(); AgentType agent = (behavior != null) ? behavior.AgentType : null; agent = Plugin.GetInstanceAgentType(instanceName, behavior, agent); if (agent != null) { IList <PropertyDef> properties = agent.GetProperties(); foreach (PropertyDef p in properties) { if (p.Name == propertyName #if BEHAVIAC_NAMESPACE_FIX || p.Name.EndsWith(propertyName) #endif ) { return(instanceName); } } } } return(VariableDef.kConst); }
private string getValueType(MethodDef.Param param, string propertyName) { if (param.IsLocalVar) { Nodes.Behavior behavior = GetBehavior(); AgentType agent = (behavior != null) ? behavior.AgentType : null; // Try to find the Agent property with the name. if (agent != null) { IList <PropertyDef> properties = agent.GetProperties(); foreach (PropertyDef p in properties) { if (p.Name == propertyName #if BEHAVIAC_NAMESPACE_FIX || p.Name.EndsWith(propertyName) #endif ) { return(VariableDef.kSelf); } } } // Try to find the global property with the name. string className = Plugin.GetClassName(propertyName); return(getValueType(param, className, propertyName)); } return(VariableDef.kConst); }
public static bool IsExpandedNode(NodeViewData nvd) { Debug.Check(nvd != null && nvd.Node != null); if (nvd != null && nvd.Node != null) { bool defaultExpanded = !(nvd.Node is Nodes.ReferencedBehavior); if (defaultExpanded) { //if there is a leaf node, collapse it foreach (NodeViewData child in nvd.Children) { if (!child.CanBeExpanded()) { //leaf node can't be expanded, there is a leaf node! defaultExpanded = false; break; } } } Nodes.Behavior behavior = nvd.Node.Behavior as Nodes.Behavior; if (behavior != null) { behavior = behavior.GetTopBehavior(); } string filename = (behavior != null) && !string.IsNullOrEmpty(behavior.Filename) ? behavior.RelativePath : string.Empty; if (!string.IsNullOrEmpty(filename) && _expandedNodeDict.ContainsKey(filename)) { Dictionary <string, ExpandedDatum> expandedNodes = _expandedNodeDict[filename]; string id = nvd.FullId; if (!expandedNodes.ContainsKey(id)) { return(defaultExpanded); } return(expandedNodes[id].isExpanded); } else { //defaultExpanded = true; } return(defaultExpanded); } return(false); }
private List <MethodDef> getMethods() { List <MethodDef> methods = new List <MethodDef>(); if (typeComboBox.SelectedIndex > -1) { Nodes.Behavior behavior = GetBehavior(); AgentType agentType = Plugin.GetInstanceAgentType(_currentNames[typeComboBox.SelectedIndex], behavior, _agentType); if (agentType != null) { // get the linked method to filter MethodDef linkedMethod = null; bool linkBroken; DesignerPropertyInfo linkedProp = _property.Attribute.GetLinkedProperty(_object, out linkBroken); object prop = linkedProp.GetValue(_object); if (prop != null && prop is MethodDef) { linkedMethod = prop as MethodDef; } DesignerMethodEnum attrMethod = _property.Attribute as DesignerMethodEnum; #if USE_NOOP IList <MethodDef> methods = new List <MethodDef>(); methods.Add(MethodDef.Noop); IList <MethodDef> agentMethods = agentType.GetMethods(attrMethod.MethodType, ValueTypes.All, linkedMethod); foreach (MethodDef m in agentMethods) { methods.Add(m); } #else if (attrMethod != null) { methods.AddRange(agentType.GetMethods(attrMethod.MethodType, attrMethod.MethodReturnType, linkedMethod)); } else { DesignerRightValueEnum attrMethodRV = _property.Attribute as DesignerRightValueEnum; if (attrMethodRV != null) { methods.AddRange(agentType.GetMethods(attrMethodRV.MethodType, ValueTypes.All, linkedMethod)); } } #endif//#if USE_NOOP } } return(methods); }
public static VariableDef setParameter(List <Nodes.Node.ErrorCheck> result, DefaultObject node, string propertyName) { Nodes.Behavior behavior = node.Behavior as Nodes.Behavior; // Convert the Par to the Property if (!propertyName.Contains(".") && !propertyName.Contains(":")) { propertyName = "Self." + behavior.AgentType.AgentTypeName + "::" + propertyName; } VariableDef var = null; string instance = Plugin.GetInstanceName(propertyName); if (!string.IsNullOrEmpty(instance)) { propertyName = propertyName.Substring(instance.Length + 1, propertyName.Length - instance.Length - 1); var = createVariable(result, node, behavior.AgentType, instance, propertyName); if (var != null) { return(var); } } // Try to find the Agent property with the name. if (behavior != null && behavior.AgentType != null) { instance = "Self"; var = createVariable(result, node, behavior.AgentType, instance, propertyName); if (var != null) { return(var); } } // Try to find the global property with the name. string instacneName = Plugin.GetClassName(propertyName); if (!string.IsNullOrEmpty(instacneName) && Plugin.GetInstanceAgentType(instacneName, behavior, null) != null) { var = createVariable(result, node, behavior.AgentType, instacneName, propertyName); if (var != null) { return(var); } } return(null); }
protected Nodes.Behavior GetBehavior() { Attachments.Attach attach = _object as Attachments.Attach; Nodes.BaseNode baseNode = (attach != null) ? attach.Node : _object as Nodes.BaseNode; Nodes.Behavior behavior = (baseNode != null) ? baseNode.Behavior as Nodes.Behavior : null; if (behavior == null && _root != null) { behavior = _root.Behavior as Nodes.Behavior; } return(behavior); }
public static bool IsExpandedConnector(NodeViewData nvd, string connector) { Debug.Check(nvd != null && nvd.Node != null); Nodes.Behavior behavior = nvd.Node.Behavior as Nodes.Behavior; if (behavior != null) { behavior = behavior.GetTopBehavior(); } string filename = (behavior != null) && !string.IsNullOrEmpty(behavior.Filename) ? behavior.RelativePath : string.Empty; return(IsExpandedConnector(filename, nvd.Node.Id.ToString(), connector)); }
public static bool SetExpandedConnector(NodeViewData nvd, string connector, bool isConnectorExpanded) { Debug.Check(nvd != null && nvd.Node != null); Nodes.Behavior behavior = nvd.Node.Behavior as Nodes.Behavior; if (behavior != null) { behavior = behavior.GetTopBehavior(); } if (behavior != null && !string.IsNullOrEmpty(behavior.Filename)) { return(SetExpandedConnector(behavior.RelativePath, nvd.Node.Id.ToString(), connector, isConnectorExpanded)); } return(false); }
private static VariableDef createVariable(List <Nodes.Node.ErrorCheck> result, DefaultObject node, AgentType agentType, string instacneName, string propertyName) { List <string> tokens = DesignerPropertyEnum.SplitTokens(propertyName); Debug.Check(tokens.Count > 0); string arrayIndexStr = null; if (tokens.Count > 1) { propertyName = tokens[0] + "[]"; arrayIndexStr = tokens[1]; } Nodes.Behavior behavior = node.Behavior as Nodes.Behavior; agentType = Plugin.GetInstanceAgentType(instacneName, behavior, agentType); if (agentType != null) { IList <PropertyDef> properties = agentType.GetProperties(); foreach (PropertyDef p in properties) { if (p.Name == propertyName #if BEHAVIAC_NAMESPACE_FIX || p.Name.EndsWith(propertyName) #endif ) { VariableDef v = new VariableDef(p, instacneName); if (v != null && !string.IsNullOrEmpty(arrayIndexStr)) { v.ArrayIndexElement = new MethodDef.Param("ArrayIndex", typeof(int), "int", "ArrayIndex", "ArrayIndex"); v.ArrayIndexElement.IsArrayIndex = true; DesignerMethodEnum.parseParam(result, node, null, v.ArrayIndexElement, arrayIndexStr); } return(v); } } } return(null); }
private List <MethodDef> getMethods() { List <MethodDef> methods = new List <MethodDef>(); Nodes.Behavior behavior = GetBehavior(); AgentType agentType = (behavior != null) ? behavior.AgentType : null; object action = _property.Property.GetValue(_object, null); VariableDef var = action as VariableDef; Debug.Check(var == null); RightValueDef varRV = action as RightValueDef; if (varRV != null && Plugin.IsInstanceName(varRV.ValueClassReal, behavior)) { agentType = Plugin.GetInstanceAgentType(varRV.ValueClassReal, behavior, agentType); } if (agentType != null) { DesignerRightValueEnum enumAttRV = _property.Attribute as DesignerRightValueEnum; DesignerMethodEnum attrMethod = _property.Attribute as DesignerMethodEnum; MethodType methodType = attrMethod != null ? attrMethod.MethodType : MethodType.Getter; if (enumAttRV != null) { methodType = enumAttRV.MethodType; } IList <MethodDef> actions = agentType.GetMethods(true, methodType); foreach (MethodDef actionType in actions) { if (Plugin.IsCompatibleType(this.ValueType, this.FilterType, actionType.ReturnType, false)) { methods.Add(actionType); } } } return(methods); }
public static bool SetExpandedNode(NodeViewData nvd, bool isExpanded) { Debug.Check(nvd != null && nvd.Node != null); Nodes.Behavior b = nvd.Node.Behavior as Nodes.Behavior; if (b != null) { b = b.GetTopBehavior(); Debug.Check(b != null); if (!string.IsNullOrEmpty(b.Filename)) { return(SetExpandedNode(b.RelativePath, nvd.FullId, isExpanded)); } } return(false); }
public static bool HasSetExpandedNodes(NodeViewData nvd) { Debug.Check(nvd != null && nvd.Node != null); Nodes.Behavior behavior = nvd.Node.Behavior as Nodes.Behavior; if (behavior != null) { behavior = behavior.GetTopBehavior(); } string filename = (behavior != null) && !string.IsNullOrEmpty(behavior.Filename) ? behavior.RelativePath : string.Empty; if (!string.IsNullOrEmpty(filename) && _expandedNodeDict.ContainsKey(filename)) { return(true); } return(false); }
public override void SetProperty(DesignerPropertyInfo property, object obj) { base.SetProperty(property, obj); _resetMethods = false; DesignerMethodEnum enumAtt = property.Attribute as DesignerMethodEnum; if (enumAtt != null && property.Property.PropertyType == null) { throw new Exception(string.Format(Resources.ExceptionDesignerAttributeExpectedEnum, property.Property.Name)); } Nodes.Behavior behavior = GetBehavior(); _agentType = (behavior != null) ? behavior.AgentType : null; SetTypes(); object action = property.Property.GetValue(obj, null); MethodDef method = action as MethodDef; int typeIndex = -1; if (method != null) { typeIndex = getTypeIndex(method.Owner); } if (typeIndex < 0) { typeIndex = 0; } // Keep only one type for efficiency. _currentNames.Clear(); _currentNames.Add(_names[typeIndex]); this.typeComboBox.Items.Clear(); this.typeComboBox.Items.Add(_types[typeIndex]); this.typeComboBox.SelectedIndex = 0; }
public override object FromStringValue(NodeTag.DefaultObject node, object parentObject, Type type, string str) { if (type != typeof(MethodDef)) { throw new Exception(Resources.ExceptionDesignerAttributeInvalidType); } Nodes.Behavior behavior = node.Behavior as Nodes.Behavior; if (behavior != null && behavior.AgentType != null) { MethodDef method = parseMethodString(node, behavior.AgentType, this.MethodType, str); if (method == null) { string className = Plugin.GetClassName(str); method = parseMethodString(node, Plugin.GetInstanceAgentType(className), this.MethodType, str); } return(method); } return(null); }
public static MethodDef parseMethodString(List <Nodes.Node.ErrorCheck> result, DefaultObject node, AgentType agentType, MethodType methodType, string str) { try { if (agentType != null) { int pos = str.IndexOf('('); if (pos < 0) { return(null); } string ownerName = agentType.ToString(); int pointIndex = str.IndexOf('.'); if (pointIndex > -1 && pointIndex < pos) { ownerName = str.Substring(0, pointIndex); Nodes.Behavior behavior = node.Behavior as Nodes.Behavior; if (ownerName != VariableDef.kSelf && !Plugin.IsInstanceName(ownerName, behavior)) { throw new Exception("The instance does not exist."); } str = str.Substring(pointIndex + 1, str.Length - pointIndex - 1); agentType = Plugin.GetInstanceAgentType(ownerName, behavior, agentType); //if (agentType == node.Behavior.AgentType) // ownerName = VariableDef.kSelf; pos = str.IndexOf('('); } IList <MethodDef> actions = agentType.GetMethods(methodType); string actionName = str.Substring(0, pos); foreach (MethodDef actionTypeIt in actions) { if (actionTypeIt.Name == actionName #if BEHAVIAC_NAMESPACE_FIX || actionTypeIt.Name.EndsWith(actionName) #endif ) { MethodDef method = new MethodDef(actionTypeIt); method.Owner = ownerName; List <string> paras = parseParams(str.Substring(pos + 1, str.Length - pos - 2)); //Debug.Check((paras.Count == actionTypeIt.Params.Count)); //if (paras.Count == actionTypeIt.Params.Count) { for (int i = 0; i < paras.Count; ++i) { if (i >= method.Params.Count) { break; } string param = paras[i]; MethodDef.Param par = method.Params[i]; bool bOk = parseParam(result, node, method, par, param); if (!bOk) { throw new Exception(string.Format(Resources.ExceptionDesignerAttributeIllegalFloatValue, str)); } } } return(method); } } } } catch (Exception) { //System.Windows.Forms.MessageBox.Show(str, Resources.LoadError, System.Windows.Forms.MessageBoxButtons.OK); if (result != null) { Nodes.Node n = node as Nodes.Node; string label = ""; if (n == null) { Attachments.Attachment a = node as Attachments.Attachment; if (a != null) { n = a.Node; label = a.Label; } } else { label = n.Label; } Nodes.Node.ErrorCheck error = new Nodes.Node.ErrorCheck(n, node.Id, label, Nodes.ErrorCheckLevel.Error, str); result.Add(error); } } return(null); }
private int getComboIndex(string valueType) { Nodes.Behavior behavior = GetBehavior(); if (_methodOnly) { if (valueType == VariableDef.kSelfMethod) { //self::method return(0); } else { int pos = valueType.IndexOf(VariableDef.kMethod); if (pos != -1) { //self::method world::method player::method string classType = valueType.Substring(0, pos); return(Plugin.InstanceNameIndex(classType, behavior) + 1); } } } List <Plugin.InstanceName_t> instanceNames = this.InstanceNames; int indexBegin = _allowConst ? 1 : 0; int indexOffset = 1; if (valueType == VariableDef.kConst) { return(0); } else if (valueType == VariableDef.kSelf) { //[const] [par] self world player self::method return(indexBegin); } else if (valueType == VariableDef.kSelfMethod) { //[const] [par] self world player self::method return(indexBegin + indexOffset + instanceNames.Count); } else { int pos = valueType.IndexOf(VariableDef.kMethod); if (pos != -1) { //[const] [par] self world player self::method world::method player::method string instanceName = valueType.Substring(0, pos); int index = Plugin.InstanceNameIndex(instanceName, behavior); return(index + indexBegin + indexOffset + instanceNames.Count + 1); } else { //[const] [par] self world player int index = Plugin.InstanceNameIndex(valueType, behavior); return(index + indexBegin + indexOffset); } } }
public override void SetProperty(DesignerPropertyInfo property, object obj) { base.SetProperty(property, obj); _resetProperties = false; Type enumtype = null; DesignerPropertyEnum enumAtt = property.Attribute as DesignerPropertyEnum; if (enumAtt != null) { enumtype = property.Property.PropertyType; } if (enumtype == null) { throw new Exception(string.Format(Resources.ExceptionDesignerAttributeExpectedEnum, property.Property.Name)); } Nodes.Behavior behavior = GetBehavior(); _agentType = (behavior != null) ? behavior.AgentType : null; object propertyMember = property.Property.GetValue(obj, null); VariableDef variable = propertyMember as VariableDef; RightValueDef variableRV = propertyMember as RightValueDef; if (variable != null && variable.ValueClass != VariableDef.kSelf) { _valueOwner = variable.ValueClass; _agentType = Plugin.GetInstanceAgentType(_valueOwner, behavior, _agentType); } if (variableRV != null && variableRV.ValueClassReal != VariableDef.kSelf) { _valueOwner = variableRV.ValueClassReal; _agentType = Plugin.GetInstanceAgentType(_valueOwner, behavior, _agentType); } string selectionName = string.Empty; if (variable != null && variable.Property != null) { selectionName = variable.Property.DisplayName; } else if (variableRV != null && variableRV.Var != null && variableRV.Var.Property != null) { selectionName = variableRV.Var.Property.DisplayName; } this.FilterType = null; if (enumAtt != null) { if (enumAtt.DependedProperty != "") { Type objType = _object.GetType(); PropertyInfo pi = objType.GetProperty(enumAtt.DependedProperty); object propMember = pi.GetValue(obj, null); VariableDef var = propMember as VariableDef; if (var != null) { this.FilterType = var.ValueType; } else { MethodDef method = propMember as MethodDef; if (method != null) { this.FilterType = method.ReturnType; } else { RightValueDef varRV = propMember as RightValueDef; if (varRV != null) { this.FilterType = varRV.ValueType; } } } } else { this.FilterType = enumAtt.FilterType; } } setComboBox(selectionName); //after the left is changed, the right might need to be invalidated if (this.comboBox.Text != selectionName) { property.Property.SetValue(_object, null, null); } }
protected VariableDef parsePropertyVar(NodeTag.DefaultObject node, string str) { Debug.Check(!str.StartsWith("const")); string[] tokens = str.Split(' '); if (tokens.Length < 2) { return(null); } string propertyType = string.Empty; string propertyName = string.Empty; if (tokens[0] == "static") { Debug.Check(tokens.Length == 3); //e.g. static int Property; propertyType = tokens[1]; propertyName = tokens[2]; } else { Debug.Check(tokens.Length == 2); //e.g. int Property; propertyType = tokens[0]; propertyName = tokens[1]; } VariableDef v = null; int pointIndex = propertyName.IndexOf('.'); if (pointIndex > -1) { string ownerName = propertyName.Substring(0, pointIndex); propertyName = propertyName.Substring(pointIndex + 1, propertyName.Length - pointIndex - 1); AgentType agentType = node.Behavior.AgentType; agentType = Plugin.GetInstanceAgentType(ownerName, agentType); string valueType = (agentType == node.Behavior.AgentType) ? VariableDef.kSelf : agentType.ToString(); v = setProperty(agentType, propertyName, valueType); } else { string className = Plugin.GetClassName(propertyName); // Assume it was World type. if (className != null) { v = setProperty(Plugin.GetInstanceAgentType(className), propertyName, className); if (v == null) { Nodes.Behavior behavior = node.Behavior as Nodes.Behavior; if (behavior != null) { // Assume it was Agent type. v = setProperty(behavior.AgentType, propertyName, VariableDef.kSelf); } } } } if (v == null) { // It should be Par type. v = setParameter(node, propertyType, propertyName); } return(v); }
public static VariableDef parsePropertyVar(List <Nodes.Node.ErrorCheck> result, DefaultObject node, string str) { Debug.Check(!str.StartsWith("const")); List <string> tokens = SplitTokens(str); if (tokens.Count < 2) { return(null); } string arrayIndexStr = string.Empty; string propertyType = string.Empty; string propertyName = string.Empty; if (tokens[0] == "static") { if (tokens.Count == 3) { //e.g. static int Property; propertyType = tokens[1]; propertyName = tokens[2]; } else { Debug.Check(tokens.Count == 4); //e.g. static int Property[int Property1]; propertyType = tokens[1]; propertyName = tokens[2] + "[]"; arrayIndexStr = tokens[3]; } } else { if (tokens.Count == 2) { //e.g. int Property; propertyType = tokens[0]; propertyName = tokens[1]; } else { Debug.Check(tokens.Count == 3); //e.g. int Property; propertyType = tokens[0]; propertyName = tokens[1] + "[]"; arrayIndexStr = tokens[2]; } } AgentType agentType = node.Behavior.AgentType; // Convert the Par to the Property if (!propertyName.Contains(".") && !propertyName.Contains(":")) { propertyName = "Self." + agentType.AgentTypeName + "::" + propertyName; } VariableDef v = null; Nodes.Behavior behavior = node.Behavior as Nodes.Behavior; int pointIndex = propertyName.IndexOf('.'); if (pointIndex > -1) { string ownerName = propertyName.Substring(0, pointIndex); propertyName = propertyName.Substring(pointIndex + 1, propertyName.Length - pointIndex - 1); agentType = Plugin.GetInstanceAgentType(ownerName, behavior, agentType); string valueType = ownerName; v = setProperty(result, node, agentType, propertyName, arrayIndexStr, valueType); } else { string className = Plugin.GetClassName(propertyName); // Assume it was global type. if (className != null) { v = setProperty(result, node, Plugin.GetInstanceAgentType(className, behavior, agentType), propertyName, arrayIndexStr, className); if (v == null && behavior != null) { // Assume it was Agent type. v = setProperty(result, node, behavior.AgentType, propertyName, arrayIndexStr, VariableDef.kSelf); } } } return(v); }