Ejemplo n.º 1
0
        public LegacyComponent()
        {
            fReference    = new LegacyField(LegacyField.FieldReference);
            fValue        = new LegacyField(LegacyField.FieldValue);
            fPcbFootprint = new LegacyField(LegacyField.FieldPcbFootprint);
            fUserDocLink  = new LegacyField(LegacyField.FieldUserDocLink);

            N         = 1;
            mm        = 1;
            Timestamp = Utils.GetTimeStamp(DateTime.Now);

            UserFields = new List <LegacyField>();
        }
Ejemplo n.º 2
0
        public override void AddOrSetField(string Name, string Value, TextFormat format)
        {
            //
            LegacyField field = null;

            switch (Name)
            {
            case "Ref":
                field = fReference;
                break;

            case "Value":
                field = fValue;
                break;

            case "Footprint":
                field = fPcbFootprint;
                break;

            default:
                if (UserFields != null)
                {
                    foreach (LegacyField ufield in UserFields)
                    {
                        if (string.Compare(ufield.UserName, Name, true) == 0)
                        {
                            field = ufield;
                            break;
                        }
                    }
                }
                break;
            }

            if (field == null)
            {
                // add field
                if (UserFields == null)
                {
                    UserFields = new List <LegacyField>();
                }

                field = new LegacyField();
                UserFields.Add(field);
                field.UserName = Name;
                field.Pos      = new PointF(Position.X, Position.Y);
            }

            field.Value  = Value;
            field.Hidden = !format.Visible;
        }
