private void Receive_MouseLeftButtonDown(object sender, MouseButtonEventArgs e, IElement element)
        {
            if (element is LineElement)
            {
                ILineElement lineElement = (LineElement)element;
                IRectElement frontElment = lineElement.FrontElement;
                IRectElement endElement = lineElement.EndElement;
                Point mousePointInLine = e.GetPosition(_itemsControl);
                int clickNum = 0;
                if(mousePointInLine.X<=frontElment.X+frontElment.Width && mousePointInLine.X>=frontElment.X &&
                    mousePointInLine.Y <= frontElment.Y + frontElment.Height && mousePointInLine.Y >= frontElment.Y)
                {
                    element = frontElment;
                    clickNum += 1;
                }
                else if (mousePointInLine.X <= endElement.X + endElement.Width && mousePointInLine.X >= endElement.X &&
                    mousePointInLine.Y <= endElement.Y + endElement.Height && mousePointInLine.Y >= endElement.Y)
                {
                    element = endElement;
                    clickNum += 1;
                }
                if (clickNum == 2)
                {
                    if (frontElment.ZIndex > endElement.ZIndex)
                    {
                        element = frontElment;
                    }
                    else if(frontElment.ZIndex<endElement.ZIndex)
                    {
                        element = endElement;
                    }
                }
                if (clickNum == 0)
                {
                    e.Handled = true;
                    return;
                }

            }
            //if (element is RectLayer)
            //{
            //    Console.WriteLine("layer");
            //}
            //if (element is RectElement)
            //{
            //    Console.WriteLine("rect");
            //}
            if (element != null && element.EleType == ElementType.receive)
            {
                CurrentRectElement = (RectElement)element;
            }
            else
            {
                CurrentRectElement = null;
            }
            if (((IRectElement)element).OperateEnviron == OperatEnvironment.AdjustSenderLocation && element.EleType == ElementType.screen)
            {
                e.Handled = true;
                return;
            }
            if (MyRectLayer.ElementCollection.Count == 0)
            {
                e.Handled = true;
                return;
            }
            _myScreenLayer = (RectLayer)MyRectLayer.ElementCollection[0];
            UpdateGroupframeList();
            #region 添加接收卡
            ObservableCollection<IElement> addCollection = new ObservableCollection<IElement>();
            ObservableCollection<ElementSizeInfo> elementSizeCollection = new ObservableCollection<ElementSizeInfo>();
            if (_addReceiveInfo != null && _myScreenLayer.OperateEnviron == OperatEnvironment.DesignScreen)
            {
                this.Cursor = Cursors.Wait;
                _selectedElementCollection.Clear();
                //取消所有元素的选中态
                for (int i = 0; i < _myScreenLayer.ElementCollection.Count; i++)
                {
                    if (_myScreenLayer.ElementCollection[i].EleType == ElementType.receive && _myScreenLayer.ElementCollection[i].ElementSelectedState != SelectedState.None)
                    {
                        _myScreenLayer.ElementCollection[i].ElementSelectedState = SelectedState.None;
                    }
                }
                Point pointInCanvas = e.GetPosition(_itemsControl);
                pointInCanvas.X -= _myScreenLayer.X;
                pointInCanvas.Y -= _myScreenLayer.Y;
                int cols = _addReceiveInfo.Cols;
                int rows = _addReceiveInfo.Rows;
                ScannerCofigInfo scanConfig = _addReceiveInfo.ScanConfig;
                ScanBoardProperty scanBdProp = scanConfig.ScanBdProp;
                double width = scanBdProp.Width;
                double height = scanBdProp.Height;
                RectElement groupframe;
                if (cols == 1 && rows == 1)
                {
                    groupframe = new RectElement(Math.Round(pointInCanvas.X - width / 2), Math.Round(pointInCanvas.Y - height / 2), width * cols, height * rows, null, -1);
                    RectElement rectElement = new RectElement(Math.Round(pointInCanvas.X - width / 2), Math.Round(pointInCanvas.Y - height / 2), width * cols, height * rows, _myScreenLayer, _myScreenLayer.MaxZorder + 1);
                    rectElement.EleType = ElementType.receive;
                    _myScreenLayer.MaxZorder += 1;
                    rectElement.Tag = scanConfig.Clone();
                    rectElement.IsLocked = true;
                    rectElement.ZIndex = 4;
                    rectElement.GroupName = -1;
                    rectElement.ElementSelectedState = SelectedState.Selected;
                    _selectedElementCollection.Add(rectElement);
                    _myScreenLayer.ElementCollection.Add(rectElement);
                    addCollection.Add(rectElement);

                }
                else
                {
                    groupframe = new RectElement(Math.Round(pointInCanvas.X - width / 2), Math.Round(pointInCanvas.Y - height / 2), width * cols, height * rows, _myScreenLayer, _myScreenLayer.MaxZorder + 1);
                    groupframe.EleType = ElementType.groupframe;
                    groupframe.ZIndex = 5;
                    groupframe.GroupName = _myScreenLayer.MaxGroupName + 1;
                    _myScreenLayer.MaxGroupName += 1;
                    _myScreenLayer.MaxZorder += 1;
                    groupframe.ElementSelectedState = SelectedState.SelectedAll;
                    _groupframeList.Add(groupframe.GroupName, groupframe);
                    for (int i = 0; i < cols; i++)
                    {
                        for (int j = 0; j < rows; j++)
                        {
                            RectElement rectElement = new RectElement(width * i + groupframe.X, height * j + groupframe.Y, width, height, _myScreenLayer, _myScreenLayer.MaxZorder + 1);
                            rectElement.EleType = ElementType.receive;
                            _myScreenLayer.MaxZorder += 1;
                            rectElement.Tag = scanConfig.Clone();
                            rectElement.IsLocked = true;
                            rectElement.ZIndex = 4;
                            rectElement.GroupName = groupframe.GroupName;
                            rectElement.ElementSelectedState = SelectedState.Selected;
                            _selectedElementCollection.Add(rectElement);
                            _myScreenLayer.ElementCollection.Add(rectElement);
                            addCollection.Add(rectElement);
                        }
                    }
                    _myScreenLayer.ElementCollection.Add(groupframe);
                    addCollection.Add(groupframe);

                }

                ElementSizeInfo info = new ElementSizeInfo();
                info.Element = _myScreenLayer;
                info.OldSize = new Size(_myScreenLayer.Width, _myScreenLayer.Height);
                bool isChangedSize = false;
                if (groupframe.X + groupframe.Width > _myScreenLayer.Width)
                {
                    _myScreenLayer.Width = groupframe.X + groupframe.Width;
                    isChangedSize = true;
                }
                if (groupframe.Y + groupframe.Height > _myScreenLayer.Height)
                {
                    _myScreenLayer.Height = groupframe.Y + groupframe.Height;
                    isChangedSize = true;
                }
                SelectedElementChangedHandle(MouseState.None);
                //记录
                if (isChangedSize)
                {
                    info.NewSize = new Size(_myScreenLayer.Width, _myScreenLayer.Height);
                    elementSizeCollection.Add(info);
                    ElementSizeAction elementSizeAction = new ElementSizeAction(elementSizeCollection);
                    AddAction addAction = new AddAction(_myScreenLayer, addCollection);
                    using (Transaction.Create(SmartLCTActionManager))
                    {
                        SmartLCTActionManager.RecordAction(elementSizeAction);
                        SmartLCTActionManager.RecordAction(addAction);
                    }
                }
                else
                {
                    AddAction addAction = new AddAction(_myScreenLayer, addCollection);
                    SmartLCTActionManager.RecordAction(addAction);
                }
                e.Handled = true;
                return;
            }
            #endregion

            #region 空格+鼠标移动屏体
            if ((Keyboard.GetKeyStates(Key.Space) == KeyStates.Down || (Keyboard.GetKeyStates(Key.Space) == (KeyStates.Down | KeyStates.Toggled))))
            {
                _itemsControl.Cursor = _moveCursor;
                Layer_MouseLeftButtonDown(sender, e, _myScreenLayer);
                e.Handled = true;
                return;
            }
            #endregion
            #region 手动鼠标点击连线
            if (element.EleType == ElementType.receive)
            {
                if (_myScreenLayer.CLineType == ConnectLineType.Manual)
                {
                    if (element.ConnectedIndex >= 0)
                    {
                        e.Handled = true;
                        return;
                    }
                    ObservableCollection<IElement> addElement = new ObservableCollection<IElement>();
                    ObservableCollection<AddLineInfo> addElementInfo = new ObservableCollection<AddLineInfo>();
                    ObservableCollection<ConnectIconVisibilityInfo> connectIconVisibleCollection = new ObservableCollection<ConnectIconVisibilityInfo>();

                    //更新map
                    #region 连线前发送卡的带载
                    int senderIndex = _myScreenLayer.CurrentSenderIndex;
                    int portIndex = _myScreenLayer.CurrentPortIndex;
                    bool isSenderLoadSizeNull = false;//第一次添加该发送卡的数据
                    if (_myScreenLayer.SenderConnectInfoList[senderIndex].LoadSize.Height == 0 &&
                        _myScreenLayer.SenderConnectInfoList[senderIndex].LoadSize.Width == 0)
                    {
                        isSenderLoadSizeNull = true;
                    }
                    Rect oldSenderLoadSize = new Rect();
                    Point oldSenderPoint = new Point();
                    Point oldMap = new Point();
                    if (!isSenderLoadSizeNull)
                    {
                        oldSenderLoadSize = _myScreenLayer.SenderConnectInfoList[senderIndex].LoadSize;
                        oldSenderPoint = new Point(oldSenderLoadSize.X, oldSenderLoadSize.Y);
                        //原来的map
                        oldMap = new Point();
                        for (int j = 0; j < _myScreenLayer.SenderConnectInfoList[_myScreenLayer.CurrentSenderIndex].PortConnectInfoList.Count; j++)
                        {
                            if (_myScreenLayer.SenderConnectInfoList[_myScreenLayer.CurrentSenderIndex].PortConnectInfoList[j].LoadSize.Width != 0 &&
                                _myScreenLayer.SenderConnectInfoList[_myScreenLayer.CurrentSenderIndex].PortConnectInfoList[j].LoadSize.Height != 0)
                            {
                                oldMap = _myScreenLayer.SenderConnectInfoList[_myScreenLayer.CurrentSenderIndex].PortConnectInfoList[j].MapLocation;
                                break;
                            }
                        }
                    }
                    #endregion

                    #region 记录相关
                    //记下该元素的前一个元素的最大和最小连线图标是否显示
                    IRectElement maxConnectElement = _myScreenLayer.SenderConnectInfoList[_myScreenLayer.CurrentSenderIndex].PortConnectInfoList[_myScreenLayer.CurrentPortIndex].MaxConnectElement;
                    if (maxConnectElement != null)
                    {
                        ConnectIconVisibilityInfo info = new ConnectIconVisibilityInfo();
                        info.Element = maxConnectElement;
                        OldAndNewVisibility oldAndNewMaxConnectIndexVisibile = new OldAndNewVisibility();
                        oldAndNewMaxConnectIndexVisibile.OldValue = maxConnectElement.MaxConnectIndexVisibile;
                        OldAndNewVisibility oldAndNewMinConnectIndexVisibile = new OldAndNewVisibility();
                        oldAndNewMinConnectIndexVisibile.OldValue = maxConnectElement.MinConnectIndexVisibile;
                        info.OldAndNewMaxConnectIndexVisibile = oldAndNewMaxConnectIndexVisibile;
                        info.OldAndNewMinConnectIndexVisibile = oldAndNewMinConnectIndexVisibile;
                        connectIconVisibleCollection.Add(info);
                    }
                    #endregion

                    int connectIndex = _myScreenLayer.SenderConnectInfoList[_myScreenLayer.CurrentSenderIndex].PortConnectInfoList[_myScreenLayer.CurrentPortIndex].MaxConnectIndex + 1;

                    ((RectElement)element).SenderIndex = _myScreenLayer.CurrentSenderIndex;
                    ((RectElement)element).PortIndex = _myScreenLayer.CurrentPortIndex;
                    element.ConnectedIndex = connectIndex;

                    #region 记录相关
                    //记下连线后最大和最小连线图标是否显示
                    for (int itemIndex = 0; itemIndex < connectIconVisibleCollection.Count; itemIndex++)
                    {
                        connectIconVisibleCollection[itemIndex].OldAndNewMaxConnectIndexVisibile.NewValue = connectIconVisibleCollection[itemIndex].Element.MaxConnectIndexVisibile;
                        connectIconVisibleCollection[itemIndex].OldAndNewMinConnectIndexVisibile.NewValue = connectIconVisibleCollection[itemIndex].Element.MinConnectIndexVisibile;
                    }
                    //记下该元素最大和最小连线图标是否显示
                    ConnectIconVisibilityInfo connectIconinfo = new ConnectIconVisibilityInfo();
                    connectIconinfo.Element = (IRectElement)element;
                    OldAndNewVisibility oldAndNewMaxConnectIconVisibile = new OldAndNewVisibility();
                    oldAndNewMaxConnectIconVisibile.OldValue = Visibility.Hidden;
                    oldAndNewMaxConnectIconVisibile.NewValue = ((IRectElement)element).MaxConnectIndexVisibile;
                    OldAndNewVisibility oldAndNewMinConnectIconVisibile = new OldAndNewVisibility();
                    oldAndNewMinConnectIconVisibile.OldValue = Visibility.Hidden;
                    oldAndNewMinConnectIconVisibile.NewValue = ((IRectElement)element).MinConnectIndexVisibile;
                    connectIconinfo.OldAndNewMaxConnectIndexVisibile = oldAndNewMaxConnectIconVisibile;
                    connectIconinfo.OldAndNewMinConnectIndexVisibile = oldAndNewMinConnectIconVisibile;
                    connectIconVisibleCollection.Add(connectIconinfo);
                    #endregion

                    #region  连线后发送卡的带载
                    if (_myScreenLayer.IsStartSetMapLocation && (!isSenderLoadSizeNull))
                        {
                            //更新该发送卡的带载
                            Rect newSenderLoadSize = _myScreenLayer.SenderConnectInfoList[_myScreenLayer.CurrentSenderIndex].LoadSize;
                            Point newSenderPoint = new Point(newSenderLoadSize.X, newSenderLoadSize.Y);
                            Point difSenderPint = new Point(newSenderLoadSize.X - oldSenderPoint.X, newSenderLoadSize.Y - oldSenderPoint.Y);
                            //发送卡带载的xy有变化的话更新该发送卡下所有网口的Map
                            if (difSenderPint.Y != 0 || difSenderPint.X != 0)
                            {
                                Point newmapLocation = new Point(oldMap.X + difSenderPint.X, oldMap.Y + difSenderPint.Y);
                                if (newmapLocation.X < 0)
                                {
                                    newmapLocation.X = 0;
                                }
                                if (newmapLocation.Y < 0)
                                {
                                    newmapLocation.Y = 0;
                                }
                                //更新网口的map
                                for (int j = 0; j < _myScreenLayer.SenderConnectInfoList[senderIndex].PortConnectInfoList.Count; j++)
                                {
                                    PortConnectInfo portConnect = _myScreenLayer.SenderConnectInfoList[senderIndex].PortConnectInfoList[j];
                                    if (portConnect.LoadSize.Height != 0 && portConnect.LoadSize.Width != 0)
                                    {
                                        portConnect.MapLocation = newmapLocation;
                                    }
                                }
                            }
                            if (difSenderPint.X == 0 && difSenderPint.Y == 0)
                            {
                                _myScreenLayer.SenderConnectInfoList[senderIndex].PortConnectInfoList[portIndex].MapLocation = oldMap;
                            }
                        }
                    #endregion

                    #region 记录相关
                    if (((IRectElement)element).FrontLine != null)
                    {
                        addElement.Add(((IRectElement)element).FrontLine);
                    }

                    AddLineInfo addInfo = new AddLineInfo();
                    addInfo.Element = (IRectElement)element;
                    OldAndNewType oldAndNewConnect = new OldAndNewType();
                    oldAndNewConnect.NewValue = element.ConnectedIndex;
                    oldAndNewConnect.OldValue = -1;
                    OldAndNewType oldAndNewSender = new OldAndNewType();
                    oldAndNewSender.NewValue = ((IRectElement)element).SenderIndex;
                    oldAndNewSender.OldValue = -1;
                    OldAndNewType oldAndNewPort = new OldAndNewType();
                    oldAndNewPort.NewValue = ((IRectElement)element).PortIndex;
                    oldAndNewPort.OldValue = -1;
                    addInfo.OldAndNewConnectIndex = oldAndNewConnect;
                    addInfo.OldAndNewSenderIndex = oldAndNewSender;
                    addInfo.OldAndNewPortIndex = oldAndNewPort;
                    addElementInfo.Add(addInfo);

                    AddAction addAction = new AddAction(_myScreenLayer, addElement);
                    AddLineAction addLineAction = new AddLineAction(addElementInfo);
                    ConnectIconVisibilityAction connectIconVisibleAction = new ConnectIconVisibilityAction(connectIconVisibleCollection);
                    using (Transaction.Create(SmartLCTActionManager))
                    {
                        SmartLCTActionManager.RecordAction(addAction);
                        SmartLCTActionManager.RecordAction(addLineAction);
                        SmartLCTActionManager.RecordAction(connectIconVisibleAction);
                    }
                    #endregion
                    e.Handled = true;
                    return;
                }

            }
            #endregion
            #region 条件
            FrameworkElement currentFramework = (FrameworkElement)sender;
            _mousePoint = e.GetPosition(currentFramework);
            Point mouseLeftDownPointInThis=this.TranslatePoint(e.GetPosition(this), _itemsControl);
            _mouseLeftDownPointInThis = new Point(mouseLeftDownPointInThis.X,mouseLeftDownPointInThis.Y);

            _copyPoint = _mouseLeftDownPointInThis;

            _isMouseLeftButtonDown = true;
            _isStartMoveX = true;
            _isStartMoveY = true;
            #endregion
            GetCurrentElementInfo();

            #region 点击图层和矩形的处理
            ObservableCollection<SelectedStateInfo> oldSelectedStateInfoCollection = new ObservableCollection<SelectedStateInfo>();
            oldSelectedStateInfoCollection = GetOldSelectedStateInfoCollection();
            if (element.EleType == ElementType.screen)
            {
                #region 点击图层的处理
                ((RectLayer)element).CLineType = ConnectLineType.Auto;
                this.Cursor = Cursors.Arrow;
                foreach (int elementIndex in _currentSelectedElement.Keys)
                {
                    ObservableCollection<IRectElement> selectedGroupList = _currentSelectedElement[elementIndex].SelectedGroupElementList;
                    for (int i = 0; i < selectedGroupList.Count; i++)
                    {
                        selectedGroupList[i].ElementSelectedState = SelectedState.None;
                        if (selectedGroupList[i].EleType == ElementType.receive)
                        {
                            selectedGroupList[i].IsLocked = true;
                        }
                    }
                }
                #endregion
            }
            else if (element.EleType == ElementType.receive || element.EleType == ElementType.groupframe)
            {
                #region 展开
                RectLayer myScreen = MyRectLayer;
                while (myScreen != null && myScreen.EleType != ElementType.baseScreen)
                {
                    myScreen = (RectLayer)myScreen.ParentElement;
                }
                if (myScreen != null && myScreen.SenderConnectInfoList != null &&
               myScreen.SenderConnectInfoList.Count > 0)
                {
                    for (int m = 0; m < myScreen.SenderConnectInfoList.Count; m++)
                    {
                        bool isexpand = false;
                        ObservableCollection<PortConnectInfo> portConnectList = myScreen.SenderConnectInfoList[m].PortConnectInfoList;
                        if (portConnectList != null)
                        {
                            for (int i = 0; i < portConnectList.Count; i++)
                            {
                                if (portConnectList[i].IsOverLoad)
                                {
                                    isexpand = true;
                                    break;
                                }
                            }
                        }
                        if (isexpand)
                        {
                            myScreen.SenderConnectInfoList[m].IsExpand = true;
                        }
                        else
                        {
                            myScreen.SenderConnectInfoList[m].IsExpand = false;
                        }
                    }
                }

                if (myScreen != null && ((IRectElement)element).SenderIndex >= 0 && myScreen.SenderConnectInfoList != null &&
                    myScreen.SenderConnectInfoList.Count > 0 &&
                    myScreen.SenderConnectInfoList.Count >= ((IRectElement)element).SenderIndex)
                {
                    myScreen.SenderConnectInfoList[((IRectElement)element).SenderIndex].IsExpand = true;
                    myScreen.SenderConnectInfoList[((IRectElement)element).SenderIndex].PortConnectInfoList[((IRectElement)element).PortIndex].IsSelected = true;
                }
                #endregion
                if ((Keyboard.GetKeyStates(Key.LeftCtrl) == KeyStates.Down || (Keyboard.GetKeyStates(Key.LeftCtrl) == (KeyStates.Down | KeyStates.Toggled))) ||
                    (Keyboard.GetKeyStates(Key.RightCtrl) == KeyStates.Down || (Keyboard.GetKeyStates(Key.RightCtrl) == (KeyStates.Down | KeyStates.Toggled))))
                {
                    #region 按ctrl键
                    if (element.ElementSelectedState == SelectedState.None)
                    {
                        element.ElementSelectedState = SelectedState.Selected;
                    }
                    else if (element.ElementSelectedState != SelectedState.None)
                    {
                        element.ElementSelectedState = SelectedState.None;
                    }
                    #endregion
                }
                else
                {
                    #region 不按ctrl键
                    if (element.ElementSelectedState == SelectedState.None)
                    {
                        Function.SetElementCollectionState(_selectedElementCollection, SelectedState.None);
                        if (element.GroupName != -1)
                        {
                            ObservableCollection<IRectElement> noSelectedGroupElement = _currentSelectedElement[element.GroupName].NoSelectedGroupElementList;
                            ObservableCollection<IRectElement> selectedGroupElement = _currentSelectedElement[element.GroupName].SelectedGroupElementList;
                            Function.SetElementCollectionState(noSelectedGroupElement, SelectedState.Selected);
                            Function.SetElementCollectionState(selectedGroupElement, SelectedState.Selected);
                        }
                        element.ElementSelectedState = SelectedState.Selected;
                    }
                    #endregion
                }
            }
            #endregion
            GetCurrentElementInfo();

            RecordBeforeMoveData();
            SelectedElementChangedHandle(MouseState.None);
            e.Handled = true;
        }
        private void OnCmdDelete()
        {
            ObservableCollection<IElement> deleteCollection = new ObservableCollection<IElement>();
            ObservableCollection<IElement> addCollection = new ObservableCollection<IElement>();
            ObservableCollection<ConnectIconVisibilityInfo> connectIconVisibleCollection = new ObservableCollection<ConnectIconVisibilityInfo>();
            _elementMoveInfo.Clear();
            _elementSizeInfo.Clear();
            for (int i = 0; i < _selectedElementCollection.Count; i++)
            {
                Point oldPoint = new Point();
                oldPoint.X = _selectedElementCollection[i].X;
                oldPoint.Y = _selectedElementCollection[i].Y;
                _elementMoveInfo.Add(new ElementMoveInfo(_selectedElementCollection[i], new Point(), oldPoint));
            }
            for (int itemIndex = 0; itemIndex < _myScreenLayer.ElementCollection.Count; itemIndex++)
            {
                if (_myScreenLayer.ElementCollection[itemIndex].EleType != ElementType.receive)
                {
                    continue;
                }
                IRectElement element = (IRectElement)_myScreenLayer.ElementCollection[itemIndex];
                if (element.ConnectedIndex >= 0)
                {
                    ConnectIconVisibilityInfo info = new ConnectIconVisibilityInfo();
                    info.Element = element;
                    OldAndNewVisibility oldAndNewMaxmaxVisible = new OldAndNewVisibility();
                    oldAndNewMaxmaxVisible.OldValue = element.MaxConnectIndexVisibile;
                    OldAndNewVisibility oldAndNewMaxminVisible = new OldAndNewVisibility();
                    oldAndNewMaxminVisible.OldValue =element.MinConnectIndexVisibile;
                    info.OldAndNewMaxConnectIndexVisibile = oldAndNewMaxmaxVisible;
                    info.OldAndNewMinConnectIndexVisibile = oldAndNewMaxminVisible;
                    connectIconVisibleCollection.Add(info);

                }
            }
                foreach (int key in _currentSelectedElement.Keys)
                {
                    if (_currentSelectedElement[key].SelectedGroupElementList.Count != 0 && key != -1)
                    {
                        Point oldPoint = new Point();
                        oldPoint.X = _groupframeList[key].X;
                        oldPoint.Y = _groupframeList[key].Y;
                        _elementMoveInfo.Add(new ElementMoveInfo(_groupframeList[key], new Point(), oldPoint));
                        Size oldSize = new Size();
                        oldSize.Width = _groupframeList[key].Width;
                        oldSize.Height = _groupframeList[key].Height;
                        _elementSizeInfo.Add(new ElementSizeInfo(_groupframeList[key], new Size(), oldSize));
                    }
                }
            foreach(int elementIndex in _currentSelectedElement.Keys)
            {
                ObservableCollection<IRectElement> selectedGroupList = _currentSelectedElement[elementIndex].SelectedGroupElementList;
                Rect noSelectedElementRect = _currentSelectedElement[elementIndex].NoSelectedElementRect;
                for (int i = 0; i < selectedGroupList.Count; i++)
                {
                    #region 删除
                    if (selectedGroupList[i].EleType == ElementType.receive)
                    {
                        #region 处理连线
                        RectElement rect = (RectElement)selectedGroupList[i];
                        PortConnectInfo portConnectInfo = new PortConnectInfo();
                        if (rect.SenderIndex != -1 && rect.PortIndex != -1)
                        {
                            portConnectInfo = _myScreenLayer.SenderConnectInfoList[rect.SenderIndex].PortConnectInfoList[rect.PortIndex];
                        }
                        if (rect.FrontLine == null && rect.EndLine == null)
                        {
                            //更新Map值(发送卡带载的x,y的改变,会影响给发送卡下网口的映射位置)
                            //记录删除前发送卡的带载的x,y
                            Point oldSenderPoint = new Point();
                            if (rect.SenderIndex >= 0 && rect.PortIndex >= 0)
                            {
                                oldSenderPoint = new Point(_myScreenLayer.SenderConnectInfoList[rect.SenderIndex].LoadSize.X, _myScreenLayer.SenderConnectInfoList[rect.SenderIndex].LoadSize.Y);
                            }

                            portConnectInfo.ConnectLineElementList.Remove(rect);
                            portConnectInfo.MaxConnectElement = null;
                            portConnectInfo.MaxConnectIndex = -1;
                            deleteCollection.Add(rect);
                            _myScreenLayer.ElementCollection.Remove(rect);

                            if (_myScreenLayer.IsStartSetMapLocation && rect.SenderIndex>=0 && rect.PortIndex>=0)
                            {
                                //更新该发送卡的带载
                                portConnectInfo.LoadSize = Function.UnionRectCollection(portConnectInfo.ConnectLineElementList);
                                if(portConnectInfo.LoadSize.Height==0 && portConnectInfo.LoadSize.Width==0)
                                {
                                    portConnectInfo.MapLocation=new Point();
                                }
                                _myScreenLayer.SenderConnectInfoList[rect.SenderIndex].LoadSize = Function.UnionRectCollection(_myScreenLayer.SenderConnectInfoList[rect.SenderIndex].PortConnectInfoList);
                                Rect newSenderLoadSize = _myScreenLayer.SenderConnectInfoList[rect.SenderIndex].LoadSize;
                                Point newSenderPoint=new Point();
                                Point difSenderPint=new Point();
                                if(newSenderLoadSize.Width==0 && newSenderLoadSize.Height==0)
                                {
                                    //发送卡带载的xy有变化的话更新该发送卡下所有网口的Map
                                    //更新网口的map
                                    for (int j = 0; j < _myScreenLayer.SenderConnectInfoList[rect.SenderIndex].PortConnectInfoList.Count; j++)
                                    {
                                        PortConnectInfo portConnect = _myScreenLayer.SenderConnectInfoList[rect.SenderIndex].PortConnectInfoList[j];
                                        portConnect.MapLocation = new Point();
                                    }
                                }
                                else
                                {
                                    newSenderPoint = new Point(newSenderLoadSize.X, newSenderLoadSize.Y);
                                    difSenderPint = new Point(newSenderLoadSize.X - oldSenderPoint.X, newSenderLoadSize.Y - oldSenderPoint.Y);
                                    //发送卡带载的xy有变化的话更新该发送卡下所有网口的Map
                                    if (difSenderPint.Y != 0 || difSenderPint.X != 0)
                                    {
                                        //更新网口的map
                                        for (int j = 0; j < _myScreenLayer.SenderConnectInfoList[rect.SenderIndex].PortConnectInfoList.Count; j++)
                                        {
                                            PortConnectInfo portConnect = _myScreenLayer.SenderConnectInfoList[rect.SenderIndex].PortConnectInfoList[j];
                                            if (portConnect.LoadSize.Height != 0 && portConnect.LoadSize.Width != 0)
                                            {
                                                Point newmapLocation = new Point(portConnect.MapLocation.X + difSenderPint.X, portConnect.MapLocation.Y + difSenderPint.Y);
                                                portConnect.MapLocation = newmapLocation;
                                            }
                                        }
                                    }
                                }

                            }

                            continue;
                        }
                        if (rect.EndLine != null)
                        {
                            rect.EndLine.EndElement.FrontLine = null;
                            deleteCollection.Add(rect.EndLine);
                            _myScreenLayer.ElementCollection.Remove(rect.EndLine);
                            rect.EndLine = null;
                        }
                        if (rect.FrontLine != null)
                        {
                            rect.FrontLine.FrontElement.EndLine = null;
                            deleteCollection.Add(rect.FrontLine);
                            _myScreenLayer.ElementCollection.Remove(rect.FrontLine);
                            rect.FrontLine = null;
                        }
                        deleteCollection.Add(rect);

                        if (portConnectInfo.MaxConnectIndex != rect.ConnectedIndex)
                        {
                            List<IRectElement> connectList = portConnectInfo.ConnectLineElementList.ToList<IRectElement>();
                            connectList.Sort(delegate(IRectElement first, IRectElement second)
                            {
                                return first.ConnectedIndex.CompareTo(second.ConnectedIndex);
                            });
                            int currentIndex = connectList.IndexOf(rect);
                            connectList[currentIndex + 1].ConnectedIndex = connectList[currentIndex + 1].ConnectedIndex;
                            if (currentIndex == 0)
                            {
                                ((RectElement)connectList[currentIndex + 1]).MinConnectIndexVisibile = Visibility.Visible;
                                ((RectElement)connectList[currentIndex + 1]).MaxConnectIndexVisibile = Visibility.Hidden;
                            }
                            if(connectList[currentIndex+1].FrontLine!=null)
                            addCollection.Add(connectList[currentIndex + 1].FrontLine);
                        }
                        else
                        {
                            List<IRectElement> connectList = portConnectInfo.ConnectLineElementList.ToList<IRectElement>();
                            connectList.Sort(delegate(IRectElement first, IRectElement second)
                            {
                                return first.ConnectedIndex.CompareTo(second.ConnectedIndex);
                            });
                            if (connectList.Count == 1)
                            {
                                portConnectInfo.MaxConnectIndex = -1;
                                portConnectInfo.MaxConnectElement = null;
                                rect.MinConnectIndexVisibile = Visibility.Hidden;
                                rect.MaxConnectIndexVisibile = Visibility.Hidden;
                            }
                            else
                            {
                                portConnectInfo.MaxConnectIndex = connectList[connectList.Count - 2].ConnectedIndex;
                                portConnectInfo.MaxConnectElement = (RectElement)connectList[connectList.Count - 2];
                                if (connectList.Count > 2)
                                {
                                    ((RectElement)connectList[connectList.Count - 2]).MaxConnectIndexVisibile = Visibility.Visible;
                                }
                            }
                        }
                        //更新Map值(发送卡带载的x,y的改变,会影响给发送卡下网口的映射位置)
                        //记录删除前发送卡的带载的x,y
                        Point oldSenderPoints = new Point(_myScreenLayer.SenderConnectInfoList[rect.SenderIndex].LoadSize.X, _myScreenLayer.SenderConnectInfoList[rect.SenderIndex].LoadSize.Y);
                        portConnectInfo.ConnectLineElementList.Remove(rect);
                        _myScreenLayer.ElementCollection.Remove(rect);
                        if (_myScreenLayer.IsStartSetMapLocation)
                        {
                            //更新该发送卡的带载
                            portConnectInfo.LoadSize = Function.UnionRectCollection(portConnectInfo.ConnectLineElementList);
                            if (portConnectInfo.LoadSize.Height == 0 && portConnectInfo.LoadSize.Width == 0)
                            {
                                portConnectInfo.MapLocation = new Point();
                            }
                            _myScreenLayer.SenderConnectInfoList[rect.SenderIndex].LoadSize = Function.UnionRectCollection(_myScreenLayer.SenderConnectInfoList[rect.SenderIndex].PortConnectInfoList);
                            Rect newSenderLoadSizes = _myScreenLayer.SenderConnectInfoList[rect.SenderIndex].LoadSize;
                            Point newSenderPoints = new Point();
                            Point difSenderPints = new Point();
                            if (newSenderLoadSizes.Height == 0 && newSenderLoadSizes.Width == 0)
                            {
                                //发送卡带载的xy有变化的话更新该发送卡下所有网口的Map
                                //更新网口的map
                                for (int j = 0; j < _myScreenLayer.SenderConnectInfoList[rect.SenderIndex].PortConnectInfoList.Count; j++)
                                {
                                    PortConnectInfo portConnect = _myScreenLayer.SenderConnectInfoList[rect.SenderIndex].PortConnectInfoList[j];
                                    portConnect.MapLocation = new Point();
                                }
                            }
                            else
                            {
                                newSenderPoints = new Point(newSenderLoadSizes.X, newSenderLoadSizes.Y);
                                difSenderPints = new Point(newSenderPoints.X - oldSenderPoints.X, newSenderPoints.Y - oldSenderPoints.Y);
                                //发送卡带载的xy有变化的话更新该发送卡下所有网口的Map
                                if (difSenderPints.Y != 0 || difSenderPints.X != 0)
                                {
                                    //更新网口的map
                                    for (int j = 0; j < _myScreenLayer.SenderConnectInfoList[rect.SenderIndex].PortConnectInfoList.Count; j++)
                                    {
                                        PortConnectInfo portConnect = _myScreenLayer.SenderConnectInfoList[rect.SenderIndex].PortConnectInfoList[j];
                                        if (portConnect.LoadSize.Height != 0 && portConnect.LoadSize.Width != 0)
                                        {
                                            Point newmapLocation = new Point(portConnect.MapLocation.X + difSenderPints.X, portConnect.MapLocation.Y + difSenderPints.Y);
                                            portConnect.MapLocation = newmapLocation;
                                        }
                                    }
                                }
                            }

                        }
                        #endregion
                    }
                    #endregion
                }

                for (int itemIndex = 0; itemIndex < connectIconVisibleCollection.Count; itemIndex++)
                {
                    ConnectIconVisibilityInfo info=connectIconVisibleCollection[itemIndex];
                    if (_myScreenLayer.ElementCollection.Contains(info.Element))
                    {
                        info.OldAndNewMaxConnectIndexVisibile.NewValue = info.Element.MaxConnectIndexVisibile;
                        info.OldAndNewMinConnectIndexVisibile.NewValue = info.Element.MinConnectIndexVisibile;
                    }
                    else
                    {
                        info.OldAndNewMaxConnectIndexVisibile.NewValue = Visibility.Hidden;
                        info.OldAndNewMinConnectIndexVisibile.NewValue = Visibility.Hidden;
                    }
                }
                    //组框大小和位置=该组内没有选中的接收卡大矩形
                    if (elementIndex != -1)
                    {
                        if (noSelectedElementRect.Width == 0 && noSelectedElementRect.Height == 0)
                        {
                            deleteCollection.Add(_groupframeList[elementIndex]);
                            _myScreenLayer.ElementCollection.Remove(_groupframeList[elementIndex]);
                            _groupframeList.Remove(elementIndex);
                        }
                        else
                        {
                            _groupframeList[elementIndex].X = noSelectedElementRect.X;
                            _groupframeList[elementIndex].Y = noSelectedElementRect.Y;
                            _groupframeList[elementIndex].Width = noSelectedElementRect.Width;
                            _groupframeList[elementIndex].Height = noSelectedElementRect.Height;
                        }
                    }
                    else
                    {
                        if (noSelectedElementRect.Width == 0 && noSelectedElementRect.Height == 0)
                        {
                            _groupframeList.Remove(elementIndex);
                        }
                    }
            }
            AddAction addAction = new AddAction(_myScreenLayer, addCollection);
            DeleteAction deleteAction = new DeleteAction(_myScreenLayer, deleteCollection);
            for(int m=0;m<addCollection.Count;m++)
            {
                if (m < 0)
                {
                    m = 0;
                }
                if(addCollection[m] is LineElement)
                {
                    LineElement addLine=(LineElement)addCollection[m];
                    for (int n = 0; n < deleteCollection.Count; n++)
                    {
                        if(deleteCollection[n] is LineElement)
                        {
                            LineElement deleteLine=(LineElement)deleteCollection[n];
                             if(addLine.FrontElement.SenderIndex==deleteLine.FrontElement.SenderIndex
                                 && addLine.FrontElement.PortIndex==deleteLine.FrontElement.PortIndex
                                 && addLine.FrontElement.ConnectedIndex==deleteLine.FrontElement.ConnectedIndex
                                 && addLine.EndElement.ConnectedIndex == deleteLine.EndElement.ConnectedIndex)
                             {
                                 addCollection.Remove(addLine);
                                 m = m - 1;
                                 deleteCollection.Remove(deleteLine);
                                 n = n - 1;

                             }
                        }

                    }
                }
            }
            ObservableCollection<ElementMoveInfo> elementMoveInfo = new ObservableCollection<ElementMoveInfo>();
            for (int i = 0; i < _elementMoveInfo.Count; i++)
            {
                Point newPoint = new Point();
                newPoint.X = _elementMoveInfo[i].Element.X;
                newPoint.Y = _elementMoveInfo[i].Element.Y;
                elementMoveInfo.Add(new ElementMoveInfo(_elementMoveInfo[i].Element, newPoint, _elementMoveInfo[i].OldPoint));
            }
            ElementMoveAction moveAction = new ElementMoveAction(elementMoveInfo);
            ObservableCollection<ElementSizeInfo> elementSizeInfo = new ObservableCollection<ElementSizeInfo>();
            for (int j = 0; j < _elementSizeInfo.Count; j++)
            {
                Size newSize = new Size();
                newSize.Width = _elementSizeInfo[j].Element.Width;
                newSize.Height = _elementSizeInfo[j].Element.Height;
                elementSizeInfo.Add(new ElementSizeInfo(_elementSizeInfo[j].Element, newSize, _elementSizeInfo[j].OldSize));
            }
            ElementSizeAction sizeAction = new ElementSizeAction(elementSizeInfo);
            ConnectIconVisibilityAction connectIconAction = new ConnectIconVisibilityAction(connectIconVisibleCollection);
            using (Transaction.Create(SmartLCTActionManager))
            {
                SmartLCTActionManager.RecordAction(moveAction);
                SmartLCTActionManager.RecordAction(sizeAction);
                SmartLCTActionManager.RecordAction(deleteAction);
                SmartLCTActionManager.RecordAction(addAction);
                SmartLCTActionManager.RecordAction(connectIconAction);
            }
            GetCurrentElementInfo();
            SelectedLayerAndElementChanged();
        }
        private void OnClearLine()
        {
            ObservableCollection<PortInfo> selectedPortCollection = new ObservableCollection<PortInfo>();
            for (int i = 0; i < _selectedElementCollection.Count; i++)
            {
                if (_selectedElementCollection[i].SenderIndex < 0 && _selectedElementCollection[i].PortIndex < 0)
                {
                    continue;
                }
                PortInfo portInfo = new PortInfo(_selectedElementCollection[i].SenderIndex, _selectedElementCollection[i].PortIndex);
                if (!selectedPortCollection.Contains(portInfo))
                {
                    selectedPortCollection.Add(portInfo);
                }
            }

            ObservableCollection<IElement> deleteCollection = new ObservableCollection<IElement>();
            ObservableCollection<AddLineInfo> addLineCollection = new ObservableCollection<AddLineInfo>();
            ObservableCollection<ConnectIconVisibilityInfo> connectIconVisibleCollection = new ObservableCollection<ConnectIconVisibilityInfo>();
            for (int itemIndex = 0; itemIndex < _myScreenLayer.ElementCollection.Count; itemIndex++)
            {
                if (_myScreenLayer.ElementCollection[itemIndex].EleType != ElementType.receive)
                {
                    continue;
                }
                IRectElement element = (IRectElement)_myScreenLayer.ElementCollection[itemIndex];
                if (element.ConnectedIndex >= 0)
                {
                    bool isExist = false;
                    for (int i = 0; i < selectedPortCollection.Count; i++)
                    {
                        if (selectedPortCollection[i].SenderIndex == element.SenderIndex && selectedPortCollection[i].PortIndex == element.PortIndex)
                        {
                            isExist = true;
                            break;
                        }
                    }
                    if (!isExist)
                    {
                        continue;
                    }
                    ConnectIconVisibilityInfo info = new ConnectIconVisibilityInfo();
                    info.Element = element;
                    OldAndNewVisibility oldAndNewMaxmaxVisible = new OldAndNewVisibility();
                    oldAndNewMaxmaxVisible.OldValue = element.MaxConnectIndexVisibile;
                    oldAndNewMaxmaxVisible.NewValue = Visibility.Hidden;
                    OldAndNewVisibility oldAndNewMaxminVisible = new OldAndNewVisibility();
                    oldAndNewMaxminVisible.OldValue = element.MinConnectIndexVisibile;
                    oldAndNewMaxminVisible.NewValue = Visibility.Hidden;
                    info.OldAndNewMaxConnectIndexVisibile = oldAndNewMaxmaxVisible;
                    info.OldAndNewMinConnectIndexVisibile = oldAndNewMaxminVisible;
                    connectIconVisibleCollection.Add(info);

                }
            }
            for (int i = 0; i < selectedPortCollection.Count; i++)
            {
                int senderIndex = selectedPortCollection[i].SenderIndex;
                int portIndex = selectedPortCollection[i].PortIndex;

                PortConnectInfo portConnectInfo = _myScreenLayer.SenderConnectInfoList[senderIndex].PortConnectInfoList[portIndex];
                if (portConnectInfo.ConnectLineElementList != null && portConnectInfo.ConnectLineElementList.Count > 0)
                {
                    for (int m = 0; m < portConnectInfo.ConnectLineElementList.Count; m++)
                    {
                        AddLineInfo addLineInfo = new AddLineInfo();
                        addLineInfo.Element = portConnectInfo.ConnectLineElementList[m];
                        OldAndNewType oldAndNewConnect=new OldAndNewType();
                        oldAndNewConnect.OldValue=portConnectInfo.ConnectLineElementList[m].ConnectedIndex;
                        oldAndNewConnect.NewValue=-1;
                        addLineInfo.OldAndNewConnectIndex = oldAndNewConnect;
                        OldAndNewType oldAndNewSender = new OldAndNewType();
                        oldAndNewSender.OldValue = portConnectInfo.ConnectLineElementList[m].SenderIndex;
                        oldAndNewSender.NewValue = -1;
                        addLineInfo.OldAndNewSenderIndex = oldAndNewSender;
                        OldAndNewType oldAndNewPort = new OldAndNewType();
                        oldAndNewPort.OldValue = portConnectInfo.ConnectLineElementList[m].PortIndex;
                        oldAndNewPort.NewValue = -1;
                        addLineInfo.OldAndNewPortIndex = oldAndNewPort;
                        addLineCollection.Add(addLineInfo);
                        if (portConnectInfo.ConnectLineElementList[m].FrontLine != null)
                        {
                            deleteCollection.Add(portConnectInfo.ConnectLineElementList[m].FrontLine);
                            _myScreenLayer.ElementCollection.Remove(portConnectInfo.ConnectLineElementList[m].FrontLine);
                        }
                        if (portConnectInfo.ConnectLineElementList[m].EndLine != null)
                        {
                            deleteCollection.Add(portConnectInfo.ConnectLineElementList[m].EndLine);
                            _myScreenLayer.ElementCollection.Remove(portConnectInfo.ConnectLineElementList[m].EndLine);
                        }
                        portConnectInfo.ConnectLineElementList[m].ConnectedIndex = -1;
                        portConnectInfo.ConnectLineElementList[m].SenderIndex = -1;
                        portConnectInfo.ConnectLineElementList[m].PortIndex = -1;
                    }
                    portConnectInfo.ConnectLineElementList.Clear();
                }
                portConnectInfo.MaxConnectElement = null;
                portConnectInfo.MaxConnectIndex = -1;
            }
            #region 更新带载区域信息
            UpdateLoadAreaInfo();
            #endregion
            DeleteAction deleteAction = new DeleteAction(_myScreenLayer,deleteCollection);
            AddLineAction addLineAction = new AddLineAction(addLineCollection);
            ConnectIconVisibilityAction connectVisibleAction = new ConnectIconVisibilityAction(connectIconVisibleCollection);
            using (Transaction.Create(SmartLCTActionManager))
            {
                SmartLCTActionManager.RecordAction(addLineAction);
                SmartLCTActionManager.RecordAction(deleteAction);
                SmartLCTActionManager.RecordAction(connectVisibleAction);
            }
            SelectedLayerAndElementChanged();
        }
        private void OnCmdClear()
        {
            ObservableCollection<IElement> deleteCollection = new ObservableCollection<IElement>();
            ObservableCollection<ConnectIconVisibilityInfo> connectIconVisibleCollection = new ObservableCollection<ConnectIconVisibilityInfo>();
            for (int i = 0; i < _myScreenLayer.ElementCollection.Count; i++)
            {
                IElement element = _myScreenLayer.ElementCollection[i];
                deleteCollection.Add(element);
                if(element.EleType==ElementType.receive && element.ConnectedIndex>=0)
                {
                    ConnectIconVisibilityInfo info = new ConnectIconVisibilityInfo();
                    info.Element = (IRectElement)element;
                    OldAndNewVisibility maxVisible = new OldAndNewVisibility();
                    maxVisible.OldValue = info.Element.MaxConnectIndexVisibile;
                    maxVisible.NewValue = Visibility.Hidden;
                    OldAndNewVisibility minVisible = new OldAndNewVisibility();
                    minVisible.OldValue = info.Element.MinConnectIndexVisibile;
                    minVisible.NewValue = Visibility.Hidden;
                    info.OldAndNewMaxConnectIndexVisibile = maxVisible;
                    info.OldAndNewMinConnectIndexVisibile = minVisible;
                    connectIconVisibleCollection.Add(info);
                }
            }
            _myScreenLayer.ElementCollection.Clear();
            UpdateSenderAndPortConnectInfo();
            UpdateGroupframeList();
            UpdateLoadAreaInfo();
            //GetCurrentElementInfo();

            DeleteAction deleteAction = new DeleteAction(_myScreenLayer, deleteCollection);
            ConnectIconVisibilityAction connectVisibleAction = new ConnectIconVisibilityAction(connectIconVisibleCollection);
            using (Transaction.Create(SmartLCTActionManager))
            {
                SmartLCTActionManager.RecordAction(deleteAction);
                SmartLCTActionManager.RecordAction(connectVisibleAction);
            }

            SelectedLayerAndElementValue.SelectedInfoList = null;
            SelectedLayerAndElementValue.SelectedLayer = _myScreenLayer;
            SelectedLayerAndElementValue.CurrentRectElement = null;
            SelectedLayerAndElementValue.GroupframeList = _groupframeList;
            SelectedLayerAndElementValue.SelectedInfoList = _currentSelectedElement;
            SelectedLayerAndElementValue.SelectedElement.Clear();
            SelectedLayerAndElementValue.MainControlSize = new Size(this.ActualWidth, this.ActualHeight);
            Messenger.Default.Send<SelectedLayerAndElement>(SelectedLayerAndElementValue, MsgToken.MSG_SELECTEDLAYERANDELEMENT_CHANGED);
        }
        private void OnCmdArrangeScan(object sender, ExecutedRoutedEventArgs e)
        {
            //判断是否使用其他屏用过的网口(多发送卡的情况下,多个显示屏不允许共用一个网口)
            IRectLayer screenLayer = ScreenRealParams.ScreenLayer;
            while (screenLayer != null && screenLayer.EleType != ElementType.baseScreen)
            {
                screenLayer = (IRectLayer)screenLayer.ParentElement;
            }
            if (screenLayer != null)
            {
                int senderIndex=-1;
                int sendercount = Function.FindSenderCount(screenLayer.SenderConnectInfoList, out senderIndex);
                if (sendercount > 1)
                {
                    for (int i = 0; i < screenLayer.ElementCollection.Count; i++)
                    {
                        if(screenLayer.ElementCollection[i].EleType==ElementType.newLayer)
                        {
                            continue;
                        }
                        RectLayer screen=(RectLayer)(((RectLayer)screenLayer.ElementCollection[i]).ElementCollection[0]);
                        if(screen.ParentElement.ConnectedIndex==ScreenRealParams.ScreenLayer.ParentElement.ConnectedIndex)
                        {
                            continue;
                        }
                        if(screen.SenderConnectInfoList[ScreenRealParams.ScreenLayer.CurrentSenderIndex].PortConnectInfoList[ScreenRealParams.ScreenLayer.CurrentPortIndex].LoadSize.Width!=0 &&
                            screen.SenderConnectInfoList[ScreenRealParams.ScreenLayer.CurrentSenderIndex].PortConnectInfoList[ScreenRealParams.ScreenLayer.CurrentPortIndex].LoadSize.Height != 0)
                        {
                            string msg = "";
                            CommonStaticMethod.GetLanguageString("多发送卡的情况下,不允许多个屏使用同一个网口!", "Lang_PortPropPanel_CannotUserOnePort", out msg);
                            string strScr = "";
                            CommonStaticMethod.GetLanguageString("显示屏", "Lang_Global_Screen", out strScr);
                            string strWarning = "";
                            CommonStaticMethod.GetLanguageString("已经使用了该网口。", "Lang_PortPropPanel_HaveUseThisPort", out strWarning);

                            msg = msg + "\n" + strScr + " " + (screen.ParentElement.ConnectedIndex + 1).ToString() + " " + strWarning;

                            _smartLCTViewModeBase.ShowGlobalDialogMessage(msg, MessageBoxImage.Warning);
                            return;
                        }
                    }
                }
            }
            //记录连线之前的数据
            addCollection.Clear();

            ObservableCollection<AddLineInfo> beforeAddLineCollection = new ObservableCollection<AddLineInfo>();
            for (int i = 0; i < ScreenRealParams.SelectedElement.Count; i++)
            {
                AddLineInfo addlineInfo = new AddLineInfo();
                OldAndNewType oldAndNewConnect = new OldAndNewType();
                OldAndNewType oldAndNewSender = new OldAndNewType();
                OldAndNewType oldAndNewPort = new OldAndNewType();
                oldAndNewSender.OldValue = ScreenRealParams.SelectedElement[i].SenderIndex;
                oldAndNewPort.OldValue = ScreenRealParams.SelectedElement[i].PortIndex;
                oldAndNewConnect.OldValue = ScreenRealParams.SelectedElement[i].ConnectedIndex;
                addlineInfo.Element = ScreenRealParams.SelectedElement[i];
                addlineInfo.OldAndNewConnectIndex=oldAndNewConnect;
                addlineInfo.OldAndNewSenderIndex=oldAndNewSender;
                addlineInfo.OldAndNewPortIndex=oldAndNewPort;
                beforeAddLineCollection.Add(addlineInfo);
            }

            #region 记录相关
            //记下该元素的前一个元素的最大和最小连线图标是否显示
            ObservableCollection<ConnectIconVisibilityInfo> connectIconVisibleCollection = new ObservableCollection<ConnectIconVisibilityInfo>();
            IRectElement maxConnectElement = ScreenRealParams.ScreenLayer.SenderConnectInfoList[ScreenRealParams.ScreenLayer.CurrentSenderIndex].PortConnectInfoList[ScreenRealParams.ScreenLayer.CurrentPortIndex].MaxConnectElement;
            if (maxConnectElement != null)
            {
                ConnectIconVisibilityInfo info = new ConnectIconVisibilityInfo();
                info.Element = maxConnectElement;
                OldAndNewVisibility oldAndNewMaxConnectIndexVisibile = new OldAndNewVisibility();
                oldAndNewMaxConnectIndexVisibile.OldValue = maxConnectElement.MaxConnectIndexVisibile;
                OldAndNewVisibility oldAndNewMinConnectIndexVisibile = new OldAndNewVisibility();
                oldAndNewMinConnectIndexVisibile.OldValue = maxConnectElement.MinConnectIndexVisibile;
                info.OldAndNewMaxConnectIndexVisibile = oldAndNewMaxConnectIndexVisibile;
                info.OldAndNewMinConnectIndexVisibile = oldAndNewMinConnectIndexVisibile;
                connectIconVisibleCollection.Add(info);
            }
            #endregion
            ScreenPropertyPanel panel = (ScreenPropertyPanel)sender;
            ArrangeType arrangeType = (ArrangeType)e.Parameter;
            bool res = false;
            switch (arrangeType)
            {
                case ArrangeType.LeftTop_Hor: res = panel.OnArrangeLeftTopHor(); break;
                case ArrangeType.RightTop_Hor: res = panel.OnArrangeRightTopHor(); break;
                case ArrangeType.LeftBottom_Hor: res = panel.OnArrangeLeftBottomHor(); break;
                case ArrangeType.RightBottom_Hor: res = panel.OnArrangeRightBottomHor(); break;
                case ArrangeType.LeftTop_Ver: res = panel.OnArrangeLeftTopVer(); break;
                case ArrangeType.RightTop_Ver: res = panel.OnArrangeRightTopVer(); break;
                case ArrangeType.LeftBottom_Ver: res = panel.OnArrangeLeftBottomVer(); break;
                case ArrangeType.RightBottom_Ver: res = panel.OnArrangeRightBottomVer(); break;
            }

            if (!res)
            {
                return;
            }

            ObservableCollection<AddLineInfo> EndAddLineCollection = new ObservableCollection<AddLineInfo>();
            for (int j = 0; j < beforeAddLineCollection.Count; j++)
            {
                AddLineInfo addLineInfo = new AddLineInfo();
                OldAndNewType oldAndNewConnect = new OldAndNewType();
                OldAndNewType oldAndNewSender = new OldAndNewType();
                OldAndNewType oldAndNewPort = new OldAndNewType();
                oldAndNewSender.OldValue = beforeAddLineCollection[j].OldAndNewSenderIndex.OldValue;
                oldAndNewPort.OldValue = beforeAddLineCollection[j].OldAndNewPortIndex.OldValue;
                oldAndNewConnect.OldValue = beforeAddLineCollection[j].OldAndNewConnectIndex.OldValue;
                oldAndNewSender.NewValue = beforeAddLineCollection[j].Element.SenderIndex;
                oldAndNewPort.NewValue = beforeAddLineCollection[j].Element.PortIndex;
                oldAndNewConnect.NewValue = beforeAddLineCollection[j].Element.ConnectedIndex;
                addLineInfo.OldAndNewConnectIndex = oldAndNewConnect;
                addLineInfo.OldAndNewSenderIndex = oldAndNewSender;
                addLineInfo.OldAndNewPortIndex = oldAndNewPort;
                addLineInfo.Element = beforeAddLineCollection[j].Element;
                
                EndAddLineCollection.Add(addLineInfo);
            }
            ObservableCollection<IElement> addInfoCollection = new ObservableCollection<IElement>();
            for (int m = 0; m < addCollection.Count; m++)
            {
                IElement element=addCollection[m];
                addInfoCollection.Add(element);
            }

            #region 记录相关
            //记下连线后最大和最小连线图标是否显示
            for (int itemIndex = 0; itemIndex < connectIconVisibleCollection.Count; itemIndex++)
            {
                connectIconVisibleCollection[itemIndex].OldAndNewMaxConnectIndexVisibile.NewValue = connectIconVisibleCollection[itemIndex].Element.MaxConnectIndexVisibile;
                connectIconVisibleCollection[itemIndex].OldAndNewMinConnectIndexVisibile.NewValue = connectIconVisibleCollection[itemIndex].Element.MinConnectIndexVisibile;
            }
            //记下该元素最大和最小连线图标是否显示
            ConnectIconVisibilityInfo connectIconinfo = new ConnectIconVisibilityInfo();
            connectIconinfo.Element = ScreenRealParams.ScreenLayer.SenderConnectInfoList[ScreenRealParams.ScreenLayer.CurrentSenderIndex].PortConnectInfoList[ScreenRealParams.ScreenLayer.CurrentPortIndex].MaxConnectElement;
            OldAndNewVisibility oldAndNewMaxConnectIconVisibile = new OldAndNewVisibility();
            oldAndNewMaxConnectIconVisibile.OldValue = Visibility.Hidden;
            oldAndNewMaxConnectIconVisibile.NewValue = connectIconinfo.Element.MaxConnectIndexVisibile;
            OldAndNewVisibility oldAndNewMinConnectIconVisibile = new OldAndNewVisibility();
            oldAndNewMinConnectIconVisibile.OldValue = Visibility.Hidden;
            oldAndNewMinConnectIconVisibile.NewValue = connectIconinfo.Element.MinConnectIndexVisibile;
            connectIconinfo.OldAndNewMaxConnectIndexVisibile = oldAndNewMaxConnectIconVisibile;
            connectIconinfo.OldAndNewMinConnectIndexVisibile = oldAndNewMinConnectIconVisibile;
            connectIconVisibleCollection.Add(connectIconinfo);
            #endregion

            AddAction addAction = new AddAction(ScreenRealParams.ScreenLayer,addInfoCollection);
            AddLineAction addLineAction = new AddLineAction(EndAddLineCollection);
            ConnectIconVisibilityAction connectIconVisibleAction = new ConnectIconVisibilityAction(connectIconVisibleCollection);
            using (Transaction.Create(SmartLCTActionManager, true))
            {
                SmartLCTActionManager.RecordAction(addAction);
                SmartLCTActionManager.RecordAction(addLineAction);
                SmartLCTActionManager.RecordAction(connectIconVisibleAction);
            }
        }