示例#1
0
 public static List<PointF> CircleToPoints(Aperture ap, double stepangle = DEFAULT_STEPANGLE)
 {
     PointF center = new PointF(
         (float)(ap.border.Left + ap.border.Width / 2.0),
         (float)(ap.border.Top + ap.border.Height / 2.0));
     return CircleToPoints(center, ap.border.Width, stepangle);
 }
示例#2
0
        public Aperture FlipY()
        {
            Aperture a = new Aperture();
            a.border = border;
            foreach (LineF line in lines)
            {
                // leave X alone; swap y about center of rectangle

                PointF ls = line.start;
                PointF le = line.end;

                ls.Y = (border.Height - (ls.Y - border.Top)) + border.Top;
                le.Y = (border.Height - (le.Y - border.Top)) + border.Top;

                a.lines.Add(new LineF(ls, le));
            }
            return a;
        }
示例#3
0
        public Aperture FlipX()
        {
            Aperture a = new Aperture();
            a.border = border;
            foreach (LineF line in lines)
            {
                // leave y alone; swap x about center of rectangle

                PointF ls = line.start;
                PointF le = line.end;

                ls.X = (border.Width - (ls.X - border.Left)) + border.Left;
                le.X = (border.Width - (le.X - border.Left)) + border.Left;

                a.lines.Add(new LineF(ls, le));
            }
            return a;
        }
示例#4
0
 public Aperture clone()
 {
     Aperture a = new Aperture();
     a.border = border;
     a.CircleDiameter = CircleDiameter;
     foreach (LineF line in lines) a.lines.Add(new LineF(line.start, line.end));
     return a;
 }
示例#5
0
        void readDrills(List<string> lines, out List<Aperture> placedAps, ref double maxx, ref double maxy, ref double minx, ref double miny)
        {
            Regex reXYLine = new Regex(@"^X(\d+)Y(\d+)$");
            Regex reFSLA = new Regex(@"%FSLAX(\d)(\d)Y(\d)(\d)\*%");
            Regex reApDef = new Regex(@"T(\d+)C([\d\.]+)$");
            Regex reApGroup = new Regex(@"^T(\d+)$");

            Dictionary<int, Aperture> apertures = new Dictionary<int, Aperture>();
            placedAps = new List<Aperture>();

            int currentAperture = -1;

            PointF pstart = new PointF(0, 0);
            PointF pend = new PointF(0, 0);

            double x, y;
            int d;

            int decimal_x = 4, decimal_y = 4;
            double mul_x = Math.Pow(10, decimal_x);
            double mul_y = Math.Pow(10, decimal_y);

            foreach (string line in lines)
            {
                try
                {
                    // format is 2.4 (CHECK?)

                    Match m = reApDef.Match(line);
                    if (m.Success)
                    {
                        int id = Int32.Parse(m.Groups[1].Captures[0].Value);
                        double diam = Double.Parse(m.Groups[2].Captures[0].Value) * INMM;
                        Aperture apCircle = new Aperture(diam, diam);
                        apCircle.CircleDiameter = (float)(diam);
                        apertures.Add(id, apCircle);

                        // ... it seems like some software doesn't bother with groups; it
                        // just defines the drill, then lists coordinates.  we can live with
                        // that, I guess.  not sure if it's legal.

                        currentAperture = id;
                    }

                    m = reApGroup.Match(line);
                    if (m.Success)
                    {
                        currentAperture = Int32.Parse(m.Groups[1].Captures[0].Value);
                        if (!apertures.ContainsKey(currentAperture))
                        {
                            throw new Exception("Don't have a definition for DRILL " + currentAperture + "!");
                        }
                    }

                    m = reFSLA.Match(line);
                    if (m.Success)
                    {
                        Group group = m.Groups[2];
                        CaptureCollection cc = group.Captures;
                        decimal_x = Int32.Parse(cc[0].Value);

                        group = m.Groups[4];
                        cc = group.Captures;
                        decimal_y = Int32.Parse(cc[0].Value);
                        mul_x = Math.Pow(10, decimal_x);
                        mul_y = Math.Pow(10, decimal_y);

                    }

                    m = reXYLine.Match(line);
                    if (m.Success)
                    {
                        if (currentAperture == -1)
                        {
                            throw new Exception("Not in a DRILL group!");
                        }

                        x = Double.Parse(m.Groups[1].Captures[0].Value) / mul_x * INMM; //* dscale;
                        y = Double.Parse(m.Groups[2].Captures[0].Value) / mul_y * INMM; //* dscale;

                        // are these centers or corners?
                        // A: looks like centers.  do the offset
                        // when you create the apertures.

                        if (INVERT_X) x = (maxx + minx - x);
                        if (INVERT_Y) y = (maxy + miny - y);

                        Aperture ap = apertures[currentAperture].clone();
                        ap.OffsetToCenter(x, y);
                        placedAps.Add(ap);

                        //if (ap.CircleDiameter > 0) MessageBox.Show("Placed circle!");

                    }
                }
                catch { }

            }
        }
