Exemple #1
0
        public static bool SaveGerberFileToImage(string GerberFilename, string BitmapFilename, float dpi, Color Foreground, Color Background)
        {
            try
            {
                ParsedGerber      PLS;
                GerberParserState State = new GerberParserState()
                {
                    PreCombinePolygons = false
                };

                var FileType = Gerber.FindFileType(GerberFilename);
                Gerber.DetermineBoardSideAndLayer(GerberFilename, out State.Side, out State.Layer);
                bool forcezero = false;

                if (State.Layer == BoardLayer.Outline)
                {
                    //    PLS.PreCombinePolygons = true;
                    //    forcezero = true;
                }
                if (FileType == BoardFileType.Drill)
                {
                    PLS = PolyLineSet.LoadExcellonDrillFile(GerberFilename);
                }
                else
                {
                    PLS = PolyLineSet.LoadGerberFile(GerberFilename, forcezero, Gerber.WriteSanitized, State);
                }
                double WidthInMM  = PLS.BoundingBox.BottomRight.X - PLS.BoundingBox.TopLeft.X;
                double HeightInMM = PLS.BoundingBox.BottomRight.Y - PLS.BoundingBox.TopLeft.Y;
                int    Width      = (int)(Math.Ceiling((WidthInMM) * (dpi / 25.4)));
                int    Height     = (int)(Math.Ceiling((HeightInMM) * (dpi / 25.4)));

                Console.WriteLine("Progress: Exporting {0} ({2},{3}mm) to {1} ({4},{5})", GerberFilename, BitmapFilename, WidthInMM, HeightInMM, Width, Height);
                GerberImageCreator GIC = new GerberImageCreator();
                GIC.scale = dpi / 25.4f; // dpi
                GIC.BoundingBox.AddBox(PLS.BoundingBox);

                var    Tr = GIC.BuildMatrix(Width, Height);
                Bitmap B2 = GIC.RenderToBitmap(Width, Height, Tr, Foreground, Background, PLS, true);
                if (B2 == null)
                {
                    return(false);
                }
                B2.Save(BitmapFilename);
                return(true);
            }
            catch (Exception E)
            {
                Console.WriteLine("Error: Errors while writing bitmap {0} for gerberfile {1} at dpi {2}:", BitmapFilename, GerberFilename, dpi);
                while (E != null)
                {
                    Console.WriteLine("Error: \t{0}", E.Message);
                    E = E.InnerException;
                }
                return(false);
            }
        }
Exemple #2
0
        private void OutlineFileBox_TextChanged(object sender, EventArgs e)
        {
            ParsedGerber PLS         = null;
            string       OutlineFile = OutlineFileBox.Text;

            if (System.IO.File.Exists(OutlineFile) == false)
            {
                return;
            }
            PLS = PolyLineSet.LoadGerberFile(OutlineFile);

            sizebox.Text = String.Format("{0}x{1}mm", PLS.BoundingBox.Width(), PLS.BoundingBox.Height());
        }
Exemple #3
0
        private static void RotateFile(string filename, string outfile, string[] args)
        {
            double dx    = 0;
            double dy    = 0;
            double cx    = 0;
            double cy    = 0;
            double angle = 0;

            if (args.Count() > 2)
            {
                double.TryParse(args[2], out dx);
            }
            if (args.Count() > 3)
            {
                double.TryParse(args[3], out dy);
            }
            if (args.Count() > 4)
            {
                double.TryParse(args[4], out cx);
            }
            if (args.Count() > 5)
            {
                double.TryParse(args[5], out cy);
            }
            if (args.Count() > 6)
            {
                double.TryParse(args[6], out angle);
            }

            var T = Gerber.FindFileType(filename);

            if (T == BoardFileType.Drill)
            {
                ExcellonFile EF = new ExcellonFile();
                EF.Load(filename);
                EF.Write(outfile, dx, dy, cx, cy, angle);
            }
            else
            {
                BoardSide  Side;
                BoardLayer Layer;
                Gerber.DetermineBoardSideAndLayer(args[0], out Side, out Layer);

                GerberTransposer.Transform(filename, outfile, dx, dy, cx, cy, angle);

                var lines = PolyLineSet.SanitizeInputLines(System.IO.File.ReadAllLines(args[0]).ToList());
                System.IO.File.WriteAllLines(args[0] + "sanit.txt", lines);

                Gerber.SaveGerberFileToImage(outfile, outfile + "_render.png", 200, Color.Black, Color.White);
            }
        }
Exemple #4
0
        public static PolyLineSet.Bounds GetBoundingBox(List <string> generatedFiles)
        {
            PolyLineSet.Bounds A = new PolyLineSet.Bounds();

            foreach (var a in generatedFiles)
            {
                ParsedGerber PLS = PolyLineSet.LoadGerberFile(a, State: new GerberParserState()
                {
                    PreCombinePolygons = false
                });
                A.AddBox(PLS.BoundingBox);
            }
            return(A);
        }
Exemple #5
0
 static void Main(string[] args)
 {
     if (args.Count() == 0)
     {
         Console.WriteLine("Usage: GernerSanitize <file1> <file2> <fileN>");
     }
     else
     {
         for (int i = 0; i < args.Count(); i++)
         {
             PolyLineSet.SanitizeInputLines(File.ReadAllLines(args[i]).ToList(), args[i] + ".sanitized.txt");
         }
     }
 }
Exemple #6
0
        static void Slice(string slicefile, List <string> inputgerbers)
        {
            List <PolyLine> SliceSet = new List <PolyLine>();

            var OutputFolder = Path.GetDirectoryName(slicefile) + @"\Output\" + Path.GetFileNameWithoutExtension(slicefile);

            ParsedGerber P = PolyLineSet.LoadGerberFile(new StandardConsoleLog(), slicefile);

            foreach (var l in P.Shapes)
            {
                /* Polygon Pp = new Polygon();
                *  Pp.Closed = true;
                *  var vertL = from i in l.Vertices select new vec2(i.X, i.Y);
                *  Pp.Vertices.AddRange(vertL);*/
                SliceSet.Add(l);
            }

            int slid = 1;

            foreach (var S in SliceSet)
            {
                Console.WriteLine("Slicing {0}/{1}", slid, SliceSet.Count);
                var SliceOutputFolder = Path.GetDirectoryName(slicefile) + @"\Output\" + Path.GetFileNameWithoutExtension(slicefile) + "\\Slice" + slid.ToString();
                if (Directory.Exists(SliceOutputFolder) == false)
                {
                    Directory.CreateDirectory(SliceOutputFolder);
                }

                foreach (var a in inputgerbers)
                {
                    try
                    {
                        var bf = GerberLibrary.Gerber.FindFileType(a);
                        if (bf == BoardFileType.Gerber)
                        {
                            BoardSide  bs;
                            BoardLayer L;
                            GerberLibrary.Gerber.DetermineBoardSideAndLayer(a, out bs, out L);

                            GerberMerger.WriteContainedOnly(a, S, Path.Combine(SliceOutputFolder + "\\", Path.GetFileName(a)), new StandardConsoleLog());
                        }
                    }
                    catch (Exception) { };
                }
                slid++;
            }
        }
