Ejemplo n.º 1
0
 /// <summary>
 /// 添加一个并显示
 /// </summary>
 /// <param name="canvas">画布对象</param>
 /// <returns>返回该RFID的索引</returns>
 public static int AddForkLine()
 {
     //添加
     MapElement.RouteForkLine line = new MapElement.RouteForkLine();
     line.Num = MapElement.MapObject.ForkLines.Count + 1;
     MapElement.MapObject.ForkLines.Add(line);
     //返回索引
     return(MapElement.MapObject.ForkLines.Count - 1);
 }
Ejemplo n.º 2
0
 public static void ForkLineShowSelect(MapElement.RouteForkLine routeForkLine)
 {
     //同步曲线
     routeForkLine.SelectPath.Data = routeForkLine.Path.Data.Clone();
     //设置为虚线
     routeForkLine.SelectPath.StrokeDashArray = new DoubleCollection()
     {
         3, 5
     };
     //更改颜色
     routeForkLine.SelectPath.Stroke = Brushes.Yellow;
     //同步位置
     routeForkLine.SelectPath.Margin = routeForkLine.Path.Margin;
     //设置线宽
     routeForkLine.SelectPath.StrokeThickness = 1;
     //添加到画板
     MapElement.CvForkLine.Children.Add(routeForkLine.SelectPath);
 }
