Ejemplo n.º 1
0
        private void saveArtworkgerberToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (gerbersaveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    GerberArtWriter GAW = new GerberArtWriter();

                    double S = 72.0 / 200.0;
                    foreach (var a in ArtRender.SubDivPoly)
                    {
                        PolyLine PL = new PolyLine(PolyLine.PolyIDs.ArtWork);
                        PL.Add(a.Vertices[0].x * S, (Mask.Height - a.Vertices[0].y) * S);
                        PL.Add(a.Vertices[1].x * S, (Mask.Height - a.Vertices[1].y) * S);
                        PL.Add(a.Vertices[2].x * S, (Mask.Height - a.Vertices[2].y) * S);
                        PL.Add(a.Vertices[0].x * S, (Mask.Height - a.Vertices[0].y) * S);
                        GAW.AddPolyLine(PL, 0.1);
                    }
                    GAW.Write(gerbersaveFileDialog1.FileName);
                }
                catch (Exception E)
                {
                }
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            string basepath = Directory.GetCurrentDirectory();

            Directory.CreateDirectory(Path.Combine(basepath, "outline"));
            Directory.CreateDirectory(Path.Combine(basepath, "frame"));

            GerberFrameWriter.FrameSettings FS = new GerberFrameWriter.FrameSettings();
            PolyLine PL = new PolyLine();

            FS.FrameTitle   = "Test Frame";
            FS.RenderSample = false;
            FS.margin       = 3;

            PL.MakeRoundedRect(new PointD(10, 10), new PointD(200, 200), 7);
            FS.PositionAround(PL);
            //FS.offset = new PointD(200, 200);
            FS.RenderSample = true;

            GerberArtWriter GAW = new GerberArtWriter();

            GAW.AddPolyLine(PL);
            GAW.Write("outline/outtestinside.gko");


            GerberFrameWriter.WriteSideEdgeFrame(PL, FS, "frame/outtest");
            GerberFrameWriter.MergeFrameIntoGerberSet(Path.Combine(basepath, "frame"), Path.Combine(basepath, "outline"), Path.Combine(basepath, "mergedoutput"), FS, new FrameCreatorTest(), "testframe");


            GerberFrameWriter.MergeFrameIntoGerberSet(Path.Combine(basepath, "SliceFrameOutline6"), Path.Combine(basepath, "Slice6"), Path.Combine(basepath, "slice6inframe"), FS, new FrameCreatorTest(), "slice6framed");



            //            PNL.SaveOutlineTo("panelized.gko", "panelcombinedgko.gko");
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            string basepath = Directory.GetCurrentDirectory();

            Directory.CreateDirectory(Path.Combine(basepath, "outline"));
            Directory.CreateDirectory(Path.Combine(basepath, "frame"));

            Directory.CreateDirectory(Path.Combine(basepath, "imagetest"));

            GerberFrameWriter.FrameSettings FS = new GerberFrameWriter.FrameSettings();
            PolyLine PL = new PolyLine();

            FS.FrameTitle   = "Test Frame";
            FS.RenderSample = false;
            FS.margin       = 3;

            PL.MakeRoundedRect(new PointD(-50, -50), new PointD(50, 50), 7);
            //FS.offset = new PointD(200, 200);
            FS.RenderSample = false;

            GerberArtWriter GAW = new GerberArtWriter();

            GAW.AddPolyLine(PL);

            GAW.Write("outline/outtestinside.gko");

            // Bitmap FrontPrint = (Bitmap)Bitmap.FromFile("BigJigImage.png");
            // Bounds FrontBound = new Bounds() { BottomRight = new PointD(220, 230), TopLeft = new PointD(-220, -230) , Valid = true};

            // PCBWriterSet s = new PCBWriterSet();
            // s.TopSilk.WriteImageToBounds(FrontPrint, FrontBound, new Bounds() { TopLeft = new PointD(-10, -10), BottomRight = new PointD(10, 10),Valid = true });
            // s.Write("imagetest", "test!");

            FS.RenderDirectionArrow = true;
            FS.DirectionArrowSide   = GerberLibrary.Core.BoardSide.Bottom;
            FS.DefaultFiducials     = true;
            FS.FiducialSide         = BoardSide.Both;
            FS.HorizontalTabs       = true;
            FS.VerticalTabs         = true;
            FS.InsideEdgeMode       = GerberFrameWriter.FrameSettings.InsideMode.FormFitting;
            FS.PositionAround(PL);
            BOM OutFiducials = new BOM();

            GerberFrameWriter.WriteSideEdgeFrame(PL, FS, Path.Combine(basepath, "frame/outtest"), OutFiducials);
            FS.RenderSample = true;
            GerberFrameWriter.MergeFrameIntoGerberSet(Path.Combine(basepath, "frame"), Path.Combine(basepath, "outline"), Path.Combine(basepath, "mergedoutput"), FS, new FrameCreatorTest(), "testframe");

            //           GerberFrameWriter.MergeFrameIntoGerberSet(Path.Combine(basepath, "SliceFrameOutline6"), Path.Combine(basepath, "Slice6"), Path.Combine(basepath, "slice6inframe"), FS, new FrameCreatorTest(),"slice6framed" );
            // PNL.SaveOutlineTo("panelized.gko", "panelcombinedgko.gko");
            //Console.ReadKey();
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            string basepath = Directory.GetCurrentDirectory();

            Directory.CreateDirectory(Path.Combine(basepath, "outline"));
            Directory.CreateDirectory(Path.Combine(basepath, "frame"));

            Directory.CreateDirectory(Path.Combine(basepath, "imagetest"));

            GerberFrameWriter.FrameSettings FS = new GerberFrameWriter.FrameSettings();
            PolyLine PL = new PolyLine();

            FS.FrameTitle   = "Test Frame";
            FS.RenderSample = false;
            FS.margin       = 3;

            PL.MakeRoundedRect(new PointD(10, 10), new PointD(400, 300), 7);
            FS.PositionAround(PL);
            //FS.offset = new PointD(200, 200);
            FS.RenderSample = true;

            GerberArtWriter GAW = new GerberArtWriter();

            GAW.AddPolyLine(PL);

            GAW.Write("outline/outtestinside.gko");

            Bitmap FrontPrint = (Bitmap)Bitmap.FromFile("BigJigImage.png");
            Bounds FrontBound = new Bounds()
            {
                BottomRight = new PointD(220, 230), TopLeft = new PointD(-220, -230), Valid = true
            };

            PCBWriterSet s = new PCBWriterSet();

            s.TopSilk.WriteImageToBounds(FrontPrint, FrontBound, new Bounds()
            {
                TopLeft = new PointD(-10, -10), BottomRight = new PointD(10, 10), Valid = true
            });
            s.Write("imagetest", "test!");

