delorie.com/archives/browse.cgi   search  
Mail Archives: geda-user/2013/12/12/18:03:11

X-Authentication-Warning: delorie.com: mail set sender to geda-user-bounces using -f
X-Recipient: geda-user AT delorie DOT com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1386889313;
bh=j3ARFL4e8ykLoivtg1i1RjX2xtphKKGChNjiVOJj6so=;
h=Date:From:To:Subject:Message-ID:X-Mailer:Mime-Version:
Content-Type;
b=CTfp7nK5q2aaOmNvvVM8zzYktwtpEo5DU8UO22uiMb4Dqjcn0nKKepJSMQlk/zYj/
FR341mCkvvo0pD+RrwFCdU/cP2KpmKVTwHQZrbzcRS9SgEX7QN5lOd8UjaZfxj8pm3
x1ZE+e1V0YCJFS48sB/bUZSMJt3O3KWBciqIWFJQ=
Authentication-Results: smtp1o.mail.yandex.net; dkim=pass header.i=@yandex.ru
Date: Fri, 13 Dec 2013 05:01:40 +0600
From: Alexey Shaposhnikov <canisdirusleidy AT yandex DOT ru>
To: geda-user AT delorie DOT com
Subject: [geda-user] [PATCH] Customizable graphical elements
Message-ID: <20131213050140.4ae1f52c@warrawoona.sti>
X-Mailer: Claws Mail 3.9.2 (GTK+ 2.24.22; x86_64-pc-linux-gnu)
Mime-Version: 1.0
Reply-To: geda-user AT delorie DOT com

--MP_/dGZFl4awxs6U6xPcnTIdpx0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline


Wrote a small patch (for master branch from git) so user can set own sizes
of the graphical elements (net, pin and bus widths plus end- and midcue siz=
es)
by using new EdaConfig mechanism. It look in "geda.graphical" group for
following keys:

bus_width (int, set a line width for buses);
net_width (int, set a line width for buses);
pin_width_net / pin_width_bus (int, set a line width for both types of pins=
);
end_cue_width (int, set width for cue box at ends of unconnected pins and
nets);
cue_width (int, set dameter for intersection cue);

Also I partially rewrote cue drawing functions and gEDA after patch will
not draw cues over buses intersections.

P.S. Patch is obviously crude, so critics and suggestions are welcome.

--=20
=D0=A1 =D1=83=D0=B2=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=D0=BC, =D0=90=D0=BB=
=D0=B5=D0=BA=D1=81=D0=B5=D0=B9 =D0=A8=D0=B0=D0=BF=D0=BE=D1=88=D0=BD=D0=B8=
=D0=BA=D0=BE=D0=B2.

--MP_/dGZFl4awxs6U6xPcnTIdpx0
Content-Type: text/x-patch
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename=customizable_graphical_elements.patch

