]> granicus.if.org Git - graphviz/commitdiff
Restore earlier versions
authorerg <devnull@localhost>
Tue, 26 May 2009 03:50:45 +0000 (03:50 +0000)
committererg <devnull@localhost>
Tue, 26 May 2009 03:50:45 +0000 (03:50 +0000)
lib/gvc/gvplugin.c
lib/neatogen/neatoinit.c

index 439097ac78176ce806753187346463b94b13ce2b..ba3f127c42a0e979e34ba1a1f72b5f1044214369 100644 (file)
 
 #include       "const.h"
 
-#ifndef HAVE_STRCASECMP
-extern int strcasecmp(const char *s1, const char *s2);
-#endif
-
 /*
  * Define an apis array of name strings using an enumerated api_t as index.
  * The enumerated type is defined gvplugin.h.  The apis array is
@@ -297,18 +293,17 @@ gvplugin_available_t *gvplugin_load(GVC_t * gvc, api_t api, const char *str)
            continue;  /* types empty or mismatched */
        if (dep && reqdep && strcmp(dep, reqdep))
            continue;  /* dependencies not empty, but mismatched */
-       if (! reqpkg || strcmp(reqpkg, (*pnext)->package->name) == 0)
-       {
-               /* found with no packagename constraints, or with required matching packagname */
-    
-               if (dep && (apidep != api)) /* load dependency if needed, continue if can't find */
-                       if (! (gvplugin_load(gvc, apidep, dep)))
-                               continue;
-               break;
-    }
+       if (! reqpkg)
+           break; /* found with no packagename constraints */
+       if (strcmp(reqpkg, (*pnext)->package->name) == 0)
+           break;  /* found with required matching packagname */
     }
     rv = *pnext;
 