//            GerberFrameWriter.WriteSideEdgeFrame(PL, FS, "frame/outtest");
//          GerberFrameWriter.MergeFrameIntoGerberSet(Path.Combine(basepath, "frame"), Path.Combine(basepath, "outline"), Path.Combine(basepath, "mergedoutput"),FS, new FrameCreatorTest(),"testframe");

//            GerberFrameWriter.MergeFrameIntoGerberSet(Path.Combine(basepath, "SliceFrameOutline6"), Path.Combine(basepath, "Slice6"), Path.Combine(basepath, "slice6inframe"), FS, new FrameCreatorTest(),"slice6framed" );
//            PNL.SaveOutlineTo("panelized.gko", "panelcombinedgko.gko");
        }
Ejemplo n.º 5
0
        public List <string> Write(string targetfolder, string basename, PointD offset = null)
        {
            if (offset == null)
            {
                offset = new PointD(0, 0);
            }

            List <string> Files      = new List <string>();
            ExcellonFile  EF         = new ExcellonFile();
            int           drillcount = 0;

            foreach (var h in DrillHoles)
            {
                ExcellonTool DrillBit = new ExcellonTool();
                DrillBit.Radius = h.Key / 2.0f;

                foreach (var a in h.Value)
                {
                    DrillBit.Drills.Add(a);
                }
                EF.Tools[10 + drillcount] = DrillBit;
                drillcount++;
            }
            string DrillFile = Path.Combine(targetfolder, basename + ".txt");

            EF.Write(DrillFile, offset.X, offset.Y, 0, 0);
            Files.Add(DrillFile);

            string OutName = Path.Combine(targetfolder, basename);

            Outline.Write(OutName + ".gko", offset); Files.Add(OutName + ".gko");
            TopSilk.Write(OutName + ".gto", offset); Files.Add(OutName + ".gto");
            TopCopper.Write(OutName + ".gtl", offset); Files.Add(OutName + ".gtl");

            TopSolderMask.Write(OutName + ".gts", offset); Files.Add(OutName + ".gts");

            BottomSilk.Write(OutName + ".gbo", offset); Files.Add(OutName + ".gbo");
            BottomCopper.Write(OutName + ".gbl", offset); Files.Add(OutName + ".gbl");
            BottomSolderMask.Write(OutName + ".gbs", offset); Files.Add(OutName + ".gbs");


            return(Files);
        }
