/// <summary> /// Проверка ряда с боковым фасадом на пересечение с предыдущими по вертикальной оси координат /// </summary> public bool CheckRowConnectOffset(VMRowBlock rowBlockVM) { if (rowBlockVM.Facade == Facade.Down || rowBlockVM.Facade == Facade.Up) { return(false); } var maxOffset = 0; foreach (var control in _controlsCollection) { if (control is RowBlock rowBlock) { var rowBlockViewModel = (VMRowBlock)rowBlock.DataContext; if (rowBlockViewModel == rowBlockVM) { break; } if (maxOffset < rowBlockViewModel.DirectX + rowBlockViewModel.GetWidth()) { maxOffset = rowBlockViewModel.DirectX + rowBlockViewModel.GetWidth(); } } } maxOffset -= (rowBlockVM.GetWidth() / 2); return(rowBlockVM.DirectX >= maxOffset); }
/// <summary> /// Пересоздание ConnectRow's, исходя из смещений RowBlock'ов /// </summary> public void UpdateRowConnects() { var connectRowList = new List <ConnectRow>(); VMRowBlock lastRowBlockViewModel = null; VMConnectRow lastConnectRowViewModel = null; var lastXOffset = 0; var lastYOffset = 0; //while (_controlsCollection.Any(x => x.GetType() == typeof(ConnectRow)) && ((ConnectRowViewModel)((ConnectRow)_controlsCollection.First(x => x.GetType() == typeof(ConnectRow))).DataContext).CabBlock == null) //{ // ControlsCollection.Remove(_controlsCollection.First(x => x.GetType() == typeof(ConnectRow) && ((ConnectRowViewModel)((ConnectRow)x).DataContext).CabBlock == null)); //} //foreach (var control in _controlsCollection) //{ // if (control is ConnectRow) // { // var cr = (ConnectRow)control; // var crvm = (ConnectRowViewModel)cr.DataContext; // if (crvm.CabBlock == null) ControlsCollection.Remove(cr); // } //} //if (_isHideConnects) return; foreach (var control in _controlsCollection) { if (control is RowBlock rowBlock) { var rowBlockViewModel = (VMRowBlock)rowBlock.DataContext; var connectLeft = new ConnectRow(); var connectRight = new ConnectRow(); var connectTop = new ConnectRow(); var connectLeftViewModel = (VMConnectRow)connectLeft.DataContext; var connectRightViewModel = (VMConnectRow)connectRight.DataContext; var connectTopViewModel = (VMConnectRow)connectTop.DataContext; connectLeftViewModel.IsInvisible = _isHideConnects; connectLeftViewModel.X = 0; connectLeftViewModel.Y = rowBlockViewModel.DirectY + (rowBlockViewModel.GetHeight() / 2); connectLeftViewModel.Size = rowBlockViewModel.DirectX * Constants.MainScale; connectRightViewModel.IsInvisible = _isHideConnects; connectRightViewModel.X = rowBlockViewModel.DirectX + rowBlockViewModel.GetWidth(); connectRightViewModel.Y = rowBlockViewModel.DirectY + (rowBlockViewModel.GetHeight() / 2); connectRightViewModel.Size = (_areaWidth - (rowBlockViewModel.DirectX + rowBlockViewModel.GetWidth())) * Constants.MainScale; var xOffsetFix = rowBlockViewModel.DirectX + (rowBlockViewModel.GetWidth() / 2); //if (lastRowBlockViewModel != null && !CheckRowConnectOffset(rowBlockViewModel) // && lastRowBlockViewModel.XOffset + (lastRowBlockViewModel.GetWidth() / 2) // < rowBlockViewModel.XOffset + (rowBlockViewModel.GetWidth() / 2)) // xOffsetFix = lastRowBlockViewModel.XOffset + (lastRowBlockViewModel.GetWidth() / 2); if ((rowBlockViewModel.Facade == Facade.Down || rowBlockViewModel.Facade == Facade.Up) && lastRowBlockViewModel?.DirectX + (lastRowBlockViewModel?.GetWidth() / 2) < rowBlockViewModel.DirectX + (rowBlockViewModel.GetWidth() / 2)) { xOffsetFix = lastRowBlockViewModel.DirectX + (lastRowBlockViewModel.GetWidth() / 2); } var yOffsetFix = CheckRowConnectOffset(rowBlockViewModel) ? 0 : lastYOffset; connectTopViewModel.IsInvisible = _isHideConnects; connectTopViewModel.X = xOffsetFix; connectTopViewModel.Y = yOffsetFix; connectTopViewModel.Size = (rowBlockViewModel.DirectY - yOffsetFix) * Constants.MainScale; connectLeftViewModel.MainBlockViewModel = this; connectLeftViewModel.RowBlockVM = rowBlockViewModel; connectLeftViewModel.ConnectSide = ConnectSide.Left; connectRightViewModel.MainBlockViewModel = this; connectRightViewModel.RowBlockVM = rowBlockViewModel; connectRightViewModel.ConnectSide = ConnectSide.Right; connectTopViewModel.MainBlockViewModel = this; connectTopViewModel.RowBlockVM = rowBlockViewModel; connectTopViewModel.LastRowBlockVM = lastRowBlockViewModel; connectTopViewModel.ConnectSide = ConnectSide.Top; connectRowList.Add(connectLeft); connectRowList.Add(connectRight); connectRowList.Add(connectTop); Panel.SetZIndex(connectLeft, 5); Panel.SetZIndex(connectRight, 5); Panel.SetZIndex(connectTop, 5); if (_controlsCollection.Any(x => x.GetType() == typeof(RowBlock)) && control == _controlsCollection.Last(x => x.GetType() == typeof(RowBlock))) { var connectBottom = new ConnectRow(); var connectBottomViewModel = (VMConnectRow)connectBottom.DataContext; connectBottomViewModel.IsInvisible = _isHideConnects; connectBottomViewModel.X = rowBlockViewModel.DirectX + (rowBlockViewModel.GetWidth() / 2); connectBottomViewModel.Y = rowBlockViewModel.DirectY + rowBlockViewModel.GetHeight(); connectBottomViewModel.Size = (_areaHeight - (rowBlockViewModel.DirectY + rowBlockViewModel.GetHeight())) * Constants.MainScale; var minBottomSize = (rowBlockViewModel.Facade == Facade.Down ? RowMinFacadeSize : RowMinVerticalSize); if (connectBottomViewModel.Size < minBottomSize) { connectBottomViewModel.Size = minBottomSize; } connectBottomViewModel.MainBlockViewModel = this; connectBottomViewModel.RowBlockVM = rowBlockViewModel; connectBottomViewModel.LastRowBlockVM = lastRowBlockViewModel; connectBottomViewModel.ConnectSide = ConnectSide.Bottom; connectRowList.Add(connectBottom); Panel.SetZIndex(connectBottom, 5); } if (lastConnectRowViewModel != null) { lastConnectRowViewModel.RowBlockVM2 = rowBlockViewModel; } lastConnectRowViewModel = connectTopViewModel; lastRowBlockViewModel = rowBlockViewModel; lastXOffset = rowBlockViewModel.DirectX + rowBlockViewModel.GetWidth(); lastYOffset = rowBlockViewModel.DirectY + rowBlockViewModel.GetHeight(); } } foreach (var connect in connectRowList) { ControlsCollection.Add(connect); } }