#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);
}
