Exemple #1
0
 public void AddFileToSet(string aname, IProgressLog Logger, double drillscaler = 1.0)
 {
     if (Streams.ContainsKey(aname))
     {
         AddFileToSet(Streams[aname], aname, Logger, drillscaler);
     }
     else
     {
         Logger.AddString(String.Format("[ERROR] no stream for {0}!!!", aname));
     }
 }
Exemple #2
0
        public static void MergeAll(List <string> files, string output, IProgressLog log)
        {
            BOMFile result = null;

            foreach (string fileName in files)
            {
                BOMFile bomFile = new BOMFile();
                log.AddString(String.Format("Reading {0}", fileName));
                bomFile.Load(fileName);
                log.AddString(String.Format("Merging {0}", fileName));
                if (result == null)
                {
                    result = bomFile;
                }
                else
                {
                    result.Merge(bomFile);
                }
            }
            log.AddString(String.Format("Writing {0}", output));
            result.WriteCsv(output);
        }
Exemple #3
0
        public static void MergeAll(List <string> files, string output, IProgressLog log)
        {
            PositionFile result = new PositionFile();

            foreach (string fileName in files)
            {
                PositionFile posFile = new PositionFile();
                log.AddString(String.Format("Reading {0}", fileName));
                posFile.Load(fileName);
                log.AddString(String.Format("Merging {0}", fileName));
                result.Merge(posFile);
            }
            log.AddString(String.Format("Writing {0}", output));
            if (output.EndsWith(".csv"))
            {
                result.WriteCsv(output);
            }
            else
            {
                result.WriteKicad(output);
            }
        }
Exemple #4
0
        public static void WriteContainedOnly(string inputfile, PolyLine Boundary, string outputfilename, IProgressLog Log)
        {
            if (File.Exists(inputfile) == false)
            {
                Console.WriteLine("{0} not found! stopping process!", Path.GetFileName(inputfile));
                return;
            }
            Log.AddString(String.Format("Clipping {0} to {1}", Path.GetFileName(inputfile), Path.GetFileName(outputfilename)));

            ExcellonFile EF = new ExcellonFile();

            EF.Load(inputfile);
            EF.WriteContained(Boundary, outputfilename, Log);
        }
Exemple #5
0
        public static void MergeAll(List <string> Files, string output, IProgressLog log)
        {
            if (Files.Count >= 2)
            {
                MultiMerge(Files[0], Files.Skip(1).ToList(), output, log);
                return;
            }
            if (Files.Count < 2)
            {
                if (Files.Count == 1)
                {
                    Console.WriteLine("Merging 1 file is copying... doing so...");
                    if (File.Exists(output))
                    {
                        File.Delete(output);
                    }
                    File.Copy(Files[0], output);
                }
                else
                {
                    Console.WriteLine("Need files to do anything??");
                }
                return;
            }

            string        LastFile  = Files[0];
            List <string> TempFiles = new List <string>();

            for (int i = 1; i < Files.Count - 1; i++)
            {
                string NewFile = Path.GetTempFileName();
                TempFiles.Add(NewFile);
                Merge(LastFile, Files[i], NewFile, log);
                LastFile = NewFile;
            }

            Merge(LastFile, Files.Last(), output, log);
            log.AddString("Removing merge tempfiles");

            foreach (string s in TempFiles)
            {
                File.Delete(s);
            }
        }
Exemple #6
0
        public void CheckRelativeBoundingBoxes(IProgressLog Logger)
        {
            List <ParsedGerber> DrillFiles         = new List <ParsedGerber>();
            List <ParsedGerber> DrillFilesToReload = new List <ParsedGerber>();
            Bounds BB = new Bounds();

            foreach (var a in PLSs)
            {
                if (a.Layer == BoardLayer.Drill)
                {
                    DrillFiles.Add(a);
                }
                else
                {
                    BB.AddBox(a.BoundingBox);
                }
            }

            foreach (var a in DrillFiles)
            {
                if (a.BoundingBox.Intersects(BB) == false)
                {
                    Errors.Add(String.Format("Drill file {0} does not seem to touch the main bounding box!", Path.GetFileName(a.Name)));
                    if (Logger != null)
                    {
                        Logger.AddString(String.Format("Drill file {0} does not seem to touch the main bounding box!", Path.GetFileName(a.Name)));
                    }
                    PLSs.Remove(a);
                }
            }



            BoundingBox = new Bounds();
            foreach (var a in PLSs)
            {
                //   Console.WriteLine("Progress: Adding board {6} to box::{0:N2},{1:N2} - {2:N2},{3:N2} -> {4:N2},{5:N2}", a.BoundingBox.TopLeft.X, a.BoundingBox.TopLeft.Y, a.BoundingBox.BottomRight.X, a.BoundingBox.BottomRight.Y, a.BoundingBox.Width(), a.BoundingBox.Height(), Path.GetFileName(a.Name));


                //Console.WriteLine("adding box for {0}:{1},{2}", a.Name, a.BoundingBox.Width(), a.BoundingBox.Height());
                BoundingBox.AddBox(a.BoundingBox);
            }
        }
