00001 /* $Id: gvlayout.c,v 1.25 2006/12/07 22:49:36 erg Exp $ $Revision: 1.25 $ */ 00002 /* vim:set shiftwidth=4 ts=8: */ 00003 00004 /********************************************************** 00005 * This software is part of the graphviz package * 00006 * http://www.graphviz.org/ * 00007 * * 00008 * Copyright (c) 1994-2004 AT&T Corp. * 00009 * and is licensed under the * 00010 * Common Public License, Version 1.0 * 00011 * by AT&T Corp. * 00012 * * 00013 * Information and Software Systems Research * 00014 * AT&T Research, Florham Park NJ * 00015 **********************************************************/ 00016 00017 /* 00018 * layout engine wrapper 00019 * 00020 */ 00021 00022 #ifdef HAVE_CONFIG_H 00023 #include "config.h" 00024 #endif 00025 00026 #include "const.h" 00027 #include "gvplugin_layout.h" 00028 #include "gvcint.h" 00029 #include "graph.h" 00030 #include "gvcproc.h" 00031 00032 extern void graph_init(graph_t *g, boolean use_rankdir); 00033 extern void graph_cleanup(graph_t *g); 00034 00035 int gvlayout_select(GVC_t * gvc, char *layout) 00036 { 00037 gvplugin_available_t *plugin; 00038 gvplugin_installed_t *typeptr; 00039 00040 plugin = gvplugin_load(gvc, API_layout, layout); 00041 if (plugin) { 00042 typeptr = plugin->typeptr; 00043 gvc->layout.type = typeptr->type; 00044 gvc->layout.engine = (gvlayout_engine_t *) (typeptr->engine); 00045 gvc->layout.id = typeptr->id; 00046 gvc->layout.features = (gvlayout_features_t *) (typeptr->features); 00047 return GVRENDER_PLUGIN; /* FIXME - need better return code */ 00048 } 00049 return NO_SUPPORT; 00050 } 00051 00052 /* gvLayoutJobs: 00053 * Layout input graph g based on layout engine attached to gvc. 00054 * Check that the root graph has been initialized. If not, initialize it. 00055 * Return 0 on success. 00056 */ 00057 int gvLayoutJobs(GVC_t * gvc, graph_t * g) 00058 { 00059 gvlayout_engine_t *gvle = gvc->layout.engine; 00060 00061 if (! gvle) 00062 return -1; 00063 00064 GD_gvc(g) = gvc; 00065 if (g != g->root) GD_gvc(g->root) = gvc; 00066 graph_init(g, gvc->layout.features->flags & LAYOUT_USES_RANKDIR); 00067 GD_drawing(g->root) = GD_drawing(g); 00068 if (gvle && gvle->layout) { 00069 gvle->layout(g); 00070 if (gvle->cleanup) 00071 GD_cleanup(g) = gvle->cleanup; 00072 } 00073 return 0; 00074 } 00075 00076 /* gvFreeLayout: 00077 * Free layout resources. 00078 * First, if the graph has a layout-specific cleanup function attached, 00079 * use it and reset. 00080 * Then, if the root graph has not been cleaned up, clean it up and reset. 00081 * Only the root graph has GD_drawing non-null. 00082 */ 00083 int gvFreeLayout(GVC_t * gvc, graph_t * g) 00084 { 00085 if (GD_cleanup(g)) { 00086 (GD_cleanup(g))(g); 00087 GD_cleanup(g) = NULL; 00088 } 00089 00090 if (GD_drawing(g)) { 00091 graph_cleanup(g); 00092 GD_drawing(g) = NULL; 00093 GD_drawing(g->root) = NULL; 00094 } 00095 return 0; 00096 }