Ejemplo n.º 3
0
        public bool LoadFromFile(string filename, string path)
        {
            string[] lines;
            int index;
            List<Token> tokens;

            try
            {
                lines = File.ReadAllLines(filename);
            }
            catch
            {
                return false;
            }

            this.Filename = Path.GetFileName(filename);

            Items = new List<sch_item_base>();

            index = 0;

            Version = lines[index++];

            LibNames = new List<string>();
            while ((index < lines.Length) && lines[index].StartsWith("LIBS:"))
            {
                LibNames.Add(StringUtils.After(lines[index], ":"));
                index++;
            }

            while ((index < lines.Length) && lines[index].StartsWith("EELAYER"))
            {
                // skip
                index++;
            }

            // $Descr
            index++;

            Encoding = StringUtils.After(lines[index++], " ");

            tokens = Utils.Tokenise(lines[index++]);
            SheetNumber = tokens[1].IntValue;
            SheetCount = tokens[2].IntValue;

            Title = StringUtils.After(lines[index++], " ");
            Date = StringUtils.After(lines[index++], " ");
            Rev = StringUtils.After(lines[index++], " ");
            Company = StringUtils.After(lines[index++], " ");

            Comment = new List<string>();
            while ((index < lines.Length) && lines[index].StartsWith("Comment"))
            {
                Comment.Add(StringUtils.After(lines[index], " "));
                index++;
            }

            // $EndDescr
            index++;

            while ((index < lines.Length) && !lines[index].StartsWith("$EndSCHEMATC"))
            {
                string type = StringUtils.Before(lines[index], " ");

                string[] fields = lines[index].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                switch (type)
                {
                    case "$Comp":
                        {
                            LegacyComponent comp = new LegacyComponent();
                            index++;

                            // L CONN_18 P4
                            comp.Symbol = new PartSpecifier(StringUtils.GetDsvField(lines[index], " ", 1));
                            comp.Reference = StringUtils.GetDsvField(lines[index], " ", 2);
                            index++;

                            while ((index < lines.Length) && !lines[index].StartsWith("$EndComp"))
                            {
                                string token = StringUtils.Before(lines[index], " ");

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

                                switch (token)
                                {
                                    case "F":
                                        {
                                            LegacyField f = new LegacyField();
                                            //TODO: need to handle quoted strings

                                            f.Number = tokens[1].IntValue;
                                            f.Value = tokens[2].Value;
                                            f.Orientation = tokens[3].Value;
                                            f.Pos = new System.Drawing.PointF(tokens[4].IntValue, tokens[5].IntValue);
                                            f.Size = tokens[6].IntValue;

                                            if (tokens[7].Value == "0001")
                                                f.Hidden = true;
                                            else
                                                f.Hidden = false;

                                            f.HorizJustify = tokens[8].Value;

                                            f.VertJustify = tokens[9].Value[0].ToString();
                                            f.Italic = tokens[9].Value[1].ToString();
                                            f.Bold = tokens[9].Value[2].ToString();

                                            if (tokens.Count > 10)
                                                f.UserName = StringUtils.TrimQuotes(tokens[10].Value);

                                            switch (f.Number)
                                            {
                                                case 0:
                                                    comp.fReference = f;
                                                    //? comp.Reference = f.Value;
                                                    break;
                                                case 1:
                                                    comp.fValue = f;
                                                    comp.Value = f.Value;
                                                    break;
                                                case 2:
                                                    comp.fPcbFootprint = f;
                                                    comp.Footprint = f.Value;
                                                    break;
                                                case 3:
                                                    comp.fUserDocLink = f;
                                                    break;
                                                default:
                                                    if (comp.UserFields == null)
                                                        comp.UserFields = new List<LegacyField>();
                                                    comp.UserFields.Add(f);
                                                    break;
                                            }
                                        }
                                        break;

                                    case "U":
                                        comp.N = tokens[1].IntValue;
                                        comp.mm = tokens[2].IntValue;
                                        comp.Timestamp = tokens[3].Value;
                                        break;

                                    case "P":
                                        comp.Position = new PointF((float)tokens[1].AsFloat(), (float)tokens[2].AsFloat());
                                        break;

                                    case "AR":
                                        AlternateRef aref = new AlternateRef();
                                        string value = StringUtils.After(tokens[1].Value, "=");
                                        aref.Path = StringUtils.TrimQuotes(value);
                                        value = StringUtils.After(tokens[2].Value, "=");
                                        aref.Ref = StringUtils.TrimQuotes(value);
                                        value = StringUtils.After(tokens[3].Value, "=");
                                        aref.Part = StringUtils.TrimQuotes(value);

                                        if (aref.Ref != comp.Reference)
                                        {
                                            if (comp.AltRefs == null)
                                                comp.AltRefs = new List<AlternateRef>();
                                            comp.AltRefs.Add(aref);
                                        }
                                        break;

                                    default:
                                        // skip line
                                        index++;

                                        // look for orientation
                                        string t = lines[index];
                                        t = t.Remove(0, 1);

                                        tokens = Utils.Tokenise(t);
                                        comp.SetOrientation (tokens[0].IntValue, tokens[1].IntValue, tokens[2].IntValue, tokens[3].IntValue);
                                        break;
                                }
                                //skip
                                index++;
                            }
                            index++;

                            if (Components == null)
                                Components = new List<ComponentBase>();

                            if (comp.AltRefs == null)
                                Components.Add(comp);
                            else
                            {
                                AlternateRef aref = comp.AltRefs.Find(x => x.Path == path);
                                if (aref != null)
                                {
                                    //todo: ???
                                }

                                Components.Add(comp);
                            }

                            Items.Add(comp);
                        }
                        break;

                    case "$Sheet":
                        {
                            SheetSpecLegacy sheet = new SheetSpecLegacy();
                            while ((index < lines.Length) && !lines[index].StartsWith("$EndSheet"))
                            {
                                tokens = Utils.Tokenise(lines[index]);
                                string token = StringUtils.Before(lines[index], " ");
                                switch (token)
                                {
                                    case "F0":
                                        sheet.Name = new LegacyField (StringUtils.TrimQuotes(tokens[1].Value), tokens[2].GetValueAsInt());
                                        break;
                                    case "F1":
                                        sheet.Filename = new LegacyField(StringUtils.TrimQuotes(tokens[1].Value), tokens[2].GetValueAsInt());
                                        break;
                                    case "S":
                                        sheet.Position = new PointF((float)tokens[1].AsFloat(), (float)tokens[2].AsFloat());
                                        sheet.Size = new PointF((float)tokens[3].AsFloat(), (float)tokens[4].AsFloat());
                                        break;
                                    case "U":
                                        sheet.Timestamp = tokens[1].Value;
                                        break;
                                    default:
                                        break;
                                }
                                index++;
                            }
                            if (SubSheets == null)
                                SubSheets = new List<SheetSpecLegacy>();
                            SubSheets.Add(sheet);
                            index++;
                        }
                        break;

                    case "Wire":
                    case "Entry":
                        {
                            sch_wire wire = new sch_wire();
                            wire.name = type;
                            wire.type = fields[1];
                            wire.type2 = fields[2];
                            index++;

                            fields = lines[index].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                            wire.start = new Point(int.Parse(fields[0]), int.Parse(fields[1]));
                            wire.end = new Point(int.Parse(fields[2]), int.Parse(fields[3]));
                            index++;

                            Items.Add(wire);
                        }
                        break;

                    case "Text":
                        {
                            sch_text text = new sch_text();
                            text.name = type;
                            text.Type = fields[1];
                            text.Pos = new Point(int.Parse(fields[2]), int.Parse(fields[3]));
                            text.Orientation = int.Parse(fields[4]);
                            text.TextSize = int.Parse(fields[5]);
                            text.Shape = fields[6];
                            text.Param = int.Parse(fields[7]);
                            index++;

                            text.Value = lines[index];
                            index++;

                            Items.Add(text);
                        }
                        break;

                    case "NoConn":
                        sch_NoConnect noconn = new sch_NoConnect();
                        noconn.name = type;
                        noconn.dummy = fields[1];
                        noconn.pos = new Point(int.Parse(fields[2]), int.Parse(fields[3]));

                        Items.Add(noconn);
                        index++;
                        break;

                    case "Connection":
                        sch_Junction junction = new sch_Junction();
                        junction.name = type;
                        junction.dummy = fields[1];
                        junction.Pos = new Point(int.Parse(fields[2]), int.Parse(fields[3]));

                        Items.Add(junction);
                        index++;
                        break;

                    default://oops
                        Console.WriteLine("unrecognised: " + type);
                        index++;
                        break;
                }

                //index++;
            }

            return true;
        }