diff options
author | Thomas White <taw@physics.org> | 2021-01-07 12:16:34 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2021-01-07 12:27:06 +0100 |
commit | 97eb1a231a07777a961efe6a389597989d1b7dc4 (patch) | |
tree | 303e93bd9bad6e13cf71fb705b5a7a096f160b4b | |
parent | 801aca3557fed6883ccc7a84b5ca38005cb6244c (diff) |
GUI: Basic labelling of reflections
Lots of improvements still to be made here, such as using the "real"
Cairo text API as well as using proper overlines for negative indices.
-rw-r--r-- | src/crystfel_gui.c | 18 | ||||
-rw-r--r-- | src/crystfelimageview.c | 40 | ||||
-rw-r--r-- | src/crystfelimageview.h | 4 | ||||
-rw-r--r-- | src/gui_project.c | 6 | ||||
-rw-r--r-- | src/gui_project.h | 1 |
5 files changed, 66 insertions, 3 deletions
diff --git a/src/crystfel_gui.c b/src/crystfel_gui.c index cf727018..09011830 100644 --- a/src/crystfel_gui.c +++ b/src/crystfel_gui.c @@ -204,6 +204,8 @@ void update_imageview(struct crystfelproject *proj) crystfel_image_view_set_show_reflections(CRYSTFEL_IMAGE_VIEW(proj->imageview), proj->show_refls); + crystfel_image_view_set_label_reflections(CRYSTFEL_IMAGE_VIEW(proj->imageview), + proj->label_refls); crystfel_image_view_set_refl_box_size(CRYSTFEL_IMAGE_VIEW(proj->imageview), proj->indexing_params.ir_inn); crystfel_image_view_set_show_peaks(CRYSTFEL_IMAGE_VIEW(proj->imageview), @@ -740,6 +742,15 @@ static gint show_refls_sig(GtkWidget *w, struct crystfelproject *proj) } +static gint label_refls_sig(GtkWidget *w, struct crystfelproject *proj) +{ + proj->label_refls = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(w)); + crystfel_image_view_set_label_reflections(CRYSTFEL_IMAGE_VIEW(proj->imageview), + proj->label_refls); + return FALSE; +} + + static void add_menu_bar(struct crystfelproject *proj, GtkWidget *vbox) { GError *error = NULL; @@ -752,6 +763,7 @@ static void add_menu_bar(struct crystfelproject *proj, GtkWidget *vbox) "<menu name=\"view\" action=\"ViewAction\" >" " <menuitem name=\"peaks\" action=\"PeaksAction\" />" " <menuitem name=\"refls\" action=\"ReflsAction\" />" + " <menuitem name=\"labelrefls\" action=\"LabelReflsAction\" />" "</menu>" "<menu name=\"tools\" action=\"ToolsAction\" >" "</menu>" @@ -783,6 +795,8 @@ static void add_menu_bar(struct crystfelproject *proj, GtkWidget *vbox) G_CALLBACK(show_peaks_sig), FALSE }, { "ReflsAction", NULL, "Calculated reflection positions", NULL, NULL, G_CALLBACK(show_refls_sig), FALSE }, + { "LabelReflsAction", NULL, "Show reflection indices", NULL, NULL, + G_CALLBACK(label_refls_sig), FALSE }, }; proj->action_group = gtk_action_group_new("cellwindow"); @@ -1093,6 +1107,10 @@ int main(int argc, char *argv[]) gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(w), proj.show_refls); + w = gtk_ui_manager_get_action(proj.ui, "/mainwindow/view/labelrefls"); + gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(w), + proj.label_refls); + update_imageview(&proj); } diff --git a/src/crystfelimageview.c b/src/crystfelimageview.c index 0117c79b..26e06bce 100644 --- a/src/crystfelimageview.c +++ b/src/crystfelimageview.c @@ -433,8 +433,10 @@ static void draw_peaks(cairo_t *cr, CrystFELImageView *iv, } -static void draw_refls(cairo_t *cr, CrystFELImageView *iv, - RefList *list) +static void draw_refls(cairo_t *cr, + CrystFELImageView *iv, + RefList *list, + int label_reflections) { const Reflection *refl; RefListIterator *iter; @@ -494,6 +496,27 @@ static void draw_refls(cairo_t *cr, CrystFELImageView *iv, cairo_stroke(cr); } + if ( label_reflections ) { + + signed int h, k, l; + char tmp[64]; + + get_indices(refl, &h, &k, &l); + snprintf(tmp, 64, "%i %i %i", h, k, l); + + cairo_save(cr); + cairo_new_path(cr); + cairo_move_to(cr, x, y); + cairo_set_source_rgb(cr, 0.0, 0.4, 0.0); + cairo_set_font_size(cr, 11*p->pixel_pitch); + cairo_scale(cr, 1.0, -1.0); + cairo_show_text(cr, tmp); + cairo_fill(cr); + cairo_restore(cr); + + } + + } } @@ -536,7 +559,9 @@ static gint draw_sig(GtkWidget *window, cairo_t *cr, CrystFELImageView *iv) int i; for ( i=0; i<iv->image->n_crystals; i++ ) { Crystal *cry = iv->image->crystals[i]; - draw_refls(cr, iv, crystal_get_reflections(cry)); + draw_refls(cr, iv, + crystal_get_reflections(cry), + iv->label_refls); } } @@ -687,6 +712,7 @@ GtkWidget *crystfel_image_view_new() iv->pixbufs = NULL; iv->peak_box_size = 1.0; iv->refl_box_size = 1.0; + iv->label_refls = 1; g_signal_connect(G_OBJECT(iv), "destroy", G_CALLBACK(destroy_sig), iv); @@ -952,6 +978,14 @@ void crystfel_image_view_set_show_reflections(CrystFELImageView *iv, } +void crystfel_image_view_set_label_reflections(CrystFELImageView *iv, + int label_refls) +{ + iv->label_refls = label_refls; + rerender_image(iv); +} + + void crystfel_image_view_set_peak_box_size(CrystFELImageView *iv, float box_size) { diff --git a/src/crystfelimageview.h b/src/crystfelimageview.h index a8f8df99..0ea2ab87 100644 --- a/src/crystfelimageview.h +++ b/src/crystfelimageview.h @@ -88,6 +88,7 @@ struct _crystfelimageview double brightness; int show_peaks; int show_refls; + int label_refls; float peak_box_size; float refl_box_size; }; @@ -117,6 +118,9 @@ extern void crystfel_image_view_set_show_peaks(CrystFELImageView *iv, extern void crystfel_image_view_set_show_reflections(CrystFELImageView *iv, int show_refls); +extern void crystfel_image_view_set_label_reflections(CrystFELImageView *iv, + int label_refls); + extern void crystfel_image_view_set_peak_box_size(CrystFELImageView *iv, float box_size); diff --git a/src/gui_project.c b/src/gui_project.c index f909eb29..d88ea791 100644 --- a/src/gui_project.c +++ b/src/gui_project.c @@ -420,6 +420,10 @@ static void handle_var(const char *key, const char *val, proj->show_refls = parse_int(val); } + if ( strcmp(key, "label_refls") == 0 ) { + proj->label_refls = parse_int(val); + } + if ( strcmp(key, "geom") == 0 ) { proj->geom_filename = strdup(val); } @@ -843,6 +847,7 @@ int save_project(struct crystfelproject *proj) fprintf(fh, "show_peaks %i\n", proj->show_peaks); fprintf(fh, "show_refls %i\n", proj->show_refls); + fprintf(fh, "label_refls %i\n", proj->label_refls); fprintf(fh, "-----\n"); for ( i=0; i<proj->n_results; i++ ) { @@ -917,6 +922,7 @@ void default_project(struct crystfelproject *proj) /* Default parameter values */ proj->show_peaks = 1; proj->show_refls = 1; + proj->label_refls = 1; proj->peak_search_params.method = PEAK_ZAEF; proj->peak_search_params.threshold = 800.0; diff --git a/src/gui_project.h b/src/gui_project.h index e1f47712..bb85be43 100644 --- a/src/gui_project.h +++ b/src/gui_project.h @@ -231,6 +231,7 @@ struct crystfelproject { struct peak_params peak_search_params; int show_refls; + int label_refls; struct index_params indexing_params; int indexing_backend_selected; GtkWidget *indexing_opts; |