diff --git a/libgeda/src/o_bus_basic.c b/libgeda/src/o_bus_basic.c
index 87ab800..fb878d5 100644
--- a/libgeda/src/o_bus_basic.c
+++ b/libgeda/src/o_bus_basic.c
@@ -64,7 +64,7 @@ void world_get_bus_bounds(TOPLEVEL *toplevel, OBJECT *object, int *left, int *to
 /*! \brief create a new bus object
  *  \par Function Description
  *  This function creates and returns a new bus object.
- *  
+ *
  *  \param [in]     toplevel    The TOPLEVEL object.
  *  \param [in]     type        The OBJECT type (usually OBJ_BUS)
  *  \param [in]     color       The color of the bus
@@ -76,29 +76,39 @@ void world_get_bus_bounds(TOPLEVEL *toplevel, OBJECT *object, int *left, int *to
  *  \return A new bus OBJECT
  */
 OBJECT *o_bus_new(TOPLEVEL *toplevel,
-		  char type, int color,
-		  int x1, int y1, int x2, int y2,
-		  int bus_ripper_direction)
+                  char type, int color,
+                  int x1, int y1, int x2, int y2,
+                  int bus_ripper_direction)
 {
-  OBJECT *new_node;
+	OBJECT *new_node;
+	EdaConfig *cfg;
+	int size;
+
+	/* TODO: add a sanity check. Just use toplevel->page_current for getting
+	   path work with gschem but make "gaf export" to segfault. */
+	cfg = eda_config_get_context_for_file (NULL);
+	size = eda_config_get_int (cfg, "geda.graphical", "bus_width", NULL);
+	if (!size) {
+		size = BUS_WIDTH;
+	};
 
-  new_node = s_basic_new_object(type, "bus");
-  new_node->color = color;
+	new_node = s_basic_new_object(type, "bus");
+	new_node->color = color;
 
-  new_node->line = (LINE *) g_malloc(sizeof(LINE));
-  /* check for null */	
+	new_node->line = (LINE *) g_malloc(sizeof(LINE));
+	/* check for null */
 
-  new_node->line->x[0] = x1;
-  new_node->line->y[0] = y1;
-  new_node->line->x[1] = x2;
-  new_node->line->y[1] = y2;
-  new_node->line_width = BUS_WIDTH;
+	new_node->line->x[0] = x1;
+	new_node->line->y[0] = y1;
+	new_node->line->x[1] = x2;
+	new_node->line->y[1] = y2;
+	new_node->line_width = size;
 
-  new_node->bus_ripper_direction = bus_ripper_direction;
+	new_node->bus_ripper_direction = bus_ripper_direction;
 
-  new_node->w_bounds_valid_for = NULL;
+	new_node->w_bounds_valid_for = NULL;
 
-  return new_node;
+	return new_node;
 }
 
 /*! \brief read a bus object from a char buffer
diff --git a/libgeda/src/o_net_basic.c b/libgeda/src/o_net_basic.c
index a701543..d662e6b 100644
--- a/libgeda/src/o_net_basic.c
+++ b/libgeda/src/o_net_basic.c
@@ -64,7 +64,7 @@ void world_get_net_bounds(TOPLEVEL *toplevel, OBJECT *object, int *left,
 /*! \brief create a new net object
  *  \par Function Description
  *  This function creates and returns a new net object.
- *  
+ *
  *  \param [in]     toplevel    The TOPLEVEL object.
  *  \param [in]     type        The OBJECT type (usually OBJ_NET)
  *  \param [in]     color       The color of the net
@@ -75,25 +75,34 @@ void world_get_net_bounds(TOPLEVEL *toplevel, OBJECT *object, int *left,
  *  \return A new net OBJECT
  */
 OBJECT *o_net_new(TOPLEVEL *toplevel, char type,
-		  int color, int x1, int y1, int x2, int y2)
+                  int color, int x1, int y1, int x2, int y2)
 {
-  OBJECT *new_node;
+	OBJECT *new_node;
+	EdaConfig *cfg;
+	int size;
+
+	/* TODO: check how to get page path for "gaf export" */
+	cfg = eda_config_get_context_for_file (NULL);
+	size = eda_config_get_int (cfg, "geda.graphical", "net_width", NULL);
+	if (!size) {
+		size = NET_WIDTH;
+	};
 
-  new_node = s_basic_new_object(type, "net");
-  new_node->color = color;
+	new_node = s_basic_new_object(type, "net");
+	new_node->color = color;
 
-  new_node->line = (LINE *) g_malloc(sizeof(LINE));
-  /* check for null */
+	new_node->line = (LINE *) g_malloc(sizeof(LINE));
+	/* check for null */
 
-  new_node->line->x[0] = x1;
-  new_node->line->y[0] = y1;
-  new_node->line->x[1] = x2;
-  new_node->line->y[1] = y2;
-  new_node->line_width = NET_WIDTH;
+	new_node->line->x[0] = x1;
+	new_node->line->y[0] = y1;
+	new_node->line->x[1] = x2;
+	new_node->line->y[1] = y2;
+	new_node->line_width = size;
 
-  new_node->w_bounds_valid_for = NULL;
+	new_node->w_bounds_valid_for = NULL;
 
-  return new_node;
+	return new_node;
 }
 
 /*! \brief read a net object from a char buffer
diff --git a/libgeda/src/o_pin_basic.c b/libgeda/src/o_pin_basic.c
index 0106f4d..3fa63ba 100644
--- a/libgeda/src/o_pin_basic.c
+++ b/libgeda/src/o_pin_basic.c
@@ -468,19 +468,32 @@ void o_pin_update_whichend(TOPLEVEL *toplevel,
  */
 void o_pin_set_type (TOPLEVEL *toplevel, OBJECT *o_current, int pin_type)
 {
-  o_emit_pre_change_notify (toplevel, o_current);
-  switch (pin_type) {
-    default:
-      g_critical ("o_pin_set_type: Got invalid pin type %i\n", pin_type);
-      /* Fall through */
-    case PIN_TYPE_NET:
-      o_current->line_width = PIN_WIDTH_NET;
-      o_current->pin_type = PIN_TYPE_NET;
-      break;
-    case PIN_TYPE_BUS:
-      o_current->line_width = PIN_WIDTH_BUS;
-      o_current->pin_type = PIN_TYPE_BUS;
-      break;
-  }
-  o_emit_change_notify (toplevel, o_current);
+	EdaConfig *cfg;
+	int size;
+
+	/* TODO: add checking for page path, without crashing "gaf export" */
+	cfg = eda_config_get_context_for_file(NULL);
+
+	o_emit_pre_change_notify (toplevel, o_current);
+	switch (pin_type) {
+	default:
+		g_critical ("o_pin_set_type: Got invalid pin type %i\n", pin_type);
+		/* Fall through */
+	case PIN_TYPE_NET:
+		size = eda_config_get_int(cfg, "geda.graphical", "pin_width_net", NULL);
+		if (!size) {
+			size = PIN_WIDTH_NET;
+		}
+		o_current->pin_type = PIN_TYPE_NET;
+		break;
+	case PIN_TYPE_BUS:
+		size = eda_config_get_int(cfg, "geda.graphical", "pin_width_bus", NULL);
+		if (!size) {
+			size = PIN_WIDTH_BUS;
+		}
+		o_current->pin_type = PIN_TYPE_BUS;
+		break;
+	}
+	o_current->line_width = size;
+	o_emit_change_notify (toplevel, o_current);
 }
