Exemplo n.º 1
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            drag = false;

            if (e.Button == MouseButtons.Left && this.ZoomMultiple > 0)
            {
                SelectDefect.Clear();
                SelectGoodDie.Clear();

                //if (locX > 0 || locY > 0)
                //    GetCurrentDefect(new Point(e.X + locX, e.Y + locY));
                //else
                //    GetCurrentDefect(new Point(e.X + locStartX, e.Y + locStartY));

                if ((((e.X - locX - this.mousedownpoint.X) / this.ZoomMultiple) + ((e.Y - locY - this.mousedownpoint.Y) / this.ZoomMultiple)) > 12)
                {
                    //选中的good die
                    foreach (var die in DieLayoutList)
                    {
                        if (!die.IsDefect & die.Points[0].X <= (e.X) / this.ZoomMultiple & die.Points[2].X >= this.mousedownpoint.X / this.ZoomMultiple
                            & die.Points[0].Y <= (e.Y) / this.ZoomMultiple & die.Points[2].Y >= this.mousedownpoint.Y / this.ZoomMultiple)
                        {
                            SelectGoodDie.Add(die.X + "," + die.Y);
                        }
                    }

                    //if (SelectGoodDie.Count > 0)
                    //    DefectChanged(new EventDefectArg() { Location = SelectGoodDie[0].ToString() });
                    foreach (var defect in DefectList)
                    {
                        if (defect.Points[0].X <= (e.X) / this.ZoomMultiple & defect.Points[2].X >= this.mousedownpoint.X / this.ZoomMultiple
                            & defect.Points[0].Y <= (e.Y) / this.ZoomMultiple & defect.Points[2].Y >= this.mousedownpoint.Y / this.ZoomMultiple)
                        {
                            SelectDefect.Add(defect.Location);
                        }
                    }

                    if (SelectDefect.Count > 0)
                    {
                        DefectChanged(new EventDefectArg()
                        {
                            Location = SelectDefect[0].ToString()
                        });
                    }
                    else if (SelectGoodDie.Count > 0)
                    {
                        this.CurrentDefect = SelectGoodDie[0].ToString();
                        ReDraw();
                    }
                }
                else
                {
                    //MessageBox.Show(e.X.ToString()+","+e.Y.ToString());

                    GetCurrentDefect(new Point((int)(e.X / this.ZoomMultiple), (int)(e.Y / this.ZoomMultiple)));
                }
            }

            base.OnMouseUp(e);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取选中缺陷的位置
        /// </summary>
        /// <param name="polygon"></param>
        /// <param name="start"></param>
        /// <returns></returns>
        private string GetCurrentDefect(Point start)
        {
            var location = string.Empty;

            //根据偏移量计算坐标
            //start.X = Convert.ToInt32(start.X * scaleX);
            //start.Y = Convert.ToInt32(start.Y * scaleY);
            if (DefectList == null)
            {
                return(location);
            }

            var index = DefectList.FindIndex(s => s.Points.IsPointInPolygon(start));

            if (index > -1)
            {
                location = DefectList[index].Location;

                SelectDefect.Add(location);

                if (CurrentDefect != location)
                {
                    DefectChanged(new EventDefectArg()
                    {
                        Location = location
                    });
                }

                CurrentDefect = location;
            }
            else
            {
                index = DieLayoutList.FindIndex(s => s.Points.IsPointInPolygon(start));

                if (index > -1)
                {
                    location = DieLayoutList[index].X + "," + DieLayoutList[index].Y;

                    SelectGoodDie.Add(location);

                    if (CurrentDefect != location)
                    {
                        CurrentDefect = location;
                        ReDraw();
                    }
                }
            }

            return(location);
        }