Ejemplo n.º 1
0
        private PlyElement ReadElement(PlyElementType elementType)
        {
            var propertyValues = new object[elementType.Properties.Count];

            var tokens = new Queue <string>(CurrentLine.Split(' '));

            foreach (var property in elementType.Properties.Values.OrderBy(p => p.Index))
            {
                if (property.IsList)
                {
                    var listElementCount = int.Parse(tokens.Dequeue());
                    var list             = new object[listElementCount];

                    for (var i = 0; i < list.Length; i++)
                    {
                        list[i] = ParseValue(property.TypeName, tokens.Dequeue());
                    }

                    propertyValues[property.Index] = list;
                }
                else
                {
                    propertyValues[property.Index] = ParseValue(property.TypeName, tokens.Dequeue());
                }
            }

            NextLine();
            return(new PlyElement(elementType, propertyValues));
        }
Ejemplo n.º 2
0
        static void VerifySimplePropertiesExist(PlyElementType elementType, params string[] propertyNames)
        {
            foreach (var name in propertyNames) {
                if (!elementType.Properties.ContainsKey(name)) {
                    throw new Exception(
                        string.Format("The element type \"{0}\" does not contain a \"{1}\" property.", elementType.Name, name));
                }

                if (elementType.Properties[name].IsList) {
                    throw new Exception(
                        string.Format("Property \"{1}\" of element type \"{0}\" was expected to be a simple property, not a list.", elementType.Name, name));
                }
            }
        }
Ejemplo n.º 3
0
        static void VerifyListPropertiesExist(PlyElementType elementType, params string[] propertyNames)
        {
            foreach (var name in propertyNames)
            {
                if (!elementType.Properties.ContainsKey(name))
                {
                    throw new Exception(
                              string.Format("The element type \"{0}\" does not contain a \"{1}\" property.", elementType.Name, name));
                }

                if (!elementType.Properties[name].IsList)
                {
                    throw new Exception(
                              string.Format("Property \"{1}\" of element type \"{0}\" was expected to be a list property.", elementType.Name, name));
                }
            }
        }
Ejemplo n.º 4
0
        private PlyElementType ReadElementType()
        {
            var tokens = CurrentLine.Split(' ');

            if (tokens.Length != 3)
            {
                throw new Exception(
                          string.Format(
                              "Incorrect number of tokens in element type line: \"{0}\". "
                              + "Element types should be in the format: \"element <element_type> <element_count>\".", CurrentLine));
            }

            if (tokens[0] != "element")
            {
                throw new Exception("Invalid element type line. Element types must start with the word \"element\".");
            }

            int count;

            if (!int.TryParse(tokens[2], out count))
            {
                throw new Exception(
                          string.Format("Invalid element count: \"{0}\"", tokens[2]));
            }

            var elementType = new PlyElementType {
                Name  = tokens[1],
                Count = count
            };

            while (NextHeaderLine().StartsWith("property"))
            {
                elementType.AddProperty(ReadProperty());
            }

            return(elementType);
        }
Ejemplo n.º 5
0
 public void AddElementType(PlyElementType elementType)
 {
     ElementTypes.Add(elementType.Name, elementType);
 }
Ejemplo n.º 6
0
        private PlyElement ReadElement(PlyElementType elementType)
        {
            var propertyValues = new object[elementType.Properties.Count];

            var tokens = new Queue<string>(CurrentLine.Split(' '));

            foreach(var property in elementType.Properties.Values.OrderBy(p => p.Index)) {
                if (property.IsList) {
                    var listElementCount = int.Parse(tokens.Dequeue());
                    var list = new object[listElementCount];

                    for(var i = 0; i < list.Length; i++) {
                        list[i] = ParseValue(property.TypeName, tokens.Dequeue());
                    }

                    propertyValues[property.Index] = list;
                }
                else {
                    propertyValues[property.Index] = ParseValue(property.TypeName, tokens.Dequeue());
                }
            }

            NextLine();
            return new PlyElement(elementType, propertyValues);
        }
Ejemplo n.º 7
0
        private PlyElementType ReadElementType()
        {
            var tokens = CurrentLine.Split(' ');

            if (tokens.Length != 3)
                throw new Exception(
                    string.Format(
                        "Incorrect number of tokens in element type line: \"{0}\". "
                        + "Element types should be in the format: \"element <element_type> <element_count>\".", CurrentLine));

            if (tokens[0] != "element")
                throw new Exception("Invalid element type line. Element types must start with the word \"element\".");

            int count;
            if (!int.TryParse(tokens[2], out count))
                throw new Exception(
                    string.Format("Invalid element count: \"{0}\"", tokens[2]));

            var elementType = new PlyElementType {
                Name = tokens[1],
                Count = count
            };

            while(NextHeaderLine().StartsWith("property")) {
                elementType.AddProperty(ReadProperty());
            }

            return elementType;
        }
Ejemplo n.º 8
0
 public void AddElementType(PlyElementType elementType)
 {
     ElementTypes.Add(elementType.Name, elementType);
 }