[dia] [autorouting] Calculate direction info from element quadrants



commit 75c6fe12b9de1f90b62c3c8d35c790e64ed8f72d
Author: Hans Breuer <hans breuer org>
Date:   Sun Aug 15 21:05:32 2010 +0200

    [autorouting] Calculate direction info from element quadrants

 lib/element.c               |   28 ++++++++++++++++++++++++++++
 lib/element.h               |    4 +++-
 objects/flowchart/diamond.c |    3 +++
 3 files changed, 34 insertions(+), 1 deletions(-)
---
diff --git a/lib/element.c b/lib/element.c
index 76cd115..2ef514f 100644
--- a/lib/element.c
+++ b/lib/element.c
@@ -102,6 +102,34 @@ element_update_connections_rectangle(Element *elem,
   cps[8].directions = DIR_ALL;
 }
 
+/**
+ * More elaborate variant to calculate connection point directions
+ *
+ * It works for any number of connection points.
+ * It calculates them based on qudrants, so works best for symmetric elements.
+ */
+void
+element_update_connections_directions (Element         *elem,
+                                       ConnectionPoint *cps)
+{
+  Point center = { elem->corner.x + elem->width / 2, elem->corner.y + elem->height / 2.0 };
+  int i;
+
+  for (i = 0; i < elem->object.num_connections; ++i) {
+    cps[i].directions = DIR_NONE;
+    if (cps[i].pos.x > center.x)
+      cps[i].directions |= DIR_EAST;
+    else if (cps[i].pos.x < center.x)
+      cps[i].directions |= DIR_WEST;
+    if (cps[i].pos.y > center.y)
+      cps[i].directions |= DIR_SOUTH;
+    else if (cps[i].pos.y < center.y)
+      cps[i].directions |= DIR_NORTH;
+    if (cps[i].flags == CP_FLAGS_MAIN)
+      cps[i].directions |= DIR_ALL;
+  }
+}
+
 /** Update the corner and edge handles of an element to reflect its position
  *  and size.
  * @param elem An element to update.
diff --git a/lib/element.h b/lib/element.h
index 48a0e41..692f40a 100644
--- a/lib/element.h
+++ b/lib/element.h
@@ -47,7 +47,9 @@ struct _Element {
 
 void element_update_handles(Element *elem);
 void element_update_connections_rectangle(Element *elem,
-					  ConnectionPoint* cps);
+					  ConnectionPoint *cps);
+void element_update_connections_directions (Element *elem,
+                                            ConnectionPoint *cps);
 void element_update_boundingbox(Element *elem);
 void element_init(Element *elem, int num_handles, int num_connections);
 void element_destroy(Element *elem);
diff --git a/objects/flowchart/diamond.c b/objects/flowchart/diamond.c
index 0bbbdba..f5d7d0e 100644
--- a/objects/flowchart/diamond.c
+++ b/objects/flowchart/diamond.c
@@ -466,6 +466,9 @@ diamond_update_data(Diamond *diamond, AnchorShape horiz, AnchorShape vert)
   diamond->connections[16].pos.x = elem->corner.x + 4*dw;
   diamond->connections[16].pos.y = elem->corner.y + 4*dh;
 
+  /* help autorouting */
+  element_update_connections_directions (elem, diamond->connections);
+
   extra->border_trans = diamond->border_width / 2.0;
   element_update_boundingbox(elem);
   



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