Ejemplo n.º 1
0
        private void LoadDocFile(string Filename)
        {
            string[] lines;
            int      index;

            try
            {
                lines = File.ReadAllLines(Filename);
                index = 0;
            }
            catch
            {
                return;
            }

            // skip header line
            if ((lines.Length == 0) || !lines[0].StartsWith("EESchema-DOCLIB"))
            {
                return;
            }
            index++;

            while (index < lines.Length)
            {
                if (lines[index].StartsWith("#"))
                {
                    index++;
                }
                else if (lines[index].StartsWith("$CMP"))
                {
                    List <Token> tokens = Utils.Tokenise(lines[index]);

                    Symbol sym = Symbols.Find(x => x.Name == tokens[1].Value);

                    while ((index < lines.Length) && (lines[index] != "$ENDCMP"))
                    {
                        if (sym != null)
                        {
                            tokens = Utils.Tokenise(lines[index]);
                            switch (tokens[0].Value)
                            {
                            case "D": sym.Description = StringUtils.After(lines[index], " "); break;

                            case "K": sym.Keywords = StringUtils.After(lines[index], " "); break;

                            case "F": sym.DataSheetFile = StringUtils.After(lines[index], " "); break;
                            }
                        }

                        index++;
                    }

                    // expecting $ENDCMP
                    if ((index < lines.Length) && (lines[index] == "$ENDCMP"))
                    {
                        index++;
                    }
                } // $ENDCMP
            }
        }
Ejemplo n.º 2
0
        // e.g. ChangeLayer ("Front", "B.Fab") ==> F.Fab
        public static string MakeLayerName(string CuLayer, string layer)
        {
            if (CuLayer.StartsWith("F"))
            {
                CuLayer = "F";
            }
            else if (CuLayer.StartsWith("B"))
            {
                CuLayer = "B";
            }

            if (layer.Contains("."))
            {
                layer = StringUtils.After(layer, ".");
            }

            return(CuLayer + "." + layer);
        }
Ejemplo n.º 3
0
        protected static void AddMapRanges(ref bool[] CharMap, string rangeSpec)
        {
            string [] ranges = rangeSpec.Split(',');
            int       from, to;

            foreach (string s in ranges)
            {
                if (s.StartsWith("'"))
                {
                    string t      = s;
                    string from_s = GetLiteral(ref t);
                    string to_s   = from_s;
                    if (t.StartsWith("-"))
                    {
                        t    = t.Remove(0, 1);
                        to_s = GetLiteral(ref t);
                    }

                    AddMapRange(ref CharMap, (int)from_s[0], (int)to_s[0]);
                }
                else
                {
                    if (s.IndexOf('-') == -1)
                    {
                        from = StringUtils.StringToInteger(s);
                        to   = from;
                        AddMapRange(ref CharMap, from, to);
                    }
                    else
                    {
                        from = StringUtils.StringToInteger(StringUtils.Before(s, "-").Trim());
                        to   = StringUtils.StringToInteger(StringUtils.After(s, "-").Trim());
                        AddMapRange(ref CharMap, from, to);
                    }
                }
            }
        }
Ejemplo n.º 4
0
 private static void ParseLayerName(string layer, ref string prefix, ref string suffix)
 {
     if (layer.Contains("."))
     {
         //return StringUtils.Before(layer, ".") + "." + new_layer;
         prefix = StringUtils.Before(layer, ".");
         suffix = StringUtils.After(layer, ".");
     }
     else
     {
         if (layer == "Front")
         {
             prefix = "F";
         }
         else if (layer == "Back")
         {
             prefix = "B";
         }
         else
         {
             suffix = layer;
         }
     }
 }
