示例#1
0
        public void SetMainData(MainData mainData)
        {
            var rowNum = 0;

            foreach (var rowData in mainData.RowDataList)
            {
                rowNum++;

                var rowBlock          = new RowBlock(this);
                var rowBlockViewModel = (VMRowBlock)rowBlock.DataContext;

                rowBlockViewModel.SetParams(this, rowData);
                rowBlockViewModel.PropertyChanged += RowViewModel_PropertyChanged;
                rowBlockViewModel.CreateCells(_cellDataList.Where(x => x.RowNum == rowNum)?.ToList());
                rowBlockViewModel.UpdateFacade();
                rowBlockViewModel.UpdateDirection();
                //rowBlockViewModel.UpdateDoorDirection();
                rowBlockViewModel.UpdateBusPositions();
                rowBlockViewModel.UpdateCellPanel();

                RowViewModelList.Add(rowBlockViewModel);

                ControlsCollection.Add(rowBlock);
            }

            LinkDataList       = mainData.LinkDataList ?? new List <LinkData>();
            _isCellsStandalone = mainData.IsCellsStandalone;
            if (_isCellsStandalone)
            {
                ReorganizeCells(true);
            }

            AreaWidth  = mainData.Width;
            AreaHeight = mainData.Height;

            UpdateAll();
            StageSave();
        }
        public void AddRow()
        {
            if ((RowViewModelList.Count != 0 && !_secondsRow) || (RowViewModelList.Count == 2))
            {
                return;
            }

            DeselectBlocks();
            var rowData           = new RowData();
            var rowBlock          = new RowBlock(this);
            var rowBlockViewModel = (VMRowBlock)rowBlock.DataContext;

            rowBlockViewModel.SetParams(this, rowData);
            rowBlockViewModel.PropertyChanged += RowViewModel_PropertyChanged;

            var facade        = Facade.Down;
            var direction     = Direction.LeftToRight;
            var doorDirection = DoorDirection.Left;

            if (RowViewModelList.Count == 0)
            {
                foreach (var cell in _cellDataList)
                {
                    cell.RowNum = 1;
                }
                rowBlockViewModel.CreateCells(_cellDataList);
            }
            else
            {
                var lastCells = RowViewModelList.Last();

                List <CellData> cellDatas = new List <CellData>();

                int count = _cellDataList.Count;
                for (int i = 0; i < count; i++)
                {
                    CellData cellData = new CellData(_cellDataList[i]);
                    cellData.SystemNum = cellData.SystemNum + count;
                    cellData.IndexNum  = cellData.IndexNum + count + 1;
                    cellData.RowNum    = cellData.RowNum + 1;
                    cellData.UserNum   = cellData.IndexNum.ToString();
                    cellDatas.Add(cellData);
                    _cellDataList.Add(cellData);
                }
                rowBlockViewModel.CreateCells(cellDatas);
                rowBlockViewModel.DirectY = AreaHeight - cellDatas.Max(x => x.Depth) / Constants.MainScale;
                if (RowViewModelList.Last().Facade == Facade.Down)
                {
                    facade = Facade.Up;
                }
                if (RowViewModelList.Last().Direction == Direction.LeftToRight)
                {
                    direction = Direction.RightToLeft;
                }
                if (RowViewModelList.Last().DoorDirection == DoorDirection.Left)
                {
                    doorDirection = DoorDirection.Right;
                }
                RowViewModelList.Last().UpdateCellPanel();
            }

            rowBlockViewModel.UpdateFacade(facade);
            rowBlockViewModel.UpdateDirection(direction);
            rowBlockViewModel.UpdateDoorDirection(doorDirection);
            rowBlockViewModel.UpdateBusPositions();
            rowBlockViewModel.UpdateCellPanel();

            RowViewModelList.Add(rowBlockViewModel);

            ControlsCollection.Add(rowBlock);

            UpdateRowPosition(RowViewModelList.Count > 1 ? RowViewModelList[RowViewModelList.Count - 2] : null, rowBlockViewModel);
            UpdateAll();
            StageSave();
        }