Beispiel #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();            //很有效!
        }
Beispiel #2
0
        //===============================================================================================
        public PathFinder(DisplayTopology topology)
        {
            topo  = topology;
            polys = topo.polys;

            open  = new WorkList();
            close = new WorkList();
        }
Beispiel #3
0
 public LOS(DisplayTopology topo)
 {
     this.topo = topo;
     ret       = new ReturnInfo();
 }
Beispiel #4
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();
            }
        }