Exemplo n.º 1
0
        static void Main(string[] args)
        {
            GerberSplitter GS = new GerberSplitter();

            GS.Split("G03*", new GerberLibrary.Core.Primitives.GerberNumberFormat());
            Console.WriteLine("{0}", GS.Pairs.Count);
            Gerber.ShowProgress = true;
            if (args.Count() < 2)
            {
                Console.WriteLine("usage: ");
                Console.WriteLine("GerberCombiner <outputfile> <inputfile1> <inputfile2> <inputfileN> ");
                Console.WriteLine("<outputfile>: file to write - if the outputfile extension is .txt, all input files will be treated as excellon");
                Console.WriteLine("<inputfileN>: files to load");

                return;
            }
            for (int j = 1; j < args.Count(); j++)
            {
                if (File.Exists(args[j]) == false)
                {
                    Console.WriteLine("file not found! {0}", args[j]);
                    return;
                }
            }
            BoardSide  S;
            BoardLayer L;

            var FileType = Gerber.FindFileType(args[1]);

            Gerber.DetermineBoardSideAndLayer(args[1], out S, out L);

            for (int j = 2; j < args.Count(); j++)
            {
                var FileType2 = Gerber.FindFileType(args[1]);

                Gerber.DetermineBoardSideAndLayer(args[1], out S, out L);
                if (FileType2 != FileType)
                {
                    Console.WriteLine("Warning! Filetypes seem to be mismatched! First file ({0}) is a {1}, but {2} is a {3}", args[1], FileType, args[j], FileType2);
                }
            }


            if (FileType == BoardFileType.Drill)
            {
                List <string> ExcellonFiles = new List <string>();
                ExcellonFiles.AddRange(args.Skip(1));
                ExcellonFile.MergeAll(ExcellonFiles, args[0], new StandardConsoleLog());
            }
            else
            {
                List <string> GerberFiles = new List <string>();
                GerberFiles.AddRange(args.Skip(1));
                GerberMerger.MergeAll(GerberFiles, args[0], new StandardConsoleLog());
            }
            //      Console.WriteLine("Press any key to continue..");
            //     Console.ReadKey();
        }
