示例#1
0
 // 选中点的 ODI
 public void AddODI(string key, ObjDrawInfo odi)
 {
     if (!m_ODIs.ContainsKey(key))
     {
         m_ODIs.Add(key, odi);
     }
 }
示例#2
0
        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Middle)
            {
                m_mmbPress           = true;
                this.m_panel1.Cursor = Cursors.Hand;
            }
            else if (e.Button == MouseButtons.Left)
            {
                m_mouseGrabODI   = m_mouseUnderODI;
                m_mouseGrabIsDir = m_mouseUnderIsDir;
                if (m_mouseGrabODI != null && m_mouseGrabIsDir)
                {
                    PointF grabPointF = m_panel1.GetODIClientPos(m_mouseGrabODI);
                    m_startDragDirX = Convert.ToInt32(grabPointF.X);
                    m_startDragDirY = Convert.ToInt32(grabPointF.Y);
                }

                if (this.m_ShiftPress)
                {
                    string strResult = string.Format("{0},{1}", mouse_map_x, mouse_map_y);
                    Clipboard.SetText(strResult);
                }
            }
        }
示例#3
0
        public PointF GetODIClientPos(ObjDrawInfo odi)
        {
            float startscalex = ((1.0f - scale) * image.Width / 2 + start_adjust_x) / image.Width;
            float startscaley = ((1.0f - scale) * image.Height / 2 + start_adjust_y) / image.Height;
            float x           = (odi.pfPos.X - startscalex) * canvasWidth / scale;
            float y           = (odi.pfPos.Y - startscaley) * canvasHeight / scale;

            return(new PointF(x, y));
        }
示例#4
0
        private Point ODI2ClientPoint(ObjDrawInfo odi)
        {
            float startscalex = ((1.0f - this.m_panel1.scale) * this.m_panel1.image.Width / 2 + this.m_panel1.start_adjust_x) / this.m_panel1.image.Width;
            float startscaley = ((1.0f - this.m_panel1.scale) * this.m_panel1.image.Height / 2 + this.m_panel1.start_adjust_y) / this.m_panel1.image.Height;

            int mousex = Convert.ToInt32((odi.pfPos.X - startscalex) * this.m_panel1.canvasWidth / this.m_panel1.scale);
            int mousey = Convert.ToInt32((odi.pfPos.Y - startscaley) * this.m_panel1.canvasHeight / this.m_panel1.scale);

            return(new Point(mousex, mousey));
        }
示例#5
0
        /// <summary>
        /// 重写的绘图方法
        /// </summary>
        /// <param name="e">绘图事件参数</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics dc = e.Graphics;

            if (canvasWidth == 0 || canvasHeight == 0)
            {
                return;
            }

            Bitmap   bufferBMP = new Bitmap(canvasWidth, canvasHeight); // 绘图的缓冲
            Graphics g         = Graphics.FromImage(bufferBMP);

            g.Clear(this.BackColor);
            g.SmoothingMode   = SmoothingMode.HighQuality;   //高质量
            g.PixelOffsetMode = PixelOffsetMode.HighQuality; //高像素偏移质量

            if (image != null)                               // 绘制图片
            {
                RectangleF destRect = new RectangleF(0, 0, canvasWidth, canvasHeight);
                RectangleF srcRect  = new RectangleF((1.0f - scale) * image.Width / 2 + start_adjust_x, (1.0f - scale) * image.Height / 2 + start_adjust_y, image.Width * scale, image.Height * scale);
                g.DrawImage(image, destRect, srcRect, GraphicsUnit.Pixel);

                foreach (DictionaryEntry entry in m_ODIs)
                {
                    ObjDrawInfo odi    = entry.Value as ObjDrawInfo;
                    PointF      pointf = GetODIClientPos(odi);
                    g.DrawEllipse(redPen, pointf.X - 3, pointf.Y - 3, 7, 7);
                    int nDir = (int)(odi.nDir);
                    if ((this.Parent as Preview).m_ShowDir && nDir != -1)
                    {
                        PointF adjustment = GetDirEndAdjustment(nDir);
                        g.DrawLine(redPen, pointf.X, pointf.Y, pointf.X + adjustment.X, pointf.Y + adjustment.Y);
                    }
                    if ((this.Parent as Preview).m_ShowObjName)
                    {
                        LogicObj curObj = odi.lObj;
                        string   strODI = string.Format("{0}[{1}]", curObj.tyPe.ToLower().EndsWith("point") ? "Point" : (curObj.tyPe.ToLower().EndsWith("vertex") ? "Vertex" : curObj.values[0]), curObj.inDex);
                        g.DrawString(strODI, timesFont, yellowBrush, pointf.X + 3, pointf.Y + 7);
                    }
                }
            }

            // 从缓冲中绘制最终图像
            dc.DrawImage(bufferBMP, 0, 0); // g.DrawLine(greenPen, p, p + littileSize);
        }