Exemple #7
0
        public static bool SaveDebugImage(string GerberFilename, string BitmapFilename, float dpi, Color Foreground, Color Background)
        {
            ParsedGerber      PLS;
            GerberParserState State = new GerberParserState()
            {
                PreCombinePolygons = false
            };

            var FileType = Gerber.FindFileType(GerberFilename);

            Gerber.DetermineBoardSideAndLayer(GerberFilename, out State.Side, out State.Layer);
            bool forcezero = false;

            if (State.Layer == BoardLayer.Outline)
            {
                //    PLS.PreCombinePolygons = true;

                //    forcezero = true;
            }
            if (FileType == BoardFileType.Drill)
            {
                PLS = PolyLineSet.LoadExcellonDrillFile(GerberFilename);
            }
            else
            {
                PLS = PolyLineSet.LoadGerberFile(GerberFilename, forcezero, Gerber.WriteSanitized, State);
            }
            double WidthInMM  = PLS.BoundingBox.BottomRight.X - PLS.BoundingBox.TopLeft.X;
            double HeightInMM = PLS.BoundingBox.BottomRight.Y - PLS.BoundingBox.TopLeft.Y;
            int    Width      = (int)(Math.Ceiling((WidthInMM) * (dpi / 25.4)));
            int    Height     = (int)(Math.Ceiling((HeightInMM) * (dpi / 25.4)));

            Console.WriteLine("Progress: Exporting {0} ({2},{3}mm) to {1} ({4},{5})", GerberFilename, BitmapFilename, WidthInMM, HeightInMM, Width, Height);
            GerberImageCreator GIC = new GerberImageCreator();

            GIC.scale = dpi / 25.4f; // dpi
            GIC.BoundingBox.AddBox(PLS.BoundingBox);

            var Tr = GIC.BuildMatrix(Width, Height);

            Bitmap B2 = GIC.RenderToBitmap(Width, Height, Tr, Foreground, Background, PLS, true);

            if (B2 == null)
            {
                return(false);
            }

            var    GerberLines = PolyLineSet.SanitizeInputLines(System.IO.File.ReadAllLines(GerberFilename).ToList());
            double LastX       = 0;
            double LastY       = 0;



            Graphics G2 = Graphics.FromImage(B2);

            GerberImageCreator.ApplyAASettings(G2);
            //G2.Clear(Background);
            G2.Transform = Tr.Clone();



            foreach (var L in GerberLines)
            {
                if (L[0] != '%')
                {
                    GerberSplitter GS = new GerberSplitter();
                    GS.Split(L, PLS.State.CoordinateFormat);

                    if (GS.Has("G") && (int)GS.Get("G") == 3)
                    {
                        double X = PLS.State.CoordinateFormat.ScaleFileToMM(GS.Get("X"));
                        double Y = PLS.State.CoordinateFormat.ScaleFileToMM(GS.Get("Y"));

                        double I = PLS.State.CoordinateFormat.ScaleFileToMM(GS.Get("I"));
                        double J = PLS.State.CoordinateFormat.ScaleFileToMM(GS.Get("J"));

                        //Console.WriteLine("Counterclockwise Curve {0},{1} -> {2},{3}", LastX, LastY, X, Y);
                        DrawCross(G2, X, Y, Color.Blue);
                        DrawCross(G2, LastX, LastY, Color.Red);

                        DrawCross(G2, LastX + I, LastY - J, Color.Yellow);
                        DrawCross(G2, LastX + I, LastY + J, Color.Purple);
                        DrawCross(G2, LastX - I, LastY - J, Color.Green);
                        DrawCross(G2, LastX - I, LastY + J, Color.Orange);
                    }

                    if (GS.Has("X"))
                    {
                        LastX = PLS.State.CoordinateFormat.ScaleFileToMM(GS.Get("X"));
                    }
                    if (GS.Has("Y"))
                    {
                        LastY = PLS.State.CoordinateFormat.ScaleFileToMM(GS.Get("Y"));
                    }
                }
            }


            B2.Save(BitmapFilename);
            return(true);
        }
Exemple #8
0
        static void Main(string[] args)
        {
            if (args.Count() < 2)
            {
                Console.WriteLine("Usage: GerberToOutline.exe <infile> <outfile>");
                return;
            }

            string infile  = args[0];
            string outfile = args[1];

            var FileType = Gerber.FindFileType(infile);

            if (FileType == BoardFileType.Unsupported)
            {
                if (Gerber.ExtremelyVerbose)
                {
                    Console.WriteLine("Warning: {1}: files with extension {0} are not supported!", Path.GetExtension(infile), Path.GetFileName(infile));
                }
                return;
            }


            ParsedGerber      PLS;
            GerberParserState State = new GerberParserState()
            {
                PreCombinePolygons = false
            };

            if (FileType == BoardFileType.Drill)
            {
                if (Gerber.ExtremelyVerbose)
                {
                    Console.WriteLine("Log: Drill file: {0}", infile);
                }
                PLS = PolyLineSet.LoadExcellonDrillFile(new StandardConsoleLog(), infile, false, 1.0);
                // ExcellonFile EF = new ExcellonFile();
                // EF.Load(a);
            }
            else

            {
                bool forcezerowidth     = false;
                bool precombinepolygons = false;
                if (Gerber.ExtremelyVerbose)
                {
                    Console.WriteLine("Log: Gerber file: {0}", infile);
                }
                BoardSide  Side  = BoardSide.Unknown;
                BoardLayer Layer = BoardLayer.Unknown;
                Gerber.DetermineBoardSideAndLayer(infile, out Side, out Layer);
                if (Layer == BoardLayer.Outline || Layer == BoardLayer.Mill)
                {
                    forcezerowidth     = true;
                    precombinepolygons = true;
                }
                State.PreCombinePolygons = precombinepolygons;

                PLS       = PolyLineSet.LoadGerberFile(new StandardConsoleLog(), infile, forcezerowidth, false, State);
                PLS.Side  = State.Side;
                PLS.Layer = State.Layer;
                if (Layer == BoardLayer.Outline)
                {
                    PLS.FixPolygonWindings();
                }
            }
            SVGGraphicsInterface SG = new SVGGraphicsInterface(PLS.BoundingBox.Width() * 100, PLS.BoundingBox.Height() * 100);

            SG.ScaleTransform(10, 10);
            SG.TranslateTransform((float)-PLS.BoundingBox.TopLeft.X, (float)-PLS.BoundingBox.TopLeft.Y);
            DrawToInterface(PLS, SG);
            SG.Save(outfile);
            System.Diagnostics.Process.Start(outfile);
            Console.WriteLine("press any key to continue..");
            Console.ReadKey();
        }
