[dia] Unfork temporary NewOrthConn



commit 302d5038e755cabb5ce9292d66d0ab9113153e15
Author: Hans Breuer <hans breuer org>
Date:   Sun Jul 22 19:50:24 2012 +0200

    Unfork temporary NewOrthConn
    
    It just took about 12 years to merge it back to orth_conn.[hc].
    Gives connection point on the middle of line segments for all
    OrthConn derivates, e.g. UML - Association, Dependency, ...
    
    Strangely enough this triggered a bug in cairo, where a very
    small arcs rendering produced an infinite loop. Didn't debug
    cairo_arc_negative() but just added a quick work-around.

 lib/Makefile.am                    |    2 -
 lib/dummy_dep.h                    |    2 -
 lib/libdia.def                     |   15 -
 lib/makefile.msc                   |    1 -
 lib/neworth_conn.c                 | 1102 ------------------------------------
 lib/neworth_conn.h                 |  100 ----
 lib/orth_conn.c                    |   80 +++-
 lib/orth_conn.h                    |    2 +
 objects/SADT/arrow.c               |   59 ++-
 plug-ins/cairo/diacairo-renderer.c |   10 +-
 10 files changed, 122 insertions(+), 1251 deletions(-)
---
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 500a31a..838c538 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -97,8 +97,6 @@ libdia_la_SOURCES =  \
 		connection.h \
 		orth_conn.c \
 		orth_conn.h \
-		neworth_conn.c \
-		neworth_conn.h \
 		poly_conn.c \
 		poly_conn.h \
 		bezier_conn.c \
diff --git a/lib/dummy_dep.h b/lib/dummy_dep.h
index b9586ab..0d10b75 100644
--- a/lib/dummy_dep.h
+++ b/lib/dummy_dep.h
@@ -21,7 +21,6 @@
 #include "font.h"
 #include "text.h"
 #include "orth_conn.h"
-#include "neworth_conn.h"
 #include "arrows.h"
 #include "utils.h"
 #include "poly_conn.h"
@@ -59,7 +58,6 @@ void *dummy_dep[] G_GNUC_UNUSED = {
   new_object_state_change, /* objchange.o */
   intl_score_locale, /* intl.o */
   connpointline_create, /* connpoint_line.o */
-  neworthconn_update_data, /* neworth_conn.o */
   object_create_props_dialog, /* properties.o */
   dynobj_list_get_dynobj_rate, /* dynamic_obj.o */
   connpoint_update, /* connectionpoint.c */
diff --git a/lib/libdia.def b/lib/libdia.def
index 97fed25..4e7c57a 100644
--- a/lib/libdia.def
+++ b/lib/libdia.def
@@ -507,21 +507,6 @@ EXPORTS
 
  new_object_state_change
 
- neworthconn_add_segment
- neworthconn_can_add_segment
- neworthconn_can_delete_segment
- neworthconn_copy
- neworthconn_delete_segment
- neworthconn_destroy
- neworthconn_distance_from
- neworthconn_init
- neworthconn_load
- neworthconn_move
- neworthconn_move_handle
- neworthconn_save
- neworthconn_update_boundingbox
- neworthconn_update_data
-
  object_add_connectionpoint
  object_add_handle
  object_apply_props
diff --git a/lib/makefile.msc b/lib/makefile.msc
index 13fa4bc..d5e76a7 100644
--- a/lib/makefile.msc
+++ b/lib/makefile.msc
@@ -81,7 +81,6 @@ OBJECTS = \
 	dialib.obj \
 	layer.obj \
 	message.obj \
-	neworth_conn.obj \
 	objchange.obj \
 	object.obj \
 	object-alias.obj \
diff --git a/lib/orth_conn.c b/lib/orth_conn.c
index db04cbc..53eee96 100644
--- a/lib/orth_conn.c
+++ b/lib/orth_conn.c
@@ -62,6 +62,9 @@ struct MidSegmentChange {
   int segment;
   Point points[2]; 
   Handle *handles[2]; /* These handles cannot be connected */
+  /* NewOrthConn additions */
+  ConnectionPoint *conn; /* ? */
+  ObjectChange *cplchange[2];
 };
 
 static ObjectChange *
@@ -93,6 +96,8 @@ struct EndSegmentChange {
   Handle *old_end_handle;
   ConnectionPoint *cp; /* NULL in add segment and if not connected in
 			  remove segment */
+  /* NewOrthConn additions */
+  ObjectChange *cplchange;
 };
 
 static ObjectChange*
@@ -258,6 +263,26 @@ orthconn_distance_from(OrthConn *orth, Point *point, real line_width)
   return dist;
 }
 
