/// <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); }
public void CellSelectMode() { DeselectBlocks(); _selectedRowVM = null; _selectedCellData = null; _selectMode = SelectMode.Single; foreach (var rowVM in RowViewModelList) { rowVM.ChangeSelectMode(_selectMode); } }
private List <MenuItem> GetCellNumbersMenu(VMRowBlock rowVM, List <CellData> cellsData, CellData cellData) { var cellTypesMenu = new List <MenuItem>(); foreach (var cellKey in cellsData) { if (cellKey.SectionNum != cellData.SectionNum) { continue; } if (cellKey.SystemNum == cellData.SystemNum) { continue; } var cellTypeMenu = new MenuItem { Header = cellKey.UserNum + " " + cellKey.UserName }; cellTypeMenu.Click += new RoutedEventHandler((sender, e) => MenuItem_Click(sender, e, delegate { var selectedCell = cellsData.Find(x => x.SystemNum == cellData.SystemNum); var replacedCell = cellsData.Find(x => x.SystemNum == cellKey.SystemNum); var indexNum = selectedCell.IndexNum; var systemNum = selectedCell.SystemNum; var userNum = selectedCell.UserNum; selectedCell.IndexNum = replacedCell.IndexNum; selectedCell.SystemNum = replacedCell.SystemNum; selectedCell.UserNum = replacedCell.UserNum; replacedCell.IndexNum = indexNum; replacedCell.SystemNum = systemNum; replacedCell.UserNum = userNum; rowVM.UpdateDirection(); rowVM.UpdateBusPositions(); })); cellTypesMenu.Add(cellTypeMenu); } return(cellTypesMenu); }
/// <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); } }
/// <summary> /// Смещение RowBlock'а, исходя из ориентаций его и предыдущего фасадов /// </summary> public void UpdateRowPosition(VMRowBlock lastRowBlockViewModel, VMRowBlock rowBlockViewModel) { //var lastFacade = Facade.NA; //var lastXOffset = 0; //var lastYOffset = 0; //if (lastRowBlockViewModel != null) //{ // lastFacade = lastRowBlockViewModel.Facade; // lastXOffset = lastRowBlockViewModel.DirectX; // lastYOffset = lastRowBlockViewModel.DirectY + lastRowBlockViewModel.GetHeight(); //} //switch (lastFacade) //{ // case Facade.NA: // case Facade.Up: // case Facade.Left: // case Facade.Right: // { // switch (rowBlockViewModel.Facade) // { // case Facade.Up: // { // rowBlockViewModel.DirectX = lastXOffset != 0 ? lastXOffset : RowMinHorizontalSize / Constants.MainScale; // rowBlockViewModel.DirectY = lastYOffset + (RowMinFacadeSize / Constants.MainScale); // } // break; // case Facade.Down: // { // rowBlockViewModel.DirectX = lastXOffset != 0 ? lastXOffset : RowMinHorizontalSize / Constants.MainScale; // rowBlockViewModel.DirectY = lastYOffset + (RowMinVerticalSize / Constants.MainScale); // } // break; // case Facade.Left: // { // rowBlockViewModel.DirectX = RowMinFacadeSize / Constants.MainScale; // rowBlockViewModel.DirectY = lastYOffset + (RowMinVerticalSize / Constants.MainScale); // } // break; // case Facade.Right: // { // rowBlockViewModel.DirectX = RowMinVerticalSize / Constants.MainScale; // rowBlockViewModel.DirectY = lastYOffset + (RowMinVerticalSize / Constants.MainScale); // } // break; // } // } // break; // case Facade.Down: // { // switch (rowBlockViewModel.Facade) // { // case Facade.Up: // { // rowBlockViewModel.DirectX = lastXOffset != 0 ? lastXOffset : RowMinHorizontalSize / Constants.MainScale; // rowBlockViewModel.DirectY = lastYOffset + (RowMaxFacadeSize / Constants.MainScale); // } // break; // case Facade.Down: // { // rowBlockViewModel.DirectX = lastXOffset != 0 ? lastXOffset : RowMinHorizontalSize / Constants.MainScale; // rowBlockViewModel.DirectY = lastYOffset + (RowMinFacadeSize / Constants.MainScale); // } // break; // case Facade.Left: // { // rowBlockViewModel.DirectX = RowMinFacadeSize / Constants.MainScale; // rowBlockViewModel.DirectY = lastYOffset + (RowMinFacadeSize / Constants.MainScale); // } // break; // case Facade.Right: // { // rowBlockViewModel.DirectX = RowMinVerticalSize / Constants.MainScale; // rowBlockViewModel.DirectY = lastYOffset + (RowMinFacadeSize / Constants.MainScale); // } // break; // } // } // break; //} }