Exemple #1
0
        public void LoadLayer(string fileName)
        {
            string[] lines = File.ReadAllLines(fileName);



            for (int i = 0; i < lines.Length; i++)
            {
                //Debug.WriteLine("Parsing Line: " + i);
                string s = lines[i].ToUpper();

                if (s.Contains("%ADD"))
                {
                    string index      = s.SubstringToNonDigit(4);
                    int    commaIndex = lines[i].IndexOf(',');
                    char   code       = s[commaIndex - 1];
                    string size       = lines[i].Substring(commaIndex + 1, s.Length - commaIndex - 3);

                    if (code == 'C')
                    {
                        //ConvertToMM(toks[1], FormatString, IsMetric);
                        //float sizeMM = Convert.ToSingle(size) * 25.4f;
                        float          sizeMM = ConvertToMM(size, IsMetric);
                        ApertureCircle ac     = new ApertureCircle {
                            Index = Convert.ToInt32(index), R = sizeMM / 2
                        };
                        Apertures.Add(ac);
                        //Debug.WriteLine(string.Format("Added Circle Aperture {0}", ac));
                    }
                    else if (code == 'R')
                    {
                        string[] sizes = size.Split('X');
                        //float sizeXMM = Convert.ToSingle(sizes[0]) * 25.4f;
                        //float sizeYMM = Convert.ToSingle(sizes[1]) * 25.4f;
                        float             sizeXMM = ConvertToMM(sizes[0], IsMetric);
                        float             sizeYMM = ConvertToMM(sizes[1], IsMetric);
                        ApertureRectangle ar      = new ApertureRectangle {
                            Index = Convert.ToInt32(index), Width = sizeXMM, Height = sizeYMM
                        };
                        Apertures.Add(ar);
                        //Debug.WriteLine(string.Format("Added Rect App {0}", ar));
                    }
                }
                else if (s.Contains("%FS"))
                {
                    FormatString = s;
                }
                else if (s.Contains("%MOIN"))
                {
                    IsMetric = false;
                }
                else if (s[0] == 'D')
                {
                    // Process aperature change
                    //int index = Convert.ToInt32( s.Substring(1, 2) );
                    int index = Convert.ToInt32(s.SubstringToNonDigit(1));
                    try
                    {
                        CurrentAperature = Apertures.First(o => o.Index == index);
                    }
                    catch
                    {
                    }
                }
                else if (s[0] == 'X' || s[0] == 'Y')
                {
                    OldX = CurrX;
                    OldY = CurrY;

                    string[] toks      = s.Split(new char[] { 'X', 'Y', 'D' });
                    string   operation = s.Substring(s.Length - 3, 2);

                    if (s[0] == 'X')
                    {
                        CurrX = ConvertToMM(toks[1], FormatString, IsMetric);

                        if (toks.Length == 4)
                        {
                            //CurrY = Convert.ToSingle(toks[2]) / 1000;
                            CurrY = ConvertToMM(toks[2], FormatString, IsMetric);
                        }
                    }
                    else if (s[0] == 'Y')
                    {
                        CurrY = ConvertToMM(toks[1], FormatString, IsMetric);
                    }

                    if (operation == "D1")
                    {
                        // Linear interp
                        OpInterp oi = new OpInterp {
                            Code = 1, Aperture = CurrentAperature, X = CurrX, Y = CurrY, X0 = OldX, Y0 = OldY
                        };
                        Ops.Add(oi);
                        //Debug.WriteLine("Added OpLin X:{0} Y:{1} X:{2} Y:{3} Aperture:{4}", CurrX, CurrY, OldX, OldY, CurrentAperature);
                    }
                    else if (operation == "D2")
                    {
                        // Move only. Nothing created
                    }
                    else if (operation == "D3")
                    {
                        // Flash operation
                        Op op = new Op {
                            Code = 3, Aperture = CurrentAperature, X = CurrX, Y = CurrY
                        };
                        Ops.Add(op);
                        //Debug.WriteLine("Added OpFlash @ {0}, {1} Aperture: {2}", CurrX, CurrY, CurrentAperature);
                    }
                }
            }
        }
