/// <summary> /// Create a child node for the given type and add it to a parent /// </summary> /// <remarks>If type is primitive, then create directly, otherwise, call corresponding create windows.</remarks> /// <param name="parentNode"></param> /// <param name="stype"></param> /// <param name="svname"></param> private void addChildNode(DataNode parentNode, string stype, string svname) { if (stype == null || stype.Equals("")) { return; } AbstractNode childNode = null; if (document_.getDataTypes().isPrimitive(stype)) { childNode = new PrimitiveNode(stype, svname); } else if (document_.isTypeDefined(stype)) { childNode = new UseTypeNode(stype, svname); } else if (stype.Equals("struct")) { addStructTypeNode(parentNode, parentNode.Nodes.Count, false); return; } else if (stype.Equals("union")) { addUnionTypeNode(parentNode, parentNode.Nodes.Count, false); return; } else if (stype.StartsWith("array")) { addArrayTypeNode(parentNode, parentNode.Nodes.Count, false); return; } addChildNode(parentNode, new DataNode(childNode), parentNode.Nodes.Count); }
/// <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> /// Parse a node for data types (primitive, complex, useType) /// </summary> /// <param name="reader"></param> /// <returns></returns> protected static AbstractNode ParseNode(XmlTextReader reader) { AbstractNode it = null; string byteOrder = reader.GetAttribute("byteOrder"); if (reader.LocalName.Equals("struct")) { it = LoadStruct(reader); } else if (reader.LocalName.Equals("union")) { it = LoadUnion(reader); } else if (reader.LocalName.StartsWith("array")) { it = LoadArray(reader); } else if (reader.LocalName.Equals("useType")) { string typeName = reader.GetAttribute("typeName"); string blockSize = reader.GetAttribute("blockSize"); it = new UseTypeNode(typeName); if (blockSize != null) { ((UseTypeNode)it).setBlockSize(Convert.ToInt16(blockSize)); } string varName = reader.GetAttribute("varName"); it.setVarName(varName); } else //primitive { string varName = reader.GetAttribute("varName"); it = new PrimitiveNode(reader.LocalName); if (varName != null) { it.setVarName(varName); } } if (byteOrder != null) { it.setBigEndian((byteOrder.Equals("bigEndian"))?true:false); } return(it); }
/// <summary> /// Insert a primitive data type node into the tree as the child node at the given position. /// </summary> /// <param name="parentNode">Parent node to insert a primitive node, can be StructNode or DatasetNode</param> /// <param name="at">Position before which the new node is to be inserted</param> public void addPrimitiveNode(DataNode parentNode, int at) { FormData formData = new FormData(); formData.DataTypeSource = document_.getPrimitiveTypeNames(); DialogResult r = DialogResult.No; int vi = parentNode.Nodes.Count; do { string vn = "var-" + Convert.ToString(++vi); formData.VarName = vn; r = formData.ShowDialog(view_); if (r != DialogResult.Cancel) { string stype = formData.SelectedType; string svar = formData.VarName; PrimitiveNode childNode = new PrimitiveNode(stype, svar); addChildNode(parentNode, new DataNode(childNode), at++); document_.setModified(); } } while (r == DialogResult.Yes); }
/// <summary> /// Parse a node for data types (primitive, complex, useType) /// </summary> /// <param name="reader"></param> /// <returns></returns> protected static AbstractNode ParseNode(XmlTextReader reader) { AbstractNode it = null; string byteOrder = reader.GetAttribute("byteOrder"); if (reader.LocalName.Equals("struct")) { it = LoadStruct(reader); } else if (reader.LocalName.Equals("union")) { it = LoadUnion(reader); } else if (reader.LocalName.StartsWith("array")) { it = LoadArray(reader); } else if (reader.LocalName.Equals("useType")) { string typeName = reader.GetAttribute("typeName"); string blockSize = reader.GetAttribute("blockSize"); it = new UseTypeNode(typeName); if (blockSize != null) { ((UseTypeNode)it).setBlockSize( Convert.ToInt16(blockSize) ); } string varName = reader.GetAttribute("varName"); it.setVarName( varName ); } else //primitive { string varName = reader.GetAttribute("varName"); it = new PrimitiveNode(reader.LocalName); if (varName!=null) { it.setVarName( varName ); } } if (byteOrder != null) { it.setBigEndian( (byteOrder.Equals("bigEndian"))?true:false ); } return it; }
/// <summary> /// Create a child node for the given type and add it to a parent /// </summary> /// <remarks>If type is primitive, then create directly, otherwise, call corresponding create windows.</remarks> /// <param name="parentNode"></param> /// <param name="stype"></param> /// <param name="svname"></param> private void addChildNode(DataNode parentNode, string stype, string svname) { if (stype==null || stype.Equals("")) return; AbstractNode childNode = null; if (document_.getDataTypes().isPrimitive(stype)) { childNode = new PrimitiveNode(stype, svname); } else if (document_.isTypeDefined(stype)) { childNode = new UseTypeNode(stype, svname); } else if (stype.Equals("struct")) { addStructTypeNode(parentNode, parentNode.Nodes.Count, false); return; } else if (stype.Equals("union")) { addUnionTypeNode(parentNode, parentNode.Nodes.Count, false); return; } else if (stype.StartsWith("array")) { addArrayTypeNode(parentNode, parentNode.Nodes.Count, false); return; } addChildNode(parentNode, new DataNode(childNode), parentNode.Nodes.Count); }
/// <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(); } }