#include<stk.h>
#include<strstream.h>
#include<LINK/stkWrapper/LINK_STk.h>
#include<LINK/layout/Layouts.h>
#include<LINK/algorithm/Algorithms.h>
#include<LINK/graph/Graph.h>

static PRIMITIVE CircleLayoutCmd(SCM g)
{
        Graph *gr;
        if (!(gr = getGraph(g)))
                Err("circle-layout!: bad arg 1, graph expected", g);
        CircleLayout(gr);

        return UNDEFINED;
}

static PRIMITIVE CircleLayoutAnimCmd(SCM g, SCM gv)
{
        Graph *gr;
        if (!(gr = getGraph(g)))
                Err("circle-layout!: bad arg 1, graph expected", g);
        CircleLayout(gr);
	char *vname = getViewName(gv);
	path_draw(vname);
	layoutVertices(vname);

        return UNDEFINED;
}

void gen_CircleLayout_Wrapper()
{
        STk_add_new_cpp_primitive("circle-layout", tc_subr_1,
                               (PRIMITIVE (*)(...))CircleLayoutCmd);
        STk_add_new_cpp_primitive("circle-layout*", tc_subr_2,
                               (PRIMITIVE (*)(...))CircleLayoutAnimCmd);
}
#include<stk.h>
#include<strstream.h>
#include<LINK/basic/Set.h>
#include<LINK/stkWrapper/LINK_STk.h>
#include<LINK/stkWrapper/CollectionWrapper.h>
#include<LINK/layout/Layouts.h>
#include<LINK/algorithm/Algorithms.h>
#include<LINK/graph/Graph.h>

static PRIMITIVE ComponentLayoutCmd(SCM gparms, int len)
{
        SCM g, ssv, layout1, layout2;

        if (len < 4)
                return UNDEFINED;
        g = CAR(gparms);
        ssv = CAR(CDR(gparms));
        layout1 = CAR(CDR(CDR(gparms)));
        layout2 = CAR(CDR(CDR(CDR(gparms))));

        Graph *gr;
        if (!(gr = getGraph(g)))
                Err("component-layout!: bad arg 1, graph expected", g);
        Collection<Set<Vertex*> >* svc =
                        CollectionWrapper<Set<Vertex*> >::getCollection(ssv);
	if (!svc)
                Err("component-layout!: bad arg 2, <set<set<Vertex*>> expected",
					ssv);
        if (!STRINGP(layout1))
                Err("component-layout!: bad arg 3, string expected", layout1);
        if (!STRINGP(layout2))
                Err("component-layout!: bad arg 4, string expected", layout2);
        ComponentLayout(gr, *svc, getLayout(CHARS(layout1)), 
				  getLayout(CHARS(layout2)));

        return UNDEFINED;
}

void gen_ComponentLayout_Wrapper()
{
        STk_add_new_cpp_primitive("component-layout", tc_lsubr,
                               (PRIMITIVE (*)(...))ComponentLayoutCmd);
}
#include<stk.h>
#include<strstream.h>
#include<LINK/stkWrapper/LINK_STk.h>
#include<LINK/layout/Layouts.h>
#include<LINK/algorithm/Algorithms.h>
#include<LINK/graph/Graph.h>

static PRIMITIVE ComponentLayout2Cmd(SCM g, SCM chunks, SCM chunk_size)
{
        Graph *gr;
        if (!(gr = getGraph(g)))
                Err("grid-layout!: bad arg 1, graph expected", g);
        if (!INTEGERP(chunks))
                Err("grid-layout!: bad arg 2, #chunks expected", chunks);
        if (!INTEGERP(chunk_size))
                Err("grid-layout!: bad arg 2, chunk_size expected", chunk_size);
        ComponentLayout2(gr, INTEGER(chunks), INTEGER(chunk_size));

        return UNDEFINED;
}

static PRIMITIVE ComponentLayout2AnimCmd(SCM gparms, int len)
{
        SCM g, gv, chunks, chunk_size;

        if (len < 4)
                return UNDEFINED;
        g = CAR(gparms);
        gv = CAR(CDR(gparms));
        chunks = CAR(CDR(CDR(gparms)));
        chunk_size = CAR(CDR(CDR(CDR(gparms))));

	Graph *gr;
        if (!(gr = getGraph(g)))
                Err("grid-layout!: bad arg 1, graph expected", g);
	char *vname = getViewName(gv);
        if (!INTEGERP(chunks))
                Err("grid-layout!: bad arg 2, #chunks expected", chunks);
        if (!INTEGERP(chunk_size))
                Err("grid-layout!: bad arg 2, chunk_size expected", chunk_size);
        ComponentLayout2(gr, INTEGER(chunks), INTEGER(chunk_size));
	path_draw(vname);
	layoutVertices(vname);
        return UNDEFINED;
}

void gen_ComponentLayout2_Wrapper()
{
        STk_add_new_cpp_primitive("component-layout2", tc_subr_3,
                               (PRIMITIVE (*)(...))ComponentLayout2Cmd);
        STk_add_new_cpp_primitive("grid-layout2*", tc_lsubr, 
                               (PRIMITIVE (*)(...))ComponentLayout2AnimCmd);
}
#include<stk.h>
#include<strstream.h>
#include<LINK/stkWrapper/LINK_STk.h>
#include<LINK/layout/Layouts.h>
#include<LINK/algorithm/Algorithms.h>
#include<LINK/graph/Graph.h>