Exemple #7
0
        public static void Merge(string file1, string file2, string outputfile, IProgressLog log)
        {
            if (File.Exists(file1) == false)
            {
                Console.WriteLine("{0} not found! stopping process!", file1);
                return;
            }
            if (File.Exists(file2) == false)
            {
                Console.WriteLine("{0} not found! stopping process!", file2);
                return;
            }
            log.AddString(String.Format("*** Merging {0} with {1}", file1, file2));

            Console.WriteLine("*** Reading {0}:", file1);
            ExcellonFile file1Parsed = new ExcellonFile();

            file1Parsed.Load(file1);
            Console.WriteLine("*** Reading {0}:", file2);
            ExcellonFile file2Parsed = new ExcellonFile();

            file2Parsed.Load(file2);

            int MaxID = 0;

            foreach (var D in file1Parsed.Tools)
            {
                if (D.Value.ID > MaxID)
                {
                    MaxID = D.Value.ID + 1;
                }
            }

            foreach (var D in file2Parsed.Tools)
            {
                D.Value.ID += MaxID;
                file1Parsed.Tools[D.Value.ID] = D.Value;
            }

            file1Parsed.Write(outputfile, 0, 0, 0, 0);
        }
Exemple #8
0
        public void FixEagleDrillExportIssues(IProgressLog Logger)
        {
            List <ParsedGerber> DrillFiles = new List <ParsedGerber>();
            List <Tuple <double, ParsedGerber> > DrillFilesToReload = new List <Tuple <double, ParsedGerber> >();
            Bounds BB = new Bounds();

            foreach (var a in PLSs)
            {
                if (a.Layer == BoardLayer.Drill)
                {
                    DrillFiles.Add(a);
                }
                else
                {
                    BB.AddBox(a.BoundingBox);
                }
            }

            foreach (var a in DrillFiles)
            {
                var b = a.BoundingBox;
                if (b.Width() > BB.Width() * 1.5 || b.Height() > BB.Height() * 1.5)
                {
                    var MaxRatio = Math.Max(b.Width() / BB.Width(), b.Height() / BB.Height());
                    if (Logger != null)
                    {
                        Logger.AddString(String.Format("Note: Really large drillfile found({0})-fix your export scripts!", a.Name));
                    }
                    Console.WriteLine("Note: Really large drillfile found ({0})- fix your export scripts!", a.Name);
                    DrillFilesToReload.Add(new Tuple <double, ParsedGerber>(MaxRatio, a));
                }
            }
            foreach (var a in DrillFilesToReload)
            {
                PLSs.Remove(a.Item2);
                var scale = 1.0;
                if (Double.IsInfinity(a.Item1) || Double.IsNaN(a.Item1))
                {
                    Errors.Add("Drill file size reached infinity - ignoring it");
                    if (Logger != null)
                    {
                        Logger.AddString("Drill file size reached infinity - ignoring it");
                    }
                }
                else
                {
                    var R = a.Item1;
                    while (R >= 1.5)
                    {
                        R     /= 10;
                        scale /= 10;
                    }
                    AddFileToSet(a.Item2.Name, Logger, scale);
                }
            }

            BoundingBox = new Bounds();
            foreach (var a in PLSs)
            {
                //Console.WriteLine("Progress: Adding board {6} to box::{0:N2},{1:N2} - {2:N2},{3:N2} -> {4:N2},{5:N2}", a.BoundingBox.TopLeft.X, a.BoundingBox.TopLeft.Y, a.BoundingBox.BottomRight.X, a.BoundingBox.BottomRight.Y, a.BoundingBox.Width(), a.BoundingBox.Height(), Path.GetFileName( a.Name));


                //Console.WriteLine("adding box for {0}:{1},{2}", a.Name, a.BoundingBox.Width(), a.BoundingBox.Height());
                BoundingBox.AddBox(a.BoundingBox);
            }
        }
