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];
public void Restore(int transactionId) { if (SavedStates.TryGetValue(transactionId, out var savedState)) { SavedStates[transactionId] = _savedCellContent; _savedCellContent = savedState; RejectChanges(); } }
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); } }
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)); }
public void Update(CellContent cellContent) { HostedCell.Apply(cellContent); }