static PRIMITIVE GridLayoutCmd(SCM g, SCM rows, SCM cols)
{
        Graph *gr;
        if (!(gr = getGraph(g)))
                Err("grid-layout!: bad arg 1, graph expected", g);
        if (!INTEGERP(rows))
                Err("grid-layout!: bad arg 2, #rows expected", rows);
        if (!INTEGERP(cols))
                Err("grid-layout!: bad arg 2, #cols expected", cols);
        GridLayout(gr, INTEGER(rows), INTEGER(cols));

        return UNDEFINED;
}

static PRIMITIVE GridLayoutAnimCmd(SCM gparms, int len)
{
        SCM g, gv, rows, cols;

        if (len < 4)
                return UNDEFINED;
        g = CAR(gparms);
        gv = CAR(CDR(gparms));
        rows = CAR(CDR(CDR(gparms)));
        cols = CAR(CDR(CDR(CDR(gparms))));

	Graph *gr;
        if (!(gr = getGraph(g)))
                Err("grid-layout!: bad arg 1, graph expected", g);
	char *vname = getViewName(gv);
        if (!INTEGERP(rows))
                Err("grid-layout!: bad arg 2, #rows expected", rows);
        if (!INTEGERP(cols))
                Err("grid-layout!: bad arg 2, #cols expected", rows);
        GridLayout(gr, INTEGER(rows), INTEGER(cols));
	path_draw(vname);
	layoutVertices(vname);
        return UNDEFINED;
}

void gen_GridLayout_Wrapper()
{
        STk_add_new_cpp_primitive("grid-layout", tc_subr_3,
                               (PRIMITIVE (*)(...))GridLayoutCmd);
        STk_add_new_cpp_primitive("grid-layout*", tc_lsubr, 
                               (PRIMITIVE (*)(...))GridLayoutAnimCmd);
}
#include<stk.h>
#include<LINK/stkWrapper/LINK_STk.h>
#include<LINK/layout/Layouts.h>
#include<LINK/algorithm/Algorithms.h>
#include<LINK/graph/Graph.h>

static PRIMITIVE HyperBipartiteLayoutCmd(SCM g)
{
        Graph *gr;
        if (!(gr = getGraph(g)))
                Err("bipartite-layout!: bad arg 1, graph expected", g);
        HyperBipartiteLayout(gr);

        return UNDEFINED;
}

static PRIMITIVE HyperBipartiteLayoutAnimCmd(SCM g, SCM gv)
{
        Graph *gr;
        if (!(gr = getGraph(g)))
                Err("bipartite-layout!: bad arg 1, graph expected", g);
        HyperBipartiteLayout(gr);
	char *vname = getViewName(gv);
	star_draw(vname);
	layoutVertices(vname);
	layoutEdges(vname);

        return UNDEFINED;
}

void gen_HyperBipartiteLayout_Wrapper()
{
        STk_add_new_cpp_primitive("bipartite-layout", tc_subr_1,
                               (PRIMITIVE (*)(...))HyperBipartiteLayoutCmd);
        STk_add_new_cpp_primitive("bipartite-layout*", tc_subr_2,
                               (PRIMITIVE (*)(...))HyperBipartiteLayoutAnimCmd);
}
#include<stk.h>
#include<strstream.h>
#include<LINK/stkWrapper/LINK_STk.h>
#include<LINK/layout/Layouts.h>
#include<LINK/algorithm/Algorithms.h>
#include<LINK/graph/Graph.h>

static PRIMITIVE RandomLayoutCmd(SCM g)
{
        Graph *gr;
        if (!(gr = getGraph(g)))
                Err("circle-layout!: bad arg 1, graph expected", g);
        RandomLayout(gr);

        return UNDEFINED;
}

static PRIMITIVE RandomLayoutAnimCmd(SCM g, SCM gv)
{
        Graph *gr;
        if (!(gr = getGraph(g)))
                Err("circle-layout!: bad arg 1, graph expected", g);
        RandomLayout(gr);
	char *vname = getViewName(gv);
	path_draw(vname);
	layoutVertices(vname);

        return UNDEFINED;
}

void gen_RandomLayout_Wrapper()
{
        STk_add_new_cpp_primitive("random-layout", tc_subr_1,
                               (PRIMITIVE (*)(...))RandomLayoutCmd);
        STk_add_new_cpp_primitive("random-layout*", tc_subr_2,
                               (PRIMITIVE (*)(...))RandomLayoutAnimCmd);
}
#include<stk.h>
#include<strstream.h>
#include<LINK/stkWrapper/LINK_STk.h>
#include<LINK/layout/Layouts.h>
#include<LINK/algorithm/Algorithms.h>
#include<LINK/graph/Graph.h>

static PRIMITIVE SpringLayoutCmd(SCM g)
{
        Graph *gr;
        if (!(gr = getGraph(g)))
                Err("spring-layout: bad arg 1, graph expected", g);
        SpringLayout(gr);

        return UNDEFINED;
}

static PRIMITIVE SpringLayoutAnimCmd(SCM g, SCM gv)
{
        Graph *gr;
        if (!(gr = getGraph(g)))
                Err("spring-layout: bad arg 1, graph expected", g);
        SpringLayout(gr);
	char *vname = getViewName(gv);
	layoutVertices(vname);
	if (!gr->binaryQ()) {
		star_draw(vname);
		layoutEdges(vname);
	} else
		path_draw(vname);

        return UNDEFINED;
}

void gen_SpringLayout_Wrapper()
{
        STk_add_new_cpp_primitive("spring-layout", tc_subr_1,
                               (PRIMITIVE (*)(...))SpringLayoutCmd);
        STk_add_new_cpp_primitive("spring-layout*", tc_subr_2,
                               (PRIMITIVE (*)(...))SpringLayoutAnimCmd);
}
