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); }
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(); }
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); }