示例#6
0
文件: Form1.cs 项目: weimingtom/pap2
        private void tree1_AfterSelNodesAdd(object sender, MWPropertyEventArgs e)
        {
            TreeNode node = e.Updated as TreeNode;

            // 显示图片
            ShowMapContainSelectObj(node);

            // 检查是否大分类结点
            if (node.Tag is string)
            {
                return;
            }

            LogicObj lobj = node.Tag as LogicObj;

            if (lobj == null) // 添加一组
            {
                LogicObj onechild = node.Nodes[0].Tag as LogicObj;
                if (onechild != null)
                {
                    foreach (TreeNode n in node.Nodes)
                    {
                        LogicObj oneObj = n.Tag as LogicObj;
                        PointF   pointf = LogicObjPosToImagePointF(oneObj);
                        int      ndir   = LogicObjToDirection(oneObj);
                        if (pointf != PointF.Empty)
                        {
                            ObjDrawInfo odi = new ObjDrawInfo(pointf, ndir, oneObj);
                            this.previewform.m_panel1.AddODI(n.Text, odi);
                        }
                    }
                }
            }
            else // 添加一个
            {
                PointF pointf = LogicObjPosToImagePointF(lobj);
                int    ndir   = LogicObjToDirection(lobj);
                if (pointf != PointF.Empty)
                {
                    ObjDrawInfo odi = new ObjDrawInfo(pointf, ndir, lobj);
                    this.previewform.m_panel1.AddODI(node.Text, odi);
                }
            }
        }
示例#7
0
        private void panel1_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.None)
            {
                this.old_mouse_x = -1;
                this.old_mouse_y = -1;
            }

            if (e.Button == MouseButtons.Middle)
            {
                m_mmbPress           = false;
                this.m_panel1.Cursor = Cursors.Default;
            }
            else if (e.Button == MouseButtons.Left)
            {
                m_mouseGrabODI  = null;
                m_startDragDirX = -1;
                m_startDragDirY = -1;
            }
        }
示例#8
0
        private ObjDrawInfo GetMouseODI(int mousex, int mousey)
        {
            if (this.m_panel1.image == null)
            {
                return(null);
            }

            Point       curMousePoint = new Point(mousex, mousey);
            ObjDrawInfo odiRet        = null;

            foreach (DictionaryEntry entry in this.m_panel1.m_ODIs)
            {
                ObjDrawInfo odi      = entry.Value as ObjDrawInfo;
                Point       pointObj = ODI2ClientPoint(odi);

                if (Helper.PointsAreNear(pointObj, curMousePoint))
                {
                    odiRet            = odi;
                    m_mouseUnderIsDir = false;
                    break;
                }

                if (m_ShowDir)
                {
                    int nDir = (int)(odi.nDir);
                    if (nDir != -1)
                    {
                        PointF adjustment  = m_panel1.GetDirEndAdjustment(nDir);
                        Point  pointDirEnd = new Point(Convert.ToInt32(pointObj.X + adjustment.X), Convert.ToInt32(pointObj.Y + adjustment.Y));
                        if (Helper.PointsAreNear(pointDirEnd, curMousePoint))
                        {
                            odiRet            = odi;
                            m_mouseUnderIsDir = true;
                        }
                    }
                }
            }

            return(odiRet);
        }
