Graphviz 12.0.1~dev.20240715.2254
Loading...
Searching...
No Matches
gvlayout.c
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11/*
12 * layout engine wrapper
13 *
14 */
15
16#include "config.h"
17
18#include <common/const.h>
19#include <gvc/gvplugin_layout.h>
20#include <gvc/gvcint.h>
21#include <cgraph/cgraph.h>
22#include <gvc/gvcproc.h>
23#include <gvc/gvc.h>
24#include <stdbool.h>
25#include <stddef.h>
26
27extern void graph_init(Agraph_t *g, bool use_rankdir);
28extern void graph_cleanup(Agraph_t *g);
29extern void gv_fixLocale (int set);
30
31int gvlayout_select(GVC_t * gvc, const char *layout)
32{
34 gvplugin_installed_t *typeptr;
35
36 plugin = gvplugin_load(gvc, API_layout, layout, NULL);
37 if (plugin) {
38 typeptr = plugin->typeptr;
39 gvc->layout.type = typeptr->type;
40 gvc->layout.engine = typeptr->engine;
41 gvc->layout.id = typeptr->id;
42 gvc->layout.features = typeptr->features;
43 return GVRENDER_PLUGIN; /* FIXME - need better return code */
44 }
45 return NO_SUPPORT;
46}
47
48/* gvLayoutJobs:
49 * Layout input graph g based on layout engine attached to gvc.
50 * Check that the root graph has been initialized. If not, initialize it.
51 * Return 0 on success.
52 */
54{
56 char *p;
57 int rc;
58
59 agbindrec(g, "Agraphinfo_t", sizeof(Agraphinfo_t), true);
60 GD_gvc(g) = gvc;
61 if (g != agroot(g)) {
62 agbindrec(agroot(g), "Agraphinfo_t", sizeof(Agraphinfo_t), true);
63 GD_gvc(agroot(g)) = gvc;
64 }
65
66 if ((p = agget(g, "layout"))) {
68 rc = gvlayout_select(gvc, p);
69 if (rc == NO_SUPPORT) {
70 agerrorf("Layout type: \"%s\" not recognized. Use one of:%s\n",
71 p, gvplugin_list(gvc, API_layout, p));
72 return -1;
73 }
74 }
75
76 gvle = gvc->layout.engine;
77 if (! gvle)
78 return -1;
79
80 gv_fixLocale (1);
83 if (gvle && gvle->layout) {
84 gvle->layout(g);
85
86
87 if (gvle->cleanup)
88 GD_cleanup(g) = gvle->cleanup;
89 }
90 gv_fixLocale (0);
91 return 0;
92}
93
95{
96 return LAYOUT_DONE(g);
97}
98
99/* gvFreeLayout:
100 * Free layout resources.
101 * First, if the graph has a layout-specific cleanup function attached,
102 * use it and reset.
103 * Then do the general graph cleanup.
104 */
106{
107 (void)gvc;
108
109 /* skip if no Agraphinfo_t yet */
110 if (! agbindrec(g, "Agraphinfo_t", 0, true))
111 return 0;
112
113 if (GD_cleanup(g)) {
114 (GD_cleanup(g))(g);
115 GD_cleanup(g) = NULL;
116 }
117
118 graph_cleanup(g);
119 return 0;
120}
abstract graph C library, Cgraph API
#define NO_SUPPORT
Definition const.h:147
#define GVRENDER_PLUGIN
Definition const.h:146
node NULL
Definition grammar.y:149
char * agget(void *obj, char *name)
Definition attr.c:442
void agerrorf(const char *fmt,...)
Definition agerror.c:165
#define GD_drawing(g)
Definition types.h:353
#define GD_cleanup(g)
Definition types.h:356
#define GD_gvc(g)
Definition types.h:355
Agraph_t * agroot(void *obj)
Definition obj.c:167
void * agbindrec(void *obj, const char *name, unsigned int recsize, int move_to_front)
attaches a new record of the given size to the object
Definition rec.c:88
bool gvLayoutDone(Agraph_t *g)
Definition gvlayout.c:94
#define LAYOUT_DONE(g)
Definition gvc.h:51
int gvFreeLayout(GVC_t *gvc, Agraph_t *g)
Definition gvlayout.c:105
int gvLayoutJobs(GVC_t *gvc, Agraph_t *g)
Definition gvlayout.c:53
Graphviz context library.
#define LAYOUT_USES_RANKDIR
Definition gvcjob.h:125
gvplugin_available_t * gvplugin_load(GVC_t *gvc, api_t api, const char *type, FILE *debug)
Definition gvplugin.c:250
char * gvplugin_list(GVC_t *gvc, api_t api, const char *str)
Definition gvplugin.c:356
void gv_fixLocale(int set)
Definition emit.c:3888
void graph_cleanup(Agraph_t *g)
Definition input.c:797
int gvlayout_select(GVC_t *gvc, const char *layout)
Definition gvlayout.c:31
void graph_init(Agraph_t *g, bool use_rankdir)
Definition input.c:596
GVC_t * gvc
Definition htmlparse.c:99
static int layout(graph_t *g, layout_info *infop)
Definition layout.c:809
graph or subgraph
Definition cgraph.h:425
Definition gvcint.h:80
gvplugin_active_layout_t layout
Definition gvcint.h:120
void(* cleanup)(graph_t *g)
void(* layout)(graph_t *g)
const char * type
Definition gvcint.h:42
gvlayout_features_t * features
Definition gvcint.h:41
gvlayout_engine_t * engine
Definition gvcint.h:39
gvplugin_installed_t * typeptr
Definition gvcint.h:65
ingroup plugin_api
Definition gvplugin.h:35
const char * type
Definition gvplugin.h:41