[cairo-commit] roadster/src import_tiger.c, 1.23, 1.24 map.c, 1.54,
1.55 test_poly.c, 1.1, 1.2 util.c, 1.16, 1.17 util.h, 1.16, 1.17
Ian McIntosh
commit at pdx.freedesktop.org
Tue Oct 11 20:04:07 PDT 2005
Committed by: ian
Update of /cvs/cairo/roadster/src
In directory gabe:/tmp/cvs-serv19441/src
Modified Files:
import_tiger.c map.c test_poly.c util.c util.h
Log Message:
* src/test_poly.c: Add checkbox to hide original line.
* src/import_tiger.c: Fix cleanup code (remove memory leak?)
* src/util.c: Add util_g_free_with_param, a generic g_free-like callback that takes an (unused) user-data param.
Index: import_tiger.c
===================================================================
RCS file: /cvs/cairo/roadster/src/import_tiger.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- import_tiger.c 10 Oct 2005 07:07:36 -0000 1.23
+++ import_tiger.c 12 Oct 2005 03:04:05 -0000 1.24
@@ -103,6 +103,13 @@
GPtrArray* pPointsArray;
} tiger_record_rt2_t;
+void callback_free_rt2(gpointer p)
+{
+ tiger_record_rt2_t* pRT2 = (tiger_record_rt2_t*)p;
+ g_ptr_array_foreach(pRT2->pPointsArray, util_g_free_with_param, NULL);
+ g_free(pRT2);
+}
+
#define TIGER_LANDMARK_NAME_LEN (30)
typedef struct tiger_record_rt7
{
@@ -125,19 +132,6 @@
gint nPointBTZID; // the unique # for the rt1's PointB
} tiger_rt1_link_t;
-typedef struct tiger_import_process {
- gchar* pszFileDescription;
-
- GHashTable* pTableRT1;
- GHashTable* pTableRT2;
- GHashTable* pTableRT7;
- GHashTable* pTableRT8;
- GHashTable* pTableRTi;
- GHashTable* pTableRTc;
-
- GPtrArray* pBoundaryRT1s;
-} tiger_import_process_t;
-
typedef struct tiger_record_rti
{
// store a list of TLIDs for a polygonID
@@ -145,6 +139,13 @@
GPtrArray* pRT1LinksArray;
} tiger_record_rti_t;
+void callback_free_rti(gpointer p)
+{
+ tiger_record_rti_t* pRTi = (tiger_record_rti_t*)p;
+ g_ptr_array_foreach(pRTi->pRT1LinksArray, util_g_free_with_param, NULL);
+ g_free(pRTi);
+}
+
#define TIGER_CITY_NAME_LEN (60)
#define TIGER_FIPS55_LEN (5)
typedef struct tiger_record_rtc
@@ -155,6 +156,19 @@
gint nCityID; // a database ID, stored here after it is inserted
} tiger_record_rtc_t;
+typedef struct tiger_import_process {
+ gchar* pszFileDescription;
+
+ GHashTable* pTableRT1;
+ GHashTable* pTableRT2;
+ GHashTable* pTableRT7;
+ GHashTable* pTableRT8;
+ GHashTable* pTableRTi;
+ GHashTable* pTableRTc;
+
+ GPtrArray* pBoundaryRT1s;
+} tiger_import_process_t;
+
// #define MAP_OBJECT_TYPE_NONE (0)
// #define MAP_OBJECT_TYPE_MINORROAD (1)
// #define MAP_OBJECT_TYPE_MAJORROAD (2)
@@ -1303,7 +1317,7 @@
importProcess.pBoundaryRT1s = g_ptr_array_new();
g_print("parsing RT1\n");
- importProcess.pTableRT1 = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, NULL);
+ importProcess.pTableRT1 = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, g_free);
import_tiger_parse_table_1(pBufferRT1, nLengthRT1, importProcess.pTableRT1, importProcess.pBoundaryRT1s);
g_print("RT1: %d records\n", g_hash_table_size(importProcess.pTableRT1));
@@ -1311,7 +1325,7 @@
importwindow_progress_pulse();
g_print("parsing RT2\n");
- importProcess.pTableRT2 = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, NULL);
+ importProcess.pTableRT2 = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, callback_free_rt2);
import_tiger_parse_table_2(pBufferRT2, nLengthRT2, importProcess.pTableRT2);
g_print("RT2: %d records\n", g_hash_table_size(importProcess.pTableRT2));
@@ -1319,7 +1333,7 @@
importwindow_progress_pulse();
g_print("parsing RT7\n");
- importProcess.pTableRT7 = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, NULL);
+ importProcess.pTableRT7 = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, g_free);
import_tiger_parse_table_7(pBufferRT7, nLengthRT7, importProcess.pTableRT7);
g_print("RT7: %d records\n", g_hash_table_size(importProcess.pTableRT7));
@@ -1327,7 +1341,7 @@
importwindow_progress_pulse();
g_print("parsing RT8\n");
- importProcess.pTableRT8 = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, NULL);
+ importProcess.pTableRT8 = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, g_free);
import_tiger_parse_table_8(pBufferRT8, nLengthRT8, importProcess.pTableRT8);
g_print("RT8: %d records\n", g_hash_table_size(importProcess.pTableRT8));
@@ -1335,12 +1349,12 @@
importwindow_progress_pulse();
g_print("parsing RTc\n");
- importProcess.pTableRTc = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, NULL);
+ importProcess.pTableRTc = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, g_free);
import_tiger_parse_table_c(pBufferRTc, nLengthRTc, importProcess.pTableRTc);
g_print("RTc: %d records\n", g_hash_table_size(importProcess.pTableRTc));
g_print("parsing RTi\n");
- importProcess.pTableRTi = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, NULL);
+ importProcess.pTableRTi = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, callback_free_rti);
import_tiger_parse_table_i(pBufferRTi, nLengthRTi, importProcess.pTableRTi);
g_print("RTi: %d records\n", g_hash_table_size(importProcess.pTableRTi));
@@ -1385,11 +1399,12 @@
g_hash_table_destroy(importProcess.pTableRT7);
g_hash_table_destroy(importProcess.pTableRT8);
g_hash_table_destroy(importProcess.pTableRTc);
+
// XXX: this call sometimes segfaults:
- g_warning("leaking some memory due to unsolved bug in import. just restart roadster after/between imports ;)\n");
- //g_hash_table_destroy(importProcess.pTableRTi);
- g_free(importProcess.pszFileDescription);
+ //g_warning("leaking some memory due to unsolved bug in import. just restart roadster after/between imports ;)\n");
+ g_hash_table_destroy(importProcess.pTableRTi);
+ g_free(importProcess.pszFileDescription);
return TRUE;
}
Index: map.c
===================================================================
RCS file: /cvs/cairo/roadster/src/map.c,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- map.c 11 Oct 2005 23:28:45 -0000 1.54
+++ map.c 12 Oct 2005 03:04:05 -0000 1.55
@@ -98,10 +98,10 @@
{ 3300000, UNIT_MILES, 5, UNIT_KILOMETERS, 7, 3, 2}, // 15
{ 2750000, UNIT_MILES, 5, UNIT_KILOMETERS, 7, 3, 2}, // 16
- { 2200000, UNIT_MILES, 8, UNIT_KILOMETERS, 5, 4, 1}, // *17
- { 1832250, UNIT_MILES, 8, UNIT_KILOMETERS, 5, 4, 1}, // 18
- { 1464500, UNIT_MILES, 8, UNIT_KILOMETERS, 5, 4, 1}, // 19
- { 1100000, UNIT_MILES, 8, UNIT_KILOMETERS, 5, 4, 1}, // 20
+ { 2200000, UNIT_MILES,20, UNIT_KILOMETERS,15, 4, 1}, // *17
+ { 1832250, UNIT_MILES,20, UNIT_KILOMETERS,15, 4, 1}, // 18
+ { 1464500, UNIT_MILES,20, UNIT_KILOMETERS,15, 4, 1}, // 19
+ { 1100000, UNIT_MILES,20, UNIT_KILOMETERS,15, 4, 1}, // 20
{ 729000, UNIT_MILES,10, UNIT_KILOMETERS, 8, 5, 1}, // *21
{ 607500, UNIT_MILES,10, UNIT_KILOMETERS, 8, 5, 1}, // 22
Index: test_poly.c
===================================================================
RCS file: /cvs/cairo/roadster/src/test_poly.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- test_poly.c 11 Oct 2005 23:28:45 -0000 1.1
+++ test_poly.c 12 Oct 2005 03:04:05 -0000 1.2
@@ -19,14 +19,14 @@
GtkButton* pClearButton;
GtkDrawingArea* pDrawingArea;
GtkLabel* pLabel;
+ GtkCheckButton* pHideDrawingCheckButton;
GArray* pPointsArray;
} g_Test_Poly;
-static gboolean on_time_to_update(GtkWidget *pDrawingArea, GdkEventExpose *event, gpointer data);
-static void test_poly_draw();
-static gboolean on_mouse_button_click(GtkWidget* w, GdkEventButton *event);
-static gboolean on_clear_clicked(GtkWidget* w, GdkEventButton *event);
+static gboolean test_poly_on_time_to_update(GtkWidget *pDrawingArea, GdkEventExpose *event, gpointer data);
+static gboolean test_poly_on_mouse_button_click(GtkWidget* w, GdkEventButton *event);
+static gboolean test_poly_on_clearbutton_clicked(GtkWidget* w, GdkEventButton *event);
void test_poly_init(GladeXML* pGladeXML)
{
@@ -36,22 +36,23 @@
GLADE_LINK_WIDGET(pGladeXML, g_Test_Poly.pClearButton, GTK_BUTTON, "test_poly_clear_button");
GLADE_LINK_WIDGET(pGladeXML, g_Test_Poly.pLabel, GTK_LABEL, "test_polylabel");
GLADE_LINK_WIDGET(pGladeXML, g_Test_Poly.pDrawingArea, GTK_DRAWING_AREA, "test_polydrawingarea");
+ GLADE_LINK_WIDGET(pGladeXML, g_Test_Poly.pHideDrawingCheckButton, GTK_CHECK_BUTTON, "test_polyhidecheck");
g_Test_Poly.pPointsArray = g_array_new(FALSE, FALSE, sizeof(mappoint_t));
// Drawing area
gtk_widget_set_double_buffered(GTK_WIDGET(g_Test_Poly.pDrawingArea), FALSE);
gtk_widget_add_events(GTK_WIDGET(g_Test_Poly.pDrawingArea), GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK);
- g_signal_connect(G_OBJECT(g_Test_Poly.pDrawingArea), "expose-event", G_CALLBACK(on_time_to_update), NULL);
- g_signal_connect(G_OBJECT(g_Test_Poly.pDrawingArea), "button_press_event", G_CALLBACK(on_mouse_button_click), NULL);
+ g_signal_connect(G_OBJECT(g_Test_Poly.pDrawingArea), "expose-event", G_CALLBACK(test_poly_on_time_to_update), NULL);
+ g_signal_connect(G_OBJECT(g_Test_Poly.pDrawingArea), "button_press_event", G_CALLBACK(test_poly_on_mouse_button_click), NULL);
// Scale
- g_signal_connect(G_OBJECT(g_Test_Poly.pScale), "value-changed", G_CALLBACK(on_time_to_update), NULL);
+ g_signal_connect(G_OBJECT(g_Test_Poly.pScale), "value-changed", G_CALLBACK(test_poly_on_time_to_update), NULL);
// make it instant-change using our hacky callback
//g_signal_connect(G_OBJECT(g_Test_Poly.pScale), "change-value", G_CALLBACK(util_gtk_range_instant_set_on_value_changing_callback), NULL);
// "Clear" button
- g_signal_connect(G_OBJECT(g_Test_Poly.pClearButton), "clicked", G_CALLBACK(on_clear_clicked), NULL);
+ g_signal_connect(G_OBJECT(g_Test_Poly.pClearButton), "clicked", G_CALLBACK(test_poly_on_clearbutton_clicked), NULL);
// don't delete window on X, just hide it
g_signal_connect(G_OBJECT(g_Test_Poly.pWindow), "delete_event", G_CALLBACK(gtk_widget_hide), NULL);
@@ -62,13 +63,22 @@
gtk_widget_show(GTK_WIDGET(g_Test_Poly.pWindow));
}
-static gboolean on_clear_clicked(GtkWidget* w, GdkEventButton *event)
+//
+// callbacks etc.
+//
+static gboolean test_poly_on_clearbutton_clicked(GtkWidget* w, GdkEventButton *event)
{
g_array_remove_range(g_Test_Poly.pPointsArray, 0, g_Test_Poly.pPointsArray->len);
gtk_widget_queue_draw(GTK_WIDGET(g_Test_Poly.pDrawingArea));
+ return TRUE;
}
-static gboolean on_mouse_button_click(GtkWidget* w, GdkEventButton *event)
+gboolean test_poly_on_hidecheck_toggled(GtkWidget* w, GdkEventButton *event)
+{
+ gtk_widget_queue_draw(GTK_WIDGET(g_Test_Poly.pDrawingArea));
+}
+
+static gboolean test_poly_on_mouse_button_click(GtkWidget* w, GdkEventButton *event)
{
gint nX, nY;
gdk_window_get_pointer(w->window, &nX, &nY, NULL);
@@ -81,10 +91,11 @@
point.fLatitude = (gdouble)nY / (gdouble)nHeight;
g_array_append_val(g_Test_Poly.pPointsArray, point);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_Test_Poly.pHideDrawingCheckButton), FALSE);
gtk_widget_queue_draw(GTK_WIDGET(g_Test_Poly.pDrawingArea));
}
-void test_poly_draw_array(cairo_t* pCairo, GArray* pArray)
+static void test_poly_draw_array(cairo_t* pCairo, GArray* pArray)
{
if(pArray->len >= 1) {
mappoint_t* pPoint;
@@ -103,18 +114,16 @@
}
}
-static gboolean on_time_to_update(GtkWidget *pDrawingArea, GdkEventExpose *event, gpointer data)
+static gboolean test_poly_on_time_to_update(GtkWidget *pDrawingArea, GdkEventExpose *event, gpointer data)
{
- Display* dpy;
- Drawable drawable;
- dpy = gdk_x11_drawable_get_xdisplay(GTK_WIDGET(g_Test_Poly.pDrawingArea)->window);
+ Display* dpy = gdk_x11_drawable_get_xdisplay(GTK_WIDGET(g_Test_Poly.pDrawingArea)->window);
Visual *visual = DefaultVisual (dpy, DefaultScreen (dpy));
+ Drawable drawable = gdk_x11_drawable_get_xid(GTK_WIDGET(g_Test_Poly.pDrawingArea)->window);
gint width, height;
- drawable = gdk_x11_drawable_get_xid(GTK_WIDGET(g_Test_Poly.pDrawingArea)->window);
gdk_drawable_get_size (GTK_WIDGET(g_Test_Poly.pDrawingArea)->window, &width, &height);
cairo_surface_t *pSurface = cairo_xlib_surface_create (dpy, drawable, visual, width, height);
- gdouble fValue = gtk_range_get_value(g_Test_Poly.pScale);
+ gdouble fValue = gtk_range_get_value(GTK_RANGE(g_Test_Poly.pScale));
cairo_t* pCairo = cairo_create (pSurface);
@@ -125,13 +134,15 @@
cairo_fill(pCairo);
// Draw lines
- cairo_set_line_join(pCairo, CAIRO_LINE_JOIN_ROUND);
- cairo_save(pCairo);
- cairo_set_line_width(pCairo, 0.02);
- cairo_set_source_rgba(pCairo, 1.0, 0.0, 0.0, 1.0);
- test_poly_draw_array(pCairo, g_Test_Poly.pPointsArray);
- cairo_stroke(pCairo);
- cairo_restore(pCairo);
+ if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g_Test_Poly.pHideDrawingCheckButton)) == FALSE) {
+ cairo_set_line_join(pCairo, CAIRO_LINE_JOIN_ROUND);
+ cairo_save(pCairo);
+ cairo_set_line_width(pCairo, 0.02);
+ cairo_set_source_rgba(pCairo, 1.0, 0.0, 0.0, 1.0);
+ test_poly_draw_array(pCairo, g_Test_Poly.pPointsArray);
+ cairo_stroke(pCairo);
+ cairo_restore(pCairo);
+ }
cairo_save(pCairo);
GArray* pSimplified = g_array_new(FALSE, FALSE, sizeof(mappoint_t));
@@ -156,54 +167,3 @@
g_array_free(pSimplified, TRUE);
return TRUE;
}
-
-// static void paint (GtkWidget *widget,GdkEventExpose *eev,gpointer data)
-// {
-// gint width, height;
-// gint i;
-// cairo_t *cr;
-//
-// width = widget->allocation.width;
-// height = widget->allocation.height;
-//
-// cr = gdk_cairo_create (widget->window);
-//
-// /* clear background */
-// cairo_set_source_rgb (cr, 1,1,1);
-// cairo_paint (cr);
-//
-//
-// cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL,
-// CAIRO_FONT_WEIGHT_BOLD);
-//
-// /* enclosing in a save/restore pair since we alter the
-// * font size
-// */
-// cairo_save (cr);
-// cairo_set_font_size (cr, 40);
-// cairo_move_to (cr, 40, 60);
-// cairo_set_source_rgb (cr, 0,0,0);
-// cairo_show_text (cr, "Hello World");
-// cairo_restore (cr);
-//
-// cairo_set_source_rgb (cr, 1,0,0);
-// cairo_set_font_size (cr, 20);
-// cairo_move_to (cr, 50, 100);
-// cairo_show_text (cr, "greetings from gtk and cairo");
-//
-// cairo_set_source_rgb (cr, 0,0,1);
-//
-// cairo_move_to (cr, 0, 150);
-// for (i=0; i< width/10; i++)
-// {
-// cairo_rel_line_to (cr, 5, 10);
-// cairo_rel_line_to (cr, 5, -10);
-// }
-// cairo_stroke (cr);
-//
-// cairo_destroy (cr);
-// }
-//
-// static gboolean on_expose_event(GtkWidget *pDrawingArea, GdkEventExpose *event, gpointer data)
-// {
-// }
Index: util.c
===================================================================
RCS file: /cvs/cairo/roadster/src/util.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- util.c 10 Oct 2005 07:07:36 -0000 1.16
+++ util.c 12 Oct 2005 03:04:05 -0000 1.17
@@ -540,3 +540,9 @@
g_ascii_dtostr(achBuffer, 20, d);
return g_strdup(achBuffer);
}
+
+void util_g_free_with_param(gpointer pMemory, gpointer _unused)
+{
+ g_assert(pMemory != NULL);
+ g_free(pMemory);
+}
Index: util.h
===================================================================
RCS file: /cvs/cairo/roadster/src/util.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- util.h 10 Oct 2005 07:07:36 -0000 1.16
+++ util.h 12 Oct 2005 03:04:05 -0000 1.17
@@ -87,5 +87,6 @@
gchar* util_format_gdouble(gdouble d);
+void util_g_free_with_param(gpointer pMemory, gpointer _unused);
#endif
More information about the cairo-commit
mailing list