示例#1
0
        public static List <string> WriteSideEdgeFrame(PolyLine pl, FrameSettings FS, string basefile, BOM output = null)
        {
            List <string> Files = new List <string>();

            try
            {
                int    polyid     = 0;
                string fname      = System.IO.Path.GetFileName(basefile);
                string fnamenoext = System.IO.Path.GetFileNameWithoutExtension(basefile);
                string OutName    = Path.Combine(System.IO.Path.GetDirectoryName(basefile), fnamenoext);
                Console.WriteLine("writing frame files to {0}", OutName);
                //   Bounds B = new Bounds();
                // B.AddPolyLine(pl);
                //                FS.innerHeight = B.Height();
                //              FS.innerWidth = B.Width();


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

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


                PCBWriterSet PCB = new PCBWriterSet();

                double mountholediameter = (double)FS.holeDiameter;



                // board outline
                PolyLine PL = new PolyLine(polyid++);
                PL.MakeRoundedRect(new PointD(0, 0), new PointD(OuterWidth, OuterHeight), (double)FS.roundedOuterCorners);
                PCB.AddOutline(PL);

                if (FS.InsideEdgeMode == FrameSettings.InsideMode.RegularEdge)
                {
                    PolyLine PL2 = new PolyLine(polyid++);
                    PL2.MakeRoundedRect(new PointD(LE, TE), new PointD(InnerWidth + LE, InnerHeight + TE), (double)FS.roundedInnerCorners);
                    PCB.AddOutline(PL2);
                }

                if (FS.InsideEdgeMode == FrameSettings.InsideMode.FormFitting && pl != null)
                {
                    PolyLine PP = pl.Copy();
                    PP.Translate(-FS.offset.X, -FS.offset.Y);
                    List <PolyLine> PL2 = PP.Offset(FS.margin, polyid++);
                    foreach (var l in PL2)
                    {
                        PCB.AddOutline(l);
                    }

                    polyid += PL2.Count;
                }

                #region fiducials

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

                foreach (var P in FS.fiducialsListData)
                {
                    PointD fiducialPoint = P.pos;
                    PCB.Fiducial(fiducialPoint, P.CopperDiameter, P.MaskDiameter, P.Top ? BoardSide.Top : BoardSide.Bottom);
                }

                #endregion

                string FrameTitle = FS.FrameTitle;

                string FrameTopTitle            = FrameTitle + " - Top";
                string FrameBottomTitle         = FrameTitle + " - Bottom";
                double verticaltitleclearance   = 0;
                double horizontaltitleclearance = 0;
                if (FrameTitle.Length > 0)
                {
                    FontSet fnt = FontSet.Load("Font.xml");
                    horizontaltitleclearance = fnt.StringWidth(FrameBottomTitle, TE / 4) + mountholediameter * 2 + FS.topEdge;
                    verticaltitleclearance   = fnt.StringWidth(FrameBottomTitle, TE / 4) + mountholediameter * 2 + FS.topEdge;

                    PCB.Label(fnt, new PointD(OuterWidth / 2.0, OuterHeight - TE / 4.0), FrameTopTitle, TE / 4, StringAlign.CenterCenter, 0.1, true, true, 0);
                    PCB.Label(fnt, new PointD(OuterWidth - LE / 4, OuterHeight / 2), FrameTopTitle, TE / 4.0, StringAlign.CenterCenter, 0.1, true, true, -90);
                    PCB.Label(fnt, new PointD(LE / 4, OuterHeight / 2), FrameTopTitle, TE / 4.0, StringAlign.CenterCenter, 0.1, true, true, 90);
                    PCB.Label(fnt, new PointD(OuterWidth / 2.0, TE - TE / 4.0), FrameTopTitle, TE / 4.0, StringAlign.CenterCenter, 0.1, true, true, 0);


                    PCB.Label(fnt, new PointD(OuterWidth / 2.0, OuterHeight - TE / 4.0), FrameBottomTitle, TE / 4, StringAlign.CenterCenter, 0.1, true, true, 0, true, true, true);
                    PCB.Label(fnt, new PointD(OuterWidth - LE / 4, OuterHeight / 2), FrameBottomTitle, TE / 4.0, StringAlign.CenterCenter, 0.1, true, true, -90, true);
                    PCB.Label(fnt, new PointD(LE / 4, OuterHeight / 2), FrameBottomTitle, TE / 4.0, StringAlign.CenterCenter, 0.1, true, true, 90, true);
                    PCB.Label(fnt, new PointD(OuterWidth / 2.0, TE - TE / 4.0), FrameBottomTitle, TE / 4.0, StringAlign.CenterCenter, 0.1, true, true, 0, true);
                }

                if (FS.addHoles)
                {
                    double side = LE / 2.0;
                    double top  = TE / 2.0;

                    PCB.Drill(new PointD(side, top), mountholediameter, 1);
                    PCB.Drill(new PointD(OuterWidth - side, top), mountholediameter, 1);
                    PCB.Drill(new PointD(OuterWidth - side, OuterHeight - top), mountholediameter, 1);
                    PCB.Drill(new PointD(side, OuterHeight - top), mountholediameter, 1);

                    double dx = (OuterWidth - side) - side;
                    double dy = (OuterHeight - top) - top;

                    dx -= horizontaltitleclearance;
                    dy -= verticaltitleclearance;
                    dx /= 2;
                    dy /= 2;

                    int horiz = (int)Math.Ceiling((dx / 2) / FS.MaxMountHoleSpacingMM);
                    int vert  = (int)Math.Ceiling((dy / 2) / FS.MaxMountHoleSpacingMM);

                    dx /= (float)horiz;
                    dy /= (float)vert;

                    if (dx < FS.MinMountHoleSpacingMM)
                    {
                        horiz = 0;
                    }
                    if (dy < FS.MinMountHoleSpacingMM)
                    {
                        vert = 0;
                    }

                    for (int i = 1; i <= horiz; i++)
                    {
                        PCB.Drill(new PointD(side + (dx) * i, top), mountholediameter, 1);
                        PCB.Drill(new PointD((OuterWidth - side) - (dx) * i, top), mountholediameter, 1);
                        PCB.Drill(new PointD(side + (dx) * i, OuterHeight - top), mountholediameter, 1);
                        PCB.Drill(new PointD((OuterWidth - side) - (dx) * i, OuterHeight - top), mountholediameter, 1);
                    }


                    for (int i = 1; i <= vert; i++)
                    {
                        PCB.Drill(new PointD(side, top + (dy) * i), mountholediameter, 1);
                        PCB.Drill(new PointD(side, (OuterHeight - top) - (dy) * i), mountholediameter, 1);
                        PCB.Drill(new PointD((OuterWidth - side), top + (dy) * i), mountholediameter, 1);
                        PCB.Drill(new PointD((OuterWidth - side), (OuterHeight - top) - (dy) * i), mountholediameter, 1);
                    }
                }
                if (FS.DefaultFiducials)
                {
                    double side = LE / 2.0;
                    double top  = TE / 2.0;

                    PCB.Fiducial(new PointD(side + mountholediameter * 2, top), 1, 2, FS.FiducialSide, PCBWriterSet.FiducialStyle.Square);
                    PCB.Fiducial(new PointD(side + mountholediameter * 3, top), 1, 2, FS.FiducialSide, PCBWriterSet.FiducialStyle.Round);


                    PCB.Fiducial(new PointD(OuterWidth - (side + mountholediameter * 2), top), 1, 2, FS.FiducialSide, PCBWriterSet.FiducialStyle.Square);
                    PCB.Fiducial(new PointD(OuterWidth - (side + mountholediameter * 3), top), 1, 2, FS.FiducialSide, PCBWriterSet.FiducialStyle.Round);


                    PCB.Fiducial(new PointD(side + mountholediameter * 2, OuterHeight - top), 1, 2, FS.FiducialSide, PCBWriterSet.FiducialStyle.Round);
                    PCB.Fiducial(new PointD(side + mountholediameter * 3, OuterHeight - top), 1, 2, FS.FiducialSide, PCBWriterSet.FiducialStyle.Square);
                }
                if (FS.RenderDirectionArrow)
                {
                    double side = LE / 2.0;
                    double top  = TE / 2.0;
                    double dy   = (OuterHeight - top) - top;

                    dy -= verticaltitleclearance;
                    dy /= 2;
                    int vert = (int)Math.Ceiling((dy / 2) / FS.MaxMountHoleSpacingMM);
                    dy /= (float)vert;

                    PCB.Arrow(new PointD(side, (OuterHeight - top) - (dy) * 1 + mountholediameter * 1.5), new PointD(side, (OuterHeight - top) - (dy) * 0 - mountholediameter * 1.5), FS.DirectionArrowSide);
                    PCB.Arrow(new PointD(OuterWidth - side, (OuterHeight - top) - (dy) * 1 + mountholediameter * 1.5), new PointD(OuterWidth - side, (OuterHeight - top) - (dy) * 0 - mountholediameter * 1.5), FS.DirectionArrowSide);

                    PCB.Arrow(new PointD(side, (top) + (dy) * 0 + mountholediameter * 1.5), new PointD(side, (top) + (dy) * 1 - mountholediameter * 1.5), FS.DirectionArrowSide);
                    PCB.Arrow(new PointD(OuterWidth - side, (top) + (dy) * 0 + mountholediameter * 1.5), new PointD(OuterWidth - side, (top) + (dy) * 1 - mountholediameter * 1.5), FS.DirectionArrowSide);
                }

                PolyLine Left   = new PolyLine();
                PolyLine Right  = new PolyLine();
                PolyLine Top    = new PolyLine();
                PolyLine Bottom = new PolyLine();


                Top.MakePRectangle(OuterWidth + 1, FS.topEdge + 1, -1, -1);
                Bottom.MakePRectangle(OuterWidth, FS.topEdge, 0, OuterHeight - FS.topEdge);
                Left.MakePRectangle(FS.leftEdge + 1, OuterHeight + 1, -1, -1);
                Right.MakePRectangle(FS.leftEdge, OuterHeight, OuterWidth - FS.leftEdge, 0);
                PCB.ArtInclusions.Add(Left);
                PCB.ArtInclusions.Add(Right);
                PCB.ArtInclusions.Add(Top);
                PCB.ArtInclusions.Add(Bottom);



                //PCB.CellularArt();


                Files.AddRange(PCB.Write(Path.GetDirectoryName(basefile), Path.GetFileNameWithoutExtension(basefile), output, FS.offset));;



                if (FS.RenderSample)
                {
                    GerberImageCreator GIC = new GerberImageCreator();
                    GIC.AddBoardsToSet(Files, new SilentLog());
                    GIC.WriteImageFiles(OutName, 200, true, false, true, null);
                }
            }
            catch (Exception e)
            {
                Console.Write(" Exception while making frames:{0}", e.Message);
            }
            foreach (var s in Files)
            {
                Console.WriteLine("Writen edge file {0} succesfully", s);
            }
            return(Files);
        }