Esempio n. 1
0
        private static void ConvertFile(string a, bool back)
        {
            string basename = a.Substring(0, a.Length - 4);

            string png     = basename + "Silk.png";
            string goldpng = basename + "Gold.png";

            if (back)
            {
                png     = basename + "BottomSilk.png";
                goldpng = basename + "BottomGold.png";
            }

            Bitmap B  = (Bitmap)Image.FromFile(png);
            Bitmap B2 = null;

            if (System.IO.File.Exists(goldpng))
            {
                B2 = (Bitmap)Image.FromFile(goldpng);
            }

            try
            {
                System.IO.Directory.CreateDirectory(basename);
            }
            catch (Exception)
            {
            }

            string newa = basename + "\\" + System.IO.Path.GetFileName(a);;
            string gko  = basename + ".gko";
            string pnl  = basename + ".pnl";

            if (System.IO.File.Exists(gko) == false && System.IO.File.Exists(pnl) == true)
            {
                gko = pnl;
            }

            string newgko = basename + "\\" + System.IO.Path.GetFileNameWithoutExtension(a) + ".gko";;

            if (System.IO.File.Exists(gko))
            {
                System.IO.File.Copy(gko, newgko, true);
            }

            System.IO.File.Copy(a, newa, true);
            a = newa;

            string p = basename + "/topsilk.gto";

            if (back)
            {
                p = basename + "/bottomsilk.gbo";
            }
            if (back)
            {
                B.RotateFlip(RotateFlipType.RotateNoneFlipX);
            }
            B.RotateFlip(RotateFlipType.RotateNoneFlipY);
            if (B2 != null)
            {
                B2.RotateFlip(RotateFlipType.RotateNoneFlipY);
            }
            if (B != null)
            {
                double Res = 200.0 / 25.4;

                ParsedGerber PLS = null;
                string       f   = basename + ".gko";
                if (System.IO.File.Exists(f))
                {
                    int polyid = 0;
                    PLS = PolyLineSet.LoadGerberFile(f);


                    string bottomcopper     = basename + "/bottomcopper.gbl";
                    string topcopper        = basename + "/topcopper.gtl";
                    string bottomsoldermask = basename + "/bottomsoldermask.gbs";
                    string topsoldermask    = basename + "/topsoldermask.gts";
                    string bottomsilk       = basename + "/bottomsilk.gbo";
                    if (back)
                    {
                        bottomsilk = basename + "/topsilk.gto";
                    }
                    GerberArtWriter GAW3 = new GerberLibrary.GerberArtWriter();
                    GAW3.Write(topsoldermask);

                    GerberArtWriter GAW = new GerberLibrary.GerberArtWriter();
                    PolyLine        PL  = new PolyLine(polyid++);
                    PL.Add(PLS.BoundingBox.TopLeft.X, PLS.BoundingBox.TopLeft.Y);
                    PL.Add(PLS.BoundingBox.BottomRight.X, PLS.BoundingBox.TopLeft.Y);
                    PL.Add(PLS.BoundingBox.BottomRight.X, PLS.BoundingBox.TopLeft.Y + 8);
                    PL.Add(PLS.BoundingBox.TopLeft.X, PLS.BoundingBox.TopLeft.Y + 8);
                    GAW.AddPolygon(PL);


                    PolyLine PL3 = new PolyLine(polyid++);
                    PL3.Add(PLS.BoundingBox.TopLeft.X, PLS.BoundingBox.BottomRight.Y - 8);
                    PL3.Add(PLS.BoundingBox.BottomRight.X, PLS.BoundingBox.BottomRight.Y - 8);
                    PL3.Add(PLS.BoundingBox.BottomRight.X, PLS.BoundingBox.BottomRight.Y);
                    PL3.Add(PLS.BoundingBox.TopLeft.X, PLS.BoundingBox.BottomRight.Y);
                    GAW.AddPolygon(PL3);

                    GAW.Write(bottomsoldermask);


                    GerberArtWriter GAW2 = new GerberLibrary.GerberArtWriter();
                    PolyLine        PL2  = new PolyLine(polyid++);
                    PL2.Add(PLS.BoundingBox.TopLeft.X, PLS.BoundingBox.TopLeft.Y);
                    PL2.Add(PLS.BoundingBox.BottomRight.X, PLS.BoundingBox.TopLeft.Y);
                    PL2.Add(PLS.BoundingBox.BottomRight.X, PLS.BoundingBox.BottomRight.Y);
                    PL2.Add(PLS.BoundingBox.TopLeft.X, PLS.BoundingBox.BottomRight.Y);
                    GAW2.AddPolygon(PL2);
                    GAW2.Write(bottomcopper);

                    if (B2 != null)
                    {
                        GerberLibrary.ArtWork.Functions.WriteBitmapToGerber(topcopper, PLS, Res, B2, -128);
                        GerberLibrary.ArtWork.Functions.WriteBitmapToGerber(topsoldermask, PLS, Res, B2, -128);
                    }
                    else
                    {
                        GAW2.Write(topcopper);
                    }
                }

                GerberLibrary.ArtWork.Functions.WriteBitmapToGerber(p, PLS, Res, B, -128);
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            GerberLibrary.GerberPanel GP = new GerberLibrary.GerberPanel();
            PanelSettings             S  = new PanelSettings();

            string SettingsFile = "";
            string InputFile    = "";

            if (args.Count() < 2)
            {
                Console.WriteLine("Usage:");
                Console.WriteLine("AutoPanelBuilder.exe  [--settings {file}]");
                Console.WriteLine("\t[--files {filewithfolders}]");
                Console.WriteLine("\t[--dumpsample]");
                Console.WriteLine("\toutput_directory");

                return;
            }

            Arguments NextArg = Arguments.None;

            for (int i = 0; i < args.Count() - 1; i++)
            {
                switch (NextArg)
                {
                case Arguments.SettingsFile: SettingsFile = args[i]; NextArg = Arguments.None; break;

                case Arguments.InputList: InputFile = args[i]; NextArg = Arguments.None; break;

                case Arguments.None:
                    switch (args[i].ToLower())
                    {
                    case "--settings": NextArg = Arguments.SettingsFile; break;

                    case "--files": NextArg = Arguments.InputList; break;

                    case "--dumpsample":
                    {
                        XmlSerializer SerializerObj   = new XmlSerializer(typeof(PanelSettings));
                        TextWriter    WriteFileStream = new StreamWriter("SettingDump.xml");
                        SerializerObj.Serialize(WriteFileStream, S);
                        WriteFileStream.Close();
                    }
                    break;
                    }
                    break;
                }
            }

            if (SettingsFile.Length > 0)
            {
                XmlSerializer SettingsSerialize = new XmlSerializer(typeof(PanelSettings));
                FileStream    ReadFileStream    = null;
                try
                {
                    ReadFileStream = new FileStream(SettingsFile, FileMode.Open, FileAccess.Read, FileShare.Read);

                    // Load the object saved above by using the Deserialize function
                    PanelSettings newset = (PanelSettings)SettingsSerialize.Deserialize(ReadFileStream);
                    if (newset != null)
                    {
                        S = newset;
                    }
                }
                catch (Exception)
                {
                }
            }

            if (InputFile.Length > 0)
            {
                foreach (var a in File.ReadAllLines(InputFile))
                {
                    var A = GP.AddGerberFolder(new StandardConsoleLog(), a);
                    GP.AddInstance(a, new GerberLibrary.Core.Primitives.PointD(0, 0));
                }
            }

            GP.TheSet.Width  = S.Width;
            GP.TheSet.Height = S.Height;
            GP.TheSet.MarginBetweenBoards      = S.MarginBetweenBoards;
            GP.TheSet.ConstructNegativePolygon = S.ConstructNegativePolygon;
            GP.TheSet.FillOffset            = S.FillOffset;
            GP.TheSet.Smoothing             = S.Smoothing;
            GP.TheSet.ExtraTabDrillDistance = S.ExtraTabDrillDistance;

            if (GP.MaxRectPack(GerberLibrary.MaxRectPacker.FreeRectChoiceHeuristic.RectBestAreaFit, 0, true))
            {
                GerberLibrary.GerberArtWriter GAW2 = new GerberLibrary.GerberArtWriter();
                GerberLibrary.GerberArtWriter GAW  = new GerberLibrary.GerberArtWriter();

                GP.BuildAutoTabs(new StandardConsoleLog(), GAW, GAW2);


                string basepath = args[args.Count() - 1];
                Directory.CreateDirectory(Path.Combine(basepath, "output"));
                GP.SaveFile(Path.Combine(basepath, "panel.gerberset"));
                GP.SaveOutlineTo(basepath, "paneloutline", new StandardConsoleLog());

                GAW.Write(Path.Combine(basepath, "delaunay.gbr"));
                GAW2.Write(Path.Combine(basepath, "points.gbr"));
                //    Console.ReadKey();
            }
        }