Example #1
0
        /// <summary>
        /// Insert a useType node into the tree as the child node at the given position.
        /// </summary>
        /// <param name="parentNode"></param>
        /// <param name="at"></param>
        public void addUseTypeNode(DataNode parentNode, int at)
        {
            if (document_.getDefinitions().count() <= 0)
            {
                MessageBox.Show("No user-defined type in the Definitions section.", "Warning");
                return;
            }
            FormData formData = new FormData();

            formData.DataTypeSource = document_.getUserDefinedTypeNames();
            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;
                    UseTypeNode childNode = new UseTypeNode(stype, svar);
                    addChildNode(parentNode, new DataNode(childNode), at++);
                    document_.setModified();
                }
            } while (r == DialogResult.Yes);
        }
Example #2
0
        /// <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);
        }
Example #3
0
        /// <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);
        }
Example #4
0
 /// <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;
 }
Example #5
0
        /// <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);
        }
Example #6
0
 /// <summary>
 /// Insert a useType node into the tree as the child node at the given position.
 /// </summary>
 /// <param name="parentNode"></param>
 /// <param name="at"></param>
 public void addUseTypeNode(DataNode parentNode, int at)
 {
     if (document_.getDefinitions().count() <= 0)
     {
         MessageBox.Show("No user-defined type in the Definitions section.", "Warning");
         return;
     }
     FormData formData = new FormData();
     formData.DataTypeSource = document_.getUserDefinedTypeNames();
     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;
             UseTypeNode childNode = new UseTypeNode(stype, svar);
             addChildNode(parentNode, new DataNode(childNode), at++);
             document_.setModified();
         }
     } while (r == DialogResult.Yes);
 }