Exemple #9
0
        private static void ConvertFile(string a, bool back)
        {
            string basename = a.Substring(0, a.Length - 4);

            string png     = basename + "Silk.png";
            string goldpng = basename + "Gold.png";

            if (back)
            {
                png     = basename + "BottomSilk.png";
                goldpng = basename + "BottomGold.png";
            }

            Bitmap B  = (Bitmap)Image.FromFile(png);
            Bitmap B2 = null;

            if (System.IO.File.Exists(goldpng))
            {
                B2 = (Bitmap)Image.FromFile(goldpng);
            }

            try
            {
                System.IO.Directory.CreateDirectory(basename);
            }
            catch (Exception)
            {
            }

            string newa = basename + "\\" + System.IO.Path.GetFileName(a);;
            string gko  = basename + ".gko";
            string pnl  = basename + ".pnl";

            if (System.IO.File.Exists(gko) == false && System.IO.File.Exists(pnl) == true)
            {
                gko = pnl;
            }

            string newgko = basename + "\\" + System.IO.Path.GetFileNameWithoutExtension(a) + ".gko";;

            if (System.IO.File.Exists(gko))
            {
                System.IO.File.Copy(gko, newgko, true);
            }

            System.IO.File.Copy(a, newa, true);
            a = newa;

            string p = basename + "/topsilk.gto";

            if (back)
            {
                p = basename + "/bottomsilk.gbo";
            }
            if (back)
            {
                B.RotateFlip(RotateFlipType.RotateNoneFlipX);
            }
            B.RotateFlip(RotateFlipType.RotateNoneFlipY);
            if (B2 != null)
            {
                B2.RotateFlip(RotateFlipType.RotateNoneFlipY);
            }
            if (B != null)
            {
                double Res = 200.0 / 25.4;

                ParsedGerber PLS = null;
                string       f   = basename + ".gko";
                if (System.IO.File.Exists(f))
                {
                    int polyid = 0;
                    PLS = PolyLineSet.LoadGerberFile(f);


                    string bottomcopper     = basename + "/bottomcopper.gbl";
                    string topcopper        = basename + "/topcopper.gtl";
                    string bottomsoldermask = basename + "/bottomsoldermask.gbs";
                    string topsoldermask    = basename + "/topsoldermask.gts";
                    string bottomsilk       = basename + "/bottomsilk.gbo";
                    if (back)
                    {
                        bottomsilk = basename + "/topsilk.gto";
                    }
                    GerberArtWriter GAW3 = new GerberLibrary.GerberArtWriter();
                    GAW3.Write(topsoldermask);

                    GerberArtWriter GAW = new GerberLibrary.GerberArtWriter();
                    PolyLine        PL  = new PolyLine(polyid++);
                    PL.Add(PLS.BoundingBox.TopLeft.X, PLS.BoundingBox.TopLeft.Y);
                    PL.Add(PLS.BoundingBox.BottomRight.X, PLS.BoundingBox.TopLeft.Y);
                    PL.Add(PLS.BoundingBox.BottomRight.X, PLS.BoundingBox.TopLeft.Y + 8);
                    PL.Add(PLS.BoundingBox.TopLeft.X, PLS.BoundingBox.TopLeft.Y + 8);
                    GAW.AddPolygon(PL);


                    PolyLine PL3 = new PolyLine(polyid++);
                    PL3.Add(PLS.BoundingBox.TopLeft.X, PLS.BoundingBox.BottomRight.Y - 8);
                    PL3.Add(PLS.BoundingBox.BottomRight.X, PLS.BoundingBox.BottomRight.Y - 8);
                    PL3.Add(PLS.BoundingBox.BottomRight.X, PLS.BoundingBox.BottomRight.Y);
                    PL3.Add(PLS.BoundingBox.TopLeft.X, PLS.BoundingBox.BottomRight.Y);
                    GAW.AddPolygon(PL3);

                    GAW.Write(bottomsoldermask);


                    GerberArtWriter GAW2 = new GerberLibrary.GerberArtWriter();
                    PolyLine        PL2  = new PolyLine(polyid++);
                    PL2.Add(PLS.BoundingBox.TopLeft.X, PLS.BoundingBox.TopLeft.Y);
                    PL2.Add(PLS.BoundingBox.BottomRight.X, PLS.BoundingBox.TopLeft.Y);
                    PL2.Add(PLS.BoundingBox.BottomRight.X, PLS.BoundingBox.BottomRight.Y);
                    PL2.Add(PLS.BoundingBox.TopLeft.X, PLS.BoundingBox.BottomRight.Y);
                    GAW2.AddPolygon(PL2);
                    GAW2.Write(bottomcopper);

                    if (B2 != null)
                    {
                        GerberLibrary.ArtWork.Functions.WriteBitmapToGerber(topcopper, PLS, Res, B2, -128);
                        GerberLibrary.ArtWork.Functions.WriteBitmapToGerber(topsoldermask, PLS, Res, B2, -128);
                    }
                    else
                    {
                        GAW2.Write(topcopper);
                    }
                }

                GerberLibrary.ArtWork.Functions.WriteBitmapToGerber(p, PLS, Res, B, -128);
            }
        }
