Exemplo n.º 1
0
        //鼠标移动
        private void imageRobot_PreviewMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            //获取当前坐标
            Point nowPoint = e.GetPosition(gridDraw);

            MapOperate.NowPoint = nowPoint;
            //显示当前坐标到界面
            MapOperate.ViewInfo.View = new Point(Math.Round(nowPoint.X, 0), Math.Round(nowPoint.Y, 0));
            //计算左键按下移动偏差
            MapOperate.mouseLeftBtnDownMoveDiff.X = nowPoint.X - MapOperate.mouseLeftBtnDownToMap.X;
            MapOperate.mouseLeftBtnDownMoveDiff.Y = nowPoint.Y - MapOperate.mouseLeftBtnDownToMap.Y;
            //判断左键按下后是否发生移动
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                if (MapOperate.mouseLeftBtnDownToMap.X != nowPoint.X ||
                    MapOperate.mouseLeftBtnDownToMap.Y != nowPoint.Y)
                {
                    //标记左键按下移动状态【是否按住左键移动过】
                    MapOperate.MovedAfterLeftBtn = true;
                }
            }

            //移动视图【如果右键按下】
            if (e.RightButton == MouseButtonState.Pressed)
            {
                System.Windows.Point position  = e.GetPosition(cvMap);
                System.Windows.Point position1 = e.GetPosition(drawViewScroll);

                tlt.X += (position.X - MapOperate.mouseRightBtnDownPoint.X) * MapOperate.ViewInfo.Scale;
                tlt.Y += (position.Y - MapOperate.mouseRightBtnDownPoint.Y) * MapOperate.ViewInfo.Scale;

                //更新圆点坐标,保留两位小数
                MapOperate.ViewInfo.Origin = new Point(Math.Round(tlt.X, 0), Math.Round(tlt.Y, 0));
            }

            //编辑单个元素
            if (MapOperate.NowMode == MapOperate.EnumMode.EditElement)
            {
                //左键按住移动位置【调整元素位置】
                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    //左键按下后,鼠标不移动也会进入移动事件,
                    //导致如果点击的位置不是中心,标签会动一下,
                    //很不美好,所以加坐标比较,没有变化就不进行移动
                    if (MapOperate.MovedAfterLeftBtn == false)
                    {
                        return;
                    }
                    if (MapOperate.NowSelectIndex != -1)
                    {
                        //移动标签
                        if (MapOperate.NowType == MapOperate.EnumElementType.RFID)
                        {
                            MapFunction.MoveRFIDTo(MapOperate.NowSelectIndex, nowPoint);
                        }
                        else
                        //移动直线
                        if (MapOperate.NowType == MapOperate.EnumElementType.RouteLine)
                        {
                            switch (MapOperate.ElementEditMode)
                            {
                            case MapOperate.EnumElementEditMode.Start:
                                MapFunction.MoveRouteLineStart(MapOperate.NowSelectIndex, nowPoint);
                                break;

                            case MapOperate.EnumElementEditMode.End:
                                MapFunction.MoveRouteLineEnd(MapOperate.NowSelectIndex, nowPoint);
                                break;

                            case MapOperate.EnumElementEditMode.All:
                                MapFunction.MoveRouteLineAll(MapOperate.NowSelectIndex, nowPoint);
                                break;

                            default:
                                break;
                            }
                        }
                        else
                        //移动分叉【圆弧】
                        if (MapOperate.NowType == MapOperate.EnumElementType.RouteForkLine)
                        {
                            switch (MapOperate.ElementEditMode)
                            {
                            case MapOperate.EnumElementEditMode.Start:
                                MapFunction.MoveForkLineStartForAdd(MapOperate.NowSelectIndex, nowPoint);
                                break;

                            case MapOperate.EnumElementEditMode.End:
                                MapFunction.MoveForkLineEnd(MapOperate.NowSelectIndex, nowPoint);
                                break;

                            case MapOperate.EnumElementEditMode.All:
                                MapFunction.MoveForkLineAll(MapOperate.NowSelectIndex, nowPoint);
                                break;

                            default:
                                break;
                            }
                        }
                    }
                }
            }
            else
            //多选模式
            if (MapOperate.NowMode == MapOperate.EnumMode.MultiSelect)
            {
                //绘制选择框
                MapOperate.DrawMultiSelectRect(nowPoint);
            }
            else
            //多编辑模式
            if (MapOperate.NowMode == MapOperate.EnumMode.MultiEdit)
            {
                //如果按住左键,则移动对象
                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    //移动所以选中的元素
                    MapFunction.MoveMultiSelected(nowPoint, MapOperate.MultiSelected);
                }
            }
            else
            //粘贴模式
            if (MapOperate.NowMode == MapOperate.EnumMode.Paste)
            {
                //移动所以选中的元素
                MapFunction.MoveMultiSelected(nowPoint, MapOperate.PastedObject);
            }
            else
            //添加新元素
            if (MapOperate.NowMode == MapOperate.EnumMode.AddElement)
            {
                if (MapOperate.NowType == MapOperate.EnumElementType.RFID)
                {
                    MapFunction.MoveRFIDTo(MapOperate.NowSelectIndex, nowPoint);
                }
                else
                if (MapOperate.NowType == MapOperate.EnumElementType.RouteLine)
                {
                    if (MapOperate.AddStep == 1)
                    {
                        MapFunction.MoveRouteLineStartForAdd(MapOperate.NowSelectIndex, nowPoint);
                    }
                    else
                    {
                        MapFunction.MoveRouteLineEnd(MapOperate.NowSelectIndex, nowPoint);
                    }
                }
                else
                if (MapOperate.NowType == MapOperate.EnumElementType.RouteForkLine)
                {
                    if (MapOperate.AddStep == 1)
                    {
                        MapFunction.MoveForkLineStartForAdd(MapOperate.NowSelectIndex, nowPoint);
                    }
                    else
                    {
                        MapFunction.MoveForkLineEnd(MapOperate.NowSelectIndex, nowPoint);
                    }
                }
            }
        }
