private void addRowControl(PropertyDef property, ParInfo par) { this.tableLayoutPanel.RowCount++; this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); int rowIndex = _rowControls.Count + 1; RowControl rowControl = new RowControl(); _rowControls.Add(rowControl); rowControl.NameLabel = new System.Windows.Forms.Label(); rowControl.NameLabel.Dock = System.Windows.Forms.DockStyle.Fill; rowControl.NameLabel.Margin = new System.Windows.Forms.Padding(0); rowControl.NameLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; rowControl.NameLabel.Text = (property != null) ? property.Name : par.Name; this.tableLayoutPanel.Controls.Add(rowControl.NameLabel, 0, rowIndex); rowControl.TypeLabel = new System.Windows.Forms.Label(); rowControl.TypeLabel.Dock = System.Windows.Forms.DockStyle.Fill; rowControl.TypeLabel.Margin = new System.Windows.Forms.Padding(0); rowControl.TypeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; rowControl.TypeLabel.Text = Plugin.GetNativeTypeName((property != null) ? property.Type.ToString() : par.TypeName); this.tableLayoutPanel.Controls.Add(rowControl.TypeLabel, 1, rowIndex); rowControl.ValueEditor = createPropertyEditor(property, par); rowControl.ValueEditor.Dock = System.Windows.Forms.DockStyle.Fill; rowControl.ValueEditor.Margin = new System.Windows.Forms.Padding(0); this.tableLayoutPanel.Controls.Add(rowControl.ValueEditor, 2, rowIndex); }
private void addButton_Click(object sender, EventArgs e) { ParInfo par = new ParInfo(_rootNode); using (ParSettingsDialog parSettingsDialog = new ParSettingsDialog()) { parSettingsDialog.SetPar(par, _rootNode, true); if (DialogResult.OK == parSettingsDialog.ShowDialog()) { par.ParameterSet -= parameter_ParameterSet; par.ParameterSet += parameter_ParameterSet; par.Copy(parSettingsDialog.GetPar()); _rootNode.Pars.Add(par); _isParReady = false; { this.Hide(); addRowControl(par); this.Show(); } _isParReady = true; PropertiesDock.UpdatePropertyGrids(); _rootNode.OnPropertyValueChanged(true); UndoManager.Save((Nodes.Behavior)_rootNode); } } }
public Type GetValueType() { if (_valueClass == kConst || _valueClass == kPar) { if (_value != null) { ParInfo parInfo = _value as ParInfo; if (parInfo != null) { VariableDef var = parInfo.Variable; if (var != null) { return(var.GetValueType()); } } else { return(_value.GetType()); } } } else if (_property != null) { return(_property.Type); } return(null); }
private void setRootNode(Nodes.Node root) { _isParReady = false; this.Hide(); if (_rootNode != null) { for (int i = 0; i < _rootNode.Pars.Count; ++i) { ParInfo parameter = _rootNode.Pars[i]; parameter.ParameterSet -= parameter_ParameterSet; } deleteAllRowControls(); } _rootNode = root; if (_rootNode != null) { for (int i = 0; i < _rootNode.Pars.Count; ++i) { ParInfo parameter = _rootNode.Pars[i]; parameter.ParameterSet -= parameter_ParameterSet; parameter.ParameterSet += parameter_ParameterSet; addRowControl(_rootNode.Pars[i]); } } this.Show(); _isParReady = true; }
public string GetExportValue(object obj) { Debug.Check(_bParamFromStruct); ParInfo par = this._value as ParInfo; if (par != null) { return(par.GetExportValue()); } VariableDef var = this._value as VariableDef; if (var != null) { return(var.GetExportValue()); } object o = obj; //if (o == null) //{ // o = this._object; //} //if (o != null && this._bParamFromStruct) //{ // object m = this._property.GetValue(o); // return this._attribute.GetExportValue(o, m); //} return(this._attribute.GetExportValue(o, this._value)); }
public static void PostGenerateCode(Behaviac.Design.MethodDef.Param param, StringWriter stream, string indent, string typename, string var, string caller, object parent, string setValue) { Behaviac.Design.ParInfo par = param.Value as Behaviac.Design.ParInfo; if (par != null) { ParInfoCsExporter.PostGenerateCode(par, null, stream, indent, typename, var, caller); return; } Behaviac.Design.VariableDef v = param.Value as Behaviac.Design.VariableDef; if (v != null) { VariableCsExporter.PostGenerateCode(v, stream, indent, typename, var, caller, parent, param.Name, setValue); return; } Type type = param.Value.GetType(); if (Plugin.IsCustomClassType(type) && !DesignerStruct.IsPureConstDatum(param.Value, parent, param.Name)) { StructCsExporter.PostGenerateCode(param.Value, stream, indent, var, parent, param.Name); } }
public bool ResetPar(ParInfo par, string name) { foreach (MethodDef.Param param in this.Params) { if (param.Value is VariableDef) { VariableDef var = param.Value as VariableDef; return(var.ResetPar(par, name)); } else if (param.Value is ParInfo) { if (par != null && par.GetExportValue() == ((ParInfo)(param.Value)).GetExportValue()) { // If the name is empty, it means clearing the par. if (string.IsNullOrEmpty(name)) { param.Value = null; } else { ((ParInfo)(param.Value)).Name = name; } return(true); } } } return(false); }
private void createValueEditor(Type type) { Type editorType = Plugin.InvokeEditorType(type); Debug.Check(editorType != null); ParInfo par = this._property as ParInfo; if (_property.Variable == null || _property.Variable.GetValueType() != type) { _property.Variable = new VariableDef(Plugin.DefaultValue(type)); } _valueEditor = (DesignerPropertyEditor)editorType.InvokeMember(string.Empty, System.Reflection.BindingFlags.CreateInstance, null, null, new object[0]); _valueEditor.Margin = new System.Windows.Forms.Padding(0); _valueEditor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; _valueEditor.Width = this.dispTextBox.Width; _valueEditor.Location = this.dispTextBox.Location; _valueEditor.Location = new Point(_valueEditor.Location.X, _valueEditor.Location.Y - _valueEditor.Height - 6); _valueEditor.ValueWasChanged += new DesignerPropertyEditor.ValueChanged(editor_ValueWasChanged); if (par != null) { _valueEditor.SetPar(par, null); } else { _valueEditor.SetVariable(this._property.Variable, null); } _valueEditor.ValueWasAssigned(); this.Controls.Add(_valueEditor); _valueEditor.BringToFront(); }
public void SetPar(ParInfo par, Nodes.Node rootNode, bool isNewPar) { Debug.Check(par != null && rootNode != null); _isNewPar = isNewPar; _initialized = false; this.Text = isNewPar ? Resources.NewPar : Resources.EditPar; _par = par; _parTemp = par.Clone(); _rootNode = rootNode; setParTypes(); if (par != null) { _isArray = Plugin.IsArrayType(par.Type); Type type = _isArray ? par.Type.GetGenericArguments()[0] : par.Type; nameTextBox.Text = par.Name; arrayCheckBox.Checked = _isArray; typeComboBox.Text = getTypeName(type); descTextBox.Text = par.Description; setValue(type); } enableOkButton(); _initialized = true; }
public void SetPar(ParInfo par, Nodes.Node rootNode, bool isNewPar) { Debug.Check(par != null && rootNode != null); _isNewPar = isNewPar; _initialized = false; this.Text = isNewPar ? Resources.NewPar : Resources.EditPar; _par = par; _parTemp = par.Clone(); _rootNode = rootNode; setParTypes(); if (par != null) { _isArray = Plugin.IsArrayType(par.Type); Type type = _isArray ? par.Type.GetGenericArguments()[0] : par.Type; nameTextBox.Text = par.Name; arrayCheckBox.Checked = _isArray; typeComboBox.Text = Plugin.GetMemberValueTypeName(type); descTextBox.Text = par.BasicDescription; setValue(type); } enableOkButton(); _initialized = true; }
public ParInfo Clone(Nodes.Node node = null) { ParInfo par = new ParInfo(this); if (node != null) { par._node = node; } return(par); }
public bool CheckPar(ParInfo par) { if (_valueClass == kPar && _value is ParInfo) { if (par.GetExportValue() == ((ParInfo)(_value)).GetExportValue()) { return(true); } } return(false); }
public void Copy(ParInfo other) { _node = other._node; _name = other._name; _eventParam = other._eventParam; _typeName = other._typeName; _description = other._description; if (other._variable != null) { _variable = (VariableDef)other._variable.Clone(); } }
public bool CheckPar(ParInfo par) { if (m_var != null) { return(m_var.CheckPar(par)); } else if (m_method != null) { return(m_method.CheckPar(par)); } return(false); }
public bool ResetPar(ParInfo par, string name) { if (m_var != null) { return(m_var.ResetPar(par, name)); } if (m_method != null) { return(m_method.ResetPar(par, name)); } return(false); }
private void okButton_Click(object sender, EventArgs e) { Debug.Check(_parTemp != null && !string.IsNullOrEmpty(_parTemp.Name) && _rootNode != null); ParInfo p = _rootNode.Pars.Find(delegate(ParInfo par) { return(par.Name == _parTemp.Name); }); if (p == null || !_isNewPar && p == _par) { _isParExisted = false; } else { _isParExisted = true; } }
public static string GenerateCode(DefaultObject defaultObj, Behaviac.Design.MethodDef.Param param, StreamWriter stream, string indent, string typename, string var, string caller) { Behaviac.Design.ParInfo par = param.Value as Behaviac.Design.ParInfo; if (par != null) { return(ParInfoCppExporter.GenerateCode(par, param.IsRef, stream, indent, typename, var, caller)); } Behaviac.Design.VariableDef v = param.Value as Behaviac.Design.VariableDef; if (v != null) { return(VariableCppExporter.GenerateCode(defaultObj, v, param.IsRef, stream, indent, typename, var, caller)); } return(DataCppExporter.GenerateCode(param.Value, defaultObj, stream, indent, typename, var, caller)); }
private void parameter_ParameterSet(Nodes.Node node, ParInfo par) { if (!_isParReady) { return; } RowControl rowControl = _rowControls.Find(delegate(RowControl row) { return(row.Par == par); }); if (rowControl != null) { rowControl.NameTextBox.Text = par.Name; rowControl.TypeTextBox.Text = Plugin.GetNativeTypeName(par.Type, true); rowControl.DefaultValueEditor.SetPar(par, node); rowControl.DescTextBox.Text = par.Description; } }
public bool CheckPar(ParInfo par) { foreach (MethodDef.Param param in this.Params) { if (param.Value is VariableDef) { VariableDef var = param.Value as VariableDef; return(var.CheckPar(par)); } else if (param.Value is ParInfo) { if (par.GetExportValue() == ((ParInfo)(param.Value)).GetExportValue()) { return(true); } } } return(false); }
private DesignerPropertyEditor createPropertyEditor(PropertyDef property, ParInfo par) { Type type = (property != null) ? property.Type : par.Variable.GetValueType(); Type editorType = Plugin.InvokeEditorType(type); Debug.Check(editorType != null); DesignerPropertyEditor editor = (DesignerPropertyEditor)editorType.InvokeMember(string.Empty, BindingFlags.CreateInstance, null, null, new object[0]); editor.TabStop = false; editor.Dock = System.Windows.Forms.DockStyle.Fill; editor.Margin = new System.Windows.Forms.Padding(0); editor.ValueWasChanged += new DesignerPropertyEditor.ValueChanged(editor_ValueWasChanged); VariableDef var = (par != null && par.Variable != null) ? par.Variable : new VariableDef(Plugin.DefaultValue(type)); editor.SetVariable(var, null); editor.ValueWasAssigned(); return(editor); }
public bool ResetPar(ParInfo par, string name) { if (_valueClass == kPar && _value is ParInfo) { if (par != null && par.GetExportValue() == ((ParInfo)(_value)).GetExportValue()) { // If the name is empty, it means clearing the par. if (string.IsNullOrEmpty(name)) { _value = null; } else { ((ParInfo)(_value)).Name = name; } return(true); } } return(false); }
public static void ResetPar(Node node, ParInfo par, string newName) { try { // self resetPar(node, par, newName); // attachment foreach (Attachments.Attachment attach in node.Attachments) { resetPar(attach, par, newName); } foreach (BaseNode child in node.Children) { if (child is Node && !(child is ReferencedBehaviorNode)) { Node childNode = child as Node; ResetPar(childNode, par, newName); } } } catch { } }
public ParInfo(ParInfo other) { Copy(other); }
private static void resetPar(NodeTag.DefaultObject obj, ParInfo par, string newName) { Node node = getNode(obj); if (node != null && par != null) { Type type = obj.GetType(); foreach (PropertyInfo property in type.GetProperties()) { try { object value = property.GetValue(obj, null); if (value != null) { if (property.PropertyType == typeof(MethodDef)) { MethodDef method = value as MethodDef; Debug.Check(method != null); method.ResetPar(par, newName); } else if (property.PropertyType == typeof(VariableDef)) { VariableDef var = value as VariableDef; Debug.Check(var != null); var.ResetPar(par, newName); } else if (property.PropertyType == typeof(RightValueDef)) { RightValueDef rv = value as RightValueDef; Debug.Check(rv != null); rv.ResetPar(par, newName); } } } catch { } } } }
public static object CloneValue(object value) { object clone = value; if (value != null) { if (value is VariableDef) { clone = new VariableDef((VariableDef)value); } else if (value is RightValueDef) { clone = ((RightValueDef)value).Clone(); } else if (value is ParInfo) { clone = new ParInfo((ParInfo)value); } else { Type type = value.GetType(); if (Plugin.IsArrayType(type)) { clone = Plugin.CreateInstance(type); System.Collections.IList listValue = (System.Collections.IList)value; System.Collections.IList listClone = (System.Collections.IList)clone; foreach (object item in listValue) { object cloneValue = CloneValue(item); listClone.Add(cloneValue); } } else if (Plugin.IsCustomClassType(type)) { clone = Plugin.CreateInstance(type); try { foreach (PropertyInfo property in type.GetProperties()) { object cloneValue = CloneValue(property.GetValue(value, null)); property.SetValue(clone, cloneValue, null); } } catch { } } } } // Primitive type return clone; }
public static void CheckPar(Node node, ParInfo par, ref List<Node.ErrorCheck> result) { try { // self checkPar(node, par, ref result); // attachment foreach(Attachments.Attachment attach in node.Attachments) { checkPar(attach, par, ref result); } // children foreach(BaseNode child in node.GetChildNodes()) { if (child is Node && !(child is ReferencedBehaviorNode)) { Node childNode = child as Node; CheckPar(childNode, par, ref result); } } } catch (Exception ex) { MessageBox.Show(ex.Message, Resources.LoadError, MessageBoxButtons.OK); } }
/// <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); }
public override void OnPropertyValueChanged(DesignerPropertyInfo property) { if (property.Property.Name == "Prototype") { List <ParInfo> pars = ((Behavior)(this.Behavior)).LocalVars; bool bLoop = true; //remove old added local variables while (bLoop) { int index = pars.FindIndex((p) => p.Name.IndexOf(LOCAL_TASK_PARAM_PRE) != -1); if (index != -1) { pars.RemoveAt(index); } else { bLoop = false; } } for (int i = 0; i < this._task.Params.Count; ++i) { var param = this._task.Params[i]; string par_name = string.Format("{0}{1}", LOCAL_TASK_PARAM_PRE, i); ParInfo par = new ParInfo(this, this.Behavior != null ? this.Behavior.AgentType : null); par.IsAddedAutomatically = true; par.Name = par_name; par.DisplayName = param.DisplayName; par.TypeName = param.Type.FullName; par.Variable = new VariableDef(param.Value); par.Description = param.Description; par.Display = false; pars.Add(par); } } }
public void Copy(ParInfo other) { _node = other._node; _name = other._name; _eventParam = other._eventParam; _typeName = other._typeName; _description = other._description; if (other._variable != null) _variable = (VariableDef)other._variable.Clone(); }
public static object CloneValue(object value) { object clone = value; if (value != null) { if (value is VariableDef) { clone = new VariableDef((VariableDef)value); } else if (value is RightValueDef) { clone = ((RightValueDef)value).Clone(); } else if (value is ParInfo) { clone = new ParInfo((ParInfo)value); } else { Type type = value.GetType(); if (Plugin.IsArrayType(type)) { clone = Plugin.CreateInstance(type); System.Collections.IList listValue = (System.Collections.IList)value; System.Collections.IList listClone = (System.Collections.IList)clone; foreach(object item in listValue) { object cloneValue = CloneValue(item); listClone.Add(cloneValue); } } else if (Plugin.IsCustomClassType(type)) { clone = Plugin.CreateInstance(type); try { foreach(PropertyInfo property in type.GetProperties()) { object cloneValue = property.GetValue(value, null); if (property.PropertyType != type) { cloneValue = CloneValue(cloneValue); } if (property.CanWrite) { property.SetValue(clone, cloneValue, null); } else { DesignerProperty[] attributes = (DesignerProperty[])property.GetCustomAttributes(typeof(DesignerProperty), false); if (attributes.Length > 0) { Debug.Check(attributes[0].HasFlags(DesignerProperty.DesignerFlags.ReadOnly)); } } } } catch { } } } } // Primitive type return clone; }
private void deleteButton_Click(object sender, EventArgs e) { List <int> referredIndexes = new List <int>(); List <int> deletedIndexes = new List <int>(); List <Node.ErrorCheck> errorResult = new List <Node.ErrorCheck>(); for (int rowIndex = _rowControls.Count - 1; rowIndex >= 0; --rowIndex) { RowControl rowControl = _rowControls[rowIndex]; if (rowControl.SelectCheckBox.Checked) { ParInfo par = _rootNode.Pars[rowIndex]; List <Node.ErrorCheck> result = new List <Node.ErrorCheck>(); Plugin.CheckPar(_rootNode, par, ref result); if (result.Count > 0) { referredIndexes.Add(rowIndex); errorResult.AddRange(result); } else { deletedIndexes.Add(rowIndex); } } } if (referredIndexes.Count > 0) { errorResult.Reverse(); referredIndexes.Reverse(); string pars = string.Empty; for (int i = 0; i < referredIndexes.Count; ++i) { int rowIndex = referredIndexes[i]; ParInfo par = _rootNode.Pars[rowIndex]; if (string.IsNullOrEmpty(pars)) { pars += par.Name; } else { pars += ", " + par.Name; } } Debug.Check(BehaviorTreeViewDock.LastFocused != null); string groupLabel = string.Format("Par(s) {0} can not be deleted, which the following nodes are using.", pars); BehaviorTreeViewDock.LastFocused.BehaviorTreeView.ShowErrorDialog("Par Delete Error", groupLabel, errorResult); } if (deletedIndexes.Count > 0) { for (int i = 0; i < deletedIndexes.Count; ++i) { int rowIndex = deletedIndexes[i]; ParInfo par = _rootNode.Pars[rowIndex]; par.ParameterSet -= parameter_ParameterSet; _rootNode.Pars.RemoveAt(rowIndex); this.Hide(); deleteRowControl(rowIndex); this.Show(); PropertiesDock.UpdatePropertyGrids(); _rootNode.OnPropertyValueChanged(true); } UndoManager.Save((Nodes.Behavior)_rootNode); } }
public bool CheckPar(ParInfo par) { if (_valueClass == kPar && _value is ParInfo) { if (par.GetExportValue() == ((ParInfo)(_value)).GetExportValue()) return true; } return false; }
public bool CheckPar(ParInfo par) { if (m_var != null) { return m_var.CheckPar(par); } if (m_method != null) { return m_method.CheckPar(par); } return false; }
public VariableDef(VariableDef other) { if (other == null) { Value = null; } else { _property = null; if (other._property != null) { if (other._property.IsPar && other._property is ParInfo) { _property = new ParInfo(other._property as ParInfo); } else { _property = new PropertyDef(other._property); } } _value = Plugin.CloneValue(other._value); ValueClass = other._valueClass; if (other.m_arrayIndexElement != null) { m_arrayIndexElement = new MethodDef.Param(other.m_arrayIndexElement); } } }
private static void checkPar(DefaultObject obj, ParInfo par, ref List<Node.ErrorCheck> result) { Node node = getNode(obj); if (node != null && par != null) { Type type = obj.GetType(); foreach(PropertyInfo property in type.GetProperties()) { try { object value = property.GetValue(obj, null); if (value != null) { if (property.PropertyType == typeof(MethodDef)) { MethodDef method = value as MethodDef; Debug.Check(method != null); if (method.CheckPar(par)) { result.Add(new Node.ErrorCheck(node, ErrorCheckLevel.Error, "Par as a parameter of the method.")); } } else if (property.PropertyType == typeof(VariableDef)) { VariableDef var = value as VariableDef; Debug.Check(var != null); if (var.CheckPar(par)) { result.Add(new Node.ErrorCheck(node, ErrorCheckLevel.Error, "Par as a value.")); } } else if (property.PropertyType == typeof(RightValueDef)) { RightValueDef rv = value as RightValueDef; Debug.Check(rv != null); if (rv.CheckPar(par)) { result.Add(new Node.ErrorCheck(node, ErrorCheckLevel.Error, "Par as a right value.")); } } } } catch { } } } }
public ParInfo(ParInfo other) { Copy(other); }
private RowControl addRowControl(ParInfo par) { Debug.Check(par != null); RowControl rowControl = new RowControl(); _rowControls.Add(rowControl); int rowIndex = _rowControls.Count; rowControl.Par = par; rowControl.SelectCheckBox = new System.Windows.Forms.CheckBox(); rowControl.SelectCheckBox.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(65)))), ((int)(((byte)(65)))), ((int)(((byte)(65))))); rowControl.SelectCheckBox.ForeColor = System.Drawing.Color.LightGray; rowControl.SelectCheckBox.FlatAppearance.MouseDownBackColor = Color.DarkGray; rowControl.SelectCheckBox.FlatAppearance.MouseOverBackColor = Color.DarkGray; rowControl.SelectCheckBox.Dock = System.Windows.Forms.DockStyle.Fill; rowControl.SelectCheckBox.CheckAlign = ContentAlignment.MiddleCenter; rowControl.SelectCheckBox.Margin = new System.Windows.Forms.Padding(0); this.tableLayoutPanel.Controls.Add(rowControl.SelectCheckBox, 0, rowIndex); rowControl.NameTextBox = new System.Windows.Forms.TextBox(); rowControl.NameTextBox.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(65)))), ((int)(((byte)(65)))), ((int)(((byte)(65))))); rowControl.NameTextBox.ForeColor = System.Drawing.Color.LightGray; rowControl.NameTextBox.BorderStyle = BorderStyle.None; rowControl.NameTextBox.Dock = System.Windows.Forms.DockStyle.Fill; rowControl.NameTextBox.Margin = new System.Windows.Forms.Padding(3); rowControl.NameTextBox.Text = par.Name; rowControl.NameTextBox.KeyDown += new KeyEventHandler(NameTextBox_KeyDown); rowControl.NameTextBox.LostFocus += new EventHandler(NameTextBox_LostFocus); this.tableLayoutPanel.Controls.Add(rowControl.NameTextBox, 1, rowIndex); rowControl.TypeTextBox = new System.Windows.Forms.TextBox(); rowControl.TypeTextBox.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(65)))), ((int)(((byte)(65)))), ((int)(((byte)(65))))); rowControl.TypeTextBox.ForeColor = System.Drawing.Color.LightGray; rowControl.TypeTextBox.BorderStyle = BorderStyle.None; rowControl.TypeTextBox.ReadOnly = true; rowControl.TypeTextBox.Dock = System.Windows.Forms.DockStyle.Fill; rowControl.TypeTextBox.Margin = new System.Windows.Forms.Padding(3); rowControl.TypeTextBox.Text = Plugin.GetNativeTypeName(par.Type, true); rowControl.TypeTextBox.MouseDoubleClick += new MouseEventHandler(TypeTextBox_MouseDoubleClick); this.tableLayoutPanel.Controls.Add(rowControl.TypeTextBox, 2, rowIndex); rowControl.DefaultValueEditor = createValueEditor(rowIndex - 1, par.Type); this.tableLayoutPanel.Controls.Add(rowControl.DefaultValueEditor, 3, rowIndex); rowControl.DescTextBox = new System.Windows.Forms.TextBox(); rowControl.DescTextBox.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(65)))), ((int)(((byte)(65)))), ((int)(((byte)(65))))); rowControl.DescTextBox.ForeColor = System.Drawing.Color.LightGray; rowControl.DescTextBox.BorderStyle = BorderStyle.None; rowControl.NameTextBox.Height = 24; rowControl.DescTextBox.Dock = System.Windows.Forms.DockStyle.Fill; rowControl.DescTextBox.Margin = new System.Windows.Forms.Padding(3); rowControl.DescTextBox.Text = par.Description; rowControl.DescTextBox.KeyDown += new KeyEventHandler(DescTextBox_KeyDown); rowControl.DescTextBox.LostFocus += new EventHandler(DescTextBox_LostFocus); this.tableLayoutPanel.Controls.Add(rowControl.DescTextBox, 4, rowIndex); this.tableLayoutPanel.RowCount++; this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); return(rowControl); }
public bool ResetPar(ParInfo par, string name) { foreach (MethodDef.Param param in this.Params) { if (param.Value is VariableDef) { VariableDef var = param.Value as VariableDef; return var.ResetPar(par, name); } else if (param.Value is ParInfo) { if (par != null && par.GetExportValue() == ((ParInfo)(param.Value)).GetExportValue()) { // If the name is empty, it means clearing the par. if (string.IsNullOrEmpty(name)) param.Value = null; else ((ParInfo)(param.Value)).Name = name; return true; } } } return false; }
private DesignerPropertyEditor createPropertyEditor(PropertyDef property, ParInfo par) { Type type = (property != null) ? property.Type : par.Variable.GetValueType(); Type editorType = Plugin.InvokeEditorType(type); Debug.Check(editorType != null); DesignerPropertyEditor editor = (DesignerPropertyEditor)editorType.InvokeMember(string.Empty, BindingFlags.CreateInstance, null, null, new object[0]); editor.TabStop = false; editor.Dock = System.Windows.Forms.DockStyle.Fill; editor.Margin = new System.Windows.Forms.Padding(0); editor.ValueWasChanged += new DesignerPropertyEditor.ValueChanged(editor_ValueWasChanged); VariableDef var = (par != null && par.Variable != null) ? par.Variable : new VariableDef(Plugin.DefaultValue(type)); editor.SetVariable(var, null); editor.ValueWasAssigned(); return editor; }
public bool ResetPar(ParInfo par, string name) { if (_valueClass == kPar && _value is ParInfo) { if (par != null && par.GetExportValue() == ((ParInfo)(_value)).GetExportValue()) { // If the name is empty, it means clearing the par. if (string.IsNullOrEmpty(name)) _value = null; else ((ParInfo)(_value)).Name = name; return true; } } return false; }
private void addRowControl(PropertyDef property, ParInfo par) { this.tableLayoutPanel.RowCount++; this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); int rowIndex = _rowControls.Count + 1; RowControl rowControl = new RowControl(); _rowControls.Add(rowControl); rowControl.NameLabel = new System.Windows.Forms.Label(); rowControl.NameLabel.Dock = System.Windows.Forms.DockStyle.Fill; rowControl.NameLabel.Margin = new System.Windows.Forms.Padding(0); rowControl.NameLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; rowControl.NameLabel.Text = (property != null) ? property.Name : par.Name; this.tableLayoutPanel.Controls.Add(rowControl.NameLabel, 0, rowIndex); rowControl.TypeLabel = new System.Windows.Forms.Label(); rowControl.TypeLabel.Dock = System.Windows.Forms.DockStyle.Fill; rowControl.TypeLabel.Margin = new System.Windows.Forms.Padding(0); rowControl.TypeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; rowControl.TypeLabel.Text = Plugin.GetNativeTypeName((property != null) ? property.Type.ToString() : par.TypeName); this.tableLayoutPanel.Controls.Add(rowControl.TypeLabel, 1, rowIndex); rowControl.ValueEditor = createPropertyEditor(property, par); rowControl.ValueEditor.Dock = System.Windows.Forms.DockStyle.Fill; rowControl.ValueEditor.Margin = new System.Windows.Forms.Padding(0); this.tableLayoutPanel.Controls.Add(rowControl.ValueEditor, 2, rowIndex); }
public bool CheckPar(ParInfo par) { foreach (MethodDef.Param param in this.Params) { if (param.Value is VariableDef) { VariableDef var = param.Value as VariableDef; bool bOk = var.CheckPar(par); if (bOk) { return true; } } else if (param.Value is ParInfo) { if (par.GetExportValue() == ((ParInfo)(param.Value)).GetExportValue()) { return true; } } } return false; }
private void editSelectedPar(int rowIndex) { if (rowIndex < 0 || _rootNode == null) { return; } ParInfo par = _rootNode.Pars[rowIndex]; List <Node.ErrorCheck> result = new List <Node.ErrorCheck>(); Plugin.CheckPar(_rootNode, par, ref result); using (ParSettingsDialog parSettingsDialog = new ParSettingsDialog()) { par.ParameterSet -= parameter_ParameterSet; parSettingsDialog.SetPar(par, _rootNode, false); Type preType = par.Type; string preName = par.Name; if (DialogResult.OK == parSettingsDialog.ShowDialog()) { UndoManager.PreSave(); ParInfo curPar = parSettingsDialog.GetPar(); Type curType = curPar.Type; string curName = curPar.Name; if (preType != curType) { // If this par is used by others if (result.Count > 0) { string info = string.Format("Par {0} is used in some nodes. Are you sure change its type?", preName); if (DialogResult.Cancel == MessageBox.Show(info, "Warning", MessageBoxButtons.OKCancel)) { par.ParameterSet += parameter_ParameterSet; return; } } Plugin.ResetPar(_rootNode, par, string.Empty); } else if (preName != curName) { Plugin.ResetPar(_rootNode, par, curName); } par.Copy(curPar); if (preType != curType) { RowControl rowControl = _rowControls[rowIndex]; rowControl.DefaultValueEditor = createValueEditor(rowIndex, curType); } par.ParameterSet += parameter_ParameterSet; par.OnValueChanged(); PropertiesDock.UpdatePropertyGrids(); _rootNode.OnPropertyValueChanged(true); UndoManager.Save((Nodes.Behavior)_rootNode); UndoManager.PostSave(); BehaviorTreeView behaviorTreeView = BehaviorTreeViewDock.LastFocused.BehaviorTreeView; if (behaviorTreeView != null) { behaviorTreeView.Redraw(); } } else { par.ParameterSet += parameter_ParameterSet; } } }
public bool CheckPar(ParInfo par) { if (_property is ParInfo) { return (par.Name == _property.Name); } return false; }
/// <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); }
public ParInfo Clone(Nodes.Node node = null) { ParInfo par = new ParInfo(this); if (node != null) { par._node = node; } return par; }
public bool ResetPar(ParInfo par, string name) { if (m_var != null) return m_var.ResetPar(par, name); if (m_method != null) return m_method.ResetPar(par, name); return false; }