diff --git a/libgedacairo/edarenderer.c b/libgedacairo/edarenderer.c
index e065081..aa48dac 100644
--- a/libgedacairo/edarenderer.c
+++ b/libgedacairo/edarenderer.c
@@ -146,8 +146,6 @@ static void eda_renderer_draw_cues_list (EdaRenderer *renderer, GList *objects);
 static void eda_renderer_draw_end_cues (EdaRenderer *renderer, OBJECT *object,
                                         int end);
 static void eda_renderer_draw_mid_cues (EdaRenderer *renderer, OBJECT *object);
-static void eda_renderer_draw_junction_cue (EdaRenderer *renderer, int x, int y,
-                                            int is_bus);
 
 static int eda_renderer_default_get_user_bounds (EdaRenderer *renderer, OBJECT *object,
                                                  double *left, double *top,
@@ -641,12 +639,12 @@ static void
 eda_renderer_draw_net (EdaRenderer *renderer, OBJECT *object)
 {
   eda_cairo_line (renderer->priv->cr, EDA_RENDERER_CAIRO_FLAGS (renderer),
-                  END_SQUARE, NET_WIDTH,
+                  END_SQUARE, object->line_width,
                   object->line->x[0], object->line->y[0],
                   object->line->x[1], object->line->y[1]);
   eda_cairo_stroke (renderer->priv->cr, EDA_RENDERER_CAIRO_FLAGS (renderer),
                     TYPE_SOLID, END_SQUARE,
-                    EDA_RENDERER_STROKE_WIDTH (renderer, NET_WIDTH),
+                    EDA_RENDERER_STROKE_WIDTH (renderer, object->line_width),
                     -1, -1);
 }
 
@@ -654,37 +652,25 @@ static void
 eda_renderer_draw_bus (EdaRenderer *renderer, OBJECT *object)
 {
   eda_cairo_line (renderer->priv->cr, EDA_RENDERER_CAIRO_FLAGS (renderer),
-                  END_SQUARE, BUS_WIDTH,
+                  END_SQUARE, object->line_width,
                   object->line->x[0], object->line->y[0],
                   object->line->x[1], object->line->y[1]);
   eda_cairo_stroke (renderer->priv->cr, EDA_RENDERER_CAIRO_FLAGS (renderer),
                     TYPE_SOLID, END_SQUARE,
-                    EDA_RENDERER_STROKE_WIDTH (renderer, BUS_WIDTH),
+                    EDA_RENDERER_STROKE_WIDTH (renderer, object->line_width),
                     -1, -1);
 }
 
 static void
 eda_renderer_draw_pin (EdaRenderer *renderer, OBJECT *object)
 {
-  int width = 0;
-  switch (object->pin_type) {
-  case PIN_TYPE_NET:
-    width = PIN_WIDTH_NET;
-    break;
-  case PIN_TYPE_BUS:
-    width = PIN_WIDTH_BUS;
-    break;
-  default:
-    g_return_if_reached ();
-  }
-
   eda_cairo_line (renderer->priv->cr, EDA_RENDERER_CAIRO_FLAGS (renderer),
-                  END_SQUARE, width,
+                  END_SQUARE, object->line_width,
                   object->line->x[0], object->line->y[0],
                   object->line->x[1], object->line->y[1]);
   eda_cairo_stroke (renderer->priv->cr, EDA_RENDERER_CAIRO_FLAGS (renderer),
                     TYPE_SOLID, END_SQUARE,
-                    EDA_RENDERER_STROKE_WIDTH (renderer, width),
+                    EDA_RENDERER_STROKE_WIDTH (renderer, object->line_width),
                     -1, -1);
 }
 
@@ -1343,11 +1329,12 @@ eda_renderer_default_draw_cues (EdaRenderer *renderer, OBJECT *object)
     eda_renderer_draw_cues_list (renderer, object->complex->prim_objs);
     break;
   case OBJ_NET:
-  case OBJ_BUS:
     eda_renderer_draw_mid_cues (renderer, object);
     eda_renderer_draw_end_cues (renderer, object, 0);
     eda_renderer_draw_end_cues (renderer, object, 1);
     break;
+  case OBJ_BUS:
+    break;
   case OBJ_PIN:
     g_return_if_fail ((object->whichend == 1) || (object->whichend == 0));
     eda_renderer_draw_end_cues (renderer, object, object->whichend);
@@ -1360,101 +1347,100 @@ eda_renderer_default_draw_cues (EdaRenderer *renderer, OBJECT *object)
 static void
 eda_renderer_draw_end_cues (EdaRenderer *renderer, OBJECT *object, int end)
 {
-  int x = object->line->x[end], y = object->line->y[end];
-  int conn_count = 0;
-  int conn_type = CONN_ENDPOINT;
-  int is_bus = FALSE;
-  GList *iter;
-
-  /* We should never be at the unconnectable end of a pin */
-  g_return_if_fail ((object->type != OBJ_PIN) || (object->whichend == end));
-
-  /* Check whether the current object is a bus or bus pin */
-  is_bus = ((object->type == OBJ_BUS)
-            || ((object->type == OBJ_PIN)
-                && (object->pin_type == PIN_TYPE_BUS)));
-
-  for (iter = object->conn_list; iter != NULL; iter = g_list_next (iter)) {
-    CONN *conn = (CONN *) iter->data;
-    if ((conn->x != x) || (conn->y != y)) continue;
-
-    /* Check whether the connected object is a bus or bus pin */
-    is_bus |= ((conn->other_object->type == OBJ_BUS)
-               || ((conn->other_object->type == OBJ_PIN)
-                   && (conn->other_object->pin_type == PIN_TYPE_BUS)));
-
-    if (conn->type == CONN_MIDPOINT) {
-      /* If it's a mid-line connection, we can stop already. */
-      conn_type = CONN_MIDPOINT;
-      break;
-    }
-
-    conn_count++;
-  }
-
-  /* Draw a midpoint, if necessary */
-  if ((conn_type == CONN_MIDPOINT)
-      || ((object->type == OBJ_NET) && (conn_count > 1))) {
-    eda_renderer_draw_junction_cue (renderer, x, y, is_bus);
-    return;
-  }
-
-  /* Only things left to be drawn are end point cues */
-  if (!eda_renderer_is_drawable_color (renderer, NET_ENDPOINT_COLOR, TRUE))
-    return;
-  eda_renderer_set_color (renderer, NET_ENDPOINT_COLOR);
-
-  switch (object->type) {
-  case OBJ_NET:
-  case OBJ_PIN:
-    /* If less than one thing was connected to this end of the net
-     * segment or pin, draw box cue */
-    if (conn_count > 0) break;
-
-    eda_cairo_center_box (renderer->priv->cr,
-                          EDA_RENDERER_CAIRO_FLAGS (renderer),
-                          -1, -1, x, y, CUE_BOX_SIZE, CUE_BOX_SIZE);
-    cairo_fill (renderer->priv->cr);
-    break;
-
-  case OBJ_BUS:
-    break;
-  default:
-    g_return_if_reached ();
-  }
+	int x = object->line->x[end], y = object->line->y[end];
+	int conn_count = 0;
+	int conn_type = CONN_ENDPOINT;
+	GList *iter;
+	EdaConfig *cfg;
+	int size;
+
+	/* TODO: get real page path without crashing gaf export. */
+	cfg = eda_config_get_context_for_file(NULL);
+	size = eda_config_get_int(cfg, "geda.graphical", "end_cue_width", NULL);
+	if (!size) {
+		size = CUE_BOX_SIZE;
+	}
+	/* We should never be at the unconnectable end of a pin */
+	g_return_if_fail ((object->type != OBJ_PIN) || (object->whichend == end));
+
+	for (iter = object->conn_list; iter != NULL; iter = g_list_next (iter)) {
+		CONN *conn = (CONN *) iter->data;
+		if ((conn->x != x) || (conn->y != y)) {
+			continue;
+		}
+		if (conn->type == CONN_MIDPOINT) {
+			/* If it's a mid-line connection, we can stop already. */
+			conn_type = CONN_MIDPOINT;
+			break;
+		}
+		conn_count++;
+	}
+
+	if ((conn_type == CONN_MIDPOINT)
+	    || ((object->type == OBJ_NET) && (conn_count > 1))) {
+		return;
+	}
+
+	/* Only things left to be drawn are end point cues */
+	if (!eda_renderer_is_drawable_color (renderer, NET_ENDPOINT_COLOR, TRUE))
+		return;
+	eda_renderer_set_color (renderer, NET_ENDPOINT_COLOR);
+
+	/* If less than one thing was connected to this end of the net
+	 * segment or pin, draw box cue */
+	if (conn_count == 0) {
+		eda_cairo_center_box (renderer->priv->cr,
+		                      EDA_RENDERER_CAIRO_FLAGS (renderer),
+		                      -1, -1, x, y, size, size);
+		cairo_fill (renderer->priv->cr);
+	}
 }
 
 static void
 eda_renderer_draw_mid_cues (EdaRenderer *renderer, OBJECT *object)
 {
-  GList *iter;
-  for (iter = object->conn_list; iter != NULL; iter = g_list_next (iter)) {
-    CONN *conn = (CONN *) iter->data;
-
-    if (conn->type == CONN_MIDPOINT) {
-      int is_bus = ((object->type == OBJ_BUS)
-                    || (conn->other_object->type == OBJ_BUS)
-                    || ((conn->other_object->type == OBJ_PIN)
-                        && (conn->other_object->pin_type == PIN_TYPE_BUS)));
-      eda_renderer_draw_junction_cue (renderer, conn->x, conn->y, is_bus);
-    }
-  }
-}
-
-static void
-eda_renderer_draw_junction_cue (EdaRenderer *renderer, int x, int y, int is_bus)
-{
-  double width = (is_bus ? BUS_WIDTH : NET_WIDTH);
-  double radius = (is_bus ? JUNCTION_CUE_SIZE_BUS : JUNCTION_CUE_SIZE_NET) / 2;
-
-  if (!eda_renderer_is_drawable_color (renderer, JUNCTION_COLOR, 1)) {
-    return;
-  }
-
-  eda_cairo_center_arc (renderer->priv->cr, EDA_RENDERER_CAIRO_FLAGS (renderer),
-                        width, -1, x, y, radius, 0, 360);
-  eda_renderer_set_color (renderer, JUNCTION_COLOR);
-  cairo_fill (renderer->priv->cr);
+	GList *iter;
+	EdaConfig *cfg;
+	int width, diameter;
+
+	/* TODO: get page path without crashing "gaf export" */
+	cfg = eda_config_get_context_for_file(NULL);
+	width = eda_config_get_int (cfg, "geda.graphical", "net_width", NULL);
+	if (!width) {
+		width = NET_WIDTH;
+	}
+	diameter = eda_config_get_int (cfg, "geda.graphical", "cue_width", NULL);
+	if (!diameter) {
+		diameter = JUNCTION_CUE_SIZE_NET;
+	}
+
+	for (iter = object->conn_list; iter != NULL; iter = g_list_next (iter)) {
+		CONN *conn = (CONN *) iter->data;
+
+		if (conn->type == CONN_ENDPOINT) {
+			continue;
+		}
+		int is_bus = ((object->type == OBJ_BUS) ||
+		              (conn->other_object->type == OBJ_BUS) ||
+		              ((conn->other_object->type == OBJ_PIN) &&
+		               (conn->other_object->pin_type == PIN_TYPE_BUS)));
+		/* Don't show cue if connected to bus.
+		   TODO: It's may be (and definitely will) a source of errors in case of
+		   two or more nets connected at one point of bus. Need to do something,
+		   at least show a clear sign of error. */
+		if (is_bus && (conn->other_object->type != OBJ_PIN)) {
+			continue;
+		}
+
+		if (!eda_renderer_is_drawable_color (renderer, JUNCTION_COLOR, 1)) {
+			return;
+		}
+		eda_cairo_center_arc (renderer->priv->cr,
+		                      EDA_RENDERER_CAIRO_FLAGS (renderer),
+		                      width, -1, conn->x, conn->y, diameter/2, 0, 360);
+		eda_renderer_set_color (renderer, JUNCTION_COLOR);
+		cairo_fill (renderer->priv->cr);
+	}
 }
 
 /* ================================================================

--MP_/dGZFl4awxs6U6xPcnTIdpx0--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019