Ejemplo n.º 6
0
        public void WriteAntennaBoard(double width, double height, double mountholediameter, double cornerrounding, double mountholeclearance, double edgeclearance = 1.26, bool WriteCombinedImage = true, bool WriteImages = false)
        {
            int     polyid = 0;
            FontSet FS     = FontSet.Load("Font.xml");

            List <String> FilesGenerated = new List <string>();
            double        LabelHeight    = 1.2;
            //double PadWidth = 1.8;
            double DrillWidth = 1.0;

            string basename = String.Format("Generated_This_is_not_RocketScience_Antenna_{0}x{1}cm", width / 10.0f, height / 10.0f);

            try
            {
                Directory.CreateDirectory(basename);
            }
            catch (Exception)
            {
            }
            basename = Path.Combine(basename, String.Format("proto_{0}x{1}cm", width / 10.0f, height / 10.0f));
            string OutlineFile      = basename + ".gko";
            string SilkFileTop      = basename + ".gto";
            string SilkFileBottom   = basename + ".gbo";
            string SolderMaskBottom = basename + ".gbs";
            string SolderMaskTop    = basename + ".gts";
            string CopperBottom     = basename + ".gbl";
            string CopperTop        = basename + ".gtl";
            string DrillFile        = basename + ".txt";

            ExcellonFile EF = new ExcellonFile();

            ExcellonTool MountHoleDrill = new ExcellonTool();

            MountHoleDrill.Radius = mountholediameter / 2.0;


            PointD C1 = new PointD(mountholeclearance, mountholeclearance);
            PointD C2 = new PointD(width - mountholeclearance, mountholeclearance);
            PointD C3 = new PointD(width - mountholeclearance, height - mountholeclearance);
            PointD C4 = new PointD(mountholeclearance, height - mountholeclearance);

            MountHoleDrill.Drills.Add(C1);
            MountHoleDrill.Drills.Add(C2);
            MountHoleDrill.Drills.Add(C3);
            MountHoleDrill.Drills.Add(C4);

            EF.Tools[10] = MountHoleDrill;

            ViaDrill.Radius = 0.6 / 2.0;

            EF.Tools[11] = ViaDrill;


            ExcellonTool ProtoHoleDrill = new ExcellonTool();

            ProtoHoleDrill.Radius = DrillWidth / 2.0;

            PointD pC1 = new PointD(mountholeclearance, height / 2 - 2.54);
            PointD pC2 = new PointD(mountholeclearance, height / 2);
            PointD pC3 = new PointD(mountholeclearance, height / 2 + 2.54);

            ProtoHoleDrill.Drills.Add(pC1);
            ProtoHoleDrill.Drills.Add(pC2);
            ProtoHoleDrill.Drills.Add(pC3);

            MaskBottom.AddFlash(pC1, 1);
            MaskBottom.AddFlash(pC2, 1);
            MaskBottom.AddFlash(pC3, 1);
            MaskTop.AddFlash(pC1, 1);
            MaskTop.AddFlash(pC2, 1);
            MaskTop.AddFlash(pC3, 1);

            PolyLine PL = new PolyLine(polyid++);

            PL.Add(cornerrounding, 0);
            PL.Add(width - cornerrounding, 0);
            PL.ArcTo(new PointD(width, cornerrounding), new PointD(0, cornerrounding), InterpolationMode.CounterClockwise);
            PL.Add(width, height - cornerrounding);
            PL.ArcTo(new PointD(width - cornerrounding, height), new PointD(-cornerrounding, 0), InterpolationMode.CounterClockwise);
            PL.Add(cornerrounding, height);
            PL.ArcTo(new PointD(0, height - cornerrounding), new PointD(0, -cornerrounding), InterpolationMode.CounterClockwise);
            PL.Add(0, cornerrounding);
            PL.ArcTo(new PointD(cornerrounding, 0), new PointD(cornerrounding, 0), InterpolationMode.CounterClockwise);
            PL.Close();

            GAW.AddPolyLine(PL, 0);
            GAW.Write(OutlineFile);

            double AX  = C1.X + mountholeclearance;
            double AY  = C1.Y + mountholeclearance;
            double gap = 5;


            double W = width - AX * 2;
            double H = height - AY * 2 - gap;

            int rounds = 6;

            antennatracewidth = 0.3 / 2;

            double spacing = 0.8;

            for (int i = 0; i < rounds; i++)
            {
                double W2 = W - i * spacing * 2;
                double H2 = H - i * spacing * 2;

                double W3 = W - (i + 1) * spacing * 2;
                double H3 = H - (i + 1) * spacing * 2;

                double AX2 = AX + i * spacing;
                double AY2 = AY + i * spacing;

                double AX3 = AX + (i + 1) * spacing;
                double AY3 = AY + (i + 1) * spacing;

                PolyLine PL2 = new PolyLine(polyid++);

                PL2.Add(AX2, AY2 + H2 / 2);
                PL2.Add(AX2, AY2);
                PL2.Add(AX2 + W2, AY2);
                PL2.Add(AX2 + W2, AY2 + H2 / 2);
                AddAntennaTop(PL2);


                PolyLine PL3 = new PolyLine(polyid++);

                PL3.Add(AX2, AY2 + gap + H2 - (H2 / 2));
                PL3.Add(AX2, AY2 + gap + H2);
                PL3.Add(AX2 + W2, AY2 + gap + H2);
                PL3.Add(AX2 + W2, AY2 + gap + H2 - (H2 / 2));
                AddAntennaTop(PL3);
                double gs = 2;

                if (i % 2 == 1)
                {
                    if (i < rounds - 1)
                    {
                        PolyLine PL4 = new PolyLine(polyid++);
                        PL4.Add(AX2, AY2 + gap + H2 - (H2 / 2));
                        PL4.Add(AX2, AY2 + gap - gs + H2 - (H2 / 2));
                        PL4.Add(AX3, AY3 + gs + (H3 / 2));
                        PL4.Add(AX3, AY3 + (H3 / 2));
                        AddAntennaTop(PL4);

                        PolyLine PL5 = new PolyLine(polyid++);
                        PL5.Add(AX3, AY3 + gap + H3 - (H3 / 2));
                        PL5.Add(AX2, AY2 + (H2 / 2));
                        AddAntennaBottom(PL5);

                        AddAntennaVia(AX3, AY3 + gap + H3 - (H3 / 2));
                        AddAntennaVia(AX2, AY2 + (H2 / 2));
                    }
                    else
                    {
                        PolyLine PL4 = new PolyLine(polyid++);
                        PL4.Add(AX2, AY2 + gap + H2 - (H2 / 2));
                        PL4.Add(AX2, AY2 + (H2 / 2));
                        AddAntennaTop(PL4);

                        AddAntennaVia(AX2, AY2 + H2 / 2 + gap / 2);

                        PolyLine PL5 = new PolyLine(polyid++);
                        PL5.Add(AX2, AY2 + H2 / 2 + gap / 2);
                        PL5.Add(AX2, AY2 + H2 / 2 - gs);
                        PL5.Add(AX - spacing, AY2 + H2 / 2 - gs);
                        PL5.Add(AX - spacing, AY2 + H2 / 2 + gap / 2);

                        AddAntennaVia(AX - spacing, AY2 + H2 / 2 + gap / 2);

                        AddAntennaBottom(PL5);
                    }
                }
                else
                {
                    PolyLine PL4 = new PolyLine(polyid++);
                    PL4.Add(AX2 + W2, AY2 + gap + H2 - (H2 / 2));
                    PL4.Add(AX2 + W2, AY2 + gap - gs + H2 - (H2 / 2));
                    PL4.Add(AX3 + W3, AY3 + gs + (H3 / 2));
                    PL4.Add(AX3 + W3, AY3 + (H3 / 2));
                    AddAntennaTop(PL4);

                    PolyLine PL5 = new PolyLine(polyid++);
                    PL5.Add(AX3 + W3, AY3 + gap + H3 - (H3 / 2));
                    PL5.Add(AX2 + W2, AY2 + (H2 / 2));

                    AddAntennaBottom(PL5);

                    PolyLine PL6 = new PolyLine(polyid++);
                    PL6.Add(AX, AY + H / 2);
                    PL6.Add(pC1.X, pC1.Y);
                    AddAntennaTop(PL6);

                    PolyLine PL7 = new PolyLine(polyid++);
                    PL7.Add(AX, AY + H / 2 + gap);
                    PL7.Add(pC3.X, pC3.Y);
                    AddAntennaTop(PL7);

                    PolyLine PL8 = new PolyLine(polyid++);
                    PL8.Add(AX - spacing, AY2 + H2 / 2 + gap / 2);
                    PL8.Add(pC2.X, pC2.Y);
                    AddAntennaTop(PL8);


                    AddAntennaVia(AX3 + W3, AY3 + gap + H3 - (H3 / 2));
                    AddAntennaVia(AX2 + W2, AY2 + (H2 / 2));
                }
            }


            string R = "NFC antenna: " + AntennaLen.ToString("N2") + " mm";

            // MaskTop.DrawString(new PointD(width / 2, 5), FS, R, LabelHeight, 0.05, StringAlign.CenterCenter);
            // MaskBottom.DrawString(new PointD(width / 2, 5), FS, R, LabelHeight, 0.05, StringAlign.CenterCenter, true);
            SilkTop.DrawString(new PointD(width / 2, 5), FS, R, LabelHeight, 0.05, StringAlign.CenterCenter);
            SilkBottom.DrawString(new PointD(width / 2, 5), FS, R, LabelHeight, 0.05, StringAlign.CenterCenter, true);


            GAWTop.Write(CopperTop);

            GAWBottom.Write(CopperBottom);
            SilkBottom.Write(SilkFileBottom);
            SilkTop.Write(SilkFileTop);

            MaskTop.Write(SolderMaskTop);
            MaskBottom.Write(SolderMaskBottom);
            EF.Tools[12] = ProtoHoleDrill;
            EF.Write(DrillFile, 0, 0, 0, 0);

            FilesGenerated.Add(CopperBottom);
            FilesGenerated.Add(CopperTop);
            FilesGenerated.Add(OutlineFile);
            FilesGenerated.Add(DrillFile);
            FilesGenerated.Add(SilkFileBottom);
            FilesGenerated.Add(SilkFileTop);
            FilesGenerated.Add(SolderMaskBottom);
            FilesGenerated.Add(SolderMaskTop);


            if (WriteCombinedImage)
            {
                GerberImageCreator GIC = new GerberImageCreator();
                GIC.AddBoardsToSet(FilesGenerated);
                GIC.WriteImageFiles(basename + "_render", 200, false);
            }
            if (WriteImages)
            {
                Gerber.SaveGerberFileToImage(OutlineFile, OutlineFile + "_render.png", 1000, Color.Black, Color.White);
                Gerber.SaveGerberFileToImage(CopperBottom, CopperBottom + "_render.png", 1000, Color.Black, Color.White);
                Gerber.SaveGerberFileToImage(CopperTop, CopperTop + "_render.png", 1000, Color.Black, Color.White);
                Gerber.SaveGerberFileToImage(DrillFile, DrillFile + "_render.png", 1000, Color.Black, Color.White);
                Gerber.SaveGerberFileToImage(SilkFileTop, SilkFileTop + "_render.png", 1000, Color.Black, Color.White);
                Gerber.SaveGerberFileToImage(SilkFileBottom, SilkFileBottom + "_render.png", 1000, Color.Black, Color.White);
            }
        }
