Esempio n. 1
0
        private void AddProp(SymbolDef current, PropertyDef pd, String text, XmlNode node)
        {
            if (pd.IsAttribute())
            {
                XmlAttribute aNode = doc.CreateAttribute(pd.Name);
                aNode.Value = text;
                node.Attributes.Append(aNode);
            }
            else
            {
                // fix namespace issue (if property was issued from a different context)
                String propName = pd.Name;
                if (pd.SymbolContext != null &&
                    pd.SymbolContext != current)
                {
                    propName = pd.SymbolContext.Name + "." + propName;
                }

                //
                // create property as enclosed element
                XmlNode pNode = doc.CreateElement("", propName.TrimEnd(), "");
                XmlNode tNode = doc.CreateTextNode(text);
                pNode.AppendChild(tNode);
                node.AppendChild(pNode);
            }
        }
Esempio n. 2
0
        private void ParseElement(SymbolDef current, XmlNode node)
        {
            int tagNumber = reader.ReadInt32() - 1;

            if (tagNumber == -1)
            {
                return;                         // shit happens
            }
            if (tagNumber < 0 || tagNumber > ntags)
            {
                throw new SPBException("Invalid tag index " + tagNumber);
            }

            DefinitionElement tagType = tags[tagNumber];

            if (tagType is SetDef)
            {
                SetDef set = (SetDef)tagType;
                ParseSet(current, set, node);
            }
            else if (tagType is PropertyDef)
            {
                PropertyDef pd = (PropertyDef)tagType;
                ParseProperty(current, pd, node);
            }
            else
            {
                throw new SPBException("Unexpected tag type : " + tagType.GetType().Name);
            }
        }
Esempio n. 3
0
        private void ParseSet(SymbolDef current, SetDef set, XmlNode node)
        {
            int  setSize     = reader.ReadInt32();
            long endPosition = reader.BaseStream.Position + setSize;

            XmlNode setNode;

            // compare SetDefs
            if (current == null || set.Parent != current)
            {
                // switch symbols
                setNode = doc.CreateElement("", set.Parent.Name + "." + set.Name, "");
                current = set.Parent;
            }
            else
            {
                setNode = doc.CreateElement("", set.Name, "");
            }


            node.AppendChild(setNode);
            while (reader.BaseStream.Position < endPosition)
            {
                ParseElement(current, setNode);
            }
        }
Esempio n. 4
0
        public bool AddSymbolDefinitionFile(string url)
        {
            // extract directory
            string dirName = new FileInfo(url).Directory.Parent.FullName;

            XmlDocument doc = new XmlDocument();

            doc.Load(url);

            foreach (XmlNode n in doc.GetElementsByTagName("SymbolDef"))
            {
                // pre-read name
                XmlAttribute attr = n.Attributes["name"];
                if (attr != null && !symbolDefsNames.Contains(attr.Value))
                {
                    SymbolDef sd = new SymbolDef(dirName, n);
                    symbolDefsNames.Add(attr.Value);
                    symbolDefs.Add(sd);
                }
            }

            return(true);
        }
