bug repair: loading .png image, from Adrian Daerr
[gpiv.git] / src / console.c
blobb2b589933670edf78c881689821174d5c4682b0b
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, 2003, 2004, 2005, 2006, 2007, 2008
9 Gerber van der Graaf <gerber_graaf@users.sourceforge.net>
11 This file is part of gpiv.
13 Gpiv is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2, or (at your option)
16 any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 ----------------------------------------------------------------------*/
30 * (Callback) functions for console
31 * $Log: console.c,v $
32 * Revision 1.30 2008-05-07 08:34:20 gerber
33 * uses .h5 and .H5 extension for hdf files (previously: .gpi)
35 * Revision 1.29 2008-04-28 12:00:57 gerber
36 * hdf-formatted files are now with .hdf extension (previously: .gpi)
38 * Revision 1.28 2007-12-19 08:42:35 gerber
39 * debugged
41 * Revision 1.27 2007-11-23 16:24:07 gerber
42 * release 0.5.0: Kafka
44 * Revision 1.26 2007-06-06 17:00:48 gerber
45 * Retreives images/data from URI using Gnome Virtual File System.
47 * Revision 1.25 2007-03-22 16:00:32 gerber
48 * Added image processing tabulator
50 * Revision 1.24 2007/02/05 15:17:09 gerber
51 * auto stretching, broadcast display settings to buffers from preferences
53 * Revision 1.23 2007-01-29 11:27:43 gerber
54 * added image formats png, gif, tif png, bmp, improved buffer display
56 * Revision 1.22 2006-09-18 07:27:03 gerber
57 * *** empty log message ***
59 * Revision 1.21 2006/01/31 14:28:11 gerber
60 * version 0.3.0
62 * Revision 1.19 2005/02/26 09:43:30 gerber
63 * parameter flags (parameter_logic) defined as gboolean
65 * Revision 1.18 2005/02/26 09:17:13 gerber
66 * structured of interrogate function by using gpiv_piv_isiadapt
68 * Revision 1.17 2005/02/12 13:09:21 gerber
69 * Changing some structure and constant names for DAC
71 * Revision 1.16 2005/01/19 15:53:41 gerber
72 * Initiation of Data Acquisition (DAC); trigerring of lasers and camera
73 * by using RTAI and Realtime Linux, recording images from IEEE1394
74 * (Firewire) IIDC compliant camera's
76 * Revision 1.15 2004/10/15 19:24:05 gerber
77 * GPIV_ and Gpiv prefix to defines and structure names of libgpiv
79 * Revision 1.14 2004/06/14 21:19:23 gerber
80 * Image depth up to 16 bits.
81 * Improvement "single int" and "drag int" in Eval tab.
82 * Viewer's pop-up menu.
83 * Adaption for gpiv_matrix_* and gpiv_vector_*.
84 * Resizing console.
85 * See Changelog for further info.
87 * Revision 1.13 2003/09/04 13:31:54 gerber
88 * init of printing (unfinished)
90 * Revision 1.12 2003/09/01 11:17:14 gerber
91 * improved monitoring of interrogation process
93 * Revision 1.11 2003/08/22 15:24:52 gerber
94 * interactive spatial scaling
96 * Revision 1.10 2003/07/31 11:43:26 gerber
97 * display images in gnome canvas (HOERAreset)
99 * Revision 1.9 2003/07/25 15:40:23 gerber
100 * removed/disabled setting of correlation in Eval tab, Correlation type in Image info tab
102 * Revision 1.8 2003/07/13 14:38:18 gerber
103 * changed error handling of libgpiv
105 * Revision 1.7 2003/07/12 21:21:15 gerber
106 * changed error handling libgpiv
108 * Revision 1.5 2003/07/10 11:56:07 gerber
109 * added man page
111 * Revision 1.4 2003/07/06 15:29:49 gerber
112 * repair message text closing buffer
114 * Revision 1.3 2003/07/05 13:14:57 gerber
115 * drag and drop of a _series_ of filenames from NAUTILUS
117 * Revision 1.2 2003/06/27 13:47:26 gerber
118 * display ruler, line/point evaluation
120 * Revision 1.1.1.1 2003/06/17 17:10:52 gerber
121 * Imported gpiv
125 #ifdef HAVE_CONFIG_H
126 # include <config.h>
127 #endif
128 #include "support.h"
130 #include "gpiv_gui.h"
131 #include "console_interface.h"
132 #include "dialog_interface.h"
133 #include "console_menus.h"
134 #include "console.h"
135 #include "display.h"
137 #ifdef ENABLE_DAC
138 #include "dac.h"
139 #endif /* ENABLE_DAC */
141 #ifdef ENABLE_TRIG
142 #include "dac_trig.h"
143 #endif /* ENABLE_TRIG */
145 #ifdef ENABLE_CAM
146 #include "dac_cam.h"
147 #endif /* ENABLE_CAM */
149 #include "piveval_interrogate.h"
150 #include "pivvalid.h"
151 #include "pivpost.h"
152 #include "preferences.h"
153 #include "print.h"
154 #include "io.h"
155 #include "utils.h"
157 #define CHOOSER
160 static void
161 file_saveas_accept (GpivConsole *gpiv,
162 const gchar *fname
165 typedef enum _Format Format;
166 enum _Format {
167 RAW_ASCII,
168 HDF,
169 GPIV_DAVIS,
173 static void
174 exec_save (Display * disp);
176 * Local functions
179 static void
180 exec_save (Display * disp)
181 /*-----------------------------------------------------------------------------
182 * Store all data in display_act->file_uri_name.h5 in hdf5 format
185 char *err_msg = NULL;
186 char *fname_out_nosuf, *fname_par;
188 gchar *uri_string_out, *uri_string_tmp;
189 GnomeVFSURI *uri_out = NULL, *uri_tmp = NULL;
193 * Create a valid uri_out to build the local or tmp fname_out_nosuf.
194 * Type of suffix doesn't actually matter as the correct suffix will
195 * be extended later to fname_out
197 if (gpiv_par->verbose) g_message ("exec_save:: file_uri_name = %s", display_act->file_uri_name);
198 uri_string_out =
199 gnome_vfs_make_uri_from_input (g_strdup_printf
200 ("%s%s" ,display_act->file_uri_name,
201 GPIV_EXT_GPIV));
202 uri_out = gnome_vfs_uri_new (uri_string_out);
203 g_free (uri_string_out);
205 if (gnome_vfs_uri_is_local (uri_out)) {
206 fname_out_nosuf = g_strdup_printf ("%s" , display_act->file_uri_name);
207 if (gpiv_par->verbose) g_message ("exec_save:: LOCAL fname_out_nosuf = %s", fname_out_nosuf);
208 } else {
209 const gchar *tmp_dir = g_get_tmp_dir ();
210 const gchar *user_name = g_get_user_name ();
211 fname_out_nosuf = g_strdup_printf ("%s/%s/%s" , tmp_dir,
212 user_name,
213 strtok (gnome_vfs_uri_extract_short_name
214 (uri_out), "."));
215 if (gpiv_par->verbose) g_message ("exec_save:: URI fname_out_suf for to tmp: %s", fname_out_nosuf);
217 /* return; */
220 if (gpiv_par->verbose) g_message ("exec_save:: STARTING THE REAL JOB");
221 if (gpiv_par->hdf) {
222 write_hdf_img_data (fname_out_nosuf, uri_out);
224 } else {
226 * Store all data in ASCII format at different files
228 #define SAVE_IMG
229 #ifdef SAVE_IMG
230 write_img (fname_out_nosuf, uri_out);
231 #endif /* SAVE_IMG */
232 write_ascii_parameters (fname_out_nosuf, uri_out, GPIV_EXT_PAR);
233 write_ascii_data (fname_out_nosuf, uri_out);
236 g_free (fname_out_nosuf);
242 * Main gpiv-gui callbacks
246 void
247 delete_console (GtkWidget *widget,
248 GdkEvent *event,
249 gpointer data)
250 /*-----------------------------------------------------------------------------
253 GpivConsole *gpiv = gtk_object_get_data (GTK_OBJECT (widget), "gpiv");
254 guint i;
255 GtkDialog *gpiv_exit = NULL;
257 #ifdef ENABLE_TRIG
258 exec_trigger_stop ();
259 #endif /* ENABLE_TRIG */
260 #ifdef ENABLE_CAM
261 exec_cam_stop ();
262 #endif /* ENABLE_CAM */
264 if (nbufs > 0) {
265 for (i = 0; i < nbufs; i++) {
266 /* if (display[i] != NULL) display_act = display[i]; */
267 display_act = gtk_clist_get_row_data (GTK_CLIST (gpiv->clist_buf), i);
268 if (!display_act->img->saved_img
269 || !display_act->pida->saved_piv
270 || !display_act->pida->saved_histo
271 || !display_act->pida->saved_vor
272 || !display_act->pida->saved_nstrain
273 || !display_act->pida->saved_sstrain) {
274 gpiv_exit = create_exit_dialog ();
275 gtk_widget_show_all (GTK_WIDGET (gpiv_exit));
276 } else {
277 free_all_bufmems (display_act);
278 gtk_main_quit ();
283 } else {
284 gtk_main_quit ();
290 void
291 on_clist_buf_rowselect (GtkWidget *clist,
292 gint row,
293 gint column,
294 GdkEventButton *event,
295 gpointer data)
296 /*-----------------------------------------------------------------------------
299 gchar *text;
300 GpivConsole * gpiv = gtk_object_get_data (GTK_OBJECT (clist), "gpiv");
301 GList *lis;
302 gint cnt = 0, buf_dum = 0;
303 gboolean saved_img_local;
306 if (!exec_process && GTK_CLIST (clist)->selection) {
307 for (lis = GTK_CLIST (clist)->selection; lis; lis = lis->next) {
308 row = GPOINTER_TO_INT (lis->data);
309 /* g_message ("on_clist_buf_rowselect:: row = %d", row); */
310 gtk_clist_get_text (GTK_CLIST (clist), row, /* column */ 0, &text);
311 display_act = gtk_clist_get_row_data (GTK_CLIST (clist /*= gpiv->clist_buf */),
312 row);
313 saved_img_local = display_act->img->saved_img;
315 if (cnt == 0) {
316 gpiv->first_selected_row = row;
317 } else {
318 gpiv->last_selected_row = row;
321 * BUGFIX: update variables of display before leaving the focus.
322 * BUGFIX: Already done when creating display
324 if (display_act->intreg->exist_int) {
325 display_act->intreg->row_start_old = 0;
326 display_act->intreg->col_start_old = 0;
327 display_act->intreg->par->row_start = gl_piv_par->row_start;
328 display_act->intreg->par->row_end = gl_piv_par->row_end;
329 display_act->intreg->par->col_start = gl_piv_par->col_start;
330 display_act->intreg->par->col_end = gl_piv_par->col_end;
331 display_act->intreg->par->int_size_f = gl_piv_par->int_size_f;
332 display_act->intreg->par->int_size_i = gl_piv_par->int_size_i;
333 display_act->intreg->par->int_shift = gl_piv_par->int_shift;
334 display_act->intreg->par->pre_shift_row = gl_piv_par->pre_shift_row;
335 display_act->intreg->par->pre_shift_col = gl_piv_par->pre_shift_col;
339 /* if (GTK_WIDGET_REALIZED (display_act->pida.display)) */
341 /* display_act = gtk_clist_get_row_data (GTK_CLIST (gpiv->clist_buf), */
342 /* row); */
345 * Set variables of new active display equal to parameters
347 if (display_act->intreg->exist_int
348 && (display_act->intreg->par->row_start != gl_piv_par->row_start
349 || display_act->intreg->par->row_end != gl_piv_par->row_end
350 || display_act->intreg->par->col_start != gl_piv_par->col_start
351 || display_act->intreg->par->col_end != gl_piv_par->col_end
352 || display_act->intreg->par->int_size_f != gl_piv_par->int_size_f
353 || display_act->intreg->par->int_size_i != gl_piv_par->int_size_i
354 || display_act->intreg->par->int_shift != gl_piv_par->int_shift
355 || display_act->intreg->par->pre_shift_row != gl_piv_par->pre_shift_row
356 || display_act->intreg->par->pre_shift_col != gl_piv_par->pre_shift_col)
358 destroy_all_intregs (display_act);
359 create_all_intregs (display_act);
362 if (display_act->mwin != NULL
363 && GTK_WIDGET_VISIBLE (GTK_WIDGET (display_act->mwin))
364 ) {
365 /* gchar *author = "Guppie GRAAF"; */
366 gdk_window_show (GTK_WIDGET (display_act->mwin)->window);
367 gdk_window_raise (GTK_WIDGET (display_act->mwin)->window);
370 * update labels and entries in image header tab/window
372 update_imgh_entries (gpiv, display_act->img->image->header);
373 display_act->img->saved_img = saved_img_local;
374 update_eval_entries (gpiv, display_act->img->image->header);
378 cnt++;
381 if (cnt == 1) {
382 gpiv->last_selected_row = gpiv->first_selected_row;
386 * exchange first and last
388 if (gpiv->last_selected_row < gpiv->first_selected_row) {
389 buf_dum = gpiv->last_selected_row;
390 gpiv->last_selected_row = gpiv->first_selected_row;
391 gpiv->first_selected_row = buf_dum;
395 /* g_message("on_clist_buf_rowselect:: nbufs = %d, first=%d last = %d", */
396 /* nbufs, gpiv->first_selected_row, gpiv->last_selected_row); */
402 void
403 on_clist_buf_drag_data_received (GtkWidget *widget,
404 GdkDragContext *context,
405 gint x,
406 gint y,
407 GtkSelectionData *selection_data,
408 guint info,
409 guint time)
410 /*-----------------------------------------------------------------------------
411 * load the data from selected uris with drag and drop
414 GpivConsole *gpiv = gtk_object_get_data (GTK_OBJECT (widget), "gpiv");
415 gchar *fname_in;
416 gchar **uri_v;
417 gint i;
419 if (info != TARGET_URI_LIST) {
420 g_message ("on_clist_buf_drag_data_received: info != TARGET_URI_LIST");
421 return;
423 if (selection_data == NULL) {
424 g_message ("on_clist_buf_drag_data_received: selection_data == NULL");
425 return;
427 if(selection_data->length < 0) {
428 g_message ("on_clist_buf_drag_data_received: selection_data->length < 0");
429 return;
432 uri_v = g_uri_list_extract_uris ((gchar *) selection_data->data);
434 for (i = 0; uri_v[i] != NULL; i++) {
435 if (gpiv_par->verbose) g_message ("on_clist_buf_drag_data_received:: uri_v[%d] = %s", i, uri_v[i]);
436 fname_in = g_strdup (uri_v[i]);
437 g_strchomp (fname_in);
438 select_action_from_name (gpiv, fname_in);
439 g_free (fname_in);
442 g_strfreev (uri_v);
446 void
447 on_open_activate_response (GtkDialog *dialog,
448 gint response,
449 gpointer data
451 /*-----------------------------------------------------------------------------
454 GpivConsole *gpiv = gtk_object_get_data (GTK_OBJECT(dialog), "gpiv");
455 /* Display *disp = gtk_object_get_data (GTK_OBJECT(dialog), "display"); */
456 char *filename;
459 g_assert ( response == GTK_RESPONSE_ACCEPT
460 || response == GTK_RESPONSE_CANCEL);
462 switch (response) {
463 case GTK_RESPONSE_ACCEPT:
464 filename = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
465 if (gpiv_par->verbose) g_message ("on_open_activate:: filename = %s", filename);
466 select_action_from_name (gpiv, filename);
467 g_free (filename);
468 break;
470 case GTK_RESPONSE_CANCEL:
471 break;
473 default:
474 g_warning("on_open_activate_response: should not arrive here");
475 break;
481 void
482 on_open_activate (GtkMenuItem *menuitem,
483 gpointer user_data)
484 /*-----------------------------------------------------------------------------
487 GpivConsole *gpiv = gtk_object_get_data (GTK_OBJECT (menuitem), "gpiv");
488 GtkWidget *dialog;
490 if (gpiv_par->verbose) g_message ("on_open_activate:: fname_last = %s",
491 gpiv_var->fname_last);
492 dialog = gtk_file_chooser_dialog_new ("Open Uri/File",
493 GTK_WINDOW (gpiv->console),
494 GTK_FILE_CHOOSER_ACTION_OPEN,
495 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
496 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
497 NULL);
499 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), FALSE);
500 gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (dialog), gpiv_var->fname_last);
502 #undef USE_CALLBACK
503 #ifdef USE_CALLBACK
504 /* Will not open dialog when pressing ^O */
505 g_signal_connect (dialog,
506 "response",
507 G_CALLBACK (on_open_activate_response),
508 NULL);
510 g_signal_connect_swapped (GTK_DIALOG (dialog),
511 "response",
512 G_CALLBACK (gtk_widget_destroy),
513 dialog);
515 gtk_object_set_data (GTK_OBJECT (dialog),
516 "gpiv",
517 gpiv);
519 #else
520 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
521 char *filename;
523 filename = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
524 if (gpiv_par->verbose) g_message ("on_open_activate:: filename = %s", filename);
525 select_action_from_name (gpiv, filename);
526 g_free (filename);
529 gtk_widget_destroy (dialog);
530 #endif /* USE_CALLBACK */
531 #ifdef USE_CALLBACK
532 #undef USE_CALLBACK
533 #endif
537 void
538 on_save_activate (GtkMenuItem * menuitem,
539 gpointer user_data)
540 /*-----------------------------------------------------------------------------
543 GpivConsole * gpiv = gtk_object_get_data (GTK_OBJECT (menuitem), "gpiv");
544 save_all_data (gpiv);
548 void
549 on_save_as_activate (GtkMenuItem *menuitem,
550 gpointer user_data)
551 /*-----------------------------------------------------------------------------
554 GpivConsole *gpiv = gtk_object_get_data (GTK_OBJECT (menuitem), "gpiv");
555 GtkWidget *dialog;
557 dialog = gtk_file_chooser_dialog_new ("Save as",
558 GTK_WINDOW (gpiv->console),
559 GTK_FILE_CHOOSER_ACTION_SAVE,
560 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
561 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
562 NULL);
564 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), FALSE);
565 gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (dialog), gpiv_var->fname_last);
567 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
568 char *fname = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
569 if (gpiv_par->verbose) g_message ("on_save_as_activate:: fname = %s", fname);
570 file_saveas_accept (gpiv, fname /* dialog */);
571 g_free (fname);
574 gtk_widget_destroy (dialog);
578 static void
579 file_saveas_accept (GpivConsole *gpiv,
580 const gchar *fname
582 /* ----------------------------------------------------------------------------
583 * Stores PIV image, data and related under different name
586 gchar *text_uri, *suffix;
587 GnomeVFSURI* uri = NULL;
588 gchar *fname_base; /* file name without suffix and directory name */
589 gchar *clist_buf_txt[MAX_BUFS][2], cl_int[3];
590 gboolean local_hdf_par;
593 * Set gpiv_par->hdf if filename has suffix GPIV_EXT_GPIV.
594 * Reset after calling exec_save.
595 * Set saved_img to FALSE to guarantee saving image.
597 suffix = g_strdup (strrchr (fname, '.'));
598 if (strcmp (suffix, GPIV_EXT_GPIV) == 0) {
599 local_hdf_par = gpiv_par->hdf;
600 gpiv_par->img_fmt = IMG_FMT_HDF;
602 display_act->img->saved_img = FALSE;
605 * Check if uri is local filesystem
606 * create proper local filename or uri and short name
608 text_uri = gnome_vfs_make_uri_from_shell_arg (fname);
609 uri = gnome_vfs_uri_new (text_uri);
610 g_free (text_uri);
612 if (gnome_vfs_uri_is_local (uri)) {
613 const gchar *path = gnome_vfs_uri_get_path (uri);
614 gchar *dirname, /* directory name */
615 *fname_nosuf, /* filename including dirname/uri, without suffix */
616 *fname_home; /* filename with $HOME substituted by ~, without suffix */
618 fname_home = replace_home_dir_with_tilde (path);
619 dirname = g_strdup (g_path_get_dirname (fname_home));
620 g_free (fname_home);
622 /* dirname = g_strdup (g_path_get_dirname */
623 /* (replace_home_dir_with_tilde (path))); */
625 fname_base = g_strdup (strtok (/*g_path_get_basename (path) */ dirname, "."));
626 strtok (fname_base, ".");
627 fname_nosuf = g_strdup (g_strconcat (dirname, G_DIR_SEPARATOR_S, fname_base, NULL));
628 fname_home = replace_home_dir_with_tilde (fname_nosuf);
629 if (gpiv_par->verbose) g_message ("file_saveas_accept:: LOCAL dirname = %s fname_base = %s fname_home = %s",
630 dirname, fname_base, fname_home);
632 display_act->file_uri_name = g_strdup_printf ("%s", fname_home);
634 g_free (dirname);
635 g_free (fname_home);
636 g_free (fname_nosuf);
638 } else {
639 fname_base = strtok (gnome_vfs_uri_extract_short_name (uri), ".");
640 g_snprintf (display_act->file_uri_name, GPIV_MAX_CHARS, "%s",
641 strtok (gnome_vfs_uri_to_string (uri, TRUE), "."));
645 * Substituting file_uri_name in display_act
646 * Changing fname in clist and in Image tab of the console
647 * storing data of display_act
648 * Resetting gpiv_par->hdf (and gpiv_par->img_fmt)
650 gtk_clist_remove (GTK_CLIST (gpiv->clist_buf), display_act->id);
651 g_snprintf (cl_int, 3, "%d", display_act->id);
652 clist_buf_txt[display_act->id][0] = (gchar *) cl_int;
653 clist_buf_txt[display_act->id][1] = fname_base;
654 gtk_clist_insert (GTK_CLIST (gpiv->clist_buf), display_act->id,
655 clist_buf_txt[display_act->id]);
656 g_snprintf (display_act->msg_display_default, GPIV_MAX_CHARS, "%s",
657 display_act->file_uri_name);
658 gnome_appbar_set_default (GNOME_APPBAR (display_act->appbar),
659 display_act->msg_display_default);
660 update_imgh_entries (gpiv, display_act->img->image->header);
661 exec_save (display_act);
663 if (strcmp (suffix, GPIV_EXT_GPIV) == 0) {
664 /* gpiv_par->hdf = local_hdf_par; */
665 gpiv_par->img_fmt = default_par->img_fmt;
668 g_free (suffix);
669 g_free (fname_base);
674 void
675 save_all_data (GpivConsole * gpiv)
676 /*-----------------------------------------------------------------------------
679 guint row, ibuf;
681 if (nbufs > 0) {
682 for (row = gpiv->first_selected_row; row <= gpiv->last_selected_row;
683 row++) {
684 display_act = gtk_clist_get_row_data (GTK_CLIST (gpiv->clist_buf),
685 row);
686 ibuf = display_act->id;
687 if (display[ibuf] != NULL
688 && display_act->mwin != NULL
689 && GTK_WIDGET_VISIBLE (GTK_WIDGET (display_act->mwin)) ) {
690 gdk_window_show (GTK_WIDGET (display_act->mwin)->window);
691 gdk_window_raise (GTK_WIDGET (display_act->mwin)->window);
694 exec_save (display_act);
702 void
703 on_print_activate (GtkMenuItem * menuitem,
704 gpointer user_data)
705 /*-----------------------------------------------------------------------------
708 GpivConsole *gpiv = gtk_object_get_data (GTK_OBJECT (menuitem), "gpiv");
709 GtkDialog *gpiv_print_dialog = create_print_dialog (gpiv);
710 gtk_widget_show (GTK_WIDGET (gpiv_print_dialog));
715 void
716 on_execute_activate (GtkMenuItem * menuitem,
717 gpointer user_data)
718 /*-----------------------------------------------------------------------------
721 GpivConsole * gpiv = gtk_object_get_data (GTK_OBJECT (menuitem), "gpiv");
722 guint row, ibuf;
724 cancel_process = FALSE;
726 #ifdef ENABLE_CAM
727 #ifdef ENABLE_TRIG
729 * RTA may trigger camera, but camera and RTAI trigger system may also be used
730 * separately
732 if (/* !cancel_process && */ gpiv_par->process__trig
733 && gpiv_par->process__cam) {
734 exec_cam_start (gpiv);
735 exec_trigger_start ();
736 if (trig_par->ttime->mode == GPIV_TIMER_MODE__DURATION) {
737 gpiv->first_selected_row = 0;
738 gpiv->last_selected_row = trig_par->ttime->cycles - 1;
740 } else if (/* !cancel_process && */ gpiv_par->process__cam) {
741 exec_cam_start (gpiv);
742 if (gl_cam_par->mode == GPIV_CAM_MODE__DURATION) {
743 gpiv->first_selected_row = 0;
744 gpiv->last_selected_row = gl_cam_par->cycles - 1;
746 } else if (/* !cancel_process && */ gpiv_par->process__trig) {
747 exec_trigger_start ();
749 #else /* ENABLE_TRIG */
751 * RTA triggering disabled, only camera may be used
753 if (/* !cancel_process && */ gpiv_par->process__cam) {
754 exec_cam_start (gpiv);
755 if (gl_cam_par->mode == GPIV_CAM_MODE__DURATION) {
756 gpiv->first_selected_row = 0;
757 gpiv->last_selected_row = gl_cam_par->cycles - 1;
760 #endif /* ENABLE_TRIG */
761 #else /* ENABLE_CAM */
762 #ifdef ENABLE_TRIG
764 * Only RTA triggering may be used, camera disabled
766 if (/* !cancel_process && */ gpiv_par->process__trig) {
767 exec_trigger_start ();
769 #endif /* ENABLE_TRIG */
770 #endif /* ENABLE_CAM */
773 if (nbufs > 0) {
774 exec_process = TRUE;
775 for (row = gpiv->first_selected_row; row <= gpiv->last_selected_row;
776 row++) {
777 display_act = gtk_clist_get_row_data (GTK_CLIST (gpiv->clist_buf),
778 row);
779 if (display[display_act->id] != NULL
780 && GTK_WIDGET_VISIBLE (GTK_WIDGET (display_act->mwin)) ) {
781 gdk_window_show (GTK_WIDGET (display_act->mwin)->window);
782 gdk_window_raise (GTK_WIDGET (display_act->mwin)->window);
785 #ifdef ENABLE_IMGPROC
786 if (!cancel_process && gpiv_par->process__imgproc) {
787 exec_imgproc (gpiv);
789 #endif
791 if (!cancel_process && gpiv_par->process__piv) {
792 exec_piv (gpiv);
795 if (!cancel_process && gpiv_par->process__gradient) {
796 exec_gradient ();
799 if (!cancel_process && gpiv_par->process__resstats) {
800 gpiv_var->residu_stats = TRUE;
801 exec_errvec (gpiv->pivvalid);
804 if (!cancel_process && gpiv_par->process__errvec) {
805 gpiv_var->residu_stats = FALSE;
806 exec_errvec (gpiv->pivvalid);
809 if (!cancel_process && gpiv_par->process__peaklock) {
810 exec_peaklock (gpiv->pivvalid);
813 if (!cancel_process && gpiv_par->process__scale) {
814 exec_scale (gpiv->pivpost);
817 if (!cancel_process && gpiv_par->process__average) {
818 exec_savg (gpiv->pivpost);
821 if (!cancel_process && gpiv_par->process__subtract) {
822 exec_subavg (gpiv->pivpost);
825 if (!cancel_process && gpiv_par->process__vorstra) {
826 exec_vorstra ();
831 exec_process = FALSE;
836 void
837 on_stop_activate (GtkMenuItem *menuitem,
838 gpointer user_data)
839 /*-----------------------------------------------------------------------------
842 /* warning_gpiv(_("process has been stopped")); */
846 void
847 on_button_stop_press (GtkWidget * widget,
848 gpointer data)
849 /*-----------------------------------------------------------------------------
852 cancel_process = TRUE;
853 message_gpiv (_("cancel_process = TRUE"));
857 void
858 on_button_stop_release (GtkWidget * widget,
859 gpointer data)
860 /*-----------------------------------------------------------------------------
863 cancel_process = FALSE;
864 message_gpiv (_("cancel_process = FALSE"));
865 /* process has been stopped */
869 /* static gboolean */
870 /* on_display_delete(GtkWidget *widget, */
871 /* GdkEvent *event, */
872 /* gpointer data) */
873 /* { */
874 /* return FALSE; */
875 /* } */
878 void
879 on_close_activate (GtkMenuItem * menuitem,
880 gpointer user_data)
881 /*-----------------------------------------------------------------------------
882 * Remove multiple selected displays
885 GpivConsole *gpiv = gtk_object_get_data (GTK_OBJECT (menuitem), "gpiv");
886 Display *disp = NULL;
888 gchar *err_msg;
889 guint row;
890 guint row_close = gpiv->first_selected_row; /* row to be closed */
891 guint first = gpiv->first_selected_row; /* first_selected_row will be modified! */
892 guint last = gpiv->last_selected_row; /* last_selected_row will be modified! */
893 guint loc_nbufs = nbufs;
894 gboolean buf_closed = TRUE;
896 #ifdef ENABLE_CAM
897 if ((err_msg = gpiv_cam_free_camvar (&cam_var)) != NULL) {
898 error_gpiv ("from: on_close_activate\n from: gpiv_cam_free_camvar\n %s",
899 err_msg);
901 #endif /* ENABLE_CAM */
903 if (nbufs > 0) {
905 * Depending on the response if a display/buffer with unsaved data will be closed,
906 * the same or next row in the clist_buf will taken for selecting next display.
908 for (row = first; row <= last; row++) {
909 if (!buf_closed) {
910 if (row_close < nbufs - 1) {
911 row_close++;
914 disp = gtk_clist_get_row_data (GTK_CLIST (gpiv->clist_buf),
915 row_close);
916 close_buffer__check_saved (gpiv, disp);
919 * Check if a buffer has been closed
921 if (loc_nbufs == nbufs) {
922 buf_closed = FALSE;
923 } else {
924 buf_closed = TRUE;
925 loc_nbufs = nbufs;
930 } else {
931 update_imgh_entries (gpiv, gl_image_par);
932 update_eval_entries (gpiv, gl_image_par);
935 #ifdef ENABLE_IMGPROC
936 set_imgproc_filtervar (gpiv, GPIV_IMGFI_SUBACK, nbufs - 1);
937 #endif
942 void
943 on_exit_activate (GtkMenuItem * menuitem,
944 gpointer user_data)
945 /*-----------------------------------------------------------------------------
948 GpivConsole *gpiv = gtk_object_get_data (GTK_OBJECT (menuitem), "gpiv");
949 GtkDialog *gpiv_exit;
950 guint i;
952 #ifdef ENABLE_TRIG
953 exec_trigger_stop ();
954 #endif /* ENABLE_TRIG */
956 #ifdef ENABLE_CAM
957 exec_cam_stop ();
958 #endif /* ENABLE_CAM */
960 if (nbufs > 0) {
961 for (i = 0; i < nbufs; i++) {
962 /* if (display[i] != NULL) display_act = display[i]; */
963 display_act = gtk_clist_get_row_data (GTK_CLIST (gpiv->clist_buf), i);
965 if (!display_act->img->saved_img
966 || !display_act->pida->saved_piv
967 || !display_act->pida->saved_histo
968 || !display_act->pida->saved_vor
969 || !display_act->pida->saved_nstrain
970 || !display_act->pida->saved_sstrain) {
971 gpiv_exit = create_exit_dialog ();
972 gtk_widget_show (GTK_WIDGET (gpiv_exit));
973 } else {
974 free_all_bufmems (display_act);
975 gtk_main_quit ();
980 } else {
981 gtk_main_quit ();
986 void
987 on_preferences_activate (GtkWidget * widget,
988 gpointer user_data)
989 /*-----------------------------------------------------------------------------
992 GpivConsole *gpiv = gtk_object_get_data (GTK_OBJECT (widget), "gpiv");
993 GtkDialog *preferences = NULL ;
995 preferences = create_preferences (gpiv);
1000 void on_about_activate (GtkMenuItem * menuitem,
1001 gpointer user_data)
1002 /*-----------------------------------------------------------------------------
1005 GtkWidget *about;
1006 about = create_about ();
1013 void on_manual_activate (GtkMenuItem * menuitem,
1014 gpointer user_data)
1015 /*-----------------------------------------------------------------------------
1018 GError* error = NULL;
1020 if (!gnome_help_display ("index.html", NULL, &error)) {
1021 g_warning ("%s", error);
1022 g_error_free (error);
1029 * Gnome toolbar buttons
1033 void
1034 on_button_open_clicked (GtkButton *button,
1035 gpointer data)
1036 /*-----------------------------------------------------------------------------
1037 * Uses gtk2
1040 gchar *msg = "Opens PIV image";
1041 GpivConsole *gpiv = gtk_object_get_data (GTK_OBJECT (button), "gpiv");
1042 GtkWidget *dialog = NULL;
1045 if (gpiv_par->verbose) g_message ("on_button_open_activate:: fname_last = %s", gpiv_var->fname_last);
1046 dialog = gtk_file_chooser_dialog_new ("Open Uri/File",
1047 GTK_WINDOW (gpiv->console),
1048 GTK_FILE_CHOOSER_ACTION_OPEN,
1049 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1050 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1051 NULL);
1053 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), FALSE);
1054 gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (dialog), gpiv_var->fname_last);
1056 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
1057 char *filename = NULL;
1059 filename = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
1060 if (gpiv_par->verbose) g_message ("on_button_open_activate:: filename = %s", filename);
1061 select_action_from_name (gpiv, filename);
1062 g_free (filename);
1065 gtk_widget_destroy (dialog);
1067 gnome_appbar_set_status (GNOME_APPBAR (gpiv->appbar), msg);
1072 void
1073 on_menubar_activate (GtkWidget * widget,
1074 gpointer data)
1075 /*-----------------------------------------------------------------------------
1078 GpivConsole *gpiv = gtk_object_get_data (GTK_OBJECT (widget), "gpiv");
1079 if (GTK_CHECK_MENU_ITEM (widget)->active) {
1080 gtk_widget_show (gpiv->menubar);
1081 } else {
1082 gtk_widget_hide (gpiv->menubar);
1088 void
1089 on_toolbuttons_activate (GtkWidget * widget,
1090 gpointer data)
1091 /*-----------------------------------------------------------------------------
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); */
1112 void
1113 on_gpivbuttons_activate (GtkWidget * widget,
1114 gpointer data)
1115 /*-----------------------------------------------------------------------------
1118 GpivConsole *gpiv = gtk_object_get_data (GTK_OBJECT (widget), "gpiv");
1119 if (GTK_CHECK_MENU_ITEM (widget)->active) {
1120 gtk_widget_show (gpiv->handlebox1);
1122 } else {
1123 gtk_widget_hide (gpiv->handlebox1);
1129 void
1130 on_tabulator_activate (GtkWidget * widget,
1131 gpointer data)
1132 /*-----------------------------------------------------------------------------
1135 GpivConsole *gpiv = gtk_object_get_data (GTK_OBJECT (widget), "gpiv");
1136 if (GTK_CHECK_MENU_ITEM (widget)->active) {
1137 gtk_widget_show (gpiv->notebook);
1138 } else {
1139 gtk_widget_hide (gpiv->notebook);
1146 void
1147 on_tooltip_activate (GtkWidget * widget,
1148 gpointer data)
1149 /*-----------------------------------------------------------------------------
1152 GpivConsole *gpiv = gtk_object_get_data (GTK_OBJECT (widget), "gpiv");
1153 if (GTK_CHECK_MENU_ITEM (widget)->active) {
1154 gtk_tooltips_enable (gpiv->tooltips );
1155 } else {
1156 gtk_tooltips_disable (gpiv->tooltips );
1164 void
1165 on_buffer_set_focus (GtkWindow * window,
1166 GtkWidget * widget,
1167 gpointer user_data)
1168 /*-----------------------------------------------------------------------------
1171 /* SEE: on_clist_buf_rowselect */
1176 void
1177 gtk_window_destroy (GtkButton * button,
1178 gpointer user_data)
1179 /*-----------------------------------------------------------------------------
1187 void
1188 on_appbar_display_user_response (GnomeAppBar * gnomeappbar,
1189 gpointer user_data)
1190 /*-----------------------------------------------------------------------------
1198 void
1199 on_button_open_enter (GtkContainer * container,
1200 GtkDirectionType direction,
1201 gpointer user_data)
1202 /*-----------------------------------------------------------------------------
1205 GpivConsole *gpiv = gtk_object_get_data (GTK_OBJECT (container), "gpiv");
1206 gchar *msg = _("Opens image/PIV data (and display)");
1207 gnome_appbar_set_status (GNOME_APPBAR (gpiv->appbar), msg);
1212 void
1213 on_button_save_enter (GtkContainer * container,
1214 GtkDirectionType direction,
1215 gpointer user_data)
1216 {/*-----------------------------------------------------------------------------
1219 GpivConsole *gpiv = gtk_object_get_data (GTK_OBJECT (container), "gpiv");
1220 gchar *msg = _("Saves data");
1221 gnome_appbar_set_status (GNOME_APPBAR (gpiv->appbar), msg);
1226 void
1227 on_button_print_enter (GtkContainer * container,
1228 GtkDirectionType direction,
1229 gpointer user_data)
1230 /*-----------------------------------------------------------------------------
1233 GpivConsole *gpiv = gtk_object_get_data (GTK_OBJECT (container), "gpiv");
1234 gchar *msg = _("Prints selected buffer(s)");
1235 gnome_appbar_set_status (GNOME_APPBAR (gpiv->appbar), msg);
1240 void
1241 on_button_execute_enter (GtkContainer * container,
1242 GtkDirectionType direction,
1243 gpointer user_data)
1244 /*-----------------------------------------------------------------------------
1247 GpivConsole *gpiv = gtk_object_get_data (GTK_OBJECT (container), "gpiv");
1248 gchar *msg = _("Executes all tickmarked processes");
1249 gnome_appbar_set_status (GNOME_APPBAR (gpiv->appbar), msg);
1254 void
1255 on_button_stop_enter (GtkContainer * container,
1256 GtkDirectionType direction,
1257 gpointer user_data)
1258 /*-----------------------------------------------------------------------------
1261 GpivConsole *gpiv = gtk_object_get_data (GTK_OBJECT (container), "gpiv");
1262 gchar *msg = _("Cancels any running processes");
1263 gnome_appbar_set_status (GNOME_APPBAR (gpiv->appbar), msg);
1268 void
1269 on_button_close_enter (GtkContainer * container,
1270 GtkDirectionType direction,
1271 gpointer user_data)
1272 /*-----------------------------------------------------------------------------
1275 GpivConsole *gpiv = gtk_object_get_data (GTK_OBJECT (container), "gpiv");
1276 gchar *msg = _("Close active buffer(s)");
1277 gnome_appbar_set_status (GNOME_APPBAR (gpiv->appbar), msg);
1282 void
1283 on_button_exit_enter (GtkContainer * container,
1284 GtkDirectionType direction,
1285 gpointer user_data)
1286 /*-----------------------------------------------------------------------------
1289 GpivConsole *gpiv = gtk_object_get_data (GTK_OBJECT (container), "gpiv");
1290 gchar *msg = _("Exits GPIV");
1291 gnome_appbar_set_status (GNOME_APPBAR (gpiv->appbar), msg);
1296 #ifdef ENABLE_CAM
1297 void
1298 on_toolbar_checkbutton_cam (GtkWidget * widget,
1299 gpointer data)
1300 /*-----------------------------------------------------------------------------
1301 * toolbar containing checkbutton for recording process
1304 if (GTK_TOGGLE_BUTTON (widget)->active) {
1305 gpiv_par->process__cam = TRUE;
1306 } else {
1307 gpiv_par->process__cam = FALSE;
1310 #endif /* ENABLE_CAM */
1313 #ifdef ENABLE_TRIG
1314 void
1315 on_toolbar_checkbutton_trig (GtkWidget * widget,
1316 gpointer data)
1317 /*-----------------------------------------------------------------------------
1318 * toolbar containing checkbutton for triggering process
1321 if (GTK_TOGGLE_BUTTON (widget)->active) {
1322 gpiv_par->process__trig = TRUE;
1323 } else {
1324 gpiv_par->process__trig = FALSE;
1327 #endif /* ENABLE_TRIG */
1330 #ifdef ENABLE_IMGPROC
1331 void
1332 on_toolbar_checkbutton_imgproc (GtkWidget * widget,
1333 gpointer data)
1334 /*-----------------------------------------------------------------------------
1335 * toolbar containing checkbutton for image process
1338 if (GTK_TOGGLE_BUTTON (widget)->active) {
1339 gpiv_par->process__imgproc = TRUE;
1340 } else {
1341 gpiv_par->process__imgproc = FALSE;
1344 #endif /* ENABLE_IMGPROC */
1348 void
1349 on_toolbar_checkbutton_piv (GtkWidget * widget,
1350 gpointer data)
1351 /*-----------------------------------------------------------------------------
1352 * toolbar containing checkbutton for processes
1355 if (GTK_TOGGLE_BUTTON (widget)->active) {
1356 gpiv_par->process__piv = TRUE;
1357 } else {
1358 gpiv_par->process__piv = FALSE;
1364 void
1365 on_toolbar_checkbutton_gradient (GtkWidget * widget,
1366 gpointer data)
1367 /*-----------------------------------------------------------------------------
1370 if (GTK_TOGGLE_BUTTON (widget)->active) {
1371 gpiv_par->process__gradient = TRUE;
1372 } else {
1373 gpiv_par->process__gradient = FALSE;
1379 void
1380 on_toolbar_checkbutton_resstats (GtkWidget * widget,
1381 gpointer data)
1382 /*-----------------------------------------------------------------------------
1385 if (GTK_TOGGLE_BUTTON (widget)->active) {
1386 gpiv_par->process__resstats = TRUE;
1387 gpiv_var->residu_stats = TRUE;
1388 } else {
1389 gpiv_par->process__resstats = FALSE;
1390 gpiv_var->residu_stats = FALSE;
1396 void
1397 on_toolbar_checkbutton_errvec (GtkWidget * widget,
1398 gpointer data)
1399 /*-----------------------------------------------------------------------------
1402 if (GTK_TOGGLE_BUTTON (widget)->active) {
1403 gpiv_par->process__errvec = TRUE;
1404 } else {
1405 gpiv_par->process__errvec = FALSE;
1411 void
1412 on_toolbar_checkbutton_peaklck (GtkWidget * widget,
1413 gpointer data)
1414 /*-----------------------------------------------------------------------------
1417 if (GTK_TOGGLE_BUTTON (widget)->active) {
1418 gpiv_par->process__peaklock = TRUE;
1419 } else {
1420 gpiv_par->process__peaklock = FALSE;
1426 void
1427 on_toolbar_checkbutton_scale (GtkWidget * widget,
1428 gpointer data)
1429 /*-----------------------------------------------------------------------------
1432 if (GTK_TOGGLE_BUTTON (widget)->active) {
1433 gpiv_par->process__scale = TRUE;
1434 } else {
1435 gpiv_par->process__scale = FALSE;
1441 void
1442 on_toolbar_checkbutton_average (GtkWidget * widget,
1443 gpointer data)
1444 /*-----------------------------------------------------------------------------
1447 if (GTK_TOGGLE_BUTTON (widget)->active) {
1448 gpiv_par->process__average = TRUE;
1449 } else {
1450 gpiv_par->process__average = FALSE;
1456 void
1457 on_toolbar_checkbutton_subavg (GtkWidget * widget,
1458 gpointer data)
1459 /*-----------------------------------------------------------------------------
1462 if (GTK_TOGGLE_BUTTON (widget)->active) {
1463 gpiv_par->process__subtract = TRUE;
1464 } else {
1465 gpiv_par->process__subtract = FALSE;
1471 void
1472 on_toolbar_checkbutton_vorstra (GtkWidget * widget,
1473 gpointer data)
1474 /*-----------------------------------------------------------------------------
1477 if (GTK_TOGGLE_BUTTON (widget)->active) {
1478 gpiv_par->process__vorstra = TRUE;
1479 } else {
1480 gpiv_par->process__vorstra = FALSE;
1487 /* PivData *pida_active = &display_act->pida; */
1489 void
1490 on_button_quit_no_clicked (GtkButton * button,
1491 gpointer user_data)
1492 /*-----------------------------------------------------------------------------
1493 * exit, message dialog callbacks
1496 /* gnome_dialog_close (GTK_DIALOG (gpiv_exit)); */
1498 * Gnome2:
1500 /* gtk_widget_destroy (GTK_DIALOG (GTK_DIALOG (gpiv_exit))); */
1505 void
1506 on_button_quit_gpiv_yes_clicked (GtkButton * button,
1507 gpointer user_data)
1508 /*-----------------------------------------------------------------------------
1511 free_all_bufmems (display_act);
1512 gtk_main_quit ();
1517 /* void */
1518 /* on_button_message_clicked (GtkButton * button, */
1519 /* gpointer user_data) */
1520 /* BUGFIX: obsolete function: on_button_message_clicked; clean up */
1521 void
1522 on_button_message_clicked (GtkDialog *dialog,
1523 gint response,
1524 gpointer data
1526 /*-----------------------------------------------------------------------------
1529 g_assert (response == GTK_RESPONSE_ACCEPT);
1531 switch (response) {
1532 case GTK_RESPONSE_ACCEPT:
1533 /* gnome_dialog_close (GNOME_DIALOG (gpiv_exit)); */
1534 /* gtk_widget_destroy (GTK_DIALOG (gpiv_exit)); */
1536 default:
1537 g_warning ("on_message_clicked: should not arrive here");
1538 break;
1544 void
1545 on_notebook_switch_page (GtkNotebook *notebook,
1546 GtkNotebookPage *page,
1547 gint page_num,
1548 gpointer user_data
1550 /*-----------------------------------------------------------------------------
1553 gpiv_var->tab_pos = page_num;
1555 gnome_config_push_prefix ("/gpiv/RuntimeVariables/");
1556 gnome_config_set_int ("tab_pos", gpiv_var->tab_pos);
1557 gnome_config_pop_prefix ();
1558 gnome_config_sync ();