Ejemplo n.º 7
0
        public static List <String> WriteProtoBoardFlowerStyle(double width, double height, double mountholediameter, double cornerrounding, double mountholeclearance, double edgeclearance = 1.26, bool WriteCombinedImage = true, bool WriteImages = false)
        {
            FontSet       FS             = FontSet.Load("Font.xml");
            int           polyid         = 0;
            List <String> FilesGenerated = new List <string>();
            double        LabelHeight    = 1.2;
            double        PadWidth       = 1.8;
            double        DrillWidth     = 1.0;

            string basename = String.Format("Generated_This_is_not_RocketScience_Flower_prototoboard_{0}x{1}cm", width / 10.0f, height / 10.0f);

            try
            {
                Directory.CreateDirectory(basename);
            }
            catch (Exception)
            {
            }
            basename = Path.Combine(basename, String.Format("proto_{0}x{1}cm", width / 10.0f, height / 10.0f));
            string OutlineFile      = basename + ".gko";
            string SilkFileTop      = basename + ".gto";
            string SilkFileBottom   = basename + ".gbo";
            string SolderMaskBottom = basename + ".gbs";
            string SolderMaskTop    = basename + ".gts";
            string CopperBottom     = basename + ".gbl";
            string CopperTop        = basename + ".gtl";
            string DrillFile        = basename + ".txt";


            int XE = (int)Math.Floor((width - Math.Max(edgeclearance, LabelHeight) * 2) / 2.54);
            int YE = (int)Math.Floor((height - Math.Max(edgeclearance, LabelHeight) * 2) / 2.54);

            PrepareGridSpace(XE, YE, true, true, 3, 2);

            string[][] Grid = new string[XE + 1][];
            for (int x = 0; x <= XE; x++)
            {
                Grid[x] = new string[YE + 1];
                for (int y = 0; y <= YE; y++)
                {
                    Grid[x][y] = GridSpaceType(x, y);
                    if (y == YE)
                    {
                        Grid[x][y] = "None";
                    }
                    if (x == XE)
                    {
                        Grid[x][y] = "None";
                    }
                }
            }

            double XO = (width / 2) - (XE / 2.0) * 2.54;
            double YO = (height / 2) - (YE / 2.0) * 2.54;

            Console.WriteLine("{0} rows and {1} columns", YE, XE);


            ExcellonFile EF = new ExcellonFile();
            PointD       C1 = new PointD(0, 0);
            PointD       C2 = new PointD(width, 0);
            PointD       C3 = new PointD(width, height);
            PointD       C4 = new PointD(0, height);

            if (mountholediameter > 0)
            {
                ExcellonTool MountHoleDrill = new ExcellonTool();
                MountHoleDrill.Radius = mountholediameter / 2.0;


                C1 = new PointD(mountholeclearance, mountholeclearance);
                C2 = new PointD(width - mountholeclearance, mountholeclearance);
                C3 = new PointD(width - mountholeclearance, height - mountholeclearance);
                C4 = new PointD(mountholeclearance, height - mountholeclearance);
                MountHoleDrill.Drills.Add(C1);
                MountHoleDrill.Drills.Add(C2);
                MountHoleDrill.Drills.Add(C3);
                MountHoleDrill.Drills.Add(C4);

                EF.Tools[10] = MountHoleDrill;
            }
            ExcellonTool ProtoHoleDrill = new ExcellonTool();

            ProtoHoleDrill.Radius = DrillWidth / 2.0;



            PolyLine PL = new PolyLine(polyid++);

            PL.Add(cornerrounding, 0);
            PL.Add(width - cornerrounding, 0);
            PL.ArcTo(new PointD(width, cornerrounding), new PointD(0, cornerrounding), InterpolationMode.CounterClockwise);
            PL.Add(width, height - cornerrounding);
            PL.ArcTo(new PointD(width - cornerrounding, height), new PointD(-cornerrounding, 0), InterpolationMode.CounterClockwise);
            PL.Add(cornerrounding, height);
            PL.ArcTo(new PointD(0, height - cornerrounding), new PointD(0, -cornerrounding), InterpolationMode.CounterClockwise);
            PL.Add(0, cornerrounding);
            PL.ArcTo(new PointD(cornerrounding, 0), new PointD(cornerrounding, 0), InterpolationMode.CounterClockwise);
            PL.Close();

            GerberArtWriter GAW = new GerberArtWriter();

            GAW.AddPolyLine(PL, 0);
            GAW.Write(OutlineFile);

            GerberArtWriter GAWTop    = new GerberArtWriter();
            GerberArtWriter GAWBottom = new GerberArtWriter();

            GerberArtWriter MaskTop    = new GerberArtWriter();
            GerberArtWriter MaskBottom = new GerberArtWriter();
            GerberArtWriter SilkTop    = new GerberArtWriter();
            GerberArtWriter SilkBottom = new GerberArtWriter();

            for (int x = 0; x < XE; x++)
            {
                double xc = XO + x * 2.54 + 2.54 / 2;
                for (int y = 0; y < YE; y++)
                {
                    double yc = YO + y * 2.54 + 2.54 / 2;

                    PointD P = new PointD(xc, yc);
                    if ((P - C1).Length() < edgeclearance + mountholediameter / 2 + 1.27)
                    {
                        Grid[x][y] = "None";
                    }
                    if ((P - C2).Length() < edgeclearance + mountholediameter / 2 + 1.27)
                    {
                        Grid[x][y] = "None";
                    }
                    if ((P - C3).Length() < edgeclearance + mountholediameter / 2 + 1.27)
                    {
                        Grid[x][y] = "None";
                    }
                    if ((P - C4).Length() < edgeclearance + mountholediameter / 2 + 1.27)
                    {
                        Grid[x][y] = "None";
                    }

                    if (Grid[x][y] != "None")
                    {
                        GAWTop.AddFlash(new PointD(xc, yc), DrillWidth * 1.3 / 2.0);
                        GAWBottom.AddFlash(new PointD(xc, yc), DrillWidth * 1.3 / 2.0);
                        MaskTop.AddFlash(new PointD(xc, yc), DrillWidth * 1.3 / 2.0);
                        MaskBottom.AddFlash(new PointD(xc, yc), DrillWidth * 1.3 / 2.0);
                        ProtoHoleDrill.Drills.Add(new PointD(xc, yc));
                    }
                }
            }

            //            SilkTop.DrawString(new PointD(5, 0), FS, "O0O", 5, 0.05, StringAlign.BottomCenter);
            //           SilkTop.DrawString(new PointD(20, 0), FS, "O0O", 5, 0.05, StringAlign.CenterCenter);
            //         SilkTop.DrawString(new PointD(40, 0), FS, "OMO", 5, 0.05, StringAlign.TopCenter);

            for (int x = 0; x < XE; x++)
            {
                double xc  = XO + x * 2.54 + 2.54 / 2;
                double yc  = YO + (0) * 2.54;
                double yc1 = YO + (YE) * 2.54 + 2.54;
                char   T   = (char)('A' + (char)((x) % 26));

                if (Grid[x][0] != "None")
                {
                    SilkTop.DrawString(new PointD(xc, yc), FS, T.ToString(), LabelHeight, 0.05, StringAlign.CenterCenter);
                    SilkBottom.DrawString(new PointD(xc, yc), FS, T.ToString(), LabelHeight, 0.05, StringAlign.CenterCenter, true);
                }

                if (Grid[x][YE - 1] != "None")
                {
                    SilkTop.DrawString(new PointD(xc, yc1), FS, T.ToString(), LabelHeight, 0.05, StringAlign.CenterCenter);
                    SilkBottom.DrawString(new PointD(xc, yc1), FS, T.ToString(), LabelHeight, 0.05, StringAlign.CenterCenter, true);
                }
            }
            for (int y = 0; y < YE; y++)
            {
                double xc  = XO + (0) * 2.54 - 2.54 / 2;
                double xc1 = XO + (XE + 1) * 2.54 - 2.54 / 2;
                double yc  = YO + (y) * 2.54 + 2.54;

                if (Grid[0][y] != "None")
                {
                    SilkTop.DrawString(new PointD(xc, yc), FS, (YE - y).ToString(), LabelHeight, 0.05, StringAlign.CenterCenter);
                    SilkBottom.DrawString(new PointD(xc, yc), FS, (YE - y).ToString(), LabelHeight, 0.05, StringAlign.CenterCenter, true);
                }

                if (Grid[XE - 1][y] != "None")
                {
                    SilkTop.DrawString(new PointD(xc1, yc), FS, (YE - y).ToString(), LabelHeight, 0.05, StringAlign.CenterCenter);
                    SilkBottom.DrawString(new PointD(xc1, yc), FS, (YE - y).ToString(), LabelHeight, 0.05, StringAlign.CenterCenter, true);
                }
            }

            PolyLine PL2 = new PolyLine(polyid++);
            double   rad = 0.6;

            for (int i = 0; i < 20; i++)
            {
                double P = i * Math.PI / 19.0;
                PL2.Add(Math.Sin(P) * rad, Math.Cos(P) * rad);
            }
            PL2.Close();
            PL2.Translate(-1.1, 0);


            for (int x = -1; x < XE + 1; x++)
            {
                for (int y = -1; y < YE + 1; y++)
                {
                    string s1 = "None";
                    if (y >= 0 && y < YE && x < XE)
                    {
                        s1 = Grid[x + 1][y];
                    }
                    string s2 = "None";
                    if (x >= 0 && x < XE && y < YE)
                    {
                        s2 = Grid[x][y + 1];
                    }
                    string s3 = "None";
                    if (x >= 0 && x < XE && y >= 0 && y < YE)
                    {
                        s3 = Grid[x][y];
                    }
                    double xc  = XO + x * 2.54 + 2.54 / 2;
                    double yc  = YO + y * 2.54 + 2.54 / 2;
                    double xc1 = XO + (x + 1) * 2.54 + 2.54 / 2;
                    double yc1 = YO + (y + 1) * 2.54 + 2.54 / 2;

                    if (s1 != "None" && s3 != "None")
                    {
                        PolyLine PLA = PL2.Copy();
                        PLA.Translate(xc1, yc);
                        PolyLine PLC = PL2.Copy();
                        PLC.RotateDegrees(180);
                        PLC.Translate(xc, yc);

                        GAWTop.AddPolygon(PLA);
                        MaskTop.AddPolygon(PLA);
                        GAWTop.AddPolygon(PLC);
                        MaskTop.AddPolygon(PLC);
                        GAWBottom.AddPolygon(PLA);
                        MaskBottom.AddPolygon(PLA);
                        GAWBottom.AddPolygon(PLC);
                        MaskBottom.AddPolygon(PLC);
                    }

                    if (s3 != "None" && s2 != "None")
                    {
                        PolyLine PLB = PL2.Copy();
                        PLB.RotateDegrees(90);
                        PLB.Translate(xc, yc1);
                        PolyLine PLD = PL2.Copy();
                        PLD.RotateDegrees(270);
                        PLD.Translate(xc, yc);

                        GAWTop.AddPolygon(PLB);
                        MaskTop.AddPolygon(PLB);
                        GAWTop.AddPolygon(PLD);
                        MaskTop.AddPolygon(PLD);
                        GAWBottom.AddPolygon(PLB);
                        MaskBottom.AddPolygon(PLB);
                        GAWBottom.AddPolygon(PLD);
                        MaskBottom.AddPolygon(PLD);
                        //       GAWTop.AddPolygon(PLD);
                        //     MaskTop.AddPolygon(PLD);
                    }
                }
            }

            GAWTop.Write(CopperTop);

            GAWBottom.Write(CopperBottom);
            SilkBottom.Write(SilkFileBottom);
            SilkTop.Write(SilkFileTop);

            MaskTop.Write(SolderMaskTop);
            MaskBottom.Write(SolderMaskBottom);
            EF.Tools[11] = ProtoHoleDrill;
            EF.Write(DrillFile, 0, 0, 0, 0);

            FilesGenerated.Add(CopperBottom);
            FilesGenerated.Add(CopperTop);
            FilesGenerated.Add(OutlineFile);
            FilesGenerated.Add(DrillFile);
            FilesGenerated.Add(SilkFileBottom);
            FilesGenerated.Add(SilkFileTop);
            FilesGenerated.Add(SolderMaskBottom);
            FilesGenerated.Add(SolderMaskTop);


            if (WriteCombinedImage)
            {
                GerberImageCreator GIC = new GerberImageCreator();
                GIC.AddBoardsToSet(FilesGenerated);
                GIC.WriteImageFiles(basename + "_render", 200, false);
            }
            if (WriteImages)
            {
                Gerber.SaveGerberFileToImage(OutlineFile, OutlineFile + "_render.png", 1000, Color.Black, Color.White);
                Gerber.SaveGerberFileToImage(CopperBottom, CopperBottom + "_render.png", 1000, Color.Black, Color.White);
                Gerber.SaveGerberFileToImage(CopperTop, CopperTop + "_render.png", 1000, Color.Black, Color.White);
                Gerber.SaveGerberFileToImage(DrillFile, DrillFile + "_render.png", 1000, Color.Black, Color.White);
                Gerber.SaveGerberFileToImage(SilkFileTop, SilkFileTop + "_render.png", 1000, Color.Black, Color.White);
                Gerber.SaveGerberFileToImage(SilkFileBottom, SilkFileBottom + "_render.png", 1000, Color.Black, Color.White);
            }

            return(FilesGenerated);
        }
