diff options
Diffstat (limited to 'Master/texmf-dist/source/generic/pgf/c')
58 files changed, 4216 insertions, 0 deletions
diff --git a/Master/texmf-dist/source/generic/pgf/c/INSTALL b/Master/texmf-dist/source/generic/pgf/c/INSTALL new file mode 100644 index 00000000000..0690faba7d2 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/INSTALL @@ -0,0 +1,28 @@ +In order to use the C code in these directories, you should first +modify / setup the file config/LocalMakefileConfig.mk, which is +included by the main Makefiles and allows you to overwrite the +settings from config/Makefile.mk. + +Once this is done, run make. + +You must then use the install targets to copy / link the resulting +shared libraries with their full paths into the "luatex/lib" +subdirectory of the directory where your TeX executable resides. For +instance, if the luatex program is in + +/usr/texbin + +then you would put SimpleDemoC.so into + +/usr/texbin/lib/luatex/lua/pgf/gd/examples/c + + +Due to bugs in the LuaTeX code, you currently need to append the paths +of the libraries to their name as done in the Makefiles. + +Note that, currently, the Makefile will link the Lua library +statically into the shared graph drawing library (at least on +MacOS). This is conceptually wrong and, indeed, a lot of effort was +need to avoid having LuaTeX crash on a TeX run because of two Lua +libraries being used simultaneously. It works, but hopefully, in the +fututure, this will be fixed.
\ No newline at end of file diff --git a/Master/texmf-dist/source/generic/pgf/c/Makefile b/Master/texmf-dist/source/generic/pgf/c/Makefile new file mode 100644 index 00000000000..a71312aeaf5 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/Makefile @@ -0,0 +1,35 @@ +.PHONY : all clean examples ogdf + +all: + $(MAKE) -C graphdrawing/pgf/gd/interface/c + $(MAKE) -C graphdrawing/pgf/gd/examples/c + $(MAKE) -C graphdrawing/pgf/gd/ogdf/c + +install_all: + $(MAKE) -C graphdrawing/pgf/gd/interface/c install + $(MAKE) -C graphdrawing/pgf/gd/examples/c install + $(MAKE) -C graphdrawing/pgf/gd/ogdf/c install + +examples: + $(MAKE) -C graphdrawing/pgf/gd/interface/c + $(MAKE) -C graphdrawing/pgf/gd/examples/c + +install_examples: + $(MAKE) -C graphdrawing/pgf/gd/interface/c install + $(MAKE) -C graphdrawing/pgf/gd/examples/c install + +ogdf: + $(MAKE) -C graphdrawing/pgf/gd/interface/c + $(MAKE) -C graphdrawing/pgf/gd/ogdf/c + +install_ogdf: + $(MAKE) -C graphdrawing/pgf/gd/interface/c install + $(MAKE) -C graphdrawing/pgf/gd/ogdf/c install + + + +clean: + $(MAKE) -C graphdrawing/pgf/gd/interface/c clean + $(MAKE) -C graphdrawing/pgf/gd/examples/c clean + $(MAKE) -C graphdrawing/pgf/gd/ogdf/c clean + diff --git a/Master/texmf-dist/source/generic/pgf/c/config/ExampleLocalMakefileConfig.mk b/Master/texmf-dist/source/generic/pgf/c/config/ExampleLocalMakefileConfig.mk new file mode 100644 index 00000000000..b42f097f545 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/config/ExampleLocalMakefileConfig.mk @@ -0,0 +1,7 @@ +MYCFLAGS=-isysroot/Developer/SDKs/MacOSX10.7.sdk +MYLDFLAGS= + +ARCHFLAGS=-arch x86_64 + +SHAREDFLAGS=-undefined dynamic_lookup -bundle -llua -L$(LUALIBPATH) + diff --git a/Master/texmf-dist/source/generic/pgf/c/config/MakefileConfig.mk b/Master/texmf-dist/source/generic/pgf/c/config/MakefileConfig.mk new file mode 100644 index 00000000000..25310b6987b --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/config/MakefileConfig.mk @@ -0,0 +1,45 @@ + +# Where Lua is installed +LUAPATH=/usr/local/lua52 + +LUAINCLUDES = $(LUAPATH)/include +LUALIBPATH = $(LUAPATH)/lib + + +# Where ogdf is installed +OGDFPATH=/usr/local/ogdf + +OGDFINCLUDES = $(OGDFPATH) +OGDFLIBPATH = $(OGDFPATH)/_release + + +# Where the pgf C includes are found +PGFINCLUDES=../../../.. + + +# Where the shared libraries should be installed (base dir) +INSTALLDIR=/usr/texbin/lib/luatex/lua + + +# If you need special flags: +MYCFLAGS= +MYLDFLAGS= + +# Link flags for building a shared library +SHAREDFLAGS= + +# Link flags for linking against the shared Lua lib +LINKSHAREDLUA= + +# Architecture flags: +ARCHFLAGS= + +# The to-be-used compiler +CC=gcc + + +# Now read local definition, which may overwrite the above +-include $(CONFIGDIR)/LocalMakefileConfig.mk + + + diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/examples/c/Makefile b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/examples/c/Makefile new file mode 100644 index 00000000000..320969d1909 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/examples/c/Makefile @@ -0,0 +1,35 @@ +CONFIGDIR=../../../../../config +include $(CONFIGDIR)/MakefileConfig.mk + +FLAGS=$(MYCFLAGS) $(ARCHFLAGS) -O2 -Wall -I$(LUAINCLUDES) -I$(PGFINCLUDES) + + +all: SimpleDemoC.so SimpleDemoCPlusPlus.so + +clean: + rm *.o *.so + +install: SimpleDemoC.so SimpleDemoCPlusPlus.so + mkdir -p $(INSTALLDIR)/pgf/gd/examples/c + cp SimpleDemoC.so $(INSTALLDIR)/pgf/gd/examples/c/pgf_gd_examples_c_SimpleDemoC.so + cp SimpleDemoCPlusPlus.so $(INSTALLDIR)/pgf/gd/examples/c/pgf_gd_examples_c_SimpleDemoCPlusPlus.so + +SimpleDemoC.so: SimpleDemoC.o + $(CC) $(FLAGS) $(SHAREDFLAGS) $(MYLDFLAGS) \ + $(LINKSHAREDLUA) \ + -o SimpleDemoC.so \ + SimpleDemoC.o ../../interface/c/InterfaceFromC.o + +SimpleDemoC.o: SimpleDemoC.c + $(CC) $(FLAGS) -c -o SimpleDemoC.o SimpleDemoC.c + + +SimpleDemoCPlusPlus.so: SimpleDemoCPlusPlus.o ../../interface/c/InterfaceFromC++.o ../../interface/c/InterfaceFromC.o + $(CC) $(FLAGS) $(SHAREDFLAGS) $(MYLDFLAGS) \ + $(LINKSHAREDLUA) \ + -o SimpleDemoCPlusPlus.so \ + SimpleDemoCPlusPlus.o ../../interface/c/InterfaceFromC++.o ../../interface/c/InterfaceFromC.o + +SimpleDemoCPlusPlus.o: SimpleDemoCPlusPlus.c++ ../../interface/c/InterfaceFromC++.h ../../interface/c/InterfaceFromC.h + g++ $(FLAGS) -c -o SimpleDemoCPlusPlus.o SimpleDemoCPlusPlus.c++ + diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/examples/c/SimpleDemoC.c b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/examples/c/SimpleDemoC.c new file mode 100644 index 00000000000..18e5889ad17 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/examples/c/SimpleDemoC.c @@ -0,0 +1,42 @@ +#include <pgf/gd/interface/c/InterfaceFromC.h> +#include <math.h> + +static void fast_hello_world (pgfgd_SyntacticDigraph* graph, void* v) { + double angle = 6.28318530718 / graph->vertices.length; + double radius = pgfgd_tonumber(graph->options, "fast simple demo radius"); + + int i; + for (i = 0; i < graph->vertices.length; i++) { + pgfgd_Vertex* v = graph->vertices.array[i]; + v->pos.x = cos(angle*i) * radius; + v->pos.y = sin(angle*i) * radius; + } +} + +int luaopen_pgf_gd_examples_c_SimpleDemoC (struct lua_State *state) { + pgfgd_Declaration* d; + + // The main layout key + d = pgfgd_new_key ("fast simple demo layout"); + pgfgd_key_summary (d, "The C version of the hello world of graph drawing."); + pgfgd_key_algorithm (d, fast_hello_world, 0); + pgfgd_key_documentation (d, + "Just like the |SimpleDemo| algorithm, this algorithm arranges \ + the nodes of a graph in a circle (without paying heed to the sizes of the \ + nodes or to the edges). Its main purpose is to show how C code \ + can access the Lua representation of graphs. See \ + Section~\ref{section-algorithms-in-c} of the manual for detais."); + pgfgd_key_add_precondition (d, "connected"); + pgfgd_declare (state, d); + pgfgd_free_key (d); + + // The radius key + d = pgfgd_new_key ("fast simple demo radius"); + pgfgd_key_summary (d, "A radius value for the hello world of graph drawing"); + pgfgd_key_type (d, "length"); + pgfgd_key_initial (d, "1cm"); + pgfgd_declare (state, d); + pgfgd_free_key (d); + + return 0; +} diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/examples/c/SimpleDemoCPlusPlus.c++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/examples/c/SimpleDemoCPlusPlus.c++ new file mode 100644 index 00000000000..0c810d25709 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/examples/c/SimpleDemoCPlusPlus.c++ @@ -0,0 +1,47 @@ +#include <pgf/gd/interface/c/InterfaceFromC++.h> +#include <pgf/gd/interface/c/InterfaceFromC.h> + +#include <math.h> + + +struct FastLayout : scripting::declarations, scripting::runner { + + void run () { + pgfgd_SyntacticDigraph* graph = parameters->syntactic_digraph; + + double angle = 6.28318530718 / graph->vertices.length; + double radius = parameters->option<double>("fast simple demo radius c++"); + + for (int i = 0; i < graph->vertices.length; i++) { + pgfgd_Vertex* v = graph->vertices.array[i]; + v->pos.x = cos(angle*i) * radius; + v->pos.y = sin(angle*i) * radius; + } + } + + void declare(scripting::script s) { + using namespace scripting; + + s.declare(key ("fast simple demo layout c++") + .summary ("The C++ version of the hello world of graph drawing") + .precondition ("connected") + .precondition ("tree") + .algorithm (this)); + + s.declare(key ("fast simple demo radius c++") + .summary ("A radius value for the hello world of graph drawing") + .type ("length") + .initial ("1cm")); + } + +}; + +extern "C" int luaopen_pgf_gd_examples_c_SimpleDemoCPlusPlus (struct lua_State *state) { + + scripting::script s (state); + + s.declare (new FastLayout); + + return 0; +} + diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/interface/c/InterfaceFromC++.c++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/interface/c/InterfaceFromC++.c++ new file mode 100644 index 00000000000..11c1f99dee0 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/interface/c/InterfaceFromC++.c++ @@ -0,0 +1,215 @@ + +// Own header: +#include <pgf/gd/interface/c/InterfaceFromC++.h> + +extern "C" { + +// Own C header: +#include <pgf/gd/interface/c/InterfaceFromC.h> + +// Lua stuff: +#include <lauxlib.h> + +} + + +namespace { + + void cpp_caller(pgfgd_SyntacticDigraph* g, void* f) + { + using namespace scripting; + + run_parameters p; + p.syntactic_digraph = g; + + runner* algo = static_cast<runner*> (f); + + algo->prepare(&p); + algo->bridge(); + algo->run(); + algo->unbridge(); + } + +} + + +namespace scripting { + + // The key class + + key::key(const char* key) : d (pgfgd_new_key(key)) {} + key::key(struct pgfgd_Declaration* dec) : d (dec) {} + key::~key() {pgfgd_free_key(d); } + + const key& key::summary (const char* x) const { + pgfgd_key_summary(d, x); + return *this; + } + + const key& key::initial (const char* x) const { + pgfgd_key_initial(d, x); + return *this; + } + + const key& key::initial (factory_base* fac) const { + pgfgd_key_initial_user(d, static_cast<void*>(fac)); + return *this; + } + + const key& key::type (const char* x) const { + pgfgd_key_type(d, x); + return *this; + } + + const key& key::module_type () const { + pgfgd_key_type(d, "user value"); + return *this; + } + + const key& key::default_value (const char* x) const { + pgfgd_key_default(d, x); + return *this; + } + + const key& key::alias (const char* x) const { + pgfgd_key_alias(d, x); + return *this; + } + + const key& key::alias_function (const char* x) const { + pgfgd_key_alias_function(d, x); + return *this; + } + + const key& key::documentation (const char* x) const { + pgfgd_key_documentation(d, x); + return *this; + } + + const key& key::documentation_in (const char* x) const { + pgfgd_key_documentation_in(d, x); + return *this; + } + + const key& key::phase (const char* x) const { + pgfgd_key_phase(d, x); + return *this; + } + + const key& key::set_key (const char* k, const char* v) const { + pgfgd_key_add_use(d, k, v); + return *this; + } + + const key& key::set_module (const char* k, factory_base* fac) const { + pgfgd_key_add_use_user(d, k, static_cast<void*>(fac)); + return *this; + } + + const key& key::example (const char* x) const { + pgfgd_key_add_example(d, x); + return *this; + } + + const key& key::precondition (const char* x) const { + pgfgd_key_add_precondition(d, x); + return *this; + } + + const key& key::postcondition (const char* x) const { + pgfgd_key_add_postcondition(d, x); + return *this; + } + + const key& key::algorithm (runner* a) const { + pgfgd_key_algorithm(d, cpp_caller, static_cast<void*>(a)); + return *this; + } + + + // The script class + + script::script (struct lua_State* s) : state(s) {} + + void script::declare (const key& k) { + pgfgd_declare(state, k.d); + } + + void script::declare (declarations* d) { + d->declare(*this); + } + + void script::declare (declarations& d) { + d.declare(*this); + } + + + // The run_parameters class + + namespace { + + // Helpers: + template <class T> + bool fromnumber (pgfgd_SyntacticDigraph* g, const char* k, T& t) + { + if (pgfgd_isnumber(g->options, k)) { + t = static_cast<T>(pgfgd_tonumber(g->options, k)); + return true; + } + return false; + } + + }; + + template <> bool run_parameters::option<bool> (const char* k, bool& t) + { + if (pgfgd_isboolean(syntactic_digraph->options, k)) { + t = static_cast<bool>(pgfgd_toboolean(syntactic_digraph->options, k)); + return true; + } + return false; + } + + template <> bool run_parameters::option<char*> (const char* k, char*& t) + { + if (pgfgd_isstring(syntactic_digraph->options, k)) { + t = pgfgd_tostring(syntactic_digraph->options, k); + return true; + } + return false; + } + + template <> bool run_parameters::option<short> (const char* k, short& t) + { return fromnumber<short> (syntactic_digraph, k, t); } + + template <> bool run_parameters::option<unsigned short> (const char* k, unsigned short& t) + { return fromnumber<unsigned short> (syntactic_digraph, k, t); } + + template <> bool run_parameters::option<int> (const char* k, int& t) + { return fromnumber<int> (syntactic_digraph, k, t); } + + template <> bool run_parameters::option<unsigned int> (const char* k, unsigned int& t) + { return fromnumber<unsigned int> (syntactic_digraph, k, t); } + + template <> bool run_parameters::option<long> (const char* k, long& t) + { return fromnumber<long> (syntactic_digraph, k, t); } + + template <> bool run_parameters::option<unsigned long> (const char* k, unsigned long& t) + { return fromnumber<unsigned long> (syntactic_digraph, k, t); } + + template <> bool run_parameters::option<float> (const char* k, float& t) + { return fromnumber<float> (syntactic_digraph, k, t); } + + template <> bool run_parameters::option<double> (const char* k, double& t) + { return fromnumber<double> (syntactic_digraph, k, t); } + + void* run_parameters::invoke_void_factory_for (const char* k) + { + if (pgfgd_isuser (syntactic_digraph->options, k)) { + factory_base* user = static_cast<factory_base *>(pgfgd_touser (syntactic_digraph->options, k)); + return user->make_void(this); + } + return 0; + } + +} diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/interface/c/InterfaceFromC++.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/interface/c/InterfaceFromC++.h new file mode 100644 index 00000000000..40cccb78846 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/interface/c/InterfaceFromC++.h @@ -0,0 +1,190 @@ +#ifndef PGF_GD_INTERFACE_C_INTERFACEFROMCPP_H +#define PGF_GD_INTERFACE_C_INTERFACEFROMCPP_H + +/** \file pgf/gd/interface/c/InterfaceFromC++.h + + The C++-header file that should be used by algorithms written + in C++ for graph drawing in Lua. +*/ + + +struct lua_State; +struct pgfgd_Declaration; +struct pgfgd_SyntacticDigraph; + +namespace scripting { + + // Forward; + class script; + class run_parameters; + + + class runner { + public: + + void prepare (run_parameters* p) { parameters = p; } + + virtual void bridge () {} + virtual void run () = 0; + virtual void unbridge () {} + + virtual ~runner () {} + + protected: + + run_parameters* parameters; + + }; + + class factory_base { + public: + virtual void* make_void (run_parameters*) = 0; + virtual ~factory_base () {} + }; + + template <class T> class factory : public factory_base { + virtual void* make_void (run_parameters*r) { return static_cast<void*>(make(r)); } + virtual T* make (run_parameters*) { return new T(); } + }; + + class key { + public: + + key (const char*); + key (struct pgfgd_Declaration*); + ~key (); + + const key& summary (const char*) const; + const key& initial (const char*) const; + const key& initial (factory_base*) const; + const key& type (const char*) const; + const key& module_type () const; + const key& default_value (const char*) const; + const key& alias (const char*) const; + const key& alias_function (const char*) const; + const key& documentation (const char*) const; + const key& documentation_in (const char*) const; + const key& phase (const char*) const; + const key& set_key (const char*, const char*) const; + const key& set_module (const char*, factory_base*) const; + const key& example (const char*) const; + const key& precondition (const char*) const; + const key& postcondition (const char*) const; + const key& algorithm (runner*) const; + + private: + + struct pgfgd_Declaration* d; + friend class script; + + key (const key& k); // Not implemented. + key& operator = (const key& k); // Not implemented. + + }; + + + // Declarations are useful for scripting: + + class declarations { + + public: + + virtual void declare (script) = 0; + virtual ~declarations () {} + + }; + + + // The script class + + class script { + + public: + + script (struct lua_State*); + + // Declares a key + void declare (const key&); + void declare (declarations&); + void declare (declarations*); + + private: + + struct lua_State* state; + + }; + + + + // Declaring algorithms defined in a function + + class function_runner : public runner { + public: + function_runner (void (*f) (run_parameters&)) : fun(f) {} + virtual void run () { fun(*parameters); } + + private: + void (*fun) (run_parameters&); + }; + + + // Configuring a class + + class run_parameters { + public: + + struct pgfgd_SyntacticDigraph* syntactic_digraph; + + template <class Layout, class T> + void configure_option (const char*, void (Layout::*) (T), Layout&); + + template <class Layout, class T> + void configure_module (const char*, void (Layout::*) (T*), Layout&); + + template <class T> bool option (const char*, T&); + template <class T> T option (const char*); + template <class T> bool option_is_set (const char*); + + template <class T> T* make (const char*); + + protected: + void* invoke_void_factory_for (const char*); + }; + + template <class T> + T run_parameters::option (const char* k) + { + T t; + option (k, t); + return t; + } + + template <class T> + bool run_parameters::option_is_set (const char* k) + { + T t; + return option(k, t); + } + + template <class Layout, class T> + void run_parameters::configure_option (const char* k, void (Layout::*f) (T), Layout& l) + { + T t; + if (option<T> (k, t)) + (l.*f) (t); + } + + template <class Layout, class T> + void run_parameters::configure_module (const char* k, void (Layout::*f) (T*), Layout& l) + { + if (void* obj = invoke_void_factory_for(k)) + (l.*f) (static_cast<T*> (obj)); + } + + template <class T> + T* run_parameters::make (const char* k) { return static_cast<T*>(invoke_void_factory_for(k)); } + +} + + +#endif diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/interface/c/InterfaceFromC.c b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/interface/c/InterfaceFromC.c new file mode 100644 index 00000000000..8a49947b950 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/interface/c/InterfaceFromC.c @@ -0,0 +1,1187 @@ + +// Own header: +#include <pgf/gd/interface/c/InterfaceFromC.h> + +// Lua stuff: +#include <lauxlib.h> + +// C stuff: +#include <stdlib.h> +#include <string.h> + + +// The following is a hack to avoid a problem with the Lua lib being linked twice. +// When this happens, two version of "dummynode" exist in Lua and we must ensure that +// we never create a table using such a dummynode while using a second lib. +// The following should later be set to 0 and replaced everywhere, once this is fixed. +#define MIN_HASH_SIZE_FIX 1 + + + +// Help functions + +static void set_field (lua_State* L, const char* what, const char* where) +{ + if (what) { + lua_pushstring(L, what); + lua_setfield(L, -2, where); + } +} + + +static void init_vertex_array(pgfgd_Vertex_array* a, int count) +{ + a->length = count; + a->array = (pgfgd_Vertex**) calloc(count, sizeof(pgfgd_Vertex*)); +} + +static void init_edge_array(pgfgd_Edge_array* a, int count) +{ + a->length = count; + a->array = (pgfgd_Edge**) calloc(count, sizeof(pgfgd_Edge*)); +} + +static void init_arcs_array(pgfgd_Arc_array* arcs, int length) +{ + arcs->length = length; + arcs->tails = (int*) calloc(length, sizeof(int)); + arcs->heads = (int*) calloc(length, sizeof(int)); +} + +static void init_path(pgfgd_Path* a, int count) +{ + a->length = count; + a->coordinates = (pgfgd_Coordinate*) calloc(count, sizeof(pgfgd_Coordinate)); + a->strings = (char**) calloc(count, sizeof(char*)); +} + +static void clear_path(pgfgd_Path* p) +{ + int i; + for (i=0; i < p->length; i++) + free(p->strings[i]); + + free(p->strings); + free(p->coordinates); + + p->length = 0; + p->strings = 0; + p->coordinates = 0; +} + + + +// Option handling + +struct pgfgd_OptionTable { + lua_State* state; + + int kind; + int index; +}; + +// These are the indices of the parameters during a run of the main +// algorithm: +#define GRAPH_INDEX 1 +#define VERTICES_INDEX 2 +#define EDGES_INDEX 3 +#define ALGORITHM_INDEX 4 + +// This is the index of a special table mapping vertices back to the +// index they have. It is created in the C code, but stays on the +// stack during the computations. +#define BACKINDEX_STORAGE_INDEX 5 + +// These are the positions of different upvalues for the C closure of +// a C algorithm. +#define FUNCTION_UPVALUE 1 +#define USER_UPVALUE 2 +#define DIGRAPH_OBJECT_UPVALUE 3 + + +static pgfgd_OptionTable* make_option_table(lua_State* L, int kind, int index) +{ + pgfgd_OptionTable* t = (pgfgd_OptionTable*) malloc(sizeof(pgfgd_OptionTable)); + + t->state = L; + t->kind = kind; + t->index = index; + + return t; +} + +static void push_option_table(pgfgd_OptionTable* t) +{ + switch (t->kind) { + case GRAPH_INDEX: + lua_getfield(t->state, GRAPH_INDEX, "options"); + break; + case VERTICES_INDEX: + lua_rawgeti(t->state, VERTICES_INDEX, t->index); + lua_getfield(t->state, -1, "options"); + lua_replace(t->state, -2); + break; + case EDGES_INDEX: + lua_rawgeti(t->state, EDGES_INDEX, t->index); + lua_getfield(t->state, -1, "options"); + lua_replace(t->state, -2); + break; + } +} + +int pgfgd_isset(pgfgd_OptionTable* t, const char* key) +{ + push_option_table(t); + lua_getfield(t->state, -1, key); + int is_nil = lua_isnil(t->state, -1); + lua_pop(t->state, 2); + return !is_nil; +} + +int pgfgd_isnumber(pgfgd_OptionTable* t, const char* key) +{ + push_option_table(t); + lua_getfield(t->state, -1, key); + int is_number = lua_isnumber(t->state, -1); + lua_pop(t->state, 2); + return is_number; +} + +int pgfgd_isboolean(pgfgd_OptionTable* t, const char* key) +{ + push_option_table(t); + lua_getfield(t->state, -1, key); + int is_bool = lua_isboolean(t->state, -1); + lua_pop(t->state, 2); + return is_bool; +} + +int pgfgd_isstring(pgfgd_OptionTable* t, const char* key) +{ + push_option_table(t); + lua_getfield(t->state, -1, key); + int is_string = lua_isstring(t->state, -1); + lua_pop(t->state, 2); + return is_string; +} + +int pgfgd_isuser(pgfgd_OptionTable* t, const char* key) +{ + push_option_table(t); + lua_getfield(t->state, -1, key); + int is_user = lua_isuserdata(t->state, -1); + lua_pop(t->state, 2); + return is_user; +} + + +double pgfgd_tonumber(pgfgd_OptionTable* t, const char* key) +{ + push_option_table(t); + lua_getfield(t->state, -1, key); + double d = lua_tonumber(t->state, -1); + lua_pop(t->state, 2); + return d; +} + +int pgfgd_toboolean(pgfgd_OptionTable* t, const char* key) +{ + push_option_table(t); + lua_getfield(t->state, -1, key); + int d = lua_toboolean(t->state, -1); + lua_pop(t->state, 2); + return d; +} + +char* pgfgd_tostring(pgfgd_OptionTable* t, const char* key) +{ + push_option_table(t); + lua_getfield(t->state, -1, key); + const char* s = lua_tostring(t->state, -1); + char* copy = strcpy((char*) malloc(strlen(s)+1), s); + lua_pop(t->state, 2); + return copy; +} + +void* pgfgd_touser(pgfgd_OptionTable* t, const char* key) +{ + push_option_table(t); + lua_getfield(t->state, -1, key); + void* d = lua_touserdata(t->state, -1); + lua_pop(t->state, 2); + return d; +} + + +// Handling algorithms + +struct pgfgd_SyntacticDigraph_internals { + lua_State* state; +}; + +static char* make_string_from(lua_State* L, const char* name) +{ + lua_getfield(L, -1, name); + if (lua_isnil(L, -1)) { + // Field not set; return emtpy string. + lua_pop(L, 1); + return (char*) calloc(1, sizeof(char)); + } + else { + const char* s = lua_tostring(L, -1); + char* copy = strcpy((char*) malloc(strlen(s)+1), s); + lua_pop(L, 1); + return copy; + } +} + +static void make_coordinate(lua_State* L, pgfgd_Coordinate* c) +{ + lua_getfield(L, -1, "x"); + c->x = lua_tonumber(L, -1); + lua_pop(L, 1); + + lua_getfield(L, -1, "y"); + c->y = lua_tonumber(L, -1); + lua_pop(L, 1); +} + +static pgfgd_Path* make_empty_path(lua_State* L) +{ + return (pgfgd_Path*) calloc(1, sizeof(pgfgd_Path)); +} + +static pgfgd_Path* make_path(lua_State* L) +{ + /* Path object must be on top of stack. */ + pgfgd_Path* p = make_empty_path(L); + + // Fill path: + int path_length = lua_rawlen(L, -1); + if (path_length > 0) { + init_path(p, path_length); + int i; + for (i = 0; i < path_length; i++) { + lua_rawgeti(L, -1, i+1); + if (lua_isstring(L, -1)) { + const char* s = lua_tostring(L, -1); + p->strings[i] = strcpy((char*) malloc(strlen(s)+1), s); + } else { + lua_getfield(L, -1, "x"); + p->coordinates[i].x = lua_tonumber(L, -1); + lua_pop(L, 1); + + lua_getfield(L, -1, "y"); + p->coordinates[i].y = lua_tonumber(L, -1); + lua_pop(L, 1); + } + lua_pop(L, 1); + } + } + + return p; +} + +static void construct_digraph(lua_State* L, pgfgd_SyntacticDigraph* d) +{ + d->internals = (pgfgd_SyntacticDigraph_internals*) calloc(1, sizeof(pgfgd_SyntacticDigraph_internals)); + d->internals->state = L; + + // Create the options table: + d->options = make_option_table(L, GRAPH_INDEX, 0); + + // Create the vertex table + init_vertex_array(&d->vertices, lua_rawlen(L, VERTICES_INDEX)); + + // Create the vertices + int i; + for (i=0; i<d->vertices.length; i++) { + pgfgd_Vertex* v = (pgfgd_Vertex*) calloc(1, sizeof(pgfgd_Vertex)); + + // Push the vertex onto the Lua stack: + lua_rawgeti(L, VERTICES_INDEX, i+1); + + // Fill v with information: + v->name = make_string_from(L, "name"); + v->shape = make_string_from(L, "shape"); + v->kind = make_string_from(L, "kind"); + + // Options: + v->options = make_option_table(L, VERTICES_INDEX, i+1); + + // Index: + v->array_index = i; + + // Setup pos field + lua_getfield(L, -1, "pos"); + make_coordinate(L, &v->pos); + lua_pop(L, 1); + + // Setup path array: + lua_getfield(L, -1, "path"); + v->path = make_path(L); + lua_pop(L, 1); + + // Pop the vertex + lua_pop(L, 1); + + d->vertices.array[i] = v; + } + + // Construct the edges: + init_edge_array(&d->syntactic_edges, lua_rawlen(L, EDGES_INDEX)); + + int edge_index; + for (edge_index = 0; edge_index < d->syntactic_edges.length; edge_index++) { + pgfgd_Edge* e = (pgfgd_Edge*) calloc(1, sizeof(pgfgd_Edge)); + + lua_rawgeti(L, EDGES_INDEX, edge_index+1); + + e->direction = make_string_from(L, "direction"); + e->options = make_option_table(L, EDGES_INDEX, edge_index+1); + + // Index: + e->array_index = edge_index; + + // Compute the tail vertex index: + lua_getfield(L, -1, "tail"); + lua_gettable(L, VERTICES_INDEX); + e->tail = d->vertices.array[lua_tointeger(L, -1) - 1]; + lua_pop(L, 1); + + lua_getfield(L, -1, "head"); + lua_gettable(L, VERTICES_INDEX); + e->head = d->vertices.array[lua_tointeger(L, -1) - 1]; + lua_pop(L, 1); + + // Fill path: + e->path = make_empty_path(L); + e->path->length = -1; // Means that a default path should be created. + + // Pop the edge form the Lua stack: + lua_pop(L, 1); + + d->syntactic_edges.array[edge_index] = e; + } +} + + +static void sync_digraph(lua_State* L, pgfgd_SyntacticDigraph* d) +{ + // Writes back the computed position information to the digraph: + int i; + for (i=0; i<d->vertices.length; i++) { + + // Push pos field of vertex: + lua_rawgeti(L, VERTICES_INDEX, i+1); + lua_getfield(L, -1, "pos"); + + // Set x and y coordinates: + pgfgd_Vertex* v = d->vertices.array[i]; + lua_pushnumber(L, v->pos.x); + lua_setfield(L, -2, "x"); + lua_pushnumber(L, v->pos.y); + lua_setfield(L, -2, "y"); + + // pop pos and vertex + lua_pop(L, 2); + } + + // Write back the paths + + int tos = lua_gettop(L); + + // First, get "Coordinate.new" as a "local" + lua_getglobal(L, "require"); + lua_pushstring(L, "pgf.gd.model.Path"); + lua_call(L, 1, 1); + int Path_index = lua_gettop(L); + + lua_getglobal(L, "require"); + lua_pushstring(L, "pgf.gd.model.Coordinate"); + lua_call(L, 1, 1); + lua_getfield(L, -1, "new"); + + int Coordinate_new_index = lua_gettop(L); + + for (i=0; i < d->syntactic_edges.length; i++) { + pgfgd_Edge* e = d->syntactic_edges.array[i]; + + lua_rawgeti(L, EDGES_INDEX, i+1); + + if (e->path->length == -1) { + // Create default path + pgfgd_path_append_moveto_tail(e); + pgfgd_path_append_lineto_head(e); + } + + lua_createtable(L, e->path->length ? e->path->length : 1, MIN_HASH_SIZE_FIX); + lua_pushvalue(L, Path_index); + lua_setmetatable(L, -2); + + int j; + for (j=0; j<e->path->length; j++) { + if (e->path->strings[j]) { + lua_pushstring(L, e->path->strings[j]); + lua_rawseti(L, -2, j+1); + } else { + lua_pushvalue(L, Coordinate_new_index); + lua_pushnumber(L, e->path->coordinates[j].x); + lua_pushnumber(L, e->path->coordinates[j].y); + lua_call(L, 2, 1); + + lua_rawseti(L, -2, j+1); + } + } + + lua_setfield(L, -2, "path"); + lua_pop(L, 1); // The edge object + } + + lua_settop(L, tos); // Cleanup +} + + +static void free_digraph(pgfgd_SyntacticDigraph* digraph) +{ + int i; + for (i=0; i < digraph->vertices.length; i++) { + pgfgd_Vertex* v = digraph->vertices.array[i]; + + clear_path(v->path); + free(v->path); + free(v->name); + free(v->shape); + free(v->kind); + free(v->options); + free(v->incoming.array); + free(v->outgoing.array); + free(v); + } + + for (i=0; i < digraph->syntactic_edges.length; i++) { + pgfgd_Edge* e = digraph->syntactic_edges.array[i]; + + clear_path(e->path); + free(e->path); + free(e->direction); + free(e->options); + free(e); + } + + free(digraph->vertices.array); + free(digraph->syntactic_edges.array); + free(digraph->options); + free(digraph->internals); + free(digraph); +} + +static int algorithm_dispatcher(lua_State* L) +{ + // Create the back index table. It will be at index BACKINDEX_STORAGE_INDEX + lua_createtable(L, 0, MIN_HASH_SIZE_FIX); + + // The actual function is stored in an upvalue. + pgfgd_SyntacticDigraph* digraph = (pgfgd_SyntacticDigraph*) calloc(1, sizeof(pgfgd_SyntacticDigraph)); + + construct_digraph(L, digraph); + + pgfgd_algorithm_fun fun = lua_touserdata(L, lua_upvalueindex(FUNCTION_UPVALUE)); + fun(digraph, lua_touserdata(L, lua_upvalueindex(USER_UPVALUE))); + + sync_digraph(L, digraph); + + free_digraph(digraph); + + return 0; +} + + +int pgfgd_vertex_anchor(pgfgd_Vertex* v, const char* anchor, double* x, double* y) +{ + lua_State* L = v->options->state; + + // Ok, first, find the vertex: + lua_rawgeti(L, VERTICES_INDEX, v->array_index+1); + + // Find the anchor function: + lua_getfield(L, -1, "anchor"); + lua_pushvalue(L, -2); + lua_pushstring(L, anchor); + + // Find the anchor: + lua_call(L, 2, 1); + + if (lua_isnil(L, -1)) { + // Failed. Cleanup! + lua_pop(L, 2); + *x = 0; + *y = 0; + return 0; + } else { + lua_getfield(L, -1, "x"); + *x = lua_tonumber(L, -1); + lua_pop(L, 1); + + lua_getfield(L, -1, "y"); + *y = lua_tonumber(L, -1); + lua_pop(L, 1); + + lua_pop(L, 2); + return 1; + } + return 0; +} + + + +void pgfgd_path_clear(pgfgd_Edge* e) +{ + clear_path (e->path); +} + +static void path_add_segment(pgfgd_Edge* edge, const char* s, int num, double a, double b, double c, double d, double e, double f) +{ + if (edge->path->length == -1) + pgfgd_path_clear(edge); + + int start = edge->path->length; + + edge->path->length += num + 1; + edge->path->strings = (char **) + realloc(edge->path->strings, edge->path->length*sizeof(char*)); + edge->path->coordinates = (pgfgd_Coordinate*) + realloc(edge->path->coordinates, edge->path->length*sizeof(pgfgd_Coordinate)); + + edge->path->coordinates[start].x = 0; + edge->path->coordinates[start].y = 0; + edge->path->strings[start] = strcpy((char*) malloc(strlen(s)+1), s); + + if (num > 0) { + edge->path->coordinates[start+1].x = a; + edge->path->coordinates[start+1].y = b; + edge->path->strings[start+1] = 0; + } + + if (num > 1) { + edge->path->coordinates[start+2].x = c; + edge->path->coordinates[start+2].y = d; + edge->path->strings[start+2] = 0; + } + + if (num > 2) { + edge->path->coordinates[start+3].x = e; + edge->path->coordinates[start+3].y = f; + edge->path->strings[start+3] = 0; + } +} + + +void pgfgd_path_append_moveto(pgfgd_Edge* e, double x, double y) +{ + path_add_segment(e, "moveto", 1, x, y, 0, 0, 0, 0); +} + +void pgfgd_path_append_moveto_tail (pgfgd_Edge* e) +{ + double x, y; + char* tail_anchor = pgfgd_tostring(e->tail->options, "tail anchor"); + + pgfgd_vertex_anchor(e->tail, tail_anchor, &x, &y); + x += e->tail->pos.x; + y += e->tail->pos.y; + + pgfgd_path_append_moveto(e, x, y); + free(tail_anchor); +} + +void pgfgd_path_append_lineto(pgfgd_Edge* e, double x, double y) +{ + path_add_segment(e, "lineto", 1, x, y, 0, 0, 0, 0); +} + +void pgfgd_path_append_lineto_head (pgfgd_Edge* e) +{ + double x, y; + char* head_anchor = pgfgd_tostring(e->head->options, "head anchor"); + + pgfgd_vertex_anchor(e->head, head_anchor, &x, &y); + x += e->head->pos.x; + y += e->head->pos.y; + + pgfgd_path_append_lineto(e, x, y); + free(head_anchor); +} + +void pgfgd_path_append_curveto(pgfgd_Edge* edge, double a, double b, double c, double d, double e, double f) +{ + path_add_segment(edge, "curveto", 3, a, b, c, d, e, f); +} + +void pgfgd_path_append_closepath(pgfgd_Edge* e) +{ + path_add_segment(e, "closepath", 0, 0, 0, 0, 0, 0, 0); +} + + + +// Handling digraphs + +struct pgfgd_Digraph { + lua_State* state; + const char* name; + pgfgd_SyntacticDigraph* syntactic_digraph; +}; + + +pgfgd_Digraph* pgfgd_get_digraph (pgfgd_SyntacticDigraph* g, const char* graph_name) +{ + lua_State* L = g->internals->state; + + lua_getfield(L, ALGORITHM_INDEX, graph_name); + if (lua_isnil(L, -1)) + luaL_error(L, "digraph named %s not found in algorithm class", graph_name); + lua_pop(L, 1); + + pgfgd_Digraph* new = (pgfgd_Digraph*) calloc(1, sizeof(pgfgd_Digraph)); + + new->state = L; + new->name = graph_name; + new->syntactic_digraph = g; + + return new; +} + +int pgfgd_digraph_num_vertices (pgfgd_Digraph* g) +{ + lua_getfield(g->state, ALGORITHM_INDEX, g->name); + lua_getfield(g->state, -1, "vertices"); + int num = lua_rawlen(g->state, -1); + lua_pop(g->state, 2); + + return num; +} + +static void push_digraph_and_backindex(pgfgd_Digraph* g) +{ + lua_State* L = g->state; + + // Get digraph + lua_getfield(L, ALGORITHM_INDEX, g->name); + int digraph_pos = lua_gettop(L); + + // Get entry in back index table + lua_pushvalue(L, digraph_pos); + lua_gettable(L, BACKINDEX_STORAGE_INDEX); + int backtable_pos = lua_gettop(L); + if (lua_isnil(L, backtable_pos)) { + // Aha. We need to install a new table: + lua_pop(L, 1); // Get rid of nil + + lua_createtable(L, 0, MIN_HASH_SIZE_FIX); + + lua_pushvalue(L, digraph_pos); // The digraph object + lua_pushvalue(L, backtable_pos); // The new table + lua_settable(L, BACKINDEX_STORAGE_INDEX); + + // Fill the table: + lua_getfield(L, digraph_pos, "vertices"); + int vertex_pos = lua_gettop(L); + int i; + int n = lua_rawlen(L, -1); + for (i = 1; i <= n; i++) { + lua_rawgeti(L, vertex_pos, i); + lua_pushinteger(L, i); + lua_settable(L, backtable_pos); + } + lua_pop(L, 1); + } +} + +static pgfgd_Arc_array* build_c_array_of_arcs_from_lua_array_of_arcs(pgfgd_Digraph* g) +{ + lua_State* L = g->state; + + pgfgd_Arc_array* arcs = (pgfgd_Arc_array*) calloc(1, sizeof(pgfgd_Arc_array)); + + int array_pos = lua_gettop(L); + + push_digraph_and_backindex(g); + int backtable_pos = lua_gettop(L); + + // Get number of arcs: + init_arcs_array(arcs, lua_rawlen(L, array_pos)); + int i; + for (i = 1; i<=arcs->length; i++) { + lua_rawgeti(L, array_pos, i); // Get arcs[i] + + // The tail field: + lua_getfield(L, -1, "tail"); + lua_gettable(L, backtable_pos); + + arcs->tails[i-1] = lua_tointeger(L, -1); + lua_pop(L, 1); // The number + + // The head field: + lua_getfield(L, -1, "head"); + lua_gettable(L, backtable_pos); + arcs->heads[i-1] = lua_tointeger(L, -1); + lua_pop(L, 1); // The number + + lua_pop(L, 1); // Pop arcs[i] + } + + lua_settop(L, array_pos); + + return arcs; +} + + +pgfgd_Arc_array* pgfgd_digraph_arcs (pgfgd_Digraph* g) +{ + lua_getfield(g->state, ALGORITHM_INDEX, g->name); + lua_getfield(g->state, -1, "arcs"); + + pgfgd_Arc_array* a = build_c_array_of_arcs_from_lua_array_of_arcs(g); + + lua_pop(g->state, 2); + + return a; +} + + +pgfgd_Vertex* pgfgd_digraph_syntactic_vertex (pgfgd_Digraph* g, int v) +{ + int tos = lua_gettop(g->state); + pgfgd_Vertex* return_me = 0; + + lua_getfield(g->state, ALGORITHM_INDEX, g->name); + lua_getfield(g->state, -1, "vertices"); + lua_rawgeti(g->state, -1, v); + + lua_gettable(g->state, VERTICES_INDEX); + if (lua_isnumber(g->state, -1)) { + return_me = g->syntactic_digraph->vertices.array[lua_tointeger(g->state, -1)-1]; + } + + lua_settop(g->state, tos); + return return_me; +} + + +int pgfgd_digraph_isarc (pgfgd_Digraph* g, int tail, int head) +{ + lua_State* L = g->state; + int is_arc = 0; + + lua_getfield(L, ALGORITHM_INDEX, g->name); + int digraph_pos = lua_gettop(L); + + lua_getfield(L, digraph_pos, "vertices"); + int vertices_pos = lua_gettop(L); + + // Call digraph:connected(tail, head) + lua_pushvalue(L, lua_upvalueindex(DIGRAPH_OBJECT_UPVALUE)); + lua_getfield(L, -1, "arc"); + lua_pushvalue(L, digraph_pos); + lua_rawgeti(L, vertices_pos, tail); + lua_rawgeti(L, vertices_pos, head); + lua_call(L, 3, 1); + + is_arc = !lua_isnil(L, -1); + + lua_settop(L, digraph_pos-1); + + return is_arc; +} + +pgfgd_Arc_array* pgfgd_digraph_incoming (pgfgd_Digraph* g, int v) +{ + lua_State* L = g->state; + + lua_getfield(L, ALGORITHM_INDEX, g->name); + int digraph_pos = lua_gettop(L); + + lua_getfield(L, digraph_pos, "vertices"); + int vertices_pos = lua_gettop(L); + + // Call digraph:connected(tail, head) + lua_pushvalue(L, lua_upvalueindex(DIGRAPH_OBJECT_UPVALUE)); + lua_getfield(L, -1, "incoming"); + lua_pushvalue(L, digraph_pos); + lua_rawgeti(L, vertices_pos, v); + lua_call(L, 2, 1); + + pgfgd_Arc_array* a = build_c_array_of_arcs_from_lua_array_of_arcs(g); + + lua_settop(L, digraph_pos-1); + + return a; +} + +pgfgd_Arc_array* pgfgd_digraph_outgoing (pgfgd_Digraph* g, int v) +{ + lua_State* L = g->state; + + lua_getfield(L, ALGORITHM_INDEX, g->name); + int digraph_pos = lua_gettop(L); + + lua_getfield(L, digraph_pos, "vertices"); + int vertices_pos = lua_gettop(L); + + // Call digraph:connected(tail, head) + lua_pushvalue(L, lua_upvalueindex(DIGRAPH_OBJECT_UPVALUE)); + lua_getfield(L, -1, "outgoing"); + lua_pushvalue(L, digraph_pos); + lua_rawgeti(L, vertices_pos, v); + lua_call(L, 2, 1); + + pgfgd_Arc_array* a = build_c_array_of_arcs_from_lua_array_of_arcs(g); + + lua_settop(L, digraph_pos-1); + + return a; +} + +pgfgd_Edge_array* pgfgd_digraph_syntactic_edges (pgfgd_Digraph* g, int tail, int head) +{ + pgfgd_Edge_array* edges = (pgfgd_Edge_array*) calloc(1, sizeof(pgfgd_Edge_array)); + + // First, get the arc in the syntatic digraph. + lua_State* L = g->state; + int tos = lua_gettop(L); + + lua_getfield(L, ALGORITHM_INDEX, g->name); + int digraph_pos = lua_gettop(L); + + lua_getfield(L, digraph_pos, "vertices"); + int vertices_pos = lua_gettop(L); + + // Call digraph:arc(tail, head) + lua_pushvalue(L, lua_upvalueindex(DIGRAPH_OBJECT_UPVALUE)); + int digraph_class_index = lua_gettop(L); + + lua_getfield(L, digraph_class_index, "arc"); + lua_pushvalue(L, digraph_pos); + lua_rawgeti(L, vertices_pos, tail); + lua_rawgeti(L, vertices_pos, head); + lua_call(L, 3, 1); + + if (!lua_isnil(L, -1)) { + // Get syntactic_digraph of the arc: + lua_getfield(L, -1, "syntactic_digraph"); + + // Call syntactic_digraph:arc(tail, head) + lua_getfield(L, digraph_class_index, "arc"); + lua_pushvalue(L, -2); + lua_rawgeti(L, vertices_pos, tail); + lua_rawgeti(L, vertices_pos, head); + lua_call(L, 3, 1); + + if (!lua_isnil(L, -1)) { + lua_getfield(L, -1, "syntactic_edges"); + int syntactic_edges_index = lua_gettop(L); + + int n = lua_rawlen(L, syntactic_edges_index); + init_edge_array(edges, n); + int i; + for (i=1; i<=n; i++) { + lua_rawgeti(L, syntactic_edges_index, i); + lua_gettable(L, EDGES_INDEX); + if (!lua_isnumber(L, -1)) { + pgfgd_digraph_free_edge_array(edges); + luaL_error(L, "syntactic edge index not found"); + } + int p = lua_tonumber(L, -1); + edges->array[i-1] = g->syntactic_digraph->syntactic_edges.array[p-1]; + } + } + } + + lua_settop(L, tos); + + return edges; +} + + + +void pgfgd_digraph_free (pgfgd_Digraph* g) +{ + free(g); +} + +void pgfgd_digraph_free_arc_array (pgfgd_Arc_array* arcs) +{ + free (arcs->tails); + free (arcs->heads); + free (arcs); +} + +void pgfgd_digraph_free_edge_array (pgfgd_Edge_array* edges) +{ + free (edges->array); + free (edges); +} + + + +// Handling declarations + + +struct pgfgd_Declaration { + const char* key; + const char* summary; + const char* type; + const char* initial; + void* initial_user; + const char* default_value; + const char* alias; + const char* alias_function_string; + const char* documentation; + const char* documentation_in; + pgfgd_algorithm_fun algorithm; + void* algorithm_user; + const char* phase; + + int use_length; + const char** use_keys; + const char** use_values_strings; + void** use_values_user; + + int examples_length; + const char** examples; + + int pre_length; + const char** pre; + + int post_length; + const char** post; +}; + + +pgfgd_Declaration* pgfgd_new_key (const char* key) +{ + pgfgd_Declaration* d = (pgfgd_Declaration*) calloc(1, sizeof(pgfgd_Declaration)); + + d->key = key; + + return d; +} + +void pgfgd_declare(struct lua_State* state, pgfgd_Declaration* d) +{ + if (d && d->key) { + int tos = lua_gettop(state); + + lua_gc(state, LUA_GCSTOP, 0); // BUG: Remove once linking against dynamic Lua lib works! + + // Find declare function: + lua_getglobal(state, "require"); + lua_pushstring(state, "pgf.gd.interface.InterfaceToAlgorithms"); + lua_call(state, 1, 1); + lua_getfield(state, -1, "declare"); + + // Build a Lua table: + lua_createtable(state, 0, 11); + + set_field (state, d->key, "key"); + set_field (state, d->summary, "summary"); + set_field (state, d->type, "type"); + set_field (state, d->initial, "initial"); + set_field (state, d->documentation, "documentation"); + set_field (state, d->documentation_in, "documentation_in"); + set_field (state, d->default_value, "default"); + set_field (state, d->alias, "alias"); + set_field (state, d->alias_function_string, "alias_function_string"); + set_field (state, d->phase, "phase"); + + if (d->initial_user) { + lua_pushlightuserdata(state, d->initial_user); + lua_setfield(state, -2, "initial"); + } + + if (d->use_length > 0) { + lua_createtable(state, d->use_length, MIN_HASH_SIZE_FIX); + int i; + for (i=0; i < d->use_length; i++) { + lua_createtable(state, 0, 2); + set_field(state, d->use_keys[i], "key"); + if (d->use_values_strings[i]) + set_field(state, d->use_values_strings[i], "value"); + if (d->use_values_user[i]) { + lua_pushlightuserdata(state, d->use_values_user[i]); + lua_setfield(state, -2, "value"); + } + lua_rawseti(state, -2, i+1); + } + lua_setfield(state, -2, "use"); + } + + if (d->pre) { + lua_createtable(state, 0, d->pre_length); + int i; + for (i=0; i < d->pre_length; i++) { + lua_pushboolean(state, 1); + lua_setfield(state, -2, d->pre[i]); + } + lua_setfield(state, -2, "preconditions"); + } + + if (d->post) { + lua_createtable(state, 0, d->post_length); + int i; + for (i=0; i < d->post_length; i++) { + lua_pushboolean(state, 1); + lua_setfield(state, -2, d->post[i]); + } + lua_setfield(state, -2, "postconditions"); + } + + if (d->examples) { + lua_createtable(state, d->examples_length, MIN_HASH_SIZE_FIX); + int i; + for (i=0; i < d->examples_length; i++) { + lua_pushstring(state, d->examples[i]); + lua_rawseti(state, -2, i+1); + } + lua_setfield(state, -2, "examples"); + } + + if (d->algorithm) { + // The algorithm function and the user data is stored as lightuserdate upvalue + lua_pushlightuserdata(state, (void *) d->algorithm); + lua_pushlightuserdata(state, (void *) d->algorithm_user); + + // Find the Digraph.arc function and store it as the second upvalue: + lua_getglobal(state, "require"); + lua_pushstring(state, "pgf.gd.model.Digraph"); + lua_call(state, 1, 1); + + lua_pushcclosure(state, algorithm_dispatcher, 3); + lua_setfield(state, -2, "algorithm_written_in_c"); + } + + // Call the declare function: + lua_call(state, 1, 0); + + // Cleanup: + lua_settop(state, tos); + + lua_gc(state, LUA_GCRESTART, 0); + } +} + +void pgfgd_key_add_use(pgfgd_Declaration* d, const char* key, const char* value) +{ + d->use_length++; + d->use_keys = (const char **) realloc(d->use_keys, d->use_length*sizeof(const char*)); + d->use_values_strings = (const char **) realloc(d->use_values_strings, d->use_length*sizeof(const char*)); + d->use_values_user = (void **) realloc(d->use_values_user, d->use_length*sizeof(void*)); + + d->use_keys [d->use_length-1] = key; + d->use_values_strings[d->use_length-1] = value; + d->use_values_user [d->use_length-1] = 0; +} + +void pgfgd_key_add_use_user(pgfgd_Declaration* d, const char* key, void* value) +{ + d->use_length++; + d->use_keys = (const char **) realloc(d->use_keys, d->use_length*sizeof(const char*)); + d->use_values_strings = (const char **) realloc(d->use_values_strings, d->use_length*sizeof(const char*)); + d->use_values_user = (void **) realloc(d->use_values_user, d->use_length*sizeof(void*)); + + d->use_keys [d->use_length-1] = key; + d->use_values_strings[d->use_length-1] = 0; + d->use_values_user [d->use_length-1] = value; +} + +void pgfgd_key_add_example(pgfgd_Declaration* d, const char* s) +{ + d->examples_length++; + d->examples = (const char **) realloc(d->examples, d->examples_length*sizeof(const char*)); + + d->examples[d->examples_length-1] = s; +} + +void pgfgd_key_add_precondition(pgfgd_Declaration* d, const char* s) +{ + d->pre_length++; + d->pre = (const char **) realloc(d->pre, d->pre_length*sizeof(const char*)); + + d->pre[d->pre_length-1] = s; +} + +void pgfgd_key_add_postcondition(pgfgd_Declaration* d, const char* s) +{ + d->post_length++; + d->post = (const char **) realloc(d->post, d->post_length*sizeof(const char*)); + + d->post[d->post_length-1] = s; +} + +void pgfgd_key_summary(pgfgd_Declaration* d, const char* s) +{ + d->summary = s; +} + +void pgfgd_key_type(pgfgd_Declaration* d, const char* s) +{ + d->type = s; +} + +void pgfgd_key_initial(pgfgd_Declaration* d, const char* s) +{ + d->initial = s; +} + +void pgfgd_key_initial_user(pgfgd_Declaration* d, void* s) +{ + d->initial_user = s; +} + +void pgfgd_key_default(pgfgd_Declaration* d, const char* s) +{ + d->default_value = s; +} + +void pgfgd_key_alias(pgfgd_Declaration* d, const char* s) +{ + d->alias = s; +} + +void pgfgd_key_alias_function(pgfgd_Declaration* d, const char* s) +{ + d->alias_function_string = s; +} + +void pgfgd_key_documentation(pgfgd_Declaration* d, const char* s) +{ + d->documentation = s; +} + +void pgfgd_key_documentation_in(pgfgd_Declaration* d, const char* s) +{ + d->documentation_in = s; +} + +void pgfgd_key_phase(pgfgd_Declaration* d, const char* s) +{ + d->phase = s; +} + +void pgfgd_key_algorithm(pgfgd_Declaration* d, pgfgd_algorithm_fun f, void* user_data) +{ + d->algorithm = f; + d->algorithm_user = user_data; +} + +void pgfgd_free_key(pgfgd_Declaration* d) +{ + if (d) { + free(d->examples); + free(d->use_keys); + free(d->use_values_user); + free(d->use_values_strings); + free(d); + } +} diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/interface/c/InterfaceFromC.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/interface/c/InterfaceFromC.h new file mode 100644 index 00000000000..40495dbdc29 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/interface/c/InterfaceFromC.h @@ -0,0 +1,613 @@ +#ifndef PGF_GD_INTERFACE_C_INTERFACEFROMC_H +#define PGF_GD_INTERFACE_C_INTERFACEFROMC_H + +/** \file pgf/gd/interface/c/InterfaceFromC.h + + The C-header file that should be used by algorithms written + in C for graph drawing in Lua. +*/ + + +#ifdef __cplusplus +extern "C" { +#endif + + + + + +// Option handling + +/** Abstraction of a Lua option table. + You cannot access it directly, but only through the function + pgfgd_isset and so on. Note that pointers to such option tables + will only be valid during a run of the algorithm; you cannot store + a point to an option table past the run of an algorithm. +*/ + +typedef struct pgfgd_OptionTable pgfgd_OptionTable; + + +/** Returns 1 if the key is actually set in the option table to any + non-nil value; otherwise 0. */ +int pgfgd_isset(pgfgd_OptionTable* t, const char* key); + +/** Returns 1 if the key is a number (or can be converted to a + number) in the option table. */ +int pgfgd_isnumber(pgfgd_OptionTable* t, const char* key); + +/** Returns 1 if the key is a string in the option table. */ +int pgfgd_isstring(pgfgd_OptionTable* t, const char* key); + +/** Returns 1 if the key is a Boolean value in the option table. */ +int pgfgd_isboolean(pgfgd_OptionTable* t, const char* key); + +/** Returns 1 if the key is a user value in the option table. */ +int pgfgd_isuser(pgfgd_OptionTable* t, const char* key); + +/** Provided that pgfgd_isnumber returns 1 for the key, this funciton + will return the number stored in the key (otherwise, the function + may crash). Note that integers are also retrieved through this function. */ +double pgfgd_tonumber(pgfgd_OptionTable* t, const char* key); + +/** Provided that pgfgd_isstring returns 1 for this key, this function + returns a copy of the string stored in the key. You must free the + returned string yourself. */ +char* pgfgd_tostring(pgfgd_OptionTable* t, const char* key); + +/** Provided that pgfgd_isboolean returns 1 for this key, the function + returns this Boolean value. */ +int pgfgd_toboolean(pgfgd_OptionTable* t, const char* key); + +/** Provided that pgfgd_isuser returns 1 for this key, the function + returns this user value. */ +void* pgfgd_touser(pgfgd_OptionTable* t, const char* key); + + + +// Graph model + +/** An abstraction of a pgf.gd.model.Coordinate object. */ +typedef struct pgfgd_Coordinate { + double x; + double y; +} pgfgd_Coordinate; + + +/** Used to pass around arrays of Coordinate objects. The main purpose + of the structure is to provide access to the length of the + array. Note that numbering starts with 0. +*/ +typedef struct pgfgd_Coordinate_array { + int length; + pgfgd_Coordinate* array; +} pgfgd_Coordinate_array; + + +typedef struct pgfgd_Edge pgfgd_Edge; + +/** An array of Edge objects. */ +typedef struct pgfgd_Edge_array { + + int length; + pgfgd_Edge** array; + +} pgfgd_Edge_array; + + +/** This struct is used to model a Lua Path. In Lua, a path is an + array where each entry is either a Coordinate object or a + string. This is modeled on the C layer by having + two arrays and for each position, either the coordinates array or + the strings array is set (the strings + array is set at position i if, and only if, it is not null). + + Graph drawing functions may wish to modify Edge paths, namely + whenever they wish to setup a special routing for an edge. In this + case, you may not directly modify the object, but, rather, you + must use the functions pgfgd_path_xxx to modify the path + field. When the graph drawing function is done, the values stored + in the the path fields of the Edges of the syntactic digraph are + copied back to Lua. + + Note that numbering starts at 0. Also note that you have to set + the path field for each syntactic edge individually. + + The |length| field will be |-1| for the ``default path'' of an + edge. The actual path (a straight line from the tail to the head + vertex) is generated only when the graph is written back, because + only then the coordinates of the nodes will be known. +*/ + +typedef struct pgfgd_Path { + + /** Both arrays of this struct will have this length, except when + this field is set to -1, indicating that a default path should + be generated when this path is written back to the graph. */ + int length; + + /** An array of coordinates. Not all entries of this array are + relevant, namely only those for which the strings array is null + at the some position. + */ + pgfgd_Coordinate* coordinates; + + /** An array of strings. Whenever an entry in this array is not + null, the entry in the coordinates array at the same position is + ignored. */ + char** strings; + +} pgfgd_Path; + + + +/** An abstraction of a pgf.gd.model.Vertex. These objects are + managed by the library (including creation and deletion), you + should not create them yourself or modify them, except for the pos + field, which you should modify (indeed, this is the whole purpose + of your graph drawing algorithm). +*/ + +typedef struct pgfgd_Vertex { + + /** The name field of the Lua Vertex class. */ + char* name; + + /** The path field of the Lua Vertex class. */ + pgfgd_Path* path; + + /** The shape field of the Lua Vertex class. */ + char* shape; + + /** The kind field of the Lua Vertex class. */ + char* kind; + + /** The pos field of the Lua Vertex class. Unlike the other fields + of this struct, you can write pos.x and pos.y. When the graph + drawing function returns, the values stored in theses fields + will be written back to the Lua layer. + */ + pgfgd_Coordinate pos; + + /** The options fields of the Lua Vertex class. Note that you do + not have direct access to theses options. Rather, all access to + them must go through functions like pgfgd_isset that take a + pgfgd_OptionsTable* as input. Also note that you cannot store a + pointer to an options table: At the end of the graph drawing + function, all option table pointers will loose their + meaning. If you really wish to store an options table, you need + to retrieve all information stored in it while the point is + still active and then store the retrieved information in your + own table. + */ + pgfgd_OptionTable* options; + + /** Similar to the incoming field of the Lua Vertex class, but it + stores abstractions of the syntactic Edges objects of the + syntactic digraph, rather than the table of Arc objects that are + really stored in a Vertex. Also note that in a Lua Vertex + object, the incoming and outgoing arcs depend on the graph, + while a pgfgd_Vertex always only stores the incoming and + outgoing edges of the syntactic digraph. The order of the edges + in the incoming array will be the same as on the Lua layer, but + numbering starts with 0 (since these are C arrays). + */ + pgfgd_Edge_array incoming; + + /** Like the incoming fields. */ + pgfgd_Edge_array outgoing; + + /** The index of this vertex in the array entry of the syntactic + digraph. */ + int array_index; + +} pgfgd_Vertex; + + + +/** Used to pass around arrays of Vertex objects (more precisely, of + arrays of pointers to pgfgd_Vertex objects). Note that numbering + starts with 0. +*/ + +typedef struct pgfgd_Vertex_array { + int length; + pgfgd_Vertex** array; +} pgfgd_Vertex_array; + + + +/** This function allows you to query an anchor of a vertex (like a + call to |Vertex:anchor|). The function returns + |1| if there is such an anchor, otherwise |0| is returned and + both |x| and |y| will be set to 0. */ +extern int pgfgd_vertex_anchor(pgfgd_Vertex* v, const char* anchor, double* x, double* y); + + + +/** An abstraction of pgf.gd.model.Edge. */ + +struct pgfgd_Edge { + + /** The tail field of the Lua Edge class. */ + pgfgd_Vertex* tail; + + /** The head field of the Lua Edge class. */ + pgfgd_Vertex* head; + + /** The direction field of the Lua Edge class. */ + char* direction; + + /** The path field of the Lua Edge class. You can read this field + directly, but you can write it only through the function whose + names start with pgfgd_path. + + For each pgfgd_Edge object, at the end of the graph drawing + routinge, the value stored in this field will be written back to + the path field of the original syntactic edge. + */ + pgfgd_Path* path; + + /** A pointer to the options table of the Edge. This works like the + options table of pgdgd_Vertex and the same restrictions apply. + */ + pgfgd_OptionTable* options; + + /** The index of this edge in the array entry of the syntactic + digraph. */ + int array_index; + +}; + + +typedef struct pgfgd_SyntacticDigraph_internals pgfgd_SyntacticDigraph_internals; + + +/** The class pgf.gd.model.Digraph is modeled using two different C + structs: First, we have pgfgd_SyntacticDigraph and, second, we + have pgfgd_Digraph. The first is used, only, to model the (single) + syntactic digraph that is passed to the graph drawing function, + while the second is used to model different, more light weight + digraphs that are computed be the graph drawing system prior to + the call of the graph drawing routine. For instance, the spanning + tree computed by the graph drawing system for algorithms whose + preconditions included "tree" will be modeled as a pgfgd_Digraph. + + There is only one pgfgd_SyntacticDigraph during a call of + the graph drawing routine and you can access its properties + directly by accessing the fields of the struct. You cannot, + however, modify the syntactic digraph, except for setting the pos + fields of the vertices and for setting the path field arrays of + the syntactic edges (through the pgfgd_path_xxx functions). When + the graph drawing function is done, the modifications will be + written back to the Lua layer. + + Note that the syntactic digraph only stores the syntactic edges, + not the Arc objects. In particular, when you write + |graph { a <- b }| on the TikZ layer, you will get one syntactic + edge from a to b (not the other way round) with its direction + field set to "<-" in the syntactic digraph object. + */ + +typedef struct pgfgd_SyntacticDigraph { + + /** The vertices field of a Lua (syntactic) digraph. You may not + modify this array, except for changing the pos fields of the + vertices. */ + pgfgd_Vertex_array vertices; + + /** All syntactic edges of the graph. You cannot modify this array, + but you can use the pgfgd_path_xxx funtion to change the routing + of the edges stored here. Note that, since you get access to + syntactic edges, the direction of these edges may not be what + you expect and there may be several syntactic edges between the + same vertices. + */ + pgfgd_Edge_array syntactic_edges; + + /** The syntactic digraph's options field. Like all options fields, + it will go out of scope at the end of the graph drawing + routine. + */ + pgfgd_OptionTable* options; + + pgfgd_SyntacticDigraph_internals* internals; + +} pgfgd_SyntacticDigraph; + + + + +// Modifying edge bend paths + +/** You can apply this function to an Edge to clear the routing path + stored in it. +*/ +extern void pgfgd_path_clear (pgfgd_Edge* e); + +/** This function adds a moveto at the end of a path. */ +extern void pgfgd_path_append_moveto (pgfgd_Edge* e, double x, double y); + +/** This function adds a moveto to the |tail anchor| of the tail of + the edge. This call is useful for ``starting'' a path. This + function is a ``service function,'' you can achieve the same + effect by directly reading the option table of the tail vertex + and then using the pgfgd_vertex_anchor method. */ +extern void pgfgd_path_append_moveto_tail (pgfgd_Edge* e); + +/** This function adds a lineto at the end of a path. */ +extern void pgfgd_path_append_lineto (pgfgd_Edge* e, double x, double y); + +/** This function adds a linto to the |head anchor| of the head of + the edge. This call is useful for ``ending'' a path. */ +extern void pgfgd_path_append_lineto_head (pgfgd_Edge* e); + +/** This function adds a closepath at the end of a path. */ +extern void pgfgd_path_append_closepath (pgfgd_Edge* e); + +/** This function adds a curevto at the end of a path. */ +extern void pgfgd_path_append_curveto (pgfgd_Edge* e, double x1, double y1, double x2, double y2, double x, double y); + + + + +// Querying graphs other than the syntactic digraph + +/** A pgfgd_Digraph is a light-weight abstraction of a Lua Digraph + object. Unlike a pgfgd_SyntacticDigraph, you cannot access the + fields such an object directly, rather, all information is + retrieved through functions starting with pgfgd_digraph. + + When the graph drawing function is called, the graph drawing + system will already have computed a number of special digraphs in + addition to the syntactic digraph passed to the function. For + instance, there is always the "ugraph", which is the undirected + graph underlying the syntactic digraph. To access these special + graphs, you first call pgfgd_get_digraph and then use the + pgfgd_digraph_xxx function to retrieve information about them. + + Unlike the pgfgd_SyntacticDigraph object, which is managed by the + library, you must free pgfgd_Digraph objects yourself through the + pgfgd_digraph_free function. +*/ + +typedef struct pgfgd_Digraph pgfgd_Digraph; + +/** There is no abstraction of an Arc object on the C layer. Rather, + an arc is simply the index of the tail vertex plus the index of + the head vertex, where the indices are relative to the array of + vertices making up the digraph under consideration. + + You may wonder why we store indices rather than pointers to + pgfgd_Vertex objects. The reason is that a pgfgd_Digraph may + actually contain vertices that are not present in the syntactic + digraph (for instance, dummy vertices in a spanning tree) and for + which no pgfgd_Vertex obejct exists. For this reason, we only use + indices and there is a special function + (pgfgd_digraph_syntactic_vertex) that can be used to retrieve the + pgfgd_Vertex object, provided it exists. + + Note that the numbers stored in the tails and heads arrays, which + refer to positions inside a Lua vertices array, start numbering + with 1. The arrays themselves, however, start numbering with + 0. So, tails[0] == 1 and heads[0] == 2 would mean that there is an + Arc from the first to the second vertex. You can pass the numbers + stored in these arrays directly to the pgfgd_digraph_xxx + functions. + + You must free pgfgd_Arc_array objects yourself via + pgfgd_digraph_free_arc_array. + */ +typedef struct pgfgd_Arc_array { + + /** The length of both arrays. */ + int length; + + /** The array of the numbers of the tail vertices of the arcs. The + array itself starts numbering with 0, but its entries refer to + positions inside Lua array, so their numbering starts with 1. */ + int* tails; + + /** Like tails. */ + int* heads; + +} pgfgd_Arc_array; + + +/** In order to access special digraphs like the |ugraph| or the + |spanning_tree| computed by the graph drawing system, you first + need to call this function. In detail, the graph_name must be the + name of a field of the Lua algorithm object and this field must + store a |Digraph| object. Examples are "digraph" or "ugraph". The + function will then return a handle to this digraph which you can + subsequently access. The handle will become invalid at the end of + the graph drawing funciton and you must free it explicitly using + pgfgd_digraph_free. + */ +extern pgfgd_Digraph* pgfgd_get_digraph (pgfgd_SyntacticDigraph* g, const char* graph_name); + +/** Returns the number of vertices in the digraph. Note that this + number needs not be the same as the number of vertices in the + syntactic digraph and that the ordering need not be the + same as in the syntactic digraph. */ +extern int pgfgd_digraph_num_vertices (pgfgd_Digraph* g); + +/** Returns a newly allocated array of all arcs present in the + digraph. You must free this array explicitly using + pgfgd_digraph_free_arc_array. +*/ +extern pgfgd_Arc_array* pgfgd_digraph_arcs (pgfgd_Digraph* g); + +/** This function allows you to retrieve the syntatic vertex that + corresponds to a given index in the digraph. Normally, the first + vertex of a digraph like the ugraph will also be the first entry + of the vertices field of the syntactic digraph, but this need not + always be the case. For instance, for a spanning_tree digraph, + there will be more vertices in the graph than there are syntactic + vertices and the order may be quite different. For theses reaons, + you must use this function to convert a vertex index into the + digraph g into a pgfgd_Vertex object. It may happen that the index + does not refer to any syntactic vertex, in this case 0 is + returned. + + Note that v is an index into a Lua array and, thus, numbering + starts with 1. +*/ +extern pgfgd_Vertex* pgfgd_digraph_syntactic_vertex (pgfgd_Digraph* g, int v); + +/** Tests whether there is an arc between two vertices in the digraph + g. The tail and head are indices starting with 1. This operation + takes time $O(1)$. +*/ +extern int pgfgd_digraph_isarc (pgfgd_Digraph* g, int tail, int head); + +/** Returns an array of all syntactic edges present between two + vertices (whose indices are given as input). You must free the + returned array explicitly using + pgfgd_digraph_free_edge_array. Typically, this array will have at + most one entry, but it may happen that the user has specified + several syntatic edges between the same vertices, in which case + you get a larger array here. + + Note that tail and head are indices (starting with 1) into the + digraph's vertices array, which the return value is an array of + syntactic edges present in the syntactic digraph between the + vertices corresponding to these indices. In particular, if the + vertices do not correspond to syntactic vertices, the returned + array will always be empty. +*/ +extern pgfgd_Edge_array* pgfgd_digraph_syntactic_edges (pgfgd_Digraph* g, int tail, int head); + +/** Returns an array of all incoming arcs of the given vertex. (As + always, the vertex is coded as an index starting with 1 into the + vertices array of the digraph.) You must free this array + yourself using pgfgd_digraph_free_arc_array. In the returned + array, all entries of the head array will equal v. + */ +extern pgfgd_Arc_array* pgfgd_digraph_incoming (pgfgd_Digraph* g, int v); + +/** Like pgfgd_digraph_incoming. */ +extern pgfgd_Arc_array* pgfgd_digraph_outgoing (pgfgd_Digraph* g, int v); + +/** Frees a pgfgd_Digraph object previously allocated by the + pgfgd_get_digraph function. */ +extern void pgfgd_digraph_free (pgfgd_Digraph* d); + +/** Frees a pgfgd_Arc_array object; in particular, the arrays stored + inside it are freed. You should call this function once at some + point for all objects of this kind returned by any library function. +*/ +extern void pgfgd_digraph_free_arc_array (pgfgd_Arc_array* arcs); + +/** Like pgfgd_digraph_free_arc_array, but for the Edge arrays + returned by pgfgd_digraph_syntactic_edges. Do not call this + function for the syntactic_edges field of a syntactic digraph. +*/ +extern void pgfgd_digraph_free_edge_array (pgfgd_Edge_array* edges); + + + +// Declarations + +struct lua_State; +typedef void (*pgfgd_algorithm_fun) (pgfgd_SyntacticDigraph* component, void* user_data); +typedef struct pgfgd_Declaration pgfgd_Declaration; + + +/** Each declaration of a new option starts with a call to this + function. The function returns an object whose properties you can + set subsequently through the pgfgd_key_xxx function. Once all + properties of the key have been set, you call pgfgd_declare to + make Lua aware of the option. Then, you need to call + pgfgd_free_key on it. + */ + +extern pgfgd_Declaration* pgfgd_new_key (const char* key); + +/** Sets the summary field of the key. You should always call this + function. */ +extern void pgfgd_key_summary (pgfgd_Declaration* d, const char* s); + +/** Sets the type field of the key. */ +extern void pgfgd_key_type (pgfgd_Declaration* d, const char* s); + +/** Sets the initial field of the key to a string. */ +extern void pgfgd_key_initial (pgfgd_Declaration* d, const char* s); + +/** Sets the initial field of the key to void* value (a light userdata + in Lua-speak). */ +extern void pgfgd_key_initial_user (pgfgd_Declaration* d, void* v); + +/** Sets the default field of the key. */ +extern void pgfgd_key_default (pgfgd_Declaration* d, const char* s); + +/** Sets the alias field of the key. */ +extern void pgfgd_key_alias (pgfgd_Declaration* d, const char* s); + +/** Sets the alias_function_string field of the key. */ +extern void pgfgd_key_alias_function (pgfgd_Declaration* d, const char* s); + +/** Sets the documentation field of the key. */ +extern void pgfgd_key_documentation (pgfgd_Declaration* d, const char* s); + +/** Sets the documentation_in field of the key. */ +extern void pgfgd_key_documentation_in (pgfgd_Declaration* d, const char* s); + +/** Sets the phase field of the key. */ +extern void pgfgd_key_phase (pgfgd_Declaration* d, const char* s); + +/** Sets the algorithm field of the key. The function f must conform + to the function prototype pgfgd_algorithm_fun, which prescribes + that the function takes a syntactic digraph as input + (pgfgd_SyntacticDigraph*) and some user data and does not return + anything. The user data that is passed to the function is the + datum passed here. + + Whenever the key is now used on the Lua layer, the graph drawing + system will run the normal layout pipeline on the graph. Then, at + some point, it would call the actual Lua graph drawing + algorithm. At that point, the function f is called instead. The + parameter of this function will be a representation of the + to-be-drawn syntatic digraph as a C pgfgd_SyntacticDigraph. +*/ +extern void pgfgd_key_algorithm (pgfgd_Declaration* d, + pgfgd_algorithm_fun f, + void* user_data); + +/** Adds a use to the key. This means that whenever the key is used, + the given key--value pairs will also be set. This is used, in + particular, to create aliases for keys (but is not to be confused + with the |alias| field, whose semantics are slightly different). + */ +extern void pgfgd_key_add_use (pgfgd_Declaration* d, const char* key, const char* value); + +/** Adds a use to the key, but with the value being a user value in + Lua-speak. + */ +extern void pgfgd_key_add_use_user (pgfgd_Declaration* d, const char* key, void* value); + +/** Adds an example to the examples field of the key. */ +extern void pgfgd_key_add_example (pgfgd_Declaration* d, const char* s); + +/** Adds a precondition (the field s of the precondition table is set + to true) to the key. */ +extern void pgfgd_key_add_precondition (pgfgd_Declaration* d, const char* s); + +/** Adds a postcondition to the key. */ +extern void pgfgd_key_add_postcondition (pgfgd_Declaration* d, const char* s); + +/** After all properties of an option key have been set, call this + function once to actually declare the key inside the state that + your graph drawing library's main function gets + passed by the Lua dynamic linkage code. */ +extern void pgfgd_declare (struct lua_State* s, pgfgd_Declaration* d); + +/** Frees the memory used by the key object. */ +extern void pgfgd_free_key (pgfgd_Declaration* d); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/interface/c/Makefile b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/interface/c/Makefile new file mode 100644 index 00000000000..898e841aa40 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/interface/c/Makefile @@ -0,0 +1,17 @@ +CONFIGDIR=../../../../../config +include $(CONFIGDIR)/MakefileConfig.mk + +FLAGS=$(MYCFLAGS) $(ARCHFLAGS) -O2 -Wall -I$(LUAINCLUDES) -I$(PGFINCLUDES) + +all: InterfaceFromC.o InterfaceFromC++.o + +clean: + rm *.o + +install: + +InterfaceFromC.o: InterfaceFromC.c InterfaceFromC.h + $(CC) $(FLAGS) -c -o InterfaceFromC.o InterfaceFromC.c + +InterfaceFromC++.o: InterfaceFromC++.h InterfaceFromC.h InterfaceFromC++.c++ + $(CC) $(FLAGS) -c -o InterfaceFromC++.o InterfaceFromC++.c++ diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/InterfaceFromOGDF.c++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/InterfaceFromOGDF.c++ new file mode 100644 index 00000000000..248ee0b19e1 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/InterfaceFromOGDF.c++ @@ -0,0 +1,105 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <pgf/gd/interface/c/InterfaceFromC.h> + +#include <ogdf/basic/geometry.h> + + +using namespace ogdf; + +namespace scripting { + + + void ogdf_runner::bridge () + { + graph = Graph(); + graph_attributes = GraphAttributes (graph, + GraphAttributes::nodeGraphics | + GraphAttributes::edgeGraphics | + GraphAttributes::nodeLevel | + GraphAttributes::edgeIntWeight | + GraphAttributes::edgeDoubleWeight | + GraphAttributes::nodeWeight); + + pgfgd_SyntacticDigraph* g = parameters->syntactic_digraph; + + int n = g->vertices.length; + int m = g->syntactic_edges.length; + + node* nodes = new node [n]; + + for (int i=0; i < n; i++) { + nodes[i] = graph.newNode(); + + // Compute width and height + double x1, x2,y1,y2; + x1 = x2 = y1 = y2 = 0; + + int first = 1; + + pgfgd_Path* path = g->vertices.array[i]->path; + + for (int j = 1; j < path->length; j++) + if (!path->strings[j]) { + double x = path->coordinates[j].x; + double y = path->coordinates[j].y; + + if (first) { + x1 = x2 = x; + y1 = y2 = y; + first = 0; + } else { + x1 = x < x1 ? x : x1; + x2 = x > x2 ? x : x2; + y1 = y < y1 ? y : y1; + y2 = y > y2 ? y : y2; + } + } + + graph_attributes.width(nodes[i]) = x2-x1; + graph_attributes.height(nodes[i]) = y2-y1; + } + + for (int i=0; i < m; i++) { + int tail = g->syntactic_edges.array[i]->tail->array_index; + int head = g->syntactic_edges.array[i]->head->array_index; + + graph.newEdge(nodes[tail], nodes[head]); + } + } + + void ogdf_runner::unbridge () + { + pgfgd_SyntacticDigraph* g = parameters->syntactic_digraph; + + node v; + int i; + for (i = 0, v = graph.firstNode(); v; v=v->succ(), i++) { + g->vertices.array[i]->pos.x = graph_attributes.x(v); + g->vertices.array[i]->pos.y = graph_attributes.y(v); + } + + edge e; + for (i = 0, e = graph.firstEdge(); e; e=e->succ(), i++) { + pgfgd_Edge* ed = g->syntactic_edges.array[i]; + + DPolyline bend = graph_attributes.bends(e); + + if (bend.begin().valid()) { + bend.unify(); + bend.normalize(); + + // We start with a moveto: + pgfgd_path_clear (ed); + + pgfgd_path_append_moveto_tail(ed); + + for (List<DPoint>::iterator it = bend.begin(); it.valid(); it++) + pgfgd_path_append_lineto(ed, (*it).m_x, (*it).m_y); + + // We end with a lineto: + pgfgd_path_append_lineto_head(ed); + } + } + } + +} diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/InterfaceFromOGDF.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/InterfaceFromOGDF.h new file mode 100644 index 00000000000..bd742eb1610 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/InterfaceFromOGDF.h @@ -0,0 +1,45 @@ +#ifndef PGF_GD_INTERFACE_C_INTERFACEFROMOGDF_H +#define PGF_GD_INTERFACE_C_INTERFACEFROMOGDF_H + +/** \file pgf/gd/interface/c/InterfaceFromOGDF.h + + The C++-header file that should be used by algorithms written + for the OGFD library when the algorithm should be included in Lua. +*/ + +#include <pgf/gd/interface/c/InterfaceFromC++.h> +#include <ogdf/basic/Graph.h> +#include <ogdf/basic/GraphAttributes.h> + +namespace scripting { + + class ogdf_runner : public runner { + public: + + void bridge (); + void unbridge (); + + protected: + + ogdf::Graph graph; + ogdf::GraphAttributes graph_attributes; + + }; + + + class ogdf_function_runner : public ogdf_runner { + public: + typedef void (*function) (run_parameters&, + ogdf::Graph&, + ogdf::GraphAttributes&); + + ogdf_function_runner (function f) : fun(f) {} + virtual void run () { fun(*parameters, graph, graph_attributes); } + + private: + function fun; + }; +} + + +#endif diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/Makefile b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/Makefile new file mode 100644 index 00000000000..7ebf338f20f --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/Makefile @@ -0,0 +1,56 @@ +CONFIGDIR=../../../../../config +include $(CONFIGDIR)/MakefileConfig.mk + +FLAGS=$(MYCFLAGS) $(ARCHFLAGS) -O2 -Wall -I$(LUAINCLUDES) -I$(PGFINCLUDES) -I$(OGDFINCLUDES) + +all: ogdf_script.so SimpleDemoOGDF.so + +clean: + rm *.o *.so + +install: ogdf_script.so SimpleDemoOGDF.so + mkdir -p $(INSTALLDIR)/pgf/gd/ogdf/c + cp SimpleDemoOGDF.so $(INSTALLDIR)/pgf/gd/ogdf/c/pgf_gd_ogdf_c_SimpleDemoOGDF.so + cp ogdf_script.so $(INSTALLDIR)/pgf/gd/ogdf/c/pgf_gd_ogdf_c_ogdf_script.so + + +ogdf_script.so: ogdf_script.o InterfaceFromOGDF.o ../../interface/c/InterfaceFromC++.o ../../interface/c/InterfaceFromC.o + $(CC) $(FLAGS) $(SHAREDFLAGS) $(MYLDFLAGS) \ + -L$(OGDFLIBPATH) -lOGDF \ + $(LINKSHAREDLUA) \ + -o ogdf_script.so \ + ogdf_script.o \ + InterfaceFromOGDF.o \ + ../../interface/c/InterfaceFromC.o \ + ../../interface/c/InterfaceFromC++.o + +ogdf_script.o: ogdf_script.c++ \ + InterfaceFromOGDF.h \ + ../../interface/c/InterfaceFromC++.h \ + ../../interface/c/InterfaceFromC.h Makefile + $(CC) $(FLAGS) -c -o ogdf_script.o ogdf_script.c++ + + +SimpleDemoOGDF.so: SimpleDemoOGDF.o \ + InterfaceFromOGDF.o \ + ../../interface/c/InterfaceFromC++.o \ + ../../interface/c/InterfaceFromC.o Makefile + $(CC) $(FLAGS) $(SHAREDFLAGS) $(MYLDFLAGS) \ + $(LINKSHAREDLUA) \ + -L$(OGDFLIBPATH) -lOGDF \ + -o SimpleDemoOGDF.so \ + SimpleDemoOGDF.o ../../interface/c/InterfaceFromC++.o ../../interface/c/InterfaceFromC.o \ + InterfaceFromOGDF.o + +SimpleDemoOGDF.o: SimpleDemoOGDF.c++ \ + InterfaceFromOGDF.h \ + ../../interface/c/InterfaceFromC++.h \ + ../../interface/c/InterfaceFromC.h + $(CC) $(FLAGS) -I$(OGDFINCLUDES) -c -o SimpleDemoOGDF.o SimpleDemoOGDF.c++ + + + +InterfaceFromOGDF.o: ../../interface/c/InterfaceFromC++.h ../../interface/c/InterfaceFromC.h \ + InterfaceFromOGDF.c++ InterfaceFromOGDF.h + $(CC) $(FLAGS) -c -o InterfaceFromOGDF.o InterfaceFromOGDF.c++ + diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/SimpleDemoOGDF.c++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/SimpleDemoOGDF.c++ new file mode 100644 index 00000000000..b7d914c5207 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/SimpleDemoOGDF.c++ @@ -0,0 +1,43 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> + +#include <math.h> + +using namespace ogdf; +using namespace scripting; + +struct FastLayoutOGDF : declarations, ogdf_runner { + + void run () { + double angle = 6.28318530718 / graph.numberOfNodes(); + double radius = parameters->option<double>("my radius ogdf"); + + int i = 0; + for (node v = graph.firstNode(); v; v=v->succ(), i++) { + graph_attributes.x(v) = cos(angle*i) * radius; + graph_attributes.y(v) = sin(angle*i) * radius; + } + } + + void declare(script s) { + using namespace scripting; + + s.declare(key ("fast simple demo layout ogdf") + .summary ("The OGDF version of the hello world of graph drawing") + .precondition ("connected") + .algorithm (this)); + + s.declare(key ("my radius ogdf") + .summary ("A radius value for the hello world of graph drawing") + .type ("length") + .initial ("1cm")); + } + +}; + +extern "C" int luaopen_pgf_gd_ogdf_c_SimpleDemoOGDF (struct lua_State *state) { + + script (state).declare (new FastLayoutOGDF); + + return 0; +} + diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/FMMMLayout_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/FMMMLayout_script.h new file mode 100644 index 00000000000..bdaf26bf672 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/FMMMLayout_script.h @@ -0,0 +1,44 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/energybased/FMMMLayout.h> + +struct FMMMLayout_script : + scripting::declarations, + scripting::ogdf_runner +{ + void run () { + using namespace ogdf; + FMMMLayout layout; + + layout.newInitialPlacement(false); + layout.qualityVersusSpeed(FMMMLayout::qvsGorgeousAndEfficient); + + parameters->configure_option ("FMMMLayout.unitEdgeLength", + &FMMMLayout::unitEdgeLength, layout); + parameters->configure_option ("FMMMLayout.randSeed", + &FMMMLayout::randSeed, layout); + + layout.call (graph_attributes); + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + s.declare (key ("FMMMLayout") + .precondition ("connected") + .algorithm (this) + .documentation_in ("pgf.gd.doc.ogdf.energybased.FMMMLayout")); + + s.declare (key ("FMMMLayout.randSeed") + .type ("number") + .initial ("42") + .alias ("random seed") + .documentation_in ("pgf.gd.doc.ogdf.energybased.FMMMLayout")); + + s.declare (key ("FMMMLayout.unitEdgeLength") + .type ("length") + .initial ("1cm") + .alias_function ("function (o) return o['node pre sep'] + o['node post sep'] end") + .documentation_in ("pgf.gd.doc.ogdf.energybased.FMMMLayout")); + } + +}; diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/FastMultipoleEmbedder_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/FastMultipoleEmbedder_script.h new file mode 100644 index 00000000000..38d9b032c9e --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/FastMultipoleEmbedder_script.h @@ -0,0 +1,51 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/energybased/FastMultipoleEmbedder.h> + +struct FastMultipoleEmbedder_script : + scripting::declarations, + scripting::factory<ogdf::FastMultipoleEmbedder> +{ + ogdf::FastMultipoleEmbedder* make (scripting::run_parameters* parameters) { + using namespace ogdf; + FastMultipoleEmbedder* r = new FastMultipoleEmbedder; + + parameters->configure_option ("FastMultipoleEmbedder.numIterations", + &FastMultipoleEmbedder::setNumIterations, *r); + parameters->configure_option ("FastMultipoleEmbedder.multipolePrec", + &FastMultipoleEmbedder::setMultipolePrec, *r); + parameters->configure_option ("FastMultipoleEmbedder.defaultEdgeLength", + &FastMultipoleEmbedder::setDefaultEdgeLength, *r); + parameters->configure_option ("FastMultipoleEmbedder.defaultNodeSize", + &FastMultipoleEmbedder::setDefaultNodeSize, *r); + + return r; + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + + s.declare (key ("FastMultipoleEmbedder") + .set_module ("LayoutModule", this) + .documentation_in ("pgf.gd.doc.ogdf.energybased.FastMultipoleEmbedder")); + + s.declare (key ("FastMultipoleEmbedder.numIterations") + .type ("number") + .documentation_in ("pgf.gd.doc.ogdf.energybased.FastMultipoleEmbedder")); + + s.declare (key ("FastMultipoleEmbedder.multipolePrec") + .type ("number") + .documentation_in ("pgf.gd.doc.ogdf.energybased.FastMultipoleEmbedder")); + + s.declare (key ("FastMultipoleEmbedder.defaultEdgeLength") + .type ("length") + .alias_function ("function (o) return o['node pre sep'] + o['node post sep'] end") + .documentation_in ("pgf.gd.doc.ogdf.energybased.FastMultipoleEmbedder")); + + s.declare (key ("FastMultipoleEmbedder.defaultNodeSize") + .type ("number") + .documentation_in ("pgf.gd.doc.ogdf.energybased.FastMultipoleEmbedder")); + + } + +}; diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/GEMLayout_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/GEMLayout_script.h new file mode 100644 index 00000000000..7b4fda7e68a --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/GEMLayout_script.h @@ -0,0 +1,101 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/energybased/GEMLayout.h> + +struct GEMLayout_script : + scripting::declarations, + scripting::factory<ogdf::GEMLayout> +{ + ogdf::GEMLayout* make (scripting::run_parameters* parameters) { + using namespace ogdf; + GEMLayout* r = new GEMLayout; + + parameters->configure_option ("GEMLayout.numberOfRounds", + &GEMLayout::numberOfRounds, *r); + parameters->configure_option ("GEMLayout.minimalTemperature", + &GEMLayout::minimalTemperature, *r); + parameters->configure_option ("GEMLayout.initialTemperature", + &GEMLayout::initialTemperature, *r); + parameters->configure_option ("GEMLayout.gravitationalConstant", + &GEMLayout::gravitationalConstant, *r); + parameters->configure_option ("GEMLayout.desiredLength", + &GEMLayout::desiredLength, *r); + parameters->configure_option ("GEMLayout.maximalDisturbance", + &GEMLayout::maximalDisturbance, *r); + parameters->configure_option ("GEMLayout.rotationAngle", + &GEMLayout::rotationAngle, *r); + parameters->configure_option ("GEMLayout.oscillationAngle", + &GEMLayout::oscillationAngle, *r); + parameters->configure_option ("GEMLayout.rotationSensitivity", + &GEMLayout::rotationSensitivity, *r); + parameters->configure_option ("GEMLayout.oscillationSensitivity", + &GEMLayout::oscillationSensitivity, *r); + parameters->configure_option ("GEMLayout.attractionFormula", + &GEMLayout::attractionFormula, *r); + + return r; + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + + s.declare (key ("GEMLayout") + .set_module ("LayoutModule", this) + .documentation_in ("pgf.gd.doc.ogdf.energybased.GEMLayout")); + + s.declare (key ("GEMLayout.numberOfRounds") + .type ("number") + .initial ("20000") + .documentation_in ("pgf.gd.doc.ogdf.energybased.GEMLayout")); + + s.declare (key ("GEMLayout.minimalTemperature") + .type ("number") + .initial ("0.005") + .documentation_in ("pgf.gd.doc.ogdf.energybased.GEMLayout")); + + s.declare (key ("GEMLayout.initialTemperature") + .type ("number") + .initial ("10") + .documentation_in ("pgf.gd.doc.ogdf.energybased.GEMLayout")); + + s.declare (key ("GEMLayout.gravitationalConstant") + .type ("number") + .initial ("0.0625") + .documentation_in ("pgf.gd.doc.ogdf.energybased.GEMLayout")); + + s.declare (key ("GEMLayout.desiredLength") + .type ("length") + .alias_function ("function (o) return o['node pre sep'] + o['node post sep'] end") + .documentation_in ("pgf.gd.doc.ogdf.energybased.GEMLayout")); + + s.declare (key ("GEMLayout.maximalDisturbance") + .type ("number") + .initial ("0") + .documentation_in ("pgf.gd.doc.ogdf.energybased.GEMLayout")); + + s.declare (key ("GEMLayout.rotationAngle") + .type ("number") + .documentation_in ("pgf.gd.doc.ogdf.energybased.GEMLayout")); + + s.declare (key ("GEMLayout.oscillationAngle") + .type ("number") + .documentation_in ("pgf.gd.doc.ogdf.energybased.GEMLayout")); + + s.declare (key ("GEMLayout.rotationSensitivity") + .type ("number") + .initial ("0.01") + .documentation_in ("pgf.gd.doc.ogdf.energybased.GEMLayout")); + + s.declare (key ("GEMLayout.oscillationSensitivity") + .type ("number") + .initial ("0.3") + .documentation_in ("pgf.gd.doc.ogdf.energybased.GEMLayout")); + + s.declare (key ("GEMLayout.attractionFormula") + .type ("number") + .initial ("1") + .documentation_in ("pgf.gd.doc.ogdf.energybased.GEMLayout")); + + } + +}; diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/MultilevelLayout_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/MultilevelLayout_script.h new file mode 100644 index 00000000000..091ab9766ce --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/MultilevelLayout_script.h @@ -0,0 +1,33 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/energybased/MultilevelLayout.h> + +struct MultilevelLayout_script : + scripting::declarations, + scripting::ogdf_runner +{ + void run () { + using namespace ogdf; + MultilevelLayout layout; + + parameters->configure_module ("LayoutModule", + &MultilevelLayout::setLayout, layout); + parameters->configure_module ("MultilevelBuilder", + &MultilevelLayout::setMultilevelBuilder, layout); + parameters->configure_module ("InitialPlacer", + &MultilevelLayout::setPlacer, layout); + + layout.call (graph_attributes); + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + + s.declare (key ("MultilevelLayout") + .precondition ("connected") + .algorithm (this) + .documentation_in ("pgf.gd.doc.ogdf.energybased.MultilevelLayout")); + + } + +}; diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/SpringEmbedderFRExact_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/SpringEmbedderFRExact_script.h new file mode 100644 index 00000000000..4e9fbfb3f17 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/SpringEmbedderFRExact_script.h @@ -0,0 +1,66 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/energybased/SpringEmbedderFRExact.h> + +struct SpringEmbedderFRExact_script : + scripting::declarations, + scripting::ogdf_runner +{ + void run () { + using namespace ogdf; + SpringEmbedderFRExact layout; + + parameters->configure_option ("SpringEmbedderFRExact.iterations", + &SpringEmbedderFRExact::iterations, layout); + parameters->configure_option ("SpringEmbedderFRExact.noise", + &SpringEmbedderFRExact::noise, layout); + parameters->configure_option ("SpringEmbedderFRExact.idealEdgeLength", + &SpringEmbedderFRExact::idealEdgeLength, layout); + parameters->configure_option ("SpringEmbedderFRExact.convTolerance", + &SpringEmbedderFRExact::convTolerance, layout); + + char* s = 0; + + if (parameters->option("SpringEmbedderFRExact.coolingFunction", s)) { + if (strcmp(s, "factor") == 0) + layout.coolingFunction(SpringEmbedderFRExact::cfFactor); + else if (strcmp(s, "logarithmic") == 0) + layout.coolingFunction(SpringEmbedderFRExact::cfLogarithmic); + + free(s); + } + + layout.call (graph_attributes); + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + + s.declare (key ("SpringEmbedderFRExact") + .precondition ("connected") + .algorithm (this) + .documentation_in ("pgf.gd.doc.ogdf.energybased.SpringEmbedderFRExact")); + + s.declare (key ("SpringEmbedderFRExact.iterations") + .type ("number") + .documentation_in ("pgf.gd.doc.ogdf.energybased.SpringEmbedderFRExact")); + + s.declare (key ("SpringEmbedderFRExact.noise") + .type ("boolean") + .documentation_in ("pgf.gd.doc.ogdf.energybased.SpringEmbedderFRExact")); + + s.declare (key ("SpringEmbedderFRExact.coolingFunction") + .type ("string") + .documentation_in ("pgf.gd.doc.ogdf.energybased.SpringEmbedderFRExact")); + + s.declare (key ("SpringEmbedderFRExact.idealEdgeLength") + .type ("number") + .documentation_in ("pgf.gd.doc.ogdf.energybased.SpringEmbedderFRExact")); + + s.declare (key ("SpringEmbedderFRExact.convTolerance") + .type ("number") + .documentation_in ("pgf.gd.doc.ogdf.energybased.SpringEmbedderFRExact")); + + } + +}; diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/SpringEmbedderFR_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/SpringEmbedderFR_script.h new file mode 100644 index 00000000000..5ae182e5898 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/SpringEmbedderFR_script.h @@ -0,0 +1,45 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/energybased/SpringEmbedderFR.h> + +struct SpringEmbedderFR_script : + scripting::declarations, + scripting::ogdf_runner +{ + void run () { + using namespace ogdf; + SpringEmbedderFR layout; + + parameters->configure_option ("SpringEmbedderFR.iterations", + &SpringEmbedderFR::iterations, layout); + parameters->configure_option ("SpringEmbedderFR.noise", + &SpringEmbedderFR::noise, layout); + parameters->configure_option ("SpringEmbedderFR.scaleFunctionFactor", + &SpringEmbedderFR::scaleFunctionFactor, layout); + + layout.call (graph_attributes); + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + + s.declare (key ("SpringEmbedderFR") + .precondition ("connected") + .algorithm (this) + .documentation_in ("pgf.gd.doc.ogdf.energybased.SpringEmbedderFR")); + + s.declare (key ("SpringEmbedderFR.iterations") + .type ("number") + .documentation_in ("pgf.gd.doc.ogdf.energybased.SpringEmbedderFR")); + + s.declare (key ("SpringEmbedderFR.noise") + .type ("boolean") + .documentation_in ("pgf.gd.doc.ogdf.energybased.SpringEmbedderFR")); + + s.declare (key ("SpringEmbedderFR.scaleFunctionFactor") + .type ("number") + .documentation_in ("pgf.gd.doc.ogdf.energybased.SpringEmbedderFR")); + + } + +}; diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/SpringEmbedderKK_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/SpringEmbedderKK_script.h new file mode 100644 index 00000000000..2b1586a5461 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/SpringEmbedderKK_script.h @@ -0,0 +1,39 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/energybased/SpringEmbedderKK.h> + +struct SpringEmbedderKK_script : + scripting::declarations, + scripting::ogdf_runner +{ + void run () { + using namespace ogdf; + SpringEmbedderKK layout; + + parameters->configure_option ("SpringEmbedderKK.stopTolerance", + &SpringEmbedderKK::setStopTolerance, layout); + parameters->configure_option ("SpringEmbedderKK.desLength", + &SpringEmbedderKK::setDesLength, layout); + + layout.call (graph_attributes); + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + + s.declare (key ("SpringEmbedderKK") + .precondition ("connected") + .algorithm (this) + .documentation_in ("pgf.gd.doc.ogdf.energybased.SpringEmbedderKK")); + + s.declare (key ("SpringEmbedderKK.stopTolerance") + .type ("number") + .documentation_in ("pgf.gd.doc.ogdf.energybased.SpringEmbedderKK")); + + s.declare (key ("SpringEmbedderKK.desLength") + .type ("length") + .documentation_in ("pgf.gd.doc.ogdf.energybased.SpringEmbedderKK")); + + } + +}; diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/energybased_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/energybased_script.h new file mode 100644 index 00000000000..fdcd92565e7 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/energybased_script.h @@ -0,0 +1,31 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> + +#include "FMMMLayout_script.h" +#include "GEMLayout_script.h" +#include "FastMultipoleEmbedder_script.h" + +#include "SpringEmbedderFR_script.h" +#include "SpringEmbedderFRExact_script.h" +#include "SpringEmbedderKK_script.h" + +#include "MultilevelLayout_script.h" + +#include "multilevelmixer/multilevelmixer_script.h" + +struct energybased_script : + scripting::declarations +{ + void declare (scripting::script s) { + s.declare (new FMMMLayout_script); + s.declare (new GEMLayout_script); + s.declare (new FastMultipoleEmbedder_script); + + s.declare (new SpringEmbedderFR_script); + s.declare (new SpringEmbedderFRExact_script); + s.declare (new SpringEmbedderKK_script); + + s.declare (new MultilevelLayout_script); + + s.declare (new multilevelmixer_script); + } +}; diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/BarycenterPlacer_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/BarycenterPlacer_script.h new file mode 100644 index 00000000000..19ac75d3147 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/BarycenterPlacer_script.h @@ -0,0 +1,32 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/energybased/multilevelmixer/BarycenterPlacer.h> + +struct BarycenterPlacer_script : + scripting::declarations, + scripting::factory<ogdf::BarycenterPlacer> +{ + ogdf::BarycenterPlacer* make (scripting::run_parameters* parameters) { + using namespace ogdf; + BarycenterPlacer* r = new BarycenterPlacer; + + parameters->configure_option ("BarycenterPlacer.weightedPositionPriority", + &BarycenterPlacer::weightedPositionPriority, *r); + + return r; + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + + s.declare (key ("BarycenterPlacer") + .set_module ("InitialPlacer", this) + .documentation_in ("pgf.gd.doc.ogdf.energybased.multilevelmixer.BarycenterPlacer")); + + s.declare (key ("BarycenterPlacer.weightedPositionPriority") + .type ("boolean") + .documentation_in ("pgf.gd.doc.ogdf.energybased.multilevelmixer.BarycenterPlacer")); + + } + +}; diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/CirclePlacer_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/CirclePlacer_script.h new file mode 100644 index 00000000000..f208dbdecff --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/CirclePlacer_script.h @@ -0,0 +1,56 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/energybased/multilevelmixer/CirclePlacer.h> + +struct CirclePlacer_script : + scripting::declarations, + scripting::factory<ogdf::CirclePlacer> +{ + ogdf::CirclePlacer* make (scripting::run_parameters* parameters) { + using namespace ogdf; + CirclePlacer* r = new CirclePlacer; + + parameters->configure_option ("CirclePlacer.circleSize", + &CirclePlacer::setCircleSize, *r); + parameters->configure_option ("CirclePlacer.radiusFixed", + &CirclePlacer::setRadiusFixed, *r); + + + char* s = 0; + + if (parameters->option("CirclePlacer.nodeSelection", s)) { + if (strcmp(s, "new") == 0) + r->setNodeSelection(CirclePlacer::nsNew); + else if (strcmp(s, "old") == 0) + r->setNodeSelection(CirclePlacer::nsOld); + else if (strcmp(s, "all") == 0) + r->setNodeSelection(CirclePlacer::nsAll); + + free(s); + } + + return r; + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + + s.declare (key ("CirclePlacer") + .set_module ("InitialPlacer", this) + .documentation_in ("pgf.gd.doc.ogdf.energybased.multilevelmixer.CirclePlacer")); + + s.declare (key ("CirclePlacer.circleSize") + .type ("number") + .documentation_in ("pgf.gd.doc.ogdf.energybased.multilevelmixer.CirclePlacer")); + + s.declare (key ("CirclePlacer.radiusFixed") + .type ("boolean") + .documentation_in ("pgf.gd.doc.ogdf.energybased.multilevelmixer.CirclePlacer")); + + s.declare (key ("CirclePlacer.nodeSelection") + .type ("string") + .documentation_in ("pgf.gd.doc.ogdf.energybased.multilevelmixer.CirclePlacer")); + + } + +}; diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/EdgeCoverMerger_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/EdgeCoverMerger_script.h new file mode 100644 index 00000000000..cb91637d5da --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/EdgeCoverMerger_script.h @@ -0,0 +1,32 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/energybased/multilevelmixer/EdgeCoverMerger.h> + +struct EdgeCoverMerger_script : + scripting::declarations, + scripting::factory<ogdf::EdgeCoverMerger> +{ + ogdf::EdgeCoverMerger* make (scripting::run_parameters* parameters) { + using namespace ogdf; + EdgeCoverMerger* r = new EdgeCoverMerger; + + parameters->configure_option ("EdgeCoverMerger.factor", + &EdgeCoverMerger::setFactor, *r); + + return r; + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + + s.declare (key ("EdgeCoverMerger") + .set_module ("MultilevelBuilder", this) + .documentation_in ("pgf.gd.doc.ogdf.energybased.multilevelmixer.EdgeCoverMerger")); + + s.declare (key ("EdgeCoverMerger.factor") + .type ("number") + .documentation_in ("pgf.gd.doc.ogdf.energybased.multilevelmixer.EdgeCoverMerger")); + + } + +}; diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/IndependentSetMerger_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/IndependentSetMerger_script.h new file mode 100644 index 00000000000..2d950f8b9c8 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/IndependentSetMerger_script.h @@ -0,0 +1,32 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/energybased/multilevelmixer/IndependentSetMerger.h> + +struct IndependentSetMerger_script : + scripting::declarations, + scripting::factory<ogdf::IndependentSetMerger> +{ + ogdf::IndependentSetMerger* make (scripting::run_parameters* parameters) { + using namespace ogdf; + IndependentSetMerger* r = new IndependentSetMerger; + + parameters->configure_option ("IndependentSetMerger.searchDepthBase", + &IndependentSetMerger::setSearchDepthBase, *r); + + return r; + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + + s.declare (key ("IndependentSetMerger") + .set_module ("MultilevelBuilder", this) + .documentation_in ("pgf.gd.doc.ogdf.energybased.multilevelmixer.IndependentSetMerger")); + + s.declare (key ("IndependentSetMerger.searchDepthBase") + .type ("number") + .documentation_in ("pgf.gd.doc.ogdf.energybased.multilevelmixer.IndependentSetMerger")); + + } + +}; diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/LocalBiconnectedMerger_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/LocalBiconnectedMerger_script.h new file mode 100644 index 00000000000..898822e0c02 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/LocalBiconnectedMerger_script.h @@ -0,0 +1,32 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/energybased/multilevelmixer/LocalBiconnectedMerger.h> + +struct LocalBiconnectedMerger_script : + scripting::declarations, + scripting::factory<ogdf::LocalBiconnectedMerger> +{ + ogdf::LocalBiconnectedMerger* make (scripting::run_parameters* parameters) { + using namespace ogdf; + LocalBiconnectedMerger* r = new LocalBiconnectedMerger; + + parameters->configure_option ("LocalBiconnectedMerger.factor", + &LocalBiconnectedMerger::setFactor, *r); + + return r; + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + + s.declare (key ("LocalBiconnectedMerger") + .set_module ("MultilevelBuilder", this) + .documentation_in ("pgf.gd.doc.ogdf.energybased.multilevelmixer.LocalBiconnectedMerger")); + + s.declare (key ("LocalBiconnectedMerger.factor") + .type ("number") + .documentation_in ("pgf.gd.doc.ogdf.energybased.multilevelmixer.LocalBiconnectedMerger")); + + } + +}; diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/MatchingMerger_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/MatchingMerger_script.h new file mode 100644 index 00000000000..1d50c273cdb --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/MatchingMerger_script.h @@ -0,0 +1,32 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/energybased/multilevelmixer/MatchingMerger.h> + +struct MatchingMerger_script : + scripting::declarations, + scripting::factory<ogdf::MatchingMerger> +{ + ogdf::MatchingMerger* make (scripting::run_parameters* parameters) { + using namespace ogdf; + MatchingMerger* r = new MatchingMerger; + + parameters->configure_option ("MatchingMerger.selectByNodeMass", + &MatchingMerger::selectByNodeMass, *r); + + return r; + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + + s.declare (key ("MatchingMerger") + .set_module ("MultilevelBuilder", this) + .documentation_in ("pgf.gd.doc.ogdf.energybased.multilevelmixer.MatchingMerger")); + + s.declare (key ("MatchingMerger.selectByNodeMass") + .type ("boolean") + .documentation_in ("pgf.gd.doc.ogdf.energybased.multilevelmixer.MatchingMerger")); + + } + +}; diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/MedianPlacer_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/MedianPlacer_script.h new file mode 100644 index 00000000000..4670554393c --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/MedianPlacer_script.h @@ -0,0 +1,26 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/energybased/multilevelmixer/MedianPlacer.h> + +struct MedianPlacer_script : + scripting::declarations, + scripting::factory<ogdf::MedianPlacer> +{ + ogdf::MedianPlacer* make (scripting::run_parameters* parameters) { + using namespace ogdf; + MedianPlacer* r = new MedianPlacer; + + + return r; + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + + s.declare (key ("MedianPlacer") + .set_module ("InitialPlacer", this) + .documentation_in ("pgf.gd.doc.ogdf.energybased.multilevelmixer.MedianPlacer")); + + } + +}; diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/RandomMerger_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/RandomMerger_script.h new file mode 100644 index 00000000000..8acc53bbeff --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/RandomMerger_script.h @@ -0,0 +1,32 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/energybased/multilevelmixer/RandomMerger.h> + +struct RandomMerger_script : + scripting::declarations, + scripting::factory<ogdf::RandomMerger> +{ + ogdf::RandomMerger* make (scripting::run_parameters* parameters) { + using namespace ogdf; + RandomMerger* r = new RandomMerger; + + parameters->configure_option ("RandomMerger.factor", + &RandomMerger::setFactor, *r); + + return r; + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + + s.declare (key ("RandomMerger") + .set_module ("MultilevelBuilder", this) + .documentation_in ("pgf.gd.doc.ogdf.energybased.multilevelmixer.RandomMerger")); + + s.declare (key ("RandomMerger.factor") + .type ("number") + .documentation_in ("pgf.gd.doc.ogdf.energybased.multilevelmixer.RandomMerger")); + + } + +}; diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/RandomPlacer_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/RandomPlacer_script.h new file mode 100644 index 00000000000..a92873ff478 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/RandomPlacer_script.h @@ -0,0 +1,32 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/energybased/multilevelmixer/RandomPlacer.h> + +struct RandomPlacer_script : + scripting::declarations, + scripting::factory<ogdf::RandomPlacer> +{ + ogdf::RandomPlacer* make (scripting::run_parameters* parameters) { + using namespace ogdf; + RandomPlacer* r = new RandomPlacer; + + parameters->configure_option ("RandomPlacer.circleSize", + &RandomPlacer::setCircleSize, *r); + + return r; + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + + s.declare (key ("RandomPlacer") + .set_module ("InitialPlacer", this) + .documentation_in ("pgf.gd.doc.ogdf.energybased.multilevelmixer.RandomPlacer")); + + s.declare (key ("RandomPlacer.circleSize") + .type ("number") + .documentation_in ("pgf.gd.doc.ogdf.energybased.multilevelmixer.RandomPlacer")); + + } + +}; diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/SolarMerger_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/SolarMerger_script.h new file mode 100644 index 00000000000..8453241bd63 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/SolarMerger_script.h @@ -0,0 +1,36 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/energybased/multilevelmixer/SolarMerger.h> + +struct SolarMerger_script : + scripting::declarations, + scripting::factory<ogdf::SolarMerger> +{ + ogdf::SolarMerger* make (scripting::run_parameters* parameters) { + using namespace ogdf; + SolarMerger* r = new SolarMerger (parameters->option<bool>("SolarMerger.simple"), + parameters->option<bool>("SolarMerger.massAsNodeRadius")); + + return r; + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + + s.declare (key ("SolarMerger") + .set_module ("MultilevelBuilder", this) + .documentation_in ("pgf.gd.doc.ogdf.energybased.multilevelmixer.SolarMerger")); + + s.declare (key ("SolarMerger.simple") + .type ("boolean") + .initial ("false") + .documentation_in ("pgf.gd.doc.ogdf.energybased.multilevelmixer.SolarMerger")); + + s.declare (key ("SolarMerger.massAsNodeRadius") + .type ("boolean") + .initial ("false") + .documentation_in ("pgf.gd.doc.ogdf.energybased.multilevelmixer.SolarMerger")); + + } + +}; diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/SolarPlacer_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/SolarPlacer_script.h new file mode 100644 index 00000000000..5f9191251ce --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/SolarPlacer_script.h @@ -0,0 +1,26 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/energybased/multilevelmixer/SolarPlacer.h> + +struct SolarPlacer_script : + scripting::declarations, + scripting::factory<ogdf::SolarPlacer> +{ + ogdf::SolarPlacer* make (scripting::run_parameters* parameters) { + using namespace ogdf; + SolarPlacer* r = new SolarPlacer; + + + return r; + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + + s.declare (key ("SolarPlacer") + .set_module ("InitialPlacer", this) + .documentation_in ("pgf.gd.doc.ogdf.energybased.multilevelmixer.SolarPlacer")); + + } + +}; diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/ZeroPlacer_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/ZeroPlacer_script.h new file mode 100644 index 00000000000..255ac34bd8c --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/ZeroPlacer_script.h @@ -0,0 +1,32 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/energybased/multilevelmixer/ZeroPlacer.h> + +struct ZeroPlacer_script : + scripting::declarations, + scripting::factory<ogdf::ZeroPlacer> +{ + ogdf::ZeroPlacer* make (scripting::run_parameters* parameters) { + using namespace ogdf; + ZeroPlacer* r = new ZeroPlacer; + + parameters->configure_option ("ZeroPlacer.randomRange", + &ZeroPlacer::setRandomRange, *r); + + return r; + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + + s.declare (key ("ZeroPlacer") + .set_module ("InitialPlacer", this) + .documentation_in ("pgf.gd.doc.ogdf.energybased.multilevelmixer.ZeroPlacer")); + + s.declare (key ("ZeroPlacer.randomRange") + .type ("number") + .documentation_in ("pgf.gd.doc.ogdf.energybased.multilevelmixer.ZeroPlacer")); + + } + +}; diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/multilevelmixer_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/multilevelmixer_script.h new file mode 100644 index 00000000000..499406bc335 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/energybased/multilevelmixer/multilevelmixer_script.h @@ -0,0 +1,33 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> + +#include "BarycenterPlacer_script.h" +#include "IndependentSetMerger_script.h" +#include "MedianPlacer_script.h" +#include "SolarMerger_script.h" +#include "CirclePlacer_script.h" +#include "LocalBiconnectedMerger_script.h" +#include "RandomMerger_script.h" +#include "SolarPlacer_script.h" +#include "EdgeCoverMerger_script.h" +#include "MatchingMerger_script.h" +#include "RandomPlacer_script.h" +#include "ZeroPlacer_script.h" + +struct multilevelmixer_script : + scripting::declarations +{ + void declare (scripting::script s) { + s.declare (new BarycenterPlacer_script); + s.declare (new IndependentSetMerger_script); + s.declare (new MedianPlacer_script); + s.declare (new SolarMerger_script); + s.declare (new CirclePlacer_script); + s.declare (new LocalBiconnectedMerger_script); + s.declare (new RandomMerger_script); + s.declare (new SolarPlacer_script); + s.declare (new EdgeCoverMerger_script); + s.declare (new MatchingMerger_script); + s.declare (new RandomPlacer_script); + s.declare (new ZeroPlacer_script); + } +}; diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/BarycenterHeuristic_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/BarycenterHeuristic_script.h new file mode 100644 index 00000000000..709e91d3de4 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/BarycenterHeuristic_script.h @@ -0,0 +1,20 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/layered/BarycenterHeuristic.h> + +struct BarycenterHeuristic_script : + scripting::declarations, + scripting::factory<ogdf::BarycenterHeuristic> +{ + + ogdf::BarycenterHeuristic* make (scripting::run_parameters* parameters) { + return new ogdf::BarycenterHeuristic; + } + + void declare (scripting::script s) { + using namespace scripting; + s.declare (key ("BarycenterHeuristic") + .documentation_in ("pgf.gd.doc.ogdf.layered.BarycenterHeuristic") + .set_module ("TwoLayerCrossMin", this)); + } +}; + diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/CoffmanGrahamRanking_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/CoffmanGrahamRanking_script.h new file mode 100644 index 00000000000..d8cb01a771d --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/CoffmanGrahamRanking_script.h @@ -0,0 +1,34 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/layered/CoffmanGrahamRanking.h> + +struct CoffmanGrahamRanking_script : + scripting::declarations, + scripting::factory<ogdf::CoffmanGrahamRanking> +{ + + ogdf::CoffmanGrahamRanking* make (scripting::run_parameters* parameters) { + using namespace ogdf; + CoffmanGrahamRanking* r = new CoffmanGrahamRanking; + + parameters->configure_option ("CoffmanGrahamRanking.width", + &CoffmanGrahamRanking::width, *r); + parameters->configure_module ("AcyclicSubgraphModule", + &CoffmanGrahamRanking::setSubgraph, *r); + + return r; + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + s.declare (key ("CoffmanGrahamRanking") + .documentation_in ("pgf.gd.doc.ogdf.layered.CoffmanGrahamRanking") + .set_module ("RankingModule", this)); + + s.declare (key ("CoffmanGrahamRanking.width") + .type ("number") + .initial ("3") + .documentation_in ("pgf.gd.doc.ogdf.layered.CoffmanGrahamRanking")); + } +}; + diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/DfsAcyclicSubgraph_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/DfsAcyclicSubgraph_script.h new file mode 100644 index 00000000000..0d784ff3f5b --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/DfsAcyclicSubgraph_script.h @@ -0,0 +1,20 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/layered/DfsAcyclicSubgraph.h> + +struct DfsAcyclicSubgraph_script : + scripting::declarations, + scripting::factory<ogdf::DfsAcyclicSubgraph> +{ + + ogdf::DfsAcyclicSubgraph* make (scripting::run_parameters* parameters) { + return new ogdf::DfsAcyclicSubgraph; + } + + void declare (scripting::script s) { + using namespace scripting; + s.declare (key ("DfsAcyclicSubgraph") + .documentation_in ("pgf.gd.doc.ogdf.layered.DfsAcyclicSubgraph") + .set_module ("AcyclicSubgraphModule", this)); + } +}; + diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/FastHierarchyLayout_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/FastHierarchyLayout_script.h new file mode 100644 index 00000000000..c8063e063af --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/FastHierarchyLayout_script.h @@ -0,0 +1,48 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/layered/FastHierarchyLayout.h> + +struct FastHierarchyLayout_script : + scripting::declarations, + scripting::factory<ogdf::FastHierarchyLayout> +{ + + ogdf::FastHierarchyLayout* make (scripting::run_parameters* parameters) { + using namespace ogdf; + FastHierarchyLayout* r = new FastHierarchyLayout; + + parameters->configure_option ("FastHierarchyLayout.fixedLayerDistance", + &FastHierarchyLayout::fixedLayerDistance, *r); + parameters->configure_option ("FastHierarchyLayout.layerDistance", + &FastHierarchyLayout::layerDistance, *r); + parameters->configure_option ("FastHierarchyLayout.nodeDistance", + &FastHierarchyLayout::nodeDistance, *r); + + return r; + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + + s.declare (key ("FastHierarchyLayout") + .documentation_in ("pgf.gd.doc.ogdf.layered.FastHierarchyLayout") + .set_module ("HierarchyLayoutModule", this)); + + s.declare (key ("FastHierarchyLayout.fixedLayerDistance") + .type ("boolean") + .initial ("false") + .documentation_in ("pgf.gd.doc.ogdf.layered.FastHierarchyLayout")); + + s.declare (key ("FastHierarchyLayout.layerDistance") + .type ("length") + .alias_function ("function (o) return o['level pre sep'] + o['level post sep'] end") + .documentation_in ("pgf.gd.doc.ogdf.layered.FastHierarchyLayout")); + + s.declare (key ("FastHierarchyLayout.nodeDistance") + .type ("length") + .alias_function ("function (o) return o['sibling pre sep'] + o['sibling post sep'] end") + .documentation_in ("pgf.gd.doc.ogdf.layered.FastHierarchyLayout")); + } +}; + + diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/FastSimpleHierarchyLayout_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/FastSimpleHierarchyLayout_script.h new file mode 100644 index 00000000000..37c6c94bc05 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/FastSimpleHierarchyLayout_script.h @@ -0,0 +1,41 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/layered/FastSimpleHierarchyLayout.h> + +struct FastSimpleHierarchyLayout_script : + scripting::declarations, + scripting::factory<ogdf::FastSimpleHierarchyLayout> +{ + + ogdf::FastSimpleHierarchyLayout* make (scripting::run_parameters* parameters) { + using namespace ogdf; + + FastSimpleHierarchyLayout* r = new FastSimpleHierarchyLayout + ( + parameters->option<int> ("FastSimpleHierarchyLayout.siblingDistance"), + parameters->option<int> ("FastSimpleHierarchyLayout.layerDistance") + ); + + return r; + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + + s.declare (key ("FastSimpleHierarchyLayout") + .documentation_in ("pgf.gd.doc.ogdf.layered.FastSimpleHierarchyLayout") + .set_module ("HierarchyLayoutModule", this)); + + s.declare (key ("FastSimpleHierarchyLayout.layerDistance") + .type ("length") + .alias ("level distance") + .documentation_in ("pgf.gd.doc.ogdf.layered.FastSimpleHierarchyLayout")); + + s.declare (key ("FastSimpleHierarchyLayout.siblingDistance") + .type ("length") + .alias ("sibling distance") + .documentation_in ("pgf.gd.doc.ogdf.layered.FastSimpleHierarchyLayout")); + } +}; + + diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/GreedyCycleRemoval_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/GreedyCycleRemoval_script.h new file mode 100644 index 00000000000..74616981414 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/GreedyCycleRemoval_script.h @@ -0,0 +1,20 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/layered/GreedyCycleRemoval.h> + +struct GreedyCycleRemoval_script : + scripting::declarations, + scripting::factory<ogdf::GreedyCycleRemoval> +{ + + ogdf::GreedyCycleRemoval* make (scripting::run_parameters* parameters) { + return new ogdf::GreedyCycleRemoval; + } + + void declare (scripting::script s) { + using namespace scripting; + s.declare (key ("GreedyCycleRemoval") + .documentation_in ("pgf.gd.doc.ogdf.layered.GreedyCycleRemoval") + .set_module ("AcyclicSubgraphModule", this)); + } +}; + diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/GreedyInsertHeuristic_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/GreedyInsertHeuristic_script.h new file mode 100644 index 00000000000..4ab2675b5aa --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/GreedyInsertHeuristic_script.h @@ -0,0 +1,20 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/layered/GreedyInsertHeuristic.h> + +struct GreedyInsertHeuristic_script : + scripting::declarations, + scripting::factory<ogdf::GreedyInsertHeuristic> +{ + + ogdf::GreedyInsertHeuristic* make (scripting::run_parameters* parameters) { + return new ogdf::GreedyInsertHeuristic; + } + + void declare (scripting::script s) { + using namespace scripting; + s.declare (key ("GreedyInsertHeuristic") + .documentation_in ("pgf.gd.doc.ogdf.layered.GreedyInsertHeuristic") + .set_module ("TwoLayerCrossMin", this)); + } +}; + diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/LongestPathRanking_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/LongestPathRanking_script.h new file mode 100644 index 00000000000..ca2e6344850 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/LongestPathRanking_script.h @@ -0,0 +1,50 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/layered/LongestPathRanking.h> + +struct LongestPathRanking_script : + scripting::declarations, + scripting::factory<ogdf::LongestPathRanking> +{ + + ogdf::LongestPathRanking* make (scripting::run_parameters* parameters) { + using namespace ogdf; + LongestPathRanking* r = new LongestPathRanking; + + parameters->configure_option ("LongestPathRanking.separateDeg0Layer", + &LongestPathRanking::separateDeg0Layer, *r); + parameters->configure_option ("LongestPathRanking.separateMultiEdges", + &LongestPathRanking::separateMultiEdges, *r); + parameters->configure_option ("LongestPathRanking.optimizeEdgeLength", + &LongestPathRanking::optimizeEdgeLength, *r); + + parameters->configure_module ("AcyclicSubgraphModule", + &LongestPathRanking::setSubgraph, *r); + + return r; + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + s.declare (key ("LongestPathRanking") + .documentation_in ("pgf.gd.doc.ogdf.layered.LongestPathRanking") + .set_module ("RankingModule", this)); + + s.declare (key ("LongestPathRanking.separateDeg0Layer") + .type ("boolean") + .initial ("true") + .documentation_in ("pgf.gd.doc.ogdf.layered.LongestPathRanking")); + + s.declare (key ("LongestPathRanking.separateMultiEdges") + .type ("boolean") + .initial ("true") + .documentation_in ("pgf.gd.doc.ogdf.layered.LongestPathRanking")); + + s.declare (key ("LongestPathRanking.optimizeEdgeLength") + .type ("boolean") + .initial ("true") + .documentation_in ("pgf.gd.doc.ogdf.layered.LongestPathRanking")); + } +}; + + diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/MedianHeuristic_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/MedianHeuristic_script.h new file mode 100644 index 00000000000..8ce4a610e7d --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/MedianHeuristic_script.h @@ -0,0 +1,20 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/layered/MedianHeuristic.h> + +struct MedianHeuristic_script : + scripting::declarations, + scripting::factory<ogdf::MedianHeuristic> +{ + + ogdf::MedianHeuristic* make (scripting::run_parameters* parameters) { + return new ogdf::MedianHeuristic; + } + + void declare (scripting::script s) { + using namespace scripting; + s.declare (key ("MedianHeuristic") + .documentation_in ("pgf.gd.doc.ogdf.layered.MedianHeuristic") + .set_module ("TwoLayerCrossMin", this)); + } +}; + diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/OptimalRanking_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/OptimalRanking_script.h new file mode 100644 index 00000000000..f35fc67da79 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/OptimalRanking_script.h @@ -0,0 +1,34 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/layered/OptimalRanking.h> + +struct OptimalRanking_script : + scripting::declarations, + scripting::factory<ogdf::OptimalRanking> +{ + + ogdf::OptimalRanking* make (scripting::run_parameters* parameters) { + using namespace ogdf; + OptimalRanking* r = new OptimalRanking; + + parameters->configure_option ("OptimalRanking.separateMultiEdges", + &OptimalRanking::separateMultiEdges, *r); + parameters->configure_module ("AcyclicSubgraphModule", + &OptimalRanking::setSubgraph, *r); + + return r; + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + s.declare (key ("OptimalRanking") + .documentation_in ("pgf.gd.doc.ogdf.layered.OptimalRanking") + .set_module ("RankingModule", this)); + + s.declare (key ("OptimalRanking.separateMultiEdges") + .type ("boolean") + .initial ("true") + .documentation_in ("pgf.gd.doc.ogdf.layered.OptimalRanking")); + } +}; + diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/SiftingHeuristic_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/SiftingHeuristic_script.h new file mode 100644 index 00000000000..653432f52b5 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/SiftingHeuristic_script.h @@ -0,0 +1,40 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/layered/SiftingHeuristic.h> + +struct SiftingHeuristic_script : + scripting::declarations, + scripting::factory<ogdf::SiftingHeuristic> +{ + + ogdf::SiftingHeuristic* make (scripting::run_parameters* parameters) { + using namespace ogdf; + + SiftingHeuristic* h = new SiftingHeuristic; + + char* strategy = 0; + + if (parameters->option("SiftingHeuristic.strategy", strategy)) { + if (strcmp(strategy, "left_to_right") == 0) + h->strategy(SiftingHeuristic::left_to_right); + else if (strcmp(strategy, "desc_degree") == 0) + h->strategy(SiftingHeuristic::desc_degree); + else if (strcmp(strategy, "random") == 0) + h->strategy(SiftingHeuristic::random); + + free(strategy); + } + return h; + } + + void declare (scripting::script s) { + using namespace scripting; + s.declare (key ("SiftingHeuristic") + .documentation_in ("pgf.gd.doc.ogdf.layered.SiftingHeuristic") + .set_module ("TwoLayerCrossMin", this)); + + s.declare (key ("SiftingHeuristic.strategy") + .type ("string") + .documentation_in ("pgf.gd.doc.ogdf.layered.SiftingHeuristic")); + } +}; + diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/SplitHeuristic_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/SplitHeuristic_script.h new file mode 100644 index 00000000000..6799be36e92 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/SplitHeuristic_script.h @@ -0,0 +1,20 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/layered/SplitHeuristic.h> + +struct SplitHeuristic_script : + scripting::declarations, + scripting::factory<ogdf::SplitHeuristic> +{ + + ogdf::SplitHeuristic* make (scripting::run_parameters* parameters) { + return new ogdf::SplitHeuristic; + } + + void declare (scripting::script s) { + using namespace scripting; + s.declare (key ("SplitHeuristic") + .documentation_in ("pgf.gd.doc.ogdf.layered.SplitHeuristic") + .set_module ("TwoLayerCrossMin", this)); + } +}; + diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/SugiyamaLayout_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/SugiyamaLayout_script.h new file mode 100644 index 00000000000..c9cf0973732 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/SugiyamaLayout_script.h @@ -0,0 +1,54 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/layered/SugiyamaLayout.h> + +struct SugiyamaLayout_script : + scripting::declarations, + scripting::ogdf_runner +{ + void run () { + using namespace ogdf; + SugiyamaLayout layout; + + parameters->configure_option ("SugiyamaLayout.runs", + &SugiyamaLayout::runs, layout); + parameters->configure_option ("SugiyamaLayout.transpose", + &SugiyamaLayout::transpose, layout); + parameters->configure_option ("SugiyamaLayout.fails", + &SugiyamaLayout::fails, layout); + + parameters->configure_module ("RankingModule", + &SugiyamaLayout::setRanking, layout); + parameters->configure_module ("TwoLayerCrossMin", + &SugiyamaLayout::setCrossMin, layout); + parameters->configure_module ("HierarchyLayoutModule", + &SugiyamaLayout::setLayout, layout); + + layout.call (graph_attributes); + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + s.declare (key ("SugiyamaLayout") + .precondition ("connected") + .postcondition ("upward_oriented_swapped") + .algorithm (this) + .documentation_in ("pgf.gd.doc.ogdf.layered.SugiyamaLayout")); + + s.declare (key ("SugiyamaLayout.runs") + .type ("number") + .initial ("15") + .documentation_in ("pgf.gd.doc.ogdf.layered.SugiyamaLayout")); + + s.declare (key ("SugiyamaLayout.transpose") + .type ("boolean") + .initial ("true") + .documentation_in ("pgf.gd.doc.ogdf.layered.SugiyamaLayout")); + + s.declare (key ("SugiyamaLayout.fails") + .type ("number") + .initial ("4") + .documentation_in ("pgf.gd.doc.ogdf.layered.SugiyamaLayout")); + } + +}; diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/layered_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/layered_script.h new file mode 100644 index 00000000000..8a117f1fc6f --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/layered/layered_script.h @@ -0,0 +1,46 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> + +#include "SugiyamaLayout_script.h" + +#include "LongestPathRanking_script.h" +#include "OptimalRanking_script.h" +#include "CoffmanGrahamRanking_script.h" + +#include "DfsAcyclicSubgraph_script.h" +#include "GreedyCycleRemoval_script.h" + +#include "BarycenterHeuristic_script.h" +#include "GreedyInsertHeuristic_script.h" +#include "SiftingHeuristic_script.h" +#include "MedianHeuristic_script.h" +#include "SplitHeuristic_script.h" + +#include "FastHierarchyLayout_script.h" +#include "FastSimpleHierarchyLayout_script.h" + +struct layered_script : + scripting::declarations +{ + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + + s.declare (new SugiyamaLayout_script); + + s.declare (new LongestPathRanking_script); + s.declare (new OptimalRanking_script); + s.declare (new CoffmanGrahamRanking_script); + + s.declare (new DfsAcyclicSubgraph_script); + s.declare (new GreedyCycleRemoval_script); + + s.declare (new BarycenterHeuristic_script); + s.declare (new GreedyInsertHeuristic_script); + s.declare (new SiftingHeuristic_script); + s.declare (new MedianHeuristic_script); + s.declare (new SplitHeuristic_script); + + s.declare (new FastHierarchyLayout_script); + s.declare (new FastSimpleHierarchyLayout_script); + } +}; diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/misclayout/BalloonLayout_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/misclayout/BalloonLayout_script.h new file mode 100644 index 00000000000..311bee3e092 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/misclayout/BalloonLayout_script.h @@ -0,0 +1,32 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/misclayout/BalloonLayout.h> + +struct BalloonLayout_script : + scripting::declarations, + scripting::ogdf_runner +{ + void run () { + using namespace ogdf; + BalloonLayout layout; + + parameters->configure_option ("BalloonLayout.evenAngles", + &BalloonLayout::setEvenAngles, layout); + + layout.call (graph_attributes); + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + + s.declare (key ("BalloonLayout") + .precondition ("connected") + .algorithm (this) + .documentation_in ("pgf.gd.doc.ogdf.misclayout.BalloonLayout")); + + s.declare (key ("BalloonLayout.evenAngles") + .type ("boolean") + .documentation_in ("pgf.gd.doc.ogdf.misclayout.BalloonLayout")); + } +}; + diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/misclayout/CircularLayout_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/misclayout/CircularLayout_script.h new file mode 100644 index 00000000000..d0840e64f6b --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/misclayout/CircularLayout_script.h @@ -0,0 +1,47 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/misclayout/CircularLayout.h> + +struct CircularLayout_script : + scripting::declarations, + scripting::ogdf_runner +{ + void run () { + using namespace ogdf; + CircularLayout layout; + + parameters->configure_option ("CircularLayout.minDistCircle", + &CircularLayout::minDistCircle, layout); + parameters->configure_option ("CircularLayout.minDistLevel", + &CircularLayout::minDistLevel, layout); + parameters->configure_option ("CircularLayout.minDistSibling", + &CircularLayout::minDistSibling, layout); + + layout.call (graph_attributes); + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + + s.declare (key ("CircularLayout") + .precondition ("connected") + .algorithm (this) + .documentation_in ("pgf.gd.doc.ogdf.misclayout.CircularLayout")); + + s.declare (key ("CircularLayout.minDistCircle") + .type ("length") + .alias_function ("function (o) return o['part pre sep'] + o['part post sep'] end") + .documentation_in ("pgf.gd.doc.ogdf.layered.CircularLayout")); + + s.declare (key ("CircularLayout.minDistLevel") + .type ("length") + .alias_function ("function (o) return o['level pre sep'] + o['level post sep'] end") + .documentation_in ("pgf.gd.doc.ogdf.layered.CircularLayout")); + + s.declare (key ("CircularLayout.minDistSibling") + .type ("length") + .alias_function ("function (o) return o['sibling pre sep'] + o['sibling post sep'] end") + .documentation_in ("pgf.gd.doc.ogdf.layered.CircularLayout")); + } +}; + diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/misclayout/misclayout_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/misclayout/misclayout_script.h new file mode 100644 index 00000000000..22ac039b7f3 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/misclayout/misclayout_script.h @@ -0,0 +1,13 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> + +#include "BalloonLayout_script.h" +#include "CircularLayout_script.h" + +struct misclayout_script : + scripting::declarations +{ + void declare (scripting::script s) { + s.declare (new BalloonLayout_script); + s.declare (new CircularLayout_script); + } +}; diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/module/module_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/module/module_script.h new file mode 100644 index 00000000000..97579ecdd92 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/module/module_script.h @@ -0,0 +1,27 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> + +struct module_script : scripting::declarations { + void declare (scripting::script s) + { + using namespace scripting; + + s.declare (key ("RankingModule") + .module_type ()); + + s.declare (key ("AcyclicSubgraphModule") + .module_type ()); + + s.declare (key ("HierarchyLayoutModule") + .module_type ()); + + s.declare (key ("TwoLayerCrossMin") + .module_type ()); + + s.declare (key ("InitialPlacer") + .module_type ()); + + s.declare (key ("MultilevelBuilder") + .module_type ()); + } +}; + diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/ogdf_script.c++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/ogdf_script.c++ new file mode 100644 index 00000000000..12a5f6bfeb0 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/ogdf_script.c++ @@ -0,0 +1,23 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> + +#include "module/module_script.h" + +#include "layered/layered_script.h" +#include "energybased/energybased_script.h" +#include "misclayout/misclayout_script.h" +#include "planarity/planarity_script.h" + + +extern "C" int luaopen_pgf_gd_ogdf_c_ogdf_script (struct lua_State *state) { + + scripting::script s (state); + + s.declare (new module_script); + s.declare (new layered_script); + s.declare (new energybased_script); + s.declare (new misclayout_script); + s.declare (new planarity_script); + + return 0; +} + diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/planarity/PlanarizationLayout_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/planarity/PlanarizationLayout_script.h new file mode 100644 index 00000000000..4fa89d5d190 --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/planarity/PlanarizationLayout_script.h @@ -0,0 +1,43 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> +#include <ogdf/planarity/PlanarizationLayout.h> + +struct PlanarizationLayout_script : + scripting::declarations, + scripting::ogdf_runner +{ + + void run () { + using namespace ogdf; + PlanarizationLayout layout; + + parameters->configure_option ("PlanarizationLayout.preprocessCliques", + &PlanarizationLayout::preprocessCliques, layout); + parameters->configure_option ("PlanarizationLayout.minCliqueSize", + &PlanarizationLayout::minCliqueSize, layout); + + // .. TODO: configure modules + + layout.call (graph_attributes); + } + + void declare (scripting::script s) { + using namespace scripting; + using namespace ogdf; + s.declare (key ("PlanarizationLayout") + .precondition ("connected") + .postcondition ("fixed") + .algorithm (this) + .documentation_in ("pgf.gd.doc.ogdf.planarity.PlanarizationLayout")); + + s.declare (key ("PlanarizationLayout.preprocessCliques") + .type ("boolean") + .initial ("false") + .documentation_in ("pgf.gd.doc.ogdf.planarity.PlanarizationLayout")); + + s.declare (key ("PlanarizationLayout.minCliqueSize") + .type ("number") + .initial ("10") + .documentation_in ("pgf.gd.doc.ogdf.planarity.PlanarizationLayout")); + } + +}; diff --git a/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/planarity/planarity_script.h b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/planarity/planarity_script.h new file mode 100644 index 00000000000..dd337fcc0ee --- /dev/null +++ b/Master/texmf-dist/source/generic/pgf/c/graphdrawing/pgf/gd/ogdf/c/planarity/planarity_script.h @@ -0,0 +1,11 @@ +#include <pgf/gd/ogdf/c/InterfaceFromOGDF.h> + +#include "PlanarizationLayout_script.h" + +struct planarity_script : + scripting::declarations +{ + void declare (scripting::script s) { + s.declare (new PlanarizationLayout_script); + } +}; |