コード例 #1
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);
        }
コード例 #2
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();
        }