Exemple #9
0
        public void AddBoardsToSet(List <string> FileList, bool fixgroup = true, IProgressLog Logger = null)
        {
            foreach (var a in FileList)
            {
                BoardSide  aSide  = BoardSide.Unknown;
                BoardLayer aLayer = BoardLayer.Unknown;
                string     ext    = Path.GetExtension(a);
                if (ext == ".zip")
                {
                    using (ZipFile zip1 = ZipFile.Read(a))
                    {
                        foreach (ZipEntry e in zip1)
                        {
                            //MemoryStream MS = new MemoryStream();
                            if (e.IsDirectory == false)
                            {
                                //                              e.Extract(MS);
                                //                                MS.Seek(0, SeekOrigin.Begin);
                                Gerber.DetermineBoardSideAndLayer(e.FileName, out aSide, out aLayer);
                                if (aLayer == BoardLayer.Outline)
                                {
                                    HasLoadedOutline = true;
                                }

                                //     AddFileStream(MS, e.FileName, drillscaler);
                            }
                        }
                    }
                }
                else
                {
                    Gerber.DetermineBoardSideAndLayer(a, out aSide, out aLayer);
                }
                if (aLayer == BoardLayer.Outline)
                {
                    HasLoadedOutline = true;
                }
            }

            foreach (var a in FileList)
            {
                if (Logger != null)
                {
                    Logger.AddString(String.Format("Loading {0}", Path.GetFileName(a)));
                }
                string ext = Path.GetExtension(a);
                if (ext == ".zip")
                {
                    using (ZipFile zip1 = ZipFile.Read(a))
                    {
                        foreach (ZipEntry e in zip1)
                        {
                            if (e.IsDirectory == false)
                            {
                                if (Logger != null)
                                {
                                    Logger.AddString(String.Format("Loading inside zip: {0}", Path.GetFileName(e.FileName)));
                                }

                                MemoryStream MS = new MemoryStream();
                                e.Extract(MS);
                                MS.Seek(0, SeekOrigin.Begin);
                                AddFileToSet(MS, e.FileName, Logger);
                            }
                        }
                    }
                }
                else
                {
                    using (FileStream FS = File.OpenRead(a))
                    {
                        MemoryStream MS2 = new MemoryStream();
                        FS.CopyTo(MS2);
                        MS2.Seek(0, SeekOrigin.Begin);
                        AddFileToSet(MS2, a, Logger);
                    }
                }
            }

            if (fixgroup)
            {
                if (Logger != null)
                {
                    Logger.AddString("Checking for common file format mistakes.");
                }
                FixEagleDrillExportIssues(Logger);
                CheckRelativeBoundingBoxes(Logger);
                CheckForOutlineFiles(Logger);

                CheckRelativeBoundingBoxes(Logger);
            }
        }
Exemple #10
0
        public void CheckForOutlineFiles(IProgressLog Logger)
        {
            List <ParsedGerber> Outlines = new List <ParsedGerber>();
            List <ParsedGerber> Mills    = new List <ParsedGerber>();
            List <ParsedGerber> Unknowns = new List <ParsedGerber>();

            foreach (var a in PLSs)
            {
                if (a.Side == BoardSide.Both && (a.Layer == BoardLayer.Outline))
                {
                    Outlines.Add(a);
                }
                if (a.Side == BoardSide.Both && (a.Layer == BoardLayer.Mill))
                {
                    Mills.Add(a);
                }
                if (a.Side == BoardSide.Unknown && a.Layer == BoardLayer.Unknown)
                {
                    Unknowns.Add(a);
                    Errors.Add(String.Format("Unknown file in set:{0}", Path.GetFileName(a.Name)));
                    if (Logger != null)
                    {
                        Logger.AddString(String.Format("Unknown file in set:{0}", Path.GetFileName(a.Name)));
                    }
                }
            }

            if (Outlines.Count == 0)
            {
                if (Unknowns.Count == 0)
                {
                    Errors.Add(String.Format("No outline file found and all other files accounted for! "));
                    if (Logger != null)
                    {
                        Logger.AddString(String.Format("No outline file found and all other files accounted for! "));
                    }

                    // if (Mills.Count == 1)
                    // {
                    //    Mills[0].Layer = BoardLayer.Outline;
                    //   Errors.Add(String.Format("Elevating mill file to outline!"));
                    //  if (Logger != null) Logger.AddString(String.Format("Elevating mill file to outline!"));
                    // }
                    // else
                    //                    if (!InventOutlineFromMill())
                    {
                        CreateBoxOutline();
                    }
                }
                else
                {
                    CreateBoxOutline();
                    return;

                    //InventOutline();
                    //return;
                    //foreach (var a in Unknowns)
                    //{
                    //    PLSs.Remove(a);
                    //    hasgko = true;
                    //    a.Layer = BoardLayer.Outline;
                    //    a.Side = BoardSide.Both;
                    //    Console.WriteLine("Note: Using {0} as outline file", Path.GetFileName(a.Name));

                    //    if (Logger != null) Logger.AddString(String.Format("Note: Using {0} as outline file", Path.GetFileName(a.Name)));

                    //    bool zerowidth = true;
                    //    bool precombine = true;

                    //    var b = AddBoardToSet(a.Name, zerowidth, precombine, 1.0);
                    //    b.Layer = BoardLayer.Outline;
                    //    b.Side = BoardSide.Both;

                    //}
                }
            }
        }