Exemplo n.º 2
0
        //左键抬起
        private void imageRobot_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            //记录按下时的位置
            MapOperate.mouseLeftBtnDownToMap = e.GetPosition(cvMap);

            //编辑单个元素
            if (MapOperate.NowMode == MapOperate.EnumMode.EditElement)
            {
                //记录当前状态
                if (MapOperate.MovedAfterLeftBtn)
                {
                    MapOperate.History.AddRecord("编辑单个");
                }
            }
            else
            if (MapOperate.NowMode == MapOperate.EnumMode.MultiEdit)
            {
                //记录当前状态
                if (MapOperate.MovedAfterLeftBtn)
                {
                    MapOperate.History.AddRecord("编辑多个");
                }
            }
            else
            //多选状态
            if (MapOperate.NowMode == MapOperate.EnumMode.MultiSelect)
            {
                //是否按住左键移动过,如果没有移动就不能计算选中
                if (MapOperate.MovedAfterLeftBtn)
                {
                    //清除移动标志
                    MapOperate.MovedAfterLeftBtn = false;
                    //清除选中框
                    MapOperate.ClearMultiSelectRect();
                    //计算选中的元素
                    MapFunction.GetMultiSelectedObject();
                    //如果一个都没有选上,退出多选状态
                    if (MapOperate.MultiSelected.RFIDS.Count == 0 &&
                        MapOperate.MultiSelected.Lines.Count == 0 &&
                        MapOperate.MultiSelected.ForkLines.Count == 0)
                    {
                        //退出多选模式
                        MapOperate.NowMode = MapOperate.EnumMode.EditElement;
                    }
                    else
                    //有选中的就进入多个编辑状态
                    {
                        MapOperate.NowMode = MapOperate.EnumMode.MultiEdit;
                    }
                }
                //没有移动,直接退出多选
                else
                {
                    //恢复单个编辑模式
                    MapOperate.NowMode = MapOperate.EnumMode.EditElement;
                }
            }
            else
            //添加新元素
            if (MapOperate.NowMode == MapOperate.EnumMode.AddElement)
            {
                switch (MapOperate.NowType)
                {
                case MapOperate.EnumElementType.None:
                    break;

                case MapOperate.EnumElementType.RFID:
                    //添加RFID
                {
                    //记录当前状态
                    MapOperate.History.AddRecord("增加RFID");
                    //增加下一个
                    MapOperate.NowSelectIndex = MapElement.AddRFIDAndShow();
                }
                break;

                case MapOperate.EnumElementType.RouteLine:
                    //添加直线
                {
                    //如果是第一步
                    if (MapOperate.AddStep == 1)
                    {
                        //【隐藏编辑器】【隐藏后再添加,避免编辑器出现在线条下发】
                        MapFunction.SetRouteLineIsNormal(MapOperate.NowSelectIndex);
                        //显示直线,并设置起点坐标
                        MapElement.DrawRouteLine(MapOperate.NowSelectIndex, MapOperate.mouseLeftBtnDownToMap);
                        //显示起点编辑器
                        MapElement.RouteLineShowStart(MapOperate.NowSelectIndex);
                        //显示终点编辑器
                        MapElement.RouteLineShowEnd(MapOperate.NowSelectIndex);
                        //进入第二步
                        MapOperate.AddStep = 2;
                    }
                    else
                    if (MapOperate.AddStep == 2)
                    {
                        //直线添加完成【隐藏编辑器】
                        MapFunction.SetRouteLineIsNormal(MapOperate.NowSelectIndex);
                        //记录当前状态
                        MapOperate.History.AddRecord("增加直线");
                        //添加新直线
                        MapOperate.NowSelectIndex = MapElement.AddRouteLine();
                        //显示直线起点编辑器
                        MapElement.RouteLineShowStart(MapOperate.NowSelectIndex);
                        //返回添加直线第一步
                        MapOperate.AddStep = 1;
                    }
                }
                break;

                case MapOperate.EnumElementType.RouteForkLine:
                    //添加分叉线【圆弧】
                {
                    //如果是第一步
                    if (MapOperate.AddStep == 1)
                    {
                        //【隐藏编辑器】【隐藏后再添加,避免编辑器出现在线条下发】
                        MapFunction.SetRouteForkLineIsNormal(MapOperate.NowSelectIndex);
                        //显示分叉【圆弧】,并设置起点坐标
                        MapElement.DrawForkLine(MapOperate.NowSelectIndex, MapOperate.mouseLeftBtnDownToMap);
                        //显示起点编辑器
                        MapElement.ForkLineShowStart(MapOperate.NowSelectIndex);
                        //显示终点编辑器
                        MapElement.ForkLineShowEnd(MapOperate.NowSelectIndex);
                        //进入第二步
                        MapOperate.AddStep = 2;
                    }
                    else
                    if (MapOperate.AddStep == 2)
                    {
                        //直线添加完成【隐藏编辑器】
                        MapFunction.SetRouteForkLineIsNormal(MapOperate.NowSelectIndex);
                        //记录当前状态
                        MapOperate.History.AddRecord("增加分叉");
                        //添加新直线
                        MapOperate.NowSelectIndex = MapElement.AddForkLine();
                        //显示直线起点编辑器
                        MapElement.ForkLineShowStart(MapOperate.NowSelectIndex);
                        //返回添加直线第一步
                        MapOperate.AddStep = 1;
                    }
                }
                break;

                default:
                    break;
                }
            }
        }