コード例 #1
0
        public static LDrawCommand DeserializeCommand(string line, LDrawModel parent)
        {
            LDrawCommand command = null;
            int          type;
            var          args = line.Split(' ');

            //first arg is the command type
            if (Int32.TryParse(args[0], out type))
            {
                var commandType = (CommandType)type;

                switch (commandType)
                {
                case CommandType.SubFile:
                    command = new LDrawSubFile();
                    break;

                case CommandType.Triangle:
                    command = new LDrawTriangle();
                    break;

                case CommandType.Quad:
                    command = new LDrawQuad();
                    break;
                }
            }

            //if it is a valid command
            if (command != null)
            {
                //parse the second arg for color code
                if (!int.TryParse(args[1], out command._ColorCode))
                {
                    command._Color = args[1];
                }
                //set the parent ldraw
                command._Parent = parent;
                command.Deserialize(line);
            }

            return(command);
        }
コード例 #2
0
        public static LDrawCommand DeserializeCommand(string line, LDrawModel parent)
        {
            LDrawCommand command = null;
            int          type;
            var          args = line.Split(' ');

            if (Int32.TryParse(args[0], out type))
            {
                var commandType = (CommandType)type;

                switch (commandType)
                {
                case CommandType.Comment:
                    command = new LDrawComment();
                    break;

                case CommandType.SubFile:
                    command = new LDrawSubFile();
                    break;

                case CommandType.Triangle:
                    command = new LDrawTriangle();
                    break;

                case CommandType.Quad:
                    command = new LDrawQuad();
                    break;
                }
            }

            if (command != null)
            {
                if (!(command is LDrawComment) && !int.TryParse(args[1], out command._ColorCode))
                {
                    command._Color = args[1];
                }
                command._Parent = parent;
                command.Deserialize(line);
            }

            return(command);
        }