示例#1
0
        public bool MoveCells(Position from, Position to, int offsetX, int offsetY)
        {
            if (offsetX == 0 && offsetY == 0)
            {
                return(true);
            }

            var points = new[]
            {
                from,
                to.Offset(-1, -1),
                from.Offset(offsetX, offsetY),
                to.Offset(offsetX - 1, offsetY - 1)
            };

            foreach (var point in points)
            {
                if (point.X < 0 || point.Y < 0 || point.X >= Width || point.Y >= Height)
                {
                    return(false);
                }
            }

            var width  = to.X - from.X;
            var height = to.Y - from.Y;

            var tempCells = new CellContent[height, width];
            var tempLinks = new (LinkContent right, LinkContent bottom)[height + 1, width + 1];
示例#2
0
            public void Restore(int transactionId)
            {
                if (SavedStates.TryGetValue(transactionId, out var savedState))
                {
                    SavedStates[transactionId] = _savedCellContent;

                    _savedCellContent = savedState;
                    RejectChanges();
                }
            }
示例#3
0
            public void CommitChanges(int transactionId, bool revertable)
            {
                if (revertable)
                {
                    SavedStates[transactionId] = _savedCellContent;
                }
                _savedCellContent = new CellContent(HostedCell);

                var maxSavedTransaction = SavedStates.Select(x => x.Key).DefaultIfEmpty(0).Max();

                for (var i = transactionId + 1; i <= maxSavedTransaction; i++)
                {
                    SavedStates.Remove(i);
                }
            }
示例#4
0
        public SavedLayer Save()
        {
            var cells       = new CellContent[Height, Width];
            var rightLinks  = new LinkContent[Height, Width];
            var bottomLinks = new LinkContent[Height, Width];

            for (var i = 0; i < Height; i++)
            {
                for (var j = 0; j < Width; j++)
                {
                    var cell = Cells[i, j];
                    cells[i, j]       = new CellContent(cell);
                    rightLinks[i, j]  = new LinkContent(cell.Links[Side.Right].SiliconLink, cell.Links[Side.Right].HasMetalLink);
                    bottomLinks[i, j] = new LinkContent(cell.Links[Side.Bottom].SiliconLink, cell.Links[Side.Bottom].HasMetalLink);
                }
            }

            var data = new LayerData(cells, rightLinks, bottomLinks);

            return(new SavedLayer(Template, data));
        }
示例#5
0
 public void Update(CellContent cellContent)
 {
     HostedCell.Apply(cellContent);
 }