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

gEDA-user: Part (and net) identifying tooltips for PCB



Does the attached patch inspire anyone to have a play and improve it?

I've knocked it together as a proof of concept. The APIs used were
introduced in GTK 2.12 unfortunately (I didn't see much point writing
new code using the old deprecated APIs which weren't as useful).

The patch works, but probably has some short-comings. I think I'm going
to find is useful myself, and will probably soon wonder how I lived
without it...

Those using any of my repository branches get to try it out "for
free" ;)

Best wishes,

-- 
Peter Clifton

Electrical Engineering Division,
Engineering Department,
University of Cambridge,
9, JJ Thomson Avenue,
Cambridge
CB3 0FA

Tel: +44 (0)7729 980173 - (No signal in the lab!)

From c2c19d7a59cb4a98e879d61cd50a993270f07f2b Mon Sep 17 00:00:00 2001
From: Peter Clifton <pcjc2@xxxxxxxxx>
Date: Fri, 26 Feb 2010 01:08:25 +0000
Subject: [PATCH] hid/gtk: Add tool-tip to identify element, pin and net when hovering

---
 src/hid/gtk/gui-output-events.c |  125 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 125 insertions(+), 0 deletions(-)

diff --git a/src/hid/gtk/gui-output-events.c b/src/hid/gtk/gui-output-events.c
index 86abad2..7466e59 100644
--- a/src/hid/gtk/gui-output-events.c
+++ b/src/hid/gtk/gui-output-events.c
@@ -44,11 +44,16 @@
 #include "error.h"
 #include "misc.h"
 #include "set.h"
+#include "find.h"
+#include "search.h"
+#include "rats.h"
 
 #ifdef HAVE_LIBDMALLOC
 #include <dmalloc.h>
 #endif
 
+#define TOOLTIP_UPDATE_DELAY 200
+
 RCSID ("$Id$");
 
 static gint x_pan_speed, y_pan_speed;
@@ -742,6 +747,123 @@ ghid_port_drawing_area_expose_event_cb (GtkWidget * widget,
   return FALSE;
 }
 
+
+static char *
+describe_location (LocationType X, LocationType Y)
+{
+  void *ptr1, *ptr2, *ptr3;
+  int type;
+  int Range = 0;
+  char *elename;
+  char *pinname;
+  char *netname = NULL;
+  char *description;
+
+  /* check if there are any pins or pads at that position */
+
+  type = SearchObjectByLocation (LOOKUP_FIRST,
+                                 &ptr1, &ptr2, &ptr3, X, Y, Range);
+  if (type == NO_TYPE)
+    type = SearchObjectByLocation (LOOKUP_MORE,
+                                   &ptr1, &ptr2, &ptr3, X, Y, Range);
+
+  if (type == NO_TYPE)
+    return NULL;
+
+  /* don't mess with silk objects! */
+  if (type & SILK_TYPE &&
+      GetLayerNumber (PCB->Data, (LayerTypePtr) ptr1) >= max_layer)
+    return NULL;
+
+  elename = UNKNOWN (NAMEONPCB_NAME ((ElementTypePtr) ptr1));
+  pinname = ConnectionName (type, ptr1, ptr2);
+
+  if (pinname == NULL)
+    return NULL;
+
+  /* Find netlist entry */
+  MENU_LOOP (&PCB->NetlistLib);
+  {
+    if (!menu->Name)
+    continue;
+
+    ENTRY_LOOP (menu);
+    {
+      if (!entry->ListEntry)
+        continue;
+
+      if (strcmp (entry->ListEntry, pinname) == 0) {
+        netname = g_strdup (menu->Name);
+        /* For some reason, the netname has spaces in front of it, strip them */
+        g_strstrip (netname);
+        break;
+      }
+    }
+    END_LOOP;
+
+    if (netname != NULL)
+      break;
+  }
+  END_LOOP;
+
+  description = g_strdup_printf ("Element name: %s\n"
+                                 "Pinname : %s\n"
+                                 "Netname : %s",
+                                 elename,
+                                 (pinname != NULL) ? pinname : "--",
+                                 (netname != NULL) ? netname : "--");
+
+  g_free (netname);
+
+  return description;
+}
+
+
+static gboolean check_object_tooltips (GHidPort *out)
+{
+  char *description;
+
+  /* check if there are any pins or pads at that position */
+  description = describe_location (out->x_crosshair, out->y_crosshair);
+
+  if (description == NULL)
+    return FALSE;
+
+  gtk_widget_set_tooltip_text (out->drawing_area, description);
+  g_free (description);
+
+  return FALSE;
+}
+
+static int tooltip_update_timeout_id = 0;
+
+static void
+cancel_tooltip_update ()
+{
+  if (tooltip_update_timeout_id)
+    g_source_remove (tooltip_update_timeout_id);
+  tooltip_update_timeout_id = 0;
+}
+
+/* FIXME: If the GHidPort is ever destroyed, we must call
+ * cancel_tooltip_update (), otherwise the timeout might
+ * fire after the data it utilises has been free'd.
+ */
+static void
+queue_tooltip_update (GHidPort *out)
+{
+  /* Zap the old tool-tip text and force it to be removed from the screen */
+  gtk_widget_set_tooltip_text (out->drawing_area, NULL);
+  gtk_widget_trigger_tooltip_query (out->drawing_area);
+
+  cancel_tooltip_update ();
+
+  tooltip_update_timeout_id =
+      g_timeout_add (TOOLTIP_UPDATE_DELAY,
+                     (GSourceFunc) check_object_tooltips,
+                     out);
+}
+
 gint
 ghid_port_window_motion_cb (GtkWidget * widget,
 			    GdkEventButton * ev, GHidPort * out)
@@ -764,6 +886,9 @@ ghid_port_window_motion_cb (GtkWidget * widget,
     }
   x_prev = y_prev = -1;
   moved = ghid_note_event_location (ev);
+
+  queue_tooltip_update (out);
+
   ghid_show_crosshair (TRUE);
   if (moved && have_crosshair_attachments ())
     ghid_draw_area_update (gport, NULL);
-- 
1.7.0


_______________________________________________
geda-user mailing list
geda-user@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user