Example #1
0
        public void AddFileStream(ProgressLog log, MemoryStream S, string origfilename, double drillscaler = 1.0)
        {
            var FileType = Gerber.FindFileTypeFromStream(new StreamReader(S), origfilename);

            S.Seek(0, SeekOrigin.Begin);

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

            ParsedGerber PLS;


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

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

                // ExcellonFile EF = new ExcellonFile();
                // EF.Load(a);
            }
            else
            {
                bool       forcezerowidth     = false;
                bool       precombinepolygons = false;
                BoardSide  Side  = BoardSide.Unknown;
                BoardLayer Layer = BoardLayer.Unknown;
                Gerber.DetermineBoardSideAndLayer(origfilename, out Side, out Layer);
                if (Layer == BoardLayer.Outline || Layer == BoardLayer.Mill)
                {
                    forcezerowidth     = true;
                    precombinepolygons = true;
                }
                State.PreCombinePolygons = precombinepolygons;


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

                PLS.Side  = Side;
                PLS.Layer = Layer;
            }

            Gerbers.Add(new DisplayGerber()
            {
                File = PLS, visible = true, sortindex = Gerber.GetDefaultSortOrder(PLS.Side, PLS.Layer), Color = Colors.GetDefaultColor(PLS.Layer, PLS.Side)
            });
        }
Example #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);
        }