+    if (dep && (apidep != api)) /* load dependency if needed */
+       if (! (gvplugin_load(gvc, apidep, dep)))
+           rv = NULL;
+
     if (rv && rv->typeptr == NULL) {
        library = gvplugin_library_load(gvc, rv->package->path);
        if (library) {
@@ -467,7 +462,7 @@ Agraph_t * gvplugin_graph(GVC_t * gvc)
     Agsym_t *a;
     gvplugin_package_t *package;
     gvplugin_available_t **pnext;
-    char bufa[100], *buf1, *buf2, bufb[100], *p, *q;
+    char bufa[100], *buf1, *buf2, bufb[100], *p, *q, *t;
     int api, found;
 
 #ifndef WITH_CGRAPH
@@ -547,11 +542,25 @@ Agraph_t * gvplugin_graph(GVC_t * gvc)
            for (pnext = &(gvc->apis[api]); *pnext; pnext = &((*pnext)->next)) {
                if ((*pnext)->package == package) {
                    found++;
-                   q = strdup((*pnext)->typestr);
+                   t = q = strdup((*pnext)->typestr);
                    if ((p = strchr(q, ':'))) *p++ = '\0';
+                   /* Now p = renderer, e.g. "gd"
+                    * and q = device, e.g. "png"
+                    * or  q = imageloader, e.g. "png" */
                    switch (api) {
                    case API_device:
                    case API_loadimage:
+
+                       /* hack for aliases */
+                       if (!strncmp(q,"jp",2))
+                           q = "jpeg/jpe/jpg";
+                       else if (!strncmp(q,"tif",3))
+                           q = "tiff/tif";
+                       else if (!strcmp(q,"x11") || !strcmp(q,"xlib"))
+                           q = "x11/xlib";
+                       else if (!strcmp(q,"dot") || !strcmp(q,"gv"))
+                           q = "gv/dot";
+
                        strcpy(buf2, q);
 #ifndef WITH_CGRAPH
                        n = agnode(ssg, bufa);
@@ -606,7 +615,7 @@ Agraph_t * gvplugin_graph(GVC_t * gvc)
                    default:
                        break;
                    }
-                   free(q);
+                   free(t);
                }
            }
            if (!found)
@@ -619,9 +628,9 @@ Agraph_t * gvplugin_graph(GVC_t * gvc)
     }
 
 #ifndef WITH_CGRAPH
-    ssg = agsubg(g, "o_formats");
+    ssg = agsubg(g, "output_formats");
 #else
-    ssg = agsubg(g, "o_formats", 1);
+    ssg = agsubg(g, "output_formats", 1);
 #endif
     a = agfindgraphattr(ssg, "rank");
 #ifndef WITH_CGRAPH
@@ -639,8 +648,22 @@ Agraph_t * gvplugin_graph(GVC_t * gvc)
            buf2 = bufa + strlen(bufa);
            for (pnext = &(gvc->apis[api]); *pnext; pnext = &((*pnext)->next)) {
                if ((*pnext)->package == package) {
-                   q = strdup((*pnext)->typestr);
+                   t = q = strdup((*pnext)->typestr);
                    if ((p = strchr(q, ':'))) *p++ = '\0';
+                   /* Now p = renderer, e.g. "gd"
+                    * and q = device, e.g. "png"
+                    * or  q = imageloader, e.g. "png" */
+
+                   /* hack for aliases */
+                   if (!strncmp(q,"jp",2))
+                       q = "jpeg/jpe/jpg";
+                   else if (!strncmp(q,"tif",3))
+                       q = "tiff/tif";
+                   else if (!strcmp(q,"x11") || !strcmp(q,"xlib"))
+                       q = "x11/xlib";
+                   else if (!strcmp(q,"dot") || !strcmp(q,"gv"))
+                       q = "gv/dot";
+
                    switch (api) {
                    case API_device:
                        strcpy(buf2, q);
@@ -649,7 +672,7 @@ Agraph_t * gvplugin_graph(GVC_t * gvc)
 #else
                        n = agnode(g, bufa, 1);
 #endif
-                       strcpy(bufb, "o_");
+                       strcpy(bufb, "output_");
                        strcat(bufb, q);
                        m = agfindnode(ssg, bufb);
                        if (!m) {
@@ -675,12 +698,19 @@ Agraph_t * gvplugin_graph(GVC_t * gvc)
                        if (p && *p) {
                            strcpy(bufb, "render_");
                            strcat(bufb, p);
+                           m = agfindnode(ssg, bufb);
+                           if (!m)
 #ifndef WITH_CGRAPH
-                           m = agnode(g, bufb);
-                           agedge(g, m, n);
+                               m = agnode(g, bufb);
 #else
-                           m = agnode(g, bufb, 1);
-                           agedge(g, m, n, NULL, 1);
+                               m = agnode(g, bufb, 1);
+#endif
+                           e = agfindedge(g, m, n);
+                           if (!e)
+#ifndef WITH_CGRAPH
+                               e = agedge(g, m, n);
+#else
+                               e = agedge(g, m, n, NULL, 1);
 #endif
                        }
                        break;
@@ -691,7 +721,7 @@ Agraph_t * gvplugin_graph(GVC_t * gvc)
 #else
                        n = agnode(g, bufa, 1);
 #endif
-                       strcpy(bufb, "i_");
+                       strcpy(bufb, "input_");
                        strcat(bufb, q);
                        m = agfindnode(g, bufb);
                        if (!m) {
@@ -716,18 +746,25 @@ Agraph_t * gvplugin_graph(GVC_t * gvc)
 #endif
                        strcpy(bufb, "render_");
                        strcat(bufb, p);
+                       m = agfindnode(g, bufb);
+                       if (!m)
+#ifndef WITH_CGRAPH
+                           m = agnode(g, bufb); 
+#else
+                           m = agnode(g, bufb, 1); 
+#endif
+                       e = agfindedge(g, n, m);
+                       if (!e)
 #ifndef WITH_CGRAPH
-                       m = agnode(g, bufb); 
-                       agedge(g, n, m);
+                           e = agedge(g, n, m);
 #else
-                       m = agnode(g, bufb, 1); 
-                       agedge(g, n, m, NULL, 1);
+                           e = agedge(g, n, m, NULL, 1);
 #endif
                        break;
                    default:
                        break;
                    }
-                   free(q);
+                   free(t);
                }
            }
        }
index 58459a2f313d65863150443d3c484f0dc43ade0e..90f8a65b70089afde0d16fe06213d5d1d5bdb283 100644 (file)
@@ -654,6 +654,12 @@ static void translate(Agraph_t * g, pos_edge posEdges)
  * clusters, edges and labels. If certain position information
  * is missing, init_nop will use a standard neato technique to
  * supply it.
+ *
+ * If adjust is false, init_nop does nothing but initialize all
+ * of the basic graph information. No tweaking of positions or 
+ * filling in edge splines is done.
+ *
+ * Returns 0 on success.
  */
 int init_nop(Agraph_t * g, int adjust)
 {
@@ -662,6 +668,7 @@ int init_nop(Agraph_t * g, int adjust)
     pos_edge posEdges;         /* How many edges have spline info */
     attrsym_t *G_lp = agfindgraphattr(g, "lp");
     attrsym_t *G_bb = agfindgraphattr(g, "bb");
+    int didAdjust = 0;  /* Have nodes been moved? */
 
     /* If G_bb not defined, define it */
     if (!G_bb)
@@ -682,13 +689,20 @@ int init_nop(Agraph_t * g, int adjust)
     nop_init_graphs(g, G_lp, G_bb);
     posEdges = nop_init_edges(g);
 
-    if (adjust && Nop == 1)
-       adjustNodes(g);
+    if (adjust && (Nop == 1))
+       didAdjust = adjustNodes(g);
+
+    if (didAdjust) {
+       if (GD_label(g)) GD_label(g)->set = FALSE;
+/* FIX: 
+ *   - if nodes are moved, clusters are no longer valid.
+ */
+    }
 
     /* If g does not have a good "bb" attribute or we adjusted the nodes, 
      * compute it. 
      */
-    if (!chkBB(g, G_bb) || (adjust && Nop == 1))
+    if (!chkBB(g, G_bb) || didAdjust)
        compute_bb(g);
 
     /* At this point, all bounding boxes should be correctly defined.
@@ -731,7 +745,7 @@ static int neatoModel(graph_t * g)
     char *p = agget(g, "model");
     char c;
 
-    if (!p || (!(c = *p)))
+    if (!p || (!(c = *p)))    /* if p is NULL or "" */
        return MODEL_SHORTPATH;
     if ((c == 'c') && streq(p, "circuit"))
        return MODEL_CIRCUIT;
@@ -741,6 +755,20 @@ static int neatoModel(graph_t * g)
        else if (streq(p, "shortpath"))
            return MODEL_SHORTPATH;
     }
+    if ((c == 'm') && streq(p, "mds")) {
+#ifndef WITH_CGRAPH
+       if (agindex(g->root->proto->e, "len") >= 0)
+#else /* WITH_CGRAPH */
+       if (agattr(g, AGEDGE, "len", 0))
+#endif /* WITH_CGRAPH */
+           return MODEL_MDS;
+       else {
+           agerr(AGWARN,
+               "edges in graph %s have no len attribute. Hence, the mds model\n", agnameof(g));
+           agerr(AGPREV, "is inappropriate. Reverting to the shortest path model.\n");
+           return MODEL_SHORTPATH;
+       }
+    }
     agerr(AGWARN,
          "Unknown value %s for attribute \"model\" in graph %s - ignored\n",
          p, agnameof(g));
@@ -1089,7 +1117,7 @@ setSeed (graph_t * G, int dflt, long* seedp)
        long seed;
        /* Check for seed value */
        if (!isdigit(*(unsigned char *)p) || sscanf(p, "%ld", &seed) < 1) {
-#if defined(MSWIN32) || defined(WIN32)
+#ifdef MSWIN32
            seed = (unsigned) time(NULL);
 #else
            seed = (unsigned) getpid() ^ (unsigned) time(NULL);
@@ -1157,8 +1185,8 @@ void dumpData(graph_t * g, vtx_data * gp, int nv, int ne)
 /* majorization:
  * Solve stress using majorization.
  * Old neato attributes to incorporate:
- *  weight?
- * model will be MODE_MAJOR, MODE_HIER or MODE_IPSEP
+ *  weight
+ * mode will be MODE_MAJOR, MODE_HIER or MODE_IPSEP
  */
 static void
 majorization(graph_t *mg, graph_t * g, int nv, int mode, int model, int dim, int steps)
@@ -1309,6 +1337,27 @@ static void subset_model(Agraph_t * G, int nG)
     freeGraphData(gp);
 }
 
+/* mds_model:
+ * Assume the matrix already contains shortest path values.
+ * Use the actual lengths provided the input for edges.
+ */
+static void mds_model(graph_t * g, int nG)
+{
+    long i, j;
+    node_t *v;
+    edge_t *e;
+
+    for (v = agfstnode(g); v; v = agnxtnode(g, v)) {
+       for (e = agfstout(g, v); e; e = agnxtout(g, e)) {
+           i = AGID(agtail(e));
+           j = AGID(aghead(e));
+           if (i == j)
+               continue;
+           GD_dist(g)[i][j] = GD_dist(g)[j][i] = GD_dist(e);
+       }
+    }
+}
+
 /* kkNeato:
  * Solve using gradient descent a la Kamada-Kawai.
  */
@@ -1328,6 +1377,9 @@ static void kkNeato(Agraph_t * g, int nG, int model)
            agerr(AGPREV, "the graph into connected components.\n");
            shortest_path(g, nG);
        }
+    } else if (model == MODEL_MDS) {
+       shortest_path(g, nG);
+       mds_model(g, nG);
     } else
        shortest_path(g, nG);
     initial_positions(g, nG);
