示例#1
0
        private void UpdateFormat(ref FormatState state, StringBuilder data)
        {
            char[] trimChars = { ',' };
            switch (state)
            {
            case FormatState.Idle:
            {
                var str = BoardUtil.SplitLine(data, 1);
                switch (str[0].ToLowerInvariant())
                {
                case "board":
                    if (data.ToString().Contains("INCH units"))
                    {
                        InchUnits = true;
                    }
                    break;

                case "user":
                    str = BoardUtil.SplitLine(data, 8);
                    var loc = new Vector2();
                    loc.X          = ParseDouble(str[3].TrimEnd(trimChars));
                    loc.Y          = ParseDouble(str[5].TrimEnd(trimChars));
                    OriginLocation = loc;
                    OriginTurn     = ParseDouble(str[7].TrimEnd(trimChars));
                    break;

                case "x":
                    state = FormatState.ContourVertex;
                    break;
                }
                break;
            }

            case FormatState.ContourVertex:
            {
                // update contour
                var str     = BoardUtil.SplitLine(data, 2);
                var newVert = new Vector2(ParseDouble(str[0]), ParseDouble(str[1]));
                if (TopContour.Count > 0 && TopContour[TopContour.Count - 1] == newVert)
                {
                    break;
                }
                TopContour.Add(newVert);
                break;
            }
            }
        }
示例#2
0
        private void Update(ref State currentState, string data)
        {
            if (data.Length == 0)
            {
                currentState = State.Idle;
                return;
            }
            switch (currentState)
            {
            case State.Idle:
            {
                var str = BoardUtil.SplitLine(data.ToLowerInvariant());
                switch (str[0])
                {
                case "brdout:":
                    currentState = State.Format;
                    break;

                case "nets:":
                    currentState = State.Nets;
                    netNames     = new string[int.Parse(str[1])];
                    break;

                case "parts:":
                    currentState   = State.Parts;
                    Parts.Capacity = int.Parse(str[1]);
                    break;

                case "pins:":
                    currentState  = State.Pins;
                    Pins.Capacity = int.Parse(str[1]);
                    break;

                case "nails:":
                    currentState   = State.Nails;
                    Nails.Capacity = int.Parse(str[1]);
                    break;

                default:
                    break; // leave in idle state
                }
                break;
            }

            case State.Format: // update contour
            {
                var str = BoardUtil.SplitLine(data);
                if (str.Length != 2)
                {
                    throw new InvalidDataException();
                }
                var newVert = new Vector2(int.Parse(str[0]), int.Parse(str[1]));
                if (TopContour.Count > 0 && TopContour[TopContour.Count - 1] == newVert)
                {
                    break;
                }
                TopContour.Add(newVert);
                break;
            }

            case State.Nets:
            {
                var str = BoardUtil.SplitLine(data);
                int id  = int.Parse(str[0]) - 1;
                netNames[id] = str[1];
                break;
            }

            case State.Parts: // update partsTest
            {
                // 0     1    2   3    4    5    6
                // J3200 6765 430 9462 1386 8754 1
                // name  ?     ?   ?   ?    fp   side
                var str = BoardUtil.SplitLine(data);
                if (str.Length != 7)
                {
                    throw new InvalidDataException();
                }
                var part = new Part();
                part.Name = str[0];
                if (part.Name == "...")
                {
                    part.Name = string.Empty;
                }
                part.Side     = BoardUtil.GetSide(int.Parse(str[6]));
                part.FirstPin = int.Parse(str[5]);
                if (prevPart != null)
                {
                    prevPart.PinCount = part.FirstPin - prevPart.FirstPin;
                }
                Parts.Add(part);
                prevPart = part;
                break;
            }

            case State.Pins:                         // update pins
            {
                var str = BoardUtil.SplitLine(data); // X Y net side
                if (str.Length != 4)
                {
                    throw new InvalidDataException();
                }
                var pin = new Pin();
                pin.Location = new Vector2(int.Parse(str[0]), int.Parse(str[1]));
                pin.Net      = int.Parse(str[2]);
                pin.Side     = BoardUtil.GetSide(int.Parse(str[3]));
                if (pin.Side == (BoardSide.Top))
                {
                    pin.Location = new Vector2(pin.Location.X, -pin.Location.Y);
                }
                if (pin.Net == 0)
                {
                    if (prevNet == 0)
                    {
                        throw new InvalidDataException();
                    }
                    pin.Net = prevNet;
                }
                //pin.PartIndex = int.Parse(str[3]);
                pin.Name = netNames[pin.Net - 1];
                Pins.Add(pin);
                prevNet = pin.Net;
                break;
            }

            case State.Nails: // update nails
            {
                // net, x, y, side?, name
                // id, x, y, net, side
                var str = BoardUtil.SplitLine(data);
                if (str.Length != 5)
                {
                    throw new InvalidDataException();
                }
                var nail = new Nail();
                nail.Id       = int.Parse(str[0]);
                nail.Location = new Vector2(int.Parse(str[1]), int.Parse(str[2]));
                nail.Net      = int.Parse(str[3]);
                nail.Side     = BoardUtil.GetSide(int.Parse(str[4]));
                if (nail.Side == (BoardSide.Top))
                {
                    nail.Location = new Vector2(nail.Location.X, -nail.Location.Y);
                }
                nail.Name = netNames[nail.Net];
                if (nail.Name == "...")
                {
                    nail.Name = string.Empty;
                }
                Nails.Add(nail);
                break;
            }
            }
        }
