예제 #1
0
        protected static void Process(StreamReader filestream)
        {
            int i = 0;
            //filestream.ReadLine(); filestream.ReadLine();
            Document Doc = TFlex.Application.ActiveDocument;

            NFGetGeom.Doc = Doc;

            Page p = new Page(Doc);

            p.Name             = "NFResult";
            p.FontStyle.Italic = true;

            int    contour_count = 0;
            string line          = "";

            string[]   split;
            NFPolyline Poly = new NFPolyline();

            double y_offset = 0;



            do
            {
                line  = filestream.ReadLine();
                split = line.Split(' ');
                bool   processing = false;
                double first_x    = -1.337;
                double first_y    = -1.337;

                if (line != null && split.Length == 2)
                {
                    processing = true;
                    contour_count++;
                    NFGetGeom.Msg("Contour: " + contour_count);

                    do
                    {
                        line  = filestream.ReadLine();
                        split = line.Split(' ');

                        if (split.Length > 1)
                        {
                            if (split.Length == 3)
                            {
                                int bulge = 0;
                                Int32.TryParse(split[2].ToString(), out bulge);
                                NFGetGeom.Msg(line);

                                double x = 0, y = 0;
                                Double.TryParse(split[0].ToString().Replace('.', ','), out x);
                                Double.TryParse(split[1].ToString().Replace('.', ','), out y);

                                if (contour_count == 1)
                                {
                                    y_offset = Math.Max(y_offset, y);
                                }
                                else
                                {
                                    y = y_offset - y;
                                }

                                if (first_x == -1.337)
                                {
                                    first_x = x;
                                    first_y = y;
                                }
                                Poly.AddPoint(x, y);
                            }

                            if (split.Length == 5)
                            {
                                NFGetGeom.Msg("ARC: " + line);
                                double x = 0, y = 0, radius = 0, ang1 = 0, ang2 = 0;
                                Double.TryParse(split[0].ToString().Replace('.', ','), out x);
                                Double.TryParse(split[1].ToString().Replace('.', ','), out y);
                                Double.TryParse(split[2].ToString().Replace('.', ','), out radius);
                                Double.TryParse(split[3].ToString().Replace('.', ','), out ang1);
                                Double.TryParse(split[4].ToString().Replace('.', ','), out ang2);
                                radius = radius / 2;

                                double x1 = Math.Cos(-ang1 / 180 * Math.PI) * radius + x + radius;
                                double y1 = Math.Sin(-ang1 / 180 * Math.PI) * radius + y + radius;

                                double x2 = Math.Cos((-ang1 - ang2 / 2) / 180 * Math.PI) * radius + x + radius;
                                double y2 = Math.Sin((-ang1 - ang2 / 2) / 180 * Math.PI) * radius + y + radius;

                                double x3 = Math.Cos((-ang1 - ang2) / 180 * Math.PI) * radius + x + radius;
                                double y3 = Math.Sin((-ang1 - ang2) / 180 * Math.PI) * radius + y + radius;

                                y1 = y_offset - y1;
                                y2 = y_offset - y2;
                                y3 = y_offset - y3;

                                FreeNode fn1 = new FreeNode(Doc, x1, y1);
                                FreeNode fn2 = new FreeNode(Doc, x2, y2);
                                FreeNode fn3 = new FreeNode(Doc, x3, y3);

                                if (first_x == -1.337)
                                {
                                    first_x = x1;
                                    first_y = y1;
                                }

                                if (Poly.count > 0)
                                {
                                    Poly.AddPoint(x1, y1);
                                    Poly.Draw(Doc, p);
                                    Poly = new NFPolyline();
                                }
                                Poly.AddPoint(x3, y3);
                                ThreePointArcOutline Arc = new ThreePointArcOutline(Doc, fn1, fn2, fn3);
                                Arc.Page = p;
                            }
                        }
                    } while (line != null & split.Length > 1);
                }

                if (processing & Poly.count > 0)
                {
                    NFGetGeom.Msg("INIT POLYLINE");
                    Poly.AddPoint(first_x, first_y);
                    Poly.Draw(Doc, p);
                    Poly = new NFPolyline();
                }
                if (filestream.EndOfStream)
                {
                    break;
                }
            } while (true);
        }