+static void
+neworthconn_update_midpoints(OrthConn *orth)
+{
+  int i;
+  GSList *elem;
+
+  elem=orth->midpoints->connections;
+
+  /* Update connection points, using the handles' positions where useful : */
+  set_midpoint(&((ConnectionPoint *)(elem->data))->pos,orth,0);
+  elem=g_slist_next(elem);
+  for (i=1; i<orth->numpoints-2; i++) {
+    ((ConnectionPoint *)(elem->data))->pos = orth->handles[i]->pos;
+    elem = g_slist_next(elem);
+  }
+  set_midpoint(&(((ConnectionPoint *)(elem->data))->pos),orth,i);
+}
+
+
+
 
 static void
 adjust_handle_count_to(OrthConn *orth, gint count) {
@@ -353,6 +378,7 @@ orthconn_update_data(OrthConn *orth)
   obj->position = orth->points[0];
 
   adjust_handle_count_to(orth, orth->numpoints-1);
+  connpointline_adjust_count(orth->midpoints,orth->numpoints-1,NULL);
 
   /* Make sure start-handle is first and end-handle is second. */
   place_handle_by_swapping(orth, 0, orth->handles[0]);
@@ -365,6 +391,7 @@ orthconn_update_data(OrthConn *orth)
   for (i=1;i<orth->numpoints-2;i++) {
     set_midpoint(&orth->handles[i]->pos, orth, i);
   }
+  neworthconn_update_midpoints(orth);
 }
 
 void
@@ -494,6 +521,8 @@ orthconn_init(OrthConn *orth, Point *startpoint)
   orth->orientation[1] = HORIZONTAL;
   orth->orientation[2] = VERTICAL;
 
+  orth->midpoints = connpointline_create(obj,3);
+
   orthconn_update_data(orth);
 }
 
@@ -531,7 +560,7 @@ orthconn_set_points(OrthConn *orth, int num_points, Point *points)
 void
 orthconn_copy(OrthConn *from, OrthConn *to)
 {
-  int i;
+  int i, rcc;
   DiaObject *toobj, *fromobj;
 
   toobj = &to->object;
@@ -560,6 +589,8 @@ orthconn_copy(OrthConn *from, OrthConn *to)
     to->handles[i]->connected_to = NULL;
     toobj->handles[i] = to->handles[i];
   }
+  rcc = 0;
+  to->midpoints = connpointline_copy(toobj,from->midpoints,&rcc);
   memcpy(&to->extra_spacing,&from->extra_spacing,sizeof(to->extra_spacing));
 }
 
@@ -568,6 +599,7 @@ orthconn_destroy(OrthConn *orth)
 {
   int i;
 
+  connpointline_destroy(orth->midpoints);
   object_destroy(&orth->object);
   
   g_free(orth->points);
@@ -701,6 +733,7 @@ orthconn_load(OrthConn *orth, ObjectNode obj_node,
     obj->handles[i+1] = orth->handles[i];
   }
   orth->numhandles = orth->numpoints-1;
+  orth->midpoints = connpointline_create(obj,orth->numpoints-1);
 
   orthconn_update_data(orth);
 }
@@ -903,6 +936,11 @@ endsegment_change_free(struct EndSegmentChange *change)
       g_free(change->handle);
     change->handle = NULL;
   }
+  if (change->cplchange) {
+    if (change->cplchange->free) change->cplchange->free(change->cplchange);
+    g_free(change->cplchange);
+    change->cplchange = NULL;
+  }
 }
 
 static void
