Esempio n. 1
0
        //------------------------------------------------------------------------------------------------
        private void frmSec_Load(object sender, EventArgs e)
        {
            this.MouseWheel += new MouseEventHandler(this.frmSec_MouseWheel);

            OpenFileDialog ofg = new OpenFileDialog();

            ofg.Title            = "Load .sec";
            ofg.Filter           = "Sec files (*.sec)|*.sec";
            ofg.FilterIndex      = 0;
            ofg.RestoreDirectory = true;

            if (ofg.ShowDialog() == DialogResult.OK)
            {
                geo     = new GeoTopology(ofg.FileName);
                display = new DisplayTopology(geo);
                pf      = new PathFinder(display);
                GenerateSketch();

                w = null;
                s = d = null;
            }
            else
            {
                Close();
            }

            Activate();            //很有效!
        }
Esempio n. 2
0
        //-----------------------------------------------------------------------------------------------
        public DisplayTopology(GeoTopology geo)
        {
            this.geo = geo;

            num_points  = geo.num_points;
            num_borders = geo.num_borders;
            num_polys   = geo.num_polys;
            num_xpolys  = geo.num_xpolys;

            //------------------------------------------------------------------------------
            points = new FPoint[num_points];
            for (int i = 0; i < num_points; i++)
            {
                FPoint dst = new FPoint();
                FPoint src = geo.points[i];

                //dst.idx = src.idx;

                dst.x     = src.x;
                dst.y     = src.y;
                points[i] = dst;
            }

            //------------------------------------------------------------------------------
            borders = new Border[num_borders];
            for (int i = 0; i < num_borders; i++)
            {
                Border dst = new Border();
                Border src = geo.borders[i];

                dst.from_idx = src.from_idx;
                dst.to_idx   = src.to_idx;

                dst.from = points[dst.from_idx];
                dst.to   = points[dst.to_idx];

                dst.belong_poly   = src.belong_poly;
                dst.neighbor_poly = src.neighbor_poly;

                borders[i] = dst;
            }

            //------------------------------------------------------------------------------
            polys = new Polygon[num_polys];
            for (int i = 0; i < num_polys; i++)
            {
                Polygon dst = new Polygon();
                Polygon src = geo.polys[i];

                dst.idx = src.idx;

                dst.num_borders = src.num_borders;
                dst.tanX        = src.tanX;
                dst.tanY        = src.tanY;
                dst.M           = src.M;
                dst.attributes  = (byte[])src.attributes.Clone();
                dst.not_sure    = (byte[])src.not_sure.Clone();

                dst.minx = src.minx; dst.miny = src.miny; dst.minz = src.minz;
                dst.maxx = src.maxx; dst.maxy = src.maxy; dst.maxz = src.maxz;

                dst.border_idxs = new int[dst.num_borders];
                dst.borders     = new Border[dst.num_borders];
                for (int j = 0; j < dst.num_borders; j++)
                {
                    dst.border_idxs[j] = src.border_idxs[j];
                    dst.borders[j]     = borders[dst.border_idxs[j]];
                }

                dst.enterable = src.enterable;

                polys[i] = dst;
            }

            //------------------------------------------------------------------------------
            num_X_grids = geo.num_X_grids;
            num_Y_grids = geo.num_Y_grids;

            grids = new Grid[num_Y_grids, num_X_grids];
            for (int y = 0; y < num_Y_grids; y++)
            {
                for (int x = 0; x < num_X_grids; x++)
                {
                    Grid src = geo.grids[y, x];
                    Grid dst = new Grid();

                    dst.num_polys = src.num_polys;
                    dst.poly_idxs = (int[])src.poly_idxs.Clone();

                    dst.polygons = new Polygon[dst.num_polys];
                    for (int i = 0; i < dst.num_polys; i++)
                    {
                        dst.polygons[i] = polys[dst.poly_idxs[i]];
                    }

                    grids[y, x] = dst;
                }
            }

            NormalizeAllPoints();

            ValidateSecData();
        }
