コード例 #1
0
ファイル: PnPProcDoc.cs プロジェクト: ixhuti/GerberTools
        private void LoadStuff()
        {
            if (stock.Length > 0 && File.Exists(stock))
            {
                try
                {
                    log.PushActivity("Loading stock");
                    StockDoc = StockDocument.Load(stock);
                    if (StockDoc == null)
                    {
                        StockDoc = new StockDocument();
                    }
                }
                catch (Exception)
                {
                    StockDoc = new StockDocument();
                }
                log.PopActivity();
            }
            else
            {
                StockDoc = new StockDocument();
            }
            log.PushActivity("Loading document");
            B = new BOM();

            if (bom.Length > 0 && pnp.Length > 0)
            {
                String DirBaseName = Path.GetFileNameWithoutExtension(pnp);
                log.PushActivity("Processing " + DirBaseName);

                log.PushActivity("Loading BOM");
                log.AddString(String.Format("Loading BOM! {0},{1}", Path.GetFileName(bom), Path.GetFileName(pnp)));
                B.LoadJLC(bom, pnp);
                log.PopActivity();

                if (gerberzip != null && File.Exists(gerberzip))
                {
                    Set = LoadGerberZip(gerberzip, log);
                }
                else
                {
                    Set = new GerberImageCreator();
                }
                Box = Set.BoundingBox;

                BuildPostBom();

                log.PopActivity();
            }
            else
            {
                log.AddString(String.Format("pnp and bom need to be valid! bom:{0} pnp:{1}", bom, pnp));
            }


            loaded = true;
            log.AddString("Done!");
            log.PopActivity();
        }
コード例 #2
0
ファイル: PnPProcDoc.cs プロジェクト: Witawat/GerberTools
        private void LoadStuff()
        {
            log.PushActivity("Loading document");
            B = new BOM();

            if (bom.Length > 0 && pnp.Length > 0)
            {
                String DirBaseName = Path.GetFileNameWithoutExtension(pnp);
                log.PushActivity("Processing " + DirBaseName);

                log.PushActivity("Loading BOM");
                log.AddString(String.Format("Loading BOM! {0},{1}", Path.GetFileName(bom), Path.GetFileName(pnp)));
                B.LoadJLC(bom, pnp);
                BuildPostBom();
                log.PopActivity();

                if (gerberzip != null && File.Exists(gerberzip))
                {
                    Set = LoadGerberZip(gerberzip, log);
                }
                else
                {
                    Set = new GerberImageCreator();
                    Set.AddBoardToSet(silk, log);
                    Set.AddBoardToSet(outline, log);
                }
                Box = Set.BoundingBox;


                //            string OutputGerberName = fixedoutputfolder + "\\" + Path.GetFileName(boardfile);
                //B.WriteRefDesGerber(OutputGerberName+"ORIGPLACEMENT");
                FixOffset = new PointD(-Set.BoundingBox.TopLeft.X, -Set.BoundingBox.BottomRight.Y);
                //                B.WriteRefDesGerber(OutputGerberName);
                //              B.WriteJLCCSV(fixedoutputfolder, Path.GetFileName(filebase), true);

                log.PopActivity();
            }
            else
            {
                log.AddString(String.Format("pnp and bom need to be valid! bom:{0} pnp:{1}", bom, pnp));
            }


            loaded = true;
            log.AddString("Done!");
            log.PopActivity();
        }
コード例 #3
0
ファイル: Viewer.cs プロジェクト: valor7/GerberTools
        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);
                }
            }
        }