[dia] UML - Fork, Branch: fix number of connection points



commit 31c78100b1adebde40fa1264f82c2b064222ad39
Author: Hans Breuer <hans breuer org>
Date:   Fri Jun 28 22:56:35 2013 +0200

    UML - Fork, Branch: fix number of connection points
    
    Not the bug I was looking for, but close. Added a unit
    test to detect such by missing connection point position
    update when moving.

 objects/UML/branch.c |   12 ++++++++----
 objects/UML/fork.c   |   39 +++++++++++++++++++++++++--------------
 tests/test-objects.c |   19 +++++++++++++++++++
 3 files changed, 52 insertions(+), 18 deletions(-)
---
diff --git a/objects/UML/branch.c b/objects/UML/branch.c
index 39b81c1..a1f4098 100644
--- a/objects/UML/branch.c
+++ b/objects/UML/branch.c
@@ -41,10 +41,13 @@
 
 typedef struct _Branch Branch;
 
+/* earlier versions claimed to have 8 connections, but initialized only 4 */
+#define NUM_CONNECTIONS 4
+
 struct _Branch
 {
   Element element;
-  ConnectionPoint connections[8];
+  ConnectionPoint connections[NUM_CONNECTIONS];
   Color line_color;
   Color fill_color;
 };
@@ -249,7 +252,8 @@ static void branch_update_data(Branch *branch)
   element_update_handles(elem);
 }
 