Ejemplo n.º 8
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                int    polyid     = 0;
                string fname      = System.IO.Path.GetFileName(saveFileDialog1.FileName);
                string fnamenoext = System.IO.Path.GetFileNameWithoutExtension(saveFileDialog1.FileName);
                string OutName    = "";
                if (fname.Length != fnamenoext.Length)
                {
                    int extlen = fname.Length - fnamenoext.Length;
                    OutName = saveFileDialog1.FileName.Substring(0, saveFileDialog1.FileName.Length - extlen);
                }
                else
                {
                    OutName = saveFileDialog1.FileName;
                }


                List <string> Files = new List <string>();

                double W  = (double)innerWidth.Value;
                double H  = (double)innerHeight.Value;
                double TE = (double)topEdge.Value;
                double LE = (double)leftEdge.Value;

                double OuterWidth  = W + LE * 2.0;
                double OuterHeight = H + TE * 2.0;
                double InnerWidth  = W;
                double InnerHeight = H;

                GerberArtWriter Outline       = new GerberArtWriter();
                GerberArtWriter TopSilk       = new GerberArtWriter();
                GerberArtWriter TopCopper     = new GerberArtWriter();
                GerberArtWriter TopSolderMask = new GerberArtWriter();

                GerberArtWriter BottomSilk       = new GerberArtWriter();
                GerberArtWriter BottomCopper     = new GerberArtWriter();
                GerberArtWriter BottomSolderMask = new GerberArtWriter();


                List <PointD> DrillHoles        = new List <PointD>();
                double        mountholediameter = (double)holeDiameter.Value;

                if (addHolesCheck.Checked)
                {
                    double side = LE / 2.0;
                    double top  = TE / 2.0;


                    DrillHoles.Add(new PointD(side, top));
                    DrillHoles.Add(new PointD(OuterWidth - side, top));
                    DrillHoles.Add(new PointD(OuterWidth - side, OuterHeight - top));
                    DrillHoles.Add(new PointD(side, OuterHeight - top));

                    ExcellonFile EF = new ExcellonFile();

                    ExcellonTool MountHoleDrill = new ExcellonTool();
                    MountHoleDrill.Radius = mountholediameter / 2.0;

                    foreach (var a in DrillHoles)
                    {
                        MountHoleDrill.Drills.Add(a);
                    }
                    EF.Tools[10] = MountHoleDrill;
                    EF.Write(OutName + ".txt", 0, 0, 0, 0);

                    Files.Add(OutName + ".txt");
                }

                // board outline
                PolyLine PL = new PolyLine(polyid++);
                PL.MakeRoundedRect(new PointD(0, 0), new PointD(OuterWidth, OuterHeight), (double)roundedOuterCorners.Value);
                Outline.AddPolyLine(PL, 0);
                PolyLine PL2 = new PolyLine(polyid++);

                PL2.MakeRoundedRect(new PointD(LE, TE), new PointD(InnerWidth + LE, InnerHeight + TE), (double)roundedInnerCorners.Value);
                Outline.AddPolyLine(PL2, 0);

                #region fiducials

                List <PointD> Fiducials = new List <PointD>();

                foreach (DataGridViewRow dataRow in fiducialsListData.Rows)
                {
                    PointD fiducialPoint = new PointD();

                    if (dataRow.Cells != null && dataRow.Cells["XCoordinate"].Value != null && dataRow.Cells["YCoordinate"].Value != null)
                    {
                        fiducialPoint.X = double.Parse(dataRow.Cells["XCoordinate"].Value.ToString());
                        fiducialPoint.Y = double.Parse(dataRow.Cells["YCoordinate"].Value.ToString());

                        if (string.Equals(dataRow.Cells["fiducialLayer"].Value.ToString(), "Top"))
                        {
                            TopCopper.AddFlash(fiducialPoint, double.Parse(dataRow.Cells["fiducialCopperDiameter"].Value.ToString()) / 2.0);
                            TopSolderMask.AddFlash(fiducialPoint, double.Parse(dataRow.Cells["fiducialSolderMaskDiam"].Value.ToString()) / 2.0);
                        }
                        else
                        {
                            BottomCopper.AddFlash(fiducialPoint, double.Parse(dataRow.Cells["fiducialCopperDiameter"].Value.ToString()) / 2.0);
                            BottomSolderMask.AddFlash(fiducialPoint, double.Parse(dataRow.Cells["fiducialSolderMaskDiam"].Value.ToString()) / 2.0);
                        }
                    }
                }

                #endregion

                string FrameTitle = FrameTitleBox.Text;

                if (FrameTitle.Length > 0)
                {
                    FontSet FS = FontSet.Load("Font.xml");
                    TopSilk.DrawString(new PointD(OuterWidth / 2.0, OuterHeight - TE / 4.0), FS, FrameTitle + " - top", TE / 4.0, 0.1, StringAlign.CenterCenter);
                    TopCopper.DrawString(new PointD(OuterWidth / 2.0, OuterHeight - TE / 4.0), FS, FrameTitle + " - top", TE / 4.0, 0.1, StringAlign.CenterCenter);
                    BottomSilk.DrawString(new PointD(OuterWidth / 2.0, OuterHeight - TE / 4.0), FS, FrameTitle + " - bottom", TE / 4.0, 0.1, StringAlign.CenterCenter, true);
                    BottomCopper.DrawString(new PointD(OuterWidth / 2.0, OuterHeight - TE / 4.0), FS, FrameTitle + " - bottom", TE / 4.0, 0.1, StringAlign.CenterCenter, true);
                }

                foreach (var a in DrillHoles)
                {
                    TopSolderMask.AddFlash(a, mountholediameter / 2.0 + 1.0);
                    BottomSolderMask.AddFlash(a, mountholediameter / 2.0 + 1.0);
                }

                Outline.Write(OutName + ".gko");
                TopSilk.Write(OutName + ".gto");
                TopCopper.Write(OutName + ".gtl");
                TopSolderMask.Write(OutName + ".gts");

                BottomSilk.Write(OutName + ".gbo");
                BottomCopper.Write(OutName + ".gbl");
                BottomSolderMask.Write(OutName + ".gbs");


                Files.Add(OutName + ".gko");
                Files.Add(OutName + ".gto");
                Files.Add(OutName + ".gtl");
                Files.Add(OutName + ".gts");
                Files.Add(OutName + ".gbo");
                Files.Add(OutName + ".gbl");
                Files.Add(OutName + ".gbs");
                GerberImageCreator GIC = new GerberImageCreator();
                GIC.AddBoardsToSet(Files, new StandardConsoleLog());

                GIC.WriteImageFiles(OutName, 50);
                // Gerber.SaveGerberFileToImage(OutName + ".gko", OutName + ".gko.png", 200, Color.Black, Color.White);
                // Gerber.SaveGerberFileToImage(OutName + ".gto", OutName + ".gto.png", 200, Color.Black, Color.White);
            }
        }
