void createParamEditor(MethodDef method, bool enable, bool bReadonlyParent) { List <MethodDef.Param> parameters = method.Params; foreach (MethodDef.Param p in parameters) { Type editorType = typeof(DesignerParameterComboEnumEditor); string arugmentsName = " " + p.DisplayName; bool bReadonly = bReadonlyParent | p.Attribute.HasFlags(DesignerProperty.DesignerFlags.ReadOnly); Label label = propertyGrid.AddProperty(arugmentsName, editorType, bReadonly); label.MouseEnter += new EventHandler(label_MouseEnter); DesignerPropertyEditor editor = (DesignerPropertyEditor)label.Tag; if (p.Type.Name == "IList") { lastListParam = p; } if (p.Type.Name == "System_Object" && lastListParam != null) { p.ListParam = lastListParam; } editor.Enabled = enable; editor.SetParameter(p, _selectedObject, bReadonly); editor.ValueWasAssigned(); editor.MouseEnter += editor_MouseEnter; editor.DescriptionWasChanged += editor_DescriptionWasChanged; editor.ValueWasChanged += editor_ValueWasChanged; //editor.ValueType = p.Attribute.ValueType; MethodDef.Param arrayIndexElement = null; if (p.Value is VariableDef) { VariableDef var = p.Value as VariableDef; arrayIndexElement = var.ArrayIndexElement; } else if (p.Value is RightValueDef) { RightValueDef varRV = p.Value as RightValueDef; if (varRV.Var != null) { arrayIndexElement = varRV.Var.ArrayIndexElement; } } if (arrayIndexElement != null) { createArrayIndexEditor(" ", arrayIndexElement); } } }
public static void GenerateClassMember(Behaviac.Design.RightValueDef rightValue, StringWriter stream, string indent, string var) { if (rightValue.IsMethod) { MethodCsExporter.GenerateClassMember(rightValue.Method, stream, indent, var); } else { VariableCsExporter.GenerateClassMember(rightValue.Var, stream, indent, var); } }
public static void PostGenerateCode(Behaviac.Design.RightValueDef rightValue, StringWriter stream, string indent, string typename, string var, string caller, object parent = null, string paramName = "") { if (rightValue.IsMethod) { MethodCppExporter.PostGenerateCode(rightValue.Method, stream, indent, rightValue.Method.NativeReturnType, var, string.Format("(({0}*)pAgent_{1})", rightValue.Method.ClassName, var)); } else { VariableCppExporter.PostGenerateCode(rightValue.Var, stream, indent, typename, var, caller, parent, paramName); } }
public static void GenerateClassConstructor(DefaultObject defaultObj, Behaviac.Design.RightValueDef rightValue, StringWriter stream, string indent, string var) { if (rightValue.IsMethod) { MethodCppExporter.GenerateClassConstructor(defaultObj, rightValue.Method, stream, indent, var); } else { VariableCppExporter.GenerateClassConstructor(defaultObj, rightValue.Var, stream, indent, var); } }
public static string GenerateCode(DefaultObject defaultObj, Behaviac.Design.RightValueDef rightValue, StringWriter stream, string indent, string typename, string var, string caller) { string retStr = string.Empty; if (rightValue.IsMethod) { retStr = MethodCppExporter.GenerateCode(defaultObj, rightValue.Method, stream, indent, rightValue.Method.NativeReturnType, var, caller); } else { retStr = VariableCppExporter.GenerateCode(defaultObj, rightValue.Var, false, stream, indent, typename, var, caller); } return(retStr); }
public object Clone() { RightValueDef clone = new RightValueDef(Var); if (m_var != null) { clone.m_var = (VariableDef)m_var.Clone(); } if (m_method != null) { clone.m_method = (MethodDef)m_method.Clone(); } clone.ValueClass = _valueClass; return(clone); }
public static void GenerateOperand(StreamWriter stream, string indent, RightValueDef operand, string operandName, string nodeName) { if (operand != null) { string typeName = DataCsExporter.GetGeneratedNativeType(operand.ValueType); typeName = typeName.Replace("::", "."); if (operand.IsMethod) // method { RightValueCsExporter.GenerateCode(operand, stream, indent, typeName, operandName, string.Empty); RightValueCsExporter.PostGenerateCode(operand, stream, indent, typeName, operandName, string.Empty); } else { VariableDef var = operand.Var; if (var != null) { if (var.IsProperty) // property { PropertyDef prop = var.Property; if (prop != null) { string property = PropertyCsExporter.GetProperty(prop, var.ArrayIndexElement, stream, indent, operandName, nodeName); string propName = prop.BasicName.Replace("[]", ""); if (prop.IsArrayElement && var.ArrayIndexElement != null) { ParameterCsExporter.GenerateCode(var.ArrayIndexElement, stream, indent, "int", operandName + "_index", nodeName + "_opl"); property = string.Format("({0})[{1}_index]", property, operandName); } stream.WriteLine("{0}{1} {2} = {3};", indent, typeName, operandName, property); } } else if (var.IsConst) // const { RightValueCsExporter.GenerateCode(operand, stream, indent, typeName, operandName, string.Empty); } } } } }
public object Clone() { RightValueDef clone = new RightValueDef(Var); if (m_var != null) { clone.m_var = (VariableDef)m_var.Clone(); } if (m_method != null) { clone.m_method = (MethodDef)m_method.Clone(); } clone.ValueClass = _valueClass; return clone; }
//private void UpdateProperties(IList<DesignerPropertyInfo> properties, List<MethodDef.Param> parameters, string parametersCategory) private void UpdateProperties(IList <DesignerPropertyInfo> properties) { //Console.WriteLine("UpdateProperties"); //this.SuspendLayout(); List <string> categories = new List <string>(); foreach (DesignerPropertyInfo property in properties) { if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoDisplay) && (property.Attribute.CategoryResourceString != "CategoryVersion" || Settings.Default.ShowVersionInfo) && !categories.Contains(property.Attribute.CategoryResourceString)) { categories.Add(property.Attribute.CategoryResourceString); } } categories.Sort(); Nodes.Node node = SelectedObject as Nodes.Node; List <ParInfo> pars = new List <ParInfo>(); bool referrencedPar = false; NodeUIPolicy uiPolicy = null; if (node != null) { node.GetAllPars(ref pars); uiPolicy = NodeUIPolicy.CreateUIPolicy(node); uiPolicy.Initialize(SelectedObject); } else { Attachments.Attach attachment = SelectedObject as Behaviac.Design.Attachments.Attach; if (attachment != null) { node = attachment.Node; referrencedPar = true; attachment.GetAllPars(ref pars); uiPolicy = NodeUIPolicy.CreateUIPolicy(attachment); uiPolicy.Initialize(SelectedObject); } } if (pars.Count > 0 && !categories.Contains("CategoryPar")) { categories.Add("CategoryPar"); } foreach (string category in categories) { propertyGrid.AddCategory(Plugin.GetResourceString(category), true); foreach (DesignerPropertyInfo property in properties) { if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoDisplay) && property.Attribute.CategoryResourceString == category) { Type type = property.Attribute.GetEditorType(property.Property.GetValue(_selectedObject, null)); Label label = propertyGrid.AddProperty(property.Attribute.DisplayName, type, property.Attribute.HasFlags(DesignerProperty.DesignerFlags.ReadOnly)); // register description showing label.MouseEnter += new EventHandler(label_MouseEnter); // when we found an editor we connect it to the object if (type != null) { DesignerPropertyEditor editor = (DesignerPropertyEditor)label.Tag; editor.SetRootNode((Nodes.Node) this._rootBehavior); editor.SetProperty(property, _selectedObject); editor.ValueWasAssigned(); editor.MouseEnter += editor_MouseEnter; editor.DescriptionWasChanged += editor_DescriptionWasChanged; editor.ValueWasChanged += editor_ValueWasChanged; if (uiPolicy != null) { uiPolicy.AddEditor(editor); } } MethodDef method = null; bool methodEditorEnable = true; DesignerMethodEnum propertyMethod = property.Attribute as DesignerMethodEnum; if (propertyMethod != null) { if (propertyMethod.MethodType != MethodType.Status) { method = property.Property.GetValue(_selectedObject, null) as MethodDef; methodEditorEnable = (propertyMethod.MethodType != MethodType.Event); } } else { DesignerRightValueEnum propertyRV = property.Attribute as DesignerRightValueEnum; if (propertyRV != null) { RightValueDef rv = property.Property.GetValue(_selectedObject, null) as RightValueDef; if (rv != null && rv.IsMethod) { method = rv.Method; } } } if (method != null) { createParamEditor(method, methodEditorEnable); } } } if (pars.Count > 0 && "CategoryPar" == category) { createParEditor(pars, referrencedPar ? typeof(DesignerParComboEnumEditor) : typeof(DesignerParEditor)); } } if (uiPolicy != null) { uiPolicy.Update(); } //this.ResumeLayout(false); }
/// <summary> /// Generate the native code for the given value object. /// </summary> /// <param name="obj">The given object.</param> /// <param name="stream">The file stream for generating the codes.</param> /// <param name="indent">The indent string when generating the line of codes.</param> /// <param name="typename">The native type of the variable.</param> /// <param name="var">The variable for the given object when generating the codes.</param> /// <param name="caller">The caller for the method or the agent.</param> /// <returns>Returns the string generated value.</returns> public static string GenerateCode(object obj, StreamWriter stream, string indent, string typename, string var, string caller) { string retStr = string.Empty; if (obj != null) { Type type = obj.GetType(); if (obj is Behaviac.Design.MethodDef) { Behaviac.Design.MethodDef method = obj as Behaviac.Design.MethodDef; retStr = MethodCppExporter.GenerateCode(method, stream, indent, typename, var, caller); } else if (obj is Behaviac.Design.MethodDef.Param) { Behaviac.Design.MethodDef.Param param = obj as Behaviac.Design.MethodDef.Param; retStr = ParameterCppExporter.GenerateCode(param, stream, indent, typename, var, caller); } else if (obj is Behaviac.Design.ParInfo) { Behaviac.Design.ParInfo par = obj as Behaviac.Design.ParInfo; retStr = ParInfoCppExporter.GenerateCode(par, false, stream, indent, typename, var, caller); } else if (obj is Behaviac.Design.PropertyDef) { Behaviac.Design.PropertyDef property = obj as Behaviac.Design.PropertyDef; retStr = PropertyCppExporter.GenerateCode(property, null, false, stream, indent, typename, var, caller); } else if (obj is Behaviac.Design.VariableDef) { Behaviac.Design.VariableDef variable = obj as Behaviac.Design.VariableDef; retStr = VariableCppExporter.GenerateCode(variable, false, stream, indent, typename, var, caller); } else if (obj is Behaviac.Design.RightValueDef) { Behaviac.Design.RightValueDef rightValue = obj as Behaviac.Design.RightValueDef; retStr = RightValueCppExporter.GenerateCode(rightValue, stream, indent, typename, var, caller); } // Array type else if (Plugin.IsArrayType(type)) { retStr = var; if (!string.IsNullOrEmpty(typename)) { stream.WriteLine("{0}{1} {2};", indent, DataCppExporter.GetBasicGeneratedNativeType(typename), var); } else { typename = DataCppExporter.GetGeneratedNativeType(type); } int startIndex = typename.IndexOf('<'); int endIndex = typename.LastIndexOf('>'); string itemType = typename.Substring(startIndex + 1, endIndex - startIndex - 1); ArrayCppExporter.GenerateCode(obj, stream, indent, itemType, var); } // Struct type else if (Plugin.IsCustomClassType(type)) { retStr = var; if (!string.IsNullOrEmpty(typename)) { if (typename.EndsWith("*")) { stream.WriteLine("{0}{1} {2} = NULL;", indent, DataCppExporter.GetBasicGeneratedNativeType(typename), var); } else { stream.WriteLine("{0}{1} {2};", indent, DataCppExporter.GetBasicGeneratedNativeType(typename), var); } } StructCppExporter.GenerateCode(obj, stream, indent, var, null, ""); } // Other types else { retStr = obj.ToString(); if (Plugin.IsStringType(type)) // string { retStr = string.Format("\"{0}\"", retStr); if (typename.StartsWith("behaviac::wstring")) { retStr = string.Format("StringUtils::MBSToWCS({0})", retStr); } else { retStr = string.Format("(char*)({0})", retStr); } } else if (Plugin.IsBooleanType(type)) // bool { retStr = retStr.ToLowerInvariant(); } else if (Plugin.IsEnumType(type)) // enum { retStr = EnumCppExporter.GeneratedCode(obj); } else if (Plugin.IsFloatType(type)) // float { if (retStr.Contains(".") && !retStr.EndsWith("f") && !retStr.EndsWith("F")) { retStr = retStr + "f"; } } if (!string.IsNullOrEmpty(var)) { if (string.IsNullOrEmpty(typename)) { stream.WriteLine("{0}{1} = {2};", indent, var, retStr); } else { typename = DataCppExporter.GetGeneratedNativeType(typename); stream.WriteLine("{0}{1} {2} = {3};", indent, typename, var, retStr); } } } } return(retStr); }
/// <summary> /// Generate code for the given value object. /// </summary> /// <param name="obj">The given object.</param> /// <param name="stream">The file stream for generating the codes.</param> /// <param name="indent">The indent string when generating the line of codes.</param> /// <param name="typename">The native type of the variable.</param> /// <param name="var">The variable for the given object when generating the codes.</param> /// <param name="caller">The caller for the method or the agent.</param> /// <returns>Returns the string generated value.</returns> public static string GenerateCode(object obj, StreamWriter stream, string indent, string typename, string var, string caller, string setValue = null) { string retStr = string.Empty; if (obj != null) { Type type = obj.GetType(); if (obj is Behaviac.Design.MethodDef) { Behaviac.Design.MethodDef method = obj as Behaviac.Design.MethodDef; retStr = MethodCsExporter.GenerateCode(method, stream, indent, typename, var, caller); } else if (obj is Behaviac.Design.MethodDef.Param) { Behaviac.Design.MethodDef.Param param = obj as Behaviac.Design.MethodDef.Param; retStr = ParameterCsExporter.GenerateCode(param, stream, indent, typename, var, caller); } else if (obj is Behaviac.Design.ParInfo) { Behaviac.Design.ParInfo par = obj as Behaviac.Design.ParInfo; retStr = ParInfoCsExporter.GenerateCode(par, false, stream, indent, typename, var, caller); } else if (obj is Behaviac.Design.PropertyDef) { Behaviac.Design.PropertyDef property = obj as Behaviac.Design.PropertyDef; retStr = PropertyCsExporter.GenerateCode(property, null, false, stream, indent, typename, var, caller, setValue); } else if (obj is Behaviac.Design.VariableDef) { Behaviac.Design.VariableDef variable = obj as Behaviac.Design.VariableDef; retStr = VariableCsExporter.GenerateCode(variable, false, stream, indent, typename, var, caller); } else if (obj is Behaviac.Design.RightValueDef) { Behaviac.Design.RightValueDef rightValue = obj as Behaviac.Design.RightValueDef; retStr = RightValueCsExporter.GenerateCode(rightValue, stream, indent, typename, var, caller); } // Array type else if (Plugin.IsArrayType(type)) { retStr = var; if (!string.IsNullOrEmpty(typename)) { stream.WriteLine("{0}{1} {2};", indent, typename, var); } else { typename = DataCsExporter.GetGeneratedNativeType(type); } int startIndex = typename.IndexOf('<'); int endIndex = typename.LastIndexOf('>'); string itemType = typename.Substring(startIndex + 1, endIndex - startIndex - 1); ArrayCsExporter.GenerateCode(obj, stream, indent, itemType, var); } // Struct type else if (Plugin.IsCustomClassType(type)) { retStr = var; if (!string.IsNullOrEmpty(typename)) { stream.WriteLine("{0}{1} {2};", indent, typename, var); } StructCsExporter.GenerateCode(obj, stream, indent, var, null, ""); } // Other types else { retStr = obj.ToString(); if (Plugin.IsStringType(type)) // string { retStr = string.Format("\"{0}\"", retStr); } else if (Plugin.IsCharType(type)) // char { char c = 'A'; if (retStr.Length >= 1) { c = retStr[0]; } retStr = string.Format("\'{0}\'", c); } else if (Plugin.IsBooleanType(type)) // bool { retStr = retStr.ToLowerInvariant(); } else if (Plugin.IsEnumType(type)) // enum { retStr = EnumCsExporter.GeneratedCode(obj); } else if (type == typeof(float)) // float { retStr += "f"; } if (!string.IsNullOrEmpty(var)) { if (string.IsNullOrEmpty(typename)) { stream.WriteLine("{0}{1} = {2};", indent, var, retStr); } else { stream.WriteLine("{0}{1} {2} = {3};", indent, typename, var, retStr); } } } } return(retStr); }
//private void UpdateProperties(IList<DesignerPropertyInfo> properties, List<MethodDef.Param> parameters, string parametersCategory) private void UpdateProperties(IList <DesignerPropertyInfo> properties) { DefaultObject obj = SelectedObject as DefaultObject; if (obj != null) { uiPolicy = obj.CreateUIPolicy(); uiPolicy.Initialize(obj); } List <string> categories = new List <string>(); foreach (DesignerPropertyInfo property in properties) { if (uiPolicy.ShouldAddProperty(property) && !property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoDisplay) && (property.Attribute.CategoryResourceString != "CategoryVersion" || Settings.Default.ShowVersionInfo) && !categories.Contains(property.Attribute.CategoryResourceString)) { categories.Add(property.Attribute.CategoryResourceString); } } categories.Sort(new CategorySorter()); foreach (string category in categories) { propertyGrid.AddCategory(Plugin.GetResourceString(category), true); foreach (DesignerPropertyInfo property in properties) { if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoDisplay) && property.Attribute.CategoryResourceString == category) { if (uiPolicy != null && !uiPolicy.ShouldAddProperty(property)) { continue; } object value_ = property.Property.GetValue(_selectedObject, null); Type type = property.Attribute.GetEditorType(value_); DesignerMethodEnum propertyMethod = property.Attribute as DesignerMethodEnum; if (propertyMethod != null) { if ((propertyMethod.MethodType & MethodType.Task) == MethodType.Task) { type = typeof(DesignerMethodEnumEditor); } } string displayName = property.Attribute.DisplayName; if (uiPolicy != null) { displayName = uiPolicy.GetLabel(property); } Label label = propertyGrid.AddProperty(displayName, type, property.Attribute.HasFlags(DesignerProperty.DesignerFlags.ReadOnly)); // register description showing label.MouseEnter += new EventHandler(label_MouseEnter); // when we found an editor we connect it to the object if (type != null) { DesignerPropertyEditor editor = (DesignerPropertyEditor)label.Tag; editor.SetRootNode((Nodes.Node) this._rootBehavior); editor.SetProperty(property, _selectedObject); editor.ValueWasAssigned(); editor.MouseEnter += editor_MouseEnter; editor.DescriptionWasChanged += editor_DescriptionWasChanged; editor.ValueWasChanged += editor_ValueWasChanged; if (uiPolicy != null) { uiPolicy.AddEditor(editor); } } MethodDef method = null; bool methodEditorEnable = true; if (propertyMethod != null) { if (propertyMethod.MethodType != MethodType.Status) { method = value_ as MethodDef; //methodEditorEnable = (propertyMethod.MethodType != MethodType.Event); } } else { DesignerRightValueEnum propertyRV = property.Attribute as DesignerRightValueEnum; if (propertyRV != null) { RightValueDef rv = value_ as RightValueDef; if (rv != null && rv.IsMethod) { method = rv.Method; } } } if (property.Attribute != null) { if (method != null) { if (property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoDisplayOnProperty)) { //don't dipslay on the property panel } else { bool bReadonly = property.Attribute.HasFlags(DesignerProperty.DesignerFlags.ReadOnlyParams); createParamEditor(method, methodEditorEnable, bReadonly); } } else { MethodDef.Param arrayIndexElement = null; if (value_ is VariableDef) { VariableDef var = value_ as VariableDef; arrayIndexElement = var.ArrayIndexElement; } else if (value_ is RightValueDef) { RightValueDef varRV = value_ as RightValueDef; if (varRV.Var != null) { arrayIndexElement = varRV.Var.ArrayIndexElement; } } if (arrayIndexElement != null) { createArrayIndexEditor(" ", arrayIndexElement); } } } } } } if (uiPolicy != null) { uiPolicy.Update(null, new DesignerPropertyInfo()); } }