예제 #1
0
        /// <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();
            }
        }
예제 #2
0
파일: Parser.cs 프로젝트: tedwen/binxeditor
 /// <summary>
 /// Parse and load a union element type
 /// </summary>
 /// <param name="reader"></param>
 /// <returns></returns>
 protected static UnionNode LoadUnion(XmlTextReader reader)
 {
     string vname = reader.GetAttribute("varName");
     string blocksize = reader.GetAttribute("blockSize");
     UnionNode ut = new UnionNode();
     if (vname != null)
     {
         ut.setVarName( vname );
     }
     if (blocksize != null)
     {
         ut.setBlockSize( Convert.ToInt32(blocksize) );
     }
     bool inDiscriminantSection = false;
     bool inCaseSection = false;
     string dv = null;
     while (reader.Read())
     {
         if (reader.NodeType == XmlNodeType.Element)
         {
             if (reader.LocalName.Equals("discriminant"))
             {
                 inDiscriminantSection = true;
             }
             else if (reader.LocalName.Equals("case"))
             {
                 inCaseSection = true;
                 dv = reader.GetAttribute("discriminantValue");
             }
             else
             {
                 AbstractNode it = ParseNode(reader);
                 if (inDiscriminantSection)
                 {
                     ut.setDiscriminantType( it.getTypeName() );
                 }
                 else if (inCaseSection)
                 {
                     CaseNode c = new CaseNode(dv, it);
                     ut.addCase(c);
                 }
             }
         }
         else if (reader.NodeType == XmlNodeType.EndElement)
         {
             if (reader.LocalName.Equals("discriminant"))
             {
                 inDiscriminantSection = false;
             }
             else if (reader.LocalName.Equals("case"))
             {
                 inCaseSection = false;
             }
             else if (reader.LocalName.Equals("union"))
             {
                 break;
             }
         }
     }
     return ut;
 }
예제 #3
0
        /// <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();
            }
        }
예제 #4
0
 /// <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();
     }
 }
예제 #5
0
파일: Parser.cs 프로젝트: tedwen/binxeditor
        /// <summary>
        /// Parse and load a union element type
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        protected static UnionNode LoadUnion(XmlTextReader reader)
        {
            string    vname     = reader.GetAttribute("varName");
            string    blocksize = reader.GetAttribute("blockSize");
            UnionNode ut        = new UnionNode();

            if (vname != null)
            {
                ut.setVarName(vname);
            }
            if (blocksize != null)
            {
                ut.setBlockSize(Convert.ToInt32(blocksize));
            }
            bool   inDiscriminantSection = false;
            bool   inCaseSection         = false;
            string dv = null;

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.LocalName.Equals("discriminant"))
                    {
                        inDiscriminantSection = true;
                    }
                    else if (reader.LocalName.Equals("case"))
                    {
                        inCaseSection = true;
                        dv            = reader.GetAttribute("discriminantValue");
                    }
                    else
                    {
                        AbstractNode it = ParseNode(reader);
                        if (inDiscriminantSection)
                        {
                            ut.setDiscriminantType(it.getTypeName());
                        }
                        else if (inCaseSection)
                        {
                            CaseNode c = new CaseNode(dv, it);
                            ut.addCase(c);
                        }
                    }
                }
                else if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName.Equals("discriminant"))
                    {
                        inDiscriminantSection = false;
                    }
                    else if (reader.LocalName.Equals("case"))
                    {
                        inCaseSection = false;
                    }
                    else if (reader.LocalName.Equals("union"))
                    {
                        break;
                    }
                }
            }
            return(ut);
        }
예제 #6
0
        /// <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();
            }
        }
예제 #7
0
 /// <summary>
 /// Add a UnionCase instance
 /// </summary>
 /// <param name="c"></param>
 public void addCase(CaseNode c)
 {
     cases_.Add(c);
 }
예제 #8
0
 /// <summary>
 /// Insert a case at position
 /// </summary>
 /// <param name="index"></param>
 /// <param name="c"></param>
 public void insertCase(int index, CaseNode c)
 {
     cases_.Insert(index, c);
 }
예제 #9
0
 /// <summary>
 /// Insert a case at position
 /// </summary>
 /// <param name="index"></param>
 /// <param name="c"></param>
 public void insertCase(int index, CaseNode c)
 {
     cases_.Insert(index, c);
 }
예제 #10
0
 /// <summary>
 /// Add a UnionCase instance
 /// </summary>
 /// <param name="c"></param>
 public void addCase(CaseNode c)
 {
     cases_.Add(c);
 }