Exemple #2
0
        public Bitmap Draw(Color c, bool drawInterpCircles, Bitmap bmp, PointF centerMM, float widthMM)
        {
            using (Graphics g = Graphics.FromImage(bmp))
            {
                // Brush for all our drawing. The pen will be created based on line width
                Brush b = new SolidBrush(c);

                float dotsXPerMM = g.DpiX / 25.4f; // Compute native dots per mm resolution
                float dotsYPerMM = g.DpiY / 25.4f;
                float heightMM   = ((float)bmp.Height / (float)bmp.Width) * widthMM;
                float zoom       = bmp.Width / widthMM;

                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.TranslateTransform((-centerMM.X + widthMM / 2) * zoom, (-centerMM.Y + heightMM / 2) * zoom);
                g.ScaleTransform(zoom, zoom);

                //Horz and vert cross hair
                g.DrawLine(Pens.Red, centerMM.X - widthMM / 10, centerMM.Y, centerMM.X + widthMM / 10, centerMM.Y);
                g.DrawLine(Pens.Red, centerMM.X, centerMM.Y - widthMM / 10, centerMM.X, centerMM.Y + widthMM / 10);

                for (int i = 0; i < Ops.Count; i++)
                {
                    if ((Ops[i] is OpInterp) && (Ops[i].Aperture is ApertureRectangle))
                    {
                        // Interpolated rectangular aperture. These aren't generally used at all
                        if (false)
                        {
                            OpInterp          obj     = (OpInterp)Ops[i];
                            ApertureRectangle rectApp = (ApertureRectangle)Ops[i].Aperture;

                            if (obj.X0 == obj.X)
                            {
                                // Vert interp
                            }
                            else if (obj.Y0 == obj.Y)
                            {
                                // Horz interp
                                for (float x = obj.X; x <= obj.X0; x += (rectApp.Width - rectApp.Width * 0.1f))
                                {
                                    GerberGraphics.Rectangle(g, b, x, obj.Y, rectApp.Width, rectApp.Height);
                                }
                            }
                        }
                    }
                    else if ((Ops[i] is OpInterp) && (Ops[i].Aperture is ApertureCircle))
                    {
                        // Interpolated circular aperture. These are typically used for drawing traces and silk
                        if (drawInterpCircles)
                        {
                            OpInterp       obj = (OpInterp)Ops[i];
                            ApertureCircle ac  = (ApertureCircle)Ops[i].Aperture;

                            Pen p = new Pen(c, ac.R * 2);
                            GerberGraphics.Line(g, p, obj.X, obj.Y, obj.X0, obj.Y0);
                            p.Dispose();

                            if (obj.X0 == obj.X)
                            {
                                // Vert interp
                            }
                            else if (obj.Y0 == obj.Y)
                            {
                                // Horz interp
                            }
                        }
                    }
                    else if (Ops[i].Code == 3)
                    {
                        // Flash operation
                        if (Ops[i].Aperture is ApertureRectangle)
                        {
                            GerberGraphics.Rectangle(g, b, Ops[i].X, Ops[i].Y, (Ops[i].Aperture as ApertureRectangle).Width, (Ops[i].Aperture as ApertureRectangle).Height);
                        }
                        else if (Ops[i].Aperture is ApertureCircle)
                        {
                            // Only draw circles above a certain size as the smaller ones are likely vias
                            if ((Ops[i].Aperture as ApertureCircle).R > 0.5)
                            {
                                GerberGraphics.Circle(g, b, Ops[i].X, Ops[i].Y, (Ops[i].Aperture as ApertureCircle).R);
                            }
                        }
                    }
                }
            }

            //bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
            return(bmp);
        }