Esempio n. 3
0
        //------------------------------------------------------------------------------------------------
        private void frmSec_KeyPress(object sender, KeyPressEventArgs e)
        {
            switch (e.KeyChar)
            {
            case 'z':
                if (zoom + 0.25 <= 16)
                {
                    zoom += 0.25F;
                }
                break;

            case 'x':
                if (zoom - 0.25 > 0.5)
                {
                    zoom -= 0.25F;
                }
                break;

            case 'd':
                show_idx = !show_idx;
                break;

            case 'g':
                show_grids = !show_grids;
                Refresh();
                return;

            case 'f':
            case (char)13:
                full_screen = !full_screen;
                if (full_screen)
                {
                    WindowState     = FormWindowState.Normal;
                    FormBorderStyle = FormBorderStyle.None;
                    WindowState     = FormWindowState.Maximized;
                }
                else
                {
                    FormBorderStyle = FormBorderStyle.Sizable;
                    WindowState     = FormWindowState.Normal;
                }

                UpdateMapping();                         //更新映射!
                Refresh();
                return;

            case '.':
                selected = (selected + 1) % display.num_polys;
                Refresh();
                return;

            case ',':
                if (selected == -1)
                {
                    selected = display.num_polys - 1;
                }
                else
                {
                    selected  = (selected - 1) + display.num_polys;
                    selected %= display.num_polys;
                }
                Refresh();
                return;

            case 'q':
            case (char)27:
                Close();
                return;

            case 'l':
                OpenFileDialog ofg = new OpenFileDialog();

                ofg.Title            = "Load .sec";
                ofg.Filter           = "Sec files (*.sec)|*.sec";
                ofg.FilterIndex      = 0;
                ofg.RestoreDirectory = true;

                if (ofg.ShowDialog() == DialogResult.OK)
                {
                    geo     = new GeoTopology(ofg.FileName);
                    display = new DisplayTopology(geo);
                    pf      = new PathFinder(display);

                    selected = -1;
                    zoom     = 3.5F;

                    GenerateSketch();

                    w = null;
                    s = d = null;

                    Refresh();
                }

                return;

            case 's':
                SaveFileDialog sfg = new SaveFileDialog();

                sfg.Title            = "Save to PNG";
                sfg.Filter           = "PNG files (*.png)|*.png";
                sfg.FilterIndex      = 0;
                sfg.RestoreDirectory = true;

                if (sfg.ShowDialog() == DialogResult.OK)
                {
                    bmp.Save(sfg.FileName, ImageFormat.Png);
                }
                return;

            case 'm':
                SaveFileDialog msfg = new SaveFileDialog();
                msfg.Title            = "Save to EMF";
                msfg.Filter           = "EMF files (*.emf)|*.emf";
                msfg.FilterIndex      = 0;
                msfg.RestoreDirectory = true;

                if (msfg.ShowDialog() == DialogResult.OK)
                {
                    using (Graphics refg = this.CreateGraphics())
                        using (Metafile meta = new Metafile(msfg.FileName, refg.GetHdc(), EmfType.EmfPlusDual))                         //如果用EmfType.EmfPlusOnly则尺寸骤减,但不便控制尺寸
                            using (Graphics g = Graphics.FromImage(meta))
                            {
                                Matrix2D trans = new Matrix2D(1, 0, 0, -1, 0, display.maxy);                        //Y翻转
                                trans.Scale(1 / zoom, 1 / zoom, MatrixOrder.Append);

                                display.DrawSketch(g, 1 / zoom, show_idx, colored);
                                if (show_grids)
                                {
                                    display.DisplayGrids(g, trans, 1 / zoom);
                                }
                                display.DisplaySelectedPolygon(g, trans, selected);
                                if (w != null)
                                {
                                    display.DisplayWaypoints(g, trans, w);
                                }
                            }
                }
                return;

            case 't':
                w = pf.PathFinding(s, d);
                Refresh();
                return;

            case 'r':
                delta.X = delta.Y = 0;
                UpdateMapping();
                Refresh();
                return;

            case 'c':
                colored = !colored;
                break;

            case 'o':
                LOS lost = new LOS(display);

                if (s == null || d == null)
                {
                    return;
                }

                //FPoint st = display.polys[246].borders[0].from;
                //Vector2 n = lost.GetV2(st, d);
                //Vector2 n=lost.GetV2FromBorder(display.polys[254].borders[1]);
                //Vector2 n = new Vector2(0, 1);

                //n.Normalize();

                lost.LOS_Engine(s, d);

                //lost.LOS_Engine(st, n);

                losw = lost.lfp;
                Refresh();
                return;

            default:
                return;
            }
            if (geo != null)
            {
                GenerateSketch();
                Refresh();
            }
        }