示例#6
0
        void readApertures(List<string> lines, out List<Aperture> placedAps, out List<LineF> lineList, ref double maxx, ref double maxy, ref double minx, ref double miny)
        {
            Regex reXYLine = new Regex(@"^X(\d+)Y(\d+)D(\d\d)\*$");
            Regex reFSLA = new Regex(@"%FSLAX(\d)(\d)Y(\d)(\d)\*%");
            Regex reApDef = new Regex(@"%ADD(\d+)R,([\d\.]+)X([\d\.]+)\*%");
            Regex reCircleDef = new Regex(@"%ADD(\d+)C,([\d\.]+)\*%");
            Regex reOctoDef = new Regex(@"%ADD(\d+)OC8,([\d\.]+)\*%");
            Regex reApGroup = new Regex(@"^D(\d+)\*$");

            Dictionary<int, Aperture> apertures = new Dictionary<int, Aperture>();
            placedAps = new List<Aperture>();
            lineList = new List<LineF>();

            int currentAperture = -1;

            PointF pstart = new PointF(0, 0);
            PointF pend = new PointF(0, 0);

            double x, y;
            int d;

            int decimal_x = 4, decimal_y = 4;
            double mul_x = Math.Pow(10, decimal_x);
            double mul_y = Math.Pow(10, decimal_y);

            foreach (string line in lines)
            {
                try
                {
                    // format is 2.4 (CHECK?)

                    Match m = reApDef.Match(line);
                    if (m.Success)
                    {
                        int id = Int32.Parse(m.Groups[1].Captures[0].Value);
                        double width = Double.Parse(m.Groups[2].Captures[0].Value) * INMM;
                        double height = Double.Parse(m.Groups[3].Captures[0].Value) * INMM;
                        apertures.Add(id, new Aperture(width, height));

                        //Console.WriteLine("add ap " + id);

                    }

                    m = reCircleDef.Match(line);
                    if (m.Success)
                    {
                        int id = Int32.Parse(m.Groups[1].Captures[0].Value);
                        double diam = Double.Parse(m.Groups[2].Captures[0].Value) * INMM;
                        Aperture apCircle = new Aperture(diam, diam);
                        apCircle.CircleDiameter = (float)(diam);
                        apertures.Add(id, apCircle);

                        //Console.WriteLine("add circle " + id);

                    }

                    m = reOctoDef.Match(line);
                    if (m.Success)
                    {
                        int id = Int32.Parse(m.Groups[1].Captures[0].Value);
                        double diam = Double.Parse(m.Groups[2].Captures[0].Value) * INMM;
                        Aperture apCircle = new Aperture(diam, diam);
                        apCircle.CircleDiameter = (float)(diam);
                        apertures.Add(id, apCircle);

                        //Console.WriteLine("add (octo) circle " + id);

                    }

                    m = reApGroup.Match(line);
                    if (m.Success)
                    {
                        currentAperture = Int32.Parse(m.Groups[1].Captures[0].Value);
                        if (!apertures.ContainsKey(currentAperture))
                        {
                            throw new Exception("Don't have a definition for aperture " + currentAperture + "!");
                        }
                    }

                    m = reFSLA.Match(line);
                    if (m.Success)
                    {
                        Group group = m.Groups[2];
                        CaptureCollection cc = group.Captures;
                        decimal_x = Int32.Parse(cc[0].Value);

                        group = m.Groups[4];
                        cc = group.Captures;
                        decimal_y = Int32.Parse(cc[0].Value);
                        mul_x = Math.Pow(10, decimal_x);
                        mul_y = Math.Pow(10, decimal_y);

                    }

                    m = reXYLine.Match(line);
                    if (m.Success)
                    {
                        if (currentAperture == -1)
                        {
                            throw new Exception("Not in an aperture group!");
                        }

                        x = Double.Parse(m.Groups[1].Captures[0].Value) / mul_x * INMM; //* dscale;
                        y = Double.Parse(m.Groups[2].Captures[0].Value) / mul_y * INMM; //* dscale;
                        d = Int32.Parse(m.Groups[3].Captures[0].Value);

                        switch (d)
                        {
                            case 1:
                            case 2:
                                if (apertures[currentAperture].CircleDiameter < 0)
                                {
                                    throw new Exception("Dragging non-circle");
                                }
                                else
                                {
                                    Group group = m.Groups[1];
                                    CaptureCollection cc = group.Captures;
                                    x = Double.Parse(cc[0].Value) / mul_x * INMM;

                                    if (INVERT_X) x = maxx + minx - x;

                                    group = m.Groups[2];
                                    cc = group.Captures;
                                    y = Double.Parse(cc[0].Value) / mul_y * INMM;

                                    if (INVERT_Y) y = maxy + miny - y;

                                    group = m.Groups[3];
                                    cc = group.Captures;
                                    d = Int32.Parse(cc[0].Value);

                                    // D02 is move...
                                    if (d == 2) pstart = new PointF((float)(x), (float)(y));

                                    // D01 is line...
                                    else if (d == 1)
                                    {
                                        pend = new PointF((float)(x), (float)(y));
                                        //pointList.Add(new PointF[] { pstart, pend });
                                        LineF newline = new LineF(pstart, pend);
                                        newline.width = apertures[currentAperture].CircleDiameter;
                                        lineList.Add(newline);

                                        pstart = pend;
                                    }
                                }
                                break;

                            case 3:
                                {
                                    // are these centers or corners?
                                    // A: looks like centers.  do the offset
                                    // when you create the apertures.

                                    if (INVERT_X) x = (maxx + minx - x);
                                    if (INVERT_Y) y = (maxy + miny - y);

                                    Aperture ap = apertures[currentAperture].clone();
                                    ap.OffsetToCenter(x, y);
                                    placedAps.Add(ap);

                                    //if (ap.CircleDiameter > 0) MessageBox.Show("Placed circle!");

                                }
                                break;
                            default:
                                throw new Exception(string.Format("D{0:00} in cream file!", d));
                        }

                    }
                }
                catch { }

            }
        }