Ejemplo n.º 3
0
        public static void ForkLineShowEnd(MapElement.RouteForkLine routeForkLine)
        {
            //找到圆弧起点和终点坐标
            PathGeometry pathGeometry = routeForkLine.Path.Data as PathGeometry;
            PathFigure   figure       = pathGeometry.Figures.First();
            ArcSegment   arc          = figure.Segments.First() as ArcSegment;
            //圆弧终点
            Point end = arc.Point;

            end.X += routeForkLine.Path.Margin.Left - MapElement.GridSize / 2;
            end.Y += routeForkLine.Path.Margin.Top - MapElement.GridSize / 2;
            //终点编辑器的位置和圆弧终点坐标同步
            routeForkLine.EndRect.Margin = new Thickness(end.X, end.Y, 0, 0);

            routeForkLine.EndRect.Fill            = CavnvasBase.GetSolid(100, Colors.Pink); //半透明
            routeForkLine.EndRect.StrokeThickness = 0.5;
            routeForkLine.EndRect.Stroke          = Brushes.Gray;
            routeForkLine.EndRect.Width           = MapElement.GridSize;
            routeForkLine.EndRect.Height          = MapElement.GridSize;
            MapElement.CvForkLine.Children.Add(routeForkLine.EndRect);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 绘制单个
 /// </summary>
 public static void ShowForkLine(MapElement.RouteForkLine forkLine)
 {
     MapElement.CvForkLine.Children.Add(forkLine.Path);
 }
Ejemplo n.º 5
0
        private void drawViewScroll_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            //V+F【重置视图】
            if (MapOperate.Userkey.Key == Key.V && e.Key == Key.F)
            {
                RestView();
            }
            else
            //Delete【删除】
            if (e.Key == Key.Delete)
            {
                //编辑单个
                if (MapOperate.NowMode == MapOperate.EnumMode.EditElement)
                {
                    //是否有选中的
                    if (MapOperate.NowSelectIndex != -1)
                    {
                        switch (MapOperate.NowType)
                        {
                        case MapOperate.EnumElementType.None:
                            break;

                        //选中了RFID
                        case MapOperate.EnumElementType.RFID:
                            MapFunction.RemoveRFID(MapElement.MapObject.RFIDS[MapOperate.NowSelectIndex]);
                            MapOperate.NowSelectIndex = -1;
                            //记录当前状态
                            MapOperate.History.AddRecord("删除了一个RFID");
                            break;

                        case MapOperate.EnumElementType.RouteLine:
                            MapFunction.RemoveRouteLine(MapElement.MapObject.Lines[MapOperate.NowSelectIndex]);
                            MapOperate.NowSelectIndex = -1;
                            //记录当前状态
                            MapOperate.History.AddRecord("删除了一条直线");
                            break;

                        case MapOperate.EnumElementType.RouteForkLine:
                            MapFunction.RemoveForkLine(MapElement.MapObject.ForkLines[MapOperate.NowSelectIndex]);
                            MapOperate.NowSelectIndex = -1;
                            //记录当前状态
                            MapOperate.History.AddRecord("删除了一条分叉线");
                            break;

                        default:
                            break;
                        }
                    }
                }
                else
                //编辑多个
                if (MapOperate.NowMode == MapOperate.EnumMode.MultiEdit)
                {
                    //删除已选中所有元素
                    //RFID
                    foreach (var item in MapOperate.MultiSelected.RFIDS)
                    {
                        MapFunction.RemoveRFID(item);
                    }
                    //Line
                    foreach (var item in MapOperate.MultiSelected.Lines)
                    {
                        MapFunction.RemoveRouteLine(item);
                    }
                    //ForkLine
                    foreach (var item in MapOperate.MultiSelected.ForkLines)
                    {
                        MapFunction.RemoveForkLine(item);
                    }
                    //清除已选中
                    MapFunction.ClearAllSelect(MapOperate.MultiSelected);
                    //记录当前状态
                    MapOperate.History.AddRecord("批量删除");
                }
            }
            else
            //Ctrl+C【复制】
            if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control && e.Key == Key.C)
            {
                //编辑单个
                if (MapOperate.NowMode == MapOperate.EnumMode.EditElement)
                {
                    if (MapOperate.NowSelectIndex != -1)
                    {
                        //清空剪切板
                        MapFunction.ClearClipBoard();
                        //将元素复制到剪贴板
                        switch (MapOperate.NowType)
                        {
                        case MapOperate.EnumElementType.None:
                            break;

                        case MapOperate.EnumElementType.RFID:
                            //列化深度复制
                            MapElement.RFID rfid = MapFunction.IgkClone.RFID(MapElement.MapObject.RFIDS[MapOperate.NowSelectIndex]);
                            //添加到剪切板
                            MapOperate.Clipboard.RFIDS.Add(rfid);
                            break;

                        case MapOperate.EnumElementType.RouteLine:
                            //列化深度复制
                            MapElement.RouteLine routeLine = MapFunction.IgkClone.Line(MapElement.MapObject.Lines[MapOperate.NowSelectIndex]);
                            //添加到剪切板
                            MapOperate.Clipboard.Lines.Add(routeLine);
                            break;

                        case MapOperate.EnumElementType.RouteForkLine:
                            //列化深度复制
                            MapElement.RouteForkLine routeForkLine = MapFunction.IgkClone.ForkLine(MapElement.MapObject.ForkLines[MapOperate.NowSelectIndex]);
                            //添加到剪切板
                            MapOperate.Clipboard.ForkLines.Add(routeForkLine);
                            break;

                        default:
                            break;
                        }
                    }
                }
                else
                //编辑多个
                if (MapOperate.NowMode == MapOperate.EnumMode.MultiEdit)
                {
                    //将元素复制到剪贴板
                    MapFunction.CopyMultiSelectToClipBoard();
                }
            }
            else
            //Ctrl+V【粘贴】
            if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control && e.Key == Key.V)
            {
                //清除之前的所有选中
                MapFunction.ClearSelect();
                MapOperate.NowSelectIndex = -1;
                MapFunction.ClearAllSelect(MapOperate.MultiSelected);
                /*----将剪切板的元素复制到对应的地图列表----------------------------*/
                //RFID
                MapOperate.PastedObject.RFIDS.Clear();
                foreach (var item in MapOperate.Clipboard.RFIDS)
                {
                    //列化深度复制
                    MapElement.RFID rfid = MapFunction.IgkClone.RFID(item);
                    //修改编号
                    rfid.Num = MapElement.MapObject.RFIDS.Last().Num + 1;
                    //更新到文本
                    rfid.textBlock.Text = rfid.Num.ToString();
                    //添加到列表
                    MapElement.MapObject.RFIDS.Add(rfid);
                    //显示
                    MapElement.ShowRFID(rfid);
                    //设置为选中状态
                    MapFunction.SetRFIDIsSelected(rfid);
                    //添加到粘贴过程对象
                    MapOperate.PastedObject.RFIDS.Add(rfid);
                }
                //Line
                MapOperate.PastedObject.Lines.Clear();
                foreach (var item in MapOperate.Clipboard.Lines)
                {
                    //列化深度复制
                    MapElement.RouteLine line = MapFunction.IgkClone.Line(item);
                    //修改编号
                    line.Num = MapElement.MapObject.Lines.Last().Num + 1;
                    //更新到文本
                    line.textBlock.Text = line.Num.ToString();
                    //添加到列表
                    MapElement.MapObject.Lines.Add(line);
                    //显示
                    MapElement.ShowLine(line);
                    //设置为选中状态
                    MapFunction.SetRouteLineIsSelected(line);
                    //添加到粘贴过程对象
                    MapOperate.PastedObject.Lines.Add(line);
                }
                //ForkLine
                MapOperate.PastedObject.ForkLines.Clear();
                foreach (var item in MapOperate.Clipboard.ForkLines)
                {
                    //列化深度复制
                    MapElement.RouteForkLine forkLine = MapFunction.IgkClone.ForkLine(item);
                    //修改编号
                    forkLine.Num = MapElement.MapObject.ForkLines.Last().Num + 1;
                    //更新到文本
                    forkLine.textBlock.Text = forkLine.Num.ToString();
                    //添加到列表
                    MapElement.MapObject.ForkLines.Add(forkLine);
                    //显示
                    MapElement.ShowForkLine(forkLine);
                    //设置为选中状态
                    MapFunction.SetForkLineIsSelected(forkLine);
                    //添加到粘贴过程对象
                    MapOperate.PastedObject.ForkLines.Add(forkLine);
                }
                /*----使所有对象处于光标中心【优化效果】---------------------------*/
                //计算所有对象的中心
                Point center = MapFunction.GetCenterPoint(MapOperate.PastedObject);
                //将左键的按下值设置为中心值【移动是根据左键按下的位置计算偏差】
                MapOperate.mouseLeftBtnDownToMap = center;
                //计算左键按下移动偏差
                MapOperate.mouseLeftBtnDownMoveDiff.X = MapOperate.NowPoint.X - MapOperate.mouseLeftBtnDownToMap.X;
                MapOperate.mouseLeftBtnDownMoveDiff.Y = MapOperate.NowPoint.Y - MapOperate.mouseLeftBtnDownToMap.Y;
                //初始移动【增加粘贴动态效果】
                MapFunction.MoveMultiSelected(MapOperate.NowPoint, MapOperate.PastedObject);
                //进入粘贴模式
                MapOperate.NowMode = MapOperate.EnumMode.Paste;
            }
            else
            //Esc【取消】
            if (e.Key == Key.Escape)
            {
                //粘贴模式
                if (MapOperate.NowMode == MapOperate.EnumMode.Paste)
                {
                    MapFunction.CancelPaste();
                    //恢复默认
                    MapOperate.NowMode = MapOperate.EnumMode.EditElement;
                }
            }
            else
            //Ctrl+Shif+Z【重做】
            if ((Keyboard.Modifiers & (ModifierKeys.Control | ModifierKeys.Shift)) == (ModifierKeys.Control | ModifierKeys.Shift) &&
                e.Key == Key.Z)
            {
                MapOperate.History.Redo();
            }
            else
            //Ctrl+Z【撤销】
            if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control && e.Key == Key.Z)
            {
                MapOperate.History.Undo();
            }
            else
            //Ctrl+X【剪切】
            if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control && e.Key == Key.X)
            {
                //编辑单个
                if (MapOperate.NowMode == MapOperate.EnumMode.EditElement)
                {
                    if (MapOperate.NowSelectIndex != -1)
                    {
                        //清空剪切板
                        MapFunction.ClearClipBoard();
                        //将元素复制到剪贴板
                        switch (MapOperate.NowType)
                        {
                        case MapOperate.EnumElementType.None:
                            break;

                        case MapOperate.EnumElementType.RFID:
                            //列化深度复制
                            MapElement.RFID rfid = MapFunction.IgkClone.RFID(MapElement.MapObject.RFIDS[MapOperate.NowSelectIndex]);
                            //添加到剪切板
                            MapOperate.Clipboard.RFIDS.Add(rfid);
                            //从地图删除
                            MapFunction.RemoveRFID(MapElement.MapObject.RFIDS[MapOperate.NowSelectIndex]);
                            MapOperate.NowSelectIndex = -1;
                            //记录当前状态
                            MapOperate.History.AddRecord("剪切掉了一个RFID");

                            break;

                        case MapOperate.EnumElementType.RouteLine:
                            //列化深度复制
                            MapElement.RouteLine routeLine = MapFunction.IgkClone.Line(MapElement.MapObject.Lines[MapOperate.NowSelectIndex]);
                            //添加到剪切板
                            MapOperate.Clipboard.Lines.Add(routeLine);
                            //从地图删除
                            MapFunction.RemoveRouteLine(MapElement.MapObject.Lines[MapOperate.NowSelectIndex]);
                            MapOperate.NowSelectIndex = -1;
                            //记录当前状态
                            MapOperate.History.AddRecord("剪切掉了一条直线");
                            break;

                        case MapOperate.EnumElementType.RouteForkLine:
                            //列化深度复制
                            MapElement.RouteForkLine routeForkLine = MapFunction.IgkClone.ForkLine(MapElement.MapObject.ForkLines[MapOperate.NowSelectIndex]);
                            //添加到剪切板
                            MapOperate.Clipboard.ForkLines.Add(routeForkLine);
                            //从地图删除
                            MapFunction.RemoveForkLine(MapElement.MapObject.ForkLines[MapOperate.NowSelectIndex]);
                            MapOperate.NowSelectIndex = -1;
                            //记录当前状态
                            MapOperate.History.AddRecord("剪切掉了一条分叉线");
                            break;

                        default:
                            break;
                        }
                    }
                }
                else
                //编辑多个
                if (MapOperate.NowMode == MapOperate.EnumMode.MultiEdit)
                {
                    //将元素复制到剪贴板
                    MapFunction.CopyMultiSelectToClipBoard();
                    //删除已选中所有元素
                    int num = 0;
                    //RFID
                    foreach (var item in MapOperate.MultiSelected.RFIDS)
                    {
                        MapFunction.RemoveRFID(item);
                        num++;
                    }
                    //Line
                    foreach (var item in MapOperate.MultiSelected.Lines)
                    {
                        MapFunction.RemoveRouteLine(item);
                        num++;
                    }
                    //ForkLine
                    foreach (var item in MapOperate.MultiSelected.ForkLines)
                    {
                        MapFunction.RemoveForkLine(item);
                        num++;
                    }
                    //清除已选中
                    MapFunction.ClearAllSelect(MapOperate.MultiSelected);
                    //记录当前状态
                    MapOperate.History.AddRecord(string.Format("剪切了{0}个元件", num));
                }
            }
            else
            //Ctrl+S【保存】
            if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control && e.Key == Key.S)
            {
                //获取字符串地图
                string str = SaveMap.Helper.ObjToJson.MapOject(MapElement.MapObject);
                //保存
                SaveMap.Helper.SaveToFile(str, @"map.json");
            }
            //记录当前按键
            MapOperate.Userkey.Key      = e.Key;
            MapOperate.Userkey.KeyState = KeyStates.Down;
        }