Пример #1
0
        }//update方法——重绘

        public static void Update(Graphics g, int Width, int Height, int i = 1)
        {
            Point pt = new Point();

            foreach (Realpoint rpt in MyGlo.rplist)
            {//实体点
                pt    = Funcs.CoorTransform(rpt.Map_X, rpt.Map_Y, Width, Height);
                pt.X += MyGlo.mouse_now_position.X - MyGlo.mouse_down_position[0] + MyGlo.offset[0];
                pt.Y += MyGlo.mouse_now_position.Y - MyGlo.mouse_down_position[1] + MyGlo.offset[1];
                Funcs.Draw(g, pt.X, pt.Y, Width, Height, rpt);
            }

            foreach (Notepoint npt in MyGlo.nplist)
            {//注记点
                pt    = Funcs.CoorTransform(npt.Map_X, npt.Map_Y, Width, Height);
                pt.X += MyGlo.mouse_now_position.X - MyGlo.mouse_down_position[0] + MyGlo.offset[0];
                pt.Y += MyGlo.mouse_now_position.Y - MyGlo.mouse_down_position[1] + MyGlo.offset[1];
                Funcs.Draw(g, pt.X, pt.Y, Width, Height, npt);
            }

            foreach (var lineshape in MyGlo.llist)
            {//线面
                List <Point> ptlist = new List <Point>();
                foreach (Linkpoint lpt in lineshape.CoorList)
                {//关联点
                    pt    = Funcs.CoorTransform(lpt.Map_X, lpt.Map_Y, Width, Height);
                    pt.X += MyGlo.mouse_now_position.X - MyGlo.mouse_down_position[0] + MyGlo.offset[0];
                    pt.Y += MyGlo.mouse_now_position.Y - MyGlo.mouse_down_position[1] + MyGlo.offset[1];
                    Funcs.Draw(g, pt.X, pt.Y, Width, Height, lpt);
                    ptlist.Add(pt);
                }
                Funcs.Draw(ptlist, g, lineshape.LineSize, Convert.ToInt32(lineshape.ID[1]) - 48, lineshape); //这里'1'是49
            }
        }//if
Пример #2
0
        public static object choice(int x, int y, int width, int height)
        {//是否被选中
            foreach (var rpt in MyGlo.rplist)
            {
                Point temp_p = Funcs.CoorTransform(rpt.Map_X, rpt.Map_Y, width, height);
                if (Math.Pow(x - temp_p.X, 2) + Math.Pow(y - temp_p.Y, 2) <= 25)
                {
                    return(rpt);
                }
            }

            foreach (var npt in MyGlo.nplist)
            {
                Point temp_p = CoorTransform(npt.Map_X, npt.Map_Y, width, height);
                if (Math.Pow(x - temp_p.X, 2) + Math.Pow(y - temp_p.Y, 2) <= 25)
                {
                    return(npt);
                }
            }

            foreach (var line in MyGlo.llist)
            {
                for (int i = 0; i < line.CoorList.Count - 1; i++)
                {
                    Point p1 = CoorTransform(line.CoorList[i].Map_X, line.CoorList[i].Map_Y, width, height);
                    Point p2 = CoorTransform(line.CoorList[i + 1].Map_X, line.CoorList[i + 1].Map_Y, width, height);
                    if ((x <= p1.X + 6 && x >= p2.X - 6 && y <= p1.Y + 6 && y >= p2.Y - 6) || (x >= p1.X - 6 && x <= p2.X + 6 && y <= p2.Y - 6 && y >= p1.Y + 6) ||
                        (x >= p1.X + 6 && x <= p2.X - 6 && y >= p2.Y + 6 && y <= p1.Y - 6) || (x <= p1.X - 6 && x >= p2.X + 6 && y <= p2.Y - 6 && y >= p1.Y + 6))
                    {
                        float dis = DouglasPeuker.Distance(x, y, p1.X, p1.Y, p2.X, p2.Y);
                        if (dis <= 5)
                        {
                            return(line);
                        }
                    }
                }
                if (line.ID[1] == '3')
                {
                    Point p1 = CoorTransform(line.CoorList[0].Map_X, line.CoorList[0].Map_Y, width, height);
                    Point p2 = CoorTransform(line.CoorList[line.CoorList.Count - 1].Map_X, line.CoorList[line.CoorList.Count - 1].Map_Y, width, height);
                    if ((x <= p1.X + 6 && x >= p2.X - 6 && y <= p1.Y + 6 && y >= p2.Y - 6) || (x >= p1.X - 6 && x <= p2.X + 6 && y <= p2.Y - 6 && y >= p1.Y + 6) ||
                        (x >= p1.X + 6 && x <= p2.X - 6 && y >= p2.Y + 6 && y <= p1.Y - 6) || (x <= p1.X - 6 && x >= p2.X + 6 && y <= p2.Y - 6 && y >= p1.Y + 6))
                    {
                        float dis = DouglasPeuker.Distance(x, y, p1.X, p1.Y, p2.X, p2.Y);
                        if (dis <= 5)
                        {
                            return(line);
                        }
                    }
                }
            }

            return(null);
        }
