added man page
[gpiv.git] / src / console.c
blobcc019a90dcb450829ccb398671ed79e71b6880b9
1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 c-style: "K&R" -*- */
3 /*----------------------------------------------------------------------
5 gpiv - Graphic program for Particle Image Velocimetry, based on gtk/gnome
6 libraries.
8 Copyright (C) 2002 Gerber van der Graaf
10 This file is part of gpiv.
12 Gpiv is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2, or (at your option)
15 any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 ----------------------------------------------------------------------*/
29 * (Callback) functions for console
30 * $Log: console.c,v $
31 * Revision 1.5 2003-07-10 11:56:07 gerber
32 * added man page
34 * Revision 1.4 2003/07/06 15:29:49 gerber
35 * repair message text closing buffer
37 * Revision 1.3 2003/07/05 13:14:57 gerber
38 * drag and drop of a _series_ of filenames from NAUTILUS
40 * Revision 1.2 2003/06/27 13:47:26 gerber
41 * display ruler, line/point evaluation
43 * Revision 1.1.1.1 2003/06/17 17:10:52 gerber
44 * Imported gpiv
48 #ifdef HAVE_CONFIG_H
49 # include <config.h>
50 #endif
51 #include "support.h"
53 #include "gpiv_gtk.h"
54 #include "console_interface.h"
55 #include "console_menus.h"
56 #include "console.h"
57 #include "display.h"
58 #include "piveval.h"
59 #include "pivvalid.h"
60 #include "pivpost.h"
61 #include "preferences.h"
62 #include "utils.h"
67 * loading images and (piv) data functions
72 static void
73 file_ok_sel(GtkWidget * w,
74 GtkFileSelection * fs);
76 static void
77 select_action_from_fname(GpivConsole *gpiv,
78 gchar *fname_in);
80 static void
81 load_buffer(GpivConsole *gpiv,
82 char *fname_in,
83 char *fname_base,
84 char *fname_ext,
85 gboolean read_hdf,
86 int ibuf,
87 enum ClistPut clist_put);
89 static int
90 open_img(char *fname_in,
91 Image * img,
92 gboolean read_hdf);
94 static void
95 open_piv(char *fname_in,
96 GpivData * gpd);
98 static void
99 exec_save(Display * disp);
102 * General callbacks
105 void
106 on_widget_leave(GtkContainer * container,
107 GtkDirectionType direction, gpointer user_data)
109 GpivConsole *gpiv = gtk_object_get_data(GTK_OBJECT(container), "gpiv");
110 gnome_appbar_push(GNOME_APPBAR(gpiv->appbar), msg_default);
115 * Callback functions for pop-up menus
118 gint
119 on_my_popup_handler(GtkWidget *widget, GdkEvent *event)
121 GtkMenu *menu;
122 GdkEventButton *event_button;
124 g_return_val_if_fail (widget != NULL, FALSE);
125 g_return_val_if_fail (GTK_IS_MENU (widget), FALSE);
126 g_return_val_if_fail (event != NULL, FALSE);
128 /* The "widget" is the menu that was supplied when
129 * gtk_signal_connect_object was called.
131 menu = GTK_MENU (widget);
133 if (event->type == GDK_BUTTON_PRESS)
135 event_button = (GdkEventButton *) event;
136 if (event_button->button == 3)
138 gtk_menu_popup (menu, NULL, NULL, NULL, NULL,
139 event_button->button, event_button->time);
140 return TRUE;
144 return FALSE;
152 * Main gpiv-gui callbacks
156 void
157 on_clist_buf_rowselect(GtkWidget * clist,
158 gint row,
159 gint column,
160 GdkEventButton * event,
161 gpointer data)
163 gchar * text, labelno[MAX_CHARS];
164 GpivConsole * gpiv = gtk_object_get_data(GTK_OBJECT(clist), "gpiv");
165 GList *lis;
166 gint cnt = 0, buf_dum = 0;
168 if (!exec_process && GTK_CLIST (clist)->selection) {
169 for (lis = GTK_CLIST (clist)->selection; lis; lis = lis->next) {
170 row=GPOINTER_TO_INT (lis->data);
171 gtk_clist_get_text(GTK_CLIST(clist), row, /* column */ 0, &text);
172 display_act = gtk_clist_get_row_data(GTK_CLIST(gpiv->clist_buf),
173 row);
176 #ifdef DEBUG
177 if (print_par) g_warning("on_clist_buf_rowselect:: row=%d, text=%s",
178 row, text);
179 #endif
181 if(cnt == 0) {
182 gpiv->first_selected_row = row;
183 } else {
184 gpiv->last_selected_row = row;
187 * update variables of display before leaving the focus
189 if (display_act->intreg.exist == TRUE) {
190 display_act->intreg.row_start_old = 0;
191 display_act->intreg.row_start = piv_eval_par.row_start;
192 display_act->intreg.row_end = piv_eval_par.row_end;
193 display_act->intreg.col_start_old = 0;
194 display_act->intreg.col_start = piv_eval_par.col_start;
195 display_act->intreg.col_end = piv_eval_par.col_end;
196 display_act->intreg.int_size_1 = piv_eval_par.int_size_1;
197 display_act->intreg.int_size_2 = piv_eval_par.int_size_2;
198 display_act->intreg.int_shift = piv_eval_par.int_shift;
199 display_act->intreg.pre_shift_row = piv_eval_par.pre_shift_row;
200 display_act->intreg.pre_shift_col = piv_eval_par.pre_shift_col;
204 /* if (GTK_WIDGET_REALIZED(display_act->gpd.display)) */
206 display_act = gtk_clist_get_row_data(GTK_CLIST(gpiv->clist_buf),
207 row);
209 * Set variables of new active display equal to parameters
211 if (display_act->intreg.exist == TRUE
212 && (display_act->intreg.row_start != piv_eval_par.row_start
213 || display_act->intreg.row_end != piv_eval_par.row_end
214 || display_act->intreg.col_start != piv_eval_par.col_start
215 || display_act->intreg.col_end != piv_eval_par.col_end
216 || display_act->intreg.int_size_1 != piv_eval_par.int_size_1
217 || display_act->intreg.int_size_2 != piv_eval_par.int_size_2
218 || display_act->intreg.int_shift != piv_eval_par.int_shift
219 || display_act->intreg.pre_shift_row != piv_eval_par.pre_shift_row
220 || display_act->intreg.pre_shift_col != piv_eval_par.pre_shift_col)
222 destroy_all_intregs(display_act);
223 create_all_intregs(display_act);
226 if (display_act->mwin != NULL
227 && GTK_WIDGET_VISIBLE(GTK_WIDGET(display_act->mwin)) )
229 gdk_window_show(GTK_WIDGET(display_act->mwin)->window);
230 gdk_window_raise(GTK_WIDGET(display_act->mwin)->window);
233 * update labels in image header tab/window
235 g_snprintf(labelno, MAX_CHARS,"%d", display_act->count);
236 gtk_label_set_text(GTK_LABEL(gpiv->imgh->label_bufno),
237 (char *) labelno);
238 gtk_label_set_text(GTK_LABEL(gpiv->imgh->label_name),
239 display_act->fname_base);
240 gtk_entry_set_text(GTK_ENTRY(gpiv->imgh->entry_project),
241 /* display_act->gpd. */ image_par.project);
242 gtk_entry_set_text(GTK_ENTRY(gpiv->imgh->entry_crdate),
243 /* display_act->gpd. */ image_par.creation_date);
244 gtk_entry_set_text(GTK_ENTRY(gpiv->imgh->entry_location),
245 /* display_act->gpd. */ image_par.location);
246 gtk_entry_set_text(GTK_ENTRY(gpiv->imgh->entry_comment),
247 /* display_act->gpd. */ image_par.comment);
248 /* gtk_widget_grab_focus (display_act); */
252 cnt++;
254 if (cnt == 1) {
255 gpiv->last_selected_row = gpiv->first_selected_row;
258 if (gpiv->last_selected_row < gpiv->first_selected_row) {
259 buf_dum = gpiv->last_selected_row;
260 gpiv->last_selected_row = gpiv->first_selected_row;
261 gpiv->first_selected_row = buf_dum;
266 #ifdef DEBUG
267 if (print_par) g_warning("on_clist_buf_rowselect:: first_selected_row = %d, ast_selected_row = %d",
268 gpiv->first_selected_row, gpiv->last_selected_row);
269 #endif
273 void
274 on_clist_buf_drag_data_received (GtkWidget *widget,
275 GdkDragContext *context,
276 gint x,
277 gint y,
278 GtkSelectionData *data,
279 guint info,
280 guint time)
282 GpivConsole *gpiv = gtk_object_get_data(GTK_OBJECT(widget), "gpiv");
283 char *fname_cnt;
284 gchar *fname_in;
285 gchar **fname_v;
286 gint i, count = 0;
288 g_print("Got: %s\n", data->data);
290 fname_v = g_strsplit(data->data, "file:", MAX_BUFS);
293 * Count the number of selected files
295 fname_cnt = strtok(data->data, ":");
296 while (fname_cnt != NULL && count < MAX_BUFS) {
297 fname_cnt = strtok(NULL, ":");
298 count++;
302 * load the data from selected files
304 for (i = 1; i <= count - 1; i++) {
305 fname_in = g_strdup(fname_v[i]);
306 g_strchomp (fname_in);
307 select_action_from_fname(gpiv, fname_in);
308 g_free(fname_in);
311 g_strfreev(fname_v);
315 void
316 on_open_activate(GtkMenuItem * menuitem,
317 gpointer user_data)
319 GtkWidget *filew;
320 GpivConsole *gpiv = gtk_object_get_data(GTK_OBJECT(menuitem), "gpiv");
323 * Create a new file selection widget
324 * Connect the ok_button and cancel_button to file_ok_sel function
325 * set user data to filew
326 * Lets set a default filename
328 filew = gtk_file_selection_new(/* "File selection" */"gpiv: open image");
329 gtk_signal_connect(GTK_OBJECT(filew), "destroy",
330 (GtkSignalFunc) destroy, &filew);
331 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(filew)->ok_button),
332 "clicked", (GtkSignalFunc) file_ok_sel,
333 GTK_OBJECT(filew));
334 gtk_signal_connect_object(GTK_OBJECT
335 (GTK_FILE_SELECTION(filew)->ok_button),
336 "clicked",
337 (GtkSignalFunc) gtk_widget_destroy,
338 GTK_OBJECT(filew));
339 gtk_object_set_data(GTK_OBJECT(GTK_FILE_SELECTION(filew)->ok_button),
340 "gpiv",
341 gpiv);
342 gtk_signal_connect_object(GTK_OBJECT
343 (GTK_FILE_SELECTION(filew)->cancel_button),
344 "clicked",
345 (GtkSignalFunc) gtk_widget_destroy,
346 GTK_OBJECT(filew));
347 gtk_file_selection_set_filename(GTK_FILE_SELECTION(filew),
348 fname_last);
349 gtk_widget_show(filew);
350 gtk_object_set_data(GTK_OBJECT(GTK_FILE_SELECTION(filew)),
351 "gpiv",
352 gpiv);
358 void
359 on_save_activate(GtkMenuItem * menuitem,
360 gpointer user_data)
362 GpivConsole * gpiv = gtk_object_get_data(GTK_OBJECT(menuitem), "gpiv");
363 save_all_data(gpiv);
367 void
368 on_save_as_activate(GtkMenuItem * menuitem,
369 gpointer user_data)
371 GtkWidget *filew;
372 GpivConsole *gpiv = gtk_object_get_data(GTK_OBJECT(menuitem), "gpiv");
376 * Create a new file selection widget
377 * Connect the ok_button and cancel_button to file_saveas_ok_sel function
378 * set user data to filew
379 * Lets set a default filename
381 filew = gtk_file_selection_new("File selection");
382 gtk_signal_connect(GTK_OBJECT(filew), "destroy",
383 (GtkSignalFunc) destroy, &filew);
384 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(filew)->ok_button),
385 "clicked", (GtkSignalFunc) file_saveas_ok_sel,
386 GTK_OBJECT(filew));
387 gtk_signal_connect_object(GTK_OBJECT
388 (GTK_FILE_SELECTION(filew)->ok_button),
389 "clicked",
390 (GtkSignalFunc) gtk_widget_destroy,
391 GTK_OBJECT(filew));
392 gtk_object_set_data(GTK_OBJECT(GTK_FILE_SELECTION(filew)->ok_button),
393 "gpiv",
394 gpiv);
395 gtk_signal_connect_object(GTK_OBJECT
396 (GTK_FILE_SELECTION(filew)->cancel_button),
397 "clicked",
398 (GtkSignalFunc) gtk_widget_destroy,
399 GTK_OBJECT(filew));
400 gtk_file_selection_set_filename(GTK_FILE_SELECTION(filew),
401 fname_last);
402 gtk_widget_show(filew);
403 gtk_object_set_data(GTK_OBJECT(GTK_FILE_SELECTION(filew)),
404 "gpiv",
405 gpiv);
407 g_warning("on_save_as_activate:: END");
411 void
412 file_saveas_ok_sel(GtkWidget * widget,
413 GtkFileSelection * fs
415 /* ---------------------------------------------- PIV data file selection */
417 GpivConsole *gpiv = gtk_object_get_data(GTK_OBJECT(fs), "gpiv");
418 gchar *fname_in,
419 *dirname,
420 *fname_base,
421 *fname_ext;
423 gchar *clist_buf_txt[MAX_BUFS][2], cl_int[2];
426 fname_in = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(fs)));
428 g_warning("file_saveas_ok_sel:: 0");
430 * Stripping file name
433 /*----------------------------------------------------------------------
434 * With GLIB-2.0:
435 * gchar* g_path_get_basename (const gchar *file_name);
436 * gchar* g_path_get_dirname (const gchar *file_name);
437 * g_build_filename
438 *----------------------------------------------------------------------*/
439 dirname = g_strdup(g_dirname(fname_in));
440 fname_base = g_strdup(g_basename(fname_in));
441 strtok(fname_base, ".");
442 fname_ext = g_strdup(g_strconcat(dirname, G_DIR_SEPARATOR_S,
443 fname_base, NULL));
446 * Substituting fname_base and storing data of display_act
448 gtk_clist_remove(GTK_CLIST(gpiv->clist_buf), display_act->count);
449 g_snprintf(cl_int, 2, "%d", display_act->count);
450 g_snprintf(display_act->fname_base, MAX_CHARS, "%s", fname_ext);
451 clist_buf_txt[display_act->count][0] = (gchar *) cl_int;
452 clist_buf_txt[display_act->count][1] = fname_base;
453 gtk_clist_insert(GTK_CLIST(gpiv->clist_buf), display_act->count,
454 clist_buf_txt[display_act->count]);
456 g_snprintf(display_act->msg_display_default, MAX_CHARS, "%s",
457 display_act->fname_base);
458 gnome_appbar_set_default(GNOME_APPBAR(display_act->appbar),
459 display_act->msg_display_default);
461 g_warning("file_saveas_ok_sel:: 1");
462 /* save_all_data(gpiv); */
463 exec_save(display_act);
464 g_warning("file_saveas_ok_sel:: 2");
465 g_free(fname_in);
466 g_free(dirname);
467 g_free(fname_base);
468 g_free(fname_ext);
473 void
474 save_all_data(GpivConsole * gpiv)
476 gint row, ibuf;
478 if (nbufs > 0) {
479 for (row = gpiv->first_selected_row; row <= gpiv->last_selected_row;
480 row++) {
481 display_act = gtk_clist_get_row_data(GTK_CLIST(gpiv->clist_buf),
482 row);
483 ibuf = display_act->count;
484 if (display[ibuf] != NULL
485 && display_act->mwin != NULL
486 && GTK_WIDGET_VISIBLE(GTK_WIDGET(display_act->mwin)) ) {
487 gdk_window_show(GTK_WIDGET(display_act->mwin)->window);
488 gdk_window_raise(GTK_WIDGET(display_act->mwin)->window);
491 exec_save(display_act);
499 static void
500 exec_save(Display * disp)
501 /*--------------------------------------------------------------------
502 * Store all data in display_act->fname_base.gpi in hdf5 format
505 char *err_msg = NULL;
506 gint return_val, flag_vor = 0;
507 char fname_out[MAX_CHARS], fname_par[MAX_CHARS];
508 FILE *fp_par;
510 if (gpiv_par.hdf) {
511 int return_val = 0;
512 if (print_par) gpiv_warning("writing HDF5 fmt");
513 gpiv_io_make_fname(display_act->fname_base, EXT_GPIV, fname_out);
515 if ((err_msg =
516 gpiv_fcreate_hdf5 (fname_out))
517 != NULL) gtk_error ("%s: %s", RCSID, err_msg);
519 if ((err_msg =
520 gpiv_img_fwrite_hdf5_parameters (fname_out,
521 &display_act->img.image_par))
522 != NULL) gtk_error ("%s: %s", RCSID, err_msg);
524 if (gpiv_par.hdf_img) {
525 if ((err_msg =
526 gpiv_fwrite_hdf5_image (fname_out, display_act->img.img1,
527 display_act->img.img2,
528 &display_act->img.image_par))
529 != NULL) gtk_error ("%s: %s", RCSID, err_msg);
534 if (display_act->gpd.exist_piv) {
535 if (display_act->gpd.scaled_piv) {
536 if ((err_msg =
537 gpiv_fwrite_hdf5_piv_position
538 (fname_out,
539 &display_act->gpd.piv_data_scaled,
540 RCSID,
541 &display_act->gpd.scaled_piv))
542 != NULL) gtk_error ("%s: %s", RCSID, err_msg);
544 if ((err_msg =
545 gpiv_fwrite_hdf5_pivdata
546 (fname_out,
547 &display_act->gpd.piv_data_scaled,
548 "PIV",
549 RCSID,
550 &display_act->gpd.scaled_piv))
551 != NULL) gtk_error ("%s: %s", RCSID, err_msg);
552 } else {
553 if ((err_msg =
554 gpiv_fwrite_hdf5_piv_position
555 (fname_out,
556 &display_act->gpd.piv_data,
557 RCSID,
558 &display_act->gpd.scaled_piv))
559 != NULL) gtk_error ("%s: %s", RCSID, err_msg);
561 if ((err_msg =
562 gpiv_fwrite_hdf5_pivdata
563 (fname_out,
564 &display_act->gpd.piv_data,
565 "PIV",
566 RCSID,
567 &display_act->gpd.scaled_piv))
568 != NULL) gtk_error ("%s: %s", RCSID, err_msg);
571 display_act->gpd.saved_piv = TRUE;
573 if ((err_msg =
574 gpiv_piv_fwrite_hdf5_parameters
575 (fname_out,
576 &display_act->gpd.piv_eval_par))
577 != NULL) gtk_error ("%s: %s", RCSID, err_msg);
581 if (display_act->gpd.exist_valid) {
582 if ((err_msg =
583 gpiv_valid_fwrite_hdf5_parameters
584 (fname_out, &display_act->gpd.piv_valid_par))
585 != NULL) gtk_error ("%s: %s", RCSID, err_msg);
589 if (display_act->gpd.exist_vor) {
590 if (display_act->gpd.scaled_piv ) {
591 if ((err_msg =
592 gpiv_fwrite_hdf5_scdata(fname_out,
593 &display_act->gpd.
594 vor_data_scaled,
595 "VORTICITY",
596 RCSID))
597 != NULL) gtk_error ("%s: %s", RCSID, err_msg);
598 } else {
599 if ((err_msg =
600 gpiv_fwrite_hdf5_scdata(fname_out,
601 &display_act->gpd.vor_data,
602 "VORTICITY",
603 RCSID))
604 != NULL) gtk_error ("%s: %s", RCSID, err_msg);
606 display_act->gpd.saved_vor = TRUE;
610 if (display_act->gpd.exist_sstrain) {
611 if (display_act->gpd.scaled_piv ) {
612 if ((err_msg =
613 gpiv_fwrite_hdf5_scdata(fname_out,
614 &display_act->gpd.
615 sstrain_data_scaled,
616 "SHEAR_STRAIN",
617 RCSID))
618 != NULL) gtk_error ("%s: %s", RCSID, err_msg);
619 } else {
620 if ((err_msg =
621 gpiv_fwrite_hdf5_scdata(fname_out,
622 &display_act->gpd.sstrain_data,
623 "SHEAR_STRAIN",
624 RCSID))
625 != NULL) gtk_error ("%s: %s", RCSID, err_msg);
627 display_act->gpd.saved_sstrain = TRUE;
631 if (display_act->gpd.exist_nstrain) {
632 if (display_act->gpd.scaled_piv ) {
633 if ((err_msg =
634 gpiv_fwrite_hdf5_scdata(fname_out,
635 &display_act->gpd.
636 nstrain_data_scaled,
637 "NORMAL_STRAIN",
638 RCSID))
639 != NULL) gtk_error ("%s: %s", RCSID, err_msg);
640 } else {
641 if ((err_msg =
642 gpiv_fwrite_hdf5_scdata(fname_out,
643 &display_act->gpd.nstrain_data,
644 "NORMAL_STRAIN",
645 RCSID))
646 != NULL) gtk_error ("%s: %s", RCSID, err_msg);
648 display_act->gpd.saved_nstrain = TRUE;
652 if ((err_msg =
653 gpiv_post_fwrite_hdf5_parameters (fname_out,
654 &display_act->gpd.piv_post_par))
655 != NULL) gtk_error ("%s: %s", RCSID, err_msg);
660 * Store all data in ASCII format at different files
662 } else {
663 if (print_par) gpiv_warning("writing ASCII fmt");
666 * Image header
668 gpiv_io_make_fname(display_act->fname_base, EXT_HEADER, fname_par);
669 if ((fp_par = fopen(fname_par, "w")) == NULL) {
670 gtk_error(_("Failure opening image header for output"));
672 fprintf(fp_par, "#%s\n", RCSID);
673 gpiv_img_fprint_header(fp_par, display_act->img.image_par);
674 fclose(fp_par);
678 * Parameters
680 gpiv_io_make_fname(display_act->fname_base, EXT_PAR, fname_par);
681 if ((fp_par = fopen(fname_par, "w")) == NULL) {
682 gtk_error(_("Failure opening parameter file for output"));
684 fprintf(fp_par, "#%s\n", RCSID);
685 gpiv_img_fprint_header(fp_par, display_act->img.image_par);
689 * Piv data
691 if (display_act->gpd.exist_piv) {
692 gpiv_io_make_fname(display_act->fname_base, EXT_PIV,
693 fname_out);
695 if (display_act->gpd.scaled_piv) {
696 if ((err_msg =
697 gpiv_fwrite_pivdata(fname_out,
698 &display_act->gpd.piv_data_scaled,
699 c_line,
701 display_act->gpd.scaled_piv,
702 RCSID))
703 != NULL) gtk_error ("%s: %s", RCSID, err_msg);
704 } else {
705 if ((err_msg =
706 gpiv_fwrite_pivdata(fname_out,
707 &display_act->gpd.piv_data,
708 c_line,
710 display_act->gpd.scaled_piv,
711 RCSID))
712 != NULL) gtk_error ("%s: %s", RCSID, err_msg);
715 display_act->gpd.saved_piv = TRUE;
716 gpiv_piv_fprint_parameters
717 (fp_par, display_act->gpd.piv_eval_par);
718 if (display_act->gpd.exist_valid) {
719 gpiv_valid_fprint_parameters
720 (fp_par, display_act->gpd.piv_valid_par);
726 * (Eventual) scalar data
728 if (display_act->gpd.exist_vor) {
729 gpiv_io_make_fname(display_act->fname_base, EXT_VOR,
730 fname_out);
731 if ((err_msg =
732 gpiv_fwrite_scdata(fname_out,
733 &display_act->gpd.vor_data,
734 c_line,
735 nc_lines,
736 display_act->gpd.scaled_piv,
737 RCSID))
738 != NULL) gtk_error ("%s: %s", RCSID, err_msg);
739 display_act->gpd.saved_vor = TRUE;
741 if (flag_vor == 0) {
742 gpiv_post_print_parameters(display_act->gpd.piv_post_par);
743 gpiv_post_fprint_parameters(fp_par,
744 display_act->gpd.piv_post_par);
745 flag_vor = 1;
749 if (display_act->gpd.exist_sstrain) {
750 gpiv_io_make_fname(display_act->fname_base, EXT_SSTR,
751 fname_out);
752 if ((err_msg =
753 gpiv_fwrite_scdata(fname_out,
754 &display_act->gpd.sstrain_data,
755 c_line,
756 nc_lines, display_act->gpd.scaled_piv,
757 RCSID))
758 != NULL) gtk_error ("%s: %s", RCSID, err_msg);
759 display_act->gpd.saved_sstrain = TRUE;
761 if (flag_vor == 0) {
762 gpiv_post_fprint_parameters(fp_par,
763 display_act->gpd.piv_post_par);
764 flag_vor = 1;
768 if (display_act->gpd.exist_nstrain) {
769 gpiv_io_make_fname(display_act->fname_base, EXT_NSTR,
770 fname_out);
771 if ((err_msg =
772 gpiv_fwrite_scdata(fname_out,
773 &display_act->gpd.nstrain_data,
774 c_line,
775 nc_lines,
776 display_act->gpd.scaled_piv,
777 RCSID))
778 != NULL) gtk_error ("%s: %s", RCSID, err_msg);
779 display_act->gpd.saved_nstrain = TRUE;
781 if (flag_vor == 0) {
782 gpiv_post_fprint_parameters(fp_par,
783 display_act->gpd.piv_post_par);
784 flag_vor = 1;
788 fclose(fp_par);
794 void
795 on_execute_activate(GtkMenuItem * menuitem,
796 gpointer user_data)
798 GpivConsole * gpiv = gtk_object_get_data(GTK_OBJECT(menuitem), "gpiv");
799 gint row, ibuf;
801 if (nbufs > 0) {
802 exec_process = TRUE;
803 for (row = gpiv->first_selected_row; row <= gpiv->last_selected_row;
804 row++) {
805 display_act = gtk_clist_get_row_data(GTK_CLIST(gpiv->clist_buf),
806 row);
807 ibuf = display_act->count;
808 if (display[ibuf] != NULL
809 && GTK_WIDGET_VISIBLE(GTK_WIDGET(display_act->mwin)) ) {
810 gdk_window_show(GTK_WIDGET(display_act->mwin)->window);
811 gdk_window_raise(GTK_WIDGET(display_act->mwin)->window);
814 if (!cancel_process && gpiv_par.process_piv) {
815 exec_piv(gpiv);
818 if (!cancel_process && gpiv_par.process_gradient) {
819 exec_gradient();
822 if (!cancel_process && gpiv_par.process_resstats) {
823 piv_valid_par.res_stats = 1;
824 exec_errvec(gpiv->pivvalid);
827 if (!cancel_process && gpiv_par.process_errvec) {
828 piv_valid_par.res_stats = 0;
829 exec_errvec(gpiv->pivvalid);
832 if (!cancel_process && gpiv_par.process_peaklock) {
833 exec_peaklock(gpiv->pivvalid);
836 if (!cancel_process && gpiv_par.process_scale) {
837 exec_scale(gpiv->pivpost);
840 if (!cancel_process && gpiv_par.process_average) {
841 exec_savg(gpiv->pivpost);
844 if (!cancel_process && gpiv_par.process_substract) {
845 exec_subavg(gpiv->pivpost);
848 if (!cancel_process && gpiv_par.process_vorstra) {
849 exec_vorstra();
854 exec_process = FALSE;
859 void
860 on_stop_activate(GtkMenuItem * menuitem,
861 gpointer user_data)
863 /* gtk_warning(_("process has been stopped")); */
867 void
868 on_button_stop_press (GtkWidget * widget,
869 gpointer data)
871 cancel_process = TRUE;
875 void
876 on_button_stop_release (GtkWidget * widget,
877 gpointer data)
879 cancel_process = FALSE;
883 void
884 on_close_activate(GtkMenuItem * menuitem,
885 gpointer user_data)
887 GpivConsole * gpiv = gtk_object_get_data(GTK_OBJECT(menuitem), "gpiv");
888 gint row, ibuf;
889 char message[2 * MAX_CHARS];
890 gint answer;
892 if (nbufs > 0) {
894 for (row = gpiv->first_selected_row; row <= gpiv->last_selected_row;
895 row++) {
896 display_act = gtk_clist_get_row_data
897 (GTK_CLIST(gpiv->clist_buf), row);
898 ibuf = display_act->count;
899 if (display[ibuf] != NULL) {
901 if(!display_act->gpd.saved_piv
902 || !display_act->gpd.saved_vor
903 || !display_act->gpd.saved_nstrain
904 || !display_act->gpd.saved_sstrain) {
906 g_snprintf(message, 2 * MAX_CHARS,
907 _("There are unsaved data that will be lost.\n\
908 Are you sure you want to close buffer #%d ?"),
909 display_act->count);
910 answer = close_buffer_yes_no (gpiv, message);
911 switch (answer){
912 case 0:
913 printf ("User selected yes\n");
914 free_all_bufmems(display_act);
915 ibuf = display_act->count;
916 gtk_widget_destroy(GTK_WIDGET(display_act->mwin));
917 display[ibuf] = NULL;
918 break;
919 case 1:
920 printf ("User selected no\n");
921 break;
922 case -1:
923 printf ("User closed the window with the window manager\n");
924 break;
928 } else {
929 free_all_bufmems(display_act);
930 ibuf = display_act->count;
931 gtk_widget_destroy(GTK_WIDGET(display_act->mwin));
932 display[ibuf] = NULL;
939 * Cleaning up clist
941 for (row = gpiv->first_selected_row; row <= gpiv->last_selected_row;
942 row++) {
943 display_act = gtk_clist_get_row_data
944 (GTK_CLIST(gpiv->clist_buf), gpiv->first_selected_row);
945 ibuf = display_act->count;
946 if (display[ibuf] == NULL) {
947 gtk_clist_remove(GTK_CLIST(gpiv->clist_buf),
948 gpiv->first_selected_row);
949 nbufs--;
950 } else {
951 gpiv->first_selected_row++;
959 * Point display_act to an existing buffer
961 for (ibuf = 0; ibuf < nbufs; ibuf++) {
962 if(display[ibuf] != NULL) {
963 gtk_clist_select_row(GTK_CLIST(gpiv->clist_buf),
964 ibuf,
966 display_act = display[ibuf];
972 void
973 on_exit_activate(GtkMenuItem * menuitem,
974 gpointer user_data)
976 /* GtkWidget *gpiv_exit; */
977 gint ibuf;
979 if (nbufs > 0) {
980 for (ibuf = 0; ibuf < nbufs; ibuf++) {
981 if (display[ibuf] != NULL) display_act = display[ibuf];
983 if(!display_act->gpd.saved_piv
984 || !display_act->gpd.saved_vor
985 || !display_act->gpd.saved_nstrain
986 || !display_act->gpd.saved_sstrain) {
987 gpiv_exit = create_exit ();
988 gtk_widget_show (gpiv_exit);
989 } else {
990 free_all_bufmems(display_act);
991 gtk_main_quit();
996 } else {
997 gtk_main_quit();
1002 void on_preferences_activate(GtkWidget * widget,
1003 /* GtkMenuItem * menuitem, */
1004 gpointer user_data)
1006 /* GtkWidget *gpiv_preferences; */
1008 GpivConsole *gpiv = gtk_object_get_data(GTK_OBJECT(widget), "gpiv");
1009 gpiv_preferences = create_preferences(gpiv);
1010 gtk_widget_show(gpiv_preferences);
1015 void on_about_activate(GtkMenuItem * menuitem, gpointer user_data)
1017 GtkWidget *about;
1018 about = create_about();
1019 gtk_widget_show(about);
1026 void on_manual_activate(GtkMenuItem * menuitem, gpointer user_data)
1028 static GnomeHelpMenuEntry help_entry = { "gpiv", "index.html" };
1029 /* /home/gerber/gpiv/doc/C/index.html */
1030 gnome_help_display(NULL, &help_entry);
1035 * Gnome toolbar buttons
1038 void
1039 on_button_open_clicked(GtkButton * button,
1040 gpointer data)
1042 gchar *msg = "Opens PIV data";
1043 GtkWidget *filew;
1044 GpivConsole *gpiv = gtk_object_get_data(GTK_OBJECT(button), "gpiv");
1048 * Create a new file selection widget
1049 * Connect the ok_button and cancel_button to file_ok_sel function
1050 * Set a default filename
1051 * set user data "gpiv" to filew
1053 filew = gtk_file_selection_new(_("File selection"));
1054 gtk_signal_connect(GTK_OBJECT(filew), "destroy",
1055 (GtkSignalFunc) destroy, &filew);
1056 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(filew)->ok_button),
1057 "clicked", (GtkSignalFunc) file_ok_sel,
1058 GTK_OBJECT(filew));
1059 gtk_signal_connect_object(GTK_OBJECT
1060 (GTK_FILE_SELECTION(filew)->ok_button),
1061 "clicked",
1062 (GtkSignalFunc) gtk_widget_destroy,
1063 GTK_OBJECT(filew));
1064 gtk_signal_connect_object(GTK_OBJECT
1065 (GTK_FILE_SELECTION(filew)->cancel_button),
1066 "clicked",
1067 (GtkSignalFunc) gtk_widget_destroy,
1068 GTK_OBJECT(filew));
1069 gtk_file_selection_set_filename(GTK_FILE_SELECTION(filew),
1070 /* DEFAULT_TEST_IMAGE */ fname_last);
1071 gtk_widget_show(filew);
1072 gtk_object_set_data(GTK_OBJECT(GTK_FILE_SELECTION(filew)),
1073 "gpiv",
1074 gpiv);
1077 gnome_appbar_set_status(GNOME_APPBAR(gpiv->appbar), msg);
1081 void on_menubar_activate(GtkWidget * widget, gpointer data)
1083 GpivConsole *gpiv = gtk_object_get_data(GTK_OBJECT(widget), "gpiv");
1084 if (GTK_CHECK_MENU_ITEM(widget)->active) {
1085 gtk_widget_show(gpiv->menubar);
1086 } else {
1087 gtk_widget_hide(gpiv->menubar);
1092 void on_toolbuttons_activate(GtkWidget * widget, gpointer data)
1094 GpivConsole *gpiv = gtk_object_get_data(GTK_OBJECT(widget), "gpiv");
1095 if (GTK_CHECK_MENU_ITEM(widget)->active) {
1096 gtk_widget_show(gpiv->toolbar1);
1097 /* gtk_widget_ref(settings_menu_gpiv_popup[1].widget); */
1098 /* gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM */
1099 /* (settings_menu_gpiv_popup[1].widget), */
1100 /* TRUE); */
1101 } else {
1102 gtk_widget_hide(gpiv->toolbar1);
1103 /* gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM */
1104 /* (settings_menu_gpiv_popup[1].widget), */
1105 /* FALSE); */
1111 void on_gpivbuttons_activate(GtkWidget * widget, gpointer data)
1113 GpivConsole *gpiv = gtk_object_get_data(GTK_OBJECT(widget), "gpiv");
1114 if (GTK_CHECK_MENU_ITEM(widget)->active) {
1115 gtk_widget_show(gpiv->handlebox1);
1117 } else {
1118 gtk_widget_hide(gpiv->handlebox1);
1123 void on_tabulator_activate(GtkWidget * widget, gpointer data)
1125 GpivConsole *gpiv = gtk_object_get_data(GTK_OBJECT(widget), "gpiv");
1126 if (GTK_CHECK_MENU_ITEM(widget)->active) {
1127 gtk_widget_show(gpiv->notebook);
1128 } else {
1129 gtk_widget_hide(gpiv->notebook);
1135 void on_tooltip_activate(GtkWidget * widget, gpointer data)
1137 GpivConsole *gpiv = gtk_object_get_data(GTK_OBJECT(widget), "gpiv");
1138 if (GTK_CHECK_MENU_ITEM(widget)->active) {
1139 gtk_tooltips_enable(gpiv->tooltips );
1140 gtk_tooltips_enable(gpiv->imgh->tooltips );
1141 gtk_tooltips_enable(gpiv->piveval->tooltips );
1142 gtk_tooltips_enable(gpiv->pivvalid->tooltips );
1143 gtk_tooltips_enable(gpiv->pivpost->tooltips );
1144 } else {
1145 gtk_tooltips_disable(gpiv->tooltips );
1146 gtk_tooltips_disable(gpiv->imgh->tooltips );
1147 gtk_tooltips_disable(gpiv->piveval->tooltips );
1148 gtk_tooltips_disable(gpiv->pivvalid->tooltips );
1149 gtk_tooltips_disable(gpiv->pivpost->tooltips );
1156 void
1157 on_buffer_set_focus(GtkWindow * window,
1158 GtkWidget * widget, gpointer user_data)
1160 /* SEE: on_clist_buf_rowselect */
1164 void
1165 gtk_window_destroy(GtkButton * button,
1166 gpointer user_data)
1172 void
1173 on_appbar_display_user_response(GnomeAppBar * gnomeappbar,
1174 gpointer user_data)
1180 void
1181 on_button_open_enter(GtkContainer * container,
1182 GtkDirectionType direction,
1183 gpointer user_data)
1185 GpivConsole *gpiv = gtk_object_get_data(GTK_OBJECT(container), "gpiv");
1186 gchar *msg = _("Opens image/PIV data (and display)");
1187 gnome_appbar_set_status(GNOME_APPBAR(gpiv->appbar), msg);
1191 void
1192 on_button_save_enter(GtkContainer * container,
1193 GtkDirectionType direction,
1194 gpointer user_data)
1196 GpivConsole *gpiv = gtk_object_get_data(GTK_OBJECT(container), "gpiv");
1197 gchar *msg = _("Saves data");
1198 gnome_appbar_set_status(GNOME_APPBAR(gpiv->appbar), msg);
1202 void
1203 on_button_execute_enter(GtkContainer * container,
1204 GtkDirectionType direction,
1205 gpointer user_data)
1207 GpivConsole *gpiv = gtk_object_get_data(GTK_OBJECT(container), "gpiv");
1208 gchar *msg = _("Executes all tickmarked processes");
1209 gnome_appbar_set_status(GNOME_APPBAR(gpiv->appbar), msg);
1213 void
1214 on_button_stop_enter(GtkContainer * container,
1215 GtkDirectionType direction,
1216 gpointer user_data)
1218 GpivConsole *gpiv = gtk_object_get_data(GTK_OBJECT(container), "gpiv");
1219 gchar *msg = _("Cancels any running processes");
1220 gnome_appbar_set_status(GNOME_APPBAR(gpiv->appbar), msg);
1224 void
1225 on_button_close_enter(GtkContainer * container,
1226 GtkDirectionType direction,
1227 gpointer user_data)
1229 GpivConsole *gpiv = gtk_object_get_data(GTK_OBJECT(container), "gpiv");
1230 gchar *msg = _("Close active buffer(s)");
1231 gnome_appbar_set_status(GNOME_APPBAR(gpiv->appbar), msg);
1235 void
1236 on_button_exit_enter(GtkContainer * container,
1237 GtkDirectionType direction, gpointer user_data)
1239 GpivConsole *gpiv = gtk_object_get_data(GTK_OBJECT(container), "gpiv");
1240 gchar *msg = _("Exits GPIV");
1241 gnome_appbar_set_status(GNOME_APPBAR(gpiv->appbar), msg);
1245 /*--------------------------------------------------------------------
1246 toolbar containing checkbutton for processes */
1247 void on_toolbar_checkbutton_piv(GtkWidget * widget, gpointer data)
1249 if (GTK_TOGGLE_BUTTON(widget)->active) {
1250 gpiv_par.process_piv = TRUE;
1251 } else {
1252 gpiv_par.process_piv = FALSE;
1257 void on_toolbar_checkbutton_gradient(GtkWidget * widget, gpointer data)
1259 if (GTK_TOGGLE_BUTTON(widget)->active) {
1260 gpiv_par.process_gradient = TRUE;
1261 } else {
1262 gpiv_par.process_gradient = FALSE;
1267 void on_toolbar_checkbutton_resstats(GtkWidget * widget, gpointer data)
1269 if (GTK_TOGGLE_BUTTON(widget)->active) {
1270 gpiv_par.process_resstats = TRUE;
1271 piv_valid_par.res_stats = 1;
1272 } else {
1273 gpiv_par.process_resstats = FALSE;
1274 piv_valid_par.res_stats = 0;
1279 void
1280 on_toolbar_checkbutton_errvec(GtkWidget * widget,
1281 gpointer data)
1283 if (GTK_TOGGLE_BUTTON(widget)->active) {
1284 gpiv_par.process_errvec = TRUE;
1285 } else {
1286 gpiv_par.process_errvec = FALSE;
1288 /* g_warning("on_toolbar_checkbutton_errvec:: process_errvec=%d", */
1292 void
1293 on_toolbar_checkbutton_peaklck(GtkWidget * widget,
1294 gpointer data)
1296 if (GTK_TOGGLE_BUTTON(widget)->active) {
1297 gpiv_par.process_peaklock = TRUE;
1298 } else {
1299 gpiv_par.process_peaklock = FALSE;
1304 void
1305 on_toolbar_checkbutton_scale(GtkWidget * widget,
1306 gpointer data)
1308 if (GTK_TOGGLE_BUTTON(widget)->active) {
1309 gpiv_par.process_scale = TRUE;
1310 } else {
1311 gpiv_par.process_scale = FALSE;
1316 void
1317 on_toolbar_checkbutton_average(GtkWidget * widget,
1318 gpointer data)
1320 if (GTK_TOGGLE_BUTTON(widget)->active) {
1321 gpiv_par.process_average = TRUE;
1322 } else {
1323 gpiv_par.process_average = FALSE;
1328 void
1329 on_toolbar_checkbutton_subavg(GtkWidget * widget,
1330 gpointer data)
1332 if (GTK_TOGGLE_BUTTON(widget)->active) {
1333 gpiv_par.process_substract = TRUE;
1334 } else {
1335 gpiv_par.process_substract = FALSE;
1340 void on_toolbar_checkbutton_vorstra(GtkWidget * widget, gpointer data)
1342 if (GTK_TOGGLE_BUTTON(widget)->active) {
1343 gpiv_par.process_vorstra = TRUE;
1344 } else {
1345 gpiv_par.process_vorstra = FALSE;
1352 /* GpivData * gpd_active = &display_act->gpd; */
1354 void on_button_quit_no_clicked(GtkButton * button, gpointer user_data)
1356 /*--------------------------------------------------------------------
1357 exit, message dialog callbacks */
1358 g_warning("on_button_quit_no_clicked::");
1359 gnome_dialog_close(GNOME_DIALOG(gpiv_exit));
1363 void on_button_quit_gpiv_yes_clicked(GtkButton * button, gpointer user_data)
1365 g_warning("on_button_quit_gpiv_yes_clicked::");
1366 free_all_bufmems(display_act);
1367 gtk_main_quit();
1371 void on_button_message_clicked(GtkButton * button, gpointer user_data)
1373 g_warning("on_button_message_clicked::");
1374 gnome_dialog_close(GNOME_DIALOG(gpiv_exit));
1377 void on_button_error_clicked(GtkButton * button, gpointer user_data)
1379 /* free_all_bufmems(); */
1380 gtk_main_quit();
1385 * Other functions than callbacks
1389 * loading images and (piv) data
1392 static void
1393 file_ok_sel(GtkWidget * widget,
1394 GtkFileSelection * fs)
1395 /* -------------------------------------------------------------------
1396 PIV data file selection */
1398 gchar *fname_in;
1399 GpivConsole *gpiv = gtk_object_get_data(GTK_OBJECT(fs), "gpiv");
1402 gtk_clist_set_selection_mode(GTK_CLIST (gpiv->clist_buf),
1403 GTK_SELECTION_SINGLE);
1405 fname_in =
1406 g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(fs)));
1408 #ifdef DEBUG
1409 if (print_par) g_warning("file_ok_sel:: fname_in = %s", fname_in);
1410 #endif
1412 select_action_from_fname(gpiv, fname_in);
1413 g_free(fname_in);
1418 static void
1419 select_action_from_fname(GpivConsole *gpiv,
1420 gchar *fname_in)
1421 /* -------------------------------------------------------------------
1422 checks filename extension on valid image/data name, on existence of buffer,
1423 loads data */
1425 gint i, j, ibuf, return_val;
1426 gchar *ext,
1427 *dirname,
1428 *fname_base,
1429 *fname_ext;
1430 gboolean exist_buf = FALSE;
1431 gboolean read_hdf;
1432 gchar *clist_buf_txt[MAX_BUFS][2], cl_int[2];
1435 ext = g_strdup(strrchr(fname_in, '.'));
1436 fname_last = g_strdup(fname_in);
1437 gnome_config_set_string("fname_last", fname_last);
1438 gnome_config_sync();
1441 * Stripping file name
1444 /*----------------------------------------------------------------------
1445 * With GLIB-2.0:
1446 * gchar* g_path_get_basename (const gchar *file_name);
1447 * gchar* g_path_get_dirname (const gchar *file_name);
1448 * g_build_filename
1449 *----------------------------------------------------------------------*/
1450 dirname = g_strdup(g_dirname(fname_in));
1451 fname_base = g_strdup(g_basename(fname_in));
1452 strtok(fname_base, ".");
1453 fname_ext = g_strdup(g_strconcat(dirname, G_DIR_SEPARATOR_S,
1454 fname_base, NULL));
1457 * reading image data from raw data format or hdf format
1459 if (strcmp(ext, EXT_RAW_IMAGE) == 0 || strcmp(ext, EXT_GPIV) == 0) {
1460 if (strcmp(ext, EXT_GPIV) == 0) {
1461 read_hdf = TRUE;
1462 } else {
1463 read_hdf = FALSE;
1465 exist_buf = FALSE;
1466 if (nbufs == 0) {
1467 sensitive(gpiv, IMG, TRUE);
1468 sensitive(gpiv, EVAL, TRUE);
1469 } else {
1472 * Check if file basename (and buffer/display) already exists
1473 * or if there is a gap in the numbering of th buffers
1475 for (ibuf = 0; ibuf < nbufs; ibuf++) {
1476 if (display[ibuf] != NULL
1477 && strcmp(fname_ext, display[ibuf]->fname_base) == 0 ) {
1478 if((return_val =
1479 open_img(fname_in, &display_act->img, read_hdf))
1480 != 0) {
1481 /* gtk_warning(_("open_img failed")); */
1482 return;
1486 * Displaying image
1489 /* display_img(display_act); */
1490 exist_buf = TRUE;
1491 break;
1492 } else if (display[ibuf] == NULL) {
1493 load_buffer(gpiv, fname_in, fname_base, fname_ext,
1494 read_hdf, ibuf, INSERT);
1495 exist_buf = TRUE;
1496 nbufs++;
1497 break;
1503 * Create new buffer and launches a display if file basename doesn't exist
1504 * and append to the list
1506 if (!exist_buf) {
1507 nbufs++;
1508 ibuf = nbufs - 1;
1509 load_buffer(gpiv, fname_in, fname_base, fname_ext, read_hdf,
1510 ibuf, APPEND);
1515 * reading piv data
1516 * NOT MAINTAINED
1518 } else if (strcmp(ext, ".piv") == 0) {
1519 exist_buf = FALSE;
1520 if (nbufs == 0) {
1521 sensitive(gpiv, EVAL, TRUE);
1522 } else {
1523 /* -------------------------------------------------------------------
1524 Look if file base name (and buffer/display) already exists */
1525 for (ibuf = 0; ibuf < nbufs; ibuf++) {
1526 if (strcmp(fname_ext, display_act->fname_base) == 0) {
1527 fprintf(stderr, "piv load::using existing buffer: %d",
1528 ibuf);
1529 open_piv(fname_in, &display_act->gpd);
1530 display_all_vectors(&display_act->gpd);
1531 exist_buf = TRUE;
1532 break;
1536 /* -------------------------------------------------------------------
1537 Create new buffer and launch a display if file base name doesn't exist */
1538 if (!exist_buf) {
1539 /* gint width, height; */
1540 nbufs++;
1541 ibuf = nbufs - 1;
1542 display_act->gpd.exist_piv = TRUE;
1543 g_snprintf(display_act->fname_base, MAX_CHARS, "%s", fname_ext);
1544 open_piv(fname_in, &display_act->gpd);
1546 /* display_act->gpd.zoom_factor = zfactor[gpiv_par.zoom_index]; */
1547 /* display_act->gpd.stretch_window = gpiv_par.stretch_window; */
1548 display[ibuf] = create_display(display_act->fname_base, ibuf, gpiv);
1549 display_act = display[ibuf];
1550 gtk_widget_show(display_act->mwin);
1551 gtk_signal_connect_object(GTK_OBJECT(display_act),
1552 "button_press_event",
1553 GTK_SIGNAL_FUNC (on_my_popup_handler),
1554 GTK_OBJECT(display_act->display_menu));
1558 g_snprintf(display_act->msg_display_default, MAX_CHARS, "%s",
1559 display_act->fname_base);
1560 gnome_appbar_set_default(GNOME_APPBAR(display_act->appbar),
1561 display_act->msg_display_default);
1563 g_snprintf(cl_int, 2, "%d", ibuf);
1564 gtk_object_set_data(GTK_OBJECT(display_act), "buffer_nr",
1565 cl_int);
1566 gtk_signal_connect(GTK_OBJECT(display_act),
1567 "focus_in_event",
1568 GTK_SIGNAL_FUNC(on_display_set_focus), NULL);
1570 display_background(display_act);
1571 for (i = 0; i < MAX_DATA; i++) {
1572 for (j = 0; j < MAX_DATA; j++) {
1573 display_act->gpd.gci_vector[i][j] = NULL;
1576 display_all_vectors(&display_act->gpd);
1578 clist_buf_txt[ibuf][0] = cl_int;
1579 clist_buf_txt[ibuf][1] = fname_base;
1580 gtk_clist_append(GTK_CLIST(gpiv->clist_buf),
1581 clist_buf_txt[ibuf]);
1582 fprintf(stderr, "finished gtk_clist\n");
1583 if (gpiv_par.display_intregs == 1)
1584 create_all_intregs(display_act);
1587 } else {
1588 gtk_warning(_("load_buffer: non-valid file name"));
1591 gtk_clist_set_selection_mode(GTK_CLIST (gpiv->clist_buf),
1592 GTK_SELECTION_EXTENDED);
1594 g_free(ext);
1595 g_free(dirname);
1596 g_free(fname_base);
1597 g_free(fname_ext);
1598 if (print_par) gpiv_warning("load_buffer: fname_base = %s", display_act->fname_base);
1603 static void
1604 load_buffer(GpivConsole *gpiv,
1605 char *fname_in,
1606 char *fname_base,
1607 char *fname_ext,
1608 gboolean read_hdf,
1609 int ibuf,
1610 enum ClistPut clist_put)
1611 /*--------------------------------------------------------------------
1612 * create display and its (popup) menu, load image and puts into clist
1615 gint return_val = 0;
1616 gchar *clist_buf_txt[MAX_BUFS][2], cl_int[2];
1618 display[ibuf] = create_display(fname_ext, ibuf, gpiv);
1619 display_act = display[ibuf];
1620 gtk_widget_show(display_act->mwin);
1621 display_act->display_menu = create_display_menu(display_act);
1622 gtk_widget_show(display_act->display_menu);
1623 gtk_signal_connect_object(GTK_OBJECT(display_act->mwin),
1624 "button_press_event",
1625 GTK_SIGNAL_FUNC (on_my_popup_handler),
1626 GTK_OBJECT(display_act->display_menu));
1627 zoom_display(display_act, display_act->zoom_index);
1631 * Load image data
1633 g_snprintf(display_act->fname_base, MAX_CHARS, "%s", fname_ext);
1634 if((return_val = open_img(fname_in, &display_act->img, read_hdf))
1635 != 0) {
1636 /* gtk_warning(_("open_img failed")); */
1637 gtk_object_destroy(GTK_OBJECT(display[ibuf]->mwin));
1638 if (ibuf > 0) {
1639 ibuf = nbufs - 1;;
1640 display_act = display[ibuf];
1641 } else {
1642 display_act = NULL;
1644 nbufs--;
1645 return;
1648 display_background(display_act);
1651 /* --------- TO BE IMPLEMENTED FOR IMAGES WITH RGB CANVAS --------------*/
1652 /* #ifdef DISPLAY_IMAGE */
1653 /* display_img(display_act); */
1654 /* #endif */
1655 /* ---------------------------------------------------------------------*/
1657 if (gpiv_par.display_intregs == 1)
1658 create_all_intregs(display_act);
1660 /* --------- TO BE REMOVED WITH RGB CANVAS ----------------------------*/
1661 /* ---------------------------------------------------------------------*/
1664 * Add buffer to list
1666 g_snprintf(cl_int, 2, "%d", ibuf);
1667 clist_buf_txt[ibuf][0] = (gchar *) cl_int;
1668 clist_buf_txt[ibuf][1] = fname_base;
1669 if (clist_put == PREPEND) {
1670 gtk_clist_prepend(GTK_CLIST(gpiv->clist_buf),
1671 clist_buf_txt[ibuf]);
1672 } else if (clist_put == INSERT) {
1673 gtk_clist_insert(GTK_CLIST(gpiv->clist_buf), ibuf,
1674 clist_buf_txt[ibuf]);
1675 } else if (clist_put == APPEND) {
1676 gtk_clist_append(GTK_CLIST(gpiv->clist_buf),
1677 clist_buf_txt[ibuf]);
1678 } else {
1679 gtk_error("non-existent CLIST enumerate");
1682 gtk_clist_set_row_data(GTK_CLIST(gpiv->clist_buf), ibuf,
1683 display_act);
1689 static int
1690 open_img(char *fname_in,
1691 Image * img,
1692 gboolean read_hdf
1694 /*--------------------------------------------------------------------
1695 * Opens image file
1698 char *err_msg = NULL;
1699 char fname_header[MAX_CHARS];
1700 char *fname_ext = display_act->fname_base;
1703 * parameter initializing of image
1705 img->image_par.nbits_logic = 0;
1706 img->image_par.ncolumns_logic = 0;
1707 img->image_par.nrows_logic = 0;
1708 img->image_par.x_corr_logic = 0;
1709 img->image_par.s_scale_logic = 0;
1710 img->image_par.t_scale_logic = 0;
1711 img->image_par.z_off_logic = 0;
1712 img->image_par.project_logic = 0;
1713 img->image_par.creation_date_logic = 0;
1714 img->image_par.location_logic = 0;
1715 img->image_par.comment_logic = 0;
1718 * Reads hdf format
1720 if (read_hdf) {
1721 int return_val = 0;
1722 if ((err_msg =
1723 gpiv_img_fread_hdf5_parameters(fname_in, &img->image_par);
1724 != NULL) {
1725 gtk_warning("%s: %s", RCSID, err_msg);
1726 return -1;
1728 if (img->image_par.nrows != gpiv_par.img_height
1729 || img->image_par.ncolumns != gpiv_par.img_width) {
1730 gtk_warning(_("Image dimensions (%dx%d) differ from \n\
1731 parameter settings (%dx%d"),
1732 img->image_par.ncolumns, img->image_par.nrows,
1733 gpiv_par.img_width, gpiv_par.img_height);
1734 return -1;
1736 copy_img_par(image_par, &img->image_par, FALSE, print_par);
1737 if ((err_msg =
1738 gpiv_img_check_header_read(img->image_par))
1739 != NULL) {
1740 gtk_warning("%s: %s", RCSID, err_msg);
1741 return -1;
1744 img->img1 = gpiv_ucmatrix(0, img->image_par.nrows - 1, 0,
1745 img->image_par.ncolumns - 1);
1746 if (img->image_par.x_corr != image_par.x_corr) {
1747 gtk_warning(_("cross correlation parameter from image \n\
1748 not in agreement with GPIV setting"));
1749 return -1;
1751 if (img->image_par.x_corr)
1752 img->img2 = gpiv_ucmatrix(0, img->image_par.nrows - 1, 0,
1753 img->image_par.ncolumns - 1);
1754 if ((err_msg =
1755 gpiv_fread_hdf5_image (fname_in, img->img1,
1756 img->img2, &img->image_par))
1757 != NULL) {
1758 gtk_warning ("%s: %s", RCSID, err_msg);
1759 return -1;
1763 } else {
1765 * Reads raw data format
1766 * Reads image header data from file.h or copies from originanals
1768 g_snprintf(fname_header, MAX_CHARS, "%s%s", fname_ext, EXT_HEADER);
1769 if (print_par) gpiv_warning("\n#image header is: %s", fname_header);
1770 gpiv_scan_parameter( "", fname_header, &img->image_par, print_par);
1771 if (print_par)
1772 g_warning("open_img:: x_corr_logic = %d \n"
1773 "image_par.nrows = %d \n"
1774 "image_par.ncolumns = %d",
1775 img->image_par.x_corr_logic,
1776 img->image_par.nrows,
1777 img->image_par.ncolumns );
1778 if (img->image_par.nrows != gpiv_par.img_height
1779 || img->image_par.ncolumns != gpiv_par.img_width) {
1780 gtk_warning(_("Image dimensions (%dx%d) differ from \n\
1781 parameter settings (%dx%d)"),
1782 img->image_par.ncolumns, img->image_par.nrows,
1783 gpiv_par.img_width, gpiv_par.img_height);
1784 return -1;
1786 copy_img_par (image_par, &img->image_par, FALSE, print_par);
1787 if ((err_msg =
1788 gpiv_img_check_header_read(img->image_par))
1789 != NULL) {
1790 gtk_warning ("%s: %s", RCSID, err_msg);
1791 return -1;
1794 * memory allocation of matrices and vectors
1795 * gpiv_alloc_imgdata(img->img1, image_par.nrows, image_par.ncolumns);
1797 img->img1 = gpiv_ucmatrix(0, img->image_par.nrows - 1, 0,
1798 img->image_par.ncolumns - 1);
1799 if (img->image_par.x_corr != image_par.x_corr) {
1800 gtk_warning(_("cross correlation parameter from image \n\
1801 not in agreement with GPIV setting"));
1802 return -1;
1804 if (image_par.x_corr)
1805 img->img2 = gpiv_ucmatrix(0, img->image_par.nrows - 1, 0,
1806 img->image_par.ncolumns - 1);
1810 * reads image data from file in binary format
1812 if ((err_msg =
1813 gpiv_fread_image(fname_in, img->img1, img->img2, img->image_par);
1814 != NULL) {
1815 gtk_warning ("%s: %s", RCSID, err_msg);
1816 return -1;
1818 /* if (!img->img1 || !img->img2) { */
1819 /* gtk_warning(_("failure reading image")); */
1820 /* return -1; */
1821 /* } */
1824 display_act->img.exist_img = TRUE;
1825 return 0;
1829 static void
1830 open_piv(char *fname,
1831 GpivData * gpd
1833 /*------------------------ Opens piv data file and views in display */
1835 char *function_name = "open_piv";
1836 int return_val;
1838 /* var_scale = 0; */
1839 nc_lines = 0;
1841 if ((return_val =
1842 gpiv_fcount_pivdata(fname, &gpd->piv_data)) == -1) {
1843 gpiv_error(_("%s: Failure calling gpiv_count_pivdata\n"), PROGNAME);
1845 } else if (print_par) {
1846 fprintf(stderr, "%s: %s: scale=%d nx=%d ny=%d \n",
1847 function_name, fname, display_act->gpd.scaled_piv, gpd->piv_data.nx,
1848 gpd->piv_data.ny);
1852 gpiv_alloc_pivdata(&gpd->piv_data);
1853 gpd->exist_piv = TRUE;
1855 if ((err_msg =
1856 gpiv_fread_pivdata(fname, &gpd->piv_data, c_line, &nc_lines))
1857 != NULL) {
1858 gtk_warning ("%s: %s", RCSID, err_msg);
1859 return -1;
1862 if (print_par)
1863 gpiv_write_pivdata(&gpd->piv_data, c_line, nc_lines,
1864 display_act->gpd.scaled_piv, RCSID);