Esempio n. 1
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();
        }
Esempio n. 2
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);

            using (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);
            }
        }
Esempio n. 3
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(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();
        }
Esempio n. 4
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);
        }