A patch to support creating network diagrams using programs



I'm writing some scripts to extract data from spreadsheets and build
network flow diagrams.  I assumed that if I created a line that
connected handle A to handle B that dia would figure out where to put
the line and display it.  It did not (instead defaulting to position 0,0
and bounding box 0,0,0,0).  Here's a patch so that locations and bb's
can be inferred by what they connect.

[tiemann localhost ~]$ cd dia-0.94/app/
[tiemann localhost app]$ diff -u load_save.c~ load_save.c
--- load_save.c~        2004-08-16 03:56:03.000000000 -0400
+++ load_save.c 2005-05-15 21:06:13.000000000 -0400
@@ -315,6 +315,79 @@
   }
 }
 
+static gboolean
+fixup_connections(GList *objects, GHashTable *objects_hash)
+{
+  GList *list;
+  int i;
+
+  list = objects;
+  while (list != NULL && list->data != NULL) {
+    DiaObject *obj = (DiaObject *) list->data;
+
+    if IS_GROUP(obj) {
+      fixup_connections(group_objects(obj), objects_hash);
+    } else {
+      if (obj->position.x == 0 && obj->position.y == 0
+         && obj->handles[0]->connected_to != NULL)
+       {
+         ConnectionPoint *con_point = obj->handles[0]->connected_to;
+         DiaObject *other_obj = con_point->object;
+         int con_point_nr;
+         ConnectionPoint *ocp;
+
+         con_point_nr=0;
+         while (other_obj->connections[con_point_nr] != con_point) {
+           con_point_nr++;
+           if (con_point_nr>=other_obj->num_connections) {
+             message_error("Internal error (1) fixing up diagram\n con_point_nr >= 
other_obj->num_connections\n");
+             return FALSE;
+           }
+         }
+         /* ocp is the actual point on the object we're connecting to.  */
+         ocp = other_obj->connections[con_point_nr];
+         
+         if (ocp->pos.x != 0 || ocp->pos.y != 0) {
+           /* We have a connection that needs to be fixed.  Fix every single connection.  */
+
+           for (i=0;i<obj->num_handles;i++) {
+             Handle *handle;
+       
+             handle = obj->handles[i];
+             con_point = handle->connected_to;
+       
+             if ( con_point != NULL ) {
+               DiaObject *other_obj;
+               int con_point_nr;
+
+               other_obj = con_point->object;
+
+               con_point_nr=0;
+               while (other_obj->connections[con_point_nr] != con_point) {
+                 con_point_nr++;
+                 if (con_point_nr>=other_obj->num_connections) {
+                   message_error("Internal error (2) fixing up diagram\n con_point_nr >= 
other_obj->num_connections\n");
+                   return FALSE;
+                 }
+               }
+         
+               /* 'obj' is our object; 'handle' is the connection source.
+                  'other_obj' is the connection target; 'con_point_nr' is the target handle.
+                  'ocp' is the actual connection target.  */
+               ocp = other_obj->connections[con_point_nr];
+
+               obj->ops->move_handle (obj, handle, &ocp->pos, ocp, HANDLE_MOVE_CONNECTED, 0);
+             }
+           }
+         }
+       }
+      }
+    
+    list = g_list_next(list);
+  }
+  return TRUE;
+}
+
 static void 
 hash_free_string(gpointer       key,
                 gpointer       value,
@@ -569,6 +642,8 @@
     layer_add_objects (layer, list);
     read_connections( list, layer_node, objects_hash);
 
+    fixup_connections (list, objects_hash);
+
     data_add_layer(data, layer);
 
     layer_node = layer_node->next;
[tiemann localhost app]$ 

M




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]