Пример #3
0
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            try
            {
                //距离量测
                if (bool_cul == true)
                {
                    if (bool_dis == true)
                    {
                        p        = pictureBox1.PointToClient(MousePosition);
                        bool_dis = false;
                    }
                    else
                    {
                        Point  p2  = pictureBox1.PointToClient(MousePosition);
                        object obj = Funcs.choice(p2.X, p2.Y, pictureBox1.Width, pictureBox1.Height);
                        if (obj == null)
                        {
                            float d = DouglasPeuker.Distance(p2.X, p2.Y, p.X, p.Y);
                            MessageBox.Show("未选中目标,鼠标两点地理距离为:" + (d / MyGlo.scale).ToString("F4"), "距离显示:");
                            NoActive();
                        }
                        else
                        {
                            if (obj is Realpoint)
                            {
                                Point temp_p;
                                temp_p = Funcs.CoorTransform((obj as Realpoint).Map_X, (obj as Realpoint).Map_Y, pictureBox1.Width, pictureBox1.Height);
                                float d = DouglasPeuker.Distance(p.X, p.Y, temp_p.X, temp_p.Y);
                                MessageBox.Show("选中实体点,鼠标两点地理距离为:" + (d / MyGlo.scale).ToString("F4"), "距离显示:");
                                NoActive();
                            }
                            else if (obj is Notepoint)
                            {
                                Point temp_p;
                                temp_p = Funcs.CoorTransform((obj as Notepoint).Map_X, (obj as Notepoint).Map_Y, pictureBox1.Width, pictureBox1.Height);
                                float d = DouglasPeuker.Distance(p.X, p.Y, temp_p.X, temp_p.Y);
                                MessageBox.Show("选中注记点,鼠标两点地理距离为:" + (d / MyGlo.scale).ToString("F4"), "距离显示:");
                                NoActive();
                            }
                            else if (obj is Lineshape)
                            {
                                if ((obj as Lineshape).ID[0] == 'l' && (obj as Lineshape).ID[1] == '1' && (obj as Lineshape).CoorList.Count == 2)
                                {
                                    if ((p.X <= (obj as Lineshape).CoorList[0].Map_X && p.X >= (obj as Lineshape).CoorList[1].Map_X &&
                                         p.Y <= (obj as Lineshape).CoorList[0].Map_Y && p.Y >= (obj as Lineshape).CoorList[1].Map_Y) ||
                                        (p.X >= (obj as Lineshape).CoorList[0].Map_X && p.X <= (obj as Lineshape).CoorList[1].Map_X &&
                                         p.Y <= (obj as Lineshape).CoorList[1].Map_Y && p.Y >= (obj as Lineshape).CoorList[0].Map_Y) ||
                                        (p.X >= (obj as Lineshape).CoorList[0].Map_X && p.X <= (obj as Lineshape).CoorList[1].Map_X &&
                                         p.Y >= (obj as Lineshape).CoorList[1].Map_Y && p.Y <= (obj as Lineshape).CoorList[0].Map_Y) ||
                                        (p.X <= (obj as Lineshape).CoorList[0].Map_X && p.X >= (obj as Lineshape).CoorList[1].Map_X &&
                                         p.Y <= (obj as Lineshape).CoorList[1].Map_Y && p.Y >= (obj as Lineshape).CoorList[0].Map_Y))
                                    {
                                        Point temp_p1, temp_p2;
                                        temp_p1 = Funcs.CoorTransform((obj as Lineshape).CoorList[0].Map_X, (obj as Lineshape).CoorList[0].Map_Y, pictureBox1.Width, pictureBox1.Height);
                                        temp_p2 = Funcs.CoorTransform((obj as Lineshape).CoorList[1].Map_X, (obj as Lineshape).CoorList[1].Map_Y, pictureBox1.Width, pictureBox1.Height);
                                        float d = DouglasPeuker.Distance(p.X, p.Y, temp_p1.X, temp_p1.Y, temp_p2.X, temp_p2.Y);
                                        MessageBox.Show("选中直线,点到地理距离为:" + (d / MyGlo.scale).ToString("F4"), "距离显示:");
                                        NoActive();
                                    }
                                    else
                                    {
                                        Point temp_p1, temp_p2;
                                        temp_p1 = Funcs.CoorTransform((obj as Lineshape).CoorList[0].Map_X, (obj as Lineshape).CoorList[0].Map_Y, pictureBox1.Width, pictureBox1.Height);
                                        temp_p2 = Funcs.CoorTransform((obj as Lineshape).CoorList[1].Map_X, (obj as Lineshape).CoorList[1].Map_Y, pictureBox1.Width, pictureBox1.Height);
                                        float d = Math.Min(DouglasPeuker.Distance(p.X, p.Y, temp_p1.X, temp_p1.Y), DouglasPeuker.Distance(p.X, p.Y, temp_p2.X, temp_p2.Y));
                                        MessageBox.Show("选中直线,点到地理距离为:" + (d / MyGlo.scale).ToString("F4"), "距离显示:");
                                        NoActive();
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("暂不支持曲线/面和多点线/面,请选择两点直线段,如果想求点到多段线的最小距离可以使用点线关系工具", "提示");
                                    NoActive();
                                }
                            }
                        }
                    }
                }

                //点点关系,写的看不下去,可使用basepoint简化
                if (bool_dd == true)
                {
                    Point p2 = pictureBox1.PointToClient(MousePosition);
                    if (o == null)
                    {
                        o = Funcs.choice(p2.X, p2.Y, (pictureBox1 as PictureBox).Width, (pictureBox1 as PictureBox).Height);
                    }
                    else if (o is Realpoint || o is Notepoint)
                    {
                        Funcs.Rdd(o, pictureBox1, p2);
                        NoActive();
                    }
                    else
                    {
                        MessageBox.Show("请选择两点");
                        NoActive();
                    }
                }

                //点线关系
                if (bool_dx == true)
                {
                    Point p2 = pictureBox1.PointToClient(MousePosition);
                    if (o == null)
                    {
                        o = Funcs.choice(p2.X, p2.Y, (pictureBox1 as PictureBox).Width, (pictureBox1 as PictureBox).Height);
                    }
                    else if (o is Realpoint || o is Notepoint)
                    {
                        Funcs.Rdx(o, pictureBox1, p2);
                        NoActive();
                    }
                    else
                    {
                        MessageBox.Show("请选择一点和一条直线");
                        NoActive();
                    }
                }

                //点面关系
                if (bool_dm == true)
                {
                    Point p2 = pictureBox1.PointToClient(MousePosition);
                    if (o == null)
                    {
                        o = Funcs.choice(p2.X, p2.Y, (pictureBox1 as PictureBox).Width, (pictureBox1 as PictureBox).Height);
                    }
                    else if (o is Realpoint || o is Notepoint)
                    {
                        Funcs.Rdm(o, pictureBox1, p2);
                        NoActive();
                    }
                    else
                    {
                        MessageBox.Show("请选择一点和一直线面");
                        NoActive();
                    }
                }

                //删除对象
                if (bool_del == true)
                {
                    Point  p2  = pictureBox1.PointToClient(MousePosition);
                    object obj = Funcs.choice(p2.X, p2.Y, pictureBox1.Width, pictureBox1.Height);
                    Funcs.Del(obj, pictureBox1);
                    NoActive();
                    this.Cursor = Cursors.Default;
                }

                //符号绘制
                if (fuhao1 == true)
                {
                    Graphics g = pictureBox1.CreateGraphics();
                    Funcs.Daoxiandian(g, pictureBox1.PointToClient(MousePosition).X, pictureBox1.PointToClient(MousePosition).Y, pictureBox1.Width, pictureBox1.Height);
                    NoActive();
                }
                if (fuhao2 == true)
                {
                    Graphics g = pictureBox1.CreateGraphics();
                    Funcs.Jiaotang(g, pictureBox1.PointToClient(MousePosition).X, pictureBox1.PointToClient(MousePosition).Y, pictureBox1.Width, pictureBox1.Height);
                    NoActive();
                }
            }
            catch
            {
                MessageBox.Show("未知错误");
            }
        }