Exemple #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sourcefile"></param>
        /// <param name="destfile"></param>
        /// <param name="DX">MM</param>
        /// <param name="DY">MM</param>
        /// <param name="Angle">Degrees</param>
        public static void Transform(string sourcefile, string destfile, double DX, double DY, double DXp, double DYp, double AngleInDeg = 0)
        {
            List <String> lines    = new List <string>();
            List <String> outlines = new List <string>();


            bool   WriteMove    = false;
            int    moveswritten = 0;
            double Angle        = AngleInDeg * (Math.PI * 2.0) / 360.0;
            double CA           = Math.Cos(Angle);
            double SA           = Math.Sin(Angle);

            using (StreamReader sr = new StreamReader(sourcefile))
            {
                while (sr.EndOfStream == false)
                {
                    String line = sr.ReadLine();
                    if (line.Length > 0)
                    {
                        lines.Add(line);
                    }
                }
            }
            lines = PolyLineSet.SanitizeInputLines(lines);

            if (Gerber.WriteSanitized)
            {
                Gerber.WriteAllLines(sourcefile + ".sanitized.txt", lines);
            }
            //   PolyLineSet Parsed = new PolyLineSet("parsed gerber");
            ParsedGerber Parsed = PolyLineSet.ParseGerber274x(lines, true, false, new GerberParserState()
            {
                GenerateGeometry = false
            });

            if (Gerber.ShowProgress)
            {
                Console.WriteLine("found apertures: ");
                foreach (var a in Parsed.State.Apertures)
                {
                    Console.WriteLine(a.Value.ToString());
                }
            }



            GerberNumberFormat CoordinateFormat = new GerberNumberFormat();

            CoordinateFormat.SetImperialMode();
            //   CoordinateFormat = Parsed.State.CoordinateFormat;

            int  cur          = 0;
            bool formatparsed = false;

            while (cur < lines.Count && formatparsed == false)
            {
                if (lines[cur].Length >= 2 && lines[cur].Substring(0, 2) == "%F")
                {
                    CoordinateFormat.Parse(lines[cur]);
                    formatparsed = true;
                }
                cur++;
            }

            //  double coordmultiplier = 1.0;
            double LastX = 0;
            double LastY = 0;

            for (int i = 0; i < lines.Count; i++)
            {
                GerberSplitter GS        = new GerberSplitter();
                string         FinalLine = lines[i].Replace("%", "").Replace("*", "").Trim();

                bool DumpToOutput = false;
                bool metaopen     = false;
                if (lines[i][0] == '%')
                {
                    DumpToOutput = true;
                    metaopen     = true;
                }
                else
                {
                    GS.Split(lines[i], CoordinateFormat);
                }


                switch (FinalLine)
                {
                case "G71": CoordinateFormat.SetMetricMode(); break;

                case "G70": CoordinateFormat.SetImperialMode(); break;

                case "MOIN":
                {
                    CoordinateFormat.SetImperialMode();
                    //CoordinateFormat.Multiplier  = 25.4f;
                }
                break;

                case "MOMM":
                {
                    CoordinateFormat.SetMetricMode();
                    //CoordinateFormat.Multiplier = 1.0f;
                }
                break;
                }
                if (lines[i].Length > 3 && lines[i].Substring(0, 3) == "%AM")
                {
                    string name = lines[i].Substring(3).Split('*')[0];

                    var M = Parsed.State.ApertureMacros[name];
                    M.Written = true;
                    var gerb = M.BuildGerber(CoordinateFormat, AngleInDeg).Split('\n');
                    foreach (var l in gerb)
                    {
                        if (l.Trim().Length > 0)
                        {
                            outlines.Add(l.Trim());
                        }
                    }
                    //    outlines.Add(lines[i]);
                    //  if (lines[i][lines[i].Length - 1] != '%')
                    ///  {
                    //   i++;
                    while (lines[i][lines[i].Length - 1] != '%')
                    {
                        //     outlines.Add(lines[i]);
                        i++;
                    }
//                       outlines.Add(lines[i]);
                    //     }
                }
                else

                if (lines[i].Length > 3 && lines[i].Substring(0, 3) == "%AD")
                {
                    GCodeCommand GCC = new GCodeCommand();
                    GCC.Decode(lines[i], CoordinateFormat);
                    if (GCC.numbercommands.Count < 1)
                    {
                        Console.WriteLine("Skipping bad aperture definition: {0}", lines[i]);
                    }
                    else
                    {
                        int ATID     = (int)GCC.numbercommands[0];
                        var Aperture = Parsed.State.Apertures[ATID];
                        if (Gerber.ShowProgress)
                        {
                            Console.WriteLine("found " + Aperture.ToString());
                        }
                        string gerb = Aperture.BuildGerber(CoordinateFormat, AngleInDeg);

                        if ((Aperture.ShapeType == GerberApertureShape.Compound || Aperture.ShapeType == GerberApertureShape.Macro) && Parsed.State.ApertureMacros[Aperture.MacroName].Written == false)
                        {
                            Console.WriteLine("Macro type defined - skipping");
                        }
                        else
                        {
                            outlines.Add(gerb);
                        }

                        //                   outlines.Add(lines[i]);
                        if (lines[i][lines[i].Length - 1] != '%')
                        {
                            i++;
                            while (lines[i] != "%")
                            {
                                //                         outlines.Add(lines[i]);
                                i++;
                            }
                            //                   outlines.Add(lines[i]);
                        }
                    }
                }
                else
                {
                    bool PureD = false;
                    if (GS.Has("G"))
                    {
                        int GCode = (int)GS.Get("G");
                        switch (GCode)
                        {
                        case 4: DumpToOutput = true; break;

                        case 90: CoordinateFormat.Relativemode = false; break;

                        case 91: CoordinateFormat.Relativemode = true; break;

                        case 71: CoordinateFormat.Multiplier = 1.0d; break;

                        case 70: CoordinateFormat.Multiplier = 25.4d; break;
                        }
                    }
                    if (DumpToOutput)
                    {
                        outlines.Add(lines[i]);
                        if (lines[i].Contains("LNData"))
                        {
                            Console.WriteLine(" heh");
                        }
                        if (lines[i][0] == '%')
                        {
                            int starti = i;
                            if (lines[i].Length == 1)
                            {
                                i++;
                            }
                            while (lines[i][lines[i].Length - 1] != '%')
                            {
                                if (i > starti)
                                {
                                    outlines.Add(lines[i]);
                                }
                                i++;
                            }
                            if (i > starti)
                            {
                                outlines.Add(lines[i]);
                            }
                        }
                    }
                    else
                    {
                        bool translate = true;
                        if (CoordinateFormat.Relativemode)
                        {
                            translate = false;
                        }
                        if (GS.Has("X") == false && GS.Has("Y") == false && (GS.Has("D") && GS.Get("D") < 10))
                        {
                            PureD = true;
                            int Dcode = (int)GS.Get("D");
                            if (Dcode == 1 || Dcode == 3)
                            {
                                if (moveswritten == 0)
                                {
                                    WriteMove = true;
                                }
                            }
                            moveswritten++;
                            Console.WriteLine(" Pure D Code: {0}", lines[i]);
                        }
                        else
                        if (GS.Has("X") || GS.Has("Y") || (GS.Has("D") && GS.Get("D") < 10))
                        {
                            int Dcode = (int)GS.Get("D");
                            if (Dcode == 1 || Dcode == 3)
                            {
                                if (moveswritten == 0)
                                {
                                    WriteMove = true;
                                }
                            }
                            moveswritten++;
                            double X = LastX;
                            if (GS.Has("X"))
                            {
                                X = GS.Get("X");
                            }
                            double Y = LastY;
                            if (GS.Has("Y"))
                            {
                                Y = GS.Get("Y");
                            }
                            LastX = X;
                            LastY = Y;
                            GetTransformedCoord(DX, DY, DXp, DYp, Angle, CA, SA, CoordinateFormat, translate, ref X, ref Y);
                            if ((GS.Has("I") || GS.Has("J")) && Angle != 0)
                            {
                                //   int g = (int)GS.Get("G");
                                //  if (g == 2 || g == 3)
                                {
                                    double I   = 0;
                                    double J   = 0;
                                    bool   arc = false;
                                    if (GS.Has("I"))
                                    {
                                        I = GS.Get("I"); arc = true;
                                    }
                                    ;
                                    if (GS.Has("J"))
                                    {
                                        J = GS.Get("J"); arc = true;
                                    }
                                    ;
                                    if (arc)
                                    {
                                        double nJ = J * CA + I * SA;
                                        double nI = -J * SA + I * CA;
                                        I = nI;
                                        J = nJ;
                                        //  GS.Set("I", Math.Abs(I));
                                        //  GS.Set("J", Math.Abs(J));
                                        GS.Set("I", I);
                                        GS.Set("J", J);
                                    }
                                }
                            }
                            GS.Set("X", X);
                            GS.Set("Y", Y);
                        }

                        if (WriteMove)
                        {
                            GerberSplitter GS2 = new GerberSplitter();
                            GS2.Set("D", 2);
                            double X0 = 0;
                            double Y0 = 0;
                            GetTransformedCoord(DX, DY, DXp, DYp, Angle, CA, SA, CoordinateFormat, translate, ref X0, ref Y0);
                            GS2.Set("X", X0);
                            GS2.Set("Y", Y0);
                            WriteMove = false;
                            outlines.Add(GS2.Rebuild(CoordinateFormat));
                        }
                        outlines.Add(GS.Rebuild(CoordinateFormat));
                        if (PureD)
                        {
                            Console.WriteLine("pureD");
                        }
                    }
                }
            }
            try
            {
                List <String> PostProcLines = new List <string>();
                foreach (var a in outlines)
                {
                    if (a == "%")
                    {
                        PostProcLines[PostProcLines.Count - 1] += "%";
                    }
                    else
                    {
                        PostProcLines.Add(a);
                    }
                }
                Gerber.WriteAllLines(destfile, PolyLineSet.SanitizeInputLines(PostProcLines));
            }
            catch (Exception E)
            {
                Console.WriteLine(E.Message);
            }
        }
