List <ApertureMacroParam> RotateParams(ApertureMacroParam A, ApertureMacroParam B, double rotation)
        {
            List <ApertureMacroParam> Res = new List <ApertureMacroParam>();

            ApertureMacroParam X = new ApertureMacroParam(true)
            {
                boundparam = A.boundparam, scaledvalue = A.scaledvalue, value = A.value
            };
            ApertureMacroParam Y = new ApertureMacroParam(true)
            {
                boundparam = B.boundparam, scaledvalue = B.scaledvalue, value = B.value
            };

            PolyLine R = new PolyLine(PolyLine.PolyIDs.Temp);

            R.Add(X.value, Y.value);
            R.Add(X.scaledvalue, Y.scaledvalue);
            R.RotateDegrees(rotation);

            X.value       = R.Vertices[0].X;
            Y.value       = R.Vertices[0].Y;
            X.scaledvalue = R.Vertices[1].X;
            Y.scaledvalue = R.Vertices[1].Y;

            Res.Add(X);
            Res.Add(Y);
            return(Res);
        }
Exemplo n.º 2
0
        public PolyLine Copy()
        {
            PolyLine PL = new PolyLine(ID);

            foreach (var a in Vertices)
            {
                PL.Add(a.X, a.Y);
            }
            return(PL);
        }
