Ejemplo n.º 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)
            });
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        internal void Load(string basefile)
        {
            Text = Path.GetFileNameWithoutExtension(basefile);

            string fn         = Path.GetFileName(basefile);
            string basefolder = Path.GetDirectoryName(basefile);
            string name       = fn.Split('_')[0];

            string BOMFile    = "";
            string PnPFile    = "";
            string gerberFile = "";
            var    L          = Directory.GetFiles(basefolder, name + "_*.*");

            SolderFile = "";
            foreach (var file in L)
            {
                if (file.EndsWith("_BOM.csv"))
                {
                    BOMFile = file;
                }
                if (file.EndsWith("_gerbers.zip"))
                {
                    gerberFile = file;
                }
                if (file.EndsWith("_PNP.csv"))
                {
                    PnPFile = file;
                }
                if (file.EndsWith("_soldered.txt"))
                {
                    SolderFile = file;
                }
            }

            LayerSets.Add(new LayerSet()
            {
                Side = BoardSide.Both, Layer = BoardLayer.Outline
            });
            LayerSets.Add(new LayerSet()
            {
                Side = BoardSide.Top, Layer = BoardLayer.SolderMask
            });
            LayerSets.Add(new LayerSet()
            {
                Side = BoardSide.Top, Layer = BoardLayer.Silk
            });
            LayerSets.Add(new LayerSet()
            {
                Side = BoardSide.Bottom, Layer = BoardLayer.SolderMask
            });
            LayerSets.Add(new LayerSet()
            {
                Side = BoardSide.Bottom, Layer = BoardLayer.Silk
            });
            if (BOMFile.Length > 0 && PnPFile.Length > 0 && gerberFile.Length > 0)
            {
                BOM B = new BOM();
                B.LoadJLC(BOMFile, PnPFile);
                TheBOM = B;

                if (SolderFile.Length > 0)
                {
                    solderedlist = File.ReadAllLines(SolderFile).ToList();

                    foreach (var a in B.DeviceTree)
                    {
                        foreach (var v in a.Value.Values)
                        {
                            if (solderedlist.Contains(v.Combined()))
                            {
                                v.Soldered = true;
                            }
                        }
                    }
                }
                else
                {
                    SolderFile = Path.Combine(basefolder, name + "_soldered.txt");
                    SaveSolderedList();
                }


                GerberLibrary.GerberImageCreator GIC = new GerberLibrary.GerberImageCreator();

                List <string> res = new List <string>();
                Dictionary <string, MemoryStream> Files = new Dictionary <string, MemoryStream>();
                using (Ionic.Zip.ZipFile zip1 = Ionic.Zip.ZipFile.Read(gerberFile))
                {
                    foreach (ZipEntry e in zip1)
                    {
                        MemoryStream MS = new MemoryStream();
                        if (e.IsDirectory == false)
                        {
                            e.Extract(MS);
                            MS.Seek(0, SeekOrigin.Begin);
                            Files[e.FileName] = MS;
                        }
                    }
                }


                string[]      FileNames       = Files.Keys.ToArray();
                List <string> outlinefiles    = new List <string>();
                List <string> topsilkfiles    = new List <string>();
                List <string> bottomsilkfiles = new List <string>();

                foreach (var F in FileNames)
                {
                    BoardSide  BS = BoardSide.Unknown;
                    BoardLayer BL = BoardLayer.Unknown;
                    Files[F].Seek(0, SeekOrigin.Begin);
                    if (Gerber.FindFileTypeFromStream(new StreamReader(Files[F]), F) == BoardFileType.Gerber)
                    {
                        Gerber.DetermineBoardSideAndLayer(F, out BS, out BL);
                        foreach (var l in LayerSets)
                        {
                            if (l.Side == BS && l.Layer == BL)
                            {
                                l.Files.Add(F);
                                Files[F].Seek(0, SeekOrigin.Begin);
                                var pls = PolyLineSet.LoadGerberFileFromStream(new StandardConsoleLog(), new StreamReader(Files[F]), F, true, false, new GerberParserState()
                                {
                                    PreCombinePolygons = false
                                });
                                l.Gerbs.Add(pls);
                            }
                        }
                    }
                }
                TheBox.Reset();

                foreach (var a in LayerSets[0].Gerbs)
                {
                    TheBox.AddBox(a.BoundingBox);
                }
            }
        }