예제 #1
0
        public static SymbolField Parse(List <Token> tokens)
        {
            SymbolField result = new SymbolField();

            result.Text.Value          = tokens[1].Value;
            result.Text.Pos            = new Position(tokens[2].IntValue, tokens[3].IntValue);
            result.Text.FontSize       = tokens[4].IntValue;
            result.Text.Pos.Rotation   = tokens[5].Value == "H" ? Orientation_Horiz : Orientation_Vert;;
            result.Text.Visible        = tokens[6].Value == "V";
            result.Text.HorizAlignment = tokens[7].Value;

            result.Text.VertAlignment = tokens[8].Value[0].ToString();
            result.Text.Italic        = tokens[8].Value[1] == 'I';
            result.Text.Bold          = tokens[8].Value[2] == 'B';

            if (tokens.Count > 9)
            {
                result.UserFieldName = tokens[9].Value;
            }

            return(result);
        }
예제 #2
0
        public static Symbol Parse(List <string> lines)
        {
            int          index = 0;
            Symbol       sym   = new Symbol();
            List <Token> tokens;

            // DEF AT89C2051-P IC 0 40 Y Y 1 F N

            while ((index < lines.Count) && (lines[index].StartsWith("#")))
            {
                index++;
            }

            tokens = Utils.Tokenise(lines[index]);

            sym.Name    = tokens[1].Value;
            sym.Visible = true;
            if (sym.Name.StartsWith("~"))
            {
                sym.Visible = false;
                sym.Name    = sym.Name.Substring(1);
            }
            sym.Reference = tokens[2].Value;
            // param 3 is always 0
            sym.Offset        = tokens[4].IntValue;
            sym.ShowPinNumber = tokens[5].Value == "Y";
            sym.ShowPinName   = tokens[6].Value == "Y";
            sym.NumUnits      = tokens[7].IntValue;
            sym.Locked        = tokens[8].Value == "L";
            sym.PowerSymbol   = tokens[9].Value == "P";
            index++;

            //
            while ((index < lines.Count) && (lines[index] != "DRAW"))
            {
                tokens = Utils.Tokenise(lines[index]);

                if (tokens[0].Value.StartsWith("F"))
                {
                    SymbolField text = SymbolField.Parse(tokens);
                    switch (tokens[0].Value)
                    {
                    case "F0": sym.fReference = text; break;

                    case "F1": sym.fValue = text; break;

                    case "F2": sym.fPcbFootprint = text; break;

                    case "F3": sym.fUserDocLink = text; break;

                    default:
                    {
                        int field_index;
                        if (int.TryParse(tokens[0].Value.Substring(1), out field_index))
                        {
                            text.Index = field_index;
                            sym.UserFields.Add(text);
                        }
                    }
                    break;
                    }
                    index++;
                }
                else if (tokens[0].Value == "ALIAS")
                {
                    for (int j = 1; j < tokens.Count; j++)
                    {
                        sym.Alias.Add(tokens[j].Value);
                    }
                    index++;
                }
                else if (tokens[0].Value == "$FPLIST")
                {
                    index++;
                    sym.Footprints = new List <string>();
                    while ((index < lines.Count) && (lines[index] != "$ENDFPLIST"))
                    {
                        sym.Footprints.Add(lines[index].Trim());
                        index++;
                    }
                    if ((index < lines.Count) && (lines[index] == "$ENDFPLIST"))
                    {
                        index++;
                    }
                }
                else
                {
                    // unknown?
                    index++;
                }
            }

            if ((index < lines.Count) && (lines[index] == "DRAW"))
            {
                index++;
                while ((index < lines.Count) && (lines[index] != "ENDDRAW"))
                {
                    tokens = Utils.Tokenise(lines[index]);

                    if ((tokens[0].Value == "X") && (tokens.Count != 12))
                    {
                        if ((tokens.Count == 13) && (tokens[11].Type == TokenType.Name))
                        {
                            sym_drawing_base drawing = sym_drawing_base.Parse(tokens);
                            if (drawing != null)
                            {
                                sym.Drawings.Add(drawing);
                            }
                        }
                        else
                        {
                            Console.WriteLine("{0} invalid pin def {1}:{2}", sym.Name, index, lines[index]);
                        }
                    }
                    else
                    {
                        sym_drawing_base drawing = sym_drawing_base.Parse(tokens);
                        if (drawing != null)
                        {
                            sym.Drawings.Add(drawing);
                        }
                    }

                    // todo:
                    index++;
                }
                if ((index < lines.Count) && (lines[index] == "ENDDRAW"))
                {
                    index++;
                }
            } // DRAW

            // expecting ENDDEF
            if ((index < lines.Count) && (lines[index] == "ENDDEF"))
            {
                index++;
            }

            return(sym);
        }