Exemple #11
0
        public ParsedGerber AddBoardToSet(ProgressLog log, MemoryStream MS, string _originalfilename, bool forcezerowidth = false, bool precombinepolygons = false, double drillscaler = 1.0)
        {
            Streams[_originalfilename] = MS;
            try
            {
                //   string[] filesplit = originalfilename.Split('.');
                //     string ext = filesplit[filesplit.Count() - 1].ToLower();

                var FileType = Gerber.FindFileTypeFromStream(new StreamReader(MS), _originalfilename);
                MS.Seek(0, SeekOrigin.Begin);

                if (FileType == BoardFileType.Unsupported)
                {
                    if (Gerber.ExtremelyVerbose)
                    {
                        Console.WriteLine("Warning: {1}: files with extension {0} are not supported!", Path.GetExtension(_originalfilename), Path.GetFileName(_originalfilename));
                    }
                    return(null);
                }


                ParsedGerber      PLS;
                GerberParserState State = new GerberParserState()
                {
                    PreCombinePolygons = precombinepolygons
                };

                if (FileType == BoardFileType.Drill)
                {
                    if (Gerber.ExtremelyVerbose)
                    {
                        Console.WriteLine("Log: Drill file: {0}", _originalfilename);
                    }
                    PLS = PolyLineSet.LoadExcellonDrillFileFromStream(log, new StreamReader(MS), _originalfilename, false, drillscaler);
                    MS.Seek(0, SeekOrigin.Begin);

                    ExcellonFile EF = new ExcellonFile();
                    EF.Load(log, new StreamReader(MS), drillscaler);
                    Excellons.Add(EF);
                }
                else
                {
                    if (Gerber.ExtremelyVerbose)
                    {
                        Console.WriteLine("Log: Gerber file: {0}", _originalfilename);
                    }
                    BoardSide  Side  = BoardSide.Unknown;
                    BoardLayer Layer = BoardLayer.Unknown;
                    Gerber.DetermineBoardSideAndLayer(_originalfilename, out Side, out Layer);
                    if (Layer == BoardLayer.Outline)
                    {
                        forcezerowidth     = true;
                        precombinepolygons = true;
                    }
                    State.PreCombinePolygons = precombinepolygons;

                    PLS = PolyLineSet.LoadGerberFileFromStream(log, new StreamReader(MS), _originalfilename, forcezerowidth, false, State);
                    MS.Seek(0, SeekOrigin.Begin);

                    PLS.Side  = State.Side;
                    PLS.Layer = State.Layer;
                    if (Layer == BoardLayer.Outline)
                    {
                        PLS.FixPolygonWindings();
                    }
                }

                PLS.CalcPathBounds();
                BoundingBox.AddBox(PLS.BoundingBox);

                Console.WriteLine("Progress: Loaded {0}: {1:N1} x {2:N1} mm", Path.GetFileName(_originalfilename), PLS.BoundingBox.BottomRight.X - PLS.BoundingBox.TopLeft.X, PLS.BoundingBox.BottomRight.Y - PLS.BoundingBox.TopLeft.Y);
                PLSs.Add(PLS);
                //     }
                //     catch (Exception)
                //    {
                //   }

                return(PLS);
            }
            catch (Exception E)
            {
                while (E != null)
                {
                    Console.WriteLine("Exception adding board: {0}", E.Message);
                    E = E.InnerException;
                }
            }
            return(null);
        }
