Exemple #1
0
        public string Rebuild(GerberNumberFormat form)
        {
            string Res = "";

            if ((Has("X") || Has("Y")) && Has("D"))
            {
                CommandsInOrder.Remove("X");
                CommandsInOrder.Remove("Y");
                CommandsInOrder.Remove("I");
                CommandsInOrder.Remove("J");
                CommandsInOrder.Remove("D");

                if (Has("X"))
                {
                    CommandsInOrder.Add("X");
                }
                if (Has("Y"))
                {
                    CommandsInOrder.Add("Y");
                }
                if (Has("I"))
                {
                    CommandsInOrder.Add("I");
                }
                if (Has("J"))
                {
                    CommandsInOrder.Add("J");
                }
                CommandsInOrder.Add("D");
            }
            foreach (var a in CommandsInOrder)
            {
                Res += a;
                if (a == "D" || a == "G" || a == "M")
                {
                    Res += ((int)Get(a)).ToString("D2");
                }
                else
                {
                    Res += form.Format(Get(a));
                }
            }
            return(Res + "*");
        }
Exemple #2
0
 public static string MoveTo(PointD t, GerberNumberFormat GNF)
 {
     return(String.Format("X{0}Y{1}D02*", GNF.Format(GNF._ScaleMMToFile(t.X)), GNF.Format(GNF._ScaleMMToFile(t.Y))));
 }
Exemple #3
0
        public string Rebuild(GerberNumberFormat form)
        {
            string Res = "";

            if ((Has("X") || Has("Y")) && Has("D"))
            {
                CommandsInOrder.Remove("X");
                CommandsInOrder.Remove("Y");
                CommandsInOrder.Remove("I");
                CommandsInOrder.Remove("J");
                CommandsInOrder.Remove("D");

                if (Has("X"))
                {
                    CommandsInOrder.Add("X");
                }
                if (Has("Y"))
                {
                    CommandsInOrder.Add("Y");
                }
                if (Has("I"))
                {
                    CommandsInOrder.Add("I");
                }
                if (Has("J"))
                {
                    CommandsInOrder.Add("J");
                }
                CommandsInOrder.Add("D");
            }
            else
            {
                if (Has("D") && Get("D") < 10)
                {
                    CommandsInOrder.Remove("D");
                    CommandsInOrder.Add("D");
                }
            }
            foreach (var a in CommandsInOrder)
            {
                if (a == "D" || a == "G" || a == "M")
                {
                    Res += a;
                    Res += ((int)Get(a)).ToString("D2");
                }
                else
                {
                    bool Write = true;
                    if (a == "J" || a == "I")

                    {
                        string R         = form.Format(Get(a));
                        int    zerocount = 0;
                        for (int i = 0; i < R.Count(); i++)
                        {
                            if (R[i] == '0')
                            {
                                zerocount++;
                            }
                        }
                        if (zerocount == R.Count())
                        {
                            Write = false;
                        }
                    }
                    if (Write)
                    {
                        Res += a;
                        Res += form.Format(Get(a));
                    }
                }
            }
            return(Res + "*");
        }
Exemple #4
0
        public void Write(string filename, double DX, double DY, double DXp, double DYp, double AngleInDeg = 0)
        {
            double Angle = AngleInDeg * (Math.PI * 2.0) / 360.0;
            double CA    = Math.Cos(Angle);
            double SA    = Math.Sin(Angle);

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

            lines.Add("%");
            lines.Add("M48");
            lines.Add("METRIC,000.000");
            //lines.Add("M71");
            foreach (var a in Tools)
            {
                lines.Add(String.Format("T{0}C{1}", a.Key.ToString("D2"), (a.Value.Radius * 2).ToString("N2").Replace(',', '.')));
            }
            lines.Add("%");
            GerberNumberFormat GNF = new GerberNumberFormat();

            GNF.SetMetricMode();
            GNF.OmitLeading  = true;
            GNF.DigitsAfter  = 3;
            GNF.DigitsBefore = 3;
            foreach (var a in Tools)
            {
                lines.Add(String.Format("T{0}", a.Key.ToString("D2")));
                double coordmultiplier = 1;

                foreach (var d in a.Value.Drills)
                {
                    double X = (d.X * coordmultiplier + DXp) / coordmultiplier;
                    double Y = (d.Y * coordmultiplier + DYp) / coordmultiplier;
                    if (Angle != 0)
                    {
                        double nX = X * CA - Y * SA;
                        double nY = X * SA + Y * CA;
                        X = nX;
                        Y = nY;
                    }
                    X = (X * coordmultiplier + DX) / coordmultiplier;
                    Y = (Y * coordmultiplier + DY) / coordmultiplier;

                    lines.Add(string.Format("X{0}Y{1}", GNF.Format(X), GNF.Format(Y).Replace(',', '.')));
                }

                foreach (var s in a.Value.Slots)
                {
                    double XS = (s.Start.X * coordmultiplier + DXp) / coordmultiplier;
                    double YS = (s.Start.Y * coordmultiplier + DYp) / coordmultiplier;
                    double XE = (s.End.X * coordmultiplier + DXp) / coordmultiplier;
                    double YE = (s.End.Y * coordmultiplier + DYp) / coordmultiplier;
                    if (Angle != 0)
                    {
                        double nX = XS * CA - YS * SA;
                        double nY = XS * SA + YS * CA;
                        XS = nX;
                        YS = nY;

                        double neX = XE * CA - YE * SA;
                        double neY = XE * SA + YE * CA;
                        XE = neX;
                        YE = neY;
                    }
                    XS = (XS * coordmultiplier + DX) / coordmultiplier;
                    YS = (YS * coordmultiplier + DY) / coordmultiplier;
                    XE = (XE * coordmultiplier + DX) / coordmultiplier;
                    YE = (YE * coordmultiplier + DY) / coordmultiplier;

                    lines.Add(string.Format("X{0}Y{1}G85X{2}Y{3}", GNF.Format(XS), GNF.Format(YS).Replace(',', '.'), GNF.Format(XE), GNF.Format(YE).Replace(',', '.')));
                }
            }
            lines.Add("M30");
            Gerber.WriteAllLines(filename, lines);
        }