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
8 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
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)
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 * utility functions for gpiv
32 * Revision 1.22 2008-04-28 12:00:58 gerber
33 * hdf-formatted files are now with .hdf extension (previously: .gpi)
35 * Revision 1.21 2007-12-19 08:42:35 gerber
38 * Revision 1.20 2007-11-23 16:24:08 gerber
39 * release 0.5.0: Kafka
41 * Revision 1.19 2007-06-06 17:00:48 gerber
42 * Retreives images/data from URI using Gnome Virtual File System.
44 * Revision 1.18 2007-03-22 16:00:32 gerber
45 * Added image processing tabulator
47 * Revision 1.17 2007-01-29 11:27:44 gerber
48 * added image formats png, gif, tif png, bmp, improved buffer display
50 * Revision 1.16 2006-09-18 07:27:06 gerber
51 * *** empty log message ***
53 * Revision 1.15 2006/01/29 15:36:56 gerber
54 * repaired a few annoying bugs
56 * Revision 1.13 2005/03/03 16:21:09 gerber
59 * Revision 1.12 2005/02/26 09:43:31 gerber
60 * parameter flags (parameter_logic) defined as gboolean
62 * Revision 1.11 2005/02/26 09:17:14 gerber
63 * structured of interrogate function by using gpiv_piv_isiadapt
65 * Revision 1.10 2005/01/19 15:53:43 gerber
66 * Initiation of Data Acquisition (DAC); trigerring of lasers and camera
67 * by using RTAI and Realtime Linux, recording images from IEEE1394
68 * (Firewire) IIDC compliant camera's
70 * Revision 1.9 2004/10/15 19:24:05 gerber
71 * GPIV_ and Gpiv prefix to defines and structure names of libgpiv
73 * Revision 1.8 2004/06/14 21:19:23 gerber
74 * Image depth up to 16 bits.
75 * Improvement "single int" and "drag int" in Eval tab.
76 * Viewer's pop-up menu.
77 * Adaption for gpiv_matrix_* and gpiv_vector_*.
79 * See Changelog for further info.
81 * Revision 1.7 2003/09/04 13:31:55 gerber
82 * init of printing (unfinished)
84 * Revision 1.6 2003/09/01 11:17:15 gerber
85 * improved monitoring of interrogation process
87 * Revision 1.5 2003/08/22 15:24:53 gerber
88 * interactive spatial scaling
90 * Revision 1.4 2003/07/31 11:43:26 gerber
91 * display images in gnome canvas (HOERAreset)
93 * Revision 1.3 2003/07/25 15:40:24 gerber
94 * removed/disabled setting of correlation in Eval tab, Correlation type in Image info tab
96 * Revision 1.2 2003/06/27 13:47:26 gerber
97 * display ruler, line/point evaluation
99 * Revision 1.1.1.1 2003/06/17 17:10:52 gerber
104 #include "gpiv_gui.h"
107 #include "dialog_interface.h"
108 #include "console_interface.h"
110 #include "dac_interface.h"
114 update_imgh_entries (GpivConsole
*gpiv
,
115 GpivImagePar
*image_par
117 /*-----------------------------------------------------------------------------
119 * Refreshes image header entries and labels (when a different buffer is
122 * PROTOTYPE LOCATATION:
126 * gpiv: console structure
127 * image_par: image parameters
130 *---------------------------------------------------------------------------*/
132 gchar label
[GPIV_MAX_CHARS
];
133 gchar
*tmp_name
, *text_uri
;
134 GnomeVFSURI
* uri
= NULL
;
136 if (display_act
!= NULL
) {
137 g_snprintf (label
, GPIV_MAX_CHARS
,"%d", display_act
->id
);
138 gtk_label_set_text (GTK_LABEL (gpiv
->imgh
->label_bufno
),
141 text_uri
= gnome_vfs_make_uri_from_input
142 ((const gchar
*) display_act
->file_uri_name
);
143 if ((uri
= gnome_vfs_uri_new (text_uri
)) == NULL
) return;
145 if (gnome_vfs_uri_is_local (uri
)) {
146 gtk_label_set_text (GTK_LABEL (gpiv
->imgh
->label_label_name
),
149 gtk_label_set_text (GTK_LABEL (gpiv
->imgh
->label_label_name
),
152 gtk_label_set_text (GTK_LABEL (gpiv
->imgh
->label_name
),
153 display_act
->file_uri_name
);
154 g_snprintf (label
, GPIV_MAX_CHARS
, "%d", display_act
->img
->image
->header
->ncolumns
);
155 gtk_label_set_text (GTK_LABEL (gpiv
->imgh
->label_ncols
),
157 g_snprintf (label
, GPIV_MAX_CHARS
, "%d", display_act
->img
->image
->header
->nrows
);
158 gtk_label_set_text (GTK_LABEL (gpiv
->imgh
->label_nrows
),
163 gtk_entry_set_text (GTK_ENTRY (gpiv
->imgh
->entry_imgtitle
),
167 gtk_spin_button_set_value (GTK_SPIN_BUTTON (gpiv
->imgh
->spinbutton_colpos
),
169 gtk_spin_button_set_value (GTK_SPIN_BUTTON (gpiv
->imgh
->spinbutton_rowpos
),
171 gtk_spin_button_set_value (GTK_SPIN_BUTTON (gpiv
->imgh
->spinbutton_sscale
),
173 gtk_spin_button_set_value (GTK_SPIN_BUTTON (gpiv
->imgh
->spinbutton_tscale
),
177 gtk_entry_set_text (GTK_ENTRY (gpiv
->imgh
->entry_crdate
),
178 image_par
->creation_date
);
179 gtk_entry_set_text (GTK_ENTRY (gpiv
->imgh
->entry_location
),
180 image_par
->location
);
181 gtk_entry_set_text (GTK_ENTRY (gpiv
->imgh
->entry_author
),
183 gtk_entry_set_text (GTK_ENTRY(gpiv
->imgh
->entry_software
),
184 image_par
->software
);
185 gtk_entry_set_text (GTK_ENTRY (gpiv
->imgh
->entry_source
),
187 gtk_entry_set_text (GTK_ENTRY (gpiv
->imgh
->entry_usertext
),
188 image_par
->usertext
);
189 gtk_entry_set_text (GTK_ENTRY (gpiv
->imgh
->entry_warning
),
191 gtk_entry_set_text (GTK_ENTRY (gpiv
->imgh
->entry_disclaimer
),
192 image_par
->disclaimer
);
193 gtk_entry_set_text (GTK_ENTRY (gpiv
->imgh
->entry_comment
),
195 gtk_entry_set_text (GTK_ENTRY(gpiv
->imgh
->entry_copyright
),
196 image_par
->copyright
);
197 gtk_entry_set_text (GTK_ENTRY (gpiv
->imgh
->entry_email
),
199 gtk_entry_set_text (GTK_ENTRY (gpiv
->imgh
->entry_url
),
206 update_eval_entries (GpivConsole
*gpiv
,
207 GpivImagePar
*image_par
209 /*-----------------------------------------------------------------------------
211 * Refreshes spinners of col/row start/ end/ shift for image size
212 * (when a different buffer is selected)
214 * PROTOTYPE LOCATATION:
218 * gpiv: console structure
219 * image_par: image parameters
222 *---------------------------------------------------------------------------*/
224 if (display_act
!= NULL
) {
225 gtk_spin_button_set_range (GTK_SPIN_BUTTON
226 (gpiv
->piveval
->spinbutton_colstart
),
228 image_par
->ncolumns
- 1);
229 gtk_spin_button_set_range (GTK_SPIN_BUTTON
230 (gpiv
->piveval
->spinbutton_colend
),
232 image_par
->ncolumns
- 1);
233 gtk_spin_button_set_range (GTK_SPIN_BUTTON
234 (gpiv
->piveval
->spinbutton_preshiftcol
),
235 0.0 - (image_par
->ncolumns
- 1),
236 image_par
->ncolumns
- 1);
237 gtk_spin_button_set_range (GTK_SPIN_BUTTON
238 (gpiv
->piveval
->spinbutton_rowstart
),
240 image_par
->nrows
- 1);
241 gtk_spin_button_set_range (GTK_SPIN_BUTTON
242 (gpiv
->piveval
->spinbutton_rowend
),
244 display_act
->img
->image
->header
->nrows
- 1);
245 gtk_spin_button_set_range (GTK_SPIN_BUTTON
246 (gpiv
->piveval
->spinbutton_preshiftrow
),
247 0.0 - (image_par
->nrows
- 1),
248 image_par
->nrows
- 1);
252 * Adjust spinbutton values if they are invalid
255 if (gl_piv_par
->col_start
> image_par
->ncolumns
- 1) {
256 gl_piv_par
->col_start
= image_par
->ncolumns
- 1;
257 gtk_spin_button_set_value (GTK_SPIN_BUTTON
258 (gpiv
->piveval
->spinbutton_colstart
),
259 gl_piv_par
->col_start
);
262 if (gl_piv_par
->col_end
> image_par
->ncolumns
- 1) {
263 gl_piv_par
->col_end
= image_par
->ncolumns
- 1;
264 gtk_spin_button_set_value (GTK_SPIN_BUTTON
265 (gpiv
->piveval
->spinbutton_colend
),
266 gl_piv_par
->col_end
);
270 if (gl_piv_par
->pre_shift_col
> image_par
->ncolumns
- 1) {
271 gl_piv_par
->pre_shift_col
= image_par
->ncolumns
- 1;
272 gtk_spin_button_set_value (GTK_SPIN_BUTTON
273 (gpiv
->piveval
->spinbutton_preshiftcol
),
274 gl_piv_par
->pre_shift_col
);
277 if (gl_piv_par
->pre_shift_col
< (0.0 - (image_par
->ncolumns
- 1))) {
278 gl_piv_par
->pre_shift_col
= - (image_par
->ncolumns
- 1);
279 gtk_spin_button_set_value (GTK_SPIN_BUTTON
280 (gpiv
->piveval
->spinbutton_preshiftcol
),
281 gl_piv_par
->pre_shift_col
);
287 if (gl_piv_par
->row_start
> image_par
->nrows
- 1) {
288 gl_piv_par
->row_start
= image_par
->nrows
- 1;
289 gtk_spin_button_set_value (GTK_SPIN_BUTTON
290 (gpiv
->piveval
->spinbutton_rowstart
),
291 gl_piv_par
->row_start
);
294 if (gl_piv_par
->row_end
> image_par
->nrows
- 1) {
295 gl_piv_par
->row_end
= image_par
->nrows
- 1;
296 gtk_spin_button_set_value (GTK_SPIN_BUTTON
297 (gpiv
->piveval
->spinbutton_rowend
),
298 gl_piv_par
->row_end
);
302 if (gl_piv_par
->pre_shift_row
> image_par
->nrows
- 1) {
303 gl_piv_par
->pre_shift_row
= image_par
->nrows
- 1;
304 gtk_spin_button_set_value (GTK_SPIN_BUTTON
305 (gpiv
->piveval
->spinbutton_preshiftrow
),
306 gl_piv_par
->pre_shift_row
);
309 if (gl_piv_par
->pre_shift_row
< (0.0 - (image_par
->nrows
- 1))) {
310 gl_piv_par
->pre_shift_row
= - (image_par
->nrows
- 1);
311 gtk_spin_button_set_value (GTK_SPIN_BUTTON
312 (gpiv
->piveval
->spinbutton_preshiftrow
),
313 gl_piv_par
->pre_shift_row
);
322 month_name (GDateMonth month
)
323 /*--------------------------------------------------------------------
324 * returns the month name
329 if (month
== G_DATE_JANUARY
) {
330 name
= g_strdup ( _("January"));
331 } else if (month
== G_DATE_FEBRUARY
) {
332 name
= g_strdup ( _("February"));
333 } else if (month
== G_DATE_MARCH
) {
334 name
= g_strdup ( _("March"));
335 } else if (month
== G_DATE_APRIL
) {
336 name
= g_strdup ( _("April"));
337 } else if (month
== G_DATE_MAY
) {
338 name
= g_strdup ( _("May"));
339 } else if (month
== G_DATE_JUNE
) {
340 name
= g_strdup ( _("June"));
341 } else if (month
== G_DATE_JULY
) {
342 name
= g_strdup ( _("July"));
343 } else if (month
== G_DATE_AUGUST
) {
344 name
= g_strdup ( _("August"));
345 } else if (month
== G_DATE_SEPTEMBER
) {
346 name
= g_strdup ( _("September"));
347 } else if (month
== G_DATE_OCTOBER
) {
348 name
= g_strdup ( _("October"));
349 } else if (month
== G_DATE_NOVEMBER
) {
350 name
= g_strdup ( _("November"));
351 } else if (month
== G_DATE_DECEMBER
) {
352 name
= g_strdup ( _("December"));
353 } else if (month
== G_DATE_BAD_MONTH
) {
354 name
= g_strdup ( _("Bad month"));
356 name
= g_strdup ( _("month_name: Unvalid month"));
366 /*--------------------------------------------------------------------
367 * Frees all allocated memory data from the application
372 for (i
= 1; i
< gpiv_var
->number_fnames_last
; i
++) {
373 g_free (gpiv_var
->fn_last
[i
]);
380 push_list_lastfnames (gchar
*fname
382 /*--------------------------------------------------------------------
383 * Pushes fname on gpiv_var fn_last[0]
384 * Eventually removes fn_last[MAX_LIST]
387 gchar fname_nr
[GPIV_MAX_CHARS
];
390 gnome_config_push_prefix ("/gpiv/RuntimeVariables/");
391 if (gpiv_var
->number_fnames_last
< MAX_LIST
) {
392 gpiv_var
->number_fnames_last
++;
393 gnome_config_set_int ("number_fnames_last",
394 gpiv_var
->number_fnames_last
);
397 for (i
= gpiv_var
->number_fnames_last
- 1; i
> 0; i
--) {
398 gpiv_var
->fn_last
[i
] = g_strdup (gpiv_var
->fn_last
[i
- 1]);
401 gpiv_var
->fn_last
[0] = g_strdup (fname
);
402 for (i
= 0; i
< gpiv_var
->number_fnames_last
; i
++) {
403 g_snprintf (fname_nr
, GPIV_MAX_CHARS
,"fname_last_%d", i
);
404 gnome_config_set_string (fname_nr
, gpiv_var
->fn_last
[i
]);
406 if (gpiv_par
->verbose
)
407 g_message ("push_list_lastfnames: fn_last[0]=%s", gpiv_var
->fn_last
[0]);
409 gnome_config_pop_prefix ();
410 gnome_config_sync ();
416 get_row_from_id (GpivConsole
*gpiv
,
419 /*-----------------------------------------------------------------------------
420 * Searches the row of buffer clist that belongs to deplay identity.
424 Display
*display_loc
= NULL
;
427 for (i
= 0; i
< nbufs
; i
++) {
428 display_loc
= gtk_clist_get_row_data (GTK_CLIST (gpiv
->clist_buf
), i
);
429 if (disp
->id
== display_loc
->id
) row
= i
;
439 point_to_existbuffer (GpivConsole
*gpiv
441 /*-----------------------------------------------------------------------------
442 * Point display_act to first existing buffer
449 display_act
= gtk_clist_get_row_data (GTK_CLIST (gpiv
->clist_buf
), 0);
450 gtk_clist_select_row (GTK_CLIST (gpiv
->clist_buf
), 0, 0);
457 close_buffer__check_saved (GpivConsole
*gpiv
,
460 /*-----------------------------------------------------------------------------
461 * closes buffer, checks if (modified) image and data have been saved.
462 * If unsaved, close_buffer_dialog will direct to on_close_buffer_response,
466 char message
[2 * GPIV_MAX_CHARS
];
467 GtkDialog
*close_buffer_dialog
;
468 guint row
= get_row_from_id (gpiv
, disp
);
471 if (disp
== NULL
) return;
474 g_message ("close_buffer__check_saved:: id = %d saved_img = %d",
475 disp
->id
, display_act
->img
->saved_img
);
478 if (!disp
->img
->saved_img
479 || !disp
->pida
->saved_piv
480 || !disp
->pida
->saved_histo
481 || !disp
->pida
->saved_vor
482 || !disp
->pida
->saved_nstrain
483 || !disp
->pida
->saved_sstrain
) {
485 * Data not stored, deleting buffer only after permission
487 g_snprintf (message
, 2 * GPIV_MAX_CHARS
,
488 _("There are unsaved data that will be lost.\n\
489 Are you sure you want to close buffer #%d ?"),
491 close_buffer_dialog
= create_close_buffer_dialog (gpiv
, disp
, message
);
492 gtk_widget_show (GTK_WIDGET (close_buffer_dialog
));
496 * No modified / new data or already stored, deleting buffer unconditionally
498 close_buffer (gpiv
, disp
);
506 close_buffer (GpivConsole
*gpiv
,
509 /*-----------------------------------------------------------------------------
510 * closes all data of a display and cleans up clist of buffer
513 guint row
= get_row_from_id (gpiv
, disp
);
515 free_all_bufmems (disp
);
516 g_free (disp
->file_uri_name
);
517 gtk_widget_destroy (GTK_WIDGET (disp
->mwin
));
523 gtk_clist_remove (GTK_CLIST (gpiv
->clist_buf
),
528 * Point display to an existing buffer
531 update_imgh_entries (gpiv
, gl_image_par
);
534 point_to_existbuffer (gpiv
);
542 image_mean (guint16
**img
,
545 /*-----------------------------------------------------------------------------
548 int i
, j
, ncount
= ncols
* nrows
;
549 float img_sum
= 0.0, mean
= 0.0;
551 for (i
= 0; i
< nrows
; i
++) {
552 for (j
= 0; j
< ncols
; j
++) {
553 img_sum
+= (float) img
[i
][j
];
557 mean
= img_sum
/ (float) ncount
;
564 **alloc_gci_matrix (long nr
,
567 /*-----------------------------------------------------------------------------
568 * Allocates 2-dimensional array for GnomeCanvasItem
572 GnomeCanvasItem
**item
;
576 * allocate pointers to rows
578 item
= (GnomeCanvasItem
**) g_malloc ((size_t) ((nr
- 1) *
579 sizeof (GnomeCanvasItem
*)));
580 if (!item
) gpiv_error ("%s: allocation failure 1 in g_malloc()",
585 * allocate rows and set pointers to them
587 item
[0] = (GnomeCanvasItem
*) g_malloc ((size_t) ((nr
* nc
- 1) *
588 sizeof (GnomeCanvasItem
)));
589 if (!item
[0]) gpiv_error ("%s: allocation failure 2 in g_malloc()",
593 for (i
= 1; i
<= nr
; i
++) item
[i
] = item
[i
-1] + 1;
596 * return pointer to array of pointers to rows
604 free_gci_matrix (GnomeCanvasItem
**item
,
608 /*-----------------------------------------------------------------------------
609 * Frees 2-dimensional array for GnomeCanvasItem
612 assert (item
[0] != NULL
);
614 free ((char*) (item
[0] - 1));
615 free ((char*) (item
- 1));
621 free_all_bufmems (Display
* disp
)
622 /*-----------------------------------------------------------------------------
623 * Frees all dynamic memory of Buffer structure
627 free_img_bufmems (disp
);
628 free_eval_bufmems (disp
);
629 free_valid_bufmems (disp
);
630 free_post_bufmems (disp
);
637 free_img_bufmems (Display
* disp
)
638 /*-----------------------------------------------------------------------------
639 * Frees all dynamic memory of Buffer structure of img
642 /* char *foo = '\0'; */
643 /* g_snprintf (disp->file_uri_name, GPIV_MAX_CHARS, ""); */
646 if (disp
->img
->exist_img
) {
647 gdk_pixbuf_unref (disp
->img
->pixbuf1
);
648 if (disp
->img
->rgbbuf_img1
!= NULL
) {
649 g_free (disp
->img
->rgbbuf_img1
);
650 disp
->img
->rgbbuf_img1
= NULL
;
653 gdk_pixbuf_unref (disp
->img
->pixbuf2
);
654 if (disp
->img
->rgbbuf_img2
!= NULL
) {
655 g_free (disp
->img
->rgbbuf_img2
);
656 disp
->img
->rgbbuf_img2
= NULL
;
660 gpiv_free_img (disp
->img
->image
);
662 disp
->img
->exist_img
= FALSE
;
665 /* destroy_background (disp); */
666 destroy_background(display_act
->gci_bg
);
667 if (disp
->intreg
->exist_int
) {
668 destroy_all_intregs (disp
);
669 disp
->intreg
->exist_int
= FALSE
;
677 free_eval_bufmems (Display
* disp
)
678 /*-----------------------------------------------------------------------------
679 * Frees all dynamic memory of Buffer structure of evaluation processing
683 if (disp
->pida
->exist_piv
) {
684 destroy_all_vectors (disp
->pida
);
685 gpiv_free_pivdata (disp
->pida
->piv_data
);
686 disp
->pida
->exist_piv
= FALSE
;
689 if (disp
->pida
->scaled_piv
) {
690 gpiv_free_pivdata (disp
->pida
->piv_data_scaled
);
691 disp
->pida
->scaled_piv
= FALSE
;
694 disp
->pida
->averaged_piv
= FALSE
;
700 free_valid_bufmems (Display
* disp
)
701 /*-----------------------------------------------------------------------------
702 * Frees all dynamic memory of Buffer structure of validation processing
706 if (disp
->pida
->exist_histo
) {
707 gpiv_free_bindata (disp
->pida
->klass
);
708 disp
->pida
->exist_valid
= FALSE
;
715 free_post_bufmems (Display
* disp
717 /*-----------------------------------------------------------------------------
718 * Frees all dynamic memory of Buffer structure of post processing
722 if (disp
->pida
->exist_vor
) {
723 destroy_all_scalars (disp
, GPIV_VORTICITY
);
724 gpiv_free_scdata (disp
->pida
->vor_data
);
725 disp
->pida
->exist_vor
= FALSE
;
726 disp
->pida
->post_par
->diff_type__set
= FALSE
;
727 disp
->pida
->post_par
->operator_vorstra__set
= FALSE
;
730 if (disp
->pida
->exist_vor_scaled
) {
731 gpiv_free_scdata (disp
->pida
->vor_data_scaled
);
732 disp
->pida
->exist_vor_scaled
= FALSE
;
735 if (disp
->pida
->exist_sstrain
) {
736 destroy_all_scalars (disp
, GPIV_S_STRAIN
);
737 gpiv_free_scdata (disp
->pida
->sstrain_data
);
738 disp
->pida
->exist_sstrain
= FALSE
;
739 disp
->pida
->post_par
->diff_type__set
= FALSE
;
740 disp
->pida
->post_par
->operator_vorstra__set
= FALSE
;
743 if (disp
->pida
->exist_sstrain_scaled
) {
744 gpiv_free_scdata (disp
->pida
->sstrain_data_scaled
);
745 disp
->pida
->exist_sstrain_scaled
= FALSE
;
748 if (disp
->pida
->exist_nstrain
) {
749 destroy_all_scalars (disp
, GPIV_N_STRAIN
);
750 gpiv_free_scdata (disp
->pida
->nstrain_data
);
751 disp
->pida
->exist_nstrain
= FALSE
;
752 disp
->pida
->post_par
->diff_type__set
= FALSE
;
753 disp
->pida
->post_par
->operator_vorstra__set
= FALSE
;
756 if (disp
->pida
->exist_nstrain_scaled
) {
757 gpiv_free_scdata (disp
->pida
->nstrain_data_scaled
);
758 disp
->pida
->exist_nstrain_scaled
= FALSE
;
770 on_widget_leave (GtkContainer
* container
,
771 GtkDirectionType direction
,
774 /*-----------------------------------------------------------------------------
775 * Resets text in application bar to default after poiner leaves
779 GpivConsole
*gpiv
= gtk_object_get_data (GTK_OBJECT (container
), "gpiv");
780 gnome_appbar_push (GNOME_APPBAR (gpiv
->appbar
), msg_default
);
786 sensitive (GpivConsole
*gpiv
,
787 enum WidgetSet wi_set
,
789 /*-----------------------------------------------------------------------------
790 * Changes the sensitivity of a set of witgets
795 Dac
*dac
= gpiv
->dac
;
797 Trig
*trig
= dac
->trig
;
800 Dac
*dac
= gpiv
->dac
;
801 Trig
*trig
= dac
->trig
;
802 #endif /* ENABLE_TRIG */
803 #endif /* ENABLE_CAM */
805 * Setting sensitivity of Dac witgets
809 gtk_widget_set_sensitive (gpiv
->tablabel_dac
, sense
);
810 gtk_widget_set_sensitive (gpiv
->dac
->label_title
, sense
);
811 gtk_widget_set_sensitive (gpiv
->dac
->label_fname
, sense
);
812 gtk_widget_set_sensitive (gpiv
->dac
->entry_fname
, sense
);
817 if (wi_set
== DAC_TRIG
) {
818 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
819 (gpiv
->button_toolbar_trig
),
820 gpiv_par
->process__trig
);
821 gtk_widget_set_sensitive (gpiv
->button_toolbar_trig
, sense
);
822 gtk_widget_set_sensitive (trig
->frame_trigger
, sense
);
823 gtk_widget_set_sensitive (trig
->radiobutton_mouse_3
, sense
);
824 gtk_widget_set_sensitive (trig
->radiobutton_mouse_4
, sense
);
825 gtk_widget_set_sensitive (trig
->radiobutton_mouse_5
, sense
);
826 gtk_widget_set_sensitive (trig
->radiobutton_mouse_6
, sense
);
827 gtk_widget_set_sensitive (trig
->label_trigger_dt
, sense
);
828 gtk_widget_set_sensitive (trig
->spinbutton_trigger_dt
, sense
);
829 gtk_widget_set_sensitive (trig
->label_trigger_incrdt
, sense
);
830 gtk_widget_set_sensitive (trig
->spinbutton_trigger_incrdt
, sense
);
831 gtk_widget_set_sensitive (trig
->label_trigger_cap
, sense
);
832 gtk_widget_set_sensitive (trig
->spinbutton_trigger_cap
, sense
);
833 gtk_widget_set_sensitive (trig
->button_trigger_start
, sense
);
834 gtk_widget_set_sensitive (trig
->button_trigger_stop
, sense
);
836 #endif /* ENABLE_TRIG */
839 if (wi_set
== DAC_TIMING
) {
840 gtk_widget_set_sensitive (trig
->frame_trigger
, sense
);
841 gtk_widget_set_sensitive (trig
->radiobutton_mouse_1
, sense
);
842 gtk_widget_set_sensitive (trig
->radiobutton_mouse_2
, sense
);
843 gtk_widget_set_sensitive (trig
->label_trigger_nf
, sense
);
844 gtk_widget_set_sensitive (trig
->spinbutton_trigger_nf
, sense
);
848 if (wi_set
== DAC_TIMING
) {
849 gtk_widget_set_sensitive (trig
->frame_trigger
, sense
);
850 gtk_widget_set_sensitive (trig
->radiobutton_mouse_1
, sense
);
851 gtk_widget_set_sensitive (trig
->radiobutton_mouse_2
, sense
);
852 gtk_widget_set_sensitive (trig
->label_trigger_nf
, sense
);
853 gtk_widget_set_sensitive (trig
->spinbutton_trigger_nf
, sense
);
855 #endif /* ENABLE_TRIG */
856 #endif /* ENABLE_CAM */
860 if (wi_set
== DAC_CAM
) {
861 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
862 (gpiv
->button_toolbar_cam
),
863 gpiv_par
->process__cam
);
864 gtk_widget_set_sensitive (gpiv
->button_toolbar_cam
, sense
);
865 gtk_widget_set_sensitive (cam
->frame_cam
, sense
);
866 gtk_widget_set_sensitive (cam
->camera_select
, sense
);
867 gtk_widget_set_sensitive (cam
->camera_select_menu
, sense
);
868 gtk_widget_set_sensitive (cam
->menu_item
, sense
);
869 gtk_widget_set_sensitive (cam
->label_temp
, sense
);
870 gtk_widget_set_sensitive (cam
->label_label_temp
, sense
);
871 gtk_widget_set_sensitive (cam
->button_cam_start
, sense
);
872 gtk_widget_set_sensitive (cam
->button_cam_stop
, sense
);
874 #endif /* ENABLE_CAM */
877 * Setting sensitivity of Image witgets
881 /* gtk_widget_set_sensitive (gpiv->imgh->label_name, sense); */
882 /* gtk_widget_set_sensitive (gpiv->imgh->entry_name, sense); */
883 /* gtk_widget_set_sensitive (gpiv->imgh->spinbutton_ncols, sense); */
885 gtk_widget_set_sensitive (gpiv
->imgh
->label_colpos
, sense
);
886 gtk_widget_set_sensitive (gpiv
->imgh
->label_sscale
, sense
);
887 gtk_widget_set_sensitive (gpiv
->imgh
->label_ncols
, sense
);
888 gtk_widget_set_sensitive (gpiv
->imgh
->label_nrows
, sense
);
889 gtk_widget_set_sensitive (gpiv
->imgh
->label_depth
, sense
);
890 gtk_widget_set_sensitive (gpiv
->imgh
->label_rowpos
, sense
);
891 gtk_widget_set_sensitive (gpiv
->imgh
->label_tscale
, sense
);
892 gtk_widget_set_sensitive (gpiv
->imgh
->label_imgtitle
, sense
);
893 gtk_widget_set_sensitive (gpiv
->imgh
->label_crdate
, sense
);
894 gtk_widget_set_sensitive (gpiv
->imgh
->label_location
, sense
);
895 gtk_widget_set_sensitive (gpiv
->imgh
->label_author
, sense
);
896 gtk_widget_set_sensitive (gpiv
->imgh
->label_software
, sense
);
897 gtk_widget_set_sensitive (gpiv
->imgh
->label_source
, sense
);
898 gtk_widget_set_sensitive (gpiv
->imgh
->label_usertext
, sense
);
899 gtk_widget_set_sensitive (gpiv
->imgh
->label_warning
, sense
);
900 gtk_widget_set_sensitive (gpiv
->imgh
->label_disclaimer
, sense
);
901 gtk_widget_set_sensitive (gpiv
->imgh
->label_comment
, sense
);
902 gtk_widget_set_sensitive (gpiv
->imgh
->label_copyright
, sense
);
903 gtk_widget_set_sensitive (gpiv
->imgh
->label_email
, sense
);
904 gtk_widget_set_sensitive (gpiv
->imgh
->label_url
, sense
);
906 gtk_widget_set_sensitive (gpiv
->imgh
->spinbutton_colpos
, sense
);
907 gtk_widget_set_sensitive (gpiv
->imgh
->spinbutton_sscale
, sense
);
908 gtk_widget_set_sensitive (gpiv
->imgh
->spinbutton_rowpos
, sense
);
909 gtk_widget_set_sensitive (gpiv
->imgh
->spinbutton_tscale
, sense
);
910 gtk_widget_set_sensitive (gpiv
->imgh
->entry_imgtitle
, sense
);
911 gtk_widget_set_sensitive (gpiv
->imgh
->entry_crdate
, sense
);
912 gtk_widget_set_sensitive (gpiv
->imgh
->entry_location
, sense
);
913 gtk_widget_set_sensitive (gpiv
->imgh
->entry_author
, sense
);
914 gtk_widget_set_sensitive (gpiv
->imgh
->entry_software
, sense
);
915 gtk_widget_set_sensitive (gpiv
->imgh
->entry_source
, sense
);
916 gtk_widget_set_sensitive (gpiv
->imgh
->entry_usertext
, sense
);
917 gtk_widget_set_sensitive (gpiv
->imgh
->entry_warning
, sense
);
918 gtk_widget_set_sensitive (gpiv
->imgh
->entry_disclaimer
, sense
);
919 gtk_widget_set_sensitive (gpiv
->imgh
->entry_comment
, sense
);
920 gtk_widget_set_sensitive (gpiv
->imgh
->entry_copyright
, sense
);
921 gtk_widget_set_sensitive (gpiv
->imgh
->entry_email
, sense
);
922 gtk_widget_set_sensitive (gpiv
->imgh
->entry_url
, sense
);
927 * Setting sensitivity of Image Processing witgets
929 if (wi_set
== IMGPROC
) {
934 * Setting sensitivity of PIV witgets
936 if (wi_set
== EVAL
) {
937 gtk_widget_set_sensitive (gpiv
->piveval
->spinbutton_colstart
, sense
);
938 gtk_widget_set_sensitive (gpiv
->piveval
->spinbutton_colend
, sense
);
939 gtk_widget_set_sensitive (gpiv
->piveval
->spinbutton_preshiftcol
, sense
);
940 gtk_widget_set_sensitive (gpiv
->piveval
->spinbutton_rowstart
, sense
);
941 gtk_widget_set_sensitive (gpiv
->piveval
->spinbutton_rowend
, sense
);
942 gtk_widget_set_sensitive (gpiv
->piveval
->spinbutton_preshiftrow
, sense
);
944 /* gtk_widget_set_sensitive (gpiv->piveval->radiobutton_intsize_f_1, sense); */
945 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_intsize_f_2
, sense
);
946 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_intsize_f_3
, sense
);
948 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_intsize_f_4
, sense
);
949 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_intsize_f_5
, sense
);
951 /* gtk_widget_set_sensitive (gpiv->piveval->radiobutton_intsize_i_1, sense); */
952 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_intsize_i_2
, sense
);
953 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_intsize_i_3
, sense
);
954 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_intsize_i_4
, sense
);
955 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_intsize_i_5
, sense
);
957 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_intshift_1
, sense
);
958 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_intshift_2
, sense
);
959 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_intshift_3
, sense
);
960 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_intshift_4
, sense
);
961 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_intshift_5
, sense
);
963 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_fit_none
, sense
);
964 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_fit_gauss
, sense
);
965 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_fit_power
, sense
);
966 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_fit_gravity
, sense
);
968 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_mouse_1
, sense
);
969 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_mouse_2
, sense
);
970 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_mouse_3
, sense
);
971 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_mouse_4
, sense
);
973 gtk_widget_set_sensitive (gpiv
->piveval
->checkbutton_monitor
, sense
);
975 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_peak_1
, sense
);
976 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_peak_2
, sense
);
977 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_peak_3
, sense
);
979 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_weightkernel
, sense
);
980 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_zerooff
, sense
);
981 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_centraldiff
, sense
);
983 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_cross_1
, FALSE
);
984 gtk_widget_set_sensitive (gpiv
->piveval
->radiobutton_cross_2
, FALSE
);
986 gtk_widget_set_sensitive (gpiv
->piveval
->button
, sense
);
991 * Setting sensitivity of a slection of PIV witgets
993 if (wi_set
== INTREGS
) {
994 /* if (piv_par->int_size_f >= 16) { */
995 /* gtk_widget_set_sensitive (GTK_WIDGET */
996 /* (gpiv->piveval->radiobutton_intsize_i_1), sense); */
997 if (gl_piv_par
->int_size_f
>= 32) {
998 gtk_widget_set_sensitive (GTK_WIDGET
999 (gpiv
->piveval
->radiobutton_intsize_i_2
),
1001 if (gl_piv_par
->int_size_f
>= 64) {
1002 gtk_widget_set_sensitive (GTK_WIDGET
1003 (gpiv
->piveval
->radiobutton_intsize_i_3
),
1005 if (gl_piv_par
->int_size_f
>= 128) {
1006 gtk_widget_set_sensitive (GTK_WIDGET
1007 (gpiv
->piveval
->radiobutton_intsize_i_4
),
1018 * Setting sensitivity of Validation witgets
1020 if (wi_set
== VALID
) {
1021 gtk_widget_set_sensitive (gpiv
->pivvalid
->radiobutton_errvec_residu_snr
, sense
);
1022 gtk_widget_set_sensitive (gpiv
->pivvalid
->radiobutton_errvec_residu_median
, sense
);
1023 gtk_widget_set_sensitive (gpiv
->pivvalid
->radiobutton_errvec_residu_normmedian
, sense
);
1024 gtk_widget_set_sensitive (gpiv
->pivvalid
->radiobutton_disable_1
, sense
);
1025 gtk_widget_set_sensitive (gpiv
->pivvalid
->label_errvec_res
, sense
);
1026 gtk_widget_set_sensitive (gpiv
->pivvalid
->spinbutton_errvec_res
, sense
);
1027 gtk_widget_set_sensitive (gpiv
->pivvalid
->checkbutton_errvec_disres
, sense
);
1028 gtk_widget_set_sensitive (gpiv
->pivvalid
->button_errvec_resstats
, sense
);
1030 gtk_widget_set_sensitive (gpiv
->pivvalid
->radiobutton_errvec_subst_1
, sense
);
1031 /* gtk_widget_set_sensitive (gpiv->pivvalid->radiobutton_errvec_subst_2, sense); */
1032 gtk_widget_set_sensitive (gpiv
->pivvalid
->radiobutton_errvec_subst_3
, sense
);
1033 gtk_widget_set_sensitive (gpiv
->pivvalid
->button_errvec
, sense
);
1035 gtk_widget_set_sensitive (gpiv
->pivvalid
->spinbutton_histo_bins
, sense
);
1036 gtk_widget_set_sensitive (gpiv
->pivvalid
->button_peaklck
, sense
);
1037 gtk_widget_set_sensitive (gpiv
->pivvalid
->button_uhisto
, sense
);
1038 gtk_widget_set_sensitive (gpiv
->pivvalid
->button_vhisto
, sense
);
1043 * Setting sensitivity of Post processing witgets
1045 if (wi_set
== POST
) {
1046 gtk_widget_set_sensitive (gpiv
->pivpost
->radiobutton_vorstra_output_1
, sense
);
1047 gtk_widget_set_sensitive (gpiv
->pivpost
->radiobutton_vorstra_output_2
, sense
);
1048 gtk_widget_set_sensitive (gpiv
->pivpost
->radiobutton_vorstra_output_3
, sense
);
1050 gtk_widget_set_sensitive (gpiv
->pivpost
->radiobutton_vorstra_diffscheme_1
,
1052 gtk_widget_set_sensitive (gpiv
->pivpost
->radiobutton_vorstra_diffscheme_2
,
1054 gtk_widget_set_sensitive (gpiv
->pivpost
->radiobutton_vorstra_diffscheme_3
,
1056 gtk_widget_set_sensitive (gpiv
->pivpost
->radiobutton_vorstra_diffscheme_4
,
1058 gtk_widget_set_sensitive (gpiv
->pivpost
->button_vorstra
, sense
);
1066 on_my_popup_handler (GtkWidget
*widget
,
1068 /*-----------------------------------------------------------------------------
1069 * Callback function for pop-up menus
1073 GdkEventButton
*event_button
;
1075 g_return_val_if_fail (widget
!= NULL
, FALSE
);
1076 g_return_val_if_fail (GTK_IS_MENU (widget
), FALSE
);
1077 g_return_val_if_fail (event
!= NULL
, FALSE
);
1079 /* The "widget" is the menu that was supplied when
1080 * gtk_signal_connect_object was called.
1082 menu
= GTK_MENU (widget
);
1084 if (event
->type
== GDK_BUTTON_PRESS
)
1086 event_button
= (GdkEventButton
*) event
;
1087 if (event_button
->button
== 3)
1089 gtk_menu_popup (menu
, NULL
, NULL
, NULL
, NULL
,
1090 event_button
->button
, event_button
->time
);
1101 replace_home_dir_with_tilde (const gchar
*uri
)
1102 /*-----------------------------------------------------------------------------
1103 * I stole this from gedit
1104 * return value will have to be freed
1110 g_return_val_if_fail (uri
!= NULL
, NULL
);
1112 /* Note that g_get_home_dir returns a const string */
1113 tmp
= (gchar
*)g_get_home_dir ();
1116 return g_strdup (uri
);
1118 home
= g_filename_to_utf8 (tmp
, -1, NULL
, NULL
, NULL
);
1120 return g_strdup (uri
);
1122 if (strcmp (uri
, home
) == 0) {
1125 return g_strdup ("~");
1129 home
= g_strdup_printf ("%s/", tmp
);
1132 if (g_str_has_prefix (uri
, home
))
1136 res
= g_strdup_printf ("~/%s", uri
+ strlen (home
));
1145 return g_strdup (uri
);
1151 replace_tilde_with_home_dir (const gchar
*uri
)
1152 /*-----------------------------------------------------------------------------
1153 * And wrote this by myself :) (What a genius that guy)
1160 g_return_val_if_fail (uri
!= NULL
, NULL
);
1162 if ((tmp
=(gchar
*)g_get_home_dir ()) == NULL
) {
1163 return g_strdup (uri
);
1166 if ((home
= g_filename_to_utf8 (tmp
, -1, NULL
, NULL
, NULL
)) == NULL
) {
1168 return g_strdup (uri
);
1171 if (g_str_has_prefix (uri
, "~/")) {
1172 home_name
= g_strdup_printf ("%s/%s", home
, uri
+ strlen ("~/"));
1175 return g_strdup (uri
);
1184 destroy (GtkWidget
* widget
,
1186 /*-----------------------------------------------------------------------------
1190 gtk_widget_destroy (widget
);
1195 void message_gpiv (gchar
* msg
, ...)
1196 /*-----------------------------------------------------------------------------
1197 * Message box with warning
1200 /* GtkWidget */ GtkDialog
*gtk_message_wi
;
1202 char local_msg
[3 * GPIV_MAX_CHARS
];
1204 va_start (args
, msg
);
1205 g_vsnprintf (local_msg
, 3 * GPIV_MAX_CHARS
, msg
, args
);
1206 gtk_message_wi
= create_message_dialog (local_msg
);
1207 gtk_widget_show (GTK_WIDGET (gtk_message_wi
));
1208 /* gtk_widget_show_all (gtk_message_wi); */
1214 void warning_gpiv (gchar
* msg
, ...)
1215 /*-----------------------------------------------------------------------------
1216 * Message box with warning
1219 GtkDialog
*gtk_warning_wi
;
1221 char lo_msg
[3 * GPIV_MAX_CHARS
];
1223 va_start (args
, msg
);
1224 g_vsnprintf (lo_msg
, 3 * GPIV_MAX_CHARS
, msg
, args
);
1225 gtk_warning_wi
= create_message_dialog (lo_msg
);
1226 gtk_widget_show (GTK_WIDGET (gtk_warning_wi
));
1232 void error_gpiv (gchar
* msg
, ...)
1233 /*-----------------------------------------------------------------------------
1234 * Message box with error
1237 GtkDialog
*gtk_error_wi
;
1239 char lo_msg
[2 * GPIV_MAX_CHARS
];
1241 va_start (args
, msg
);
1242 g_vsnprintf (lo_msg
, 2 * GPIV_MAX_CHARS
, msg
, args
);
1243 gtk_error_wi
= create_error_dialog (lo_msg
);
1244 gtk_widget_show (GTK_WIDGET (gtk_error_wi
));