Exemple #12
0
        static void Main(string[] args)
        {
            GerberNumberFormat GNF = new GerberNumberFormat();

            GNF.DigitsAfter  = 3;
            GNF.DigitsBefore = 3;
            GNF.SetMetricMode();

            GerberSplitter GS = new GerberSplitter();

            GS.Split("X-1.15Y-1.9", GNF, true);

            foreach (var a in GS.Pairs)
            {
                Console.WriteLine("{0}:{1} {2}", a.Key, a.Value.Command, a.Value.Number);
            }
            Console.ReadKey();

            if (args.Count() == 0)
            {
                Console.WriteLine("Usage:");
                Console.WriteLine("GerberAnalyse <inputfile> <-forcezerowidth> <-dim>");
                return;
            }
            ParsedGerber PLS;
            bool         forcezerowidth = false;
            bool         compact        = false;

            for (int i = 1; i < args.Count(); i++)
            {
                if (args[i] == "-forcezerowidth")
                {
                    forcezerowidth = true;
                }
                if (args[i] == "-dim")
                {
                    compact = true;
                }
            }

            if (Gerber.FindFileType(args[0].ToLower()) == BoardFileType.Drill)
            {
                PLS = PolyLineSet.LoadExcellonDrillFile(args[0]);
                // ExcellonFile EF = new ExcellonFile();
                // EF.Load(a);
            }
            else
            {
                // PLS.PreCombinePolygons = false;
                // forcezerowidth = true;
                PLS = PolyLineSet.LoadGerberFile(args[0], forcezerowidth, false, new GerberParserState()
                {
                    PreCombinePolygons = false
                });
            }

            PLS.CalcPathBounds();

            if (compact)
            {
                CultureInfo CI = CultureInfo.InvariantCulture;

                Console.WriteLine("{0}x{1}(mm)", (PLS.BoundingBox.BottomRight.X - PLS.BoundingBox.TopLeft.X).ToString("N3", CI), (PLS.BoundingBox.BottomRight.Y - PLS.BoundingBox.TopLeft.Y).ToString("N3", CI));
                Console.WriteLine("{0}x{1}(imp)", ((PLS.BoundingBox.BottomRight.X - PLS.BoundingBox.TopLeft.X) / 25.4).ToString("N3", CI), ((PLS.BoundingBox.BottomRight.Y - PLS.BoundingBox.TopLeft.Y) / 25.4).ToString("N3", CI));
            }
            else
            {
                Console.WriteLine("Report for {0}:", args[0]);
                Console.WriteLine("Suspected file side: {0}, layertype: {1}", PLS.Side.ToString(), PLS.Layer.ToString());
                Console.WriteLine("DisplayShape #: {0}", PLS.DisplayShapes.Count);
                foreach (var o in PLS.DisplayShapes)
                {
                    Console.WriteLine("\tOutline {0} vertices thin:{1}", o.Vertices.Count, o.Thin);
                    foreach (var v in o.Vertices)
                    {
                        Console.WriteLine("\t\t{0}", v);
                    }
                }

                Console.WriteLine("OutlineShape #: {0}", PLS.OutlineShapes.Count);
                foreach (var o in PLS.OutlineShapes)
                {
                    Console.WriteLine("\tOutline {0} vertices thin:{1}", o.Vertices.Count, o.Thin);
                    foreach (var v in o.Vertices)
                    {
                        Console.WriteLine("\t\t{0}", v);
                    }
                }
                Console.WriteLine("Aperture #: {0}", PLS.State.Apertures.Count);
                foreach (var apt in PLS.State.Apertures)
                {
                    Console.Write("\tAperture D{0} ", apt.Key.ToString("D2"));
                    Console.Write("type: {0} ", apt.Value.ShapeType.ToString());
                    switch (apt.Value.ShapeType)
                    {
                    case GerberApertureShape.Circle:

                        Console.Write("diameter {0} ", apt.Value.CircleRadius * 2); break;
                    }
                    Console.WriteLine();
                }
                Console.WriteLine("Corners: ");
                Console.WriteLine(PLS.BoundingBox.TopLeft);
                Console.WriteLine(PLS.BoundingBox.BottomRight);
                Console.WriteLine("Size: {0}x{1} mm", PLS.BoundingBox.BottomRight.X - PLS.BoundingBox.TopLeft.X, PLS.BoundingBox.BottomRight.Y - PLS.BoundingBox.TopLeft.Y);
            }
            //  Console.WriteLine("Press any key to continue");
            //  Console.ReadKey();
        }
Exemple #13
0
        internal void Load(string basefile)
        {
            Text = Path.GetFileNameWithoutExtension(basefile);

            string fn         = Path.GetFileName(basefile);
            string basefolder = Path.GetDirectoryName(basefile);
            string name       = fn.Split('_')[0];

            string BOMFile    = "";
            string PnPFile    = "";
            string gerberFile = "";
            var    L          = Directory.GetFiles(basefolder, name + "_*.*");

            SolderFile = "";
            foreach (var file in L)
            {
                if (file.EndsWith("_BOM.csv"))
                {
                    BOMFile = file;
                }
                if (file.EndsWith("_gerbers.zip"))
                {
                    gerberFile = file;
                }
                if (file.EndsWith("_PNP.csv"))
                {
                    PnPFile = file;
                }
                if (file.EndsWith("_soldered.txt"))
                {
                    SolderFile = file;
                }
            }

            LayerSets.Add(new LayerSet()
            {
                Side = BoardSide.Both, Layer = BoardLayer.Outline
            });
            LayerSets.Add(new LayerSet()
            {
                Side = BoardSide.Top, Layer = BoardLayer.SolderMask
            });
            LayerSets.Add(new LayerSet()
            {
                Side = BoardSide.Top, Layer = BoardLayer.Silk
            });
            LayerSets.Add(new LayerSet()
            {
                Side = BoardSide.Bottom, Layer = BoardLayer.SolderMask
            });
            LayerSets.Add(new LayerSet()
            {
                Side = BoardSide.Bottom, Layer = BoardLayer.Silk
            });
            if (BOMFile.Length > 0 && PnPFile.Length > 0 && gerberFile.Length > 0)
            {
                BOM B = new BOM();
                B.LoadJLC(BOMFile, PnPFile);
                TheBOM = B;

                if (SolderFile.Length > 0)
                {
                    solderedlist = File.ReadAllLines(SolderFile).ToList();

                    foreach (var a in B.DeviceTree)
                    {
                        foreach (var v in a.Value.Values)
                        {
                            if (solderedlist.Contains(v.Combined()))
                            {
                                v.Soldered = true;
                            }
                        }
                    }
                }
                else
                {
                    SolderFile = Path.Combine(basefolder, name + "_soldered.txt");
                    SaveSolderedList();
                }


                GerberLibrary.GerberImageCreator GIC = new GerberLibrary.GerberImageCreator();

                List <string> res = new List <string>();
                Dictionary <string, MemoryStream> Files = new Dictionary <string, MemoryStream>();
                using (Ionic.Zip.ZipFile zip1 = Ionic.Zip.ZipFile.Read(gerberFile))
                {
                    foreach (ZipEntry e in zip1)
                    {
                        MemoryStream MS = new MemoryStream();
                        if (e.IsDirectory == false)
                        {
                            e.Extract(MS);
                            MS.Seek(0, SeekOrigin.Begin);
                            Files[e.FileName] = MS;
                        }
                    }
                }


                string[]      FileNames       = Files.Keys.ToArray();
                List <string> outlinefiles    = new List <string>();
                List <string> topsilkfiles    = new List <string>();
                List <string> bottomsilkfiles = new List <string>();

                foreach (var F in FileNames)
                {
                    BoardSide  BS = BoardSide.Unknown;
                    BoardLayer BL = BoardLayer.Unknown;
                    Files[F].Seek(0, SeekOrigin.Begin);
                    if (Gerber.FindFileTypeFromStream(new StreamReader(Files[F]), F) == BoardFileType.Gerber)
                    {
                        Gerber.DetermineBoardSideAndLayer(F, out BS, out BL);
                        foreach (var l in LayerSets)
                        {
                            if (l.Side == BS && l.Layer == BL)
                            {
                                l.Files.Add(F);
                                Files[F].Seek(0, SeekOrigin.Begin);
                                var pls = PolyLineSet.LoadGerberFileFromStream(new StandardConsoleLog(), new StreamReader(Files[F]), F, true, false, new GerberParserState()
                                {
                                    PreCombinePolygons = false
                                });
                                l.Gerbs.Add(pls);
                            }
                        }
                    }
                }
                TheBox.Reset();

                foreach (var a in LayerSets[0].Gerbs)
                {
                    TheBox.AddBox(a.BoundingBox);
                }
            }
        }
