Undo support, limit selection, not select already selected

Added undo support, limit selection to 4 bricks, and not allow
selecting already selected bricks.