Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
        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;
        }
Exemplo n.º 4
0
        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;
        }
Exemplo n.º 5
0
 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;
 }