@@ -921,17 +959,24 @@ endsegment_change_apply(struct EndSegmentChange *change, DiaObject *obj)
 		    change->handle, FLIP_ORIENT(orth->orientation[0]) );
       setup_midpoint_handle(orth->handles[1]);
       obj->position = orth->points[0];
+      change->cplchange = connpointline_add_point(orth->midpoints,
+						  &change->point);
     } else { /* last */
       add_point(orth, orth->numpoints, &change->point);
       insert_handle(orth, change->segment, change->handle,
 		    FLIP_ORIENT(orth->orientation[orth->numpoints-3]) );
       setup_midpoint_handle(orth->handles[orth->numpoints-3]);
+      change->cplchange = connpointline_add_point(orth->midpoints,
+						  &orth->midpoints->end);      
     }
     if (change->cp) 
       object_connect(obj, change->handle, change->cp);
     break;
   case TYPE_REMOVE_SEGMENT:
     object_unconnect(obj, change->old_end_handle);
+    change->cplchange = 
+      connpointline_remove_point(orth->midpoints,
+				 &orth->points[change->segment]);
     if (change->segment==0) { /* first */
       delete_point(orth, 0);
       remove_handle(orth, 0);
@@ -945,6 +990,7 @@ endsegment_change_apply(struct EndSegmentChange *change, DiaObject *obj)
     }
     break;
   }
+  neworthconn_update_midpoints(orth); /* useless ? */
 }
 
 static void
@@ -952,6 +998,7 @@ endsegment_change_revert(struct EndSegmentChange *change, DiaObject *obj)
 {
   OrthConn *orth = (OrthConn *)obj;
   
+  change->cplchange->revert(change->cplchange,obj);    
   switch (change->type) {
   case TYPE_ADD_SEGMENT:
     object_unconnect(obj, change->handle);
@@ -987,6 +1034,7 @@ endsegment_change_revert(struct EndSegmentChange *change, DiaObject *obj)
     break;
   }
   change->applied = 0;
+  neworthconn_update_midpoints(orth); /* useless ? */
 }
 
 static ObjectChange *
@@ -1029,12 +1077,27 @@ midsegment_change_free(struct MidSegmentChange *change)
       g_free(change->handles[1]);
     change->handles[1] = NULL;
   }
+
+  if (change->cplchange[0]) {
+    if (change->cplchange[0]->free) 
+      change->cplchange[0]->free(change->cplchange[0]);
+    g_free(change->cplchange[0]);
+    change->cplchange[0] = NULL;
+  }
+  if (change->cplchange[1]) {
+    if (change->cplchange[1]->free) 
+      change->cplchange[1]->free(change->cplchange[1]);
+    g_free(change->cplchange[1]);
+    change->cplchange[1] = NULL;
+  }
 }
 
 static void
 midsegment_change_apply(struct MidSegmentChange *change, DiaObject *obj)
 {
   OrthConn *orth = (OrthConn *)obj;
+  int seg;
+
   change->applied = 1;
 
   switch (change->type) {
@@ -1045,8 +1108,19 @@ midsegment_change_apply(struct MidSegmentChange *change, DiaObject *obj)
 		  orth->orientation[change->segment] );
     insert_handle(orth, change->segment+1, change->handles[0],
 		  FLIP_ORIENT(orth->orientation[change->segment]) );
+    change->cplchange[0] = 
+      connpointline_add_point(orth->midpoints,&change->points[0]);
+    change->cplchange[1] = 
+      connpointline_add_point(orth->midpoints,&change->points[1]);
     break;
   case TYPE_REMOVE_SEGMENT:
+    seg = change->segment?change->segment:1;
+    change->cplchange[0] = 
+      connpointline_remove_point(orth->midpoints,
+				 &orth->points[seg-1]);
+    change->cplchange[1] = 
+      connpointline_remove_point(orth->midpoints,
+				 &orth->points[seg]);
     delete_point(orth, change->segment);
     remove_handle(orth, change->segment);
     delete_point(orth, change->segment);
@@ -1058,6 +1132,7 @@ midsegment_change_apply(struct MidSegmentChange *change, DiaObject *obj)
     }
     break;
   }