示例#3
0
        private void Update(ref State currentState, StringBuilder data)
        {
            if (data.Length == 0)
            {
                currentState = State.Idle;
                return;
            }
            switch (currentState)
            {
            case State.Idle:
                switch (data.ToString())
                {
                case "str_length:":
                    currentState = State.StrLength;
                    break;

                case "var_data:":
                    currentState = State.VarData;
                    break;

                case "Format:":
                    currentState = State.Format;
                    break;

                case "Parts:":
                    currentState = State.Parts;
                    break;

                case "Pins:":
                    currentState = State.Pins;
                    break;

                case "Nails:":
                    currentState = State.Nails;
                    break;

                default:
                    break; // leave in idle state
                }
                break;

            case State.StrLength: // XXX: wtf is this?
                break;

            case State.VarData: // XXX: wtf is this?
                break;

            case State.Format: // update contour
            {
                var str     = BoardUtil.SplitLine(data, 2);
                var newVert = new Vector2(int.Parse(str[0]), int.Parse(str[1]));
                if (TopContour.Count > 0 && TopContour[TopContour.Count - 1] == newVert)
                {
                    break;
                }
                TopContour.Add(newVert);
                break;
            }

            case State.Parts: // update partsTest
            {
                var str  = BoardUtil.SplitLine(data, 3);
                var part = new Part();
                part.Name = str[0];
                if (part.Name == "...")
                {
                    part.Name = string.Empty;
                }
                part.Side       = BoardUtil.GetSide(int.Parse(str[1]));
                part.FirstPin   = prevPartLastPin + 1;
                part.PinCount   = int.Parse(str[2]) - part.FirstPin;
                prevPartLastPin = part.FirstPin + part.PinCount - 1;
                if (part.Name.Length == 0 && part.PinCount == 1)
                {
                    nailParts.Add(part);
                    break;
                }
                Parts.Add(part);
                break;
            }

            case State.Pins: // update pins
            {
                var str = BoardUtil.SplitLine(data, 5);
                var pin = new Pin();
                pin.Location = new Vector2(int.Parse(str[0]), int.Parse(str[1]));
                pin.Net      = int.Parse(str[2]);
                //pin.PartIndex = int.Parse(str[3]);
                pin.Name = str[4];
                Pins.Add(pin);
                break;
            }

            case State.Nails: // update nails
            {
                // net, x, y, side?, name
                var str  = BoardUtil.SplitLine(data, 5);
                var nail = new Nail();
                nail.Location = new Vector2(int.Parse(str[1]), int.Parse(str[2]));
                nail.Net      = int.Parse(str[0]);
                nail.Side     = BoardUtil.GetSide(int.Parse(str[3]));
                nail.Name     = str[4];
                if (nail.Name == "...")
                {
                    nail.Name = string.Empty;
                }
                Nails.Add(nail);
                break;
            }
            }
        }