Esempio n. 5
0
        private void ParseProperty(SymbolDef current, PropertyDef prop, XmlNode node)
        {
            TypeDef type = prop.Type;

            switch (type.Name)
            {
            case "TEXT":
            case "MLTEXT":
            {
                int    stringLen = reader.ReadInt32();
                string s;
                if (stringLen <= 0)
                {
                    s = "";
                }
                else
                {
                    s = TextDecode.Decode(reader.ReadBytes(stringLen));
                }
                AddProp(current, prop, s, node);
            }
            break;

            case "ULONG":
            {
                uint uv = reader.ReadUInt32();
                AddProp(current, prop, Convert.ToString(uv), node);
            }
            break;

            case "LONG":
            {
                int v = reader.ReadInt32();
                AddProp(current, prop, Convert.ToString(v), node);
            }
            break;

            case "LONG2":
            {
                int v1 = reader.ReadInt32();
                int v2 = reader.ReadInt32();
                AddProp(current, prop, v1 + "," + v2, node);
            }
            break;

            case "LONG4":
            {
                int v1 = reader.ReadInt32();
                int v2 = reader.ReadInt32();
                int v3 = reader.ReadInt32();
                int v4 = reader.ReadInt32();
                AddProp(current, prop, v1 + "," + v2 + "," + v3 + "," + v4, node);
            }
            break;

            case "BOOL":
            {
                int v = reader.ReadInt32();
                AddProp(current, prop, (v == 1) ? "true" : "false", node);
            }
            break;

            case "FLOAT":
            {
                float f = reader.ReadSingle();
                AddProp(current, prop, f.ToString(DEC_FORMAT), node);
            }
            break;

            case "FLOAT2":
            {
                float f1 = reader.ReadSingle();
                float f2 = reader.ReadSingle();
                AddProp(current, prop, f1.ToString(DEC_FORMAT) + "," + f2.ToString(DEC_FORMAT), node);
            }
            break;

            case "FLOAT4":
            {
                float f1 = reader.ReadSingle();
                float f2 = reader.ReadSingle();
                float f3 = reader.ReadSingle();
                float f4 = reader.ReadSingle();
                AddProp(current, prop, f1.ToString(DEC_FORMAT) + "," +
                        f2.ToString(DEC_FORMAT) + "," +
                        f3.ToString(DEC_FORMAT) + "," +
                        f4.ToString(DEC_FORMAT), node);
            }
            break;

            case "DOUBLE":
            {
                double v = reader.ReadDouble();
                AddProp(current, prop, v.ToString(DEC_FORMAT), node);
            }
            break;

            case "BYTE4":
            {
                byte b1 = reader.ReadByte();
                byte b2 = reader.ReadByte();
                byte b3 = reader.ReadByte();
                byte b4 = reader.ReadByte();
                AddProp(current, prop, b1 + "," + b2 + "," + b3 + "," + b4, node);
            }
            break;

            case "GUID":
            {
                byte[] gd = reader.ReadBytes(16);
                Guid   g  = new Guid(gd);
                if (models != null)
                {
                    string modelName = models.Lookup(g);
                    if (modelName != null)
                    {
                        XmlComment com = doc.CreateComment("Model: " + modelName);
                        node.AppendChild(com);
                    }
                }
                AddProp(current, prop, "{" + new Guid(gd).ToString().ToUpper() + "}", node);
            }
            break;

            case "PBH":
            case "PBH32":
            {
                double p = reader.ReadUInt32() / ((double)65536 * 65536) * 360.0;
                double b = reader.ReadUInt32() / ((double)65536 * 65536) * 360.0;
                double h = reader.ReadUInt32() / ((double)65536 * 65536) * 360.0;
                // pad
                reader.ReadInt32();
                AddProp(current, prop, p.ToString(DEC_FORMAT) + "," + b.ToString(DEC_FORMAT) + "," + h.ToString(DEC_FORMAT), node);
            }
            break;

            case "ENUM":
            {
                EnumDef enumDef = prop.Enum;
                if (enumDef == null)
                {
                    throw new SPBException("Enum type without values");
                }
                int    idx = reader.ReadInt32();
                string val = enumDef[idx];
                AddProp(current, prop, val, node);
            }
            break;

            case "LLA":
            {
                long lat  = reader.ReadInt64();
                long lon  = reader.ReadInt64();
                uint alt1 = reader.ReadUInt32();
                int  alt2 = reader.ReadInt32();
                LLA  l    = new LLA(lat, lon, alt1, alt2);
                AddProp(current, prop, l.ToString("D2"), node);
            }
            break;

            case "FILETIME":
            {
                // TODO: filetime
            }
            break;

            default:
                throw new SPBException("Don't know how to format type " + type.Type + " at " + reader.BaseStream.Position);
            }
        }