/*  Copyright (C) 2010 Joshua Judson Rosen <rozzin@geekspace.com>.

    This program is free software: you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    version 3 as published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; see the file COPYING. If not, see
    <http://www.gnu.org/licenses/> or write to:

        The Free Software Foundation, inc.
        51 Franklin Street, Fifth Floor
        Boston, MA 02110-1301
        USA
*/

#include <string.h>
#include <stdarg.h>

#include <glib.h>
#include <glib-object.h>
#include "virand/generator.h"
#include "generator.h"

#include <cairo.h>
#include "graphics.h"
#include "radial.h"
#include "spiral.h"
#include "line.h"
#include "figure.h"
#include "metashape.h"
#include "shape.h"
#include "path.h"
#include "symmetry.h"

struct _VisualID_GeneratorClass
{
  GObjectClass parent_class;
};

G_DEFINE_TYPE (VisualID_Generator, visualid_generator, G_TYPE_OBJECT)

void
visualid_generator_dispose (GObject *self)
{
  VisualID_Generator *generator = VISUALID_GENERATOR (self);

  if (generator->roots) {
    g_object_unref (generator->roots);
    generator->roots = NULL;
  }

  if (generator->children) {
    g_object_unref (generator->children);
    generator->children = NULL;
  }

  if (generator->terminals) {
    g_object_unref (generator->terminals);
    generator->terminals = NULL;
  }
}

void
visualid_generator_init (VisualID_Generator *generator)
{
  generator->recursion_max = 3;
  generator->complexity_max = 5000;

  generator->roots =
    virand_generator_new ((gpointer) VISUALID_TYPE_RADIAL, 1,
                          (gpointer) VISUALID_TYPE_FIGURE, 1,
                          (gpointer) VISUALID_TYPE_SHAPE, 1,
                          (gpointer) VISUALID_TYPE_PATH, 1,
                          (gpointer) VISUALID_TYPE_LINE, 1,
                          (gpointer) VISUALID_TYPE_SYMMETRY, 1,
                          (gpointer) VISUALID_TYPE_SPIRAL, 1,
                          NULL);
  generator->state = virand_generator_state (generator->roots);

  generator->children =
    virand_generator_new ((gpointer) VISUALID_TYPE_RADIAL, 1,
                          (gpointer) VISUALID_TYPE_FIGURE, 1,
                          (gpointer) VISUALID_TYPE_SHAPE, 1,
                          (gpointer) VISUALID_TYPE_PATH, 1,
                          (gpointer) VISUALID_TYPE_LINE, 1,
                          (gpointer) VISUALID_TYPE_SYMMETRY, 1,
                          (gpointer) VISUALID_TYPE_SPIRAL, 1,
                          NULL);
  virand_generator_share_state (generator->children, generator->roots);

  generator->terminals =
    virand_generator_new ((gpointer) VISUALID_TYPE_LINE, 1,
                          NULL);
  virand_generator_share_state (generator->terminals, generator->roots);
}

void
visualid_generator_class_init (VisualID_GeneratorClass *class)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS (class);

  gobject_class->dispose = visualid_generator_dispose;
}

