From 6d9eff9db89360fafe79493fe0f9bc907499a899 Mon Sep 17 00:00:00 2001 From: Valerio Mariani Date: Tue, 28 Jan 2014 13:36:27 +0100 Subject: Implemented calibration mode --- data/hdfsee.ui | 1 + src/dw-hdfsee.c | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/dw-hdfsee.h | 4 +- src/hdfsee.c | 5 ++- 4 files changed, 140 insertions(+), 4 deletions(-) diff --git a/data/hdfsee.ui b/data/hdfsee.ui index 0d00164b..873fe062 100644 --- a/data/hdfsee.ui +++ b/data/hdfsee.ui @@ -25,6 +25,7 @@ + diff --git a/src/dw-hdfsee.c b/src/dw-hdfsee.c index 75232b12..73a56832 100644 --- a/src/dw-hdfsee.c +++ b/src/dw-hdfsee.c @@ -39,6 +39,7 @@ #include #include #include +#include #include "dw-hdfsee.h" #include "hdfsee-render.h" @@ -1012,6 +1013,26 @@ static int load_geometry_file(DisplayWindow *dw, struct image *image, return 0; } +static int save_geometry_file(DisplayWindow *dw) +{ + GtkWidget *d; + gchar * filename; + int w; + + d = gtk_file_chooser_dialog_new("Save Calibration Geometry", + GTK_WINDOW(dw->window), + GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, + NULL); + + gtk_dialog_run (GTK_DIALOG (d)); + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER (d)); + w = write_detector_geometry(filename, dw->image->det); + gtk_widget_destroy(d); + g_free(filename); + return w; +} static gint displaywindow_loadgeom_response(GtkWidget *d, gint response, DisplayWindow *dw) @@ -1096,6 +1117,25 @@ static gint displaywindow_set_usegeom(GtkWidget *d, DisplayWindow *dw) return 0; } +static gint displaywindow_set_calibmode(GtkWidget *d, DisplayWindow *dw) +{ + + GtkWidget *w; + w = gtk_ui_manager_get_widget(dw->ui, + "/ui/displaywindow/tools/calibmode"); + + if (dw->use_geom == 0) { + gtk_check_menu_item_set_state(GTK_CHECK_MENU_ITEM(w),0); + } else { + + /* Get new value */ + dw->calib_mode = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w)); + + displaywindow_update(dw); + } + + return 0; +} static gint displaywindow_set_rings(GtkWidget *d, DisplayWindow *dw) { @@ -1495,6 +1535,8 @@ static void displaywindow_addmenubar(DisplayWindow *dw, GtkWidget *vbox, GtkToggleActionEntry toggles[] = { { "GeometryAction", NULL, "Use Detector Geometry", NULL, NULL, G_CALLBACK(displaywindow_set_usegeom), FALSE }, + { "CalibModeAction", NULL, "Calibration Mode", NULL, NULL, + G_CALLBACK(displaywindow_set_calibmode), FALSE }, { "ColScaleAction", NULL, "Colour Scale", NULL, NULL, G_CALLBACK(displaywindow_set_colscale), FALSE }, { "RingsAction", NULL, "Resolution Rings", "F9", NULL, @@ -1818,9 +1860,80 @@ static gint displaywindow_press(GtkWidget *widget, GdkEventButton *event, } +static gint displaywindow_keypress(GtkWidget *widget, GdkEventKey *event, + DisplayWindow *dw) +{ + int pi,s; + + if (dw->calib_mode == 0) { + return 0; + } + + switch (event->keyval) { + + case GDK_Up: + for (pi=0;piimage->det->rigid_groups[dw->calib_mode_curr_quad]->n_panels;++pi) { + dw->image->det->rigid_groups[dw->calib_mode_curr_quad]->panels[pi]->cny += 1.0; + } + redraw_window(dw); + break; + + case GDK_Down: + for (pi=0;piimage->det->rigid_groups[dw->calib_mode_curr_quad]->n_panels;++pi) { + dw->image->det->rigid_groups[dw->calib_mode_curr_quad]->panels[pi]->cny -= 1.0; + } + while (gtk_events_pending()) { + gtk_main_iteration_do(FALSE); + } + redraw_window(dw); + break; + + case GDK_Left: + for (pi=0;piimage->det->rigid_groups[dw->calib_mode_curr_quad]->n_panels;++pi) { + dw->image->det->rigid_groups[dw->calib_mode_curr_quad]->panels[pi]->cnx -= 1.0; + } + redraw_window(dw); + break; + + case GDK_Right: + for (pi=0;piimage->det->rigid_groups[dw->calib_mode_curr_quad]->n_panels;++pi) { + dw->image->det->rigid_groups[dw->calib_mode_curr_quad]->panels[pi]->cnx += 1.0; + } + redraw_window(dw); + break; + + case GDK_1: + dw->calib_mode_curr_quad = 0; + break; + + case GDK_2: + dw->calib_mode_curr_quad = 1; + break; + + case GDK_3: + dw->calib_mode_curr_quad = 2; + break; + + case GDK_4: + dw->calib_mode_curr_quad = 3; + break; + + case GDK_s: + s = save_geometry_file(dw); + if ( s != 0 ) { + if ( s != 2 ) { + displaywindow_error(dw, "Unable to save the calibration geometry."); + } + } + break; + } + + return 0; +} + DisplayWindow *displaywindow_open(const char *filename, const char *peaks, double boost, int binning, - int noisefilter, int colscale, + int noisefilter, int calibmode, int colscale, const char *element, const char *geometry, const char *beam, int show_rings, double *ring_radii, @@ -1831,6 +1944,7 @@ DisplayWindow *displaywindow_open(const char *filename, const char *peaks, char *title; GtkWidget *vbox; GtkWidget *w; + GtkWidget *ww; dw = calloc(1, sizeof(DisplayWindow)); if ( dw == NULL ) return NULL; @@ -1857,6 +1971,8 @@ DisplayWindow *displaywindow_open(const char *filename, const char *peaks, dw->n_rings = n_rings; dw->median_filter = median_filter; dw->image = calloc(1, sizeof(struct image)); + dw->calib_mode = 0; + dw->calib_mode_curr_quad = 0; if ( beam != NULL ) { dw->image->beam = get_beam_parameters(beam); @@ -1940,18 +2056,32 @@ DisplayWindow *displaywindow_open(const char *filename, const char *peaks, load_geometry_file(dw, dw->image, geometry); } + if (dw->use_geom == 1) { + dw->calib_mode = calibmode; + } + + if (dw->calib_mode == 1) { + ww = gtk_ui_manager_get_widget(dw->ui, "/ui/displaywindow/tools/calibmode"); + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ww), TRUE); + } + displaywindow_update(dw); gtk_widget_add_events(GTK_WIDGET(dw->drawingarea), GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - | GDK_BUTTON1_MOTION_MASK); + | GDK_BUTTON1_MOTION_MASK + | GDK_KEY_PRESS_MASK); g_object_set(G_OBJECT(dw->drawingarea), "can-focus", TRUE, NULL); + gtk_widget_grab_focus(dw->drawingarea); + g_signal_connect(GTK_OBJECT(dw->drawingarea), "button-press-event", G_CALLBACK(displaywindow_press), dw); g_signal_connect(GTK_OBJECT(dw->drawingarea), "button-release-event", G_CALLBACK(displaywindow_release), dw); + g_signal_connect(GTK_OBJECT(dw->drawingarea), "key-press-event", + G_CALLBACK(displaywindow_keypress), dw); displaywindow_update_menus(dw, element); dw->not_ready_yet = 0; diff --git a/src/dw-hdfsee.h b/src/dw-hdfsee.h index 92ca9d42..fcffd130 100644 --- a/src/dw-hdfsee.h +++ b/src/dw-hdfsee.h @@ -108,6 +108,8 @@ typedef struct { double ring_radius; double *ring_radii; int n_rings; + int calib_mode; + int calib_mode_curr_quad; int show_col_scale; int scale; @@ -119,7 +121,7 @@ typedef struct { extern DisplayWindow *displaywindow_open(const char *filename, const char *peaks, double boost, int binning, - int noisefilter, int colscale, + int noisefilter, int calibmode, int colscale, const char *element, const char *geometry, const char *beam, int show_rings, diff --git a/src/hdfsee.c b/src/hdfsee.c index df0bd281..49c4775f 100644 --- a/src/hdfsee.c +++ b/src/hdfsee.c @@ -61,7 +61,7 @@ static void show_help(const char *s) " --filter-noise Apply an aggressive noise filter to the\n" " image data.\n" " --median-filter= Apply a median filter to the image data.\n" - +" --calibration-mode Starts in calibration mode\n" " --show-rings Overlay rings that indicate resolution.\n" " --simple-rings=XX,YY,... Overlay rings at specified radii XX, YY, ...\n" " in pixel units.\n" @@ -115,6 +115,7 @@ int main(int argc, char *argv[]) int binning = 2; int config_noisefilter = 0; int config_showrings = 0; + int config_calibmode =0; int colscale = SCALE_COLOUR; char *cscale = NULL; char *element = NULL; @@ -141,6 +142,7 @@ int main(int argc, char *argv[]) {"ring-size", 1, NULL, 2}, {"simple-rings", 1, NULL, 'r'}, {"median-filter", 1, NULL, 3}, + {"calibration-mode", 0, &config_calibmode, 1}, {0, 0, NULL, 0} }; @@ -276,6 +278,7 @@ int main(int argc, char *argv[]) main_window_list[i] = displaywindow_open(argv[optind+i], peaks, boost, binning, config_noisefilter, + config_calibmode, colscale, element, geometry, beam, config_showrings, -- cgit v1.2.3 From b42fa256f456c13800c8dec026d0802561fa098d Mon Sep 17 00:00:00 2001 From: Valerio Mariani Date: Wed, 29 Jan 2014 17:24:15 +0100 Subject: Arrow keys can be used to move to the previous/next quadrant, with wraparound --- src/dw-hdfsee.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/dw-hdfsee.c b/src/dw-hdfsee.c index 73a56832..57033916 100644 --- a/src/dw-hdfsee.c +++ b/src/dw-hdfsee.c @@ -1902,7 +1902,23 @@ static gint displaywindow_keypress(GtkWidget *widget, GdkEventKey *event, redraw_window(dw); break; - case GDK_1: + case GDK_plus: + if (dw->calib_mode_curr_quad == (dw->image->det->n_rigid_groups-1)) { + dw->calib_mode_curr_quad = 0; + } else { + dw->calib_mode_curr_quad += 1; + } + break; + + case GDK_minus: + if (dw->calib_mode_curr_quad == 0) { + dw->calib_mode_curr_quad = (dw->image->det->n_rigid_groups-1); + } else { + dw->calib_mode_curr_quad -= 1; + } + break; + + case GDK_1: dw->calib_mode_curr_quad = 0; break; -- cgit v1.2.3 From 70af22f8092f09a795aa4f9b4725d0876311c783 Mon Sep 17 00:00:00 2001 From: Valerio Mariani Date: Thu, 6 Feb 2014 14:17:26 +0100 Subject: Focus rectangle on active group. Can be toggled Support for numpad keys --- src/dw-hdfsee.c | 98 +++++++++++++++++++++++++++++++++++++++++++++------------ src/dw-hdfsee.h | 3 +- 2 files changed, 80 insertions(+), 21 deletions(-) diff --git a/src/dw-hdfsee.c b/src/dw-hdfsee.c index 57033916..45655998 100644 --- a/src/dw-hdfsee.c +++ b/src/dw-hdfsee.c @@ -139,6 +139,32 @@ static void draw_panel_rectangle(cairo_t *cr, cairo_matrix_t *basic_m, cairo_rectangle(cr, 0.0, 0.0, w, h); } +static void draw_calib_focus_rectangle(cairo_t *cr, cairo_matrix_t *basic_m, + DisplayWindow *dw, int i) +{ + struct panel p = dw->image->det->panels[i]; + int w = gdk_pixbuf_get_width(dw->pixbufs[i]); + int h = gdk_pixbuf_get_height(dw->pixbufs[i]); + cairo_matrix_t m; + + /* Start with the basic coordinate system */ + cairo_set_matrix(cr, basic_m); + + /* Move to the right location */ + cairo_translate(cr, p.cnx/dw->binning, + p.cny/dw->binning); + + /* Twiddle directions according to matrix */ + cairo_matrix_init(&m, p.fsx, p.fsy, p.ssx, p.ssy, + 0.0, 0.0); + cairo_transform(cr, &m); + + cairo_set_line_width (cr, 3.0); + cairo_set_source_rgb (cr, 255, 255, 255); + cairo_rectangle(cr, 0.0, 0.0, w, h); + +} + static void show_ring(cairo_t *cr, DisplayWindow *dw, double d, const char *label, cairo_matrix_t *basic_m, @@ -233,6 +259,15 @@ static int draw_stuff(cairo_surface_t *surf, DisplayWindow *dw) draw_panel_rectangle(cr, &basic_m, dw, i); cairo_fill(cr); + if ( dw->calib_mode == 1 && dw->calib_mode_show_focus == 1) { + + if ( dw->image->det->panels[i].rigid_group == dw->image->det->rigid_groups[dw->calib_mode_curr_rg] ) { + draw_calib_focus_rectangle(cr, &basic_m, dw, i); + cairo_stroke(cr); + } + + } + } } @@ -1872,15 +1907,17 @@ static gint displaywindow_keypress(GtkWidget *widget, GdkEventKey *event, switch (event->keyval) { case GDK_Up: - for (pi=0;piimage->det->rigid_groups[dw->calib_mode_curr_quad]->n_panels;++pi) { - dw->image->det->rigid_groups[dw->calib_mode_curr_quad]->panels[pi]->cny += 1.0; + case GDK_KP_Up: + for (pi=0;piimage->det->rigid_groups[dw->calib_mode_curr_rg]->n_panels;++pi) { + dw->image->det->rigid_groups[dw->calib_mode_curr_rg]->panels[pi]->cny += 1.0; } redraw_window(dw); break; case GDK_Down: - for (pi=0;piimage->det->rigid_groups[dw->calib_mode_curr_quad]->n_panels;++pi) { - dw->image->det->rigid_groups[dw->calib_mode_curr_quad]->panels[pi]->cny -= 1.0; + case GDK_KP_Down: + for (pi=0;piimage->det->rigid_groups[dw->calib_mode_curr_rg]->n_panels;++pi) { + dw->image->det->rigid_groups[dw->calib_mode_curr_rg]->panels[pi]->cny -= 1.0; } while (gtk_events_pending()) { gtk_main_iteration_do(FALSE); @@ -1889,49 +1926,68 @@ static gint displaywindow_keypress(GtkWidget *widget, GdkEventKey *event, break; case GDK_Left: - for (pi=0;piimage->det->rigid_groups[dw->calib_mode_curr_quad]->n_panels;++pi) { - dw->image->det->rigid_groups[dw->calib_mode_curr_quad]->panels[pi]->cnx -= 1.0; + case GDK_KP_Left: + for (pi=0;piimage->det->rigid_groups[dw->calib_mode_curr_rg]->n_panels;++pi) { + dw->image->det->rigid_groups[dw->calib_mode_curr_rg]->panels[pi]->cnx -= 1.0; } redraw_window(dw); break; case GDK_Right: - for (pi=0;piimage->det->rigid_groups[dw->calib_mode_curr_quad]->n_panels;++pi) { - dw->image->det->rigid_groups[dw->calib_mode_curr_quad]->panels[pi]->cnx += 1.0; + case GDK_KP_Right: + for (pi=0;piimage->det->rigid_groups[dw->calib_mode_curr_rg]->n_panels;++pi) { + dw->image->det->rigid_groups[dw->calib_mode_curr_rg]->panels[pi]->cnx += 1.0; } redraw_window(dw); break; case GDK_plus: - if (dw->calib_mode_curr_quad == (dw->image->det->n_rigid_groups-1)) { - dw->calib_mode_curr_quad = 0; + case GDK_KP_Add: + if (dw->calib_mode_curr_rg == (dw->image->det->n_rigid_groups-1)) { + dw->calib_mode_curr_rg = 0; } else { - dw->calib_mode_curr_quad += 1; + dw->calib_mode_curr_rg += 1; } + redraw_window(dw); break; case GDK_minus: - if (dw->calib_mode_curr_quad == 0) { - dw->calib_mode_curr_quad = (dw->image->det->n_rigid_groups-1); + case GDK_KP_Subtract: + if (dw->calib_mode_curr_rg == 0) { + dw->calib_mode_curr_rg = (dw->image->det->n_rigid_groups-1); } else { - dw->calib_mode_curr_quad -= 1; + dw->calib_mode_curr_rg -= 1; } + redraw_window(dw); break; - case GDK_1: - dw->calib_mode_curr_quad = 0; + case GDK_1: + dw->calib_mode_curr_rg = 0; + redraw_window(dw); break; case GDK_2: - dw->calib_mode_curr_quad = 1; + dw->calib_mode_curr_rg = 1; + redraw_window(dw); break; case GDK_3: - dw->calib_mode_curr_quad = 2; + dw->calib_mode_curr_rg = 2; + redraw_window(dw); break; case GDK_4: - dw->calib_mode_curr_quad = 3; + dw->calib_mode_curr_rg = 3; + redraw_window(dw); + break; + + case GDK_f: + if ( dw->calib_mode_show_focus == 1 ) { + dw->calib_mode_show_focus = 0; + } else { + dw->calib_mode_show_focus = 1; + } + redraw_window(dw); break; case GDK_s: @@ -1942,6 +1998,7 @@ static gint displaywindow_keypress(GtkWidget *widget, GdkEventKey *event, } } break; + } return 0; @@ -1988,7 +2045,8 @@ DisplayWindow *displaywindow_open(const char *filename, const char *peaks, dw->median_filter = median_filter; dw->image = calloc(1, sizeof(struct image)); dw->calib_mode = 0; - dw->calib_mode_curr_quad = 0; + dw->calib_mode_curr_rg = 0; + dw->calib_mode_show_focus = 1; if ( beam != NULL ) { dw->image->beam = get_beam_parameters(beam); diff --git a/src/dw-hdfsee.h b/src/dw-hdfsee.h index fcffd130..56f22b54 100644 --- a/src/dw-hdfsee.h +++ b/src/dw-hdfsee.h @@ -109,7 +109,8 @@ typedef struct { double *ring_radii; int n_rings; int calib_mode; - int calib_mode_curr_quad; + int calib_mode_curr_rg; + int calib_mode_show_focus; int show_col_scale; int scale; -- cgit v1.2.3 From d9df3e76cca7be254dc2654cd844343b2e748462 Mon Sep 17 00:00:00 2001 From: Valerio Mariani Date: Tue, 11 Feb 2014 12:16:03 +0100 Subject: Group/single panel mode. Some code cleanup --- src/dw-hdfsee.c | 186 ++++++++++++++++++++++++++++++++++++++++++-------------- src/dw-hdfsee.h | 4 +- 2 files changed, 143 insertions(+), 47 deletions(-) diff --git a/src/dw-hdfsee.c b/src/dw-hdfsee.c index 45655998..d30de55f 100644 --- a/src/dw-hdfsee.c +++ b/src/dw-hdfsee.c @@ -261,9 +261,20 @@ static int draw_stuff(cairo_surface_t *surf, DisplayWindow *dw) if ( dw->calib_mode == 1 && dw->calib_mode_show_focus == 1) { - if ( dw->image->det->panels[i].rigid_group == dw->image->det->rigid_groups[dw->calib_mode_curr_rg] ) { - draw_calib_focus_rectangle(cr, &basic_m, dw, i); - cairo_stroke(cr); + if ( dw->calib_mode_groups == 1 ) { + + if ( dw->image->det->panels[i].rigid_group == dw->calib_mode_curr_rg ) { + draw_calib_focus_rectangle(cr, &basic_m, dw, i); + cairo_stroke(cr); + } + + } else { + + if ( &dw->image->det->panels[i] == dw->calib_mode_curr_p) { + draw_calib_focus_rectangle(cr, &basic_m, dw, i); + cairo_stroke(cr); + } + } } @@ -386,7 +397,7 @@ static int draw_stuff(cairo_surface_t *surf, DisplayWindow *dw) cairo_set_line_width(cr, 0.75/dw->binning); cairo_stroke(cr); - +; } } @@ -440,7 +451,7 @@ static void set_window_size(DisplayWindow *dw) dw->height = (max_y - min_y) / dw->binning; /* Add a thin border */ - dw->width += 2.0; + dw->width += 2.0;; dw->height += 2.0; } @@ -971,7 +982,7 @@ static gint displaywindow_peaklist_response(GtkWidget *d, gint response, gtk_widget_destroy(d); - return 0; + return 0;; } @@ -1158,15 +1169,17 @@ static gint displaywindow_set_calibmode(GtkWidget *d, DisplayWindow *dw) GtkWidget *w; w = gtk_ui_manager_get_widget(dw->ui, "/ui/displaywindow/tools/calibmode"); + if ( dw->use_geom == 0 ) { - if (dw->use_geom == 0) { gtk_check_menu_item_set_state(GTK_CHECK_MENU_ITEM(w),0); + } else { /* Get new value */ dw->calib_mode = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w)); displaywindow_update(dw); + } return 0; @@ -1895,92 +1908,154 @@ static gint displaywindow_press(GtkWidget *widget, GdkEventButton *event, } +int curr_rg_pointer_index (DisplayWindow *dw) +{ + int r; + + for ( r=0; rimage->det->n_rigid_groups; ++r) { + if ( dw->image->det->rigid_groups[r] == dw->calib_mode_curr_rg ) { + return r; + } + } + + // should never be reached. Here just to make the compiler happy + return -1; +} + + +int curr_p_pointer_index_in_rg (DisplayWindow *dw) +{ + int p; + + for ( p=0; pcalib_mode_curr_rg->n_panels; ++p) { + if ( dw->calib_mode_curr_rg->panels[p] == dw->calib_mode_curr_p ) { + return p; + } + } + + // should never be reached. Here just to make the compiler happy + return -1; +} + + static gint displaywindow_keypress(GtkWidget *widget, GdkEventKey *event, DisplayWindow *dw) { int pi,s; - if (dw->calib_mode == 0) { + if ( dw->calib_mode == 0 ) { return 0; } - switch (event->keyval) { + int num_rg = dw->image->det->n_rigid_groups; + int num_p; + + switch ( event->keyval ) { case GDK_Up: case GDK_KP_Up: - for (pi=0;piimage->det->rigid_groups[dw->calib_mode_curr_rg]->n_panels;++pi) { - dw->image->det->rigid_groups[dw->calib_mode_curr_rg]->panels[pi]->cny += 1.0; + if ( dw->calib_mode_groups == 1 ) { + for ( pi=0; picalib_mode_curr_rg->n_panels; ++pi ) { + dw->calib_mode_curr_rg->panels[pi]->cny += 1.0; + } + } else { + dw->calib_mode_curr_p->cny += 1.0; } redraw_window(dw); break; + case GDK_Down: case GDK_KP_Down: - for (pi=0;piimage->det->rigid_groups[dw->calib_mode_curr_rg]->n_panels;++pi) { - dw->image->det->rigid_groups[dw->calib_mode_curr_rg]->panels[pi]->cny -= 1.0; - } - while (gtk_events_pending()) { - gtk_main_iteration_do(FALSE); + if ( dw->calib_mode_groups == 1 ) { + for ( pi=0; picalib_mode_curr_rg->n_panels; ++pi ) { + dw->calib_mode_curr_rg->panels[pi]->cny -= 1.0; + } + } else { + dw->calib_mode_curr_p->cny -= 1.0; } redraw_window(dw); break; + case GDK_Left: case GDK_KP_Left: - for (pi=0;piimage->det->rigid_groups[dw->calib_mode_curr_rg]->n_panels;++pi) { - dw->image->det->rigid_groups[dw->calib_mode_curr_rg]->panels[pi]->cnx -= 1.0; + if ( dw->calib_mode_groups == 1 ) { + for ( pi=0; picalib_mode_curr_rg->n_panels; ++pi ) { + dw->calib_mode_curr_rg->panels[pi]->cnx -= 1.0; + } + } else { + dw->calib_mode_curr_p->cnx -= 1.0; } redraw_window(dw); break; + case GDK_Right: case GDK_KP_Right: - for (pi=0;piimage->det->rigid_groups[dw->calib_mode_curr_rg]->n_panels;++pi) { - dw->image->det->rigid_groups[dw->calib_mode_curr_rg]->panels[pi]->cnx += 1.0; + if ( dw->calib_mode_groups == 1) { + for ( pi=0; picalib_mode_curr_rg->n_panels; ++pi ) { + dw->calib_mode_curr_rg->panels[pi]->cnx += 1.0; + } + } else { + dw->calib_mode_curr_p->cnx -= 1.0; } redraw_window(dw); break; + case GDK_plus: case GDK_KP_Add: - if (dw->calib_mode_curr_rg == (dw->image->det->n_rigid_groups-1)) { - dw->calib_mode_curr_rg = 0; + num_p = dw->calib_mode_curr_rg->n_panels; + if ( dw->calib_mode_groups == 1) { + + if ( dw->calib_mode_curr_rg == dw->image->det->rigid_groups[num_rg-1 ] ) { + dw->calib_mode_curr_rg = dw->image->det->rigid_groups[0]; + } else { + dw->calib_mode_curr_rg = + dw->image->det->rigid_groups[curr_rg_pointer_index(dw)+1]; + } + } else { - dw->calib_mode_curr_rg += 1; + + if ( dw->calib_mode_curr_p == dw->calib_mode_curr_rg->panels[num_p-1] ) { + dw->calib_mode_curr_p = dw->calib_mode_curr_rg->panels[0]; + } else { + dw->calib_mode_curr_p = + dw->calib_mode_curr_rg->panels[curr_p_pointer_index_in_rg(dw)+1]; + } + } redraw_window(dw); break; + case GDK_minus: case GDK_KP_Subtract: - if (dw->calib_mode_curr_rg == 0) { - dw->calib_mode_curr_rg = (dw->image->det->n_rigid_groups-1); - } else { - dw->calib_mode_curr_rg -= 1; - } - redraw_window(dw); - break; + num_p = dw->calib_mode_curr_rg->n_panels; + if ( dw->calib_mode_groups == 1) { - case GDK_1: - dw->calib_mode_curr_rg = 0; - redraw_window(dw); - break; + if ( dw->calib_mode_curr_rg == dw->image->det->rigid_groups[0] ) { + dw->calib_mode_curr_rg = dw->image->det->rigid_groups[num_rg-1]; + } else { + dw->calib_mode_curr_rg = + dw->image->det->rigid_groups[curr_rg_pointer_index(dw)-1]; + } - case GDK_2: - dw->calib_mode_curr_rg = 1; - redraw_window(dw); - break; + } else { - case GDK_3: - dw->calib_mode_curr_rg = 2; - redraw_window(dw); - break; + if ( dw->calib_mode_curr_p == dw->calib_mode_curr_rg->panels[0] ) { + dw->calib_mode_curr_p = dw->calib_mode_curr_rg->panels[num_p-1]; + } else { + dw->calib_mode_curr_p = + dw->calib_mode_curr_rg->panels[curr_p_pointer_index_in_rg(dw)-1]; + } - case GDK_4: - dw->calib_mode_curr_rg = 3; + } redraw_window(dw); break; + case GDK_f: if ( dw->calib_mode_show_focus == 1 ) { dw->calib_mode_show_focus = 0; @@ -1990,6 +2065,19 @@ static gint displaywindow_keypress(GtkWidget *widget, GdkEventKey *event, redraw_window(dw); break; + + case GDK_g: + if ( dw->calib_mode_groups == 1 ) { + dw->calib_mode_groups = 0; + dw->calib_mode_curr_p = dw->calib_mode_curr_rg->panels[0]; + } else { + dw->calib_mode_groups = 1; + dw->calib_mode_curr_rg = dw->calib_mode_curr_p->rigid_group; + } + redraw_window(dw); + break; + + case GDK_s: s = save_geometry_file(dw); if ( s != 0 ) { @@ -2001,9 +2089,10 @@ static gint displaywindow_keypress(GtkWidget *widget, GdkEventKey *event, } - return 0; + return 0; } + DisplayWindow *displaywindow_open(const char *filename, const char *peaks, double boost, int binning, int noisefilter, int calibmode, int colscale, @@ -2045,8 +2134,10 @@ DisplayWindow *displaywindow_open(const char *filename, const char *peaks, dw->median_filter = median_filter; dw->image = calloc(1, sizeof(struct image)); dw->calib_mode = 0; - dw->calib_mode_curr_rg = 0; + dw->calib_mode_curr_rg = NULL; + dw->calib_mode_curr_p = NULL; dw->calib_mode_show_focus = 1; + dw->calib_mode_groups = 1; if ( beam != NULL ) { dw->image->beam = get_beam_parameters(beam); @@ -2139,6 +2230,9 @@ DisplayWindow *displaywindow_open(const char *filename, const char *peaks, gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ww), TRUE); } + dw->calib_mode_curr_rg = dw->image->det->rigid_groups[0]; + dw->calib_mode_curr_p = dw->calib_mode_curr_rg->panels[0]; + displaywindow_update(dw); gtk_widget_add_events(GTK_WIDGET(dw->drawingarea), diff --git a/src/dw-hdfsee.h b/src/dw-hdfsee.h index 56f22b54..cc7659bc 100644 --- a/src/dw-hdfsee.h +++ b/src/dw-hdfsee.h @@ -109,8 +109,10 @@ typedef struct { double *ring_radii; int n_rings; int calib_mode; - int calib_mode_curr_rg; + struct rigid_group *calib_mode_curr_rg; + struct panel *calib_mode_curr_p; int calib_mode_show_focus; + int calib_mode_groups; int show_col_scale; int scale; -- cgit v1.2.3 From fb941e1a8e0cbcce94d0534173122ab324777acc Mon Sep 17 00:00:00 2001 From: Valerio Mariani Date: Mon, 3 Mar 2014 13:49:23 +0100 Subject: Fixed bug with accessing rigid group and panel information even if the geometry was not loaded --- src/dw-hdfsee.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/dw-hdfsee.c b/src/dw-hdfsee.c index d30de55f..93de9041 100644 --- a/src/dw-hdfsee.c +++ b/src/dw-hdfsee.c @@ -1173,11 +1173,17 @@ static gint displaywindow_set_calibmode(GtkWidget *d, DisplayWindow *dw) gtk_check_menu_item_set_state(GTK_CHECK_MENU_ITEM(w),0); + dw->calib_mode_curr_rg = dw->image->det->rigid_groups[0]; + dw->calib_mode_curr_p = dw->calib_mode_curr_rg->panels[0]; + } else { /* Get new value */ dw->calib_mode = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w)); - + if ( dw->calib_mode_curr_rg == NULL && dw->calib_mode_curr_p == NULL) { + dw->calib_mode_curr_rg = dw->image->det->rigid_groups[0]; + dw->calib_mode_curr_p = dw->calib_mode_curr_rg->panels[0]; + } displaywindow_update(dw); } @@ -2228,10 +2234,10 @@ DisplayWindow *displaywindow_open(const char *filename, const char *peaks, if (dw->calib_mode == 1) { ww = gtk_ui_manager_get_widget(dw->ui, "/ui/displaywindow/tools/calibmode"); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ww), TRUE); + dw->calib_mode_curr_rg = dw->image->det->rigid_groups[0]; + dw->calib_mode_curr_p = dw->calib_mode_curr_rg->panels[0]; } - dw->calib_mode_curr_rg = dw->image->det->rigid_groups[0]; - dw->calib_mode_curr_p = dw->calib_mode_curr_rg->panels[0]; displaywindow_update(dw); -- cgit v1.2.3 From 149f3df068869bdb26bc103b301ece84e14766c9 Mon Sep 17 00:00:00 2001 From: Valerio Mariani Date: Tue, 4 Mar 2014 18:09:40 +0100 Subject: Added statusbar to calibration mode with info on last clicked position --- src/dw-hdfsee.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++---------- src/dw-hdfsee.h | 2 ++ 2 files changed, 56 insertions(+), 11 deletions(-) diff --git a/src/dw-hdfsee.c b/src/dw-hdfsee.c index 93de9041..6e1a5e99 100644 --- a/src/dw-hdfsee.c +++ b/src/dw-hdfsee.c @@ -1166,25 +1166,49 @@ static gint displaywindow_set_usegeom(GtkWidget *d, DisplayWindow *dw) static gint displaywindow_set_calibmode(GtkWidget *d, DisplayWindow *dw) { - GtkWidget *w; + GtkWidget *w, *vbox; + guint calibmode_context; + w = gtk_ui_manager_get_widget(dw->ui, "/ui/displaywindow/tools/calibmode"); if ( dw->use_geom == 0 ) { gtk_check_menu_item_set_state(GTK_CHECK_MENU_ITEM(w),0); - dw->calib_mode_curr_rg = dw->image->det->rigid_groups[0]; - dw->calib_mode_curr_p = dw->calib_mode_curr_rg->panels[0]; - } else { /* Get new value */ dw->calib_mode = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w)); - if ( dw->calib_mode_curr_rg == NULL && dw->calib_mode_curr_p == NULL) { - dw->calib_mode_curr_rg = dw->image->det->rigid_groups[0]; - dw->calib_mode_curr_p = dw->calib_mode_curr_rg->panels[0]; + + /* When entering calibration mode */ + if ( dw-> calib_mode == 1 ) { + + if ( dw->calib_mode_curr_rg == NULL && dw->calib_mode_curr_p == NULL ) { + dw->calib_mode_curr_rg = dw->image->det->rigid_groups[0]; + dw->calib_mode_curr_p = dw->calib_mode_curr_rg->panels[0]; + } + + dw->calibmode_statusbar = gtk_statusbar_new(); + gtk_widget_show(dw->calibmode_statusbar); + vbox = gtk_bin_get_child(GTK_BIN(dw->window)); + gtk_box_pack_end(GTK_BOX(vbox), dw->calibmode_statusbar, TRUE, TRUE, 0); + calibmode_context = gtk_statusbar_get_context_id(GTK_STATUSBAR(dw->calibmode_statusbar), + "calibmode"); + gtk_statusbar_push(GTK_STATUSBAR(dw->calibmode_statusbar), + calibmode_context, + "Last Clicked Position: x: --, y: --, fs: --, ss: --, (panel --)"); + displaywindow_update(dw); + + } + + /* When leaving calibration mode */ + if ( dw-> calib_mode == 0 ) { + + gtk_widget_destroy(dw->calibmode_statusbar); + dw->calibmode_statusbar = NULL; + displaywindow_update(dw); + } - displaywindow_update(dw); } @@ -1889,6 +1913,11 @@ static gint displaywindow_motion(GtkWidget *widget, GdkEventMotion *event, static gint displaywindow_press(GtkWidget *widget, GdkEventButton *event, DisplayWindow *dw) { + int x,y; + double dfs, dss; + int fs, ss; + char statusbar_string[80]; + if ( dw->motion_callback != 0 ) { return 0; } @@ -1907,6 +1936,22 @@ static gint displaywindow_press(GtkWidget *widget, GdkEventButton *event, numbers_update(dw); } + if ( dw->calibmode_statusbar != NULL ) { + guint calibmode_context = gtk_statusbar_get_context_id(GTK_STATUSBAR(dw->calibmode_statusbar), "calibmode"); + x = dw->binning * (event->x); + y = dw->binning * (dw->height - 1 - event->y); + x += dw->min_x; + y += dw->min_x; + reverse_2d_mapping(x, y, &dfs, &dss, dw->image->det); + fs = dfs; + ss = dss; + sprintf(statusbar_string, + "Last Clicked Position: x: %i, y: %i, fs: %u, ss: %u, (panel %s)", + x, y, fs, ss, find_panel(dw->image->det, fs, ss)->name); + gtk_statusbar_push(GTK_STATUSBAR(dw->calibmode_statusbar), + calibmode_context, statusbar_string); + } + } return 0; @@ -2144,6 +2189,7 @@ DisplayWindow *displaywindow_open(const char *filename, const char *peaks, dw->calib_mode_curr_p = NULL; dw->calib_mode_show_focus = 1; dw->calib_mode_groups = 1; + dw->calibmode_statusbar = NULL; if ( beam != NULL ) { dw->image->beam = get_beam_parameters(beam); @@ -2183,7 +2229,6 @@ DisplayWindow *displaywindow_open(const char *filename, const char *peaks, free(dw); return NULL; } - dw->loaded_geom = NULL; dw->simple_geom = simple_geometry(dw->image); dw->image->det = dw->simple_geom; @@ -2234,8 +2279,6 @@ DisplayWindow *displaywindow_open(const char *filename, const char *peaks, if (dw->calib_mode == 1) { ww = gtk_ui_manager_get_widget(dw->ui, "/ui/displaywindow/tools/calibmode"); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ww), TRUE); - dw->calib_mode_curr_rg = dw->image->det->rigid_groups[0]; - dw->calib_mode_curr_p = dw->calib_mode_curr_rg->panels[0]; } diff --git a/src/dw-hdfsee.h b/src/dw-hdfsee.h index cc7659bc..96f7dcf5 100644 --- a/src/dw-hdfsee.h +++ b/src/dw-hdfsee.h @@ -114,6 +114,8 @@ typedef struct { int calib_mode_show_focus; int calib_mode_groups; + GtkWidget *calibmode_statusbar; + int show_col_scale; int scale; GdkPixbuf *col_scale; -- cgit v1.2.3 From 3dd005b6af2d1b68db3288bfc6d8653321ed87e5 Mon Sep 17 00:00:00 2001 From: Valerio Mariani Date: Wed, 5 Mar 2014 10:19:13 +0100 Subject: Fixed bug with handling of clicking outside of panel areas --- src/dw-hdfsee.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/dw-hdfsee.c b/src/dw-hdfsee.c index 6e1a5e99..be2c2dad 100644 --- a/src/dw-hdfsee.c +++ b/src/dw-hdfsee.c @@ -1196,7 +1196,7 @@ static gint displaywindow_set_calibmode(GtkWidget *d, DisplayWindow *dw) "calibmode"); gtk_statusbar_push(GTK_STATUSBAR(dw->calibmode_statusbar), calibmode_context, - "Last Clicked Position: x: --, y: --, fs: --, ss: --, (panel --)"); + "Last clicked position: Not available"); displaywindow_update(dw); } @@ -1915,7 +1915,7 @@ static gint displaywindow_press(GtkWidget *widget, GdkEventButton *event, { int x,y; double dfs, dss; - int fs, ss; + int fs, ss, revmap_return_value; char statusbar_string[80]; if ( dw->motion_callback != 0 ) { @@ -1942,12 +1942,15 @@ static gint displaywindow_press(GtkWidget *widget, GdkEventButton *event, y = dw->binning * (dw->height - 1 - event->y); x += dw->min_x; y += dw->min_x; - reverse_2d_mapping(x, y, &dfs, &dss, dw->image->det); - fs = dfs; - ss = dss; - sprintf(statusbar_string, - "Last Clicked Position: x: %i, y: %i, fs: %u, ss: %u, (panel %s)", - x, y, fs, ss, find_panel(dw->image->det, fs, ss)->name); + snprintf(statusbar_string, 80, "Last clicked position: x: %i, y: %i (Not in panel)", x, y); + revmap_return_value = reverse_2d_mapping(x, y, &dfs, &dss, dw->image->det); + if ( revmap_return_value == 0 ) { + fs = dfs; + ss = dss; + snprintf(statusbar_string, 80, + "Last clicked position: x: %i, y: %i, fs: %u, ss: %u, (panel %s)", + x, y, fs, ss, find_panel(dw->image->det, fs, ss)->name); + } gtk_statusbar_push(GTK_STATUSBAR(dw->calibmode_statusbar), calibmode_context, statusbar_string); } -- cgit v1.2.3 From 1009c723b27c118e2333895bbf518ccd33b35f13 Mon Sep 17 00:00:00 2001 From: Valerio Mariani Date: Thu, 27 Mar 2014 15:52:15 +0100 Subject: Updated author list --- src/dw-hdfsee.c | 1 + src/dw-hdfsee.h | 1 + src/hdfsee.c | 1 + 3 files changed, 3 insertions(+) diff --git a/src/dw-hdfsee.c b/src/dw-hdfsee.c index be2c2dad..ea5220ef 100644 --- a/src/dw-hdfsee.c +++ b/src/dw-hdfsee.c @@ -10,6 +10,7 @@ * Authors: * 2009-2013 Thomas White * 2012 Richard Kirian + * 2014 Valerio Mariani * * This file is part of CrystFEL. * diff --git a/src/dw-hdfsee.h b/src/dw-hdfsee.h index 96f7dcf5..b469e79d 100644 --- a/src/dw-hdfsee.h +++ b/src/dw-hdfsee.h @@ -10,6 +10,7 @@ * Authors: * 2009-2012 Thomas White * 2012 Richard Kirian + * 2014 Valerio Mariani * * This file is part of CrystFEL. * diff --git a/src/hdfsee.c b/src/hdfsee.c index 49c4775f..1a461a2b 100644 --- a/src/hdfsee.c +++ b/src/hdfsee.c @@ -10,6 +10,7 @@ * Authors: * 2009-2012 Thomas White * 2012 Richard Kirian + * 2014 Valerio Mariani * * This file is part of CrystFEL. * -- cgit v1.2.3 From 961ed21976d3eeede27e5317aec5184709f9a4d8 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 25 Apr 2014 17:28:29 +0200 Subject: Fussiness --- src/dw-hdfsee.c | 303 +++++++++++++++++++++++++++++--------------------------- src/hdfsee.c | 8 +- 2 files changed, 161 insertions(+), 150 deletions(-) diff --git a/src/dw-hdfsee.c b/src/dw-hdfsee.c index ea5220ef..7fa7f3e2 100644 --- a/src/dw-hdfsee.c +++ b/src/dw-hdfsee.c @@ -140,8 +140,9 @@ static void draw_panel_rectangle(cairo_t *cr, cairo_matrix_t *basic_m, cairo_rectangle(cr, 0.0, 0.0, w, h); } + static void draw_calib_focus_rectangle(cairo_t *cr, cairo_matrix_t *basic_m, - DisplayWindow *dw, int i) + DisplayWindow *dw, int i) { struct panel p = dw->image->det->panels[i]; int w = gdk_pixbuf_get_width(dw->pixbufs[i]); @@ -152,12 +153,10 @@ static void draw_calib_focus_rectangle(cairo_t *cr, cairo_matrix_t *basic_m, cairo_set_matrix(cr, basic_m); /* Move to the right location */ - cairo_translate(cr, p.cnx/dw->binning, - p.cny/dw->binning); + cairo_translate(cr, p.cnx/dw->binning, p.cny/dw->binning); /* Twiddle directions according to matrix */ - cairo_matrix_init(&m, p.fsx, p.fsy, p.ssx, p.ssy, - 0.0, 0.0); + cairo_matrix_init(&m, p.fsx, p.fsy, p.ssx, p.ssy, 0.0, 0.0); cairo_transform(cr, &m); cairo_set_line_width (cr, 3.0); @@ -228,6 +227,28 @@ static void show_simple_ring(cairo_t *cr, DisplayWindow *dw, } +static void maybe_draw_focus(DisplayWindow *dw, cairo_t *cr, int i, + cairo_matrix_t *basic_m) +{ + if ( dw->calib_mode_groups ) { + + if ( dw->image->det->panels[i].rigid_group + == dw->calib_mode_curr_rg ) + { + draw_calib_focus_rectangle(cr, basic_m, dw, i); + cairo_stroke(cr); + } + + } else { + + if ( &dw->image->det->panels[i] == dw->calib_mode_curr_p) { + draw_calib_focus_rectangle(cr, basic_m, dw, i); + cairo_stroke(cr); + } + + } +} + static int draw_stuff(cairo_surface_t *surf, DisplayWindow *dw) { cairo_t *cr; @@ -260,24 +281,8 @@ static int draw_stuff(cairo_surface_t *surf, DisplayWindow *dw) draw_panel_rectangle(cr, &basic_m, dw, i); cairo_fill(cr); - if ( dw->calib_mode == 1 && dw->calib_mode_show_focus == 1) { - - if ( dw->calib_mode_groups == 1 ) { - - if ( dw->image->det->panels[i].rigid_group == dw->calib_mode_curr_rg ) { - draw_calib_focus_rectangle(cr, &basic_m, dw, i); - cairo_stroke(cr); - } - - } else { - - if ( &dw->image->det->panels[i] == dw->calib_mode_curr_p) { - draw_calib_focus_rectangle(cr, &basic_m, dw, i); - cairo_stroke(cr); - } - - } - + if ( dw->calib_mode && dw->calib_mode_show_focus ) { + maybe_draw_focus(dw, cr, i, &basic_m); } } @@ -292,16 +297,6 @@ static int draw_stuff(cairo_surface_t *surf, DisplayWindow *dw) cairo_set_source_rgb(cr, 1.0, 0.0, 0.0); cairo_fill(cr); - //cairo_rectangle(cr, -370.0, 800.0, 120.0, 60.0); - //cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.3); - //cairo_fill(cr); - - //show_simple_ring(cr, dw, 80.0, &basic_m); - //show_simple_ring(cr, dw, 186.0, &basic_m); - //show_simple_ring(cr, dw, 230.0, &basic_m); - //show_simple_ring(cr, dw, 320.0, &basic_m); - //show_simple_ring(cr, dw, 380.0, &basic_m); - /* Draw resolution circles */ if ( dw->n_rings == -1 ) { /* n_rings == -1 means default behavior */ @@ -1060,13 +1055,14 @@ static int load_geometry_file(DisplayWindow *dw, struct image *image, return 0; } + static int save_geometry_file(DisplayWindow *dw) { GtkWidget *d; gchar * filename; int w; - d = gtk_file_chooser_dialog_new("Save Calibration Geometry", + d = gtk_file_chooser_dialog_new("Save Detector Geometry", GTK_WINDOW(dw->window), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, @@ -1081,6 +1077,7 @@ static int save_geometry_file(DisplayWindow *dw) return w; } + static gint displaywindow_loadgeom_response(GtkWidget *d, gint response, DisplayWindow *dw) { @@ -1168,48 +1165,45 @@ static gint displaywindow_set_calibmode(GtkWidget *d, DisplayWindow *dw) { GtkWidget *w, *vbox; - guint calibmode_context; w = gtk_ui_manager_get_widget(dw->ui, - "/ui/displaywindow/tools/calibmode"); - if ( dw->use_geom == 0 ) { - - gtk_check_menu_item_set_state(GTK_CHECK_MENU_ITEM(w),0); - - } else { - - /* Get new value */ - dw->calib_mode = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w)); + "/ui/displaywindow/tools/calibmode"); + if ( !dw->use_geom ) { + gtk_check_menu_item_set_state(GTK_CHECK_MENU_ITEM(w), 0); + return 0; + } - /* When entering calibration mode */ - if ( dw-> calib_mode == 1 ) { + /* Get new value */ + dw->calib_mode = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w)); - if ( dw->calib_mode_curr_rg == NULL && dw->calib_mode_curr_p == NULL ) { - dw->calib_mode_curr_rg = dw->image->det->rigid_groups[0]; - dw->calib_mode_curr_p = dw->calib_mode_curr_rg->panels[0]; - } + /* When entering calibration mode */ + if ( dw->calib_mode ) { - dw->calibmode_statusbar = gtk_statusbar_new(); - gtk_widget_show(dw->calibmode_statusbar); - vbox = gtk_bin_get_child(GTK_BIN(dw->window)); - gtk_box_pack_end(GTK_BOX(vbox), dw->calibmode_statusbar, TRUE, TRUE, 0); - calibmode_context = gtk_statusbar_get_context_id(GTK_STATUSBAR(dw->calibmode_statusbar), - "calibmode"); - gtk_statusbar_push(GTK_STATUSBAR(dw->calibmode_statusbar), - calibmode_context, - "Last clicked position: Not available"); - displaywindow_update(dw); + guint cc; + if ( (dw->calib_mode_curr_rg == NULL) + && (dw->calib_mode_curr_p == NULL) ) + { + dw->calib_mode_curr_rg = dw->image->det->rigid_groups[0]; + dw->calib_mode_curr_p = dw->calib_mode_curr_rg->panels[0]; } - /* When leaving calibration mode */ - if ( dw-> calib_mode == 0 ) { + dw->calibmode_statusbar = gtk_statusbar_new(); + gtk_widget_show(dw->calibmode_statusbar); + vbox = gtk_bin_get_child(GTK_BIN(dw->window)); + gtk_box_pack_end(GTK_BOX(vbox), dw->calibmode_statusbar, + TRUE, TRUE, 0); + cc = gtk_statusbar_get_context_id(GTK_STATUSBAR(dw->calibmode_statusbar), + "calibmode"); + gtk_statusbar_push(GTK_STATUSBAR(dw->calibmode_statusbar), cc, + "Last clicked position: Not available"); + displaywindow_update(dw); - gtk_widget_destroy(dw->calibmode_statusbar); - dw->calibmode_statusbar = NULL; - displaywindow_update(dw); + } else { - } + gtk_widget_destroy(dw->calibmode_statusbar); + dw->calibmode_statusbar = NULL; + displaywindow_update(dw); } @@ -1911,14 +1905,42 @@ static gint displaywindow_motion(GtkWidget *widget, GdkEventMotion *event, } -static gint displaywindow_press(GtkWidget *widget, GdkEventButton *event, - DisplayWindow *dw) +static void calibmode_press(DisplayWindow *dw, GdkEventButton *event) { int x,y; double dfs, dss; int fs, ss, revmap_return_value; char statusbar_string[80]; + guint cc; + + cc = gtk_statusbar_get_context_id(GTK_STATUSBAR(dw->calibmode_statusbar), + "calibmode"); + + x = dw->binning * (event->x); + y = dw->binning * (dw->height - 1 - event->y); + x += dw->min_x; + y += dw->min_x; + snprintf(statusbar_string, 80, + "Last clicked position: x: %i, y: %i (Not in panel)", x, y); + + revmap_return_value = reverse_2d_mapping(x, y, &dfs, &dss, + dw->image->det); + if ( revmap_return_value == 0 ) { + fs = dfs; + ss = dss; + snprintf(statusbar_string, 80, + "Last clicked position: x: %i, y: %i, fs: %u, ss: %u," + " (panel %s)", + x, y, fs, ss, find_panel(dw->image->det, fs, ss)->name); + } + gtk_statusbar_push(GTK_STATUSBAR(dw->calibmode_statusbar), + cc, statusbar_string); +} + +static gint displaywindow_press(GtkWidget *widget, GdkEventButton *event, + DisplayWindow *dw) +{ if ( dw->motion_callback != 0 ) { return 0; } @@ -1938,32 +1960,16 @@ static gint displaywindow_press(GtkWidget *widget, GdkEventButton *event, } if ( dw->calibmode_statusbar != NULL ) { - guint calibmode_context = gtk_statusbar_get_context_id(GTK_STATUSBAR(dw->calibmode_statusbar), "calibmode"); - x = dw->binning * (event->x); - y = dw->binning * (dw->height - 1 - event->y); - x += dw->min_x; - y += dw->min_x; - snprintf(statusbar_string, 80, "Last clicked position: x: %i, y: %i (Not in panel)", x, y); - revmap_return_value = reverse_2d_mapping(x, y, &dfs, &dss, dw->image->det); - if ( revmap_return_value == 0 ) { - fs = dfs; - ss = dss; - snprintf(statusbar_string, 80, - "Last clicked position: x: %i, y: %i, fs: %u, ss: %u, (panel %s)", - x, y, fs, ss, find_panel(dw->image->det, fs, ss)->name); - } - gtk_statusbar_push(GTK_STATUSBAR(dw->calibmode_statusbar), - calibmode_context, statusbar_string); + calibmode_press(dw, event); } } return 0; - } -int curr_rg_pointer_index (DisplayWindow *dw) +static int curr_rg_pointer_index(DisplayWindow *dw) { int r; @@ -1978,7 +1984,7 @@ int curr_rg_pointer_index (DisplayWindow *dw) } -int curr_p_pointer_index_in_rg (DisplayWindow *dw) +static int curr_p_pointer_index_in_rg(DisplayWindow *dw) { int p; @@ -1993,23 +1999,66 @@ int curr_p_pointer_index_in_rg (DisplayWindow *dw) } +static void select_next_group(DisplayWindow *dw, int num_rg) +{ + if ( dw->calib_mode_curr_rg == dw->image->det->rigid_groups[num_rg-1] ) { + dw->calib_mode_curr_rg = dw->image->det->rigid_groups[0]; + } else { + dw->calib_mode_curr_rg = + dw->image->det->rigid_groups[curr_rg_pointer_index(dw)+1]; + } +} + + +static void select_prev_group(DisplayWindow *dw, int num_rg) +{ + if ( dw->calib_mode_curr_rg == dw->image->det->rigid_groups[0] ) { + dw->calib_mode_curr_rg = dw->image->det->rigid_groups[num_rg-1]; + } else { + dw->calib_mode_curr_rg = + dw->image->det->rigid_groups[curr_rg_pointer_index(dw)-1]; + } +} + + +static void select_next_panel(DisplayWindow *dw, int num_p) +{ + if ( dw->calib_mode_curr_p == dw->calib_mode_curr_rg->panels[num_p-1] ) { + dw->calib_mode_curr_p = dw->calib_mode_curr_rg->panels[0]; + } else { + dw->calib_mode_curr_p = + dw->calib_mode_curr_rg->panels[curr_p_pointer_index_in_rg(dw)+1]; + } +} + + +static void select_prev_panel(DisplayWindow *dw, int num_p) +{ + if ( dw->calib_mode_curr_p == dw->calib_mode_curr_rg->panels[0] ) { + dw->calib_mode_curr_p = dw->calib_mode_curr_rg->panels[num_p-1]; + } else { + dw->calib_mode_curr_p = + dw->calib_mode_curr_rg->panels[curr_p_pointer_index_in_rg(dw)-1]; + } +} + + static gint displaywindow_keypress(GtkWidget *widget, GdkEventKey *event, - DisplayWindow *dw) + DisplayWindow *dw) { - int pi,s; + int pi, s, num_rg, num_p; if ( dw->calib_mode == 0 ) { return 0; } - int num_rg = dw->image->det->n_rigid_groups; - int num_p; + num_rg = dw->image->det->n_rigid_groups; switch ( event->keyval ) { case GDK_Up: case GDK_KP_Up: - if ( dw->calib_mode_groups == 1 ) { + if ( dw->calib_mode_groups ) { for ( pi=0; picalib_mode_curr_rg->n_panels; ++pi ) { dw->calib_mode_curr_rg->panels[pi]->cny += 1.0; } @@ -2019,10 +2068,9 @@ static gint displaywindow_keypress(GtkWidget *widget, GdkEventKey *event, redraw_window(dw); break; - case GDK_Down: case GDK_KP_Down: - if ( dw->calib_mode_groups == 1 ) { + if ( dw->calib_mode_groups ) { for ( pi=0; picalib_mode_curr_rg->n_panels; ++pi ) { dw->calib_mode_curr_rg->panels[pi]->cny -= 1.0; } @@ -2032,10 +2080,9 @@ static gint displaywindow_keypress(GtkWidget *widget, GdkEventKey *event, redraw_window(dw); break; - case GDK_Left: case GDK_KP_Left: - if ( dw->calib_mode_groups == 1 ) { + if ( dw->calib_mode_groups ) { for ( pi=0; picalib_mode_curr_rg->n_panels; ++pi ) { dw->calib_mode_curr_rg->panels[pi]->cnx -= 1.0; } @@ -2045,10 +2092,9 @@ static gint displaywindow_keypress(GtkWidget *widget, GdkEventKey *event, redraw_window(dw); break; - case GDK_Right: case GDK_KP_Right: - if ( dw->calib_mode_groups == 1) { + if ( dw->calib_mode_groups ) { for ( pi=0; picalib_mode_curr_rg->n_panels; ++pi ) { dw->calib_mode_curr_rg->panels[pi]->cnx += 1.0; } @@ -2058,71 +2104,35 @@ static gint displaywindow_keypress(GtkWidget *widget, GdkEventKey *event, redraw_window(dw); break; - case GDK_plus: case GDK_KP_Add: num_p = dw->calib_mode_curr_rg->n_panels; - if ( dw->calib_mode_groups == 1) { - - if ( dw->calib_mode_curr_rg == dw->image->det->rigid_groups[num_rg-1 ] ) { - dw->calib_mode_curr_rg = dw->image->det->rigid_groups[0]; - } else { - dw->calib_mode_curr_rg = - dw->image->det->rigid_groups[curr_rg_pointer_index(dw)+1]; - } - + if ( dw->calib_mode_groups ) { + select_next_group(dw, num_rg); } else { - - if ( dw->calib_mode_curr_p == dw->calib_mode_curr_rg->panels[num_p-1] ) { - dw->calib_mode_curr_p = dw->calib_mode_curr_rg->panels[0]; - } else { - dw->calib_mode_curr_p = - dw->calib_mode_curr_rg->panels[curr_p_pointer_index_in_rg(dw)+1]; - } - + select_next_panel(dw, num_p); } redraw_window(dw); break; - case GDK_minus: case GDK_KP_Subtract: num_p = dw->calib_mode_curr_rg->n_panels; - if ( dw->calib_mode_groups == 1) { - - if ( dw->calib_mode_curr_rg == dw->image->det->rigid_groups[0] ) { - dw->calib_mode_curr_rg = dw->image->det->rigid_groups[num_rg-1]; - } else { - dw->calib_mode_curr_rg = - dw->image->det->rigid_groups[curr_rg_pointer_index(dw)-1]; - } - + if ( dw->calib_mode_groups ) { + select_prev_group(dw, num_rg); } else { - - if ( dw->calib_mode_curr_p == dw->calib_mode_curr_rg->panels[0] ) { - dw->calib_mode_curr_p = dw->calib_mode_curr_rg->panels[num_p-1]; - } else { - dw->calib_mode_curr_p = - dw->calib_mode_curr_rg->panels[curr_p_pointer_index_in_rg(dw)-1]; - } - + select_prev_panel(dw, num_p); } redraw_window(dw); break; - case GDK_f: - if ( dw->calib_mode_show_focus == 1 ) { - dw->calib_mode_show_focus = 0; - } else { - dw->calib_mode_show_focus = 1; - } + dw->calib_mode_show_focus = 1 - dw->calib_mode_show_focus; redraw_window(dw); break; - case GDK_g: - if ( dw->calib_mode_groups == 1 ) { + if ( dw->calib_mode_groups ) { dw->calib_mode_groups = 0; dw->calib_mode_curr_p = dw->calib_mode_curr_rg->panels[0]; } else { @@ -2132,17 +2142,17 @@ static gint displaywindow_keypress(GtkWidget *widget, GdkEventKey *event, redraw_window(dw); break; - case GDK_s: s = save_geometry_file(dw); if ( s != 0 ) { if ( s != 2 ) { - displaywindow_error(dw, "Unable to save the calibration geometry."); + displaywindow_error(dw, + "Unable to save the detector geometry."); } } break; - } + } return 0; } @@ -2281,7 +2291,8 @@ DisplayWindow *displaywindow_open(const char *filename, const char *peaks, } if (dw->calib_mode == 1) { - ww = gtk_ui_manager_get_widget(dw->ui, "/ui/displaywindow/tools/calibmode"); + ww = gtk_ui_manager_get_widget(dw->ui, + "/ui/displaywindow/tools/calibmode"); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ww), TRUE); } diff --git a/src/hdfsee.c b/src/hdfsee.c index 1a461a2b..ea6de2b2 100644 --- a/src/hdfsee.c +++ b/src/hdfsee.c @@ -3,12 +3,12 @@ * * Quick yet non-crappy HDF viewer * - * Copyright © 2012 Deutsches Elektronen-Synchrotron DESY, - * a research centre of the Helmholtz Association. + * Copyright © 2012-2014 Deutsches Elektronen-Synchrotron DESY, + * a research centre of the Helmholtz Association. * Copyright © 2012 Richard Kirian * * Authors: - * 2009-2012 Thomas White + * 2009-2014 Thomas White * 2012 Richard Kirian * 2014 Valerio Mariani * @@ -62,7 +62,7 @@ static void show_help(const char *s) " --filter-noise Apply an aggressive noise filter to the\n" " image data.\n" " --median-filter= Apply a median filter to the image data.\n" -" --calibration-mode Starts in calibration mode\n" +" --calibration-mode Start in calibration mode\n" " --show-rings Overlay rings that indicate resolution.\n" " --simple-rings=XX,YY,... Overlay rings at specified radii XX, YY, ...\n" " in pixel units.\n" -- cgit v1.2.3