/// <summary> /// Add an array data element. /// </summary> /// <param name="parentNode">parent node that contains this new node</param> /// <param name="at">position before which the new node is inserted</param> public void addArrayTypeNode(DataNode parentNode, int at, bool defineType) { FormArray formArray = new FormArray(); if (!defineType) { formArray.Text = "Build an array element"; formArray.ChangeLabel("Var Name:"); formArray.TypeName = "myArray-" + Convert.ToString(parentNode.Nodes.Count); //TODO: check for duplicate names } else { formArray.TypeName = "MyArray-" + Convert.ToString(++typeArrayCounter_); } formArray.DataTypeSource = document_.getTypeNames(); DialogResult r = formArray.ShowDialog(view_); if (r == DialogResult.OK) { string varName = formArray.TypeName; string arrayType = formArray.ArrayTypeName; ArrayNode an = new ArrayNode(arrayType, (defineType)?"":varName); //if variable, add sizeRef if (formArray.ArrayType == 2) { AbstractNode data = new PrimitiveNode(formArray.SizeRef); an.setSizeRef( data ); } AbstractNode aNode = an; if (defineType) { aNode = new DefineTypeNode(formArray.TypeName, an); } DataNode dn = new DataNode(aNode); addChildNode(dn, formArray.DataType, ""); //element data type as first child node of array if (formArray.ArrayType == 3) //arrayStreamed containing only one dim { //an.addDimension("", 0); addChildNode(dn, new DataNode(new DimNode("", 0)), 1); //dim as second child node of array } else //fixed or variable { DataNode tmpNode = dn; foreach (ListViewItem itm in formArray.getDimensions()) { string scount = itm.Text; string sdimname = itm.SubItems[1].Text; if (!scount.Equals("")) { //DataNode dNode = new DataNode(an.addDimension(sdimname, scount)); DataNode dNode = new DataNode(new DimNode(sdimname, scount)); addChildNode(tmpNode, dNode, 1); tmpNode = dNode; } } } addChildNode(parentNode, dn, at); document_.setModified(); parentNode.ExpandAll(); } }
/// <summary> /// Add a struct data element. /// </summary> /// <param name="parentNode">parent node that contains this struct element node</param> /// <param name="at">position where the new struct is inserted before</param> public void addStructTypeNode(DataNode parentNode, int at, bool defineType) { FormStruct formStruct = new FormStruct(); if (defineType) { formStruct.TypeName = "MyStructType-" + Convert.ToString(++typeStructCounter_); } else { formStruct.Text = "Build a struct element"; formStruct.ChangeLabel("Var Name:"); formStruct.TypeName = "myStruct-" + Convert.ToString(parentNode.Nodes.Count); //TODO: check for duplicate name } formStruct.setDataTypeSource(document_.getTypeNames()); DialogResult r = formStruct.ShowDialog(view_); if (r == DialogResult.OK) { string varName = formStruct.TypeName; string blockSize = formStruct.BlockSize; int nBlockSize = 0; try { nBlockSize = Convert.ToInt32(blockSize); } catch (Exception ex) { Console.WriteLine(ex.Message); } StructNode sn = new StructNode((defineType)?"":varName, nBlockSize); AbstractNode aNode = sn; if (defineType) { aNode = new DefineTypeNode(formStruct.TypeName, sn); } DataNode dn = new DataNode(aNode); //collect struct members foreach (ListViewItem itm in formStruct.getMemberItems()) { string stype = itm.Text; string svname = itm.SubItems[1].Text; if (!stype.Equals("")) { addChildNode(dn, stype, svname); } } addChildNode(parentNode, dn, at); document_.setModified(); parentNode.ExpandAll(); } }
/// <summary> /// Load definitions section. /// </summary> /// <param name="reader"></param> protected static void loadDefinitions(XmlTextReader reader, ref DefinitionsNode definitions) { DefineTypeNode ut = null; while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (reader.LocalName.Equals("defineType")) { string sTypename = reader.GetAttribute("typeName"); ut = new DefineTypeNode(sTypename); } else if (reader.LocalName.Equals("struct") && ut != null) { ut.setBaseType(LoadStruct(reader)); } else if (reader.LocalName.Equals("union") && ut != null) { ut.setBaseType(LoadUnion(reader)); } else if (reader.LocalName.StartsWith("array") && ut != null) { ut.setBaseType(LoadArray(reader)); } } else if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName.Equals("defineType") && ut != null) { definitions.addChild(ut); ut = null; } else if (reader.LocalName.Equals(sDefinitions)) { return; } } } }
/// <summary> /// Add a union data element. /// </summary> /// <param name="parentNode">parent that contains this union element</param> /// <param name="at">position where the new node is inserted before</param> /// <param name="defineType">if true invokes a define union type window</param> public void addUnionTypeNode(DataNode parentNode, int at, bool defineType) { FormUnion formUnion = new FormUnion(); if (defineType) { formUnion.TypeName = "MyUnionType-" + Convert.ToString(++typeUnionCounter_); } else { formUnion.Text = "Build a union element"; formUnion.ChangeLabel("Var Name:"); formUnion.TypeName = "myUnion-" + Convert.ToString(parentNode.Nodes.Count); //TODO: check for duplicate name } formUnion.setDataTypeSource(document_.getTypeNames()); DialogResult r = formUnion.ShowDialog(view_); if (r==DialogResult.OK) { string varName = formUnion.TypeName; string discriminantType = formUnion.DiscriminantType; string blockSize = formUnion.BlockSize; int nBlockSize = 0; try { nBlockSize = Convert.ToInt32(blockSize); } catch (Exception ex) { Console.WriteLine(ex.Message); } UnionNode un = new UnionNode((defineType)?"":varName); un.setDiscriminantType(discriminantType); if (nBlockSize > 0) { un.setBlockSize(nBlockSize); } AbstractNode aNode = un; if (defineType) { aNode = new DefineTypeNode(formUnion.TypeName, un); } DataNode dn = new DataNode(aNode); int n = 0; foreach (ListViewItem itm in formUnion.getCases()) { string sval = itm.Text; string stype = itm.SubItems[1].Text; string svname = itm.SubItems[2].Text; if (!stype.Equals("")) { //create a CaseNode CaseNode cn = new CaseNode(sval, null); //add data object as child node and case body of the case node DataNode dcn = new DataNode(cn); addChildNode(dcn, stype, svname); addChildNode(dn, dcn, n++); } } addChildNode(parentNode, dn, at); document_.setModified(); parentNode.ExpandAll(); } }
/// <summary> /// Add a struct data element. /// </summary> /// <param name="parentNode">parent node that contains this struct element node</param> /// <param name="at">position where the new struct is inserted before</param> public void addStructTypeNode(DataNode parentNode, int at, bool defineType) { FormStruct formStruct = new FormStruct(); if (defineType) { formStruct.TypeName = "MyStructType-" + Convert.ToString(++typeStructCounter_); } else { formStruct.Text = "Build a struct element"; formStruct.ChangeLabel("Var Name:"); formStruct.TypeName = "myStruct-" + Convert.ToString(parentNode.Nodes.Count); //TODO: check for duplicate name } formStruct.setDataTypeSource(document_.getTypeNames()); DialogResult r = formStruct.ShowDialog(view_); if (r==DialogResult.OK) { string varName = formStruct.TypeName; string blockSize = formStruct.BlockSize; int nBlockSize = 0; try { nBlockSize = Convert.ToInt32(blockSize); } catch (Exception ex) { Console.WriteLine(ex.Message); } StructNode sn = new StructNode((defineType)?"":varName, nBlockSize); AbstractNode aNode = sn; if (defineType) { aNode = new DefineTypeNode(formStruct.TypeName, sn); } DataNode dn = new DataNode(aNode); //collect struct members foreach (ListViewItem itm in formStruct.getMemberItems()) { string stype = itm.Text; string svname = itm.SubItems[1].Text; if (!stype.Equals("")) { addChildNode(dn, stype, svname); } } addChildNode(parentNode, dn, at); document_.setModified(); parentNode.ExpandAll(); } }
public bool contains(DefineTypeNode node) { return definitions_.Contains(node); }
public int indexOf(DefineTypeNode node) { return definitions_.IndexOf(node); }
public void addDefinition(DefineTypeNode node) { definitions_.addChild(node); }
public void remove(DefineTypeNode node) { definitions_.Remove(node); }
/// <summary> /// Add a union data element. /// </summary> /// <param name="parentNode">parent that contains this union element</param> /// <param name="at">position where the new node is inserted before</param> /// <param name="defineType">if true invokes a define union type window</param> public void addUnionTypeNode(DataNode parentNode, int at, bool defineType) { FormUnion formUnion = new FormUnion(); if (defineType) { formUnion.TypeName = "MyUnionType-" + Convert.ToString(++typeUnionCounter_); } else { formUnion.Text = "Build a union element"; formUnion.ChangeLabel("Var Name:"); formUnion.TypeName = "myUnion-" + Convert.ToString(parentNode.Nodes.Count); //TODO: check for duplicate name } formUnion.setDataTypeSource(document_.getTypeNames()); DialogResult r = formUnion.ShowDialog(view_); if (r == DialogResult.OK) { string varName = formUnion.TypeName; string discriminantType = formUnion.DiscriminantType; string blockSize = formUnion.BlockSize; int nBlockSize = 0; try { nBlockSize = Convert.ToInt32(blockSize); } catch (Exception ex) { Console.WriteLine(ex.Message); } UnionNode un = new UnionNode((defineType)?"":varName); un.setDiscriminantType(discriminantType); if (nBlockSize > 0) { un.setBlockSize(nBlockSize); } AbstractNode aNode = un; if (defineType) { aNode = new DefineTypeNode(formUnion.TypeName, un); } DataNode dn = new DataNode(aNode); int n = 0; foreach (ListViewItem itm in formUnion.getCases()) { string sval = itm.Text; string stype = itm.SubItems[1].Text; string svname = itm.SubItems[2].Text; if (!stype.Equals("")) { //create a CaseNode CaseNode cn = new CaseNode(sval, null); //add data object as child node and case body of the case node DataNode dcn = new DataNode(cn); addChildNode(dcn, stype, svname); addChildNode(dn, dcn, n++); } } addChildNode(parentNode, dn, at); document_.setModified(); parentNode.ExpandAll(); } }
public int indexOf(DefineTypeNode node) { return(definitions_.IndexOf(node)); }
public bool contains(DefineTypeNode node) { return(definitions_.Contains(node)); }
public void add(DefineTypeNode node) { definitions_.Add(node); }
/// <summary> /// Add an array data element. /// </summary> /// <param name="parentNode">parent node that contains this new node</param> /// <param name="at">position before which the new node is inserted</param> public void addArrayTypeNode(DataNode parentNode, int at, bool defineType) { FormArray formArray = new FormArray(); if (!defineType) { formArray.Text = "Build an array element"; formArray.ChangeLabel("Var Name:"); formArray.TypeName = "myArray-" + Convert.ToString(parentNode.Nodes.Count); //TODO: check for duplicate names } else { formArray.TypeName = "MyArray-" + Convert.ToString(++typeArrayCounter_); } formArray.DataTypeSource = document_.getTypeNames(); DialogResult r = formArray.ShowDialog(view_); if (r == DialogResult.OK) { string varName = formArray.TypeName; string arrayType = formArray.ArrayTypeName; ArrayNode an = new ArrayNode(arrayType, (defineType)?"":varName); //if variable, add sizeRef if (formArray.ArrayType == 2) { AbstractNode data = new PrimitiveNode(formArray.SizeRef); an.setSizeRef(data); } AbstractNode aNode = an; if (defineType) { aNode = new DefineTypeNode(formArray.TypeName, an); } DataNode dn = new DataNode(aNode); addChildNode(dn, formArray.DataType, ""); //element data type as first child node of array if (formArray.ArrayType == 3) //arrayStreamed containing only one dim { //an.addDimension("", 0); addChildNode(dn, new DataNode(new DimNode("", 0)), 1); //dim as second child node of array } else //fixed or variable { DataNode tmpNode = dn; foreach (ListViewItem itm in formArray.getDimensions()) { string scount = itm.Text; string sdimname = itm.SubItems[1].Text; if (!scount.Equals("")) { //DataNode dNode = new DataNode(an.addDimension(sdimname, scount)); DataNode dNode = new DataNode(new DimNode(sdimname, scount)); addChildNode(tmpNode, dNode, 1); tmpNode = dNode; } } } addChildNode(parentNode, dn, at); document_.setModified(); parentNode.ExpandAll(); } }
/// <summary> /// Load definitions section. /// </summary> /// <param name="reader"></param> protected static void loadDefinitions(XmlTextReader reader, ref DefinitionsNode definitions) { DefineTypeNode ut = null; while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (reader.LocalName.Equals("defineType")) { string sTypename = reader.GetAttribute("typeName"); ut = new DefineTypeNode(sTypename); } else if (reader.LocalName.Equals("struct") && ut!=null) { ut.setBaseType( LoadStruct(reader) ); } else if (reader.LocalName.Equals("union") && ut!=null) { ut.setBaseType( LoadUnion(reader) ); } else if (reader.LocalName.StartsWith("array") && ut!=null) { ut.setBaseType( LoadArray(reader) ); } } else if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName.Equals("defineType") && ut!=null) { definitions.addChild(ut); ut = null; } else if (reader.LocalName.Equals(sDefinitions)) { return; } } } }