+  neworthconn_update_midpoints(orth); /* useless ? */
 }
 
 static void
@@ -1065,6 +1140,9 @@ midsegment_change_revert(struct MidSegmentChange *change, DiaObject *obj)
 {
   OrthConn *orth = (OrthConn *)obj;
   
+  change->cplchange[0]->revert(change->cplchange[0],obj);
+  change->cplchange[1]->revert(change->cplchange[1],obj);
+
   switch (change->type) {
   case TYPE_ADD_SEGMENT:
     delete_point(orth, change->segment+1);
diff --git a/lib/orth_conn.h b/lib/orth_conn.h
index ad93e36..f808490 100644
--- a/lib/orth_conn.h
+++ b/lib/orth_conn.h
@@ -20,6 +20,7 @@
 
 #include "diatypes.h"
 #include "object.h"
+#include "connpoint_line.h"
 #include "boundingbox.h"
 
 typedef enum {
@@ -52,6 +53,7 @@ struct _OrthConn {
    * problematic, as they can only move freely in one direction.)
    * The array of pointers is ordered in segment order.
    */
+  ConnPointLine *midpoints;
   PolyBBExtras extra_spacing;
   gboolean autorouting; /* True if this line is autorouted. */
 };
diff --git a/objects/SADT/arrow.c b/objects/SADT/arrow.c
index 059747c..c48e385 100644
--- a/objects/SADT/arrow.c
+++ b/objects/SADT/arrow.c
@@ -28,7 +28,7 @@
 
 #include "intl.h"
 #include "object.h"
-#include "neworth_conn.h"
+#include "orth_conn.h"
 #include "connectionpoint.h"
 #include "diarenderer.h"
 #include "attributes.h"
@@ -60,7 +60,7 @@ typedef enum { SADT_ARROW_NORMAL,
 	       SADT_ARROW_DISABLED } Sadtarrow_style;
 
 typedef struct _Sadtarrow {
-  NewOrthConn orth;
+  OrthConn orth;
 
   Sadtarrow_style style;
   gboolean autogray;
@@ -106,7 +106,8 @@ static ObjectTypeOps sadtarrow_type_ops =
 DiaObjectType sadtarrow_type =
 {
   "SADT - arrow",   /* name */
-  0,                         /* version */
+  /* Version 0 had no autorouting and so shouldn't have it set by default. */
+  1,                         /* version */
   (char **) arrow_xpm,      /* pixmap */
   
   &sadtarrow_type_ops       /* ops */
@@ -140,7 +141,7 @@ PropEnumData flow_style[] = {
   { NULL }};
 
 static PropDescription sadtarrow_props[] = {
-  NEWORTHCONN_COMMON_PROPERTIES,
+  ORTHCONN_COMMON_PROPERTIES,
 
   { "arrow_style", PROP_TYPE_ENUM, PROP_FLAG_VISIBLE,
     N_("Flow style:"), NULL, flow_style },
@@ -162,7 +163,7 @@ sadtarrow_describe_props(Sadtarrow *sadtarrow)
 }    
 
 static PropOffset sadtarrow_offsets[] = {
-  NEWORTHCONN_COMMON_PROPERTIES_OFFSETS,
+  ORTHCONN_COMMON_PROPERTIES_OFFSETS,
   { "arrow_style", PROP_TYPE_ENUM, offsetof(Sadtarrow,style)},
   { "autogray",PROP_TYPE_BOOL, offsetof(Sadtarrow,autogray)},
   { "line_colour", PROP_TYPE_COLOUR, offsetof(Sadtarrow, line_color) },
@@ -188,15 +189,15 @@ sadtarrow_set_props(Sadtarrow *sadtarrow, GPtrArray *props)
 static real
 sadtarrow_distance_from(Sadtarrow *sadtarrow, Point *point)
 {
-  NewOrthConn *orth = &sadtarrow->orth;
-  return neworthconn_distance_from(orth, point, ARROW_LINE_WIDTH);
+  OrthConn *orth = &sadtarrow->orth;
+  return orthconn_distance_from(orth, point, ARROW_LINE_WIDTH);
 }
 
 static void
 sadtarrow_select(Sadtarrow *sadtarrow, Point *clicked_point,
 		  DiaRenderer *interactive_renderer)
 {
-  neworthconn_update_data(&sadtarrow->orth);
+  orthconn_update_data(&sadtarrow->orth);
 }
 
 static ObjectChange*
@@ -209,7 +210,7 @@ sadtarrow_move_handle(Sadtarrow *sadtarrow, Handle *handle,
   assert(handle!=NULL);
   assert(to!=NULL);
 
-  change = neworthconn_move_handle(&sadtarrow->orth, handle, to, cp, 
+  change = orthconn_move_handle(&sadtarrow->orth, handle, to, cp, 
 				   reason, modifiers);
   sadtarrow_update_data(sadtarrow);
 
@@ -222,7 +223,7 @@ sadtarrow_move(Sadtarrow *sadtarrow, Point *to)
 {
   ObjectChange *change;
 
-  change = neworthconn_move(&sadtarrow->orth, to);
+  change = orthconn_move(&sadtarrow->orth, to);
   sadtarrow_update_data(sadtarrow);
 
   return change;
@@ -240,7 +241,7 @@ static void
 sadtarrow_draw(Sadtarrow *sadtarrow, DiaRenderer *renderer)
 {
   DiaRendererClass *renderer_ops = DIA_RENDERER_GET_CLASS (renderer);
-  NewOrthConn *orth = &sadtarrow->orth;
+  OrthConn *orth = &sadtarrow->orth;
   Point *points;
   int n;
   Color col;
@@ -372,7 +373,7 @@ sadtarrow_create(Point *startpoint,
 		  Handle **handle2)
 {
   Sadtarrow *sadtarrow;
-  NewOrthConn *orth;
+  OrthConn *orth;
   DiaObject *obj;
 
   sadtarrow = g_malloc0(sizeof(Sadtarrow));
@@ -382,7 +383,7 @@ sadtarrow_create(Point *startpoint,
   obj->type = &sadtarrow_type;
   obj->ops = &sadtarrow_ops;
   
-  neworthconn_init(orth, startpoint);
+  orthconn_init(orth, startpoint);
 
   sadtarrow_update_data(sadtarrow);
 
@@ -398,16 +399,16 @@ sadtarrow_create(Point *startpoint,
 static void
 sadtarrow_destroy(Sadtarrow *sadtarrow)
 {
-  neworthconn_destroy(&sadtarrow->orth);
+  orthconn_destroy(&sadtarrow->orth);
 }
 
 static void
 sadtarrow_update_data(Sadtarrow *sadtarrow)
 {
-  NewOrthConn *orth = &sadtarrow->orth;
+  OrthConn *orth = &sadtarrow->orth;
   PolyBBExtras *extra = &orth->extra_spacing;
 
-  neworthconn_update_data(&sadtarrow->orth);
+  orthconn_update_data(&sadtarrow->orth);
 
   extra->start_long = 
     extra->middle_trans = ARROW_LINE_WIDTH / 2.0;
@@ -437,14 +438,14 @@ sadtarrow_update_data(Sadtarrow *sadtarrow)
   default: 
     break;
   }
-  neworthconn_update_boundingbox(orth);
+  orthconn_update_boundingbox(orth);
 }
 
 static ObjectChange *
 sadtarrow_add_segment_callback(DiaObject *obj, Point *clicked, gpointer data)
 {
   ObjectChange *change;
-  change = neworthconn_add_segment((NewOrthConn *)obj, clicked);
+  change = orthconn_add_segment((OrthConn *)obj, clicked);
   sadtarrow_update_data((Sadtarrow *)obj);
   return change;
 }
@@ -453,7 +454,7 @@ static ObjectChange *
 sadtarrow_delete_segment_callback(DiaObject *obj, Point *clicked, gpointer data)
 {
   ObjectChange *change;
-  change = neworthconn_delete_segment((NewOrthConn *)obj, clicked);
+  change = orthconn_delete_segment((OrthConn *)obj, clicked);
   sadtarrow_update_data((Sadtarrow *)obj);
   return change;
 }
@@ -461,7 +462,7 @@ sadtarrow_delete_segment_callback(DiaObject *obj, Point *clicked, gpointer data)
 static DiaMenuItem object_menu_items[] = {
   { N_("Add segment"), sadtarrow_add_segment_callback, NULL, 1 },
   { N_("Delete segment"), sadtarrow_delete_segment_callback, NULL, 1 },
-  /*  ORTHCONN_COMMON_MENUS,*/
+  ORTHCONN_COMMON_MENUS,
 };
 
 static DiaMenu object_menu = {
@@ -474,12 +475,12 @@ static DiaMenu object_menu = {
 static DiaMenu *
 sadtarrow_get_object_menu(Sadtarrow *sadtarrow, Point *clickedpoint)
 {
-  NewOrthConn *orth;
+  OrthConn *orth;
 
   orth = &sadtarrow->orth;
   /* Set entries sensitive/selected etc here */
-  object_menu_items[0].active = neworthconn_can_add_segment(orth, clickedpoint);
-  object_menu_items[1].active = neworthconn_can_delete_segment(orth, clickedpoint);
+  object_menu_items[0].active = orthconn_can_add_segment(orth, clickedpoint);
+  object_menu_items[1].active = orthconn_can_delete_segment(orth, clickedpoint);
   /*  orthconn_update_object_menu(orth, clickedpoint, &object_menu_items[2]);*/
   return &object_menu;
 }
@@ -487,7 +488,15 @@ sadtarrow_get_object_menu(Sadtarrow *sadtarrow, Point *clickedpoint)
 static DiaObject *
 sadtarrow_load(ObjectNode obj_node, int version, DiaContext *ctx)
 {
-  return object_load_using_properties(&sadtarrow_type,
-                                      obj_node,version,ctx);
+  DiaObject *obj = object_load_using_properties(&sadtarrow_type,
+						obj_node,version,ctx);
+  if (version == 0) {
+    AttributeNode attr;
+    /* In old objects with no autorouting, set it to false. */
+    attr = object_find_attribute(obj_node, "autorouting");
+    if (attr == NULL)
+      ((OrthConn*)obj)->autorouting = FALSE;
+  }
+  return obj;
 }
 
diff --git a/plug-ins/cairo/diacairo-renderer.c b/plug-ins/cairo/diacairo-renderer.c
index a9fef2b..15be076 100644
--- a/plug-ins/cairo/diacairo-renderer.c
+++ b/plug-ins/cairo/diacairo-renderer.c
@@ -567,6 +567,7 @@ draw_arc(DiaRenderer *self,
   DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self);
   Point start;
   double a1, a2;
+  real onedu = 0.0;
 
   DIAG_NOTE(g_message("draw_arc %fx%f <%f,<%f", 
             width, height, angle1, angle2));
@@ -584,9 +585,12 @@ draw_arc(DiaRenderer *self,
   a1 = - (angle1 / 180.0) * G_PI;
   a2 = - (angle2 / 180.0) * G_PI;
   /* FIXME: to handle width != height some cairo_scale/cairo_translate would be needed */
-  cairo_arc_negative (renderer->cr, center->x, center->y, 
-                      width > height ? height / 2.0 : width / 2.0, /* FIXME 2nd radius */
-                      a1, a2);
+  ensure_minimum_one_device_unit (renderer, &onedu);
+  /* FIXME2: with too small arcs cairo goes into an endless loop */
+  if (height/2.0 > onedu && width/2.0 > onedu)
+    cairo_arc_negative (renderer->cr, center->x, center->y, 
+                        width > height ? height / 2.0 : width / 2.0, /* FIXME 2nd radius */
+                        a1, a2);
   if (!renderer->stroke_pending)
     cairo_stroke (renderer->cr);
   DIAG_STATE(renderer->cr)



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