예제 #2
0
        protected static void Process(StreamReader filestream)
        {
            Document Doc = TFlex.Application.ActiveDocument;

            NFUtils.Doc = Doc;

            Page p = new Page(Doc);

            p.Name             = "NFResult";
            p.FontStyle.Italic = true;

            int        contour_count = 0;
            string     line          = "";
            NFPolyline Poly          = new NFPolyline();

            double y_offset = 0;

            do
            {
                line = filestream.ReadLine();
                var    split      = line.Split(' ').ToList();
                bool   processing = false;
                double?firstX     = null;
                double?firstY     = null;

                if (line != null && split.Count == 2)
                {
                    processing = true;
                    contour_count++;
                    NFUtils.Msg("Contour: " + contour_count);

                    do
                    {
                        line  = filestream.ReadLine();
                        split = line.Split(' ').ToList();

                        if (split.Count > 1)
                        {
                            if (split.Count == 3)
                            {
                                int bulge;
                                int.TryParse(split[2], out bulge);
                                NFUtils.Msg(line);

                                double x, y;
                                double.TryParse(split[0].Replace('.', ','), out x);
                                double.TryParse(split[1].Replace('.', ','), out y);

                                if (contour_count == 1)
                                {
                                    y_offset = Math.Max(y_offset, y);
                                }
                                else
                                {
                                    y = y_offset - y;
                                }

                                if (firstX == null)
                                {
                                    firstX = x;
                                    firstY = y;
                                }
                                Poly.AddPoint(x, y);
                            }

                            if (split.Count == 5)
                            {
                                NFUtils.Msg($"ARC: {line}");
                                double x, y, radius, ang1, ang2;
                                double.TryParse(split[0].Replace('.', ','), out x);
                                double.TryParse(split[1].Replace('.', ','), out y);
                                double.TryParse(split[2].Replace('.', ','), out radius);
                                double.TryParse(split[3].Replace('.', ','), out ang1);
                                double.TryParse(split[4].Replace('.', ','), out ang2);
                                radius = radius / 2;

                                double x1 = Math.Cos(-ang1 / 180 * Math.PI) * radius + x + radius;
                                double y1 = Math.Sin(-ang1 / 180 * Math.PI) * radius + y + radius;

                                double x2 = Math.Cos((-ang1 - ang2 / 2) / 180 * Math.PI) * radius + x + radius;
                                double y2 = Math.Sin((-ang1 - ang2 / 2) / 180 * Math.PI) * radius + y + radius;

                                double x3 = Math.Cos((-ang1 - ang2) / 180 * Math.PI) * radius + x + radius;
                                double y3 = Math.Sin((-ang1 - ang2) / 180 * Math.PI) * radius + y + radius;

                                y1 = y_offset - y1;
                                y2 = y_offset - y2;
                                y3 = y_offset - y3;

                                FreeNode fn1 = new FreeNode(Doc, x1, y1);
                                FreeNode fn2 = new FreeNode(Doc, x2, y2);
                                FreeNode fn3 = new FreeNode(Doc, x3, y3);

                                if (firstX == null)
                                {
                                    firstX = x1;
                                    firstY = y1;
                                }

                                if (Poly.count > 0)
                                {
                                    Poly.AddPoint(x1, y1);
                                    Poly.Draw(Doc, p);
                                    Poly = new NFPolyline();
                                }
                                Poly.AddPoint(x3, y3);
                                ThreePointArcOutline Arc = new ThreePointArcOutline(Doc, fn1, fn2, fn3);
                                Arc.Page = p;
                            }
                        }
                    } while (line != null & split.Count > 1);
                }

                if (processing & Poly.count > 0)
                {
                    NFUtils.Msg("INIT POLYLINE");
                    Poly.AddPoint(firstX ?? 0, firstY ?? 0);
                    Poly.Draw(Doc, p);
                    Poly = new NFPolyline();
                }
                if (filestream.EndOfStream)
                {
                    break;
                }
            } while (true);
        }