Ejemplo n.º 5
0
        void process_file(string filename, bool display, bool create_thumb_file)
        {
            string[] lines      = File.ReadAllLines(filename);
            string   thumb_data = "";
            int      index      = 0;
            string   file_base  = Path.GetFileNameWithoutExtension(filename);

            // ; thumbnail begin 220x124 19588

            // ; Jggg ==
            // ; thumbnail end

            bool   getting_data = false;
            string temp;
            double max_z                = 0;
            string z_line               = "Z0 ";
            string support              = "Unknown";
            string layer_height         = "Unknown";
            string estimated_print_time = "Unknown";

            // ; estimated printing time (normal mode) = 4h 21m 30s
            // ; support_material = 0

            while (index < lines.Length)
            {
                if (lines[index].StartsWith(";"))
                {
                    if (lines[index].Contains("thumbnail begin"))
                    {
                        temp = StringUtils.After(lines[index], "begin ");
                        int dim_x = StringUtils.StringToInteger(StringUtils.Before(temp, "x"));

                        if (dim_x > 16)
                        {
                            getting_data = true;
                        }
                    }
                    else if (getting_data && lines[index].Contains("thumbnail end"))
                    {
                        getting_data = false;
                    }
                    else if (getting_data)
                    {
                        thumb_data += StringUtils.After(lines[index], "; ");
                    }
                    else if (lines[index].Contains("estimated printing time"))
                    {
                        estimated_print_time = StringUtils.After(lines[index], "= ");
                    }
                    else if (lines[index].Contains(" support_material "))
                    {
                        if (StringUtils.After(lines[index], "= ") == "1")
                        {
                            support = "Yes";
                        }
                        else
                        {
                            support = "No";
                        }
                    }
                    else if (lines[index].Contains(" layer_height "))
                    {
                        layer_height = StringUtils.After(lines[index], "= ");
                    }
                }
                else
                {
                    if (lines[index].StartsWith("G1"))
                    {
                        if (lines[index].Contains("Z"))
                        {
                            z_line = lines[index];
                            temp   = StringUtils.After(z_line, "Z");
                            temp   = StringUtils.Before(temp, " ");
                            double val;
                            if (double.TryParse(temp, out val))
                            {
                                max_z = Math.Max(max_z, val);
                            }
                        }
                    }
                }

                index++;
            }

            byte[] data = System.Convert.FromBase64String(thumb_data);

            if (display)
            {
                if (data.Length > 0)
                {
                    MemoryStream stream = new MemoryStream(data);
                    Image        img    = Bitmap.FromStream(stream);

                    Bitmap   bmp = new Bitmap(220 * 2, 124 * 2);
                    Graphics g   = Graphics.FromImage(bmp);

                    g.DrawImage(
                        img,
                        // destination rectangle
                        new Rectangle(0, 0, bmp.Width, bmp.Height),
                        // source
                        0,
                        0,
                        img.Width,
                        img.Height,
                        GraphicsUnit.Pixel);

                    pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                    pictureBox1.Height   = bmp.Height;
                    pictureBox1.Width    = bmp.Width;
                    pictureBox1.Image    = bmp;
                }
                else
                {
                    Bitmap   bmp = new Bitmap(220, 124);
                    Graphics g   = Graphics.FromImage(bmp);
                    g.FillRectangle(Brushes.White, 0, 0, bmp.Width, bmp.Height);

                    StringFormat stringFormat = new StringFormat();
                    stringFormat.Alignment     = StringAlignment.Center;
                    stringFormat.LineAlignment = StringAlignment.Center;
                    Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
                    g.DrawString("No thumbnail available", new Font("Arial", 10), Brushes.Red, rect, stringFormat);

                    pictureBox1.Height = bmp.Height;
                    pictureBox1.Width  = bmp.Width;
                    pictureBox1.Image  = bmp;
                }

                toolStripStatusLabel1.Text = filename;

                textBoxInfo.Clear();
                textBoxInfo.AppendText(string.Format("Height  = {0}", max_z) + Environment.NewLine);
                textBoxInfo.AppendText(string.Format("Support = {0}", support) + Environment.NewLine);
                textBoxInfo.AppendText(string.Format("Layer height = {0}", layer_height) + Environment.NewLine);
                textBoxInfo.AppendText(string.Format("Estimated print time = {0}", estimated_print_time) + Environment.NewLine);
            }

            if (create_thumb_file)
            {
                filename = Path.ChangeExtension(filename, ".png");
                File.WriteAllBytes(filename, data);
            }
        }
Ejemplo n.º 6
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;
        }
Ejemplo n.º 7
0
        public bool LoadFromFile(string Filename)
        {
            bool result = false;

            string[] lines;
            int      index;

            try
            {
                lines = File.ReadAllLines(Filename);
                index = 0;
            }
            catch
            {
                return(false);
            }

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

            Symbols = new List <Symbol>();

            while (index < lines.Length)
            {
                if (lines[index].StartsWith("#"))
                {
                    if (lines[index].StartsWith("#encoding"))
                    {
                        Encoding = StringUtils.After(lines[index], " ");
                    }

                    index++;
                }
                else if (lines[index].StartsWith("DEF"))
                {
                    List <string> symbol_def = new List <string>();

                    while ((index < lines.Length) && (lines[index] != "ENDDEF"))
                    {
                        symbol_def.Add(lines[index]);
                        index++;
                    }

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

                    Symbol sym = Symbol.Parse(symbol_def);

                    if (sym != null)
                    {
                        Symbols.Add(sym);
                    }
                } // DEF
            }

            LoadDocFile(Path.ChangeExtension(Filename, ".dcm"));
            return(result);
        }
Ejemplo n.º 8
0
        public bool LoadFromFile(string Filename)
        {
            bool result = true;

            string[] lines;
            int      index;

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

            index = 0;

            Section section        = null;
            Section global_section = null;

            Item current_key = null;

            Sections = new List <Section>();

            while (index < lines.Length)
            {
                if (lines[index].StartsWith("["))
                {
                    // new section
                    string section_name;
                    section_name = lines[index];
                    section_name = section_name.Substring(1, section_name.Length - 2);
                    section      = new Section();
                    section.Name = section_name;

                    Sections.Add(section);
                    current_key = null;
                }
                else
                {
                    //new Item or continuation
                    string key   = StringUtils.Before(lines[index], "=");
                    string value = StringUtils.After(lines[index], "=");

                    //
                    if (section == null)
                    {
                        if (global_section == null)
                        {
                            global_section = new Section();
                            Sections.Add(global_section);
                        }
                        section = global_section;
                    }
                    //

                    string baseName;
                    int    num;
                    if (ParseKey(key, out baseName, out num))
                    {
                        if (current_key == null)
                        {
                            current_key = new Item();
                            section.Items.Add(current_key);
                        }
                        current_key.KeyName = baseName;
                        current_key.Values.Add(value);
                    }
                    else
                    {
                        section.Items.Add(new Item(key, value));
                        current_key = null;
                    }
                }
                index++;
            }

            return(result);
        }