/// <summary>
        /// Write *.RGN file contents into a string
        /// </summary>
        /// <param name="design"></param>
        /// <returns>String ready to be written into a file</returns>
        public string Write(PcbDesign design)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            design.SynchronizeUnits(PcbUnits.Thou);
            design.SynchronizeCoordinateUnits(PcbUnits.TenNanometers);
            StringBuilder res = new StringBuilder(Signature);

            res.AppendFormat(Header, this[design.CoordinateUnits]);
            StringBuilder temp = new StringBuilder();

            //Objects (pads and graphics)
            foreach (var item in design.Pads)
            {
                try
                {
                    temp.AppendFormat(PadInObjects, item.Number,
                                      string.Format(this[item.Style.Shape],
                                                    item.Style.Dimension1 + (item.Layer == PcbLayer.Drill ? 10 : 0), //10 thou ring for drill holes (ARES7 does not support Dim1=Dim2)
                                                    item.Style.Drill > 0 ? item.Style.Drill : item.Style.Dimension2),
                                      this[item.Layer], item.X, item.Y, item.Flags ?? StandardPadFlags);
                }
                catch (NotImplementedException e)
                {
                    WarningListener.Add(e);
                }
            }
            foreach (var item in design.Graphics)
            {
                foreach (var line in item.Lines)
                {
                    try
                    {
                        temp.AppendFormat(GraphicsLineInObjects, this[item.Layer], line.Start.X, line.Start.Y, line.End.X, line.End.Y);
                    }
                    catch (NotImplementedException e)
                    {
                        WarningListener.Add(e);
                    }
                }
            }
            res.AppendFormat(Objects, temp.ToString().TrimEnd(Environment.NewLine.ToCharArray()));
            temp.Clear();
            //Vias
            res.AppendFormat(Vias, "");
            //Layers and traces
            var layers = design.GetLayers(true);

            foreach (var item in layers)
            {
                var objects = design.GetObjectsFromLayer(item, true).Cast <PcbTrace>();
                foreach (var trace in objects)
                {
                    temp.AppendFormat(TraceInLayer, trace.Thickness, trace.Segments,
                                      string.Join(" ", trace.XY.ToList().Select(x => string.Format("{0} {1}", x.X, x.Y))));
                }
                res.AppendFormat(Layer, this[item], temp.ToString().TrimEnd(Environment.NewLine.ToCharArray()));
            }

            return(res.ToString());
        }
        private static PcbDesign PADSToPcbDesign(PcbUnits coordinateUnits,Partdecal decal)
        {
            PcbDesign res = new PcbDesign();

            //Partdecal
            try
            {
                if (decal != null)
                {
                    ProcessDecalPieces(res,coordinateUnits,decal);
                    ProcessDecalPads(res,coordinateUnits,decal);
                }
            }
            catch (Exception e)
            {
                WarningListener.Add(e);
            }

            //Others are not implemented yet

            //Header info
            res.SynchronizeCoordinateUnits(coordinateUnits);
            return(res);
        }