Ejemplo n.º 9
0
        public List <string> Write(string targetfolder, string basename, BOM inFiducialBom, PointD offset = null)
        {
            if (offset == null)
            {
                offset = new PointD(0, 0);
            }

            List <string> Files      = new List <string>();
            ExcellonFile  EF         = new ExcellonFile();
            int           drillcount = 0;

            foreach (var h in DrillHoles)
            {
                ExcellonTool DrillBit = new ExcellonTool();
                DrillBit.Radius = h.Key / 2.0f;

                foreach (var a in h.Value)
                {
                    DrillBit.Drills.Add(a);
                }
                EF.Tools[10 + drillcount] = DrillBit;
                drillcount++;
            }
            string DrillFile = Path.Combine(targetfolder, basename + ".txt");

            EF.Write(DrillFile, offset.X, offset.Y, 0, 0);
            Files.Add(DrillFile);

            string OutName = Path.Combine(targetfolder, basename);

            Outline.Write(OutName + ".gko", offset); Files.Add(OutName + ".gko");
            TopSilk.Write(OutName + ".gto", offset); Files.Add(OutName + ".gto");
            TopCopper.Write(OutName + ".gtl", offset); Files.Add(OutName + ".gtl");

            TopSolderMask.Write(OutName + ".gts", offset); Files.Add(OutName + ".gts");

            BottomSilk.Write(OutName + ".gbo", offset); Files.Add(OutName + ".gbo");
            BottomCopper.Write(OutName + ".gbl", offset); Files.Add(OutName + ".gbl");
            BottomSolderMask.Write(OutName + ".gbs", offset); Files.Add(OutName + ".gbs");

            BOM FiducialBom;

            if (inFiducialBom != null)
            {
                FiducialBom = inFiducialBom;
            }
            else
            {
                FiducialBom = new BOM();
            }

            BOMNumberSet set = new BOMNumberSet();
            int          fd  = 1;

            foreach (var a in Fiducials)
            {
                FiducialBom.AddBOMItemExt("FIDUCIAL_" + a.Style.ToString(), "FIDUCIAL_" + a.Style.ToString(), a.Style.ToString(), "__FD" + (fd.ToString()), set, "Frame_" + basename, a.Pos.X + offset.X, a.Pos.Y + offset.Y, 0, a.Side);
            }
            FiducialBom.WriteJLCCSV(targetfolder, basename + "_fiducials");

            return(Files);
        }
