public int AddFigure(IFigure figure, bool isUndoAction = false) { if (!isUndoAction) { figure.ID = maxID++; ActionWithFigure undoAction = new ActionWithFigure(figure, RemoveFigure); undoStack.Push(undoAction); Console.WriteLine("Add Figure {0}", figure.ID); } if (!figureDic.ContainsKey(figure.ID)) { figureDic.Add(figure.ID, figure); } else { Console.WriteLine("Error on adding, a figure with ID {0} already exists", figure.ID); } return figure.ID; }
private int RotateClockwize(IFigure figure, double angle, bool isUndoAction = false) { if (!isUndoAction) { ActionWithFigure undoAction = new ActionWithFigure(figure, RotateClockwize, -angle); undoStack.Push(undoAction); } figure.RotateClockwize(angle); Console.WriteLine("Rotate Figure {0}", figure.ID); return figure.ID; }
private int RemoveFigure(IFigure figure, bool isUndoAction = false) { if (figureDic.ContainsKey(figure.ID)) { figureDic.Remove(figure.ID); } if (!isUndoAction) { ActionWithFigure undoAction = new ActionWithFigure(figure, AddFigure); undoStack.Push(undoAction); Console.WriteLine("Remove Figure {0}", figure.ID); } return figure.ID; }
private int ResizeFigure(IFigure figure, double k, bool isUndoAction = false) { if (!isUndoAction) { ActionWithFigure undoAction = new ActionWithFigure(figure, ResizeFigure, 1/k); undoStack.Push(undoAction); } figure.Resize(k); Console.WriteLine("Resize Figure {0}", figure.ID); return figure.ID; }
private int MoveFigure(IFigure figure, double deltaX, double deltaY, bool isUndoAction = false) { if (!isUndoAction) { ActionWithFigure undoAction = new ActionWithFigure(figure, MoveFigure, -deltaX, -deltaY); undoStack.Push(undoAction); } figure.Move(deltaX, deltaY); Console.WriteLine("Move Figure {0}", figure.ID); return figure.ID; }