/// <summary> /// Add a dim node to array node or another dim node, if one is available, it is replaced. /// </summary> /// <remarks>If parent node is the ArrayNode or DefineTypeNode of ArrayNode, then /// the new DimNode will replace the original DimNode which is then indented (demoted as the grandchild. /// If the parent node is a DimNode, then its child node is replaced and degraded, or if no child node /// exists, the new node is added as the child.</remarks> /// <param name="parentNode"></param> /// <param name="at"></param> public void addDimNode(DataNode parentNode, int at) { AbstractNode dNode = parentNode.getDataNode(); if (dNode.GetType().Equals(typeof(DefineTypeNode))) { dNode = ((DefineTypeNode)dNode).getBaseType(); } FormDim formDim = new FormDim(); DialogResult r = formDim.ShowDialog(view_); if (r == DialogResult.OK) { string sdname = formDim.DimName; string scount = formDim.DimCount; DimNode dimNode = new DimNode(sdname, scount); ((ComplexNode)dNode).insertChild(dimNode, 0); //at irrelevant for array and dim node DataNode d = new DataNode(dimNode); DataNode old = (DataNode)parentNode.LastNode; if (old != null) { parentNode.Nodes.Remove(old); d.Nodes.Add(old); } parentNode.Nodes.Add(d); 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> /// Add a case node to a union node. /// </summary> /// <param name="parentNode">must be a union node</param> /// <param name="at">position to insert the case node</param> public void addCaseNode(DataNode parentNode, int at) { FormCase formCase = new FormCase(); formCase.DataTypeSource = document_.getTypeNames(); string vname = "case-" + Convert.ToString(parentNode.Nodes.Count); formCase.VarName = vname; DialogResult r = formCase.ShowDialog(view_); if (r == DialogResult.OK) { string sDiscriminantVal = formCase.DiscriminantValue; string sBodyType = formCase.SelectedType; string sBodyVarName = formCase.VarName; CaseNode cn = new CaseNode(sDiscriminantVal, null); DataNode dcn = new DataNode(cn); addChildNode(dcn, sBodyType, sBodyVarName); //parentNode.Nodes.Insert(at, dcn); addChildNode(parentNode, dcn, at); parentNode.ExpandAll(); } }
/// <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 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(); } }
/// <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 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(); } }