Ejemplo n.º 1
0
        public void Eat(Circle e)
        {
            x0 = Math.Min(x0, e.x - e.r);
            y0 = Math.Min(y0, e.y - e.r);

            x1 = Math.Max(x1, e.x + e.r);
            y1 = Math.Max(y1, e.y + e.r);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            if (args.Length < 4) {
                Console.Error.WriteLine("dxf2bmp input.dxf output.bmp cx cy ");
                Environment.Exit(1);
            }
            using (StreamReader rr = new StreamReader(args[0], Encoding.Default)) {
                IEater eater = null;
                List<IEater> al = new List<IEater>();
                while (true) {
                    String row0 = rr.ReadLine();
                    String row1 = rr.ReadLine();
                    int ty;
                    if (row1 == null || !int.TryParse(row0.Trim(), out ty))
                        break;
                    if (ty == 0) {
                        if (false) { }
                        else if (row1 == "LINE") al.Add(eater = new Line());
                        else if (row1 == "CIRCLE") al.Add(eater = new Circle());
                        else eater = null;
                    }
                    else if (eater != null) {
                        eater.Eat(ty, row1);
                    }
                }

                BBox bbox = new BBox();
                {
                    foreach (var q in al.Where(p => p is Line).Cast<Line>()) bbox.Eat(q);
                    foreach (var q in al.Where(p => p is Circle).Cast<Circle>()) bbox.Eat(q);
                }

                bbox.InflateRate(0.02f, 0.02f);

                using (Bitmap pic = new Bitmap(int.Parse(args[2]), int.Parse(args[3]))) {
                    using (Graphics cv = Graphics.FromImage(pic)) {
                        cv.TranslateTransform(0, pic.Height);
                        cv.ScaleTransform(1, -1);

                        cv.SmoothingMode = SmoothingMode.HighQuality;

                        CBox cb = new CBox(pic.Width, pic.Height, bbox);

                        cv.Clear(Color.White);

                        foreach (IEater eat in al) {
                            if (eat is Line) {
                                Line t = (Line)eat;
                                cv.DrawLine(
                                    new Pen(t.color),
                                    (float)cb.X(t.x0),
                                    (float)cb.Y(t.y0),
                                    (float)cb.X(t.x1),
                                    (float)cb.Y(t.y1)
                                    );
                            }
                            else if (eat is Circle) {
                                Circle t = (Circle)eat;
                                cv.DrawEllipse(
                                    Pens.Black,
                                    RectangleF.FromLTRB(
                                        (float)cb.X(t.x - t.r),
                                        (float)cb.Y(t.y - t.r),
                                        (float)cb.X(t.x + t.r),
                                        (float)cb.Y(t.y + t.r)
                                    )
                                    );
                            }
                        }

            #if false
                        cv.FillRectangle(
                            new LinearGradientBrush(new Point(0, 0), new Point(pic.Width, pic.Height), Color.Black, Color.Gray),
                            new RectangleF(PointF.Empty, pic.Size)
                            );
                        cv.DrawString(
                            "A DXF thumbnail",
                            new Font(FontFamily.GenericSerif, 8),
                            Brushes.WhiteSmoke,
                            new RectangleF(PointF.Empty, pic.Size)
                            );
            #endif
                    }
                    pic.Save(args[1], System.Drawing.Imaging.ImageFormat.Bmp);
                }
            }
        }