Exemplo n.º 3
0
 public bool EntirelyInside(PolyLine b)
 {
     foreach (var v in Vertices)
     {
         if (b.PointInPoly(v) == false)
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 4
0
        //  public Tool MyTool;

        public void FillTransformed(PolyLine c, PointD trans, float angle)
        {
            double cx = Math.Cos(angle * Math.PI * 2 / 360.0);
            double sx = Math.Sin(angle * Math.PI * 2 / 360.0);


            Vertices.Clear();
            foreach (var a in c.Vertices)
            {
                Vertices.Add(new PointD(cx * a.X - sx * a.Y + trans.X, sx * a.X + cx * a.Y + trans.Y));
            }
            //  throw new NotImplementedException();
        }
Exemplo n.º 5
0
        public static PolyLine Stroke(double x1, double y1, double x2, double y2, double w)
        {
            PolyLine PL = new PolyLine(PolyIDs.GFXTemp);
            PointD   A  = new PointD(x1, y1);
            PointD   B  = new PointD(x2, y2);
            var      C  = B - A;

            PL.MakeRectangle(w, C.Length() + w);
            PL.Translate(0, C.Length() / 2);
            PL.RotateDegrees(Math.Atan2(C.Y, C.X) * 360 / (Math.PI * 2) - 90);
            PL.Translate(x1, y1);

            return(PL);
        }
Exemplo n.º 6
0
        public PolyLine Copy()
        {
            PolyLine PL = new PolyLine(ID);

            foreach (var a in Vertices)
            {
                PL.Add(a.X, a.Y);
            }
            PL.ID            = ID;
            PL.Hole          = Hole;
            PL.Width         = Width;
            PL.Thin          = Thin;
            PL.ClearanceMode = ClearanceMode;
            PL.Draw          = Draw;
            PL.MyColor       = MyColor;

            return(PL);
        }
Exemplo n.º 7
0
        internal List <PolyLine> Offset(double margin, int v)
        {
            List <PolyLine> Res = new List <PolyLine>();


            Polygons clips = new Polygons();
            Polygon  b     = this.toPolygon();

            clips.Add(b);
            Polygons clips2 = Clipper.OffsetPolygons(clips, margin * 100000.0f, JoinType.jtRound);

            foreach (var r in clips2)
            {
                PolyLine PLR = new PolyLine(v++);
                PLR.fromPolygon(r);
                Res.Add(PLR);
            }


            return(Res);
        }
        public string BuildGerber(GerberNumberFormat GNF, double rotationdegrees)
        {
            string res = "";

            switch (Type)
            {
            case ApertureMacroTypes.Equation:
                res += String.Format("{0}={1}", EquationTarget, EquationSource);
                break;

            case ApertureMacroTypes.Line:
            case ApertureMacroTypes.Line_2:
            {
                var Rot = RotateParams(Params[3], Params[4], rotationdegrees);

                res += String.Format("20,1,{0},{1},{2},{3},{4},{5}",
                                     //Params[1].BuildGerber(rotationdegrees, false),
                                     Params[2].BuildGerber(GNF, rotationdegrees, false, true),
                                     Params[3].BuildGerber(GNF, rotationdegrees, false, true),
                                     Params[4].BuildGerber(GNF, rotationdegrees, false, true),
                                     Params[5].BuildGerber(GNF, rotationdegrees, false, true),
                                     Params[6].BuildGerber(GNF, rotationdegrees, false, true),
                                     Params[7].BuildGerber(GNF, rotationdegrees, true, false)
                                     );
                break;
            }

            default:
                Console.WriteLine("Sorry - I cant make gerber for macro parts of type {0} yet", Type);
                break;

            case ApertureMacroTypes.Outline:
                res += String.Format("4,1,{0}," + Gerber.LineEnding, OutlineVertices.Count - 1);
                if (rotationdegrees != 0)
                {
                    PolyLine P = new PolyLine(PolyLine.PolyIDs.Aperture);
                    for (int i = 0; i < OutlineVertices.Count; i++)
                    {
                        PointD B = OutlineVertices[i].Get(Params);
                        P.Add(B.X, B.Y);
                    }
                    P.RotateDegrees(rotationdegrees);
                    for (int i = 0; i < P.Vertices.Count(); i++)
                    {
                        res += String.Format("{0},{1}," + Gerber.LineEnding, Gerber.ToFloatingPointString(GNF._ScaleMMToFile(P.Vertices[i].X)).Replace(',', '.'), Gerber.ToFloatingPointString(GNF._ScaleMMToFile(P.Vertices[i].Y)).Replace(',', '.'));
                    }
                }
                else
                {
                    for (int i = 0; i < OutlineVertices.Count; i++)
                    {
                        PointD B = OutlineVertices[i].Get(Params);

                        res += String.Format("{0},{1}," + Gerber.LineEnding, Gerber.ToFloatingPointString(GNF._ScaleMMToFile(B.X)).Replace(',', '.'), Gerber.ToFloatingPointString(GNF._ScaleMMToFile(B.Y)).Replace(',', '.'));
                    }
                }
                res += "0";
                break;

            case ApertureMacroTypes.Polygon:
            {
                var Rot = RotateParams(Params[3], Params[4], rotationdegrees);

                res += String.Format("5,1,{0},{1},{2},{3},{4}",
                                     //Params[1].BuildGerber(rotationdegrees, false),
                                     Params[2].BuildGerberInt(GNF, rotationdegrees, false),
                                     Rot[0].BuildGerber(GNF, rotationdegrees, false, true),
                                     Rot[1].BuildGerber(GNF, rotationdegrees, false, true),
                                     Params[5].BuildGerber(GNF, rotationdegrees, false, false),
                                     Params[6].BuildGerber(GNF, rotationdegrees, true, false)
                                     );
                break;
            }

            case ApertureMacroTypes.Thermal:
            {
                var Rot = RotateParams(Params[1], Params[2], rotationdegrees);

                res += String.Format("7,1,{0},{1},{2},{3},{4},{5}",
                                     Rot[0].BuildGerber(GNF, rotationdegrees, false, true),
                                     Rot[1].BuildGerber(GNF, rotationdegrees, false, true),
                                     Params[3].BuildGerber(GNF, rotationdegrees, false, false),
                                     Params[4].BuildGerber(GNF, rotationdegrees, false, false),
                                     Params[5].BuildGerber(GNF, rotationdegrees, false, false),
                                     Params[6].BuildGerber(GNF, rotationdegrees, true, false)
                                     );
                break;
            }

            case ApertureMacroTypes.CenterLine:
            {
                var Rot = RotateParams(Params[4], Params[5], rotationdegrees);
                res += String.Format("21,1,{0},{1},{2},{3},{4}",
                                     //Params[1].BuildGerber(rotationdegrees, false),
                                     Params[2].BuildGerber(GNF, rotationdegrees, false, true),
                                     Params[3].BuildGerber(GNF, rotationdegrees, false, true),
                                     Rot[0].BuildGerber(GNF, rotationdegrees, false, true),
                                     Rot[1].BuildGerber(GNF, rotationdegrees, false, true),
                                     Params[6].BuildGerber(GNF, rotationdegrees, true, false)
                                     );
            }
            break;

            case ApertureMacroTypes.LowerLeftLine:
            {
                var Rot = RotateParams(Params[4], Params[5], rotationdegrees);
                res += String.Format("21,1,{0},{1},{2},{3},{4}",
                                     //Params[1].BuildGerber(rotationdegrees, false),
                                     Params[2].BuildGerber(GNF, rotationdegrees, false, true),
                                     Params[3].BuildGerber(GNF, rotationdegrees, false, true),
                                     Rot[0].BuildGerber(GNF, rotationdegrees, false, true),
                                     Rot[1].BuildGerber(GNF, rotationdegrees, false, true),
                                     Params[6].BuildGerber(GNF, rotationdegrees, true, false)
                                     );
            }
            break;

            case ApertureMacroTypes.Circle:
                //res += "circ";
            {
                var Rot = RotateParams(Params[3], Params[4], rotationdegrees);

                res += String.Format("1,1,{0},{1},{2}",
                                     //Params[1].BuildGerber(rotationdegrees, false),
                                     Params[2].BuildGerber(GNF, rotationdegrees, false, true),
                                     Rot[0].BuildGerber(GNF, rotationdegrees, false, true),
                                     Rot[1].BuildGerber(GNF, rotationdegrees, false, true)
                                     );
            }
            break;
            }
            foreach (var a in Params)
            {
            }
            res += "*" + Gerber.LineEnding;
            return(res);
        }
Exemplo n.º 9
0
        public static List <PolyLine> MiniFontShapes(string v1, double _x, double _y, double size, double rotation = 0)
        {
            List <PolyLine> Res    = new List <PolyLine>();
            double          wunit  = size * 0.55f;
            double          hunit  = -size;
            double          stroke = size * 0.15;
            double          w      = 0;
            double          x      = 0;
            double          y      = 0;

            y -= hunit / 2;

            for (int i = 0; i < v1.Length; i++)
            {
                var c = v1[i];
                switch (c)
                {
                case '1': w += 0.5 * wunit; break;

                default: w += 1.5 * wunit; break;
                }
            }
            w -= 0.5 * wunit;
            x -= w / 2;

            for (int i = 0; i < v1.Length; i++)
            {
                var c = v1[i];
                switch (c)
                {
                case '0':
                    Res.Add(PolyLine.Stroke(x, y, x, y + hunit, stroke));
                    Res.Add(PolyLine.Stroke(x + wunit, y, x + wunit, y + hunit, stroke));
                    Res.Add(PolyLine.Stroke(x, y, x + wunit, y, stroke));
                    Res.Add(PolyLine.Stroke(x, y + hunit, x + wunit, y + hunit, stroke));
                    x += 1.5 * wunit;
                    break;

                case '1':
                    Res.Add(PolyLine.Stroke(x, y, x, y + hunit, stroke));
                    x += 0.5 * wunit;
                    break;

                case '2':
                    Res.Add(PolyLine.Stroke(x, y, x + wunit, y, stroke));
                    Res.Add(PolyLine.Stroke(x, y + hunit / 2, x + wunit, y + hunit / 2, stroke));
                    Res.Add(PolyLine.Stroke(x, y + hunit, x + wunit, y + hunit, stroke));
                    Res.Add(PolyLine.Stroke(x + wunit, y, x + wunit, y + hunit / 2, stroke));
                    Res.Add(PolyLine.Stroke(x, y + hunit / 2, x, y + hunit, stroke));


                    x += 1.5 * wunit;
                    break;

                case '3':
                    Res.Add(PolyLine.Stroke(x, y, x + wunit, y, stroke));
                    Res.Add(PolyLine.Stroke(x + wunit / 2, y + hunit / 2, x + wunit, y + hunit / 2, stroke));
                    Res.Add(PolyLine.Stroke(x, y + hunit, x + wunit, y + hunit, stroke));
                    Res.Add(PolyLine.Stroke(x + wunit, y, x + wunit, y + hunit, stroke));
                    x += 1.5 * wunit;
                    break;

                case '4':
                    Res.Add(PolyLine.Stroke(x, y, x, y + hunit / 2, stroke));
                    Res.Add(PolyLine.Stroke(x, y + hunit / 2, x + wunit, y + hunit / 2, stroke));
                    Res.Add(PolyLine.Stroke(x + wunit, y, x + wunit, y + hunit, stroke));

                    x += 1.5 * wunit;
                    break;

                case '5':
                    Res.Add(PolyLine.Stroke(x, y, x + wunit, y, stroke));
                    Res.Add(PolyLine.Stroke(x, y + hunit / 2, x + wunit, y + hunit / 2, stroke));
                    Res.Add(PolyLine.Stroke(x, y + hunit, x + wunit, y + hunit, stroke));
                    Res.Add(PolyLine.Stroke(x, y, x, y + hunit / 2, stroke));
                    Res.Add(PolyLine.Stroke(x + wunit, y + hunit / 2, x + wunit, y + hunit, stroke));

                    x += 1.5 * wunit;
                    break;

                case '6':
                    Res.Add(PolyLine.Stroke(x, y, x, y + hunit, stroke));
                    Res.Add(PolyLine.Stroke(x + wunit, y + hunit / 2, x + wunit, y + hunit, stroke));
                    Res.Add(PolyLine.Stroke(x, y, x + wunit, y, stroke));
                    Res.Add(PolyLine.Stroke(x, y + hunit / 2, x + wunit, y + hunit / 2, stroke));
                    Res.Add(PolyLine.Stroke(x, y + hunit, x + wunit, y + hunit, stroke));
                    x += 1.5 * wunit;
                    break;

                case '7':
                    Res.Add(PolyLine.Stroke(x, y, x + wunit, y, stroke));
                    Res.Add(PolyLine.Stroke(x + wunit, y, x + wunit, y + hunit, stroke));
                    x += 1.5 * wunit;
                    break;

                case '8':
                    Res.Add(PolyLine.Stroke(x, y, x, y + hunit, stroke));
                    Res.Add(PolyLine.Stroke(x + wunit, y, x + wunit, y + hunit, stroke));
                    Res.Add(PolyLine.Stroke(x, y, x + wunit, y, stroke));
                    Res.Add(PolyLine.Stroke(x, y + hunit, x + wunit, y + hunit, stroke));
                    Res.Add(PolyLine.Stroke(x, y + hunit / 2, x + wunit, y + hunit / 2, stroke));

                    x += 1.5 * wunit;
                    break;

                case '9':
                    Res.Add(PolyLine.Stroke(x, y + hunit / 2, x + wunit, y + hunit / 2, stroke));
                    Res.Add(PolyLine.Stroke(x, y, x, y + hunit / 2, stroke));

                    Res.Add(PolyLine.Stroke(x, y, x + wunit, y, stroke));

                    Res.Add(PolyLine.Stroke(x + wunit, y, x + wunit, y + hunit, stroke));
                    x += 1.5 * wunit;
                    break;
                }
            }

            Res.Add(PolyLine.Stroke(-w / 2, hunit * 0.5 - stroke * 2, w / 2, hunit * 0.5 - stroke * 2, stroke));
            foreach (var r in Res)
            {
                r.RotateDegrees(rotation);
                r.Translate(_x, _y);
            }

            return(Res);
        }
Exemplo n.º 10
0
        public List <PolyLine> CreatePolyLineSet(double X, double Y, int ShapeID, double rotation, double scale, GerberParserState.MirrorMode mirrored)
        {
            List <PolyLine> Res = new List <PolyLine>();

            if (Parts.Count > 0)
            {
                List <PolyLine> ResPre    = new List <PolyLine>();
                List <PolyLine> ResPreNeg = new List <PolyLine>();

                foreach (var a in Parts.Where(x => x.Polarity == true))
                {
                    ResPre.AddRange(a.CreatePolyLineSet(0, 0, ShapeID, 0, 1, GerberParserState.MirrorMode.NoMirror));
                }
                foreach (var a in Parts.Where(x => x.Polarity == false))
                {
                    ResPreNeg.AddRange(a.CreatePolyLineSet(0, 0, ShapeID, 0, 1, GerberParserState.MirrorMode.NoMirror));
                }
                Polygons Combined = new Polygons();
                Polygons Solution = new Polygons();


                Polygons clips = new Polygons();


                if (ResPreNeg.Count == 0)
                {
                    foreach (var c in ResPre)
                    {
                        //                    c.CheckIfHole();
                        //clips.Add(c.toPolygon());
                        //cp.AddPolygons(clips, PolyType.ptClip);
                        //cp.Execute(ClipType.ctUnion, Combined, PolyFillType.pftNonZero, PolyFillType.pftEvenOdd);

                        Solution.Add(c.toPolygon());
                    }
                    foreach (var p in Solution)
                    {
                        PolyLine PL = new PolyLine(ShapeID);
                        PL.fromPolygon(p);
                        Res.Add(PL);
                    }
                }
                else
                {
                    foreach (var c in ResPreNeg)
                    {
                        //                    c.CheckIfHole();
                        //clips.Add(c.toPolygon());
                        //cp.AddPolygons(clips, PolyType.ptClip);
                        //cp.Execute(ClipType.ctUnion, Combined, PolyFillType.pftNonZero, PolyFillType.pftEvenOdd);

                        clips.Add(c.toPolygon());
                    }

                    foreach (var c in ResPre)
                    {
                        //                    c.CheckIfHole();
                        //clips.Add(c.toPolygon());
                        //cp.AddPolygons(clips, PolyType.ptClip);
                        //cp.Execute(ClipType.ctUnion, Combined, PolyFillType.pftNonZero, PolyFillType.pftEvenOdd);

                        Combined.Add(c.toPolygon());
                    }

                    Clipper cp = new Clipper();
                    cp.AddPolygons(Combined, PolyType.ptClip);
                    cp.AddPolygons(clips, PolyType.ptSubject);

                    cp.Execute(ClipType.ctDifference, Solution, PolyFillType.pftNonZero, PolyFillType.pftNonZero);


                    foreach (var p in Solution)
                    {
                        PolyLine PL = new PolyLine(ShapeID);
                        PL.fromPolygon(p);
                        Res.Add(PL);
                    }
                }
            }
            else
            {
                if (Shape.Count() > 0)
                {
                    var PL = new PolyLine(ShapeID);
                    for (int i = 0; i < Shape.Count(); i++)
                    {
                        PL.Add(Shape.Vertices[i].X, Shape.Vertices[i].Y);
                    }
                    PL.Add(Shape.Vertices[0].X, Shape.Vertices[0].Y);
                    PL.Close();
                    Res.Add(PL);
                }
                else
                {
                    if (Gerber.ShowProgress)
                    {
                        Console.WriteLine("creating empty shape?? {0} {1}", MacroName, ShapeType);
                    }
                }
            }
            if (rotation != 0 || scale != 1 || mirrored != GerberParserState.MirrorMode.NoMirror)
            {
                double CA = Math.Cos((rotation * Math.PI * 2) / 360.0);
                double SA = Math.Sin((rotation * Math.PI * 2) / 360.0);

                double xscale = scale;
                double yscale = scale;
                switch (mirrored)
                {
                case GerberParserState.MirrorMode.X: xscale = -xscale; break;

                case GerberParserState.MirrorMode.XY: xscale = -xscale; yscale = -yscale; break;

                case GerberParserState.MirrorMode.Y: yscale = -yscale; break;
                }
                foreach (var a in Res)
                {
                    foreach (var p in a.Vertices)
                    {
                        double Xin = p.X;
                        double Yin = p.Y;

                        double nX = Xin * CA - Yin * SA;
                        double nY = Xin * SA + Yin * CA;


                        p.X = nX * xscale;
                        p.Y = nY * yscale;
                    }
                }
            }

            foreach (var a in Res)
            {
                foreach (var p in a.Vertices)
                {
                    p.X += X;
                    p.Y += Y;
                }
            }
            return(Res);
        }
Exemplo n.º 11
0
        public string BuildGerber(GerberNumberFormat format, string MacroNameSuffix = "", double RotationAngle = 0)
        {
            string res       = String.Format("%ADD{0}", ID.ToString("D2"));
            int    parmcount = 0;

            switch (ShapeType)
            {
            case GerberApertureShape.Macro:

                res += MacroName + MacroNameSuffix;
                if (MacroParamList.Count > 0)
                {
                    res += ",";
                }
                foreach (var a in MacroParamList)
                {
                    parmcount++;
                    if (parmcount >= 2)
                    {
                        res += "X";
                    }
                    res += Gerber.ToFloatingPointString(format._ScaleMMToFile(a)).Replace(',', '.');
                }
                break;

            case GerberApertureShape.Circle:
            {
                if (CircleRadius > 3)
                {
                    //Console.WriteLine("test");
                }
                res += "C," + Gerber.ToFloatingPointString(format._ScaleMMToFile(CircleRadius * 2)).Replace(',', '.');
            }
            break;

            case GerberApertureShape.Rectangle:
                if (RotationAngle == 0 || (int)RotationAngle == 180)
                {
                    res += "R," + Gerber.ToFloatingPointString(format._ScaleMMToFile(RectWidth)).Replace(',', '.') + "X" + Gerber.ToFloatingPointString(format._ScaleMMToFile(RectHeight)).Replace(',', '.');
                }
                else
                {
                    if ((int)RotationAngle == 90 || (int)RotationAngle == (-90) || (int)RotationAngle == (270))
                    {
                        res += "R," + Gerber.ToFloatingPointString(format._ScaleMMToFile(RectHeight)).Replace(',', '.') + "X" + Gerber.ToFloatingPointString(format._ScaleMMToFile(RectWidth)).Replace(',', '.');
                    }
                    else
                    {
                        string macroname = "REC" + (MacroPostFix++).ToString();

                        PolyLine Rect = new PolyLine(PolyLine.PolyIDs.Temp);
                        Rect.MakeRectangle(RectWidth, RectHeight);
                        Rect.RotateDegrees(RotationAngle);
                        res = Gerber.BuildOutlineApertureMacro(macroname, Rect.Vertices, format) + res;

                        res += macroname;
                        if (Gerber.ShowProgress)
                        {
                            Console.WriteLine("generated rotated rect: ");
                        }
                        if (Gerber.ShowProgress)
                        {
                            Console.WriteLine(res);
                        }
                    }
                }
                break;

            case GerberApertureShape.Polygon:
                if (RotationAngle == 0)
                {
                    res += "P," + Gerber.ToFloatingPointString(format._ScaleMMToFile(NGonRadius * 2)).Replace(',', '.') + "X" + NGonSides.ToString() + "X" + Gerber.ToFloatingPointString(NGonRotation).Replace(',', '.');
                }
                else
                {
                    double newangle = NGonRotation + RotationAngle;
                    while (newangle < 0)
                    {
                        newangle += 360;
                    }
                    while (newangle > 360)
                    {
                        newangle -= 360;
                    }
                    res += "P," + Gerber.ToFloatingPointString(format._ScaleMMToFile(NGonRadius * 2)).Replace(',', '.') + "X" + NGonSides.ToString() + "X" + Gerber.ToFloatingPointString(newangle).Replace(',', '.');
                    if (Gerber.ShowProgress)
                    {
                        Console.WriteLine("generated rotated NGon: ");
                    }
                    if (Gerber.ShowProgress)
                    {
                        Console.WriteLine(res);
                    }
                }
                break;

            case GerberApertureShape.OBround:
                if (RotationAngle == 0 || Math.Abs(Math.Abs(RotationAngle) - 180) < 0.01)
                {
                    res += "O," + Gerber.ToFloatingPointString(format._ScaleMMToFile(RectWidth)).Replace(',', '.') + "X" + Gerber.ToFloatingPointString(format._ScaleMMToFile(RectHeight)).Replace(',', '.');
                }
                else
                {
                    if (Math.Abs(Math.Abs(RotationAngle) - 90) < 0.01)
                    {
                        res += "O," + Gerber.ToFloatingPointString(format._ScaleMMToFile(RectHeight)).Replace(',', '.') + "X" + Gerber.ToFloatingPointString(format._ScaleMMToFile(RectWidth)).Replace(',', '.');
                    }
                    else
                    {
                        string macroname = "OBR" + (MacroPostFix++).ToString();


                        PolyLine Obround = new PolyLine(PolyLine.PolyIDs.Temp);

                        Obround.SetObround(RectWidth, RectHeight);
                        Obround.RotateDegrees(RotationAngle);

                        res  = Gerber.BuildOutlineApertureMacro(macroname, Obround.Vertices, format) + res;
                        res += macroname;


                        if (Gerber.ShowProgress)
                        {
                            Console.WriteLine("generated rotated obround: ");
                        }
                        if (Gerber.ShowProgress)
                        {
                            Console.WriteLine(res);
                        }
                    }
                }
                break;

            case GerberApertureShape.Compound:
            {
                string macroname = "COMP" + (MacroPostFix++).ToString() + MacroNameSuffix;
                string macrores  = Gerber.WriteMacroStart(macroname);
                foreach (var P in Parts)
                {
                    PolyLine Comp = new PolyLine(PolyLine.PolyIDs.Temp);

                    foreach (var a in P.Shape.Vertices)

                    {
                        Comp.Add(a.X, a.Y);
                    }
                    Comp.Close();
                    Comp.RotateDegrees(RotationAngle);

                    macrores += Gerber.WriteMacroPartVertices(Comp.Vertices, format);
                }

                macrores += Gerber.WriteMacroEnd();
                res       = macrores + res;
                res      += macroname;


                if (Parts.Count > 1)
                {
                    Console.WriteLine("Number of parts: {0} but only 1 written", Parts.Count);
                    Console.WriteLine(res);
                }

                // res += MacroName;
                if (MacroParamList.Count > 0)
                {
                    res += ",";
                }
                foreach (var a in MacroParamList)
                {
                    parmcount++;
                    if (parmcount >= 2)
                    {
                        res += "X";
                    }
                    res += Gerber.ToFloatingPointString(a).Replace(',', '.');
                }


                if (Gerber.ShowProgress)
                {
                    Console.WriteLine("generated rotated compound macro shape: ");
                }
                if (Gerber.ShowProgress)
                {
                    Console.WriteLine(res);
                }
            }
            break;

            default:
                Console.WriteLine("I don't know how to generate the source for this aperture yet.");
                break;
            }

            res += "*%";

            return(res);
        }
Exemplo n.º 12
0
 public GerberApertureType()
 {
     Shape = new PolyLine(PolyLine.PolyIDs.ApertureConstr);
     SetRectangle(1, 1, 0);
     ID = 0;
 }
Exemplo n.º 13
0
        public List <PolyLine> CreatePolyLineSet(double X, double Y, int ShapeID)
        {
            List <PolyLine> Res = new List <PolyLine>();

            if (Parts.Count > 0)
            {
                List <PolyLine> ResPre = new List <PolyLine>();

                foreach (var a in Parts)
                {
                    ResPre.AddRange(a.CreatePolyLineSet(X, Y, ShapeID));
                }
                Polygons Combined = new Polygons();

                Polygons clips = new Polygons();


                foreach (var c in ResPre)
                {
                    //                    c.CheckIfHole();
                    //Clipper cp = new Clipper();
                    //cp.AddPolygons(Combined, PolyType.ptSubject);
                    //clips.Add(c.toPolygon());
                    //cp.AddPolygons(clips, PolyType.ptClip);
                    //cp.Execute(ClipType.ctUnion, Combined, PolyFillType.pftNonZero, PolyFillType.pftEvenOdd);

                    Combined.Add(c.toPolygon());
                }



                foreach (var p in Combined)
                {
                    PolyLine PL = new PolyLine(ShapeID);
                    PL.fromPolygon(p);
                    Res.Add(PL);
                }
            }
            else
            {
                if (Shape.Count() > 0)
                {
                    var PL = new PolyLine(ShapeID);
                    for (int i = 0; i < Shape.Count(); i++)
                    {
                        PL.Add(X + Shape.Vertices[i].X, Y + Shape.Vertices[i].Y);
                    }
                    PL.Add(X + Shape.Vertices[0].X, Y + Shape.Vertices[0].Y);
                    PL.Close();
                    Res.Add(PL);
                }
                else
                {
                    if (Gerber.ShowProgress)
                    {
                        Console.WriteLine("creating empty shape?? {0} {1}", MacroName, ShapeType);
                    }
                }
            }
            return(Res);
        }
Exemplo n.º 14
0
 public GerberApertureType()
 {
     Shape = new PolyLine();
     SetRectangle(1, 1);
     ID = 0;
 }