Ejemplo n.º 10
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string fname      = System.IO.Path.GetFileName(saveFileDialog1.FileName);
                string fnamenoext = System.IO.Path.GetFileNameWithoutExtension(saveFileDialog1.FileName);
                string OutName    = "";
                if (fname.Length != fnamenoext.Length)
                {
                    int extlen = fname.Length - fnamenoext.Length;
                    OutName = saveFileDialog1.FileName.Substring(0, saveFileDialog1.FileName.Length - extlen);
                }
                else
                {
                    OutName = saveFileDialog1.FileName;
                }



                List <string> Files = new List <string>();

                double W  = (double)innerWidth.Value;
                double H  = (double)innerHeight.Value;
                double TE = (double)topEdge.Value;
                double LE = (double)leftEdge.Value;

                double OuterWidth  = W + LE * 2.0;
                double OuterHeight = H + TE * 2.0;
                double InnerWidth  = W;
                double InnerHeight = H;

                GerberArtWriter Outline       = new GerberArtWriter();
                GerberArtWriter TopSilk       = new GerberArtWriter();
                GerberArtWriter TopCopper     = new GerberArtWriter();
                GerberArtWriter TopSolderMask = new GerberArtWriter();

                GerberArtWriter BottomSilk       = new GerberArtWriter();
                GerberArtWriter BottomCopper     = new GerberArtWriter();
                GerberArtWriter BottomSolderMask = new GerberArtWriter();


                List <PointD> DrillHoles        = new List <PointD>();
                double        mountholediameter = (double)holeDiameter.Value;

                if (addHolesCheck.Checked)
                {
                    double side = LE / 2.0;
                    double top  = TE / 2.0;


                    DrillHoles.Add(new PointD(side, top));
                    DrillHoles.Add(new PointD(OuterWidth - side, top));
                    DrillHoles.Add(new PointD(OuterWidth - side, OuterHeight - top));
                    DrillHoles.Add(new PointD(side, OuterHeight - top));


                    ExcellonFile EF = new ExcellonFile();

                    ExcellonTool MountHoleDrill = new ExcellonTool();
                    MountHoleDrill.Radius = mountholediameter / 2.0;

                    foreach (var a in DrillHoles)
                    {
                        MountHoleDrill.Drills.Add(a);
                    }
                    EF.Tools[10] = MountHoleDrill;
                    EF.Write(OutName + ".txt", 0, 0, 0, 0);

                    Files.Add(OutName + ".txt");
                }


                PolyLine PL = new PolyLine();
                PL.MakeRoundedRect(new PointD(0, 0), new PointD(OuterWidth, OuterHeight), (double)roundedOuterCorners.Value);
                Outline.AddPolyLine(PL, 0);
                PolyLine PL2 = new PolyLine();

                PL2.MakeRoundedRect(new PointD(LE, TE), new PointD(InnerWidth + LE, InnerHeight + TE), (double)roundedInnerCorners.Value);
                Outline.AddPolyLine(PL2, 0);

                if (fiducials.Checked)
                {
                    List <PointD> Fiducials = new List <PointD>();
                    Fiducials.Add(new PointD(LE * 2.0, TE / 2.0));
                    Fiducials.Add(new PointD(OuterWidth - LE * 2.0, TE / 2.0));
                    Fiducials.Add(new PointD(OuterWidth - LE * 2.0, OuterHeight - TE / 2.0));
                    Fiducials.Add(new PointD(LE * 2.0, OuterHeight - TE / 2.0));
                    Fiducials.Add(new PointD(OuterWidth / 2, TE / 2.0)); //generate extra non symetric fiducial
                    foreach (var A in Fiducials)
                    {
                        TopCopper.AddFlash(A, 1.0);
                        TopSolderMask.AddFlash(A, 3.0);
                    }
                }
                string FrameTitle = FrameTitleBox.Text;

                if (FrameTitle.Length > 0)
                {
                    FontSet FS = FontSet.Load("Font.xml");
                    TopSilk.DrawString(new PointD(OuterWidth / 2.0, OuterHeight - TE / 4.0), FS, FrameTitle + " - top", TE / 4.0, 0.1, StringAlign.CenterCenter);
                    TopCopper.DrawString(new PointD(OuterWidth / 2.0, OuterHeight - TE / 4.0), FS, FrameTitle + " - top", TE / 4.0, 0.1, StringAlign.CenterCenter);
                    BottomSilk.DrawString(new PointD(OuterWidth / 2.0, OuterHeight - TE / 4.0), FS, FrameTitle + " - bottom", TE / 4.0, 0.1, StringAlign.CenterCenter, true);
                    BottomCopper.DrawString(new PointD(OuterWidth / 2.0, OuterHeight - TE / 4.0), FS, FrameTitle + " - bottom", TE / 4.0, 0.1, StringAlign.CenterCenter, true);
                }

                foreach (var a in DrillHoles)
                {
                    TopSolderMask.AddFlash(a, mountholediameter / 2.0 + 1.0);
                    BottomSolderMask.AddFlash(a, mountholediameter / 2.0 + 1.0);
                }

                Outline.Write(OutName + ".gko");
                TopSilk.Write(OutName + ".gto");
                TopCopper.Write(OutName + ".gtl");
                TopSolderMask.Write(OutName + ".gts");

                BottomSilk.Write(OutName + ".gbo");
                BottomCopper.Write(OutName + ".gbl");
                BottomSolderMask.Write(OutName + ".gbs");


                Files.Add(OutName + ".gko");
                Files.Add(OutName + ".gto");
                Files.Add(OutName + ".gtl");
                Files.Add(OutName + ".gts");
                Files.Add(OutName + ".gbo");
                Files.Add(OutName + ".gbl");
                Files.Add(OutName + ".gbs");
                GerberImageCreator GIC = new GerberImageCreator();
                GIC.AddBoardsToSet(Files);

                GIC.WriteImageFiles(OutName, 50);
                // Gerber.SaveGerberFileToImage(OutName + ".gko", OutName + ".gko.png", 200, Color.Black, Color.White);
                // Gerber.SaveGerberFileToImage(OutName + ".gto", OutName + ".gto.png", 200, Color.Black, Color.White);
            }
        }