Graphviz  2.29.20120524.0446
lib/gvc/gvcjob.h
Go to the documentation of this file.
00001 /* $Id$ $Revision$ */
00002 /* vim:set shiftwidth=4 ts=8: */
00003 
00004 /*************************************************************************
00005  * Copyright (c) 2011 AT&T Intellectual Property 
00006  * All rights reserved. This program and the accompanying materials
00007  * are made available under the terms of the Eclipse Public License v1.0
00008  * which accompanies this distribution, and is available at
00009  * http://www.eclipse.org/legal/epl-v10.html
00010  *
00011  * Contributors: See CVS logs. Details at http://www.graphviz.org/
00012  *************************************************************************/
00013 
00014 /* Common header used by both clients and plugins */
00015 
00016 #ifndef GVCJOB_H
00017 #define GVCJOB_H
00018 
00019 #ifdef __cplusplus
00020 extern "C" {
00021 #endif
00022 
00023 #include "gvcommon.h"
00024 #include "color.h"
00025 
00026 #define ARRAY_SIZE(A) (sizeof(A)/sizeof(A[0]))
00027 
00028     typedef struct gvdevice_engine_s gvdevice_engine_t;
00029     typedef struct gvformatter_engine_s gvformatter_engine_t;
00030     typedef struct gvrender_engine_s gvrender_engine_t;
00031     typedef struct gvlayout_engine_s gvlayout_engine_t;
00032     typedef struct gvtextlayout_engine_s gvtextlayout_engine_t;
00033     typedef struct gvloadimage_engine_s gvloadimage_engine_t;
00034 
00035     typedef enum { PEN_NONE, PEN_DASHED, PEN_DOTTED, PEN_SOLID } pen_type;
00036     typedef enum { FILL_NONE, FILL_SOLID, FILL_LINEAR, FILL_RADIAL } fill_type;
00037     typedef enum { FONT_REGULAR, FONT_BOLD, FONT_ITALIC } font_type;
00038     typedef enum { LABEL_PLAIN, LABEL_HTML } label_type;
00039 
00040 #define PENWIDTH_NORMAL 1.
00041 #define PENWIDTH_BOLD 2.
00042     typedef enum { GVATTR_STRING, GVATTR_BOOL, GVATTR_COLOR } gvattr_t;
00043 
00044 /* The -T output formats listed below are examples only, they are not definitive or inclusive,
00045  other outputs may use the flags now, or in the future 
00046 
00047                    Default emit order is breadth first graph walk order 
00048  EMIT_SORTED                    emits nodes before edges                
00049  EMIT_COLORS                    emits colors before nodes or edge -Tfig 
00050  EMIT_CLUSTERS_LAST             emits cluster after nodes and edges     
00051  EMIT_PREORDER                  emit in preorder traversal ???          
00052  EMIT_EDGE_SORTED               emits edges before nodes                
00053 
00054  GVDEVICE_DOES_PAGES            provides pagination support -Tps        
00055  GVDEVICE_DOES_LAYERS           provides support for layers -Tps        
00056  GVDEVICE_EVENTS                supports mouse events -Tgtk, -Txlib     
00057  GVDEVICE_DOES_TRUECOLOR        supports alpha channel -Tpng, -Tgtk, -Txlib 
00058  GVDEVICE_BINARY_FORMAT         Suppresses \r\n substitution for linends 
00059  GVDEVICE_COMPRESSED_FORMAT     controls libz compression               
00060  GVDEVICE_NO_WRITER             used when gvdevice is not used because device uses its own writer, -Tming, devil outputs   (FIXME seems to overlap OUTPUT_NOT_REQUIRED)
00061 
00062  GVRENDER_Y_GOES_DOWN           device origin top left, y goes down, otherwise
00063                                 device origin lower left, y goes up     
00064  GVRENDER_DOES_TRANSFORM        device uses scale, translate, rotate to do its own
00065                                 coordinate transformations, otherwise coordinates 
00066                                 are pre-transformed                     
00067  GVRENDER_DOES_ARROWS           renderer has its own idea of arrow shapes (deprecated) 
00068  GVRENDER_DOES_LABELS           basically, maps don't need labels       
00069  GVRENDER_DOES_MAPS             renderer encodes mapping information for mouse events -Tcmapx -Tsvg 
00070  GVRENDER_DOES_MAP_RECTANGLE    supports a 2 coord rectngle optimization 
00071  GVRENDER_DOES_MAP_CIRCLE       supports a 1 coord + radius circle optimization 
00072  GVRENDER_DOES_MAP_POLYGON      supports polygons (basically, -Tsvg uses anchors, so doesn't need to support any map shapes) 
00073  GVRENDER_DOES_MAP_ELLIPSE      supports a 2 coord ellipse optimization 
00074  GVRENDER_DOES_MAP_BSPLINE      supports mapping of splines             
00075  GVRENDER_DOES_TOOLTIPS         can represent tooltip info -Tcmapx, -Tsvg               
00076  GVRENDER_DOES_TARGETS          can represent target info (open link in a new tab or window) 
00077  GVRENDER_DOES_Z                render support 2.5D representation -Tvrml 
00078  GVRENDER_NO_WHITE_BG           don't paint white background, assumes white paper -Tps 
00079  LAYOUT_NOT_REQUIRED            don't perform layout -Tcanon            
00080  OUTPUT_NOT_REQUIRED            don't use gvdevice for output (basically when agwrite() used instead) -Tcanon, -Txdot 
00081  */
00082 
00083 
00084 #define EMIT_SORTED (1<<0)
00085 #define EMIT_COLORS (1<<1)
00086 #define EMIT_CLUSTERS_LAST (1<<2)
00087 #define EMIT_PREORDER (1<<3)
00088 #define EMIT_EDGE_SORTED (1<<4)
00089 #define GVDEVICE_DOES_PAGES (1<<5)
00090 #define GVDEVICE_DOES_LAYERS (1<<6)
00091 #define GVDEVICE_EVENTS (1<<7)
00092 #define GVDEVICE_DOES_TRUECOLOR (1<<8)
00093 #define GVDEVICE_BINARY_FORMAT (1<<9)
00094 #define GVDEVICE_COMPRESSED_FORMAT (1<<10)
00095 #define GVDEVICE_NO_WRITER (1<<11)
00096 #define GVRENDER_Y_GOES_DOWN (1<<12)
00097 #define GVRENDER_DOES_TRANSFORM (1<<13)
00098 #define GVRENDER_DOES_ARROWS (1<<14)
00099 #define GVRENDER_DOES_LABELS (1<<15)
00100 #define GVRENDER_DOES_MAPS (1<<16)
00101 #define GVRENDER_DOES_MAP_RECTANGLE (1<<17)
00102 #define GVRENDER_DOES_MAP_CIRCLE (1<<18)
00103 #define GVRENDER_DOES_MAP_POLYGON (1<<19)
00104 #define GVRENDER_DOES_MAP_ELLIPSE (1<<20)
00105 #define GVRENDER_DOES_MAP_BSPLINE (1<<21)
00106 #define GVRENDER_DOES_TOOLTIPS (1<<22)
00107 #define GVRENDER_DOES_TARGETS (1<<23)
00108 #define GVRENDER_DOES_Z (1<<24)
00109 #define GVRENDER_NO_WHITE_BG (1<<25)
00110 #define LAYOUT_NOT_REQUIRED (1<<26)
00111 #define OUTPUT_NOT_REQUIRED (1<<27)
00112 
00113     typedef struct {
00114         int flags;
00115         double default_pad;     /* graph units */
00116         char **knowncolors;
00117         int sz_knowncolors;
00118         color_type_t color_type;
00119     } gvrender_features_t;
00120 
00121     typedef struct {
00122         int flags;
00123         pointf default_margin;  /* left/right, top/bottom - points */
00124         pointf default_pagesize;/* default page width, height - points */
00125         pointf default_dpi;
00126     } gvdevice_features_t;
00127 
00128 #define LAYOUT_USES_RANKDIR (1<<0)
00129 
00130     typedef struct gvplugin_active_device_s {
00131         gvdevice_engine_t *engine;
00132         int id;
00133         gvdevice_features_t *features;
00134         const char *type;
00135     } gvplugin_active_device_t;
00136 
00137     typedef struct gvplugin_active_render_s {
00138         gvrender_engine_t *engine;
00139         int id;
00140         gvrender_features_t *features;
00141         const char *type;
00142     } gvplugin_active_render_t;
00143 
00144     typedef struct gvplugin_active_loadimage_t {
00145         gvloadimage_engine_t *engine;
00146         int id;
00147         const char *type;
00148     } gvplugin_active_loadimage_t;
00149 
00150     typedef struct gv_argvlist_s {
00151         char **argv;
00152         int argc;
00153         int alloc;
00154     } gv_argvlist_t;
00155     
00156     typedef struct gvdevice_callbacks_s {
00157         void (*refresh) (GVJ_t * job);
00158         void (*button_press) (GVJ_t * job, int button, pointf pointer);
00159         void (*button_release) (GVJ_t * job, int button, pointf pointer);
00160         void (*motion) (GVJ_t * job, pointf pointer);
00161         void (*modify) (GVJ_t * job, const char *name, const char *value);
00162         void (*del) (GVJ_t * job);  /* can't use "delete" 'cos C++ stole it */
00163         void (*read) (GVJ_t * job, const char *filename, const char *layout);
00164         void (*layout) (GVJ_t * job, const char *layout);
00165         void (*render) (GVJ_t * job, const char *format, const char *filename);
00166     } gvdevice_callbacks_t;
00167 
00168     typedef int (*gvevent_key_callback_t) (GVJ_t * job);
00169 
00170     typedef struct gvevent_key_binding_s {
00171         char *keystring;
00172         gvevent_key_callback_t callback;
00173     } gvevent_key_binding_t;
00174 
00175     typedef enum {MAP_RECTANGLE, MAP_CIRCLE, MAP_POLYGON, } map_shape_t;
00176 
00177     typedef enum {ROOTGRAPH_OBJTYPE, CLUSTER_OBJTYPE, NODE_OBJTYPE, EDGE_OBJTYPE} obj_type;
00178 
00179     /* If this enum is changed, the implementation of xbuf and xbufs in
00180      * gvrender_core_dot.c will probably need to be changed.
00181      */
00182     typedef enum {
00183         EMIT_GDRAW, EMIT_CDRAW, EMIT_TDRAW, EMIT_HDRAW, 
00184         EMIT_GLABEL, EMIT_CLABEL, EMIT_TLABEL, EMIT_HLABEL, 
00185         EMIT_NDRAW, EMIT_EDRAW, EMIT_NLABEL, EMIT_ELABEL,
00186     } emit_state_t;
00187 
00188     typedef struct obj_state_s obj_state_t;
00189 
00190     struct obj_state_s {
00191         obj_state_t *parent;
00192 
00193         obj_type type;
00194         union {
00195             graph_t *g;
00196             graph_t *sg;  
00197             node_t *n;
00198             edge_t *e;
00199         } u;
00200 
00201         emit_state_t emit_state; 
00202 
00203         gvcolor_t pencolor, fillcolor, stopcolor;
00204         int gradient_angle;
00205         pen_type pen;
00206         fill_type fill;
00207         double penwidth;
00208         char **rawstyle;
00209 
00210         double z, tail_z, head_z;   /* z depths for 2.5D renderers such as vrml */
00211 
00212         /* fully substituted text strings */
00213         char *label;
00214         char *xlabel;
00215         char *taillabel;
00216         char *headlabel; 
00217 
00218         char *url;              /* if GVRENDER_DOES_MAPS */
00219         char *id;
00220         char *labelurl;
00221         char *tailurl;
00222         char *headurl; 
00223 
00224         char *tooltip;          /* if GVRENDER_DOES_TOOLTIPS */
00225         char *labeltooltip;
00226         char *tailtooltip;
00227         char *headtooltip; 
00228 
00229         char *target;           /* if GVRENDER_DOES_TARGETS */
00230         char *labeltarget;
00231         char *tailtarget;
00232         char *headtarget; 
00233 
00234         int explicit_tooltip:1;
00235         int explicit_tailtooltip:1;
00236         int explicit_headtooltip:1;
00237         int explicit_labeltooltip:1;
00238         int explicit_tailtarget:1;
00239         int explicit_headtarget:1;
00240         int explicit_edgetarget:1;
00241         int explicit_tailurl:1;
00242         int explicit_headurl:1;
00243 
00244         /* primary mapped region - node shape, edge labels */
00245         map_shape_t url_map_shape; 
00246         int url_map_n;                  /* number of points for url map if GVRENDER_DOES_MAPS */
00247         pointf *url_map_p;
00248 
00249         /* additonal mapped regions for edges */
00250         int url_bsplinemap_poly_n;      /* number of polygons in url bspline map
00251                                          if GVRENDER_DOES_MAPS && GVRENDER_DOES_MAP_BSPLINES */
00252         int *url_bsplinemap_n;          /* array of url_bsplinemap_poly_n ints 
00253                                          of number of points in each polygon */
00254         pointf *url_bsplinemap_p;       /* all the polygon points */
00255 
00256         int tailendurl_map_n;           /* tail end intersection with node */
00257         pointf *tailendurl_map_p;
00258 
00259         int headendurl_map_n;           /* head end intersection with node */
00260         pointf *headendurl_map_p;
00261     };
00262 
00263 /* Note on units:
00264  *     points  - a physical distance (1/72 inch) unaffected by zoom or dpi.
00265  *     graph units - related to physical distance by zoom.  Equals points at zoom=1
00266  *     device units - related to physical distance in points by dpi/72
00267  */
00268 
00269     struct GVJ_s {
00270         GVC_t *gvc;             /* parent gvc */
00271         GVJ_t *next;            /* linked list of jobs */
00272         GVJ_t *next_active;     /* linked list of active jobs (e.g. multiple windows) */
00273 
00274         GVCOMMON_t *common;
00275 
00276         obj_state_t *obj;       /* objects can be nested (at least clusters can)
00277                                         so keep object state on a stack */
00278         char *input_filename;
00279         int graph_index;
00280 
00281         const char *layout_type;
00282 
00283         const char *output_filename;
00284         FILE *output_file;
00285         char *output_data;
00286         unsigned int output_data_allocated;
00287         unsigned int output_data_position;
00288 
00289         const char *output_langname;
00290         int output_lang;
00291 
00292         gvplugin_active_render_t render;
00293         gvplugin_active_device_t device;
00294         gvplugin_active_loadimage_t loadimage;
00295         gvdevice_callbacks_t *callbacks;
00296         pointf device_dpi;
00297         boolean device_sets_dpi;
00298 
00299         void *display;
00300         int screen;
00301 
00302         void *context;          /* gd or cairo surface */
00303         boolean external_context;       /* context belongs to caller */
00304         char *imagedata;        /* location of imagedata */
00305 
00306         int flags;              /* emit_graph flags */
00307 
00308         int numLayers;          /* number of layers */
00309         int layerNum;           /* current layer - 1 based*/
00310 
00311         point   pagesArraySize; /* 2D size of page array */
00312         point   pagesArrayFirst;/* 2D starting corner in */
00313         point   pagesArrayMajor;/* 2D major increment */
00314         point   pagesArrayMinor;/* 2D minor increment */
00315         point   pagesArrayElem; /* 2D coord of current page - 0,0 based */
00316         int     numPages;       /* number of pages */
00317 
00318         boxf    bb;             /* graph bb with padding - graph units */
00319         pointf  pad;            /* padding around bb - graph units */
00320         boxf    clip;           /* clip region in graph units */
00321         boxf    pageBox;        /* current page in graph units */
00322         pointf  pageSize;       /* page size in graph units */
00323         pointf  focus;          /* viewport focus - graph units */
00324 
00325         double  zoom;           /* viewport zoom factor (points per graph unit) */
00326         int     rotation;       /* viewport rotation (degrees)  0=portrait, 90=landscape */
00327 
00328         pointf  view;           /* viewport size - points */
00329         boxf    canvasBox;      /* viewport area - points */
00330         pointf  margin;         /* job-specific margin - points */
00331 
00332         pointf  dpi;            /* device resolution device-units-per-inch */
00333 
00334         unsigned int width;     /* device width - device units */
00335         unsigned int height;    /* device height - device units */
00336         box     pageBoundingBox;/* rotated boundingBox - device units */
00337         box     boundingBox;    /* cumulative boundingBox over all pages - device units */
00338 
00339         pointf  scale;          /* composite device to graph units (zoom and dpi) */
00340         pointf  translation;    /* composite translation */
00341         pointf  devscale;       /* composite device to points: dpi, y_goes_down */
00342 
00343         boolean fit_mode,
00344                 needs_refresh,
00345                 click,
00346                 has_grown,
00347                 has_been_rendered;
00348 
00349         unsigned char button;   /* active button */
00350         pointf pointer;         /* pointer position in device units */
00351         pointf oldpointer;      /* old pointer position in device units */
00352 
00353         void *current_obj;      /* graph object that pointer is in currently */
00354 
00355         void *selected_obj;      /* graph object that has been selected */
00356                                         /* (e.g. button 1 clicked on current obj) */
00357         char *active_tooltip;           /* tooltip of active object - or NULL */
00358         char *selected_href;            /* href of selected object - or NULL */
00359         gv_argvlist_t selected_obj_type_name; /* (e.g. "edge" "node3" "e" "->" "node5" "") */
00360         gv_argvlist_t selected_obj_attributes; /* attribute triplets: name, value, type */
00361                                 /* e.g. "color", "red", GVATTR_COLOR,
00362                                         "style", "filled", GVATTR_BOOL, */
00363 
00364         void *window;           /* display-specific data for gvrender plugin */
00365 
00366         /* keybindings for keyboard events */
00367         gvevent_key_binding_t *keybindings;
00368         int numkeys;
00369         void *keycodes;
00370     };
00371 
00372 #ifdef __cplusplus
00373 }
00374 #endif
00375 #endif                          /* GVCJOB_H */