示例#9
0
文件: Form1.cs 项目: viticm/pap2
        private void tree1_AfterSelNodesAdd(object sender, MWPropertyEventArgs e)
        {
            TreeNode node = e.Updated as TreeNode;

            // 显示图片
            ShowMapContainSelectObj(node);

            // 检查是否大分类结点
            if (node.Tag is string)
            {
                return;
            }

            LogicObj lobj = node.Tag as LogicObj;
            if (lobj == null) // 添加一组
            {
                LogicObj onechild = node.Nodes[0].Tag as LogicObj;
                if (onechild != null)
                {
                    foreach (TreeNode n in node.Nodes)
                    {
                        LogicObj oneObj = n.Tag as LogicObj;
                        PointF pointf = LogicObjPosToImagePointF(oneObj);
                        int ndir = LogicObjToDirection(oneObj);
                        if (pointf != PointF.Empty)
                        {
                            ObjDrawInfo odi = new ObjDrawInfo(pointf, ndir, oneObj);
                            this.previewform.m_panel1.AddODI(n.Text, odi);
                        }
                    }
                }
            }
            else // 添加一个
            {
                PointF pointf = LogicObjPosToImagePointF(lobj);
                int ndir = LogicObjToDirection(lobj);
                if (pointf != PointF.Empty)
                {
                    ObjDrawInfo odi = new ObjDrawInfo(pointf, ndir, lobj);
                    this.previewform.m_panel1.AddODI(node.Text, odi);
                }
            }
        }
示例#10
0
        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            int deltax = 0;
            int deltay = 0;

            if (e.Button != MouseButtons.None)
            {
                if (old_mouse_x != -1)
                {
                    deltax = e.X - old_mouse_x;
                }
                old_mouse_x = e.X;

                if (old_mouse_y != -1)
                {
                    deltay = e.Y - old_mouse_y;
                }
                old_mouse_y = e.Y;
            }

            bool bNeedRefresh = false;

            if (e.Button == MouseButtons.Middle)
            {
                float deltaxf = deltax / (float)this.m_panel1.CanvasWidth;
                float deltayf = deltay / (float)this.m_panel1.CanvasHeight;

                this.m_panel1.start_adjust_x -= deltaxf * this.m_panel1.image.Width * this.m_panel1.scale;
                this.m_panel1.start_adjust_y -= deltayf * this.m_panel1.image.Height * this.m_panel1.scale;

                bNeedRefresh = true;
            }

            ShowMousePosInfo(e.X, e.Y);

            if (m_mouseGrabODI == null)
            {
                m_mouseUnderODI = GetMouseODI(e.X, e.Y);
                if (m_mouseUnderODI != null)
                {
                    this.m_panel1.Cursor = Cursors.Hand;
                }
                else if (!m_mmbPress)
                {
                    this.m_panel1.Cursor = Cursors.Default;
                }
            }
            else
            {
                if (m_mouseGrabIsDir)
                {
                    int delx = e.X - m_startDragDirX;
                    int dely = m_startDragDirY - e.Y;

                    if (delx == 0)
                    {
                        m_mouseGrabODI.nDir = dely >= 0 ? 64 : 192;
                    }
                    else
                    {
                        if (delx > 0)
                        {
                            if (dely >= 0)
                            {
                                double fdiv  = (double)dely / delx;
                                double angel = Math.Atan(fdiv);
                                m_mouseGrabODI.nDir = Convert.ToInt32(angel * 256 / 2 / Math.PI);
                            }
                            else
                            {
                                double fdiv  = (double)(-dely) / delx;
                                double angel = Math.PI * 2 - Math.Atan(fdiv);
                                m_mouseGrabODI.nDir = Convert.ToInt32(angel * 256 / 2 / Math.PI);
                            }
                        }
                        else
                        {
                            if (dely >= 0)
                            {
                                double fdiv  = (double)dely / (-delx);
                                double angel = Math.PI - Math.Atan(fdiv);
                                m_mouseGrabODI.nDir = Convert.ToInt32(angel * 256 / 2 / Math.PI);
                            }
                            else
                            {
                                double fdiv  = (double)(-dely) / (-delx);
                                double angel = Math.PI + Math.Atan(fdiv);
                                m_mouseGrabODI.nDir = Convert.ToInt32(angel * 256 / 2 / Math.PI);
                            }
                        }

                        if (m_mouseGrabODI.nDir >= 256)
                        {
                            m_mouseGrabODI.nDir = 0;
                        }
                    }

                    bNeedRefresh = true;

                    // 更新内存obj:
                    AdjustObjLogicalDir(m_mouseGrabODI.lObj, m_mouseGrabODI.nDir);
                }
                else
                {
                    float fAdjustX = (float)deltax / this.m_panel1.CanvasWidth;
                    float fAdjustY = (float)deltay / this.m_panel1.CanvasHeight;

                    m_mouseGrabODI.pfPos.X += fAdjustX * this.m_panel1.scale;
                    m_mouseGrabODI.pfPos.Y += fAdjustY * this.m_panel1.scale;
                    bNeedRefresh            = true;

                    // 更新内存obj: 加入落在地图上时,刷新此对象的 vPosition, x, y, z等
                    AdjustObjLogicalPos(m_mouseGrabODI.lObj, new PointF(fAdjustX, fAdjustY));
                }
            }

            if (bNeedRefresh)
            {
                this.Refresh();
            }
        }