Exemple #14
0
        private static Dictionary <string, Tuple <GerberApertureType, List <PointD> > > FillOverlapList(ProgressLog log, Dictionary <string, Tuple <GerberApertureType, List <PointD> > > overlapList, ParsedGerber subtr, string subtractfile)
        {
            log.PushActivity("Filling overlap list coords");
            List <String> lines    = new List <string>();
            List <String> outlines = new List <string>();

            int  CurrentAperture = 10;
            bool WriteMove       = false;
            int  moveswritten    = 0;

            using (StreamReader sr = new StreamReader(subtractfile))
            {
                while (sr.EndOfStream == false)
                {
                    String line = sr.ReadLine();
                    if (line.Length > 0)
                    {
                        lines.Add(line);
                    }
                }
            }
            lines = PolyLineSet.SanitizeInputLines(lines);

            //ParsedGerber Parsed = PolyLineSet.ParseGerber274x(log, lines, true, false, new GerberParserState() { GenerateGeometry = false });



            GerberNumberFormat CoordinateFormat = new GerberNumberFormat();

            CoordinateFormat.SetImperialMode();
            //   CoordinateFormat = Parsed.State.CoordinateFormat;

            int  cur          = 0;
            bool formatparsed = false;

            while (cur < lines.Count && formatparsed == false)
            {
                if (lines[cur].Length >= 2 && lines[cur].Substring(0, 2) == "%F")
                {
                    CoordinateFormat.Parse(lines[cur]);
                    formatparsed = true;
                }
                cur++;
            }

            //  double coordmultiplier = 1.0;
            double LastX = 0;
            double LastY = 0;

            for (int i = 0; i < lines.Count; i++)
            {
                GerberSplitter GS           = new GerberSplitter();
                string         FinalLine    = lines[i].Replace("%", "").Replace("*", "").Trim();
                bool           DumpToOutput = false;
                bool           metaopen     = false;
                if (lines[i][0] == '%')
                {
                    DumpToOutput = true;
                    metaopen     = true;
                }
                else
                {
                    GS.Split(lines[i], CoordinateFormat);
                }


                switch (FinalLine)
                {
                case "G71": CoordinateFormat.SetMetricMode(); break;

                case "G70": CoordinateFormat.SetImperialMode(); break;

                case "MOIN":
                {
                    CoordinateFormat.SetImperialMode();
                    //CoordinateFormat.Multiplier  = 25.4f;
                }
                break;

                case "MOMM":
                {
                    CoordinateFormat.SetMetricMode();
                    //CoordinateFormat.Multiplier = 1.0f;
                }
                break;
                }
                if (lines[i].Length > 3 && lines[i].Substring(0, 3) == "%AM")
                {
                    string name = lines[i].Substring(3).Split('*')[0];

                    var M = subtr.State.ApertureMacros[name];
                    M.Written = true;
                    var gerb = M.BuildGerber(CoordinateFormat, 0, "").Split('\n');
                    foreach (var l in gerb)
                    {
                        if (l.Trim().Length > 0)
                        {
                            outlines.Add(l.Trim());
                        }
                    }
                    //    outlines.Add(lines[i]);
                    //  if (lines[i][lines[i].Length - 1] != '%')
                    ///  {
                    //   i++;
                    while (lines[i][lines[i].Length - 1] != '%')
                    {
                        //     outlines.Add(lines[i]);
                        i++;
                    }
                    //                       outlines.Add(lines[i]);
                    //     }
                }
                else

                if (lines[i].Length > 3 && lines[i].Substring(0, 3) == "%AD")
                {
                    GCodeCommand GCC = new GCodeCommand();
                    GCC.Decode(lines[i], CoordinateFormat);
                    if (GCC.numbercommands.Count < 1)
                    {
                        log.AddString(String.Format("Skipping bad aperture definition: {0}", lines[i]));
                    }
                    else
                    {
                        int ATID     = (int)GCC.numbercommands[0];
                        var Aperture = subtr.State.Apertures[ATID];
                        if (Gerber.ShowProgress)
                        {
                            log.AddString(String.Format("found " + Aperture.ToString()));
                        }
                        string gerb = Aperture.BuildGerber(CoordinateFormat, "", 0);

                        if ((Aperture.ShapeType == GerberApertureShape.Compound || Aperture.ShapeType == GerberApertureShape.Macro) && subtr.State.ApertureMacros[Aperture.MacroName].Written == false)
                        {
                            log.AddString(String.Format("Macro type defined - skipping"));
                        }
                        else
                        {
                            outlines.Add(gerb);
                        }

                        //                   outlines.Add(lines[i]);
                        if (lines[i][lines[i].Length - 1] != '%')
                        {
                            i++;
                            while (lines[i] != "%")
                            {
                                //                         outlines.Add(lines[i]);
                                i++;
                            }
                            //                   outlines.Add(lines[i]);
                        }
                    }
                }
                else
                {
                    bool PureD = false;
                    if (GS.Has("G"))
                    {
                        int GCode = (int)GS.Get("G");
                        switch (GCode)
                        {
                        case 4: DumpToOutput = true; break;

                        case 90: CoordinateFormat.Relativemode = false; break;

                        case 91: CoordinateFormat.Relativemode = true; break;

                        case 71: CoordinateFormat.Multiplier = 1.0d; break;

                        case 70: CoordinateFormat.Multiplier = 25.4d; break;
                        }
                    }
                    if (DumpToOutput)
                    {
                        outlines.Add(lines[i]);
                        if (lines[i].Contains("LNData"))
                        {
                            log.AddString(String.Format(" heh"));
                        }
                        if (lines[i][0] == '%')
                        {
                            int starti = i;
                            if (lines[i].Length == 1)
                            {
                                i++;
                            }
                            while (lines[i][lines[i].Length - 1] != '%')
                            {
                                if (i > starti)
                                {
                                    outlines.Add(lines[i]);
                                }
                                i++;
                            }
                            if (i > starti)
                            {
                                outlines.Add(lines[i]);
                            }
                        }
                    }
                    else
                    {
                        bool translate = true;
                        if (CoordinateFormat.Relativemode)
                        {
                            translate = false;
                        }
                        if (GS.Has("X") == false && GS.Has("Y") == false && (GS.Has("D") && GS.Get("D") < 10))
                        {
                            PureD = true;
                            int Dcode = (int)GS.Get("D");
                            if (Dcode == 1 || Dcode == 3)
                            {
                                if (moveswritten == 0)
                                {
                                    WriteMove = true;
                                }
                            }
                            moveswritten++;
                            //log.AddString(String.Format("Pure D Code: {0}", lines[i]));
                        }
                        else
                        if (GS.Has("X") || GS.Has("Y") || (GS.Has("D") && GS.Get("D") < 10))
                        {
                            int Dcode = (int)GS.Get("D");
                            if (Dcode == 1 || Dcode == 3)
                            {
                                if (moveswritten == 0)
                                {
                                    WriteMove = true;
                                }
                            }
                            moveswritten++;
                            double X = LastX;
                            if (GS.Has("X"))
                            {
                                X = GS.Get("X");
                            }
                            double Y = LastY;
                            if (GS.Has("Y"))
                            {
                                Y = GS.Get("Y");
                            }
                            LastX = X;
                            LastY = Y;

                            GS.Set("X", X);
                            GS.Set("Y", Y);
                        }
                        if (GS.Get("D") >= 10)
                        {
                            CurrentAperture = (int)GS.Get("D");
                            // Select Aperture;
                        }
                        string hash = subtr.State.Apertures[CurrentAperture].GetApertureHash();
                        if (overlapList.ContainsKey(hash))
                        {
                            overlapList[hash].Item2.Add(new PointD(LastX, LastY));
                        }
                        if (WriteMove)
                        {
                            GerberSplitter GS2 = new GerberSplitter();
                            GS2.Set("D", 2);
                            double X0 = 0;
                            double Y0 = 0;
                            if (overlapList.ContainsKey(hash))
                            {
                                overlapList[hash].Item2.Add(new PointD(0, 0));
                            }
                            //GetTransformedCoord(DX, DY, DXp, DYp, Angle, CA, SA, CoordinateFormat, translate, ref X0, ref Y0);
                            GS2.Set("X", X0);
                            GS2.Set("Y", Y0);
                            WriteMove = false;
                            //                          outlines.Add(GS2.Rebuild(CoordinateFormat));
                        }
                        //                        outlines.Add(GS.Rebuild(CoordinateFormat));
                        if (PureD)
                        {
                            //log.AddString(String.Format("pureD"));
                        }
                    }
                }
            }
            try
            {
                //            List<String> PostProcLines = new List<string>();
                //              foreach (var a in outlines)
                //                {
                //  if (a == "%")
                //    {
                //          PostProcLines[PostProcLines.Count - 1] += "%";
                //        }
                //          else
                //            {
                //                  PostProcLines.Add(a);
                //                }
                //              }
                //                Gerber.WriteAllLines(outputfile, PolyLineSet.SanitizeInputLines(PostProcLines));
            }
            catch (Exception E)
            {
                log.AddString(String.Format(E.Message));
            }
            log.PopActivity();


            return(overlapList);
        }