Exemplo n.º 2
0
        public void Parse(string p)
        {
            GCodeCommand GCC = new GCodeCommand();

            GCC.Decode(p, new GerberNumberFormat());
            GerberSplitter GS = new GerberSplitter();

            GS.Split(p, new GerberNumberFormat());
            if (true)//GCC.charcommands[2] == 'S')
            {
                if (p.IndexOf('L') > p.IndexOf('T'))
                {
                    OmitLeading = true;
                }
                else
                {
                    OmitLeading = false;
                    // omit trailing zeroes
                }
                if (p.IndexOf('A') > p.IndexOf('I'))
                {
                    Relativemode = false;
                }
                else
                {
                    Relativemode = true;
                }

                int X1 = (int)GS.GetByLastChar("X");

                int X2 = (int)GS.GetByLastChar("Y");


                if (X1 != X2)
                {
                    Console.WriteLine("Format has different precisions for X and Y coordinates - not supported yet.");
                }

                DigitsBefore = X1 / 10;
                DigitsAfter  = X1 % 10;;
                if (Gerber.ShowProgress)
                {
                    Console.WriteLine("Gerber number format: {0} before, {1} after. Omitleading: {2}", DigitsBefore, DigitsAfter, OmitLeading);
                }
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            //CultureInfo ci = new CultureInfo("en-US");
            //Thread.CurrentThread.CurrentCulture = ci;
            //Thread.CurrentThread.CurrentUICulture = ci;

            GerberSplitter     GS  = new GerberSplitter();
            GerberNumberFormat GNF = new GerberNumberFormat();

            GNF.DigitsBefore = 2;
            GNF.DigitsAfter  = 4;
            GNF.OmitLeading  = true;

            GS.Split("X1.4917Y-2.1589", GNF, true);
            foreach (var a in GS.Pairs)
            {
                Console.WriteLine("{0}:{1}", a.Key, a.Value.Number);
            }
            Console.ReadKey();
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            GerberNumberFormat GNF = new GerberNumberFormat();

            GNF.DigitsAfter  = 3;
            GNF.DigitsBefore = 3;
            GNF.SetMetricMode();

            GerberSplitter GS = new GerberSplitter();

            GS.Split("X-1.15Y-1.9", GNF, true);

            foreach (var a in GS.Pairs)
            {
                Console.WriteLine("{0}:{1} {2}", a.Key, a.Value.Command, a.Value.Number);
            }
            Console.ReadKey();

            if (args.Count() == 0)
            {
                Console.WriteLine("Usage:");
                Console.WriteLine("GerberAnalyse <inputfile> <-forcezerowidth> <-dim>");
                return;
            }
            ParsedGerber PLS;
            bool         forcezerowidth = false;
            bool         compact        = false;

            for (int i = 1; i < args.Count(); i++)
            {
                if (args[i] == "-forcezerowidth")
                {
                    forcezerowidth = true;
                }
                if (args[i] == "-dim")
                {
                    compact = true;
                }
            }

            if (Gerber.FindFileType(args[0].ToLower()) == BoardFileType.Drill)
            {
                PLS = PolyLineSet.LoadExcellonDrillFile(args[0]);
                // ExcellonFile EF = new ExcellonFile();
                // EF.Load(a);
            }
            else
            {
                // PLS.PreCombinePolygons = false;
                // forcezerowidth = true;
                PLS = PolyLineSet.LoadGerberFile(args[0], forcezerowidth, false, new GerberParserState()
                {
                    PreCombinePolygons = false
                });
            }

            PLS.CalcPathBounds();

            if (compact)
            {
                CultureInfo CI = CultureInfo.InvariantCulture;

                Console.WriteLine("{0}x{1}(mm)", (PLS.BoundingBox.BottomRight.X - PLS.BoundingBox.TopLeft.X).ToString("N3", CI), (PLS.BoundingBox.BottomRight.Y - PLS.BoundingBox.TopLeft.Y).ToString("N3", CI));
                Console.WriteLine("{0}x{1}(imp)", ((PLS.BoundingBox.BottomRight.X - PLS.BoundingBox.TopLeft.X) / 25.4).ToString("N3", CI), ((PLS.BoundingBox.BottomRight.Y - PLS.BoundingBox.TopLeft.Y) / 25.4).ToString("N3", CI));
            }
            else
            {
                Console.WriteLine("Report for {0}:", args[0]);
                Console.WriteLine("Suspected file side: {0}, layertype: {1}", PLS.Side.ToString(), PLS.Layer.ToString());
                Console.WriteLine("DisplayShape #: {0}", PLS.DisplayShapes.Count);
                foreach (var o in PLS.DisplayShapes)
                {
                    Console.WriteLine("\tOutline {0} vertices thin:{1}", o.Vertices.Count, o.Thin);
                    foreach (var v in o.Vertices)
                    {
                        Console.WriteLine("\t\t{0}", v);
                    }
                }

                Console.WriteLine("OutlineShape #: {0}", PLS.OutlineShapes.Count);
                foreach (var o in PLS.OutlineShapes)
                {
                    Console.WriteLine("\tOutline {0} vertices thin:{1}", o.Vertices.Count, o.Thin);
                    foreach (var v in o.Vertices)
                    {
                        Console.WriteLine("\t\t{0}", v);
                    }
                }
                Console.WriteLine("Aperture #: {0}", PLS.State.Apertures.Count);
                foreach (var apt in PLS.State.Apertures)
                {
                    Console.Write("\tAperture D{0} ", apt.Key.ToString("D2"));
                    Console.Write("type: {0} ", apt.Value.ShapeType.ToString());
                    switch (apt.Value.ShapeType)
                    {
                    case GerberApertureShape.Circle:

                        Console.Write("diameter {0} ", apt.Value.CircleRadius * 2); break;
                    }
                    Console.WriteLine();
                }
                Console.WriteLine("Corners: ");
                Console.WriteLine(PLS.BoundingBox.TopLeft);
                Console.WriteLine(PLS.BoundingBox.BottomRight);
                Console.WriteLine("Size: {0}x{1} mm", PLS.BoundingBox.BottomRight.X - PLS.BoundingBox.TopLeft.X, PLS.BoundingBox.BottomRight.Y - PLS.BoundingBox.TopLeft.Y);
            }
            //  Console.WriteLine("Press any key to continue");
            //  Console.ReadKey();
        }
Exemplo n.º 5
0
        private static Dictionary <string, Tuple <GerberApertureType, List <PointD> > > FillOverlapList(ProgressLog log, Dictionary <string, Tuple <GerberApertureType, List <PointD> > > overlapList, ParsedGerber subtr, string subtractfile)
        {
            log.PushActivity("Filling overlap list coords");
            List <String> lines    = new List <string>();
            List <String> outlines = new List <string>();

            int  CurrentAperture = 10;
            bool WriteMove       = false;
            int  moveswritten    = 0;

            using (StreamReader sr = new StreamReader(subtractfile))
            {
                while (sr.EndOfStream == false)
                {
                    String line = sr.ReadLine();
                    if (line.Length > 0)
                    {
                        lines.Add(line);
                    }
                }
            }
            lines = PolyLineSet.SanitizeInputLines(lines);

            //ParsedGerber Parsed = PolyLineSet.ParseGerber274x(log, lines, true, false, new GerberParserState() { GenerateGeometry = false });



            GerberNumberFormat CoordinateFormat = new GerberNumberFormat();

            CoordinateFormat.SetImperialMode();
            //   CoordinateFormat = Parsed.State.CoordinateFormat;

            int  cur          = 0;
            bool formatparsed = false;

            while (cur < lines.Count && formatparsed == false)
            {
                if (lines[cur].Length >= 2 && lines[cur].Substring(0, 2) == "%F")
                {
                    CoordinateFormat.Parse(lines[cur]);
                    formatparsed = true;
                }
                cur++;
            }

            //  double coordmultiplier = 1.0;
            double LastX = 0;
            double LastY = 0;

            for (int i = 0; i < lines.Count; i++)
            {
                GerberSplitter GS           = new GerberSplitter();
                string         FinalLine    = lines[i].Replace("%", "").Replace("*", "").Trim();
                bool           DumpToOutput = false;
                bool           metaopen     = false;
                if (lines[i][0] == '%')
                {
                    DumpToOutput = true;
                    metaopen     = true;
                }
                else
                {
                    GS.Split(lines[i], CoordinateFormat);
                }


                switch (FinalLine)
                {
                case "G71": CoordinateFormat.SetMetricMode(); break;

                case "G70": CoordinateFormat.SetImperialMode(); break;

                case "MOIN":
                {
                    CoordinateFormat.SetImperialMode();
                    //CoordinateFormat.Multiplier  = 25.4f;
                }
                break;

                case "MOMM":
                {
                    CoordinateFormat.SetMetricMode();
                    //CoordinateFormat.Multiplier = 1.0f;
                }
                break;
                }
                if (lines[i].Length > 3 && lines[i].Substring(0, 3) == "%AM")
                {
                    string name = lines[i].Substring(3).Split('*')[0];

                    var M = subtr.State.ApertureMacros[name];
                    M.Written = true;
                    var gerb = M.BuildGerber(CoordinateFormat, 0, "").Split('\n');
                    foreach (var l in gerb)
                    {
                        if (l.Trim().Length > 0)
                        {
                            outlines.Add(l.Trim());
                        }
                    }
                    //    outlines.Add(lines[i]);
                    //  if (lines[i][lines[i].Length - 1] != '%')
                    ///  {
                    //   i++;
                    while (lines[i][lines[i].Length - 1] != '%')
                    {
                        //     outlines.Add(lines[i]);
                        i++;
                    }
                    //                       outlines.Add(lines[i]);
                    //     }
                }
                else

                if (lines[i].Length > 3 && lines[i].Substring(0, 3) == "%AD")
                {
                    GCodeCommand GCC = new GCodeCommand();
                    GCC.Decode(lines[i], CoordinateFormat);
                    if (GCC.numbercommands.Count < 1)
                    {
                        log.AddString(String.Format("Skipping bad aperture definition: {0}", lines[i]));
                    }
                    else
                    {
                        int ATID     = (int)GCC.numbercommands[0];
                        var Aperture = subtr.State.Apertures[ATID];
                        if (Gerber.ShowProgress)
                        {
                            log.AddString(String.Format("found " + Aperture.ToString()));
                        }
                        string gerb = Aperture.BuildGerber(CoordinateFormat, "", 0);

                        if ((Aperture.ShapeType == GerberApertureShape.Compound || Aperture.ShapeType == GerberApertureShape.Macro) && subtr.State.ApertureMacros[Aperture.MacroName].Written == false)
                        {
                            log.AddString(String.Format("Macro type defined - skipping"));
                        }
                        else
                        {
                            outlines.Add(gerb);
                        }

                        //                   outlines.Add(lines[i]);
                        if (lines[i][lines[i].Length - 1] != '%')
                        {
                            i++;
                            while (lines[i] != "%")
                            {
                                //                         outlines.Add(lines[i]);
                                i++;
                            }
                            //                   outlines.Add(lines[i]);
                        }
                    }
                }
                else
                {
                    bool PureD = false;
                    if (GS.Has("G"))
                    {
                        int GCode = (int)GS.Get("G");
                        switch (GCode)
                        {
                        case 4: DumpToOutput = true; break;

                        case 90: CoordinateFormat.Relativemode = false; break;

                        case 91: CoordinateFormat.Relativemode = true; break;

                        case 71: CoordinateFormat.Multiplier = 1.0d; break;

                        case 70: CoordinateFormat.Multiplier = 25.4d; break;
                        }
                    }
                    if (DumpToOutput)
                    {
                        outlines.Add(lines[i]);
                        if (lines[i].Contains("LNData"))
                        {
                            log.AddString(String.Format(" heh"));
                        }
                        if (lines[i][0] == '%')
                        {
                            int starti = i;
                            if (lines[i].Length == 1)
                            {
                                i++;
                            }
                            while (lines[i][lines[i].Length - 1] != '%')
                            {
                                if (i > starti)
                                {
                                    outlines.Add(lines[i]);
                                }
                                i++;
                            }
                            if (i > starti)
                            {
                                outlines.Add(lines[i]);
                            }
                        }
                    }
                    else
                    {
                        bool translate = true;
                        if (CoordinateFormat.Relativemode)
                        {
                            translate = false;
                        }
                        if (GS.Has("X") == false && GS.Has("Y") == false && (GS.Has("D") && GS.Get("D") < 10))
                        {
                            PureD = true;
                            int Dcode = (int)GS.Get("D");
                            if (Dcode == 1 || Dcode == 3)
                            {
                                if (moveswritten == 0)
                                {
                                    WriteMove = true;
                                }
                            }
                            moveswritten++;
                            //log.AddString(String.Format("Pure D Code: {0}", lines[i]));
                        }
                        else
                        if (GS.Has("X") || GS.Has("Y") || (GS.Has("D") && GS.Get("D") < 10))
                        {
                            int Dcode = (int)GS.Get("D");
                            if (Dcode == 1 || Dcode == 3)
                            {
                                if (moveswritten == 0)
                                {
                                    WriteMove = true;
                                }
                            }
                            moveswritten++;
                            double X = LastX;
                            if (GS.Has("X"))
                            {
                                X = GS.Get("X");
                            }
                            double Y = LastY;
                            if (GS.Has("Y"))
                            {
                                Y = GS.Get("Y");
                            }
                            LastX = X;
                            LastY = Y;

                            GS.Set("X", X);
                            GS.Set("Y", Y);
                        }
                        if (GS.Get("D") >= 10)
                        {
                            CurrentAperture = (int)GS.Get("D");
                            // Select Aperture;
                        }
                        string hash = subtr.State.Apertures[CurrentAperture].GetApertureHash();
                        if (overlapList.ContainsKey(hash))
                        {
                            overlapList[hash].Item2.Add(new PointD(LastX, LastY));
                        }
                        if (WriteMove)
                        {
                            GerberSplitter GS2 = new GerberSplitter();
                            GS2.Set("D", 2);
                            double X0 = 0;
                            double Y0 = 0;
                            if (overlapList.ContainsKey(hash))
                            {
                                overlapList[hash].Item2.Add(new PointD(0, 0));
                            }
                            //GetTransformedCoord(DX, DY, DXp, DYp, Angle, CA, SA, CoordinateFormat, translate, ref X0, ref Y0);
                            GS2.Set("X", X0);
                            GS2.Set("Y", Y0);
                            WriteMove = false;
                            //                          outlines.Add(GS2.Rebuild(CoordinateFormat));
                        }
                        //                        outlines.Add(GS.Rebuild(CoordinateFormat));
                        if (PureD)
                        {
                            //log.AddString(String.Format("pureD"));
                        }
                    }
                }
            }
            try
            {
                //            List<String> PostProcLines = new List<string>();
                //              foreach (var a in outlines)
                //                {
                //  if (a == "%")
                //    {
                //          PostProcLines[PostProcLines.Count - 1] += "%";
                //        }
                //          else
                //            {
                //                  PostProcLines.Add(a);
                //                }
                //              }
                //                Gerber.WriteAllLines(outputfile, PolyLineSet.SanitizeInputLines(PostProcLines));
            }
            catch (Exception E)
            {
                log.AddString(String.Format(E.Message));
            }
            log.PopActivity();


            return(overlapList);
        }