示例#11
0
文件: Preview.cs 项目: viticm/pap2
        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Middle)
            {
                m_mmbPress = true;
                this.m_panel1.Cursor = Cursors.Hand;
            }
            else if (e.Button == MouseButtons.Left)
            {
                m_mouseGrabODI = m_mouseUnderODI;
                m_mouseGrabIsDir = m_mouseUnderIsDir;
                if (m_mouseGrabODI != null && m_mouseGrabIsDir)
                {
                    PointF grabPointF = m_panel1.GetODIClientPos(m_mouseGrabODI);
                    m_startDragDirX = Convert.ToInt32(grabPointF.X);
                    m_startDragDirY = Convert.ToInt32(grabPointF.Y);
                }

                if (this.m_ShiftPress)
                {
                    string strResult = string.Format("{0},{1}", mouse_map_x, mouse_map_y);
                    Clipboard.SetText(strResult);
                }
            }
        }
示例#12
0
文件: Preview.cs 项目: viticm/pap2
        private void panel1_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.None)
            {
                this.old_mouse_x = -1;
                this.old_mouse_y = -1;
            }

            if (e.Button == MouseButtons.Middle)
            {
                m_mmbPress = false;
                this.m_panel1.Cursor = Cursors.Default;
            }
            else if (e.Button == MouseButtons.Left)
            {
                m_mouseGrabODI = null;
                m_startDragDirX = -1;
                m_startDragDirY = -1;
            }
        }