-static DiaObject *branch_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2)
+static DiaObject *
+branch_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2)
 {
   Branch *branch;
   Element *elem;
@@ -265,12 +269,12 @@ static DiaObject *branch_create(Point *startpoint, void *user_data, Handle **han
   obj->ops = &branch_ops;
 
   elem->corner = *startpoint;
-  element_init(elem, 8, 8);
+  element_init(elem, 8, NUM_CONNECTIONS);
 
   branch->line_color = attributes_get_foreground();
   branch->fill_color = attributes_get_background();
 
-  for (i=0;i<8;i++)
+  for (i=0;i<NUM_CONNECTIONS;i++)
     {
       obj->connections[i] = &branch->connections[i];
       branch->connections[i].object = obj;
diff --git a/objects/UML/fork.c b/objects/UML/fork.c
index 4f8f0f7..098d187 100644
--- a/objects/UML/fork.c
+++ b/objects/UML/fork.c
@@ -41,11 +41,14 @@
 
 typedef struct _Fork Fork;
 
+/* earlier versions claimed to have 8 connections, but initialized only 6 */
+#define NUM_CONNECTIONS 6
+
 struct _Fork
 {
   Element element;
   Color fill_color;
-  ConnectionPoint connections[8];
+  ConnectionPoint connections[NUM_CONNECTIONS];
 };
 
 static const double FORK_BORDERWIDTH = 0.0;
@@ -196,7 +199,8 @@ fork_move(Fork *branch, Point *to)
   return NULL;
 }
 
-static void fork_draw(Fork *branch, DiaRenderer *renderer)
+static void
+fork_draw(Fork *branch, DiaRenderer *renderer)
 {
   DiaRendererClass *renderer_ops = DIA_RENDERER_GET_CLASS (renderer);
   Element *elem;
@@ -224,7 +228,8 @@ static void fork_draw(Fork *branch, DiaRenderer *renderer)
                           &branch->fill_color);
 }
 
-static void fork_update_data(Fork *branch)
+static void
+fork_update_data(Fork *branch)
 {
   Element *elem = &branch->element;
   DiaObject *obj = &elem->object;
@@ -242,14 +247,15 @@ static void fork_update_data(Fork *branch)
   branch->connections[4].pos.y = elem->corner.y + elem->height;
   branch->connections[5].pos.x = elem->corner.x + elem->width - FORK_MARGIN*elem->width;
   branch->connections[5].pos.y = elem->corner.y + elem->height;
-  
+
   element_update_boundingbox(elem);
   obj->position = elem->corner;
 
   element_update_handles(elem);
 }
 
-static DiaObject *fork_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2)
+static DiaObject *
+fork_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2)
 {
   Fork *branch;
   Element *elem;
@@ -267,16 +273,19 @@ static DiaObject *fork_create(Point *startpoint, void *user_data, Handle **handl
   elem->corner = *startpoint;
   elem->width = FORK_WIDTH;
   elem->height = FORK_HEIGHT;
-  element_init(elem, 8, 8);
+  element_init(elem, 8, NUM_CONNECTIONS);
 
   branch->fill_color = attributes_get_foreground();
 
-  for (i=0;i<8;i++)
-    {
-      obj->connections[i] = &branch->connections[i];
-      branch->connections[i].object = obj;
-      branch->connections[i].connected = NULL;
-    }
+  for (i = 0; i < NUM_CONNECTIONS; ++i) {
+    obj->connections[i] = &branch->connections[i];
+    branch->connections[i].object = obj;
+    branch->connections[i].connected = NULL;
+    if (i < NUM_CONNECTIONS/2)
+      branch->connections[i].directions = DIR_NORTH;
+    else
+      branch->connections[i].directions = DIR_SOUTH;
+  }
   elem->extra_spacing.border_trans = FORK_BORDERWIDTH / 2.0;
   fork_update_data(branch);
   
@@ -290,12 +299,14 @@ static DiaObject *fork_create(Point *startpoint, void *user_data, Handle **handl
   return &branch->element.object;
 }
 
-static void fork_destroy(Fork *branch)
+static void
+fork_destroy(Fork *branch)
 {
   element_destroy(&branch->element);
 }
 
-static DiaObject *fork_load(ObjectNode obj_node, int version,DiaContext *ctx)
+static DiaObject *
+fork_load(ObjectNode obj_node, int version,DiaContext *ctx)
 {
   return object_load_using_properties(&fork_type,
                                       obj_node,version,ctx);
diff --git a/tests/test-objects.c b/tests/test-objects.c
index 9ad00f0..c793679 100644
--- a/tests/test-objects.c
+++ b/tests/test-objects.c
@@ -191,6 +191,9 @@ _test_movement (gconstpointer user_data)
   ObjectChange *change;
   Point pos;
   real epsilon;
+  Point *handle_positions;
+  Point *cp_positions;
+  guint i;
   
   /* does the object move ... ? */
   from = o->position;
@@ -214,12 +217,27 @@ _test_movement (gconstpointer user_data)
   /* .... really: without changing size ? */
   pos = o->position;
   bbox1 = o->bounding_box;
+  /* remember handle and connection point positions ... */
+  handle_positions = g_alloca (sizeof(Point) * o->num_handles);
+  for (i = 0; i < o->num_handles; ++i)
+    handle_positions[i] = o->handles[i]->pos;
+  cp_positions = g_alloca (sizeof(Point) * o->num_connections);
+  for (i = 0; i < o->num_connections; ++i)
+    cp_positions[i] = o->connections[i]->pos;
+
   change = o->ops->move (o, &to);
   if (change) /* usually this is NULL for move */
     _object_change_free(change);
   /* does the position reflect the move? */
   g_assert (   fabs(fabs(pos.x - o->position.x) - fabs(from.x - to.x)) < EPSILON
             && fabs(fabs(pos.y - o->position.y) - fabs(from.y - to.y)) < EPSILON );
+  /* ... also for handles and connection points? */
+  for (i = 0; i < o->num_handles; ++i)
+    g_assert (   fabs(fabs(handle_positions[i].x - o->handles[i]->pos.x) - fabs(from.x - to.x)) < EPSILON
+              && fabs(fabs(handle_positions[i].y - o->handles[i]->pos.y) - fabs(from.y - to.y)) < EPSILON);
+  for (i = 0; i < o->num_connections; ++i)
+    g_assert (   fabs(fabs(cp_positions[i].x - o->connections[i]->pos.x) - fabs(from.x - to.x)) < EPSILON
+              && fabs(fabs(cp_positions[i].y - o->connections[i]->pos.y) - fabs(from.y - to.y)) < EPSILON);
 
   bbox2 = o->bounding_box;
   /* test fails e.g. for 'Cisco - Web cluster' probably due to bezier-bbox-issues: bug 568115 */
@@ -394,6 +412,7 @@ _test_connectionpoint_consistency (gconstpointer user_data)
         || strcmp (type->name, "Standard - Polygon") == 0
         || strcmp (type->name, "GRAFCET - Action") == 0)
       continue; /* undecided */
+    /* Some things which should not be set */
     if (cp->pos.x > center.x)
       g_assert ((cp->directions & DIR_WEST) == 0);
     else if (cp->pos.x < center.x)


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