Exemple #15
0
        private List <Shape> LoadGerber(string Path)
        {
            BoardFileType FileType = Gerber.FindFileType(Path);

            if (FileType == BoardFileType.Unsupported)
            {
                return(null);
            }

            ParsedGerber      PLS;
            GerberParserState State = new GerberParserState()
            {
                PreCombinePolygons = false
            };

            if (FileType == BoardFileType.Drill)
            {
                PLS = PolyLineSet.LoadExcellonDrillFile(Path, false, 1.0);
            }
            else
            {
                bool forcezerowidth     = false;
                bool precombinepolygons = false;

                BoardSide  Side  = BoardSide.Unknown;
                BoardLayer Layer = BoardLayer.Unknown;
                Gerber.DetermineBoardSideAndLayer(Path, out Side, out Layer);

                if (Layer == BoardLayer.Outline || Layer == BoardLayer.Mill)
                {
                    forcezerowidth     = true;
                    precombinepolygons = true;
                }
                State.PreCombinePolygons = precombinepolygons;

                PLS       = PolyLineSet.LoadGerberFile(Path, forcezerowidth, false, State);
                PLS.Side  = State.Side;
                PLS.Layer = State.Layer;

                if (Layer == BoardLayer.Outline)
                {
                    PLS.FixPolygonWindings();
                }
            }

            //Convert the gerber polygons into a generic shape list used by other functions
            List <Shape> retShape = new List <Shape>();

            foreach (var shape in PLS.DisplayShapes)
            {
                Shape tempShape = new Shape();

                tempShape.Vertices = new List <Vector2d>();

                for (int i = 0; i < shape.Vertices.Count; i++)
                {
                    tempShape.Vertices.Add(new Vector2d(shape.Vertices[i].X, shape.Vertices[i].Y));
                }

                retShape.Add(tempShape);
            }

            return(retShape);
        }