Exemple #1
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 #2
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);
        }