private void SenderRealParameters_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "X" || e.PropertyName == "Y") { if (_senderCount > 1) { //if (CurrentScreen.EleType == ElementType.groupframe) //{ // //整个组在移动(记录该组中全部网口的MAP) // RectLayer screenLayer = ((RectLayer)ScreenLocationRectLayer.ElementCollection[0]); // for (int i = 0; i < screenLayer.ElementCollection.Count; i++) // { // //找到该组的元素,确定是哪个屏哪发送卡哪个网口 // IRectElement rectElement = (IRectElement)screenLayer.ElementCollection[i]; // if (rectElement.SenderIndex < 0 || rectElement.PortIndex < 0) // { // continue; // } // if (rectElement.ConnectedIndex == CurrentScreen.ConnectedIndex && // rectElement.GroupName == CurrentScreen.GroupName) // { // Point mapLocation = new Point(CurrentScreen.X,CurrentScreen.Y); // ((RectLayer)((RectLayer)MyScreen.ElementCollection[rectElement.ConnectedIndex]).ElementCollection[0]).SenderConnectInfoList[rectElement.SenderIndex].PortConnectInfoList[rectElement.PortIndex].MapLocation = mapLocation; // } // } // Function.UpdateSenderConnectInfo(((RectLayer)((RectLayer)MyScreen.ElementCollection[CurrentScreen.ConnectedIndex]).ElementCollection[0]).SenderConnectInfoList, MyScreen); //} //else if (CurrentScreen.EleType == ElementType.receive && CurrentScreen.GroupName >= 0) { //组中的某一个在移动(根据移动的距离去移动网口对应的箱体,并记录map) //看是移动一个组还是移动组中的一个 //计算原来网口的位置 SenderConnectInfo oldsenderInfo = ((RectLayer)((RectLayer)MyScreen.ElementCollection[CurrentScreen.ConnectedIndex]).ElementCollection[0]).SenderConnectInfoList[CurrentScreen.SenderIndex]; Rect senderLoadSize = oldsenderInfo.LoadSize; Point oldPortPoint = new Point(); PortConnectInfo oldPortInfo = oldsenderInfo.PortConnectInfoList[CurrentScreen.PortIndex]; oldPortPoint.X = oldPortInfo.LoadSize.X - senderLoadSize.X + oldPortInfo.MapLocation.X; oldPortPoint.Y = oldPortInfo.LoadSize.Y - senderLoadSize.Y + oldPortInfo.MapLocation.Y; //计算现在网口和原来网口对比,移动的距离 Point difPoint = new Point(CurrentScreen.X - oldPortPoint.X, CurrentScreen.Y - oldPortPoint.Y); //判断设计区域的箱体按difPoint去移动,是否超出区域,超出的距离让该发送卡的其他网口移动 Point overDifPoint = new Point(); if (oldPortInfo.LoadSize.X + difPoint.X < 0) { overDifPoint.X = -(oldPortInfo.LoadSize.X + difPoint.X); difPoint.X = -oldPortInfo.LoadSize.X; } if (oldPortInfo.LoadSize.Y + difPoint.Y < 0) { overDifPoint.Y = -(oldPortInfo.LoadSize.Y + difPoint.Y); difPoint.Y = -oldPortInfo.LoadSize.Y; } if (oldPortInfo.LoadSize.X + oldPortInfo.LoadSize.Width + difPoint.X > SmartLCTViewModeBase.MaxScreenWidth) { double oldX = difPoint.X; difPoint.X = SmartLCTViewModeBase.MaxScreenWidth - oldPortInfo.LoadSize.X - oldPortInfo.LoadSize.Width; overDifPoint.X = difPoint.X - oldX; } if (oldPortInfo.LoadSize.Y + oldPortInfo.LoadSize.Height + difPoint.Y > SmartLCTViewModeBase.MaxScreenHeight) { double oldY = difPoint.Y; difPoint.Y = SmartLCTViewModeBase.MaxScreenHeight - oldPortInfo.LoadSize.Y - oldPortInfo.LoadSize.Height; overDifPoint.Y = difPoint.Y - oldY; } //移动箱体 Function.SetElementCollectionX(oldPortInfo.ConnectLineElementList, difPoint.X); Function.SetElementCollectionY(oldPortInfo.ConnectLineElementList, difPoint.Y); //看移动的箱体都是那些组框下面的 ObservableCollection<int> groupnameList = new ObservableCollection<int>(); for (int i = 0; i < oldPortInfo.ConnectLineElementList.Count; i++) { int groupname = oldPortInfo.ConnectLineElementList[i].GroupName; if (!groupnameList.Contains(groupname)) { groupnameList.Add(groupname); } } //移动该网口的组框(先计算组框的位置和大小) RectLayer screen = ((RectLayer)((RectLayer)MyScreen.ElementCollection[CurrentScreen.ConnectedIndex]).ElementCollection[0]); for (int i = 0; i < groupnameList.Count; i++) { int groupname = groupnameList[i]; IRectElement groupElement = new RectElement(); Rect groupframeRect = new Rect(); //找到该组下的全部元素 for (int j = 0; j < screen.ElementCollection.Count; j++) { if (screen.ElementCollection[j].EleType == ElementType.groupframe && screen.ElementCollection[j].GroupName==groupname) { groupElement = (RectElement)screen.ElementCollection[j]; } else if (screen.ElementCollection[j].EleType == ElementType.receive && screen.ElementCollection[j].GroupName == groupname) { IRectElement element=(IRectElement)screen.ElementCollection[j]; Rect rect = new Rect(element.X, element.Y, element.Width, element.Height); if (groupframeRect == new Rect()) { groupframeRect = rect; } else { groupframeRect = Rect.Union(groupframeRect, rect); } } } groupElement.X = groupframeRect.X; groupElement.Y = groupframeRect.Y; groupElement.Width = groupframeRect.Width; groupElement.Height = groupframeRect.Height; } //移动其他网口的箱体(当按照difPont去移动超出区域时) if (overDifPoint.X != 0 || overDifPoint.Y != 0) { ObservableCollection<PortConnectInfo> portConnectInfoList = screen.SenderConnectInfoList[CurrentScreen.SenderIndex].PortConnectInfoList; for (int i = 0; i < portConnectInfoList.Count; i++) { if (portConnectInfoList[i].LoadSize.Width != 0 && portConnectInfoList[i].LoadSize.Height != 0 && portConnectInfoList[i].PortIndex != CurrentScreen.PortIndex) { if (overDifPoint.X != 0) Function.SetElementCollectionX(portConnectInfoList[i].ConnectLineElementList, overDifPoint.X); if (overDifPoint.Y != 0) Function.SetElementCollectionY(portConnectInfoList[i].ConnectLineElementList, overDifPoint.Y); //看移动的箱体都是那些组框下面的 ObservableCollection<int> groupnameLists = new ObservableCollection<int>(); for (int j = 0; j < portConnectInfoList[i].ConnectLineElementList.Count; j++) { int groupname = portConnectInfoList[i].ConnectLineElementList[j].GroupName; if (!groupnameLists.Contains(groupname)) { groupnameLists.Add(groupname); } } //移动组框(先计算组框的位置和大小) for (int m = 0; m < groupnameLists.Count; m++) { int groupname = groupnameLists[m]; IRectElement groupElement = new RectElement(); Rect groupframeRect = new Rect(); //找到该组下的全部元素 for (int j = 0; j < screen.ElementCollection.Count; j++) { if (screen.ElementCollection[j].EleType == ElementType.groupframe && screen.ElementCollection[j].GroupName == groupname) { groupElement = (RectElement)screen.ElementCollection[j]; } else if (screen.ElementCollection[j].EleType == ElementType.receive && screen.ElementCollection[j].GroupName == groupname) { IRectElement element = (IRectElement)screen.ElementCollection[j]; Rect rect = new Rect(element.X, element.Y, element.Width, element.Height); if (groupframeRect == new Rect()) { groupframeRect = rect; } else { groupframeRect = Rect.Union(groupframeRect, rect); } } } groupElement.X = groupframeRect.X; groupElement.Y = groupframeRect.Y; groupElement.Width = groupframeRect.Width; groupElement.Height = groupframeRect.Height; } } } } //更新组中全部网口的Map ObservableCollection<IRectElement> selectedCollection = new ObservableCollection<IRectElement>(); for (int i = 0; i < ((RectLayer)ScreenLocationRectLayer.ElementCollection[0]).ElementCollection.Count; i++) { IRectElement rectElement = (IRectElement)((RectLayer)ScreenLocationRectLayer.ElementCollection[0]).ElementCollection[i]; if (rectElement.ConnectedIndex == CurrentScreen.ConnectedIndex && rectElement.GroupName == CurrentScreen.GroupName) { if (rectElement.EleType != ElementType.groupframe) { selectedCollection.Add(rectElement); } } } Rect groupRect = Function.UnionRectCollection(selectedCollection); Point mapLocation = new Point(); mapLocation.X = groupRect.X; mapLocation.Y = groupRect.Y; for (int j = 0; j < selectedCollection.Count; j++) { ((RectLayer)((RectLayer)MyScreen.ElementCollection[selectedCollection[j].ConnectedIndex]).ElementCollection[0]).SenderConnectInfoList[selectedCollection[j].SenderIndex].PortConnectInfoList[selectedCollection[j].PortIndex].MapLocation = mapLocation; } Function.UpdateSenderConnectInfo(((RectLayer)((RectLayer)MyScreen.ElementCollection[CurrentScreen.ConnectedIndex]).ElementCollection[0]).SenderConnectInfoList, MyScreen); } else if (CurrentScreen.EleType == ElementType.receive && CurrentScreen.GroupName < 0) { //不属于某个组的单个网口在移动(记录map) Point mapLocation = new Point(CurrentScreen.X, CurrentScreen.Y); ((RectLayer)((RectLayer)MyScreen.ElementCollection[CurrentScreen.ConnectedIndex]).ElementCollection[0]).SenderConnectInfoList[CurrentScreen.SenderIndex].PortConnectInfoList[CurrentScreen.PortIndex].MapLocation = mapLocation; Function.UpdateSenderConnectInfo(((RectLayer)((RectLayer)MyScreen.ElementCollection[CurrentScreen.ConnectedIndex]).ElementCollection[0]).SenderConnectInfoList, MyScreen); } } else if (_senderCount == 1) { #region 单卡 //是哪个卡 int currentSenderIndex = -1; for (int n = 0; n < MyScreen.SenderConnectInfoList.Count; n++) { if (MyScreen.SenderConnectInfoList[n].LoadSize.Height != 0 && MyScreen.SenderConnectInfoList[n].LoadSize.Width != 0) { currentSenderIndex = n; break; } } if (currentSenderIndex >= 0) { //更新带载 //保存显示屏映射位置 for (int i = 0; i < ScreenMapRealParametersValue.RectLayerCollection.Count; i++) { Point mapLocation = new Point(); mapLocation.X = ((IRectElement)ScreenMapRealParametersValue.RectLayerCollection[i]).X; mapLocation.Y = ((IRectElement)ScreenMapRealParametersValue.RectLayerCollection[i]).Y; //找到相应的显示屏 for (int j = 0; j < MyScreen.ElementCollection.Count; j++) { if (MyScreen.ElementCollection[j].ConnectedIndex == ScreenMapRealParametersValue.RectLayerCollection[i].ConnectedIndex) { RectLayer screenRectLayer = ((RectLayer)(((RectLayer)MyScreen.ElementCollection[j]).ElementCollection[0])); for (int m = 0; m < screenRectLayer.SenderConnectInfoList[currentSenderIndex].PortConnectInfoList.Count; m++) { PortConnectInfo portInfo = screenRectLayer.SenderConnectInfoList[currentSenderIndex].PortConnectInfoList[m]; portInfo.MapLocation = mapLocation; } //screenRectLayer.SenderConnectInfoList[0].MapLocation = mapLocation; Function.UpdateSenderConnectInfo(screenRectLayer.SenderConnectInfoList, screenRectLayer); break; } } } //保存DVI MyScreen.SenderConnectInfoList[0].DviSize = new Size(ScreenMapRealParametersValue.SenderLoadRectLayer.Width, ScreenMapRealParametersValue.SenderLoadRectLayer.Height); #endregion } } } }
private void OnCreateScreenWithConfigurationData(ConfigurationData data) { string projectPath = data.ProjectLocationPath + "\\" + data.ProjectName + SmartLCTViewModeBase.ProjectExtension; if (data.OperateType == OperateScreenType.CreateScreenAndOpenConfigFile) { OpenConfigFileAndHandleData(projectPath); return; } SelectedLayerAndElement selectedLayerAndElement = new SelectedLayerAndElement(); ObservableCollection<IRectElement> selectedElementCollection = new ObservableCollection<IRectElement>(); Dictionary<int, IRectElement> groupframeList = new Dictionary<int, IRectElement>(); RectLayer screen = (RectLayer)SelectedValue.ElementCollection[0]; if (data.IsCreateEmptyProject) { // 创建空工程 return; } CurrentSenderConfigInfo = data.SelectedSenderConfigInfo; //更新发送卡连线数据 MyScreen.SenderConnectInfoList.Clear(); ObservableCollection<PortConnectInfo> portConnectList = new ObservableCollection<PortConnectInfo>(); for (int i = 0; i < CurrentSenderConfigInfo.PortCount; i++) { portConnectList.Add(new PortConnectInfo(i, 0, -1, null, null, new Rect())); } MyScreen.SenderConnectInfoList.Add(new SenderConnectInfo(0, portConnectList, new Rect())); #region 添加接收卡 ObservableCollection<IElement> addCollection = new ObservableCollection<IElement>(); Point pointInCanvas = new Point(0, 0); int cols = data.Cols; int rows = data.Rows; ScannerCofigInfo scanConfig = data.SelectedScannerConfigInfo; ScanBoardProperty scanBdProp = scanConfig.ScanBdProp; int width = scanBdProp.Width; int height = scanBdProp.Height; //每个网口行的整数倍和列的整数倍 double rowIndex = -1; double colIndex = -1; //需要多少网口可以带载完 Size portLoadPoint = Function.CalculatePortLoadSize(60, 24); double portLoadSize = portLoadPoint.Height * portLoadPoint.Width; //1、需要几个网口 double portCount = Math.Ceiling(rows * cols / (portLoadSize / (height * width))); //2、计算每个网口的行列数(水平串线则是列的整数倍,垂直串线则是行的整数倍) while (true) { if (data.SelectedArrangeType == ArrangeType.LeftBottom_Hor || data.SelectedArrangeType == ArrangeType.LeftTop_Hor || data.SelectedArrangeType == ArrangeType.RightBottom_Hor || data.SelectedArrangeType == ArrangeType.RightTop_Hor)//水平串线 { rowIndex = Math.Ceiling(rows * cols / portCount / cols); if (rowIndex * cols * height * width > portLoadSize) { portCount += 1; if (portCount > data.SelectedSenderConfigInfo.PortCount) { string msg = ""; CommonStaticMethod.GetLanguageString("超出带载,请重新设置!", "Lang_ScanBoardConfigManager_OverLoad", out msg); ShowGlobalDialogMessage(msg, MessageBoxImage.Warning); return; } } else { break; } } else { colIndex = Math.Ceiling(rows * cols / portCount / rows); if (colIndex * rows * height * width > portLoadSize) { portCount += 1; if (portCount > data.SelectedSenderConfigInfo.PortCount) { string msg = ""; CommonStaticMethod.GetLanguageString("超出带载,请重新设置!", "Lang_ScanBoardConfigManager_OverLoad", out msg); ShowGlobalDialogMessage(msg, MessageBoxImage.Warning); return; } } else { break; } } } RectElement groupframe; if (cols == 1 && rows == 1) { groupframe = new RectElement(0, 0, width * cols, height * rows, null, -1); RectElement rectElement = new RectElement(0, 0, width * cols, height * rows, screen, screen.MaxZorder + 1); rectElement.EleType = ElementType.receive; screen.MaxZorder += 1; rectElement.Tag = scanConfig.Clone(); rectElement.IsLocked = true; rectElement.ZIndex = 4; rectElement.GroupName = -1; rectElement.ElementSelectedState = SelectedState.None; rectElement.SenderIndex = 0; rectElement.PortIndex = 0; screen.ElementCollection.Add(rectElement); selectedElementCollection.Add(rectElement); addCollection.Add(rectElement); } else { for (int i = 0; i < cols; i++) { for (int j = 0; j < rows; j++) { RectElement rectElement = new RectElement(width * i, height * j, width, height, screen, screen.MaxZorder + 1); rectElement.EleType = ElementType.receive; screen.MaxZorder += 1; rectElement.Tag = scanConfig.Clone(); rectElement.IsLocked = true; rectElement.ZIndex = 4; rectElement.ElementSelectedState = SelectedState.None; rectElement.SenderIndex = 0; if (rowIndex != -1) { rectElement.PortIndex = (int)Math.Ceiling((j + 1) / rowIndex) - 1; } else if (colIndex != -1) { rectElement.PortIndex = (int)Math.Ceiling((i + 1) / colIndex) - 1; } screen.ElementCollection.Add(rectElement); addCollection.Add(rectElement); selectedElementCollection.Add(rectElement); } } } ////记录添加 //AddAction addAction = new AddAction(SelectedScreenLayer, addCollection); //SmartLCTActionManager.RecordAction(addAction); Dictionary<int, ObservableCollection<IRectElement>> eachPortElement = new Dictionary<int, ObservableCollection<IRectElement>>(); for (int j = 0; j < portCount; j++) { eachPortElement.Add(j, new ObservableCollection<IRectElement>()); } for (int i = 0; i < selectedElementCollection.Count; i++) { eachPortElement[selectedElementCollection[i].PortIndex].Add(selectedElementCollection[i]); } foreach (int key in eachPortElement.Keys) { if (eachPortElement[key].Count == 0) { continue; } ScreenRealParameters screenRealPara = new ScreenRealParameters(); screen.CurrentPortIndex = key; screen.CurrentSenderIndex = 0; screenRealPara.ScreenLayer = screen; screenRealPara.SelectedElement = eachPortElement[key]; #region 每个网口添加组框 Rect groupRect = new Rect(); for (int i = 0; i < screenRealPara.SelectedElement.Count; i++) { IRectElement rectElement = screenRealPara.SelectedElement[i]; rectElement.GroupName = screen.MaxGroupName + 1; Rect rect = new Rect(rectElement.X, rectElement.Y, rectElement.Width, rectElement.Height); if (i == 0) { groupRect = rect; } groupRect = Rect.Union(groupRect, rect); } groupframe = new RectElement(groupRect.X, groupRect.Y, groupRect.Width, groupRect.Height, screen, screen.MaxZorder + 1); groupframe.EleType = ElementType.groupframe; groupframe.ZIndex = 5; groupframe.GroupName = screen.MaxGroupName + 1; screen.MaxGroupName += 1; screen.MaxZorder += 1; groupframe.ElementSelectedState = SelectedState.SelectedAll; groupframeList.Add(groupframe.GroupName, groupframe); screen.ElementCollection.Add(groupframe); #endregion ScreenRealParametersValue = screenRealPara; SelectedArrangeType = data.SelectedArrangeType; IsConnectLine = !IsConnectLine; } #endregion }
/// <summary> /// 切换设计界面和调整映射位置界面 /// </summary> private void OnSelectedEnvironmentChanged() { List<int> senderIndexList = new List<int>(); int senderIndex; _oldSenderCount = _senderCount; int senderCount = Function.FindSenderCount(MyScreen.SenderConnectInfoList, out senderIndex); _senderCount = senderCount; if (_oldSenderCount != senderCount) { //发送卡个数更改,则map置为初始值 for (int i = 0; i < MyScreen.ElementCollection.Count; i++) { if (MyScreen.ElementCollection[i].EleType == ElementType.newLayer) { continue; } RectLayer screen = (RectLayer)((RectLayer)MyScreen.ElementCollection[i]).ElementCollection[0]; Function.InitMapLocation(screen); } } if (SelectedEnvironMentIndex == 0) { ScreenMapLocationVisible = Visibility.Collapsed; SenderVisible = Visibility.Collapsed; ScanVisible = Visibility.Collapsed; CustomScanVisible = Visibility.Collapsed; if (MyScreen!=null && MyScreen.ElementCollection!=null) { if (MyScreen.ElementCollection.Count <= 1) { ScreenVisible = Visibility.Collapsed; } else { ScreenVisible = Visibility.Visible; } } else { ScreenVisible = Visibility.Collapsed; } PleaseSelElmentVisible = Visibility.Hidden; } else if (SelectedEnvironMentIndex == 1) { //查看用了多少个发送卡 #region 单发送卡 if (senderCount == 0) { ScreenVisible = Visibility.Collapsed; ScanVisible = Visibility.Collapsed; CustomScanVisible = Visibility.Collapsed; PleaseSelElmentVisible = Visibility.Hidden; SenderVisible = Visibility.Collapsed; ScreenMapLocationVisible = Visibility.Collapsed; ScreenLocationRectLayer = new RectLayer(0, 0, SmartLCTViewModeBase.DviViewBoxWidth, SmartLCTViewModeBase.DviViewBoxHeight, null, 0, ElementType.baselayer, 0); } else if (senderCount == 1) { ScreenMapLocationVisible = Visibility.Visible; ScreenVisible = Visibility.Collapsed; ScanVisible = Visibility.Collapsed; CustomScanVisible = Visibility.Collapsed; PleaseSelElmentVisible = Visibility.Hidden; int selectedIndex = -1; for (int i = 0; i < ScreenMapRealParametersValue.RectLayerCollection.Count; i++) { if (ScreenMapRealParametersValue.RectLayerCollection[i].ElementSelectedState != SelectedState.None) { selectedIndex = ScreenMapRealParametersValue.RectLayerCollection[i].ConnectedIndex; break; } } #region 显示屏映射(测试界面数据) ScreenLocationRectLayer.ElementCollection.Clear(); RectLayer screenLocationRectLayer = new RectLayer(0, 0, SmartLCTViewModeBase.DviViewBoxWidth, SmartLCTViewModeBase.DviViewBoxHeight, null, 0, ElementType.baselayer, 0); screenLocationRectLayer.OperateEnviron = OperatEnvironment.AdjustScreenLocation; //显示屏移动区域的Layer(没有DVI则由发送卡最大带载决定) Size screenLayerSize = MyScreen.SenderConnectInfoList[senderIndex].DviSize; RectLayer screenBaseRectLayer = new RectLayer(0, 0, screenLayerSize.Width, screenLayerSize.Height, screenLocationRectLayer, 0, ElementType.screen, 0); screenBaseRectLayer.OperateEnviron = OperatEnvironment.AdjustScreenLocation; //由每个屏的发送卡带载生成各个显示屏带载 for (int i = 0; i < MyScreen.ElementCollection.Count; i++) { if (MyScreen.ElementCollection[i].ConnectedIndex < 0) { continue; } RectLayer screenRectLayer = ((RectLayer)(((RectLayer)MyScreen.ElementCollection[i]).ElementCollection[0])); Rect screenRect = screenRectLayer.SenderConnectInfoList[senderIndex].LoadSize; Point screenMapLocation = new Point(); for (int n = 0; n < screenRectLayer.SenderConnectInfoList[senderIndex].PortConnectInfoList.Count; n++) { if (screenRectLayer.SenderConnectInfoList[senderIndex].PortConnectInfoList[n].LoadSize.Width != 0 && screenRectLayer.SenderConnectInfoList[senderIndex].PortConnectInfoList[n].LoadSize.Height != 0) { screenMapLocation = screenRectLayer.SenderConnectInfoList[senderIndex].PortConnectInfoList[n].MapLocation; break; } } if (screenRect.Width == 0 || screenRect.Height == 0) { continue; } RectElement screen = new RectElement(screenMapLocation.X, screenMapLocation.Y, screenRect.Width, screenRect.Height, screenBaseRectLayer, i); screen.OperateEnviron = OperatEnvironment.AdjustScreenLocation; screen.ConnectedIndex = MyScreen.ElementCollection[i].ConnectedIndex; screen.Opacity = 0.5; string msg = ""; CommonStaticMethod.GetLanguageString("显示屏", "Lang_Global_Screen", out msg); screen.DisplayName = msg + (screen.ConnectedIndex + 1); screenBaseRectLayer.ElementCollection.Add(screen); } screenLocationRectLayer.ElementCollection.Add(screenBaseRectLayer); screenLocationRectLayer.SenderIndex = senderIndex; int increaseOrDecreaseIndex = GetIncreaseOrDecreaseIndex(senderIndex, ((RectLayer)screenLocationRectLayer.ElementCollection[0])); ((RectLayer)screenLocationRectLayer.ElementCollection[0]).IncreaseOrDecreaseIndex = increaseOrDecreaseIndex; Point newLocation=GetDviCenterPoint(increaseOrDecreaseIndex, ((RectLayer)screenLocationRectLayer.ElementCollection[0])); ((RectLayer)screenLocationRectLayer.ElementCollection[0]).X = newLocation.X; ((RectLayer)screenLocationRectLayer.ElementCollection[0]).Y = newLocation.Y; ScreenLocationRectLayer = screenLocationRectLayer; MyScreen.SenderConnectInfoList[senderIndex].IncreaseOrDecreaseIndex = increaseOrDecreaseIndex; MyScreen.SenderConnectInfoList[senderIndex].IsStatIncreaseOrDecreaseIndex = true; ScreenMapLocationVisible = Visibility.Visible; ScreenMapRealParameters p = new ScreenMapRealParameters(); p.SenderLoadRectLayer = screenBaseRectLayer; p.RectLayerCollection = screenBaseRectLayer.ElementCollection; p.RectLayerType = ElementType.screen; if (screenBaseRectLayer.ElementCollection.Count != 0) { if (selectedIndex != -1) { int realIndex = -1; for (int i = 0; i < screenBaseRectLayer.ElementCollection.Count; i++) { if (screenBaseRectLayer.ElementCollection[i].ConnectedIndex == selectedIndex) { realIndex = i; break; } } if (realIndex != -1) { SenderRealParameters senderRealPara = new SenderRealParameters(); senderRealPara.Element = (IRectElement)screenBaseRectLayer.ElementCollection[realIndex]; senderRealPara.Element.ElementSelectedState = SelectedState.Selected; senderRealPara.EleType = ElementType.screen; SenderRealParametersValue = senderRealPara; SenderVisible = Visibility.Visible; } else { SenderVisible = Visibility.Collapsed; } } else { SenderVisible = Visibility.Collapsed; } } else { SenderVisible = Visibility.Collapsed; } ScreenMapRealParametersValue = p; PleaseSelElmentVisible = Visibility.Hidden; #endregion } #endregion #region 多发送卡 else if (senderCount > 1) { #region 选中的网口 IRectElement selectedPort = new RectElement(); if (_currentScreen != null) { selectedPort.SenderIndex = _currentScreen.SenderIndex; selectedPort.PortIndex = _currentScreen.PortIndex; selectedPort.OperateEnviron = OperatEnvironment.AdjustSenderLocation; selectedPort.ConnectedIndex = _currentScreen.ConnectedIndex; } if (selectedPort.SenderIndex >= 0 && selectedPort.PortIndex < 0) { RectLayer screenLayer = (RectLayer)((RectLayer)MyScreen.ElementCollection[selectedPort.ConnectedIndex]).ElementCollection[0]; ObservableCollection<PortConnectInfo> portConnectInfoList = screenLayer.SenderConnectInfoList[selectedPort.SenderIndex].PortConnectInfoList; for (int m = 0; m < portConnectInfoList.Count; m++) { if (portConnectInfoList[m].LoadSize.Height == 0 && portConnectInfoList[m].LoadSize.Width == 0) { continue; } selectedPort.PortIndex = m; break; } } else if (selectedPort.SenderIndex < 0 && selectedPort.PortIndex < 0) { for (int i = 0; i < MyScreen.ElementCollection.Count; i++) { if (selectedPort.SenderIndex >= 0 && selectedPort.PortIndex >= 0) { break; } if (MyScreen.ElementCollection[i].EleType == ElementType.newLayer) { continue; } RectLayer screenLayer = (RectLayer)((RectLayer)MyScreen.ElementCollection[i]).ElementCollection[0]; for (int j = 0; j < screenLayer.SenderConnectInfoList.Count; j++) { if (selectedPort.SenderIndex >= 0 && selectedPort.PortIndex >= 0) { break; } if (screenLayer.SenderConnectInfoList[j].LoadSize.Height == 0 && screenLayer.SenderConnectInfoList[j].LoadSize.Width == 0) { continue; } ObservableCollection<PortConnectInfo> portConnectInfoList = screenLayer.SenderConnectInfoList[j].PortConnectInfoList; for (int m = 0; m < portConnectInfoList.Count; m++) { if (portConnectInfoList[m].LoadSize.Height == 0 && portConnectInfoList[m].LoadSize.Width == 0) { continue; } selectedPort = new RectElement(); selectedPort.ConnectedIndex = i; selectedPort.SenderIndex = j; selectedPort.PortIndex = m; break; } } } } #endregion ScreenMapLocationVisible = Visibility.Visible; ScreenVisible = Visibility.Collapsed; ScanVisible = Visibility.Collapsed; CustomScanVisible = Visibility.Collapsed; PleaseSelElmentVisible = Visibility.Hidden; #region 全部发送卡的带载(用于缩略图的大小) Rect senderLoadSizeSum = new Rect(); for (int i = 0; i < MyScreen.SenderConnectInfoList.Count; i++) { if (MyScreen.SenderConnectInfoList[i].LoadSize.Height == 0 && MyScreen.SenderConnectInfoList[i].LoadSize.Width == 0) { continue; } if (senderLoadSizeSum == new Rect()) { senderLoadSizeSum = MyScreen.SenderConnectInfoList[i].LoadSize; } else { senderLoadSizeSum = Rect.Union(senderLoadSizeSum, MyScreen.SenderConnectInfoList[i].LoadSize); } } #endregion #region 缩略图数据 RectLayer senderMapRectLayer = new RectLayer(0, 0, senderLoadSizeSum.Width, senderLoadSizeSum.Height, null, 0, ElementType.baselayer, 0); senderMapRectLayer.OperateEnviron = OperatEnvironment.AdjustSenderLocation; RectLayer screenBaseRectLayer = new RectLayer(0, 0, senderLoadSizeSum.Width, senderLoadSizeSum.Height, senderMapRectLayer, 0, ElementType.screen, 0); screenBaseRectLayer.OperateEnviron = OperatEnvironment.AdjustSenderLocation; //每个发送卡在所有显示屏中的网口带载 生成显示屏(缩略图中显示所有发送卡的网口) for (int m = 0; m < MyScreen.SenderConnectInfoList.Count; m++) { //发送卡m在所有显示屏中的网口带载 for (int i = 0; i < MyScreen.ElementCollection.Count; i++) { if (MyScreen.ElementCollection[i].EleType == ElementType.newLayer) { continue; } RectLayer screenLayer = (RectLayer)((RectLayer)MyScreen.ElementCollection[i]).ElementCollection[0]; if (screenLayer.SenderConnectInfoList[m].LoadSize.Width == 0 && screenLayer.SenderConnectInfoList[m].LoadSize.Height == 0) { continue; } Rect senderLoadSize = screenLayer.SenderConnectInfoList[m].LoadSize; ObservableCollection<PortConnectInfo> portConnectInfoList = screenLayer.SenderConnectInfoList[m].PortConnectInfoList; ObservableCollection<IRectElement> portScreenCollection = new ObservableCollection<IRectElement>(); for (int n = 0; n < portConnectInfoList.Count; n++) { Rect portRect = portConnectInfoList[n].LoadSize; if (portRect.Width == 0 && portRect.Height == 0) { continue; } Point portMapLocation = portConnectInfoList[n].MapLocation; RectElement portScreen = new RectElement(portRect.X - senderLoadSize.X + portMapLocation.X, portRect.Y - senderLoadSize.Y + portMapLocation.Y, portRect.Width, portRect.Height, screenBaseRectLayer, screenBaseRectLayer.MaxZorder + 1); screenBaseRectLayer.MaxZorder += 1; portScreen.OperateEnviron = OperatEnvironment.AdjustSenderLocation; portScreen.ConnectedIndex = MyScreen.ElementCollection[i].ConnectedIndex; portScreen.SenderIndex = m; portScreen.PortIndex = portConnectInfoList[n].PortIndex; portScreen.DisplayName = GetMultiSenderDisplayString(portScreen.ConnectedIndex + 1, portScreen.SenderIndex + 1, portScreen.PortIndex + 1); screenBaseRectLayer.ElementCollection.Add(portScreen); portScreenCollection.Add(portScreen); } //一个显示屏使用了一个发送卡的多个网口,则生成的带载显示屏成为一个组(因为一个屏里一个发送卡的网口之间的相对位置是有效的) if (portScreenCollection.Count > 1) { Rect groupRect = Function.UnionRectCollection(portScreenCollection); RectElement groupElement = new RectElement(groupRect.X, groupRect.Y, groupRect.Width, groupRect.Height, screenBaseRectLayer, screenBaseRectLayer.MaxZorder + 1); screenBaseRectLayer.MaxZorder += 1; groupElement.EleType = ElementType.groupframe; groupElement.GroupName = screenBaseRectLayer.MaxGroupName + 1; screenBaseRectLayer.MaxGroupName += 1; groupElement.OperateEnviron = OperatEnvironment.DesignScreen; groupElement.ConnectedIndex = MyScreen.ElementCollection[i].ConnectedIndex; groupElement.SenderIndex = m; screenBaseRectLayer.ElementCollection.Add(groupElement); for (int j = 0; j < portScreenCollection.Count; j++) { portScreenCollection[j].GroupName = groupElement.GroupName; } } } } senderMapRectLayer.ElementCollection.Add(screenBaseRectLayer); SenderVisible = Visibility.Visible; #endregion #region 选中网口 RectElement currentSelectedScreen = new RectElement(); Size sender1LoadSize = MyScreen.SenderConnectInfoList[selectedPort.SenderIndex].DviSize; ScreenLocationRectLayer.ElementCollection.Clear(); RectLayer screenLocationRectLayer = new RectLayer(0, 0, SmartLCTViewModeBase.DviViewBoxWidth, SmartLCTViewModeBase.DviViewBoxHeight, null, 0, ElementType.baselayer, -1); screenLocationRectLayer.OperateEnviron = OperatEnvironment.AdjustSenderLocation; RectLayer screenBaseloaRectLayer = new RectLayer(0, 0, sender1LoadSize.Width, sender1LoadSize.Height, screenLocationRectLayer, 0, ElementType.screen, -1); screenBaseloaRectLayer.OperateEnviron = OperatEnvironment.AdjustSenderLocation; ObservableCollection<IRectElement> portCollection = new ObservableCollection<IRectElement>(); for (int j = 0; j < screenBaseRectLayer.ElementCollection.Count; j++) { IRectElement currentPortScreen = (IRectElement)screenBaseRectLayer.ElementCollection[j]; if (currentPortScreen.PortIndex < 0) { continue; } if (currentPortScreen.SenderIndex == selectedPort.SenderIndex && currentPortScreen.PortIndex == selectedPort.PortIndex) { RectLayer currentScreen = (RectLayer)((RectLayer)MyScreen.ElementCollection[currentPortScreen.ConnectedIndex]).ElementCollection[0]; RectElement e = (RectElement)((RectElement)screenBaseRectLayer.ElementCollection[j]).Clone(); e.ParentElement = screenBaseloaRectLayer; screenBaseRectLayer.ElementCollection[j].ElementSelectedState = SelectedState.Selected; e.ElementSelectedState = SelectedState.Selected; e.EleType = ElementType.receive; e.DisplayName = GetMultiSenderDisplayString(e.ConnectedIndex + 1, e.SenderIndex + 1, e.PortIndex + 1); screenBaseloaRectLayer.ElementCollection.Add(e); portCollection.Add(e); SenderRealParameters senderRealPara = new SenderRealParameters(); senderRealPara.Element = e; senderRealPara.EleType = ElementType.port; SenderRealParametersValue = senderRealPara; //网口基本信息 currentSelectedScreen = e; } else if (currentPortScreen.SenderIndex == selectedPort.SenderIndex) { RectLayer currentScreen = (RectLayer)((RectLayer)MyScreen.ElementCollection[currentPortScreen.ConnectedIndex]).ElementCollection[0]; RectElement e = (RectElement)((RectElement)screenBaseRectLayer.ElementCollection[j]).Clone(); e.ParentElement = screenBaseloaRectLayer; e.EleType = ElementType.receive; e.DisplayName = GetMultiSenderDisplayString(e.ConnectedIndex + 1, e.SenderIndex + 1, e.PortIndex + 1); screenBaseloaRectLayer.ElementCollection.Add(e); } } for (int m = 0; m < screenBaseRectLayer.ElementCollection.Count; m++) { if (screenBaseRectLayer.ElementCollection[m].EleType == ElementType.groupframe) { ObservableCollection<IRectElement> portList = new ObservableCollection<IRectElement>(); for (int j = 0; j < screenBaseloaRectLayer.ElementCollection.Count; j++) { //同一个屏下面的同一张发送卡下的网口用组框框起来 if (((IRectElement)screenBaseloaRectLayer.ElementCollection[j]).ConnectedIndex == screenBaseRectLayer.ElementCollection[m].ConnectedIndex && ((IRectElement)screenBaseloaRectLayer.ElementCollection[j]).SenderIndex == ((IRectElement)screenBaseRectLayer.ElementCollection[m]).SenderIndex) { portList.Add((IRectElement)screenBaseloaRectLayer.ElementCollection[j]); } } if (portList.Count < 2) { continue; } Rect groupRect = Function.UnionRectCollection(portList); RectElement groupElement = (RectElement)((RectElement)screenBaseRectLayer.ElementCollection[m]).Clone(); groupElement.X = groupRect.X; groupElement.Y = groupRect.Y; groupElement.Width = groupRect.Width; groupElement.Height = groupRect.Height; groupElement.ParentElement = screenBaseloaRectLayer; screenBaseloaRectLayer.ElementCollection.Add(groupElement); } } screenLocationRectLayer.ElementCollection.Add(screenBaseloaRectLayer); screenLocationRectLayer.SenderIndex = selectedPort.SenderIndex; int increaseOrDecreaseIndex = GetIncreaseOrDecreaseIndex(selectedPort.SenderIndex, ((RectLayer)screenLocationRectLayer.ElementCollection[0])); ((RectLayer)screenLocationRectLayer.ElementCollection[0]).IncreaseOrDecreaseIndex = increaseOrDecreaseIndex; Point newLocation = GetDviCenterPoint(increaseOrDecreaseIndex, ((RectLayer)screenLocationRectLayer.ElementCollection[0])); ((RectLayer)screenLocationRectLayer.ElementCollection[0]).X = newLocation.X; ((RectLayer)screenLocationRectLayer.ElementCollection[0]).Y = newLocation.Y; ScreenLocationRectLayer = screenLocationRectLayer; MyScreen.SenderConnectInfoList[selectedPort.SenderIndex].IncreaseOrDecreaseIndex = increaseOrDecreaseIndex; MyScreen.SenderConnectInfoList[selectedPort.SenderIndex].IsStatIncreaseOrDecreaseIndex = true; ScreenMapRealParameters p = new ScreenMapRealParameters(); p.SenderLoadRectLayer = screenBaseloaRectLayer; p.RectLayerCollection = screenBaseRectLayer.ElementCollection; p.RectLayerType = ElementType.sender; ScreenMapRealParametersValue = p; CurrentScreen = currentSelectedScreen; #endregion PleaseSelElmentVisible = Visibility.Hidden; } //开始设置映射位置 for (int i = 0; i < MyScreen.ElementCollection.Count; i++) { if (MyScreen.ElementCollection[i].EleType == ElementType.newLayer) { continue; } RectLayer screenlayer = (RectLayer)((RectLayer)MyScreen.ElementCollection[i]).ElementCollection[0]; } #endregion Function.UpdateSenderConnectInfo(MyScreen.SenderConnectInfoList, MyScreen); } }
/// <summary> /// 更改某个元素的位置后,该元素处于某个组时,处理该元素组框的位置 /// </summary> /// <param name="element"></param> private void OnHandleGroupFrameLocation(IRectElement element) { #region 移动的网口属于某个组,则处理组框的位置 if (element.EleType == ElementType.receive && element.GroupName >= 0) { //找到该组下所有的元素 IRectElement groupFrame = new RectElement(); ObservableCollection<IRectElement> elementCollection = new ObservableCollection<IRectElement>(); if (element.ParentElement != null && element.ParentElement.EleType == ElementType.screen) { RectLayer screenLayer = (RectLayer)element.ParentElement; for (int i = 0; i < screenLayer.ElementCollection.Count; i++) { if (screenLayer.ElementCollection[i].EleType == ElementType.receive && screenLayer.ElementCollection[i].GroupName == element.GroupName) { elementCollection.Add((IRectElement)screenLayer.ElementCollection[i]); } else if (screenLayer.ElementCollection[i].EleType == ElementType.groupframe && screenLayer.ElementCollection[i].GroupName == element.GroupName) { groupFrame = (IRectElement)screenLayer.ElementCollection[i]; } } } //计算组框新值 if (elementCollection.Count > 0) { Rect newGroupframeRect = Function.UnionRectCollection(elementCollection); groupFrame.X = newGroupframeRect.X; groupFrame.Y = newGroupframeRect.Y; groupFrame.Width = newGroupframeRect.Width; groupFrame.Height = newGroupframeRect.Height; } } #endregion }
private void OnRecordActionValueChanged(PrePropertyChangedEventArgs e) { RectElement rectElement = new RectElement(); //RectLayerChangedAction action; //action = new RectLayerChangedAction(MyRectLayer, e.PropertyName, ((RectLayer)e.NewValue).ElementCollection, ((RectLayer)e.OldValue).ElementCollection); //SmartLCTActionManager.RecordAction(action); }
public object Clone() { RectElement newObj = new RectElement(); bool res = this.CopyTo(newObj); if (!res) { return null; } else { return newObj; } }
private void _itemsControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (MyRectLayer.ElementCollection.Count == 0) { e.Handled = true; return; } #region 添加接收卡 ObservableCollection<IElement> addCollection = new ObservableCollection<IElement>(); ObservableCollection<ElementSizeInfo> elementSizeCollection = new ObservableCollection<ElementSizeInfo>(); if (_addReceiveInfo != null && MyRectLayer.ElementCollection.Count != 0 && _myScreenLayer.OperateEnviron == OperatEnvironment.DesignScreen) { _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 if (_myScreenLayer != null) { Function.SetElementCollectionState(_myScreenLayer.ElementCollection, SelectedState.None); } if (MyRectLayer == null || MyRectLayer.ElementCollection.Count == 0) { return; } _myScreenLayer = (RectLayer)MyRectLayer.ElementCollection[0]; _mousePoint = this.TranslatePoint(e.GetPosition(this), _itemsControl); CurrentRectElement = null; _isMouseLeftButtonDown = true; GetCurrentElementInfo(); SelectedLayerAndElementValue.SelectedLayer = _myScreenLayer; SelectedLayerAndElementValue.GroupframeList = _groupframeList; SelectedLayerAndElementValue.SelectedInfoList = _currentSelectedElement; SelectedLayerAndElementValue.MainControlSize = new Size(this.ActualWidth, this.ActualHeight); Messenger.Default.Send<SelectedLayerAndElement>(SelectedLayerAndElementValue, MsgToken.MSG_SELECTEDLAYERANDELEMENT_CHANGED); //e.Handled = true; }
private void OnCmdPaste() { ObservableCollection<IElement> addCollection = new ObservableCollection<IElement>(); Function.SetElementCollectionState(_selectedElementCollection, SelectedState.None); Rect unionRect = Function.UnionRectCollection(_selectedElementCollection); _selectedElementCollection.Clear(); Point startPoint = new Point(); if(_keyInfo.Count==2 && (_keyInfo.Contains(Key.LeftCtrl)|| _keyInfo.Contains(Key.RightCtrl)) && _keyInfo.Contains(Key.V) ) { if (_copyPoint.X == -1 && _copyPoint.Y == -1) //键盘操作 { startPoint.X = unionRect.Left + 10; startPoint.Y = unionRect.Top + 10; } else { startPoint = this.TranslatePoint(_copyPoint, _itemsControl); } } else { startPoint = this.TranslatePoint(_copyPoint, _itemsControl); } Rect copyUnionRect = Function.UnionRectCollection(_copyElementCollection); for (int elementIndex = 0; elementIndex < _copyElementCollection.Count; elementIndex++) { IRectElement element = _copyElementCollection[elementIndex]; RectElement rectElement = new RectElement(); rectElement = new RectElement(startPoint.X + (element.X - copyUnionRect.Left), startPoint.Y + (element.Y - copyUnionRect.Top), element.Width, element.Height, _myScreenLayer, _myScreenLayer.MaxZorder + 1); rectElement.EleType = ElementType.receive; _myScreenLayer.MaxZorder += 1; rectElement.IsLocked = true; rectElement.ZIndex = 7; rectElement.GroupName = -1; rectElement.ElementSelectedState = SelectedState.Selected; _selectedElementCollection.Add(rectElement); _myScreenLayer.ElementCollection.Add(rectElement); addCollection.Add(rectElement); } AddAction addAction = new AddAction(_myScreenLayer,addCollection); SmartLCTActionManager.RecordAction(addAction); GetCurrentElementInfo(); }
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; }
public bool CopyTo(object obj) { if (!(obj is LineElement)) { return false; } LineElement temp = (LineElement)obj; temp.BackgroundBrush = this.BackgroundBrush; temp.CenterX = this.CenterX; temp.CenterY = this.CenterY; temp.ElementSelectedState = this.ElementSelectedState; temp.Height = this.Height; temp.IsLocked = this.IsLocked; temp.IsOutlineDisplay = this.IsOutlineDisplay; temp.StartAndEndIconMargin = this.StartAndEndIconMargin; //temp.LockVisible = this.LockVisible; temp.Margin = this.Margin; temp.Opacity = this.Opacity; temp.OutlineBrush = this.OutlineBrush; temp.Visible = this.Visible; temp.Width = this.Width; temp.X = this.FrontElement.X + this.FrontElement.Width / 2; temp.Y = this.FrontElement.Y + this.FrontElement.Height / 2; temp.ZOrder = this.ZOrder; temp.EndX = this.EndElement.X+this.EndElement.Width/2; temp.EndY = this.EndElement.Y+this.EndElement.Height/2; temp.Angle = this.Angle; RectElement frontElement = new RectElement(); RectElement endElement = new RectElement(); ((RectElement)this.FrontElement).CopyTo(frontElement); ((RectElement)this.EndElement).CopyTo(endElement); temp.FrontElement = frontElement; temp.EndElement = endElement; temp.RectSize = this.RectSize; return true; }
private void OnCmdCreateGroup() { ObservableCollection<IElement> addCollection = new ObservableCollection<IElement>(); ObservableCollection<GroupInfo> groupCollection = new ObservableCollection<GroupInfo>(); RectElement groupframe = new RectElement(); groupframe.ElementSelectedState = SelectedState.Selected; groupframe.EleType = ElementType.groupframe; groupframe.ZIndex = 2; groupframe.GroupName = _myScreenLayer.MaxGroupName + 1; _myScreenLayer.MaxGroupName += 1; groupframe.ZOrder = _myScreenLayer.MaxZorder + 1; _myScreenLayer.MaxZorder += 1; groupframe.X = _currentSelectedElement[-1].SelectedElementRect.X; groupframe.Y = _currentSelectedElement[-1].SelectedElementRect.Y; groupframe.Width=_currentSelectedElement[-1].SelectedElementRect.Width; groupframe.Height = _currentSelectedElement[-1].SelectedElementRect.Height; groupframe.ParentElement = _myScreenLayer; for (int i = 0; i < _currentSelectedElement[-1].SelectedGroupElementList.Count; i++) { RectElement rect = (RectElement)(RectElement)_currentSelectedElement[-1].SelectedGroupElementList[i]; rect.GroupName = groupframe.GroupName; GroupInfo groupInfo = new GroupInfo(rect, new OldAndNewType(-1, rect.GroupName)); groupCollection.Add(groupInfo); } _groupframeList.Add(groupframe.GroupName, groupframe); _myScreenLayer.ElementCollection.Add(groupframe); addCollection.Add(groupframe); foreach (int key in _currentSelectedElement.Keys) { if (key == -1 && _currentSelectedElement[key].SelectedGroupElementList.Count==0 && _currentSelectedElement[key].NoSelectedGroupElementList.Count==0) { _groupframeList.Remove(key); break; } } GetCurrentElementInfo(); AddAction addAction = new AddAction(_myScreenLayer,addCollection); CreatOrCancelGroupAction groupAction = new CreatOrCancelGroupAction(groupCollection); using (Transaction.Create(SmartLCTActionManager)) { SmartLCTActionManager.RecordAction(addAction); SmartLCTActionManager.RecordAction(groupAction); } }
private void Receive_MouseMove(object sender, MouseEventArgs 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; } } FrameworkElement currentFramework = (FrameworkElement)sender; if (e.LeftButton == MouseButtonState.Pressed) { currentFramework.CaptureMouse(); } else { currentFramework.ReleaseMouseCapture(); if (this._adorner != null || (_addReceiveInfo != null && _myScreenLayer.OperateEnviron == OperatEnvironment.DesignScreen)) { e.Handled = false; } else { e.Handled = true; } return; } if (this._adorner != null) { e.Handled = false; return; } else { 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)))) { } else if (_isMouseLeftButtonDown == true && element.EleType == ElementType.receive && element.ElementSelectedState != SelectedState.None) { //虚构选中箱体的区域 _selectedReceiveArea = new Rect(); if (_selectedElementCollection != null && _selectedElementCollection.Count != 0) { double changedValue = Math.Pow(SmartLCTViewModeBase.IncreaseOrDecreaseValue, _myScreenLayer.IncreaseOrDecreaseIndex); #region 1.计算选中箱体的区域 foreach (int groupName in _currentSelectedElement.Keys) { Rect currentSelectedRect = _currentSelectedElement[groupName].SelectedElementRect; if (currentSelectedRect.Height != 0 && currentSelectedRect.Width != 0) { if (_selectedReceiveArea == new Rect()) { _selectedReceiveArea = currentSelectedRect; } else { _selectedReceiveArea = Rect.Union(_selectedReceiveArea, currentSelectedRect); } } } #endregion #region 2.生成虚构的箱体移动区域 //拖动的区域 this._dragScope = _itemsControl as FrameworkElement; //是否可以拖放 this._dragScope.AllowDrop = true; draghandler = new MouseEventHandler(DragScope_PreviewDragOver); //加载处理拖放的路由事件 this._dragScope.MouseMove += draghandler; this._dragScope.PreviewMouseMove += draghandler; //鼠标跟随效果的装饰器 Point adornerMousePoint = new Point(); adornerMousePoint = e.GetPosition(this); adornerMousePoint = this.TranslatePoint(adornerMousePoint, _itemsControl); //已经是缩放后的真实值 _virtualMoveDifValue = new Point(adornerMousePoint.X - _selectedReceiveArea.X, adornerMousePoint.Y - _selectedReceiveArea.Y); if (_myScreenLayer.OperateEnviron == OperatEnvironment.AdjustScreenLocation || _myScreenLayer.OperateEnviron == OperatEnvironment.AdjustSenderLocation) { _virtualMoveDifValue.X -= _myScreenLayer.X; _virtualMoveDifValue.Y -= _myScreenLayer.Y; } //_virtualMoveDifValue.X = Math.Round(_virtualMoveDifValue.X); //_virtualMoveDifValue.Y = Math.Round(_virtualMoveDifValue.Y); this._adorner = new DragAdorner(this._dragScope, _selectedReceiveArea.Width, _selectedReceiveArea.Height, adornerMousePoint, 0.5); //装饰器的位置 this._adorner.LeftOffset = _selectedReceiveArea.X * changedValue; this._adorner.TopOffset = _selectedReceiveArea.Y * changedValue; if (_myScreenLayer.OperateEnviron == OperatEnvironment.AdjustSenderLocation || _myScreenLayer.OperateEnviron == OperatEnvironment.AdjustScreenLocation) { this._adorner.LeftOffset += _myScreenLayer.X * changedValue; this._adorner.TopOffset += _myScreenLayer.Y * changedValue; } this._adorner.Height = _selectedReceiveArea.Height; this._adorner.Width = _selectedReceiveArea.Width; this._layer = AdornerLayer.GetAdornerLayer(this._dragScope as Visual); this._layer.Add(this._adorner); //显示位置的装饰器 this._locationAdorner = new DragAdorner(this._dragScope, this._adorner); //this._locationAdorner.TopOffset = adornerMousePoint.Y-20; //this._locationAdorner.LeftOffset = adornerMousePoint.X; this._locationAdorner.LeftOffset = _selectedReceiveArea.X * changedValue; this._locationAdorner.TopOffset = _selectedReceiveArea.Y * changedValue; if (_myScreenLayer.OperateEnviron == OperatEnvironment.AdjustSenderLocation || _myScreenLayer.OperateEnviron == OperatEnvironment.AdjustScreenLocation) { this._locationAdorner.LeftOffset += _myScreenLayer.X * changedValue; this._locationAdorner.TopOffset += _myScreenLayer.Y * changedValue; } this._layer.Add(this._locationAdorner); return; #endregion } } } if (_addReceiveInfo != null && _myScreenLayer.OperateEnviron == OperatEnvironment.DesignScreen) { e.Handled = false; return; } if (_myScreenLayer != null && _myScreenLayer.CLineType == ConnectLineType.Manual) { this.Cursor = Cursors.Hand; e.Handled = true; return; } #region 空格+鼠标移动屏体 if ((Keyboard.GetKeyStates(Key.Space) == KeyStates.Down || (Keyboard.GetKeyStates(Key.Space) == (KeyStates.Down | KeyStates.Toggled)))) { Layer_MouseMove(sender, e, _myScreenLayer); e.Handled = true; return; } #endregion #region 条件 if (e.LeftButton == MouseButtonState.Pressed) { currentFramework.CaptureMouse(); } else { currentFramework.ReleaseMouseCapture(); e.Handled = true; return; } List<IElement> selectedElementList = new List<IElement>(); Point mousePoint = e.GetPosition(currentFramework); if (element.EleType == ElementType.receive && element.ElementSelectedState == SelectedState.None) { if (Keyboard.GetKeyStates(Key.LeftCtrl) == KeyStates.Down || Keyboard.GetKeyStates(Key.LeftCtrl) == (KeyStates.Down | KeyStates.Toggled)) { //有可能是框选 } else { e.Handled = true; return; } } if ((!_isMouseLeftButtonDown) || element.ParentElement.IsLocked) { e.Handled = true; return; } #endregion #region 鼠标框选处理 if (((Keyboard.GetKeyStates(Key.LeftCtrl) == KeyStates.Down || (Keyboard.GetKeyStates(Key.LeftCtrl) == (KeyStates.Down | KeyStates.Toggled))) && element.EleType == ElementType.receive) || element.EleType == ElementType.screen || element.EleType == ElementType.groupframe) { Rect oldRect = new Rect(); if (((IRectElement)element.ParentElement).OperateEnviron == OperatEnvironment.DesignScreen) { #region 移除前一个(框选的矩形zorder==-1) for (int elementIndex = 0; elementIndex < _myScreenLayer.ElementCollection.Count; elementIndex++) { if (!(_myScreenLayer.ElementCollection[elementIndex] is RectElement)) { continue; } if (((RectElement)_myScreenLayer.ElementCollection[elementIndex]).ZOrder == -1) { IRectElement re = (RectElement)_myScreenLayer.ElementCollection[elementIndex]; _myScreenLayer.ElementCollection.RemoveAt(elementIndex); oldRect = new Rect(re.X, re.Y, re.Width, re.Height); } } #endregion Point mouseMovePointInThis = e.GetPosition(this); mouseMovePointInThis.X = mouseMovePointInThis.X; mouseMovePointInThis.Y = mouseMovePointInThis.Y; Point mouseMovePointInItemsControl = this.TranslatePoint(mouseMovePointInThis, _itemsControl); if (mouseMovePointInItemsControl.X > SmartLCTViewModeBase.MaxScreenWidth) { mouseMovePointInItemsControl.X = SmartLCTViewModeBase.MaxScreenWidth; } if (mouseMovePointInItemsControl.Y > SmartLCTViewModeBase.MaxScreenHeight) { mouseMovePointInItemsControl.Y = SmartLCTViewModeBase.MaxScreenHeight; } if (mouseMovePointInItemsControl.X < 0) { mouseMovePointInItemsControl.X = 0; } if (mouseMovePointInItemsControl.Y < 0) { mouseMovePointInItemsControl.Y = 0; } Point mouseLeftDownPointInItemControl = _mouseLeftDownPointInThis; double height = Math.Abs(mouseMovePointInItemsControl.Y - mouseLeftDownPointInItemControl.Y); double width = Math.Abs(mouseMovePointInItemsControl.X - mouseLeftDownPointInItemControl.X); RectElement rect = new RectElement(mouseLeftDownPointInItemControl.X, mouseLeftDownPointInItemControl.Y, width, height, _myScreenLayer, -1); if (mouseMovePointInItemsControl.X > mouseLeftDownPointInItemControl.X && mouseMovePointInItemsControl.Y > mouseLeftDownPointInItemControl.Y) { rect.X = mouseLeftDownPointInItemControl.X; rect.Y = mouseLeftDownPointInItemControl.Y; } else if (mouseMovePointInItemsControl.X > mouseLeftDownPointInItemControl.X && mouseMovePointInItemsControl.Y < mouseLeftDownPointInItemControl.Y) { rect.X = mouseLeftDownPointInItemControl.X; rect.Y = mouseMovePointInItemsControl.Y; } else if (mouseMovePointInItemsControl.X < mouseLeftDownPointInItemControl.X && mouseMovePointInItemsControl.Y > mouseLeftDownPointInItemControl.Y) { rect.X = mouseMovePointInItemsControl.X; rect.Y = mouseLeftDownPointInItemControl.Y; } else if (mouseMovePointInItemsControl.X < mouseLeftDownPointInItemControl.X && mouseMovePointInItemsControl.Y < mouseLeftDownPointInItemControl.Y) { rect.X = mouseMovePointInItemsControl.X; rect.Y = mouseMovePointInItemsControl.Y; } Thickness margin = new Thickness(rect.X, rect.Y, rect.X + rect.Width, rect.Y + rect.Height); rect.Margin = margin; rect.ZOrder = -1; rect.BackgroundBrush = Brushes.Gray; rect.Opacity = 0.5; rect.ZIndex = 8; rect.MyLockAndVisibleButtonVisible = Visibility.Hidden; rect.ElementSelectedState = SelectedState.FrameSelected; rect.EleType = ElementType.frameSelected; _myScreenLayer.ElementCollection.Add(rect); _isFrameSelected = true; Point minPoint = new Point(0, 0); Point maxPoint = new Point(this.ActualWidth, this.ActualHeight); minPoint = this.TranslatePoint(minPoint, _itemsControl); maxPoint = this.TranslatePoint(maxPoint, _itemsControl); //判断移动的方向 if (oldRect != new Rect()) { //向右框选 if (oldRect.X == rect.X && oldRect.Width < rect.Width && rect.X + rect.Width > maxPoint.X) { _scrollViewer.ScrollToHorizontalOffset(_scrollViewer.HorizontalOffset + rect.X + rect.Width - maxPoint.X); } else if (oldRect.X + oldRect.Width == rect.X + rect.Width && oldRect.Width > rect.Width && rect.X > maxPoint.X) { _scrollViewer.ScrollToHorizontalOffset(_scrollViewer.HorizontalOffset + rect.X - maxPoint.X); } //向左框选 if (oldRect.X + oldRect.Width == rect.X + rect.Width && oldRect.X > rect.X && rect.X < minPoint.X) { _scrollViewer.ScrollToHorizontalOffset(_scrollViewer.HorizontalOffset - (minPoint.X - rect.X)); } else if (oldRect.X == rect.X && oldRect.Width > rect.Width && rect.X + rect.Width < minPoint.X) { _scrollViewer.ScrollToHorizontalOffset(_scrollViewer.HorizontalOffset - (minPoint.X - rect.X - rect.Width)); } //向下框选 if (oldRect.Y == rect.Y && oldRect.Height < rect.Height && rect.Y + rect.Height > maxPoint.Y) { _scrollViewer.ScrollToVerticalOffset(_scrollViewer.VerticalOffset + rect.Y + rect.Height - maxPoint.Y); } else if (oldRect.Y + oldRect.Height == rect.Y + rect.Height && oldRect.Height > rect.Height && rect.Y > maxPoint.Y) { _scrollViewer.ScrollToVerticalOffset(_scrollViewer.VerticalOffset + rect.Y - maxPoint.Y); } //向上框选 if (oldRect.Y + oldRect.Height == rect.Y + rect.Height && oldRect.Y > rect.Y && rect.Y < minPoint.Y) { _scrollViewer.ScrollToVerticalOffset(_scrollViewer.VerticalOffset - (minPoint.Y - rect.Y)); } else if (oldRect.Y == rect.Y && oldRect.Height > rect.Height && rect.Y + rect.Height < minPoint.Y) { _scrollViewer.ScrollToVerticalOffset(_scrollViewer.VerticalOffset - (minPoint.Y - rect.Y - rect.Height)); } } e.Handled = true; return; } } #endregion e.Handled = true; }
public Window2_VM() { CmdTest = new RelayCommand(OnCmdTest); RectLayer layer = new RectLayer(20, 30, 100, 110, new RectLayer(), 0, ElementType.None,0); SenderRealParameters rp = new SenderRealParameters(); rp.Element = layer; MyRectLayer = rp; if (!this.IsInDesignMode) { ScannerTypeCollection.Add(new ScannerCofigInfo() { DisplayName = "aa", ScanBdProp = new ScanBoardProperty() }); ScannerTypeCollection.Add(new ScannerCofigInfo() { DisplayName = "bb", ScanBdProp = new ScanBoardProperty() }); PortRealParameters param = new PortRealParameters(); RectLayer rectLayer = new RectLayer(); SelectedElementCollection = new ObservableCollection<IRectElement>(); RectElement element = new RectElement(0, 0, 10, 10, rectLayer, 0); rectLayer.ElementCollection.Add(element); SelectedElementCollection.Add(element); element = new RectElement(15, 20, 10, 10, rectLayer, 0); rectLayer.ElementCollection.Add(element); SelectedElementCollection.Add(element); element = new RectElement(18, 20, 10, 10, rectLayer, 0); rectLayer.ElementCollection.Add(element); SelectedElementCollection.Add(element); element = new RectElement(0, 60, 10, 10, rectLayer, 0); rectLayer.ElementCollection.Add(element); SelectedElementCollection.Add(element); element = new RectElement(30, 0, 10, 10, rectLayer, 0); rectLayer.ElementCollection.Add(element); SelectedElementCollection.Add(element); element = new RectElement(30, 60, 10, 10, rectLayer, 0); rectLayer.ElementCollection.Add(element); SelectedElementCollection.Add(element); param.PortLayer = rectLayer; PortRealParams = param; PortRealParams.SelectedElementCollection = SelectedElementCollection; rectLayer = new RectLayer(); ScannerRealParameters scanParam = new ScannerRealParameters(); scanParam.ScannerElement = new RectElement(30, 60, 10, 10, rectLayer, 0); scanParam.ScannerConfig = new ScannerCofigInfo() { DisplayName = "aa", ScanBdProp = new ScanBoardProperty() }; ScannerRealParams = scanParam; } }
private void OnCmdTest() { bool res = true; if (res) { double data = 5.71234; int dt = (int)Math.Round(data, 0); PortRealParams.SelectedElementCollection.Clear(); } else { RectElement element = new RectElement(0, 0, 10, 10, PortRealParams.PortLayer, 0); PortRealParams.SelectedElementCollection.Add(element); } }
public bool CopyTow(object obj) { if (!(obj is RectLayer)) { return false; } RectLayer temp = (RectLayer)obj; #region temp.BackgroundBrush = this.BackgroundBrush; temp.CenterX = this.CenterX; temp.CenterY = this.CenterY; temp.ElementSelectedState = this.ElementSelectedState; temp.Height = this.Height; temp.IsLocked = this.IsLocked; temp.IsOutlineDisplay = this.IsOutlineDisplay; temp.StartAndEndIconMargin = this.StartAndEndIconMargin; temp.Name = this.Name; temp.Opacity = this.Opacity; temp.OutlineBrush = this.OutlineBrush; temp.Visible = this.Visible; temp.Width = this.Width; temp.Tag = this.Tag; temp.EleType = this.EleType; temp.BorderThickness = this.BorderThickness; temp.SizeVisibility = this.SizeVisibility; temp.CLineType = this.CLineType; temp.MaxGroupName = this.MaxGroupName; temp.MaxZorder = this.MaxZorder; temp.CurrentPortIndex = this.CurrentPortIndex; temp.CurrentSenderIndex = this.CurrentSenderIndex; temp.RectSize = this.RectSize; temp.OperateEnviron = this.OperateEnviron; #endregion temp.ElementCollection = new ObservableCollection<IElement>(); for (int i = 0; i < this.ElementCollection.Count; i++) { if (this.ElementCollection[i] is RectElement) { RectElement rect = new RectElement(); rect = (RectElement)((RectElement)this.ElementCollection[i]).Clone(); rect.ParentElement = temp; temp.ElementCollection.Add(rect); } else if (this.ElementCollection[i] is RectLayer) { RectLayer rectLayer = new RectLayer(); rectLayer = (RectLayer)((RectLayer)this.ElementCollection[i]).Clone(); rectLayer.ParentElement = temp; temp.ElementCollection.Add(rectLayer); } else if (this.ElementCollection[i] is LineElement) { LineElement lineElement = new LineElement(); ((LineElement)this.ElementCollection[i]).CopyTo(lineElement); lineElement.ParentElement = temp; temp.ElementCollection.Add(lineElement); } } for (int i = 0; i < temp.ElementCollection.Count; i++) { if (temp.ElementCollection[i] is LineElement) { for (int j = 0; j < temp.ElementCollection.Count; j++) { if ((temp.ElementCollection[j] is RectElement) && (((LineElement)temp.ElementCollection[i]).FrontElement.ZOrder == temp.ElementCollection[j].ZOrder)) { ((LineElement)temp.ElementCollection[i]).FrontElement=(RectElement)temp.ElementCollection[j]; } if ((temp.ElementCollection[j] is RectElement) && (((LineElement)temp.ElementCollection[i]).EndElement.ZOrder == temp.ElementCollection[j].ZOrder)) { ((LineElement)temp.ElementCollection[i]).EndElement = (RectElement)temp.ElementCollection[j]; } } ((LineElement)temp.ElementCollection[i]).FrontElement.EndLine = (LineElement)temp.ElementCollection[i]; ((LineElement)temp.ElementCollection[i]).EndElement.FrontLine = (LineElement)temp.ElementCollection[i]; } } return true; }
private void Receive_MouseMove(object sender, MouseEventArgs 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; } } FrameworkElement currentFramework = (FrameworkElement)sender; if (e.LeftButton == MouseButtonState.Pressed) { currentFramework.CaptureMouse(); } else { currentFramework.ReleaseMouseCapture(); if (this._adorner != null || (_addReceiveInfo != null && _myScreenLayer.OperateEnviron == OperatEnvironment.DesignScreen)) { e.Handled = false; } else { e.Handled = true; } return; } if (this._adorner != null) { e.Handled = false; return; } else { 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)))) { } else if (_isMouseLeftButtonDown == true && element.EleType == ElementType.receive && element.ElementSelectedState != SelectedState.None) { //虚构选中箱体的区域 _selectedReceiveArea = new Rect(); if (_selectedElementCollection != null && _selectedElementCollection.Count != 0) { double changedValue = Math.Pow(SmartLCTViewModeBase.IncreaseOrDecreaseValue, _myScreenLayer.IncreaseOrDecreaseIndex); #region 1.计算选中箱体的区域 foreach (int groupName in _currentSelectedElement.Keys) { Rect currentSelectedRect = _currentSelectedElement[groupName].SelectedElementRect; if (currentSelectedRect.Height != 0 && currentSelectedRect.Width != 0) { if (_selectedReceiveArea == new Rect()) { _selectedReceiveArea = currentSelectedRect; } else { _selectedReceiveArea = Rect.Union(_selectedReceiveArea, currentSelectedRect); } } } #endregion #region 2.生成虚构的箱体移动区域 //拖动的区域 this._dragScope = _itemsControl as FrameworkElement; //是否可以拖放 this._dragScope.AllowDrop = true; draghandler = new MouseEventHandler(DragScope_PreviewDragOver); //加载处理拖放的路由事件 this._dragScope.MouseMove += draghandler; this._dragScope.PreviewMouseMove += draghandler; //鼠标跟随效果的装饰器 Point adornerMousePoint = new Point(); adornerMousePoint = e.GetPosition(this); adornerMousePoint = this.TranslatePoint(adornerMousePoint, _itemsControl); //已经是缩放后的真实值 _virtualMoveDifValue = new Point(adornerMousePoint.X - _selectedReceiveArea.X, adornerMousePoint.Y - _selectedReceiveArea.Y); if(_myScreenLayer.OperateEnviron==OperatEnvironment.AdjustScreenLocation || _myScreenLayer.OperateEnviron == OperatEnvironment.AdjustSenderLocation) { _virtualMoveDifValue.X -= _myScreenLayer.X; _virtualMoveDifValue.Y -= _myScreenLayer.Y; } //_virtualMoveDifValue.X = Math.Round(_virtualMoveDifValue.X); //_virtualMoveDifValue.Y = Math.Round(_virtualMoveDifValue.Y); this._adorner = new DragAdorner(this._dragScope, _selectedReceiveArea.Width, _selectedReceiveArea.Height, adornerMousePoint, 0.5); //装饰器的位置 this._adorner.LeftOffset = _selectedReceiveArea.X * changedValue; this._adorner.TopOffset = _selectedReceiveArea.Y * changedValue; if(_myScreenLayer.OperateEnviron==OperatEnvironment.AdjustSenderLocation || _myScreenLayer.OperateEnviron == OperatEnvironment.AdjustScreenLocation) { this._adorner.LeftOffset += _myScreenLayer.X*changedValue; this._adorner.TopOffset += _myScreenLayer.Y*changedValue; } this._adorner.Height = _selectedReceiveArea.Height; this._adorner.Width = _selectedReceiveArea.Width; this._layer = AdornerLayer.GetAdornerLayer(this._dragScope as Visual); this._layer.Add(this._adorner); //显示位置的装饰器 this._locationAdorner = new DragAdorner(this._dragScope, this._adorner); //this._locationAdorner.TopOffset = adornerMousePoint.Y-20; //this._locationAdorner.LeftOffset = adornerMousePoint.X; this._locationAdorner.LeftOffset = _selectedReceiveArea.X * changedValue; this._locationAdorner.TopOffset = _selectedReceiveArea.Y * changedValue; if (_myScreenLayer.OperateEnviron == OperatEnvironment.AdjustSenderLocation || _myScreenLayer.OperateEnviron == OperatEnvironment.AdjustScreenLocation) { this._locationAdorner.LeftOffset += _myScreenLayer.X*changedValue; this._locationAdorner.TopOffset += _myScreenLayer.Y*changedValue; } this._layer.Add(this._locationAdorner); return; #endregion } } } if (_addReceiveInfo != null && _myScreenLayer.OperateEnviron == OperatEnvironment.DesignScreen) { e.Handled = false; return; } if (_myScreenLayer != null && _myScreenLayer.CLineType == ConnectLineType.Manual) { this.Cursor = Cursors.Hand; e.Handled = true; return; } #region 空格+鼠标移动屏体 if ((Keyboard.GetKeyStates(Key.Space) == KeyStates.Down || (Keyboard.GetKeyStates(Key.Space) == (KeyStates.Down | KeyStates.Toggled)))) { Layer_MouseMove(sender, e, _myScreenLayer); e.Handled = true; return; } #endregion #region 条件 if (e.LeftButton == MouseButtonState.Pressed) { currentFramework.CaptureMouse(); } else { currentFramework.ReleaseMouseCapture(); e.Handled = true; return; } List<IElement> selectedElementList = new List<IElement>(); bool isMoveX = true; bool isMoveY = true; Point mousePoint = e.GetPosition(currentFramework); if (element.EleType == ElementType.receive && element.ElementSelectedState == SelectedState.None) { if (Keyboard.GetKeyStates(Key.LeftCtrl) == KeyStates.Down || Keyboard.GetKeyStates(Key.LeftCtrl) == (KeyStates.Down | KeyStates.Toggled)) { //有可能是框选 } else { e.Handled = true; return; } } if ((!_isMouseLeftButtonDown) || element.ParentElement.IsLocked) { e.Handled = true; return; } #endregion #region 鼠标框选处理 if (((Keyboard.GetKeyStates(Key.LeftCtrl) == KeyStates.Down || (Keyboard.GetKeyStates(Key.LeftCtrl) == (KeyStates.Down | KeyStates.Toggled))) && element.EleType == ElementType.receive) || element.EleType == ElementType.screen || element.EleType == ElementType.groupframe) { Rect oldRect = new Rect(); if (((IRectElement)element.ParentElement).OperateEnviron == OperatEnvironment.DesignScreen) { #region 移除前一个(框选的矩形zorder==-1) for (int elementIndex = 0; elementIndex < _myScreenLayer.ElementCollection.Count; elementIndex++) { if (!(_myScreenLayer.ElementCollection[elementIndex] is RectElement)) { continue; } if (((RectElement)_myScreenLayer.ElementCollection[elementIndex]).ZOrder == -1) { IRectElement re=(RectElement)_myScreenLayer.ElementCollection[elementIndex]; _myScreenLayer.ElementCollection.RemoveAt(elementIndex); oldRect = new Rect(re.X, re.Y, re.Width, re.Height); } } #endregion Point mouseMovePointInThis = e.GetPosition(this); mouseMovePointInThis.X = mouseMovePointInThis.X; mouseMovePointInThis.Y = mouseMovePointInThis.Y; Point mouseMovePointInItemsControl = this.TranslatePoint(mouseMovePointInThis, _itemsControl); if (mouseMovePointInItemsControl.X > SmartLCTViewModeBase.MaxScreenWidth) { mouseMovePointInItemsControl.X = SmartLCTViewModeBase.MaxScreenWidth; } if (mouseMovePointInItemsControl.Y > SmartLCTViewModeBase.MaxScreenHeight) { mouseMovePointInItemsControl.Y = SmartLCTViewModeBase.MaxScreenHeight; } if (mouseMovePointInItemsControl.X < 0) { mouseMovePointInItemsControl.X = 0; } if (mouseMovePointInItemsControl.Y < 0) { mouseMovePointInItemsControl.Y = 0; } Point mouseLeftDownPointInItemControl = _mouseLeftDownPointInThis; double height = Math.Abs(mouseMovePointInItemsControl.Y - mouseLeftDownPointInItemControl.Y); double width = Math.Abs(mouseMovePointInItemsControl.X - mouseLeftDownPointInItemControl.X); RectElement rect = new RectElement(mouseLeftDownPointInItemControl.X, mouseLeftDownPointInItemControl.Y, width, height, _myScreenLayer, -1); if (mouseMovePointInItemsControl.X > mouseLeftDownPointInItemControl.X && mouseMovePointInItemsControl.Y > mouseLeftDownPointInItemControl.Y) { rect.X = mouseLeftDownPointInItemControl.X; rect.Y = mouseLeftDownPointInItemControl.Y; } else if (mouseMovePointInItemsControl.X > mouseLeftDownPointInItemControl.X && mouseMovePointInItemsControl.Y < mouseLeftDownPointInItemControl.Y) { rect.X = mouseLeftDownPointInItemControl.X; rect.Y = mouseMovePointInItemsControl.Y; } else if (mouseMovePointInItemsControl.X < mouseLeftDownPointInItemControl.X && mouseMovePointInItemsControl.Y > mouseLeftDownPointInItemControl.Y) { rect.X = mouseMovePointInItemsControl.X; rect.Y = mouseLeftDownPointInItemControl.Y; } else if (mouseMovePointInItemsControl.X < mouseLeftDownPointInItemControl.X && mouseMovePointInItemsControl.Y < mouseLeftDownPointInItemControl.Y) { rect.X = mouseMovePointInItemsControl.X; rect.Y = mouseMovePointInItemsControl.Y; } Thickness margin = new Thickness(rect.X, rect.Y, rect.X + rect.Width, rect.Y + rect.Height); rect.Margin = margin; rect.ZOrder = -1; rect.BackgroundBrush = Brushes.Gray; rect.Opacity = 0.5; rect.ZIndex = 8; rect.MyLockAndVisibleButtonVisible = Visibility.Hidden; rect.ElementSelectedState = SelectedState.FrameSelected; rect.EleType = ElementType.frameSelected; _myScreenLayer.ElementCollection.Add(rect); _isFrameSelected = true; Point minPoint=new Point(0,0); Point maxPoint = new Point(this.ActualWidth, this.ActualHeight); minPoint=this.TranslatePoint(minPoint, _itemsControl); maxPoint = this.TranslatePoint(maxPoint, _itemsControl); //判断移动的方向 if (oldRect != new Rect()) { //向右框选 if (oldRect.X == rect.X && oldRect.Width<rect.Width && rect.X + rect.Width > maxPoint.X) { _scrollViewer.ScrollToHorizontalOffset(_scrollViewer.HorizontalOffset + rect.X + rect.Width - maxPoint.X); } else if (oldRect.X+oldRect.Width==rect.X+rect.Width && oldRect.Width > rect.Width && rect.X > maxPoint.X) { _scrollViewer.ScrollToHorizontalOffset(_scrollViewer.HorizontalOffset + rect.X - maxPoint.X); } //向左框选 if (oldRect.X + oldRect.Width == rect.X + rect.Width && oldRect.X > rect.X && rect.X < minPoint.X) { _scrollViewer.ScrollToHorizontalOffset(_scrollViewer.HorizontalOffset - (minPoint.X-rect.X)); } else if (oldRect.X == rect.X && oldRect.Width > rect.Width && rect.X + rect.Width < minPoint.X) { _scrollViewer.ScrollToHorizontalOffset(_scrollViewer.HorizontalOffset - (minPoint.X - rect.X-rect.Width)); } //向下框选 if (oldRect.Y == rect.Y && oldRect.Height < rect.Height && rect.Y + rect.Height > maxPoint.Y) { _scrollViewer.ScrollToVerticalOffset(_scrollViewer.VerticalOffset + rect.Y + rect.Height - maxPoint.Y); } else if (oldRect.Y + oldRect.Height == rect.Y + rect.Height && oldRect.Height > rect.Height && rect.Y > maxPoint.Y) { _scrollViewer.ScrollToVerticalOffset(_scrollViewer.VerticalOffset + rect.Y - maxPoint.Y); } //向上框选 if (oldRect.Y + oldRect.Height == rect.Y + rect.Height && oldRect.Y > rect.Y && rect.Y < minPoint.Y) { _scrollViewer.ScrollToVerticalOffset(_scrollViewer.VerticalOffset - (minPoint.Y - rect.Y)); } else if (oldRect.Y == rect.Y && oldRect.Height > rect.Height && rect.Y + rect.Height < minPoint.Y) { _scrollViewer.ScrollToVerticalOffset(_scrollViewer.VerticalOffset - (minPoint.Y - rect.Y - rect.Height)); } } e.Handled = true; return; } } #endregion #region 旧的移动 //if (element.EleType==ElementType.receive && ((IRectElement)element).OperateEnviron==OperatEnvironment.DesignScreen) //{ // element.AddressVisible = Visibility.Visible; // if (_selectedElementCollection.Count == 0) // { // e.Handled = true; // return; // } //} //#region 移动距离处理(超出最大最小边界时) //double controlMovingValueX = mousePoint.X - _mousePoint.X; //double controlMovingValueY = mousePoint.Y - _mousePoint.Y; ////controlMovingValueX = Math.Round(controlMovingValueX); ////controlMovingValueY = Math.Round(controlMovingValueY); //double maxScreenHeight = 0; //double maxScreenWidth = 0; //if (_myScreenLayer.OperateEnviron == OperatEnvironment.DesignScreen) //{ // maxScreenHeight = SmartLCTViewModeBase.MaxScreenHeight; // maxScreenWidth = SmartLCTViewModeBase.MaxScreenWidth; //} //else //{ // maxScreenWidth = _myScreenLayer.Width; // maxScreenHeight = _myScreenLayer.Height; //} //if (_selectedElementRect.Width > maxScreenWidth) //{ // controlMovingValueX = -_selectedElementRect.X; //} //else if (_selectedElementRect.X + controlMovingValueX + _selectedElementRect.Width > maxScreenWidth) // { // controlMovingValueX = maxScreenWidth - _selectedElementRect.X - _selectedElementRect.Width; //} //else if (_selectedElementRect.X + controlMovingValueX < 0) // { // controlMovingValueX = -_selectedElementRect.X; // _isStartMoveX = false; // } //if (_selectedElementRect.Height > maxScreenHeight) //{ // controlMovingValueY = -_selectedElementRect.Y; //} //else if (_selectedElementRect.Y + controlMovingValueY + _selectedElementRect.Height > maxScreenHeight) // { // controlMovingValueY = maxScreenHeight - _selectedElementRect.Y - _selectedElementRect.Height; // } //else if (_selectedElementRect.Y + controlMovingValueY < 0) // { // controlMovingValueY = -_selectedElementRect.Y; // _isStartMoveY = false; // } // #endregion // #region 吸附 //if (_isStartMoveX) //刚开始移动(移动距离大于SmartLCTViewModeBase.AdsorbValue才能移动) //{ // isMoveX = true; // if (Math.Abs(controlMovingValueX) < SmartLCTViewModeBase.AdsorbValue) // { // isMoveX = false; // controlMovingValueX = 0; // } // else // { // isMoveX = true; // _isStartMoveX = false; // } //} //if (_isStartMoveY) //刚开始移动(移动距离大于5才能移动) //{ // isMoveY = true; // if (Math.Abs(controlMovingValueY) < SmartLCTViewModeBase.AdsorbValue) // { // isMoveY = false; // controlMovingValueY = 0; // } // else // { // isMoveY = true; // _isStartMoveY = false; // } //} //if (isMoveY == false && isMoveX == false) //{ // e.Handled = true; // return; //} //double valueX = SmartLCTViewModeBase.AdsorbValue + 1; //double valueY = SmartLCTViewModeBase.AdsorbValue + 1; //double currentElementMaxX = 0; //double currentElementMaxY = 0; //IRectElement currentElement = (IRectElement)element; //currentElementMaxX = currentElement.X; //currentElementMaxY = currentElement.Y; //if (controlMovingValueX > 0) //{ // if (_currentSelectedElement[element.GroupName].NoSelectedGroupElementList.Count == 0) // { // currentElementMaxX += _currentSelectedElement[element.GroupName].SelectedElementRect.Width; // } // else // { // currentElementMaxX += currentElement.Width; // } //} //if (controlMovingValueY > 0) //{ // if (_currentSelectedElement[element.GroupName].NoSelectedGroupElementList.Count == 0) // { // currentElementMaxY += _currentSelectedElement[element.GroupName].SelectedElementRect.Height; // } // else // { // currentElementMaxY += currentElement.Height; // } //} //for (int i = 0; i < _myScreenLayer.ElementCollection.Count; i++) //{ // if (_myScreenLayer.ElementCollection[i] is LineElement || // _myScreenLayer.ElementCollection[i].ElementSelectedState!=SelectedState.None) // { // continue; // } // IRectElement rect = (IRectElement)_myScreenLayer.ElementCollection[i]; // if (controlMovingValueX < 0 && isMoveX) // { // #region 向左移动 // if (rect.X > currentElementMaxX // || rect.X + rect.Width < currentElementMaxX - SmartLCTViewModeBase.AdsorbValue // || rect.Y > currentElementMaxY + currentElement.Height // || rect.Height + rect.Y < currentElementMaxY) // { // continue; // } // if (rect.X < currentElementMaxX // && rect.X + rect.Width > currentElement.X + currentElement.Width // && currentElementMaxX - rect.X < valueX && currentElementMaxX - rect.X > 0) // { // valueX = currentElementMaxX - rect.X; // } // else // { // if (currentElementMaxX - rect.X < valueX && currentElementMaxX - rect.X > 0) // { // valueX = currentElementMaxX - rect.X; // } // else if (currentElementMaxX - rect.X - rect.Width < valueX // && currentElementMaxX - rect.X - rect.Width > 0) // { // valueX = currentElementMaxX - rect.X - rect.Width; // } // } // if (valueX < SmartLCTViewModeBase.AdsorbValue + 1 && valueX > 0) // { // controlMovingValueX = -valueX; // _isStartMoveX = true; // } // #endregion // } // else if (controlMovingValueX > 0 && isMoveX) // { // #region 向右移动 // if (rect.X + rect.Width < currentElementMaxX // || rect.X > currentElementMaxX + SmartLCTViewModeBase.AdsorbValue // || rect.Y + rect.Height < currentElementMaxY // || rect.Y > currentElementMaxY + currentElement.Height) // { // continue; // } // if (rect.X < currentElementMaxX && rect.X + rect.Width > currentElementMaxX // && rect.X + rect.Width - currentElementMaxX < valueX // && rect.X + rect.Width - currentElementMaxX > 0) // { // valueX = rect.X + rect.Width - currentElementMaxX; // } // else // { // if (rect.X - currentElementMaxX < valueX && rect.X - currentElementMaxX > 0) // { // valueX = rect.X - currentElementMaxX; // } // else if (rect.X + rect.Width - currentElementMaxX < valueX // && rect.X + rect.Width - currentElementMaxX > 0) // { // valueX = rect.X + rect.Width - currentElementMaxX; // } // } // if (valueX < SmartLCTViewModeBase.AdsorbValue + 1 && valueX > 0) // { // controlMovingValueX = valueX; // _isStartMoveX = true; // } // #endregion // } // if (controlMovingValueY < 0 && isMoveY) // { // #region 向上移动 // if (rect.Y > currentElementMaxY // || rect.Y + rect.Height < currentElementMaxY - SmartLCTViewModeBase.AdsorbValue // || rect.X > currentElementMaxX + currentElement.Width // || rect.Width + rect.X < currentElementMaxX) // { // continue; // } // if (rect.Y < currentElementMaxY // && rect.Y + rect.Height > currentElement.Y + currentElement.Height // && currentElementMaxY - rect.Y < valueY && currentElementMaxY - rect.Y > 0) // { // valueY = currentElementMaxY - rect.Y; // } // else // { // if (currentElementMaxY - rect.Y < valueY && currentElementMaxY - rect.Y > 0) // { // valueY = currentElementMaxY - rect.Y; // } // else if (currentElementMaxY - rect.Y - rect.Height < valueY // && currentElementMaxY - rect.Y - rect.Height > 0) // { // valueY = currentElementMaxY - rect.Y - rect.Height; // } // } // if (valueY < SmartLCTViewModeBase.AdsorbValue + 1 && valueY > 0) // { // controlMovingValueY = -valueY; // _isStartMoveY = true; // } // #endregion // } // else if (controlMovingValueY > 0 && isMoveY) // { // #region 向下移动 // if (rect.Y + rect.Height < currentElementMaxY // || rect.Y > currentElementMaxY + SmartLCTViewModeBase.AdsorbValue // || rect.X + rect.Width < currentElementMaxX // || rect.X > currentElementMaxX + currentElement.Width) // { // continue; // } // if (rect.Y < currentElementMaxY && rect.Y + rect.Height > currentElementMaxY // && rect.Y + rect.Height - currentElementMaxY < valueY // && rect.Y + rect.Height - currentElementMaxY > 0) // { // valueY = rect.Y + rect.Height - currentElementMaxY; // } // else // { // if (rect.Y - currentElementMaxY < valueY && rect.Y - currentElementMaxY > 0) // { // valueY = rect.Y - currentElementMaxY; // } // else if (rect.Y + rect.Height - currentElementMaxY < valueY // && rect.Y + rect.Height - currentElementMaxY > 0) // { // valueY = rect.Y + rect.Height - currentElementMaxY; // } // if (valueY < SmartLCTViewModeBase.AdsorbValue + 1 && valueY > 0) // { // controlMovingValueY = valueY; // _isStartMoveY = true; // } // } // #endregion // } //} // #endregion // #region 滚动条处理 // Point maxXInThis = new Point(); // Point minXInThis = new Point(); // minXInThis.X = _selectedElementRect.X + controlMovingValueX + _myScreenLayer.X; // minXInThis.Y = _selectedElementRect.Y + controlMovingValueY + _myScreenLayer.Y; // maxXInThis.X = _selectedElementRect.X + controlMovingValueX + _selectedElementRect.Width + _myScreenLayer.X; // maxXInThis.Y = _selectedElementRect.Y + controlMovingValueY + _selectedElementRect.Height + _myScreenLayer.Y; // maxXInThis = _itemsControl.TranslatePoint(maxXInThis, this); // minXInThis = _itemsControl.TranslatePoint(minXInThis, this); //if (isMoveX) // { // if (minXInThis.X < 0 && controlMovingValueX < 0) // { // if (minXInThis.X - controlMovingValueX < 0) // { // _scrollViewer.ScrollToHorizontalOffset(_scrollViewer.HorizontalOffset + controlMovingValueX * Math.Pow(SmartLCTViewModeBase.IncreaseOrDecreaseValue, _myScreenLayer.IncreaseOrDecreaseIndex)); // } // else // { // _scrollViewer.ScrollToHorizontalOffset(_scrollViewer.HorizontalOffset + minXInThis.X * Math.Pow(SmartLCTViewModeBase.IncreaseOrDecreaseValue, _myScreenLayer.IncreaseOrDecreaseIndex)); // } // } // else if (maxXInThis.X > this.ActualWidth - (_scrollViewer.ActualWidth - _scrollViewer.ViewportWidth) && controlMovingValueX > 0) // { // if (maxXInThis.X - controlMovingValueX > this.ActualWidth - (_scrollViewer.ActualWidth - _scrollViewer.ViewportWidth)) // { // _scrollViewer.ScrollToHorizontalOffset(_scrollViewer.HorizontalOffset + controlMovingValueX * Math.Pow(SmartLCTViewModeBase.IncreaseOrDecreaseValue, _myScreenLayer.IncreaseOrDecreaseIndex)); // } // else // { // _scrollViewer.ScrollToHorizontalOffset(_scrollViewer.HorizontalOffset + (maxXInThis.X - this.ActualWidth + (_scrollViewer.ActualWidth - _scrollViewer.ViewportWidth)) * Math.Pow(SmartLCTViewModeBase.IncreaseOrDecreaseValue, _myScreenLayer.IncreaseOrDecreaseIndex)); // } // } // } // if (isMoveY) // { // if (minXInThis.Y < 0 && controlMovingValueY < 0) // { // if (minXInThis.Y - controlMovingValueY < 0) // { // _scrollViewer.ScrollToVerticalOffset(_scrollViewer.VerticalOffset + controlMovingValueY * Math.Pow(SmartLCTViewModeBase.IncreaseOrDecreaseValue, _myScreenLayer.IncreaseOrDecreaseIndex)); // } // else // { // _scrollViewer.ScrollToVerticalOffset(_scrollViewer.VerticalOffset + minXInThis.Y * Math.Pow(SmartLCTViewModeBase.IncreaseOrDecreaseValue, _myScreenLayer.IncreaseOrDecreaseIndex)); // } // } // else if (maxXInThis.Y > this.ActualHeight - (_scrollViewer.ActualHeight - _scrollViewer.ViewportHeight) && controlMovingValueY > 0) // { // if (maxXInThis.Y - controlMovingValueY > this.ActualHeight - (_scrollViewer.ActualHeight - _scrollViewer.ViewportHeight)) // { // _scrollViewer.ScrollToVerticalOffset(_scrollViewer.VerticalOffset + controlMovingValueY * Math.Pow(SmartLCTViewModeBase.IncreaseOrDecreaseValue, _myScreenLayer.IncreaseOrDecreaseIndex)); // } // else // { // _scrollViewer.ScrollToVerticalOffset(_scrollViewer.VerticalOffset + (maxXInThis.Y - this.ActualHeight + (_scrollViewer.ActualHeight - _scrollViewer.ViewportHeight)) * Math.Pow(SmartLCTViewModeBase.IncreaseOrDecreaseValue, _myScreenLayer.IncreaseOrDecreaseIndex)); // } // } // } // #endregion // #region 移动与边框改变 // if (controlMovingValueX != 0 || controlMovingValueY != 0) // { // _isMoving = true; // } // foreach (int i in _currentSelectedElement.Keys) // { // if (_currentSelectedElement[i].SelectedGroupElementList.Count == 0) // { // continue; // } // ObservableCollection<IRectElement> selectedList = _currentSelectedElement[i].SelectedGroupElementList; // ObservableCollection<IRectElement> noSelectedList = _currentSelectedElement[i].NoSelectedGroupElementList; // Rect selectedElementRect = _currentSelectedElement[i].SelectedElementRect; // Rect noSelectedElementRect = _currentSelectedElement[i].NoSelectedElementRect; // if (controlMovingValueX != 0) // { // Console.WriteLine("旧的移动x:" + controlMovingValueX.ToString()); // Function.SetElementCollectionX(selectedList, controlMovingValueX); // selectedElementRect.X += controlMovingValueX; // selectedElementRect.X = Math.Round(selectedElementRect.X); // } // if (controlMovingValueY != 0) // { // Console.WriteLine("旧的移动y:" + controlMovingValueY.ToString()); // Function.SetElementCollectionY(selectedList, controlMovingValueY); // selectedElementRect.Y += controlMovingValueY; // selectedElementRect.Y = Math.Round(selectedElementRect.Y); // } // if (i != -1 && (controlMovingValueX != 0 || controlMovingValueY != 0)) // { // if (noSelectedList.Count == 0) // { // _groupframeList[i].X += controlMovingValueX; // _groupframeList[i].Y += controlMovingValueY; // } // else // { // Rect unionrect = Rect.Union(selectedElementRect, noSelectedElementRect); // _groupframeList[i].Width = unionrect.Width; // _groupframeList[i].Height = unionrect.Height; // _groupframeList[i].X = unionrect.X; // _groupframeList[i].Y = unionrect.Y; // } // _currentSelectedElement[i].SelectedElementRect = selectedElementRect; // _currentSelectedElement[i].NoSelectedElementRect = noSelectedElementRect; // } // else if (i == -1 && (controlMovingValueX != 0 || controlMovingValueY != 0)) // { // _currentSelectedElement[i].SelectedElementRect = selectedElementRect; // } // } // _selectedElementRect = new Rect(); // foreach (int key in _currentSelectedElement.Keys) // { // if (_currentSelectedElement[key].SelectedGroupElementList.Count != 0) // { // if (_selectedElementRect == new Rect()) // { // _selectedElementRect = _currentSelectedElement[key].SelectedElementRect; // } // else // { // _selectedElementRect = Rect.Union(_selectedElementRect, _currentSelectedElement[key].SelectedElementRect); // } // } // } // #endregion #endregion e.Handled = true; }
private void OnCmdSenderBut(IRectElement senderElement) { RectElement currentScreen = new RectElement(); currentScreen.SenderIndex = senderElement.SenderIndex ; currentScreen.EleType = ElementType.sender; currentScreen.OperateEnviron = OperatEnvironment.AdjustSenderLocation; currentScreen.ConnectedIndex = senderElement.ConnectedIndex; CurrentScreen = currentScreen; }
/// <summary> /// 切换设计界面和调整映射位置界面 /// </summary> /// private void IniDisplayScreen(int senderIndex, RectLayer screenLocationRectLayer, RectLayer screenBaseRectLayer) { //由每个屏的发送卡带载生成各个显示屏带载 ///// for (int i = 0; i < MyScreen.ElementCollection.Count; i++) { if (MyScreen.ElementCollection[i].ConnectedIndex < 0) { continue; } RectLayer screenRectLayer = ((RectLayer)(((RectLayer)MyScreen.ElementCollection[i]).ElementCollection[0])); Rect screenRect = screenRectLayer.SenderConnectInfoList[senderIndex].LoadSize; Point screenMapLocation = new Point(); for (int n = 0; n < screenRectLayer.SenderConnectInfoList[senderIndex].PortConnectInfoList.Count; n++) { if (screenRectLayer.SenderConnectInfoList[senderIndex].PortConnectInfoList[n].LoadSize.Width != 0 && screenRectLayer.SenderConnectInfoList[senderIndex].PortConnectInfoList[n].LoadSize.Height != 0) { screenMapLocation = screenRectLayer.SenderConnectInfoList[senderIndex].PortConnectInfoList[n].MapLocation; break; } } if (screenRect.Width == 0 || screenRect.Height == 0) { continue; } RectElement screen = new RectElement(screenMapLocation.X, screenMapLocation.Y, screenRect.Width, screenRect.Height, screenBaseRectLayer, i); screen.OperateEnviron = OperatEnvironment.AdjustScreenLocation; screen.ConnectedIndex = MyScreen.ElementCollection[i].ConnectedIndex; screen.Opacity = 0.5; string msg = ""; CommonStaticMethod.GetLanguageString("显示屏", "Lang_Global_Screen", out msg); screen.DisplayName = msg + (screen.ConnectedIndex + 1); screenBaseRectLayer.ElementCollection.Add(screen); } }