@@ -1396,6 +1448,7 @@ void neato_layout(Agraph_t * g)
     int layoutMode;
     int model;
     pack_mode mode;
+    pack_info pinfo;
 
     if (Nop) {
        int save = PSinputscale;
@@ -1413,7 +1466,7 @@ void neato_layout(Agraph_t * g)
        neato_init_graph(g);
        layoutMode = neatoMode(g);
        model = neatoModel(g);
-       mode = getPackMode(g, l_undef);
+       mode = getPackModeInfo (g, l_undef, &pinfo);
        Pack = getPack(g, -1, CL_OFFSET);
        /* pack if just packmode defined. */
        if (mode == l_undef) {
@@ -1422,7 +1475,7 @@ void neato_layout(Agraph_t * g)
             */
            if ((Pack < 0) && layoutMode)
                Pack = CL_OFFSET;
-           mode = l_node;
+           pinfo.mode = l_node;
        } else if (Pack < 0)
            Pack = CL_OFFSET;
        if (Pack >= 0) {
@@ -1430,7 +1483,6 @@ void neato_layout(Agraph_t * g)
            graph_t **cc;
            int n_cc;
            int i;
-           pack_info pinfo;
            boolean pin;
 
            cc = pccomps(g, &n_cc, cc_pfx, &pin);
@@ -1449,8 +1501,6 @@ void neato_layout(Agraph_t * g)
                } else
                    bp = 0;
                pinfo.margin = Pack;
-               pinfo.doSplines = 0;
-               pinfo.mode = mode;
                pinfo.fixed = bp;
                packGraphs(n_cc, cc, 0, &pinfo);
                if (bp)