Exemple #1
0
        internal void SetMoire(double Xoff, double Yoff, double OuterDiameter, double Width, double RingGap, int MaxRings, double CrossHairThickness, double CrossHairLength, double Rotation)
        {
            Shape.Vertices.Clear();
            double Rad   = OuterDiameter / 2 - Width / 2;
            int    Rings = 0;

            if (CrossHairThickness > 0 && CrossHairLength > 0)
            {
                GerberApertureType L1 = new GerberApertureType();
                L1.SetLineSegment(new PointD(Xoff - CrossHairLength / 2, Yoff), new PointD(Xoff + CrossHairLength / 2, Yoff), CrossHairThickness, Rotation);
                Parts.Add(L1);
                GerberApertureType L2 = new GerberApertureType();
                L2.SetLineSegment(new PointD(Xoff, Yoff - CrossHairLength / 2), new PointD(Xoff, Yoff + CrossHairLength / 2), CrossHairThickness, Rotation);
                Parts.Add(L2);
            }
            while (Rad > 0 && Rings < MaxRings)
            {
                GerberApertureType AT = new GerberApertureType();
                AT.SetRing(Xoff, Yoff, Rad, Width);
                Parts.Add(AT);

                Rad -= RingGap + Width;
                Rings++;
            }
        }
        public GerberApertureType BuildAperture(List <double> paramlist, GerberNumberFormat GNF)
        {
            GerberApertureType GAT = new GerberApertureType();

            GAT.MacroParamList = paramlist.ToList();
            GAT.ShapeType      = GerberApertureShape.Compound;
            //GAT.ShapeType = GerberApertureShape.Macro;
            GAT.MacroName = Name;

            GAT.Shape.Vertices.Clear();
            if (Gerber.ShowProgress)
            {
                Console.WriteLine("Building aperture for macro {1}  with {0} parts", Parts.Count, Name);
            }
            for (int i = 0; i < Parts.Count; i++)
            {
                var part = Parts[i];
                var Part = part.BuildAperture(paramlist, GNF);
                Part.Polarity = Parts[i].Polarity;
                GAT.Parts.Add(Part);

                if (Gerber.ShowProgress)
                {
                    Console.WriteLine("part with {0} vertices", Part.Shape.Count());
                }
            }
            return(GAT);
        }
        private void SetRing(double Xoff, double Yoff, double p, double Width)
        {
            GerberApertureType GA = new GerberApertureType();

            GA.NGon((int)Math.Floor(10 * Math.Max(2.0, p)), 1, 0, 0);
            Shape.Vertices.Clear();

            for (int i = 0; i < GA.Shape.Vertices.Count(); i++)
            {
                Shape.Vertices.Add(new PointD(Xoff + GA.Shape.Vertices[i].X * (p - (Width / 2)), Yoff + GA.Shape.Vertices[i].Y * (p - (Width / 2))));
            }
            Shape.Vertices.Add(new PointD(Xoff + GA.Shape.Vertices[0].X * (p + (Width / 2)), Yoff + GA.Shape.Vertices[0].Y * (p + (Width / 2))));
            for (int i = GA.Shape.Vertices.Count() - 1; i >= 0; i--)
            {
                Shape.Vertices.Add(new PointD(Xoff + GA.Shape.Vertices[i].X * (p + (Width / 2)), Yoff + GA.Shape.Vertices[i].Y * (p + (Width / 2))));
            }
            Shape.Vertices.Add(new PointD(Xoff + GA.Shape.Vertices[GA.Shape.Vertices.Count() - 1].X * (p - (Width / 2)), Yoff + GA.Shape.Vertices[GA.Shape.Vertices.Count() - 1].Y * (p - (Width / 2))));
            Shape.Close();
        }
        public GerberApertureType BuildAperture(List <double> paramlist, GerberNumberFormat GNF)
        {
            //List<double> paramlist = _paramlist.ToList();
            GerberApertureType AT = new GerberApertureType();

            AT.MacroParamList = paramlist.ToList();
            AT.Shape.Vertices.Clear();

            switch (Type)
            {
            case ApertureMacroTypes.Equation:

                int T = int.Parse(EquationTarget.Substring(1));
                while (paramlist.Count() < T)
                {
                    paramlist.Add(0);
                }
                {
                    string srccopy = EquationSource.Replace("$1", "V1");
                    for (int i = 2; i <= paramlist.Count(); i++)
                    {
                        srccopy = srccopy.Replace("$" + i.ToString(), "V" + i.ToString());
                    }
                    srccopy = srccopy.Replace("X", "*");
                    MacroExpressionEvaluator E = new MacroExpressionEvaluator();
                    for (int i = 0; i < paramlist.Count(); i++)
                    {
                        E.Set("V" + (i + 1).ToString(), paramlist[i]);
                    }
                    while (paramlist.Count() < T)
                    {
                        paramlist.Add(0);
                    }

                    paramlist[T - 1] = E.Evaluate(srccopy);;
                    if (Gerber.ShowProgress)
                    {
                        Console.Write("equation {0}={1} -> {2}. Paramlist: ", EquationTarget, EquationSource, paramlist[T - 1]);
                        int c = 1;
                        foreach (var a in paramlist)
                        {
                            Console.Write(" {0}:{1},", c, a);
                            c++;
                        }
                        Console.WriteLine();
                    }
                    AT.MacroParamList = paramlist.ToList();
                }

                break;

            case ApertureMacroTypes.Polygon:
            {
                if (Gerber.ShowProgress)
                {
                    Console.WriteLine("Making an aperture for polygon. {0} params. {1} in paramlist", Params.Count, paramlist.Count());
                }

                Sides = (int)Params[2].BuildValue(paramlist);
                var diamvalue = Params[5].BuildValue(paramlist);
                Diameter = GNF.ScaleFileToMM(diamvalue);
                Rotation = Params[6].BuildValue(paramlist);
                Xoff     = GNF.ScaleFileToMM(Params[3].BuildValue(paramlist));
                Yoff     = GNF.ScaleFileToMM(Params[4].BuildValue(paramlist));
                AT.NGon(Sides, Diameter / 2, Xoff, Yoff, Rotation);
            }
            break;

            case ApertureMacroTypes.Outline:
                if (Gerber.ShowProgress)
                {
                    Console.WriteLine("Making an aperture for outline. {0} params. {1} in paramlist", Params.Count, paramlist.Count());
                }
                OutlineVerticesPostProc = new List <PointD>();
                foreach (var a in OutlineVertices)
                {
                    OutlineVerticesPostProc.Add(a.Get(paramlist));
                }
                AT.SetCustom(OutlineVerticesPostProc);
                break;

            case ApertureMacroTypes.Circle:
                if (Gerber.ShowProgress)
                {
                    Console.WriteLine("Making an aperture for circle. {0} params. {1} in paramlist", Params.Count, paramlist.Count());
                }
                Diameter = GNF.ScaleFileToMM(Params[2].BuildValue(paramlist));
                Xoff     = GNF.ScaleFileToMM(Params[3].BuildValue(paramlist));
                Yoff     = GNF.ScaleFileToMM(Params[4].BuildValue(paramlist));
                Rotation = GNF.ScaleFileToMM(Params[5].BuildValue(paramlist));
                AT.SetCircle(Diameter / 2, Xoff, Yoff, Rotation);

                break;

            case ApertureMacroTypes.CenterLine:
            {
                if (Gerber.ShowProgress)
                {
                    Console.WriteLine("Making an aperture for centerline. {0} params. {1} in paramlist", Params.Count, paramlist.Count());
                }
                {
                    //1 Exposure off/on (0/1))
                    //2 Rectangle width, a decimal ≥ 0.
                    //3 Rectangle height, a decimal ≥ 0.
                    //4 A decimal defining the X coordinate of center point.
                    //5 A decimal defining the Y coordinate of center point.
                    //6 A decimal defining the rotation angle around the origin (rotation is notaround the center of the object)
                }
                Width    = GNF.ScaleFileToMM(Params[2].BuildValue(paramlist));
                Height   = GNF.ScaleFileToMM(Params[3].BuildValue(paramlist));
                Xoff     = GNF.ScaleFileToMM(Params[4].BuildValue(paramlist));
                Yoff     = GNF.ScaleFileToMM(Params[5].BuildValue(paramlist));
                Rotation = Params[6].BuildValue(paramlist);
                AT.SetRotatedRectangle(Width, Height, Rotation, Xoff, Yoff);
                //AT.ShapeType = GerberApertureShape.CenterLine;
            }
            break;

            case ApertureMacroTypes.LowerLeftLine:
            {
                if (Gerber.ShowProgress)
                {
                    Console.WriteLine("Making an aperture for lowerleftline. {0} params. {1} in paramlist", Params.Count, paramlist.Count());
                }
                {
                    // 1 Exposure off/on (0/1))
                    // 2 Rectangle width, a decimal ≥ 0.
                    // 3 Rectangle height, a decimal ≥ 0.
                    // 4 A decimal defining the X coordinate of lower left point.
                    // 5 A decimal defining the Y coordinate of lower left point.
                    // 6 A decimal defining the rotation angle around the origin (rotation is not around the center of the object)
                }

                Width    = GNF.ScaleFileToMM(Params[2].BuildValue(paramlist));
                Height   = GNF.ScaleFileToMM(Params[3].BuildValue(paramlist));
                Xoff     = GNF.ScaleFileToMM(Params[4].BuildValue(paramlist));
                Yoff     = GNF.ScaleFileToMM(Params[5].BuildValue(paramlist));
                Rotation = Params[6].BuildValue(paramlist);
                AT.SetRotatedRectangle(Width, Height, Rotation, Xoff + Width / 2, Yoff + Height / 2);
            }
            break;

            case ApertureMacroTypes.Thermal:
                if (Gerber.ShowProgress)
                {
                    Console.WriteLine("Making an aperture for moire. {0} params. {1} in paramlist", Params.Count, paramlist.Count());
                }

                Xoff          = GNF.ScaleFileToMM(Params[1].BuildValue(paramlist));
                Yoff          = GNF.ScaleFileToMM(Params[2].BuildValue(paramlist));
                OuterDiameter = GNF.ScaleFileToMM(Params[3].BuildValue(paramlist));
                InnerDiameter = GNF.ScaleFileToMM(Params[4].BuildValue(paramlist));
                GapWidth      = GNF.ScaleFileToMM(Params[5].BuildValue(paramlist));
                Rotation      = Params[6].BuildValue(paramlist);

                AT.SetThermal(Xoff, Yoff, OuterDiameter, InnerDiameter, GapWidth, Rotation);

                //1 A decimal defining the X coordinate of center point
                //2 A decimal defining the Y coordinate of center point
                //3 Outer diameter, must be a decimal and > inner diameter
                //4 Inner diameter, must be a decimal and ≥ 0
                //5 Gap thickness, must be a decimal < (outer diameter)/√2
                //6 A decimal defining the rotation angle around the origin. Rotation is
                //only allowed if the center point is on the origin. If the rotation angle is
                //zero the gaps are on the X and Y axes through the center.



                break;

            case ApertureMacroTypes.Moire:

                if (Gerber.ShowProgress)
                {
                    Console.WriteLine("Making an aperture for moire. {0} params. {1} in paramlist", Params.Count, paramlist.Count());
                }

                Xoff               = GNF.ScaleFileToMM(Params[1].BuildValue(paramlist));
                Yoff               = GNF.ScaleFileToMM(Params[2].BuildValue(paramlist));
                OuterDiameter      = GNF.ScaleFileToMM(Params[3].BuildValue(paramlist));
                Width              = GNF.ScaleFileToMM(Params[4].BuildValue(paramlist));
                RingGap            = GNF.ScaleFileToMM(Params[5].BuildValue(paramlist));
                MaxRings           = (int)Params[6].BuildValue(paramlist);
                CrossHairThickness = GNF.ScaleFileToMM(Params[7].BuildValue(paramlist));
                CrossHairLength    = GNF.ScaleFileToMM(Params[8].BuildValue(paramlist));
                Rotation           = GNF.ScaleFileToMM(Params[9].BuildValue(paramlist));

                AT.SetMoire(Xoff, Yoff, OuterDiameter, Width, RingGap, MaxRings, CrossHairThickness, CrossHairLength, Rotation);
                //1 A decimal defining the X coordinate of center point.
                //2 A decimal defining the Y coordinate of center point.
                //3 A decimal defining the outer diameter of outer concentric ring
                //4 A decimal defining the ring thickness
                //5 A decimal defining the gap between rings
                //6 Maximum number of rings
                //7 A decimal defining the cross hair thickness
                //8 A decimal defining the cross hair length
                //9 A decimal defining the rotation angle around the origin. Rotation is only allowed if the center point is on the origin.

                break;


            case ApertureMacroTypes.Line_2:
            case ApertureMacroTypes.Line:
            {
                if (Gerber.ShowProgress)
                {
                    Console.WriteLine("Making an aperture for line. {0} params. {1} in paramlist", Params.Count, paramlist.Count());
                }
                {
                    //1 Exposure off/on (0/1)
                    //2 Line width, a decimal ≥ 0.
                    //3 A decimal defining the X coordinate of start point.
                    //4 A decimal defining the Y coordinate of start point.
                    //5 A decimal defining the X coordinate of end point.
                    //6 A decimal defining the Y coordinate of end point.
                    //7 A decimal defining the rotation angle around the origin (rotation is not around the center of the object)
                }
                Width    = GNF.ScaleFileToMM(Params[2].BuildValue(paramlist));
                Xoff     = GNF.ScaleFileToMM(Params[3].BuildValue(paramlist));
                Yoff     = GNF.ScaleFileToMM(Params[4].BuildValue(paramlist));
                Xend     = GNF.ScaleFileToMM(Params[5].BuildValue(paramlist));
                Yend     = GNF.ScaleFileToMM(Params[6].BuildValue(paramlist));
                Rotation = Params[7].BuildValue(paramlist);



                AT.SetLineSegment(new PointD(Xoff, Yoff), new PointD(Xend, Yend), Width, Rotation);
            }
            break;

            default:
                Console.WriteLine("I don't know how to make an aperture for macro type {0}!", Type);
                break;
            }

            AT.ShapeType = GerberApertureShape.Macro;
            AT.MacroName = Name;

            return(AT);
        }
        internal void SetThermal(double Xoff, double Yoff, double OuterDiameter, double InnerDiameter, double GapWidth, double Rotation)
        {
            Shape.Vertices.Clear();
            GerberApertureType sector1 = new GerberApertureType();

            sector1.Shape.Vertices.Clear();
            GerberApertureType sector2 = new GerberApertureType();

            sector2.Shape.Vertices.Clear();
            GerberApertureType sector3 = new GerberApertureType();

            sector3.Shape.Vertices.Clear();
            GerberApertureType sector4 = new GerberApertureType();

            sector4.Shape.Vertices.Clear();
            int sides = (int)Math.Floor(10 * Math.Max(18.0, OuterDiameter / 2));

            // draw outer arc
            {
                double radius = OuterDiameter / 2;
                double padd   = 0;// -rotation * Math.PI * 2.0 / 360;
                for (int i = 0; i < sides; i++)
                {
                    double P = i / (double)sides * Math.PI * 2.0 + padd;
                    double x = (double)(Xoff + Math.Sin(P) * radius);
                    double y = (double)(Yoff + Math.Cos(P) * radius);
                    if ((y < Yoff - GapWidth / 2) && (x < Xoff - GapWidth / 2))
                    {
                        if (i == 0)
                        {
                            sector1.Shape.Add(Xoff - GapWidth / 2, Yoff - GapWidth / 2);
                        }
                        sector1.Shape.Add(x, y);
                    }
                    if ((y < Yoff - GapWidth / 2) && (x >= Xoff + GapWidth / 2))
                    {
                        if (i == 0)
                        {
                            sector2.Shape.Add(Xoff + GapWidth / 2, Yoff - GapWidth / 2);
                        }
                        sector2.Shape.Add(x, y);
                    }
                    if ((y >= Yoff + GapWidth / 2) && (x >= Xoff + GapWidth / 2))
                    {
                        if (i == 0)
                        {
                            sector3.Shape.Add(Xoff + GapWidth / 2, Yoff + GapWidth / 2);
                        }
                        sector3.Shape.Add(x, y);
                    }
                    if ((y >= Yoff + GapWidth / 2) && (x < Xoff - GapWidth / 2))
                    {
                        if (i == 0)
                        {
                            sector4.Shape.Add(Xoff - GapWidth / 2, Yoff + GapWidth / 2);
                        }
                        sector4.Shape.Add(x, y);
                    }
                }
            }

            // draw inner arc
            {
                double radius = InnerDiameter / 2;
                double padd   = 0;// -rotation * Math.PI * 2.0 / 360;
                for (int i = sides - 1; i >= 0; i--)
                {
                    double P = i / (double)sides * Math.PI * 2.0 + padd;
                    double x = (double)(Xoff + Math.Sin(P) * radius);
                    double y = (double)(Yoff + Math.Cos(P) * radius);
                    if ((y < Yoff - GapWidth / 2) && (x < Xoff - GapWidth / 2))
                    {
                        if (i == 0)
                        {
                            sector1.Shape.Add(Xoff - GapWidth / 2, Yoff - GapWidth / 2);
                        }
                        sector1.Shape.Add(x, y);
                    }
                    if ((y < Yoff - GapWidth / 2) && (x >= Xoff + GapWidth / 2))
                    {
                        if (i == 0)
                        {
                            sector2.Shape.Add(Xoff + GapWidth / 2, Yoff - GapWidth / 2);
                        }
                        sector2.Shape.Add(x, y);
                    }
                    if ((y >= Yoff + GapWidth / 2) && (x >= Xoff + GapWidth / 2))
                    {
                        if (i == 0)
                        {
                            sector3.Shape.Add(Xoff + GapWidth / 2, Yoff + GapWidth / 2);
                        }
                        sector3.Shape.Add(x, y);
                    }
                    if ((y >= Yoff + GapWidth / 2) && (x < Xoff - GapWidth / 2))
                    {
                        if (i == 0)
                        {
                            sector4.Shape.Add(Xoff - GapWidth / 2, Yoff + GapWidth / 2);
                        }
                        sector4.Shape.Add(x, y);
                    }
                }
            }
            sector1.Shape.Close();
            sector1.Shape.RotateDegrees(Rotation);
            sector2.Shape.Close();
            sector2.Shape.RotateDegrees(Rotation);
            sector3.Shape.Close();
            sector3.Shape.RotateDegrees(Rotation);
            sector4.Shape.Close();
            sector4.Shape.RotateDegrees(Rotation);
            Parts.Add(sector1);
            Parts.Add(sector2);
            Parts.Add(sector3);
            Parts.Add(sector4);
        }