示例#13
0
文件: Preview.cs 项目: viticm/pap2
        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            int deltax = 0;
            int deltay = 0;
            if (e.Button != MouseButtons.None)
            {
                if (old_mouse_x != -1)
                {
                    deltax = e.X - old_mouse_x;
                }
                old_mouse_x = e.X;

                if (old_mouse_y != -1)
                {
                    deltay = e.Y - old_mouse_y;
                }
                old_mouse_y = e.Y;
            }

            bool bNeedRefresh = false;
            if (e.Button == MouseButtons.Middle)
            {
                float deltaxf = deltax / (float)this.m_panel1.CanvasWidth;
                float deltayf = deltay / (float)this.m_panel1.CanvasHeight;

                this.m_panel1.start_adjust_x -= deltaxf * this.m_panel1.image.Width * this.m_panel1.scale;
                this.m_panel1.start_adjust_y -= deltayf * this.m_panel1.image.Height * this.m_panel1.scale;

                bNeedRefresh = true;
            }

            ShowMousePosInfo(e.X, e.Y);

            if (m_mouseGrabODI == null)
            {
                m_mouseUnderODI = GetMouseODI(e.X, e.Y);
                if (m_mouseUnderODI != null)
                    this.m_panel1.Cursor = Cursors.Hand;
                else if (!m_mmbPress)
                    this.m_panel1.Cursor = Cursors.Default;
            }
            else
            {
                if (m_mouseGrabIsDir)
                {
                    int delx = e.X - m_startDragDirX;
                    int dely = m_startDragDirY - e.Y;

                    if (delx == 0)
                    {
                        m_mouseGrabODI.nDir = dely >= 0 ? 64 : 192;
                    }
                    else
                    {
                        if (delx > 0)
                        {
                            if (dely >= 0)
                            {
                                double fdiv = (double)dely / delx;
                                double angel = Math.Atan(fdiv);
                                m_mouseGrabODI.nDir = Convert.ToInt32(angel * 256 / 2 / Math.PI);
                            }
                            else
                            {
                                double fdiv = (double)(-dely) / delx;
                                double angel = Math.PI * 2 - Math.Atan(fdiv);
                                m_mouseGrabODI.nDir = Convert.ToInt32(angel * 256 / 2 / Math.PI);
                            }
                        }
                        else
                        {
                            if (dely >= 0)
                            {
                                double fdiv = (double)dely / (-delx);
                                double angel = Math.PI - Math.Atan(fdiv);
                                m_mouseGrabODI.nDir = Convert.ToInt32(angel * 256 / 2 / Math.PI);
                            }
                            else
                            {
                                double fdiv = (double)(-dely) / (-delx);
                                double angel = Math.PI + Math.Atan(fdiv);
                                m_mouseGrabODI.nDir = Convert.ToInt32(angel * 256 / 2 / Math.PI);
                            }
                        }

                        if (m_mouseGrabODI.nDir >= 256)
                            m_mouseGrabODI.nDir = 0;
                    }

                    bNeedRefresh = true;

                    // 更新内存obj:
                    AdjustObjLogicalDir(m_mouseGrabODI.lObj, m_mouseGrabODI.nDir);
                }
                else
                {
                    float fAdjustX = (float)deltax / this.m_panel1.CanvasWidth;
                    float fAdjustY = (float)deltay / this.m_panel1.CanvasHeight;

                    m_mouseGrabODI.pfPos.X += fAdjustX * this.m_panel1.scale;
                    m_mouseGrabODI.pfPos.Y += fAdjustY * this.m_panel1.scale;
                    bNeedRefresh = true;

                    // 更新内存obj: 加入落在地图上时,刷新此对象的 vPosition, x, y, z等
                    AdjustObjLogicalPos(m_mouseGrabODI.lObj, new PointF(fAdjustX, fAdjustY));
                }
            }

            if (bNeedRefresh)
                this.Refresh();
        }
示例#14
0
文件: Preview.cs 项目: viticm/pap2
        private Point ODI2ClientPoint(ObjDrawInfo odi)
        {
            float startscalex = ((1.0f - this.m_panel1.scale) * this.m_panel1.image.Width / 2 + this.m_panel1.start_adjust_x) / this.m_panel1.image.Width;
            float startscaley = ((1.0f - this.m_panel1.scale) * this.m_panel1.image.Height / 2 + this.m_panel1.start_adjust_y) / this.m_panel1.image.Height;

            int mousex = Convert.ToInt32((odi.pfPos.X - startscalex) * this.m_panel1.canvasWidth / this.m_panel1.scale);
            int mousey = Convert.ToInt32((odi.pfPos.Y - startscaley) * this.m_panel1.canvasHeight / this.m_panel1.scale);

            return new Point(mousex, mousey);
        }
示例#15
0
文件: Canvas.cs 项目: viticm/pap2
 public PointF GetODIClientPos(ObjDrawInfo odi)
 {
     float startscalex = ((1.0f - scale) * image.Width / 2 + start_adjust_x) / image.Width;
     float startscaley = ((1.0f - scale) * image.Height / 2 + start_adjust_y) / image.Height;
     float x = (odi.pfPos.X - startscalex) * canvasWidth / scale;
     float y = (odi.pfPos.Y - startscaley) * canvasHeight / scale;
     return new PointF(x, y);
 }
示例#16
0
文件: Canvas.cs 项目: viticm/pap2
 // 选中点的 ODI
 public void AddODI(string key, ObjDrawInfo odi)
 {
     if (!m_ODIs.ContainsKey(key))
         m_ODIs.Add(key, odi);
 }