lib/App/SeismicUnixGui/misc/green_flow.pm untested

filter: Statementstmt 0.0% 0 / 1128 Branchbran 0.0% 0 / 146 Conditioncond 0.0% 0 / 114 MC/DCmcdc 0.0% 0 / 65 Subroutinesub 0.0% 0 / 67 Podpod 0.0% 0 / 43 totaltotal 0.0% 0 / 1563 CC 74 SCAR 31.0
CC
74
Cov
0%
flow_select
90.0
delete_from_flow_button
72.0
FileDialog_button
56.0
CRAP 22.2
1 package App::SeismicUnixGui::misc::green_flow;
2  
3 =head1 DOCUMENTATION
4  
5  
6 =head2 SYNOPSIS
7  
8 PERL PERL PROGRAM NAME: green_flow.pm
9 AUTHOR: Juan Lorenzo
10 DATE: June 8 2018
11  
12 DESCRIPTION
13
14  
15 BASED ON:
16 previous versions of the main userBuiltFlow.pl
17
18  
19 =cut
20  
21 =head2 USE
22  
23 =head3 NOTES
24  
25 Provides in-house macros/superflows
26 1. Find widget you have selected
27  
28 if widget_name= frame then we have flow
29 $var->{_flow}
30
31 if widget_name= menubutton we have superflow
32 $var->{_tool}
33  
34 2. Set the new program name
35  
36 3. Make widget states active for:
37 run_button
38 save_button
39  
40 4. Disable the following widgets:
41 delete_from_flow_button
42 (sunix) flow_listbox
43  
44 sunix_listbox -choice of listed sunix modules in a listbox
45 gui_history records updates to GUI selections
46 but color_flow_href points to the changed has reference and senses
47 the change as well.
48
49 =head4 Examples
50  
51 =head3 SEISMIC UNIX NOTES
52  
53 =head2 CHANGES and their DATES
54 refactoring of 2017 version of L_SU.pl
55 V 0.0.2 removed unused methods in comments
56
57 V 0.0.3 2021 allows for better color listbox control
58
59 V 0.0.4 7.10.21 allows control to handle non-numeric
60 names for input files
61  
62 =cut
63  
64 =head2 Notes
65  
66 sub sunix_select (subroutine is only active in neutral_flow.pm)
67
68
69 =cut
70  
71 use Moose;
72 our $VERSION = '0.0.4';
73  
74 use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants';
75 use aliased 'App::SeismicUnixGui::configs::big_streams::Project_config';
76  
77 extends 'App::SeismicUnixGui::misc::gui_history' => { -version => 0.0.2 };
78 use aliased 'App::SeismicUnixGui::misc::gui_history';
79  
80 # use App::SeismicUnixGui::misc::param_widgets_green '0.0.2';
81 # use aliased 'App::SeismicUnixGui::misc::param_widgets_green';
82  
83 use App::SeismicUnixGui::misc::param_widgets_color '0.0.3';
84 use aliased 'App::SeismicUnixGui::misc::param_widgets_color';
85  
86 use App::SeismicUnixGui::misc::param_flow_green '0.0.5';
87 use aliased 'App::SeismicUnixGui::misc::param_flow_green';
88  
89 use aliased 'App::SeismicUnixGui::misc::binding';
90  
91 use App::SeismicUnixGui::misc::control '0.0.3';
92 use aliased 'App::SeismicUnixGui::misc::control';
93  
94 use App::SeismicUnixGui::misc::decisions '1.0.0';
95 use aliased 'App::SeismicUnixGui::misc::decisions';
96  
97 use aliased 'App::SeismicUnixGui::misc::dirs';
98 use aliased 'App::SeismicUnixGui::misc::file_dialog';
99 use aliased 'App::SeismicUnixGui::misc::files_LSU';
100 use aliased 'App::SeismicUnixGui::misc::flow_widgets';
101 use aliased 'App::SeismicUnixGui::misc::help';
102 use aliased 'App::SeismicUnixGui::misc::manage_files_by2';
103 use aliased 'App::SeismicUnixGui::messages::message_director';
104 use aliased 'App::SeismicUnixGui::misc::perl_flow';
105 use aliased 'App::SeismicUnixGui::misc::param_sunix';
106  
107 use Carp;
108 use Clone 'clone';
109  
110 =head2 Instantiation
111  
112 =cut
113  
114 my $Project = Project_config->new();
115 my $L_SU_global_constants = L_SU_global_constants->new();
116 my $control = control->new();
117 my $decisions = decisions->new();
118 my $dirs = dirs->new();
119 my $file_dialog = file_dialog->new();
120 my $flow_widgets = flow_widgets->new();
121 my $gui_history = gui_history->new();
122 my $manage_files_by2 = manage_files_by2->new();
123 my $message_director = message_director->new();
124  
125 my $param_flow_color_pkg = param_flow_green->new();
126 my $param_widgets = param_widgets_color->new();
127  
128  
129 my $flow_type = $L_SU_global_constants->flow_type_href();
130 my $var = $L_SU_global_constants->var();
131 my $empty_string = $var->{_empty_string};
132 my $this_color = 'green';
133  
134 my $color_flow_href = $gui_history->get_defaults();
135 my $neutral = $var->{_neutral};
136 my $sunix_select = $var->{_sunix_select};
137 my $number_from_color = $L_SU_global_constants->number_from_color_href();
138  
139 # set the flow color being used for the instance
140 $param_widgets->set_color_flow($this_color);
141  
142 my $_is_last_parameter_index_touched_color =
143 '_is_last_parameter_index_touched_' . $this_color;
144 my $_flow_listbox_color_w = '_flow_listbox_' . $this_color . '_w';
145 my $_flow_name_color_w = '_flow_name_' . $this_color . '_w';
146 my $_number_from_color = $number_from_color->{ ( '_' . $this_color ) };
147 my $_flow_name_in_color = '_flow_name_in_' . $this_color;
148 my $_flow_name_out_color = '_flow_name_out_' . $this_color;
149  
150 =head2
151  
152 share the following parameters in same name
153 space
154
155 =cut
156  
157 my $flow_color;
158 my $flow_name_color_w;
159 my $flowNsuperflow_name_w;
160 my $last_flow_color;
161 my $message_w;
162 my $occupied_listbox_aref;
163 my $vacant_listbox_aref;
164 my $parameter_values_button_frame;
165 my $parameter_values_frame;
166  
167 my $user_built = $flow_type->{_user_built};
168 my $true = $var->{_true};
169 my $false = $var->{_false};
170  
171 #my @empty_array = (0); # length=1
172  
173 =head2 memory leak saviors
174  
175 =cut
176  
177 my $default = 0;
178 my @save_last_param_widget_values;
179 my $save_last_param_widget_value;
180 my $save_last_param_widget_index = $default;
181 my $memory_leak4save_button_fixed = $false;
182 my $memory_leak4flow_select_fixed = $false;
183 my $min_clicks4save_button = $var->{_min_clicks4save_button};
184 my $min_clicks4flow_select = $var->{_min_clicks4flow_select};
185 my $first_opening = $true; # don't touch, but commented out below
186  
187 =head2 private anonymous hash
188 to share variable values easily
189  
190 =cut
191  
192 my $color_flow = {
193  
194 _Flow_file_exists => $false,
195 _perl_flow_errors => $true,
196  
197 };
198  
199 =head2 sub _add2flow
200  
201 When automatically reading a user-built perl flow and not directed
202 to do so by a user's click of the mouse.
203 As when a file is opened
204 Incorporate new program parameter values and labels into the gui
205 and save the values, labels and checkbuttons setting in the param_flow
206 namespace
207  
208 foreach my $key (sort keys %$color_flow_href) {
209 print (" color_flow _add2flow,key is $key, value is $color_flow_href->{$key}\n");
210 }
211
212 _flow_select is run from _perl_flow
213  
214 =cut
215  
216 sub _add2flow {
217  
218 my ( $self, $value ) = @_;
219  
220 my $message = $message_director->null_button(0);
221  
222 my $here;
223 my $flow_color = _get_flow_color();
224 $gui_history->set_add2flow_color($flow_color);
225 $gui_history->set_button('add2flow_button');
226 $gui_history->set_flow_type($user_built);
227  
228 $gui_history->set_hash_ref($color_flow_href);
229 $gui_history->set4start_of_add2flow_button($flow_color);
230 $color_flow_href = $gui_history->get_hash_ref();
231  
232 $message_w->delete( "1.0", 'end' );
233 $message_w->insert( 'end', $message );
234  
235 # add the most recently selected program
236 # name (scalar reference) to the
237 # end of the list inside flow_listbox
238 _local_set_flow_listbox_color_w($flow_color); # in "color"_flow namespace
239  
240 # append new program names to the end of the list but this item is NOT selected
241 # selection occurs inside gui_history, conditions_gui
242 $color_flow_href->{_flow_listbox_color_w}
243 ->insert( "end", ${ $color_flow_href->{_prog_name_sref} }, );
244  
245 # display default paramters in the GUI
246 # same as for sunix_select
247 # can not get program name from the item selected in the sunix list box
248 # because focus is transferred to a flow list box ($this_color)
249  
250 # widgets are initialized in a super class
251 # Assign program parameters in the GUI
252 # See: L_SU_global_constants.pl
253  
254 $param_widgets->set_labels_w_aref( $color_flow_href->{_labels_w_aref} );
255 $param_widgets->set_values_w_aref( $color_flow_href->{_values_w_aref} );
256 $param_widgets->set_check_buttons_w_aref(
257 $color_flow_href->{_check_buttons_w_aref} );
258  
259 $param_widgets->range($color_flow_href);
260 $param_widgets->set_labels( $color_flow_href->{_names_aref} );
261 $param_widgets->set_values( $color_flow_href->{_values_aref} );
262 $param_widgets->set_check_buttons(
263 $color_flow_href->{_check_buttons_settings_aref} );
264  
265 # print(" 22. color_flow, _add2flow, color_flow_href->{_values_aref}=@{$color_flow_href->{_values_aref}}\n");
266  
267 # wipe out values labels and checkbuttons from the gui
268 # strange memory leak inside param_widgets
269 # TODO check it this is still true?
270 # my $save1 = clone( $color_flow_href->{_check_buttons_settings_aref} );
271 # $param_widgets->gui_full_clear();
272 # @{ $color_flow_href->{_check_buttons_settings_aref} } = @$save1;
273 #
274 # $param_widgets->redisplay_labels();
275 # $param_widgets->redisplay_values();
276 # $param_widgets->redisplay_check_buttons();
277  
278 # @{ $color_flow_href->{_names_aref} } = @$save2;
279 # @{ $color_flow_href->{_values_aref} } = @$save3;
280  
281 # Collect and store prog versions changed in list box
282 _stack_versions();
283  
284 # Add a single_program to the growing stack
285 # store one program name, its associated parameters and their values
286 # as well as the checkbuttons settings (on or off) in another namespace
287 _stack_flow();
288  
289 $gui_history->set_hash_ref($color_flow_href);
290 $gui_history->set4end_of_add2flow($flow_color);
291  
292 my $index = $flow_widgets->get_flow_selection(
293 $color_flow_href->{_flow_listbox_color_w} );
294  
295 $gui_history->set_flow_index_last_touched($index); # flow color is not reset
296 $color_flow_href = $gui_history->get_hash_ref();
297  
298 # switch between the correct index of the last parameter that was touched
299 # as a function of the flow's color
300 # These data are encapsulated
301 $color_flow_href->{_last_parameter_index_touched_color} = 0; # initialize
302 $color_flow_href->{$_is_last_parameter_index_touched_color} = $true;
303  
304 $param_widgets->set_check_buttons(
305 $color_flow_href->{_check_buttons_settings_aref} );
306  
307 # print(
308 #" 2. color_flow, END _add2flow, color_flow_href->{_values_aref}=@{$color_flow_href->{_values_aref}}\n"
309 # );
310  
311 # print(" 2. color_flow, END _add2flow, widget values =@{$param_widgets->get_values_aref()} \n");
312  
313 _flow_select_director('_add2flow');
314  
315 $param_widgets->set_entry_change_status($false);
316  
317 return ();
318  
319 }
320  
321 =head2 sub _clear_color_flow
322  
323 wipe out color-flow list box with programs
324 wipe out param_widgets_color
325 wipe out parameters stored for color flow
326  
327 =cut
328  
329 sub _clear_color_flow {
330 my ($self) = @_;
331  
332 # my $number = $param_flow_color_pkg->get_num_items();
333  
334 #clear all stored parameters and versions in the param_flow
335 $param_flow_color_pkg->clear();
336 my $number = $param_flow_color_pkg->get_num_items();
337  
338 my $test = $color_flow_href->{_check_buttons_settings_aref};
339  
340 # clear the parameter values and labels belonging to the gui
341 # strange memory leak inside param_widgets
342 my $save = clone( $color_flow_href->{_check_buttons_settings_aref} );
343 $param_widgets->gui_full_clear();
344  
345 # print("color_flow,_clear_color_flow: print gui_history.txt \n");
346 # $gui_history->view();
347 @{ $color_flow_href->{_check_buttons_settings_aref} } = @$save;
348  
349 # remove all sunix program names from the flow listbox
350 # in "color"_flow namespace
351 my $_flow_listbox_color_w = _get_flow_listbox_color_w();
352 $flow_widgets->clear($_flow_listbox_color_w);
353  
354 }
355  
356 =head2 sub _FileDialog_button
357  
358 Only cases with MB binding use this private ('_') subroutine
359 e.g., sunix programs displayed in the parameter boxes during
360 flow construction.
361 sub binding is responsible
362 Other cases that select the GUI file buttons directly (user click) use: FileDialog_button instead.
363 Once the file name is selected the parameter value is updated in the GUI
364  
365 foreach my $key (sort keys %$color_flow) {
366 print (" color_flowkey is $key, value is $color_flow->{$key}\n");
367 }
368 print ("color_flow,_FileDialog_button(binding), _is_flow_listbox_color_w: $color_flow_href->{_is_flow_listbox_color_w} \n");
369
370 =cut
371  
372 sub _FileDialog_button {
373  
374 my ( $self, $flow_dialog_type_sref ) = @_;
375  
376 if ($flow_dialog_type_sref) {
377  
378 # flow dialog type can be
379 # 'Open' or Data_PL_SEISMIC
380  
381 # provide values in the current widget
382 $color_flow_href->{_values_aref} = $param_widgets->get_values_aref();
383  
384 my $most_recent_flow_index_touched =
385 ( $color_flow_href->{_flow_select_index_href} )->{_most_recent};
386  
387 # establish which program is active in the flow
388 $color_flow_href->{_prog_names_aref} =
389 $param_flow_color_pkg->get_flow_prog_names_aref();
390 $control->set_flow_prog_names_aref(
391 $color_flow_href->{_prog_names_aref} );
392 $control->set_flow_prog_name_index($most_recent_flow_index_touched);
393  
394 # clean all quotes upon input
395 $color_flow_href->{_values_aref} =
396 $control->get_no_quotes4array( $color_flow_href->{_values_aref} );
397  
398 # restore string quotes to values that need them
399 # e.g., character strings as well as fnumeric file names
400 $color_flow_href->{_values_aref} = $control->get_string_or_number4aref(
401 $color_flow_href->{_values_aref} );
402  
403 # dereference scalar
404 $color_flow_href->{_dialog_type} = $$flow_dialog_type_sref;
405  
406 $file_dialog->set_flow_color( $color_flow_href->{_flow_color} );
407 $file_dialog->set_hash_ref($color_flow_href);
408 $file_dialog->set_dialog_type($$flow_dialog_type_sref);
409 $file_dialog->FileDialog_director();
410  
411 # updates to parameter values
412 # changed within file_dialog are retrieved
413 $color_flow_href->{_values_aref} = $file_dialog->get_values_aref();
414  
415 # print("color flow, _FileDialog_button: color_flow_href->{_values_aref}=@{$color_flow_href->{_values_aref}}\n");
416  
417 # assume that after selection to open of a data file, while using file-dialog button, the
418 # GUI has been updated
419 # Assume we are still dealing with the current flow item selected
420 # Update the value of the Entry widget (in GUI) with the selected file name
421 # Also update the parameter_widgets with the updated value
422  
423 my $current_index = $file_dialog->get_current_index();
424 my $selected_Entry_widget = $file_dialog->get_selected_Entry_widget();
425 @{ $param_widgets->{_values_aref} }[$current_index] =
426 $file_dialog->get_selected_file_name();
427 @{ $color_flow_href->{_values_aref} }[$current_index] =
428 $file_dialog->get_selected_file_name();
429  
430 $param_widgets->redisplay_values();
431  
432 # Make sure to place focus again on the updated widget so other modules can find the selection
433  
434 $selected_Entry_widget->focus; # from above
435  
436 #print("13 color_flow, _FileDialog_button,color_flow selected_file_name: @{ $param_widgets->{_values_aref} }[$current_index]\n");
437 #print("13 color_flow, _FileDialog_button,color_flow values: @{ $color_flow_href->{_values_aref} }\n");
438 # print("9. color_flow, _FileDialog_button, last_flow_color:$color_flow_href->{_last_flow_color}\n");
439 # print("1. color_flow, _FileDialog_button, last_flow_index_touched $color_flow_href->{_last_flow_index_touched}\n");
440  
441 # set up this flow listbox item as the last item touched
442 # user-built_flow in current use
443 my $_flow_listbox_color_w = _get_flow_listbox_color_w();
444 my $current_flow_listbox_index =
445 $flow_widgets->get_flow_selection($_flow_listbox_color_w);
446  
447 # print("2. color_flow, _FileDialog_button, last_flow_index_touched $color_flow_href->{_last_flow_index_touched}\n");
448 # print("10. color_flow, _FileDialog_button, last_flow_color:$color_flow_href->{_last_flow_color}\n");
449 # Changes made with another instance of param_widgets (in file_dialog) will require
450 # that we update the namespace of the current param_flow
451 # We make this change inside _save_most_recent_param_flow
452 _save_most_recent_param_flow();
453  
454 }
455 else {
456 print("color_flow,_FileDialog_button (binding),option type missing ");
457 }
458 return ();
459 }
460  
461 =head2 sub _clear_items_version_aref
462  
463 clear items_versions_aref
464 used when last item is removed from the listbox
465  
466 =cut
467  
468 sub _clear_items_version_aref {
469  
470 my ($self) = @_;
471  
472 if ($color_flow_href) {
473  
474 $color_flow_href->{_items_versions_aref} = '';
475 return ();
476  
477 }
478 else {
479 print("color_flow, _clear_items_version_aref, missing color_flow \n");
480 return ();
481 }
482  
483 }
484  
485 =head2 sub _clear_stack_versions
486  
487 clear items_versions_aref
488 when last flow item is deleted
489 in the listbox
490  
491 =cut
492  
493 sub _clear_stack_versions {
494  
495 my $_flow_listbox_color_w = _get_flow_listbox_color_w();
496  
497 $flow_widgets->clear_flow_item($_flow_listbox_color_w);
498 $flow_widgets->clear_items_versions_aref();
499  
500 # with hash value = ''
501 _clear_items_version_aref();
502  
503 $param_flow_color_pkg->clear_flow_items_version_aref();
504  
505 }
506  
507 =head2 sub _flow_select_director
508  
509 Private alias for flow_select
510 both color and button are set as
511 per the flow_select called by an active click
512 from Main, in_L_SU_flow_bindings
513  
514 =cut
515  
516 sub _flow_select_director {
517  
518 my ($type) = @_;
519  
520 if ( defined $type ) {
521 $gui_history->set_flow_select_color($this_color);
522  
523 if (
524 $type eq '_add2flow' # when perl flow is read
525 or $type eq '_perl_flow'
526 or $type eq 'delete_from_flow_button'
527 or $type eq 'delete_whole_flow_button'
528 or $type eq 'flow_item_down_arrow_button'
529 or $type eq 'flow_item_up_arrow_button'
530 )
531 {
532 # update most recent flow
533 # print(
534 #" 3. color_flow,_flow_select_director,END OF LOADING INTO GUI for type=$type\n"
535 # );
536 # print(
537 #" 3. color_flow,_flow_select_director,color_flow_href->{_values_aref}=@{$color_flow_href->{_values_aref}}\n"
538 # );
539  
540 _flow_select2save_most_recent_param_flow();
541  
542 # print(" 3. color_flow,_flow_select_director, widget values=@{$param_widgets->get_values_aref()} \n");
543  
544 if ( $type eq '_add2flow' ) {
545  
546 # CASE of opening a perl flow
547 # the last set of param_widgets opened
548 @save_last_param_widget_values =
549 @{ $param_widgets->get_values_aref() };
550 $save_last_param_widget_value = $save_last_param_widget_values[-1];
551 $save_last_param_widget_index = $#save_last_param_widget_values;
552  
553 }
554  
555 # flow loading and display is complete
556 # print("1. color_flow, _flow_select_director, print out gui_history\n");
557 # $gui_history->view();
558  
559 }
560 elsif ( $type eq 'add2flow_button' ) {
561  
562 _flow_select2save_most_recent_param_flow();
563  
564 # update prior flow
565 # flow_select();
566  
567 }
568 else {
569 print("color_flow,_flow_select_director, unexpected\n");
570 }
571 return ();
572  
573 }
574 }
575  
576 =head2 sub flow_select2save_most_recent_param_flow
577  
578 Select a program from the flow
579 Apply when add2flow_button is directly selected by the user
580
581 Archive the index
582 Update any changed parameter flows
583 Consider prior flow-color changes
584 Correct unticked strings from GUI a
585 Use _updateNsave_most_recent_param_flow();
586  
587 # print("color_flow, flow_select2save_most_recent_param_flow, view stored flow parameters BEFORE update\n");
588 # $param_flow_color_pkg->view_data();
589 # print("color_flow, flow_select2save_most_recent_param_flow, view stored flow parameters AFTER update\n");
590 # $param_flow_color_pkg->view_data();
591  
592 # print("3. color_flow, flow_select2save_most_recent_param_flow: writing gui_history.txt\n");
593 # $gui_history->view(
594  
595 # print("10 flow_select2save_most_recent_param_flow,check_buttons_settings_aref: @{color_flow_href->{_check_buttons_settings_aref}}\n");
596  
597
598 =cut
599  
600 sub flow_select2save_most_recent_param_flow {
601 my ($self) = @_;
602  
603 $color_flow_href->{_flow_type} = $flow_type->{_user_built};
604  
605 _local_set_flow_listbox_color_w($flow_color);
606  
607 my $message = $message_director->null_button(0);
608 $message_w->delete( "1.0", 'end' );
609 $message_w->insert( 'end', $message );
610  
611 $gui_history->set_hash_ref($color_flow_href);
612 $gui_history->set_defaults_4start_of_flow_select($flow_color);
613 $color_flow_href = $gui_history->get_hash_ref();
614  
615 # update the flow color as per add2flow_select2save_most_recent_param_flow
616 my $_flow_listbox_color_w = _get_flow_listbox_color_w();
617  
618 $color_flow_href->{_prog_name_sref} =
619 $flow_widgets->get_current_program( \$_flow_listbox_color_w );
620  
621 $decisions->set_hash_ref($color_flow_href);
622  
623 my $pre_req_ok = $decisions->get4flow_select();
624  
625 if ($pre_req_ok) {
626  
627 my $binding = binding->new();
628 my $here;
629  
630 # consider previous flow-color changes
631 # unticked strings from GUI are corrected within
632 _updateNsave_most_recent_param_flow();
633  
634 # For just-selected program name
635 # Retrieve flow parameters from storage
636 # Redisplay the widgets with parameters
637  
638 # Update the flow item index to the program that is currently being used, instead
639 # of prior program
640 # Warning: Flow selection gets reset if user double-clicks on a parameter value
641 # in another window
642 $gui_history->set_button('flow_select');
643 my $index = $flow_widgets->get_flow_selection($_flow_listbox_color_w);
644 # print("635 color_flow, flow_select2save_most_recent_param_flow index=$index \n");
645  
646 # MOST COMMON CASE
647 if ( defined($index)
648 and $index >= 0 )
649 {
650  
651 $param_flow_color_pkg->set_flow_index($index);
652 $color_flow_href->{_names_aref} =
653 $param_flow_color_pkg->get_names_aref();
654 $color_flow_href->{_values_aref} =
655 $param_flow_color_pkg->get_values_aref();
656  
657 $color_flow_href->{_check_buttons_settings_aref} =
658 $param_flow_color_pkg->get_check_buttons_settings();
659  
660 # get stored first index and num of items
661 $color_flow_href->{_param_flow_first_idx} =
662 $param_flow_color_pkg->first_idx();
663 $color_flow_href->{_param_flow_length} =
664 $param_flow_color_pkg->length();
665  
666 $param_widgets->set_current_program(
667 $color_flow_href->{_prog_name_sref} );
668  
669 # widgets were initialized in super class
670 $param_widgets->set_labels_w_aref(
671 $color_flow_href->{_labels_w_aref} );
672 $param_widgets->set_values_w_aref(
673 $color_flow_href->{_values_w_aref} );
674 $param_widgets->set_check_buttons_w_aref(
675 $color_flow_href->{_check_buttons_w_aref} );
676  
677 $color_flow_href->{_prog_name_sref} =
678 $flow_widgets->get_current_program( \$_flow_listbox_color_w );
679  
680 $param_widgets->range($color_flow_href);
681  
682 # strange memory leak inside param_widgets
683 my $save1 =
684 clone( $color_flow_href->{_check_buttons_settings_aref} );
685 $param_widgets->gui_full_clear();
686 @{ $color_flow_href->{_check_buttons_settings_aref} } = @$save1;
687  
688 $param_widgets->set_labels( $color_flow_href->{_names_aref} );
689  
690 $param_widgets->set_check_buttons(
691 $color_flow_href->{_check_buttons_settings_aref} );
692  
693 $param_widgets->redisplay_labels();
694 $param_widgets->redisplay_values();
695 $param_widgets->redisplay_check_buttons();
696 $param_widgets->set_entry_change_status($false);
697  
698 # Unpectedly Entry focus is delayed until the end of this method before
699 # completion;
700 # that is we get to gui_history->view before we can update the focus
701 # mysterious!!!!!
702 $param_widgets->set_focus_on_Entry_w(0); # put focus on first entry widget, index=0
703  
704 # Rebind the different buttons depending on the
705 # program name that is selected (i.e., through spec.pm)
706 $binding->set_prog_name_sref( $color_flow_href->{_prog_name_sref} );
707 $binding->set_values_w_aref( $param_widgets->get_values_w_aref );
708  
709 # reference to local subroutine that will be run when MB3 is pressed
710 $binding->setFileDialog_button_sub_ref( \&_FileDialog_button );
711 $binding->set();
712  
713 $gui_history->set_hash_ref($color_flow_href);
714 $gui_history->set4end_of_flow_select($flow_color);
715 $gui_history->set_flow_index_last_touched($index);
716 $color_flow_href = $gui_history->get_hash_ref();
717  
718 # Use currently selected program name from the flow list
719 # e.g. data_in, suximage, suxgraph etc. to update the
720 # entry button value displaying the currently active
721 # flow or superflow name
722 ( $color_flow_href->{_flowNsuperflow_name_w} )
723 ->configure( -text => ${ $color_flow_href->{_prog_name_sref} } );
724  
725 # For possible export via get_hash_ref to help
726 my $prog_name_sref = $color_flow_href->{_prog_name_sref};
727  
728 }
729 # LESS COMMON CASE
730 # index is defined but negative
731 elsif ( defined $index ) {
732 print("736 color_flow,flow_select2save_most_recent_param_flow, NADA probably deleted last of flow\n");
733 }
734 # LESS COMMON CASE
735 # undefined but needed index
736 else {
737  
738 # print("729 color_flow,flow_select2save_most_recent_param_flow, no index, - NADA\n");
739 }
740  
741 } # end pre_ok
742 # print("733. color_flow,flow_select2save_most_recent_param_flow, end\n");
743 return ();
744 } # end sub
745  
746 =head2 sub _flow_select2save_most_recent_param_flow
747  
748 select a program from the flow
749 archive the index
750 and update any changed parameter flows
751
752 =cut
753  
754 sub _flow_select2save_most_recent_param_flow {
755 my ($self) = @_;
756  
757 $color_flow_href->{_flow_type} = $flow_type->{_user_built};
758  
759 # print("1. color_flow,_flow_select2save_most_recent_param_flow, last_flow_index_touched:$color_flow_href->{_last_flow_index_touched}\n");
760 # print("color_flow,_flow_select2save_most_recent_param_flow, last_flow_color:$color_flow_href->{_last_flow_color}\n");
761  
762 # reset residual flow_listbox_color_w of another color
763 # flow_color exists in current (color_flow) namespace
764 _local_set_flow_listbox_color_w($flow_color);
765 $gui_history->set_flow_select_color($flow_color);
766  
767 # print("1. color_flow, _flow_select2save_most_recent_param_flow, show stored flow parameters\n");
768 # $param_flow_color_pkg->view_data();
769  
770 my $message = $message_director->null_button(0);
771 $message_w->delete( "1.0", 'end' );
772 $message_w->insert( 'end', $message );
773  
774 $gui_history->set_hash_ref($color_flow_href);
775 $gui_history->set_defaults_4start_of_flow_select($flow_color);
776 $color_flow_href = $gui_history->get_hash_ref();
777  
778 # update the flow color as per add2_flow_select2save_most_recent_param_flow
779 my $_flow_listbox_color_w = _get_flow_listbox_color_w();
780  
781 $color_flow_href->{_prog_name_sref} =
782 $flow_widgets->get_current_program( \$_flow_listbox_color_w );
783  
784 $decisions->set_hash_ref($color_flow_href);
785  
786 # print("3. color_flow, _flow_select2save_most_recent_param_flow: writing gui_history.txt\n");
787 # $gui_history->view();
788  
789 # print("3. color_flow,_flow_select2save_most_recent_param_flow, last_flow_index_touched:$color_flow_href->{_last_flow_index_touched}\n");
790 #$param_flow_color_pkg->view_data();
791  
792 my $pre_req_ok = $decisions->get4flow_select();
793  
794 if ($pre_req_ok) {
795  
796 my $binding = binding->new();
797 my $here;
798  
799 $gui_history->set_button('flow_select');
800  
801 # consider prior flow-color changes
802 # unticked strings from GUI are corrected here
803  
804 # print(" 8, color_flow, before _updatenNsave_most_recent_param_flow\n");
805  
806 # $param_flow_color_pkg->view_data();
807 # print(
808 #"8B. color_flow, _flow_select2save_most_recent_param_flow, values@{$color_flow_href->{_values_aref}}\n"
809 # );
810  
811 _updateNsave_most_recent_param_flow();
812  
813 # print("after 117 _updateNsave_most_recent_param_flow\n");
814 # print(
815 # "after 118 _color_flow, _flow_select2save_most_recent_param_flow, values@{$color_flow_href->{_values_aref}}\n"
816 # );
817  
818 # for just-selected program name
819 # get its flow parameters from storage
820 # and redisplay the widgets with parameters
821  
822 # Update the flow item index to the program that is currently being used, instead
823 # of prior program
824 # Warning: Flow selection gets reset if user double-clicks on a parameter value
825 # in another window
826 my $index = $flow_widgets->get_flow_selection($_flow_listbox_color_w);
827  
828 $param_flow_color_pkg->set_flow_index($index);
829 $color_flow_href->{_names_aref} =
830 $param_flow_color_pkg->get_names_aref();
831  
832 # print("9 _flow_select2save_most_recent_param_flow,index=$index\n");
833 # $param_flow_color_pkg->view_data();
834 # print("9B. color_flow, _flow_select2save_most_recent_param_flow, values@{$color_flow_href->{_values_aref}}\n");
835  
836 $color_flow_href->{_values_aref} =
837 $param_flow_color_pkg->get_values_aref();
838 $color_flow_href->{_check_buttons_settings_aref} =
839 $param_flow_color_pkg->get_check_buttons_settings();
840  
841 # print("10 _flow_select2save_most_recent_param_flow,index=$index\n");
842 # $param_flow_color_pkg->view_data();
843  
844 # print("10 _flow_select2save_most_recent_param_flow,check_buttons_settings_aref: @{color_flow_href->{_check_buttons_settings_aref}}\n");
845 # get stored first index and num of items
846 $color_flow_href->{_param_flow_first_idx} =
847 $param_flow_color_pkg->first_idx();
848 $color_flow_href->{_param_flow_length} =
849 $param_flow_color_pkg->length();
850  
851 $param_widgets->set_current_program(
852 $color_flow_href->{_prog_name_sref} );
853  
854 # print("4. color_flow, _flow_select2save_most_recent_param_flow: writing gui_history.txt\n");
855 # $gui_history->view();
856  
857 # widgets were initialized in super class
858 $param_widgets->set_labels_w_aref( $color_flow_href->{_labels_w_aref} );
859 $param_widgets->set_values_w_aref( $color_flow_href->{_values_w_aref} );
860 $param_widgets->set_check_buttons_w_aref(
861 $color_flow_href->{_check_buttons_w_aref} );
862  
863 $color_flow_href->{_prog_name_sref} =
864 $flow_widgets->get_current_program( \$_flow_listbox_color_w );
865  
866 # wipes out values labels and checkbuttons from the gui
867  
868 $param_widgets->range($color_flow_href);
869  
870 # print(
871 #"119 color_flow, END _flow_select2save_most_recent_param_flow,color_flow_href->{_values_aref} =@{$color_flow_href->{_values_aref}}\n"
872 # );
873  
874 # strange memory leak inside param_widgets
875 # my @save1 = clone( @{$color_flow_href->{_check_buttons_settings_aref}} );
876 # $color_flow_href->{_check_buttons_settings_aref} = \@save1;
877 # my @save2 = clone( @{$color_flow_href->{_values_aref}} );
878 # $color_flow_href->{_values_aref} = \@save2;
879 # my @save3 = clone( @{$color_flow_href->{_names_aref}} );
880 # $color_flow_href->{_names_aref} = \@save3;
881 # print("120 color_flow, END _flow_select2save_most_recent_param_flow,color_flow_href->{_values_aref} =@{$color_flow_href->{_values_aref}}\n");
882 #
883 $param_widgets->gui_full_clear();
884 $param_widgets->set_labels( $color_flow_href->{_names_aref} );
885 $param_widgets->set_values( $color_flow_href->{_values_aref} );
886 $param_widgets->set_check_buttons(
887 $color_flow_href->{_check_buttons_settings_aref} );
888  
889 # print(
890 #"121 color_flow, END _flow_select2save_most_recent_param_flow,color_flow_href->{_values_aref} =@{$color_flow_href->{_values_aref}}\n"
891 # );
892  
893 $param_widgets->redisplay_labels();
894 $param_widgets->redisplay_values();
895 $param_widgets->redisplay_check_buttons();
896 $param_widgets->set_entry_change_status($false);
897  
898 # mysterious!!!!!
899 # We need to get gui_istory->view before we can update the focus
900 # Unxpectedly, Entry focus is delayed until the end of this method before
901 # completion;
902 # put focus on first entry widget, index=0
903 $param_widgets->set_focus_on_Entry_w(0);
904  
905 # print(
906 #"122 color_flow, END _flow_select2save_most_recent_param_flow,color_flow_href->{_values_aref} =@{$color_flow_href->{_values_aref}}\n"
907 # );
908  
909 # $color_flow_href->{_last_parameter_index_touched_color} = 0;
910 # the changed parameter value in the Entry widget should force an update of stored values
911 # in the current flow item (not the last flow item touched)
912 # _save_most_recent_param_flow(); # is only active if
913 # $color_flow_href->{_last_parameter_index_touched_color} >= 0
914 # Here is where you rebind the different buttons depending on the
915 # program name that is selected (i.e., through *_spec.pm)
916 $binding->set_prog_name_sref( $color_flow_href->{_prog_name_sref} );
917 $binding->set_values_w_aref( $param_widgets->get_values_w_aref );
918  
919 # reference to local subroutine that will be run when MB3 is pressed
920 $binding->setFileDialog_button_sub_ref( \&_FileDialog_button );
921 $binding->set();
922  
923 $gui_history->set_hash_ref($color_flow_href);
924 $gui_history->set4end_of_flow_select($flow_color);
925 $gui_history->set_flow_index_last_touched($index);
926 $color_flow_href = $gui_history->get_hash_ref();
927  
928 # Update the entry button value that displays the currently active
929 # flow or superflow name, by using the currently selected program name from the flow list
930 # e.g. data_in, suximage, suxgraph etc.
931 ( $color_flow_href->{_flowNsuperflow_name_w} )
932 ->configure( -text => ${ $color_flow_href->{_prog_name_sref} } );
933  
934 # needed in possible export via get_hash_ref to help
935 my $prog_name_sref = $color_flow_href->{_prog_name_sref};
936  
937 # will not reflect the Entry focus change
938 # print("color_flow_href _flow_select2save_most_recent_param_flow, log view is on\n");
939 # $gui_history->view();
940 # print("11, color_flow, END of _flow_select2save_most_recent_param_flow \n");
941 # $param_flow_color_pkg->view_data();
942 # print("14.color_flow,_flow_select2save_most_recent_param_flow,widget values =@{$param_widgets->get_values_aref()} \n");
943  
944 } # end pre_ok
945  
946 return ();
947 }
948  
949 =head2 sub _get_flow_color
950  
951 get a private hash value
952
953 =cut
954  
955 sub _get_flow_color {
956 my ($self) = @_;
957  
958 if ( $color_flow_href->{_flow_color} ) {
959 my $color;
960  
961 $color = $color_flow_href->{_flow_color};
962 return ($color);
963  
964 }
965 else {
966 print("color_flow, missing flow color\n");
967 }
968  
969 }
970  
971 =head2 sub _get_flow_listbox_color_w
972  
973  
974 =cut
975  
976 sub _get_flow_listbox_color_w {
977 my ($self) = @_;
978 my $this_flow_listbox_color_w;
979  
980 if ( defined $this_color
981 and $this_color ne $empty_string )
982 {
983 my $flow_color = $this_color;
984  
985 # print("color_flow, color=$flow_color; this_color=$this_color\n");
986  
987 $this_flow_listbox_color_w = $color_flow_href->{$_flow_listbox_color_w};
988  
989 }
990 else {
991 print("color_flow, _get_flow_listbox_color_w, missing color\n");
992 }
993  
994 return ($this_flow_listbox_color_w);
995  
996 }
997  
998 =head2 sub _move_in_stored_flows
999  
1000 move program names,
1001 parameter names, values and checkbutton setttings
1002 --- these are stored separately (via param_flows.pm)
1003 from GUI widgets (via flow_widgets.pm)
1004 The flow-widgets is a single copy of names and values
1005 that constantly changes as the uses interacts with the GUI
1006 The param-flows stores several program (items) and their
1007 names and values
1008  
1009 =cut
1010  
1011 sub _move_in_stored_flows {
1012 my ($self) = @_;
1013  
1014 $color_flow_href->{_index2move} = $flow_widgets->index2move();
1015 $color_flow_href->{_destination_index} = $flow_widgets->destination_index();
1016  
1017 my $start = $color_flow_href->{_index2move};
1018 my $end = $color_flow_href->{_destination_index};
1019 print("color_flow move_in_stored_flows,start index is the $start\n");
1020 print("color_flow move_in_stored_flows, insertion index is $end \n");
1021  
1022 $param_flow_color_pkg->set_insert_start($start);
1023 $param_flow_color_pkg->set_insert_end($end);
1024 $param_flow_color_pkg->insert_selection();
1025  
1026 return ();
1027 }
1028  
1029 =head2 sub _SaveAs_button
1030  
1031 topic: only for 'SaveAs'
1032 for safety, place set_hash_ref first
1033
1034 CASE #1 considered:
1035 Flow_selection is forced during _add2flow
1036  
1037 CASE #2
1038 if the previous items have not been directly selected with sub flow_select
1039 they will not have been updated since loading into the GUI
1040 if user made changes to the paramters but the flow was not selected
1041 via flow_select (directly by the user) the flow parameters are not correct
1042  
1043 =cut
1044  
1045 sub _SaveAs_button {
1046 my ($topic) = @_;
1047  
1048 if ( $topic eq 'SaveAs' ) {
1049  
1050 my $files_LSU = files_LSU->new();
1051  
1052 # Start refocus index in flow, in case focus has been removed
1053 # e.g., by double-clicking in parameter values window
1054 my $most_recent_flow_index_touched =
1055 ( $color_flow_href->{_flow_select_index_href} )->{_most_recent};
1056 my $prior_flow_index_touched =
1057 ( $color_flow_href->{_flow_select_index_href} )->{_prior};
1058 my $most_recent_flow_color =
1059 ( $color_flow_href->{_flow_select_color_href} )->{_most_recent};
1060 my $last_flow_index = $most_recent_flow_index_touched;
1061  
1062 # print("1 OLD save, last_flow_color is: $color_flow_href->{_last_flow_color} \n");
1063 # print("1 OLD save, last_flow_index is: $color_flow_href->{_last_flow_index} \n");
1064  
1065 # print("1 save_button, most_recent_flow_index is: $most_recent_flow_index_touched\n");
1066 # print("1 save_button, pior_flow_index is: $prior_flow_index_touched\n");
1067  
1068 # print("1 color_flow, _SaveAs_button, new save, last_flow_color is: $most_recent_flow_color \n");
1069  
1070 # print("_SaveAs_button, view stored data in param flow3\n");
1071 # $param_flow_color_pkg->view_data();
1072  
1073 $gui_history->set_hash_ref($color_flow_href);
1074 $gui_history->set4_start_of_SaveAs_button();
1075  
1076 my $num_items = $param_flow_color_pkg->get_num_items();
1077  
1078 $color_flow_href->{_names_aref} =
1079 $param_flow_color_pkg->get_names_aref();
1080  
1081 $param_flow_color_pkg->set_good_values();
1082 $param_flow_color_pkg->set_good_labels();
1083  
1084 # collect information to be saved in a perl flow
1085 $color_flow_href->{_good_labels_aref2} =
1086 $param_flow_color_pkg->get_good_labels_aref2();
1087 $color_flow_href->{_items_versions_aref} =
1088 $param_flow_color_pkg->get_flow_items_version_aref();
1089 $color_flow_href->{_good_values_aref2} =
1090 $param_flow_color_pkg->get_good_values_aref2();
1091 $color_flow_href->{_prog_names_aref} =
1092 $param_flow_color_pkg->get_flow_prog_names_aref();
1093  
1094 my $num_items4flow = scalar @{ $color_flow_href->{_good_labels_aref2} };
1095  
1096 # for (my $i=0; $i < $num_items4flow; $i++ ) {
1097 # @{@{$color_flow_href->{_good_labels_aref2}}[$i]}\n");
1098 # }
1099  
1100 # for (my $i=0; $i < $num_items4flow; $i++ ) {
1101 # print("color_flow,_SaveAs_button, _good_values_aref2,
1102 # @{@{$color_flow_href->{_good_values_aref2}}[$i]}\n");
1103 # }
1104 # print("color_flow,_prog_versions_aref,
1105 # @{$color_flow_href->{_items_versions_aref}}\n");
1106  
1107 $files_LSU->set_prog_param_labels_aref2($color_flow_href);
1108 $files_LSU->set_prog_param_values_aref2($color_flow_href);
1109 $files_LSU->set_prog_names_aref($color_flow_href);
1110 $files_LSU->set_items_versions_aref($color_flow_href);
1111 $files_LSU->set_data();
1112 $files_LSU->set_message($color_flow_href);
1113  
1114 # listbox color assignment
1115 $files_LSU->set_flow_color($this_color);
1116  
1117 # update PL_SEISMIC in case user has recently changed project area
1118 $files_LSU->set_PL_SEISMIC();
1119  
1120 # flows saved to PL_SEISMIC
1121 $files_LSU->set2pl($color_flow_href);
1122 $files_LSU->save();
1123  
1124 $gui_history->set4_end_of_SaveAs_button(); # sets: _has_used_SaveAs=true
1125 $color_flow_href = $gui_history->get_hash_ref();
1126  
1127 return ();
1128  
1129 }
1130 else {
1131 print("color_flow,_SaveAs_button, missing topic\n");
1132 }
1133 }
1134  
1135 =head2 sub _perl_flow_errors
1136 Based on _perl_flow
1137 Parse (while reading) perl flows
1138  
1139 =cut
1140  
1141 sub _perl_flow_errors {
1142  
1143 my ($self) = @_;
1144  
1145 my $result;
1146  
1147 # instantiate modules
1148 my $perl_flow = perl_flow->new();
1149 my $param_sunix = param_sunix->new();
1150  
1151 # messages
1152 my $message = $message_director->null_button(0);
1153 $message_w->delete( "1.0", 'end' );
1154 $message_w->insert( 'end', $message );
1155  
1156 # should be at start of color_flow
1157 $color_flow_href->{_flow_type} = $flow_type->{_user_built};
1158 my $flow_name_in_color = $color_flow_href->{$_flow_name_in_color};
1159  
1160 my $flow_color = $color_flow_href->{_flow_color};
1161  
1162 # read in variables from the perl flow file
1163 $perl_flow->set_perl_file_in($flow_name_in_color);
1164 my $is_error = $perl_flow->get_parse_errors();
1165  
1166 $result = $is_error;
1167  
1168 return ($result);
1169 }
1170  
1171 =head2 sub _perl_flow
1172 Parse (while reading) perl flows
1173  
1174 foreach my $key (sort keys %$color_flow_href) {
1175 print (" color_flowkey is $key, value is $color_flow_href->{$key}\n");
1176 }
1177 my $length = scalar @{$all_values_aref};
1178 print("color_flow,perl_flow, length = $length\n");
1179
1180 for (my $j=0; $j <$length; $j++) {
1181 print("color_flow,perl_flow,name & value:@{$all_names_aref}[$j] = @{$all_values_aref}[$j]\n");
1182  
1183 }
1184
1185 =cut
1186  
1187 sub _perl_flow {
1188 my ($self) = @_;
1189  
1190 # instantiate modules
1191 my $perl_flow = perl_flow->new();
1192 my $param_sunix = param_sunix->new();
1193  
1194 # messages
1195 my $message = $message_director->null_button(0);
1196 $message_w->delete( "1.0", 'end' );
1197 $message_w->insert( 'end', $message );
1198  
1199 # should be at start of color_flow
1200 $color_flow_href->{_flow_type} = $flow_type->{_user_built};
1201 my $flow_name_in_color = $color_flow_href->{$_flow_name_in_color};
1202  
1203 my $flow_color = $color_flow_href->{_flow_color};
1204  
1205 # read in variables from the perl flow file
1206 $perl_flow->set_perl_file_in($flow_name_in_color);
1207 $perl_flow->parse();
1208  
1209 # clear all signs in GUI and wipe all the memory spaces
1210 # associated with the contents in the flow listbox that is about to
1211 # be occupied
1212 _clear_color_flow();
1213  
1214 my $num_prog_names = $perl_flow->get_num_prog_names();
1215  
1216 if ( length $num_prog_names ) {
1217  
1218 for ( my $prog_idx = 0 ; $prog_idx < $num_prog_names ; $prog_idx++ ) {
1219  
1220 # collect info. from perl file
1221 $perl_flow->set_prog_index($prog_idx);
1222 $color_flow_href->{_prog_name_sref} =
1223 $perl_flow->get_prog_name_sref();
1224 $color_flow_href->{_names_aref} = $perl_flow->get_all_names_aref();
1225 $color_flow_href->{_values_aref} =
1226 $perl_flow->get_all_values_aref();
1227 $color_flow_href->{_check_buttons_settings_aref} =
1228 $perl_flow->get_check_buttons_settings_aref();
1229  
1230 # establish which program is active in the flow 7.10.21
1231 $control->set_flow_program_name_sref(
1232 $color_flow_href->{_prog_name_sref} );
1233 $control->set_flow_prog_name_index(0);
1234  
1235 # remove quotes upon input
1236 $color_flow_href->{_values_aref} =
1237 $control->get_no_quotes4array( $color_flow_href->{_values_aref} );
1238  
1239 # add single quotes upon input only to strings
1240 $color_flow_href->{_values_aref} =
1241 $control->get_string_or_number4aref(
1242 $color_flow_href->{_values_aref} );
1243  
1244 $perl_flow->set_prog_index($prog_idx);
1245 my $number_of_values = scalar @{ $color_flow_href->{_values_aref} };
1246  
1247 $color_flow_href->{_param_sunix_length} =
1248 $perl_flow->get_param_sunix_length();
1249  
1250 my $values_aref = $color_flow_href->{_values_aref};
1251  
1252 # print("2. color_flow,_perl_flow, values = @$values_aref \n");
1253  
1254 # Populate GUI with the parameter values and labels of the first item
1255 # _add2flow will call _flow_select to select the last flow item loaded
1256 # _flow select marks the gui history and calls
1257 # flow_select which will detect any parameter changes
1258 # and will store
1259 # upload variables into the param_flow for each program
1260  
1261 _add2flow();
1262 }
1263  
1264 _flow_select_director('_perl_flow');
1265  
1266 # flow loading and display is complete
1267 # print("1. color_flow, _perl_flow, print out gui_history\n");
1268 # $gui_history->view();
1269  
1270 return ();
1271  
1272 }
1273 else {
1274 print("$this_color flow is missing the number of programs in a flow\n");
1275 }
1276  
1277 }
1278  
1279 =head2 sub _set_flow_color
1280  
1281  
1282 =cut
1283  
1284 sub _set_flow_color {
1285 my ($flow_color) = @_;
1286  
1287 if ($flow_color) {
1288  
1289 $color_flow_href->{_flow_color} = $flow_color;
1290  
1291 }
1292 else {
1293 print("color_flow, set_flow_color, missing color\n");
1294 }
1295 return ();
1296 }
1297  
1298 =head2 sub _local_set_flow_listbox_color_w
1299  
1300  
1301 =cut
1302  
1303 sub _local_set_flow_listbox_color_w {
1304 my ($flow_color) = @_;
1305  
1306 if ( $flow_color eq $this_color ) {
1307  
1308 $color_flow_href->{_flow_listbox_color_w} =
1309 $color_flow_href->{$_flow_listbox_color_w};
1310  
1311 }
1312 else {
1313 print(
1314 "color_flow,_local_set_flow_listbox_color_w, _local_set_flow_listbox_color_w, missing color\n"
1315 );
1316 }
1317  
1318 return ();
1319 }
1320  
1321 =head2 sub _set_flow_name_color_w
1322  
1323 =cut
1324  
1325 sub _set_flow_name_color_w {
1326 my ($flow_color) = @_;
1327  
1328 # print(
1329 # "color_flow,_set_flow_name_color_w, flow_color,this_color: $flow_color,$this_color \n"
1330 # );
1331 if ( $flow_color eq $this_color ) {
1332  
1333 $flow_name_color_w = $color_flow_href->{$_flow_name_color_w};
1334  
1335 # do not export
1336 $flow_name_color_w = $color_flow_href->{$_flow_name_color_w};
1337  
1338 }
1339 else {
1340 print(
1341 "color_flow,_set_flow_name_color_w, _set_flow_name_color_w, missing color \n"
1342 );
1343 }
1344  
1345 return ();
1346 }
1347  
1348 =head2 sub _set_flowNsuperflow_name_w
1349  
1350 displays superflow name at top of gui
1351
1352 =cut
1353  
1354 sub _set_flowNsuperflow_name_w {
1355 my ($flowNsuperflow_name) = @_;
1356  
1357 if ( $flowNsuperflow_name
1358 && $color_flow_href->{_flowNsuperflow_name_w} )
1359 {
1360  
1361 ( $color_flow_href->{_flowNsuperflow_name_w} )
1362 ->configure( -text => $flowNsuperflow_name, );
1363 }
1364 else {
1365 print(
1366 "color_flow, set_flowNsuperflow_name_w, missing widget or program name\n"
1367 );
1368 }
1369  
1370 return ();
1371 }
1372  
1373 =head2 sub _set_user_built_flow_name_w
1374  
1375 place and show the user-built flow name
1376  
1377 =cut
1378  
1379 sub _set_user_built_flow_name_w {
1380 my ($user_built_flow_name) = @_;
1381  
1382 if ($user_built_flow_name) {
1383  
1384 if ($flow_name_color_w) {
1385  
1386 # do not export
1387 $flow_name_color_w = $flow_name_color_w;
1388  
1389 # display name in widget
1390 $flow_name_color_w->configure( -text => $user_built_flow_name, );
1391  
1392 }
1393 elsif ( not $flow_name_color_w ) {
1394  
1395 _set_flow_name_color_w($flow_color);
1396  
1397 # do not export
1398 $flow_name_color_w = $flow_name_color_w;
1399  
1400 # display name in widget
1401 $flow_name_color_w->configure( -text => $user_built_flow_name, );
1402  
1403 }
1404 else {
1405 print(
1406 "color_flow, set_user_built_flow_name_w, missing flow_name_color_w \n"
1407 );
1408 }
1409 }
1410 else {
1411 print("color_flow, set_user_built_flow_name_w, missing program name\n");
1412 }
1413  
1414 return ();
1415 }
1416  
1417 =head2 sub _stack_flow
1418  
1419 store an initial version of the parameters in a
1420 namespace different to the one belonging to param_widgets
1421
1422 The initial version comes from default parameter files
1423 i.e., the same code as for sunix_select
1424
1425 print("color_flow,_stack_flow, color_flow_href->{_values_aref} =@{$color_flow_href->{_values_aref}} \n");
1426
1427 =cut
1428  
1429 sub _stack_flow {
1430 my ($self) = @_;
1431  
1432 # my $num_items = $param_flow_color_pkg->get_num_items();
1433 # print("color_flow,_stack_flow, data before stack num_items=$num_items\n");
1434 # $param_flow_color_pkg->view_data();
1435  
1436 $param_flow_color_pkg->stack_flow_item(
1437 $color_flow_href->{_prog_name_sref} );
1438  
1439 $param_flow_color_pkg->stack_names_aref2( $color_flow_href->{_names_aref} );
1440  
1441 # print("color_flow,_stack_flow, color_flow_href->{_names_aref} =@{$color_flow_href->{_names_aref}} \n");
1442  
1443 # when used for very first time in a GUI the index can be < 0
1444 # control->set_flow_prog_name_index takes care of this situation
1445 my $most_recent_flow_index_touched =
1446 ( $color_flow_href->{_flow_select_index_href} )->{_most_recent};
1447  
1448 # print("color_flow,_stack_flow, most_recent_flow_index_touched = $most_recent_flow_index_touched\n");
1449  
1450 $color_flow_href->{_prog_names_aref} =
1451 $param_flow_color_pkg->get_flow_prog_names_aref();
1452 $control->set_flow_prog_names_aref( $color_flow_href->{_prog_names_aref} );
1453 $control->set_flow_prog_name_index($most_recent_flow_index_touched);
1454  
1455 # restore strings to have terminal strings
1456 # remove quotes upon input
1457 $color_flow_href->{_values_aref} =
1458 $control->get_no_quotes4array( $color_flow_href->{_values_aref} );
1459  
1460 # in case parameter values have been displayed stringless
1461 $color_flow_href->{_values_aref} =
1462 $control->get_string_or_number4aref( $color_flow_href->{_values_aref} );
1463  
1464 # print("color_flow,_stack_flow, color_flow_href->{_names_aref} =@{$color_flow_href->{_values_aref}} \n");
1465  
1466 $param_flow_color_pkg->stack_values_aref2(
1467 $color_flow_href->{_values_aref} );
1468  
1469 $param_flow_color_pkg->stack_checkbuttons_aref2(
1470 $color_flow_href->{_check_buttons_settings_aref} );
1471  
1472 # my $num_items = $param_flow_color_pkg->get_num_items();
1473 # print("color_flow,_stack_flow, data after stack num_items=$num_items\n");
1474 # $param_flow_color_pkg->view_data();
1475  
1476 return ();
1477  
1478 } # end _stack_flow
1479  
1480 =head2 sub _stack_versions
1481  
1482 Collect and store latest program versions from changed list
1483
1484 Will update listbox variables inside flow_widgets.pm
1485 Therefore pop is not needed on the array
1486 Use after data have been stored, deleted, or
1487 suffered an insertion event
1488  
1489 =cut
1490  
1491 sub _stack_versions {
1492  
1493 my $_flow_listbox_color_w = _get_flow_listbox_color_w();
1494  
1495 $flow_widgets->set_flow_items($_flow_listbox_color_w);
1496 $color_flow_href->{_items_versions_aref} =
1497 $flow_widgets->items_versions_aref;
1498 $param_flow_color_pkg->set_flow_items_version_aref(
1499 $color_flow_href->{_items_versions_aref} );
1500  
1501 }
1502  
1503 =head2 _updateNsave_most_recent_param_flow
1504  
1505 update parameter values of the most recently touched
1506 program in the flow
1507  
1508 print(
1509 "1. START color_flow, _updateNsave_most_recent_param_flow, prior_flow_index=$prior, most_recent=$most_recent\n"
1510 );
1511 print(
1512 "color_flow, START _updateNsave_most_recent_param_flow, view param flow stored data:\n"
1513 );
1514  
1515  
1516 =cut
1517  
1518 sub _updateNsave_most_recent_param_flow {
1519  
1520 my ($self) = @_;
1521  
1522 my $last_parameter_index_on_entry;
1523 my $last_parameter_index_touched_color;
1524 my $most_recent_flow_index_touched;
1525 my $prior_flow_index_touched;
1526  
1527 $prior_flow_index_touched =
1528 ( $color_flow_href->{_flow_select_index_href} )->{_prior};
1529 $most_recent_flow_index_touched =
1530 ( $color_flow_href->{_flow_select_index_href} )->{_most_recent};
1531 my $_flow_listbox_color_w = _get_flow_listbox_color_w();
1532  
1533 =pod
1534  
1535 hash remains partially undefined in gui_history.pm
1536  
1537 =cut
1538  
1539 if (
1540 not(
1541 defined(
1542 (
1543 $color_flow_href->{_parameter_index_on_entry_click_seq_href}
1544 )->{_most_recent}
1545 )
1546 )
1547 )
1548 {
1549 ( $color_flow_href->{_parameter_index_on_entry_click_seq_href} )
1550 ->{_most_recent} = -1;
1551 my $value =
1552 ( $color_flow_href->{_parameter_index_on_entry_click_seq_href} )
1553 ->{_most_recent};
1554  
1555 }
1556 if (
1557 not(
1558 defined(
1559 ( $color_flow_href->{_parameter_index_on_exit_click_seq_href} )
1560 ->{_most_recent}
1561 )
1562 )
1563 )
1564  
1565 {
1566 ( $color_flow_href->{_parameter_index_on_exit_click_seq_href} )
1567 ->{_most_recent} = -1;
1568 my $value =
1569 ( $color_flow_href->{_parameter_index_on_exit_click_seq_href} )
1570 ->{_most_recent};
1571  
1572 # print("color_flow,_updateNsave_most_recent_param_flow, undefined 2 is: $value\n");
1573 }
1574  
1575 =pod
1576  
1577 The following two values = -1 (default) until a
1578 second program is placed in the flow
1579
1580 =cut
1581  
1582 $last_parameter_index_on_entry =
1583 ( $color_flow_href->{_parameter_index_on_entry_click_seq_href} )
1584 ->{_most_recent};
1585 $last_parameter_index_touched_color =
1586 ( $color_flow_href->{_parameter_index_on_exit_click_seq_href} )
1587 ->{_most_recent};
1588  
1589 my $prior_flow_color =
1590 ( $color_flow_href->{_flow_select_color_href} )->{_prior};
1591 my $most_recent_flow_color =
1592 ( $color_flow_href->{_flow_select_color_href} )->{_most_recent};
1593  
1594 my $storage_flow_index = $most_recent_flow_index_touched;
1595  
1596 =pod To update parameters in the most recent flow
1597 at least one program item must exist
1598 =cut
1599  
1600 my $num_flow_items = $flow_widgets->get_num_items($_flow_listbox_color_w);
1601  
1602 # print("color_flow, _updateNsave_most_recent_param_flow, num flow items= $num_flow_items\n");
1603  
1604 if (
1605 (
1606 $most_recent_flow_index_touched >= 0
1607 or $last_parameter_index_touched_color >= 0
1608 )
1609 and $num_flow_items > 0
1610 )
1611 {
1612  
1613 # prior flow must have the same color as the current one or
1614 # we have just clicked an sunix program (neutral-flow case)
1615 if ( $prior_flow_color eq $neutral
1616 or $prior_flow_color eq $most_recent_flow_color )
1617 {
1618 my $most_recent =
1619 ( ( $gui_history->get_defaults() )->{_flow_select_index_href} )
1620 ->{_most_recent};
1621 my $prior =
1622 ( ( $gui_history->get_defaults() )->{_flow_select_index_href} )
1623 ->{_prior};
1624  
1625 # the checkbuttons, values and names of ONLY the last program used
1626 # are stored in param_widgets at any ONE time
1627 $color_flow_href->{_values_aref} =
1628 $param_widgets->get_values_aref();
1629  
1630 # establish which program is active in the flow-- for control
1631 $color_flow_href->{_prog_names_aref} =
1632 $param_flow_color_pkg->get_flow_prog_names_aref();
1633 $control->set_flow_prog_names_aref(
1634 $color_flow_href->{_prog_names_aref} );
1635 $control->set_flow_prog_name_index($most_recent);
1636  
1637 # restore terminal ticks in strings after reading from the GUI
1638 # remove possible terminal strings
1639 $color_flow_href->{_values_aref} =
1640 $control->get_no_quotes4array( $color_flow_href->{_values_aref} );
1641  
1642 # in case parameter values have been displayed stringless
1643 $color_flow_href->{_values_aref} =
1644 $control->get_string_or_number4aref(
1645 $color_flow_href->{_values_aref} );
1646 $color_flow_href->{_names_aref} = $param_widgets->get_labels_aref();
1647 $color_flow_href->{_check_buttons_settings_aref} =
1648 $param_widgets->get_check_buttons_settings_aref();
1649  
1650 $param_flow_color_pkg->set_flow_index($storage_flow_index);
1651  
1652 # The following 3 lines save old changed values and names but not the versions
1653 $param_flow_color_pkg->set_values_aref(
1654 $color_flow_href->{_values_aref} );
1655  
1656 # print(
1657 # "99. color flow,leaving _updateNsave_most_recent_param_flow \n"
1658 # );
1659 # $param_flow_color_pkg->view_data();
1660  
1661 $param_flow_color_pkg->set_names_aref(
1662 $color_flow_href->{_names_aref} );
1663 $param_flow_color_pkg->set_check_buttons_settings_aref(
1664 $color_flow_href->{_check_buttons_settings_aref} );
1665  
1666 $param_widgets->set_entry_change_status($false)
1667 ; # changes are now complete, needwd??
1668 $color_flow_href->{_last_flow_color} =
1669 $color_flow_href->{_flow_color};
1670  
1671 $most_recent =
1672 ( ( $gui_history->get_defaults() )->{_flow_select_index_href} )
1673 ->{_most_recent};
1674 $prior =
1675 ( ( $gui_history->get_defaults() )->{_flow_select_index_href} )
1676 ->{_prior};
1677  
1678 # print(
1679 # "1. END color_flow, _updateNsave_most_recent_param_flow, prior_flow_index=$prior, most_recent=$most_recent\n"
1680 # );
1681  
1682 }
1683 else {
1684  
1685 #NADA
1686 }
1687 }
1688 else {
1689 }
1690  
1691 return ();
1692 }
1693  
1694 =head2 _update_prior_param_flow
1695  
1696 Updates the values for parameters stored via param_flow
1697 param-flow takes uses parameters from param_widgets
1698 BUT param_widgets needs to have been updated by _update_most_recent_flow? or
1699 user changes on the screen will not have been updated
1700  
1701 Apply every time that a flow item is selected
1702 1. Assume that selection of a flow item implies pre-existing parameter values were changed/added
1703
1704 2. Opening a file dialog assumes parameter values were also changed (Entry widget)
1705 -- this means that a prior program must have been touched and that the color must change
1706 from either neutral to the current color or be overwritten by the same color
1707
1708 Exceptions include the
1709 (1) case when you have just left a flow of a different color
1710 and are returning to previous settings.
1711 (2) case when you are using the first item in a flow for the first time, i.e. it has never been
1712 used before
1713
1714 Find out the previous color, then ... there are
1715 2 possible CASES
1716 CASE 1
1717 The current color is the same as the previously touched color
1718 i.e., if the last color-flow box touched was of the current flow color
1719 i.e., consider situation when we are still using the same colored list box
1720
1721 in which case...
1722 1. Find out which index was touched in "color"-flow box
1723 2. Find out which program was previously touched
1724 3. Assume the touched program had its parameter values modified
1725 4. Update all the previously touched program's values in storage via param_flow
1726
1727 CASE 2
1728 If the current color is different to the previously touched color, then
1729 2. ELIMINATE all the previous changes
1730
1731 Clicking Save will activate _update_prior_param_flow.
1732 Before Save is clicked:
1733 the
1734 _last_parameter_index_touched_color = 0
1735 _last_flow_index_touched = -1
1736 _last_flow_color = current flow color
1737
1738
1739 print("1. color_flow, _update_prior_param_flow, start\n");
1740 $param_flow_color_pkg->view_data();
1741  
1742 # print("2. color_flow, _update_prior_param_flow, print gui_history.txt\n");
1743 # $gui_history->view();
1744
1745 deprecated 1.23.23
1746 if ( $prior_flow_color eq $neutral
1747 or $prior_flow_color eq $most_recent_flow_color )
1748  
1749
1750
1751 print(
1752 "color_flow,_update_prior_param_flow,prior_color_flow = $prior_flow_color\n"
1753 );
1754 print("2 color_flow, _update_prior_param_flow, start\n");
1755 $param_flow_color_pkg->view_data();
1756  
1757 print(
1758 "3. color_flow,_update_prior_param_flow,names, color_flow: @{$color_flow_href->{_names_aref}}\n"
1759 );
1760 print(
1761 "3.color_flow,_update_prior_param_flow,values, color_flow: @{$color_flow_href->{_values_aref}}\n"
1762 );
1763 print(
1764 "3.color_flow,_update_prior_param_flow,n, param_widgets:@{$param_widgets->get_labels_aref()}\n"
1765 );
1766 print(
1767 "3.color_flow,_update_prior_param_flow,values, param_widgets:@{$param_widgets->get_values_aref()}\n"
1768 );
1769 print("1. color_flow,_update_prior_param_flow, prior_flow and storage index=$storage_flow_index\n");
1770 print("color_flow,_update_prior_param_flow,most_recent_flow_index=$most_recent_flow_index_touched\n");
1771
1772 print("4.color flow,_update_prior_param_flow \n");
1773 $param_flow_color_pkg->view_data();
1774 =cut
1775  
1776 sub _update_prior_param_flow {
1777  
1778 my ($self) = @_;
1779  
1780 my $prior_item_exists = $false;
1781 my $_flow_listbox_color_w =
1782 _get_flow_listbox_color_w(); # user-built_flow in current use
1783  
1784 my $prior_flow_index_touched =
1785 ( $color_flow_href->{_flow_select_index_href} )->{_prior};
1786 my $most_recent_flow_index_touched =
1787 ( $color_flow_href->{_flow_select_index_href} )->{_most_recent};
1788  
1789 # following two values are empty until a second program is placed in the flow
1790 my $last_parameter_index_on_entry =
1791 ( $color_flow_href->{_parameter_index_on_entry_click_seq_href} )
1792 ->{_most_recent};
1793 my $last_parameter_index_touched_color =
1794 ( $color_flow_href->{_parameter_index_on_exit_click_seq_href} )
1795 ->{_most_recent};
1796 my $prior_flow_color =
1797 ( $color_flow_href->{_flow_select_color_href} )->{_prior};
1798 my $most_recent_flow_color =
1799 ( $color_flow_href->{_flow_select_color_href} )->{_most_recent};
1800 my $storage_flow_index = $prior_flow_index_touched;
1801 my $prior_flow_select = ( $color_flow_href->{_button_href} )->{_prior};
1802  
1803 # get number of items in the flow listbox
1804 # prior program must exist
1805 if ( $prior_flow_index_touched <=
1806 $flow_widgets->get_num_items($_flow_listbox_color_w) )
1807 {
1808  
1809 $prior_item_exists = $true;
1810  
1811 }
1812 else {
1813 print("color_flow,_update_prior_param_flow, missing prior item\n");
1814 }
1815  
1816 if (
1817 (
1818 $most_recent_flow_index_touched >= 0
1819 or $last_parameter_index_touched_color >= 0
1820 )
1821 and $prior_item_exists
1822 )
1823 {
1824  
1825 if ( $prior_flow_select eq $sunix_select
1826 and $prior_flow_color eq $most_recent_flow_color )
1827 {
1828  
1829 print(
1830 "4.color flow,_update_prior_param_flow, prior_flow_select=$prior_flow_select \n"
1831 );
1832  
1833 # CASE 1 prior flow must have been an sunix program
1834 # so ignore the param_widgets that were just displayed
1835 # NADA
1836  
1837 }
1838 elsif ( $prior_flow_color eq $most_recent_flow_color ) {
1839  
1840 # CASE 2 prior flow must have the same color as the current one
1841 # but sunix_select was not previously selected
1842  
1843 # the checkbuttons, values and names of ONLY the last program used
1844 # are stored in param_widgets at any ONE time
1845 $color_flow_href->{_values_aref} =
1846 $param_widgets->get_values_aref();
1847  
1848 # establish which program is active in the flow--for control
1849 $color_flow_href->{_prog_names_aref} =
1850 $param_flow_color_pkg->get_flow_prog_names_aref();
1851 $control->set_flow_prog_names_aref(
1852 $color_flow_href->{_prog_names_aref} );
1853 $control->set_flow_prog_name_index($most_recent_flow_index_touched);
1854  
1855 # restore terminal ticks in strings after reading from the GUI
1856 # remove possible terminal strings
1857 $color_flow_href->{_values_aref} =
1858 $control->get_no_quotes4array( $color_flow_href->{_values_aref} );
1859  
1860 # correct parameter values that have been displayed stringless
1861 $color_flow_href->{_values_aref} =
1862 $control->get_string_or_number4aref(
1863 $color_flow_href->{_values_aref} );
1864  
1865 # collect checkbuttons, names from what is currently in the gui
1866 $color_flow_href->{_names_aref} = $param_widgets->get_labels_aref();
1867 $color_flow_href->{_check_buttons_settings_aref} =
1868 $param_widgets->get_check_buttons_settings_aref();
1869  
1870 # The following 3 lines save old changed values and names but not the versions
1871 $param_flow_color_pkg->set_values_aref(
1872 $color_flow_href->{_values_aref} );
1873 $param_flow_color_pkg->set_names_aref(
1874 $color_flow_href->{_names_aref} );
1875 $param_flow_color_pkg->set_check_buttons_settings_aref(
1876 $color_flow_href->{_check_buttons_settings_aref} );
1877 $param_flow_color_pkg->set_flow_index($storage_flow_index);
1878  
1879 $param_widgets->set_entry_change_status($false)
1880 ; # changes are now complete, needwd??
1881 $color_flow_href->{_last_flow_color} =
1882 $color_flow_href->{_flow_color};
1883  
1884 }
1885 else {
1886 #NADA
1887 }
1888 }
1889 else {
1890 }
1891  
1892 return ();
1893 }
1894  
1895 =head2 _save_most_recent_param_flow
1896
1897 Force to save flow parameters to param_flow
1898
1899 We assume that the program of interest within an active flow stays the same.
1900 Nevertheless that a parameter within a fixed program has changed so that
1901 the stored parameters for that program need to be updated. (TODO??)
1902 That is, param_flow will update the stored parameters for a member of the flow
1903 without having to change the flow item/program with which we interact.
1904
1905 The checkbuttons, values and names of only the present program in use
1906 are stored in param_widgets at any one time
1907
1908 After selecting a data file name, the file name is automatically inserted
1909 into the GUI. Following, we update the data file name into the stored parameters via param_flow
1910
1911 $last_parameter_index_touched_color must =0 or > 0
1912 but does exist and means the parameters are untouched
1913
1914 =cut
1915  
1916 sub _save_most_recent_param_flow {
1917  
1918 my ($self) = @_;
1919  
1920 my $prior_flow_index_touched =
1921 ( $color_flow_href->{_flow_select_index_href} )->{_prior};
1922 my $most_recent_flow_index_touched =
1923 ( $color_flow_href->{_flow_select_index_href} )->{_most_recent};
1924 my $storage_flow_index = $most_recent_flow_index_touched;
1925  
1926 # The following two values are empty until a second program is placed in the flow
1927 my $last_parameter_index_on_entry =
1928 ( $color_flow_href->{_parameter_index_on_entry_href} )->{_most_recent};
1929 my $last_parameter_index_touched_color =
1930 ( $color_flow_href->{_parameter_index_on_exit_href} )->{_most_recent};
1931  
1932 # print("color_flow _save_most_recent_param_flow ,last changed entry index was $last_parameter_index_touched_color \n");
1933 # print("2. color_flow, _save_most_recent_param_flow , print gui_history.txt\n");
1934 # $gui_history->view();
1935  
1936 # my $prior_flow_color = ( $color_flow_href->{_flow_select_color_href} )->{_prior};
1937 # my $most_recent_flow_color = ( $color_flow_href->{_flow_select_color_href} )->{_most_recent};
1938  
1939 if ( $last_parameter_index_touched_color >= 0 ) {
1940  
1941 # Update names and check_buttons again, while reading in from the GUI ( via param_widgets)
1942 $color_flow_href->{_names_aref} = $param_widgets->get_labels_aref();
1943 $color_flow_href->{_check_buttons_settings_aref} =
1944 $param_widgets->get_check_buttons_settings_aref();
1945 $color_flow_href->{_values_aref} = $param_widgets->get_values_aref();
1946  
1947 # establish which program is active in the flow
1948 $color_flow_href->{_prog_names_aref} =
1949 $param_flow_color_pkg->get_flow_prog_names_aref();
1950 $control->set_flow_prog_names_aref(
1951 $color_flow_href->{_prog_names_aref} );
1952 $control->set_flow_prog_name_index($most_recent_flow_index_touched);
1953  
1954 # restore terminal ticks in strings after reading from the GUI
1955 # remove possible terminal strings
1956 $color_flow_href->{_values_aref} =
1957 $control->get_no_quotes4array( $color_flow_href->{_values_aref} );
1958  
1959 # print(
1960 # "color_flow, _save_most_recent_param_flow, param_widgets->get_values_aref():@{$color_flow_href->{_values_aref}}\n"
1961 # );
1962 # in case parameter values have been displayed stringless
1963 $color_flow_href->{_values_aref} = $control->get_string_or_number4aref(
1964 $color_flow_href->{_values_aref} );
1965  
1966 # print(
1967 # "3B. color_flow, _save_most_recent_param_flow,color_flow_href->{_values_aref}=
1968 # @{$color_flow_href->{_values_aref}}\n");
1969  
1970 # Use flow item index of the program in the color-flow listbox that is currently being used,
1971 # i.e., not the index of the last-used program ut the current
1972 # user-built_flow.
1973 my $_flow_listbox_color_w = _get_flow_listbox_color_w();
1974  
1975 if ( $storage_flow_index >= 0 ) {
1976  
1977 # select an item from which to extract data
1978 $param_flow_color_pkg->set_flow_index($storage_flow_index);
1979  
1980 # save current values, names and check buttons BUT not the versions
1981 $param_flow_color_pkg->set_values_aref(
1982 $color_flow_href->{_values_aref} );
1983 $param_flow_color_pkg->set_names_aref(
1984 $color_flow_href->{_names_aref} );
1985 $param_flow_color_pkg->set_check_buttons_settings_aref(
1986 $color_flow_href->{_check_buttons_settings_aref} );
1987 $param_widgets->set_entry_change_status($false)
1988 ; # changes are now complete
1989  
1990 # print(
1991 # "1912 End of $this_color _save_most_recent_param_flow: _last_parameter_index_touched reset:
1992 # $color_flow_href->{_last_parameter_index_touched_color}\n"
1993 # );
1994  
1995 }
1996 else {
1997  
1998 # Look for the last flow index that was touched
1999 my $last_idx_chng = $storage_flow_index;
2000 $param_flow_color_pkg->set_flow_index($last_idx_chng);
2001  
2002 # save current values, names and check buttons BUT not the versions
2003 $param_flow_color_pkg->set_values_aref(
2004 $color_flow_href->{_values_aref} );
2005 $param_flow_color_pkg->set_names_aref(
2006 $color_flow_href->{_names_aref} );
2007 $param_flow_color_pkg->set_check_buttons_settings_aref(
2008 $color_flow_href->{_check_buttons_settings_aref} );
2009 $param_widgets->set_entry_change_status($false)
2010 ; # changes are now complete
2011  
2012 # print(
2013 # "1656 End of $this_color _save_most_recent_param_flow: _last_parameter_index_touched reset: $color_flow_href->{_last_parameter_index_touched_color}\n"
2014 # );
2015  
2016 }
2017  
2018 }
2019 else {
2020  
2021 # print("color_flow,_save_most_recent_param-flow,NADA \n");
2022 }
2023  
2024 return ();
2025 }
2026  
2027 =head2 sub FileDialog_button
2028  
2029 Handles Data, SaveAs and (perl) Open (in) or Delete
2030 May provide values from the current widget if it is used.
2031 Can also be (1) a previous pre-built superflow that is already in the GUI
2032 or 2) empty if program is just starting
2033  
2034 dialog type (option_sref) can be:
2035 Data,
2036 Open (open an exisiting user-built flow, but not a pre-built
2037 superflow), or
2038 SaveAs
2039
2040 Delete ( a file or any type, default $PL_SEISMIC)
2041
2042 my $uBF = $file_dialog->get_hash_ref();
2043 foreach my $key (sort keys %$uBF) {
2044 print (" color_flowkey is $key, value is $uBF->{$key}\n");
2045 }
2046
2047 =cut
2048  
2049 sub FileDialog_button {
2050  
2051 my ( $self, $dialog_type_sref ) = @_;
2052  
2053 my $file_dialog_type = $L_SU_global_constants->file_dialog_type_href();
2054 my $PL_SEISMIC = $Project->PL_SEISMIC();
2055  
2056 if ($dialog_type_sref) {
2057  
2058 $color_flow_href->{_dialog_type} =
2059 $$dialog_type_sref; # dereference scalar
2060 my $topic = $color_flow_href->{_dialog_type};
2061  
2062 if ( $topic eq $file_dialog_type->{_SaveAs} ) {
2063  
2064 # print("color_flow, L_SU,FileDialog_button, ONLY for SaveAs\n");
2065 # i.e., in this module, dialog_type_sref can only be SaveAs
2066 # Save for 'user-built flows' is accessible via L_SU.pm
2067  
2068 my $most_recent_flow_index_touched =
2069 ( $color_flow_href->{_flow_select_index_href} )->{_most_recent};
2070  
2071 $color_flow_href->{_values_aref} =
2072 $param_widgets->get_values_aref();
2073  
2074 # establish which program is active in the flow
2075 $color_flow_href->{_prog_names_aref} =
2076 $param_flow_color_pkg->get_flow_prog_names_aref();
2077 $control->set_flow_prog_names_aref(
2078 $color_flow_href->{_prog_names_aref} );
2079 $control->set_flow_prog_name_index($most_recent_flow_index_touched);
2080  
2081 # restore strings to have terminal strings
2082 # remove quotes upon input
2083 $color_flow_href->{_values_aref} =
2084 $control->get_no_quotes4array( $color_flow_href->{_values_aref} );
2085  
2086 # in case parameter values have been displayed stringless
2087 $color_flow_href->{_values_aref} =
2088 $control->get_string_or_number4aref(
2089 $color_flow_href->{_values_aref} );
2090  
2091 $color_flow_href->{_dialog_type} =
2092 $$dialog_type_sref; # dereference scalar
2093  
2094 $file_dialog->set_flow_color( $color_flow_href->{_flow_color} );
2095 $file_dialog->set_hash_ref($color_flow_href);
2096 $file_dialog->FileDialog_director();
2097  
2098 $color_flow_href->{_has_used_SaveAs_button} = $true;
2099  
2100 # new file name will generate a case that an index has been touched
2101 $color_flow_href->{_last_parameter_index_touched_color} =
2102 $file_dialog->get_last_parameter_index_touched_color();
2103  
2104 # print ("1. color_flow,FileDialog_button,_last_parameter_index_touched_color:$color_flow_href->{_last_parameter_index_touched_color} \n");
2105 # print ("1. color_flow,FileDialog_button, color: $flow_color \n");
2106 $color_flow_href->{$_is_last_parameter_index_touched_color} = $true;
2107  
2108 _save_most_recent_param_flow();
2109  
2110 $color_flow_href->{$_flow_name_out_color} =
2111 file_dialog->get_perl_flow_name_out();
2112 $color_flow_href->{_path} = file_dialog->get_file_path();
2113  
2114 # consider empty case, for which saving is not possible
2115 if ( !( $color_flow_href->{$_flow_name_out_color} )
2116 || $color_flow_href->{$_flow_name_out_color} eq ''
2117 || !( $color_flow_href->{_path} )
2118 || $color_flow_href->{_path} eq '' )
2119 {
2120  
2121 my $message = $message_director->save_button(1);
2122 $message_w->delete( "1.0", 'end' );
2123 $message_w->insert( 'end', $message );
2124  
2125 }
2126 else {
2127  
2128 # CASE: NON-EMPTY and good
2129  
2130 # displays user-built flow name at top of color-flow gui
2131 _set_flowNsuperflow_name_w(
2132 $color_flow_href->{$_flow_name_out_color} );
2133 _set_user_built_flow_name_w(
2134 $color_flow_href->{$_flow_name_out_color} );
2135  
2136 # go save perl flow file
2137 _SaveAs_button($topic);
2138  
2139 # print("color_flow,FileDialog_button, saving the perl file\n");
2140  
2141 # restore message at the bottom of the string to blank if not already so
2142 # messages
2143 my $message = $message_director->null_button(0);
2144 $message_w->delete( "1.0", 'end' );
2145 $message_w->insert( 'end', $message );
2146  
2147 } # Ends SaveAs option
2148  
2149 }
2150 elsif ( $topic eq $file_dialog_type->{_Open} ) {
2151  
2152 # 1. Read perl flow file
2153 # 2. Write name to the file name in the appropriate flow
2154 # 3. populate GUI
2155 # 4. populate hashes (color_flow)and memory spaces (param_flow)
2156 # 5. Make sure to clean prior information from the FileDialog Button such as file names.
2157 # 6. save moment all this is done in gui_history
2158  
2159 $file_dialog->set_flow_color( $color_flow_href->{_flow_color} );
2160 $file_dialog->set_hash_ref($color_flow_href); # uses values_aref
2161 $file_dialog->set_flow_type('user_built');
2162  
2163 $file_dialog->FileDialog_director();
2164  
2165 $color_flow_href->{$_flow_name_in_color} =
2166 $file_dialog->get_perl_flow_name_in();
2167  
2168 # print("color_flow, flow_name_in = $color_flow_href->{$_flow_name_in_color}\n");
2169 $color_flow_href->{$_flow_name_out_color} =
2170 $color_flow_href->{$_flow_name_in_color};
2171  
2172 # print("color_flow,color_flow_href->{_has_used_open_perl_file_button}=$color_flow_href->{_has_used_open_perl_file_button}\n");
2173  
2174 # Is $flow_name_in empty?
2175 my $file2query =
2176 $PL_SEISMIC . '/' . $color_flow_href->{$_flow_name_in_color};
2177 $color_flow->{_Flow_file_exists} =
2178 $manage_files_by2->does_file_exist_sref( \$file2query );
2179  
2180 # Are there any errors when reading the perl flow file
2181 $color_flow->{_perl_flow_errors} = _perl_flow_errors();
2182  
2183 if ( $color_flow->{_Flow_file_exists}
2184 && $color_flow->{_perl_flow_errors} eq $false )
2185 {
2186  
2187 _set_flow_name_color_w($flow_color);
2188  
2189 # Place names of the programs at the top of the color listbox
2190 $flow_name_color_w->configure(
2191 -text => $color_flow_href->{$_flow_name_in_color} );
2192  
2193 # Place names of the programs at the head of the GUI
2194 $color_flow_href->{_flowNsuperflow_name_w}->configure(
2195 -text => $color_flow_href->{_big_stream_name_in} );
2196  
2197 # populate gui, and bot param_flow and param_widgets namespaces
2198 _perl_flow();
2199  
2200 }
2201 else {
2202 # print(" color_flow,FileDialog_button, perl flow parse errors\n");
2203 # print("3 color_flow,FileDialog_button, Warning: missing file. \"Cancel\" clicked by user? NADA\n");
2204 }
2205  
2206 }
2207 elsif ( $topic eq $file_dialog_type->{_Data} ) {
2208  
2209 # print("color_flow, FileDialog_button,option_sref $topic\n");
2210 # assume that after selection to open of a data file in file-dialog the
2211 # GUI has been updated
2212 # See if the last parameter index has been touched (>= 0)
2213 # Assume we are still dealing with the current flow item selected
2214 $color_flow_href->{_last_parameter_index_touched_color} =
2215 $file_dialog->get_last_parameter_index_touched_color();
2216 $color_flow_href->{$_is_last_parameter_index_touched_color} = $true;
2217  
2218 # set the current listbox as the last color listbox
2219 $color_flow_href->{_last_flow_listbox_color_w} =
2220 $color_flow_href->{_flow_listbox_color_w};
2221  
2222 # provide values in the current widget
2223 $color_flow_href->{_values_aref} =
2224 $param_widgets->get_values_aref();
2225  
2226 my $most_recent_flow_index_touched =
2227 ( $color_flow_href->{_flow_select_index_href} )->{_most_recent};
2228  
2229 # restore terminal ticks to strings
2230  
2231 # establish which program is active in the flow
2232 $color_flow_href->{_prog_names_aref} =
2233 $param_flow_color_pkg->get_flow_prog_names_aref();
2234 $control->set_flow_prog_names_aref(
2235 $color_flow_href->{_prog_names_aref} );
2236 $control->set_flow_prog_name_index($most_recent_flow_index_touched);
2237  
2238 # restore strings to have terminal strings
2239 # remove quotes upon input
2240 $color_flow_href->{_values_aref} =
2241 $control->get_no_quotes4array( $color_flow_href->{_values_aref} );
2242  
2243 # in case parameter values have been displayed stringless
2244 $color_flow_href->{_values_aref} =
2245 $control->get_string_or_number4aref(
2246 $color_flow_href->{_values_aref} );
2247  
2248 # print(
2249 # "color_flow,FileDialog_button(binding), flow_listbox_color_w: $color_flow_href->{_flow_listbox_color_w} \n"
2250 # );
2251 $file_dialog->set_flow_color( $color_flow_href->{_flow_color} );
2252 $file_dialog->set_hash_ref($color_flow_href);
2253 $file_dialog->FileDialog_director();
2254  
2255 # print(
2256 # "color_flow,FileDialog_button(binding), last_parameter_index_touched_color: $color_flow_href->{_last_parameter_index_touched_color} \n"
2257 # );
2258  
2259 # update to parameter values occurs in file_dialog
2260 $color_flow_href->{_values_aref} = $file_dialog->get_values_aref();
2261  
2262 # set up this flow listbox item as the last item touched
2263 my $_flow_listbox_color_w =
2264 _get_flow_listbox_color_w(); # user-built_flow in current use
2265 my $current_flow_listbox_index =
2266 $flow_widgets->get_flow_selection($_flow_listbox_color_w);
2267  
2268 # $color_flow_href->{_last_flow_index_touched} =
2269 # $current_flow_listbox_index; # for next time
2270 # $color_flow_href->{$_is_last_flow_index_touched_color} = $true;
2271  
2272 # print("color_flow,FileDialog_button(binding), last_flow_index_touched:$color_flow_href->{_last_flow_index_touched} \n");
2273  
2274 # Changes made with another instance of param_widgets (in file_dialog) will require
2275 # that we also update the namespace of the current param_flow
2276 # We make this change inside _save_most_recent_param_flow
2277 _save_most_recent_param_flow();
2278  
2279 }
2280 else {
2281 print("1. color_flow, FileDialog_button, missing topic \n");
2282  
2283 # Ends opt_ref
2284 }
2285 }
2286 else {
2287 print("color_flow,FileDialog_button ,option type missing\n");
2288 }
2289  
2290 return ();
2291 }
2292  
2293 =head2 sub add2flow_button
2294  
2295 When build a first-time perl flow
2296 Incorporate new prorgam parameter values and labels into the gui
2297 and save the values, labels and checkbuttons setting in the param_flow
2298 namespace
2299  
2300 foreach my $key (sort keys %$color_flow_href) {
2301 print (" color_flow key is $key, value is $color_flow_href->{$key}\n");
2302 }
2303
2304 $ans= $color_flow_href->{_param_sunix_length};
2305 print("1b. color_flow, add2flow_button, _param_sunix_length= $ans\n");
2306  
2307 =cut
2308  
2309 sub add2flow_button {
2310  
2311 my ( $self, $value ) = @_;
2312  
2313 # $color_flow_href->{_names_aref} = $param_widgets->get_labels_aref();
2314 # print("start add2flow_button all label0 = @{$color_flow_href->{_names_aref}}[0]\n");
2315 # print("start add2flow_buttonall label1 = @{$color_flow_href->{_names_aref}}[1]\n");
2316 # $color_flow_href->{_values_aref} = $param_widgets->get_values_aref();
2317 # print("start add2flow_buttonall value0 = @{$color_flow_href->{_values_aref}}[0]\n");
2318 # print("start add2flow_buttonall value1 = @{$color_flow_href->{_values_aref}}[1]\n");
2319  
2320 # There is a case when a flow is used for the first time, when
2321 # a parameter value has been added or
2322 # modified and the flow item
2323 # is not selected manually after a change (using select_flow_button)
2324 # If a previous flow item has not been updated
2325 # we must force an update to save these first-time, new, parameter values
2326 # by using _flow_select (which calls flow_select).
2327 # When we are coming from selecting an sunix program
2328 # the flow listbox has been cleared of selections
2329 # The last flow listbox selection was stored in the gui history
2330 # We can not set flow_select button index
2331 # We will increment the number of clicks
2332 # (TODO) and that you have not changed color
2333 my $_flow_listbox_color_w = _get_flow_listbox_color_w();
2334 my $flow_num_items = $_flow_listbox_color_w->size();
2335  
2336 $color_flow_href->{_flow_type} = $flow_type->{_user_built};
2337  
2338 my $param_sunix = param_sunix->new();
2339 my $message = $message_director->null_button(0);
2340  
2341 $gui_history->set_hash_ref($color_flow_href);
2342 $gui_history->set4start_of_add2flow_button($flow_color);
2343 $color_flow_href = $gui_history->get_hash_ref();
2344  
2345 $message_w->delete( "1.0", 'end' );
2346 $message_w->insert( 'end', $message );
2347  
2348 # add the most recently selected program
2349 # name (scalar reference) to the
2350 # end of the list inside flow_listbox
2351 _local_set_flow_listbox_color_w($flow_color); # in "color"_flow namespace
2352  
2353 # append new program names to the end of the list but this item is NOT selected
2354 # selection occurs inside conditions4flow (inheritance by gui_history)
2355 $color_flow_href->{_flow_listbox_color_w}
2356 ->insert( "end", ${ $color_flow_href->{_prog_name_sref} }, );
2357  
2358 # Display default paramters in the GUI,
2359 # as for sunix_select
2360 # Can not get program name from the item selected in the sunix list box
2361 # because focus is transferred to another list box
2362  
2363 my $most_recent =
2364 ( ( $gui_history->get_defaults() )->{_flow_select_index_href} )
2365 ->{_most_recent};
2366 my $prior =
2367 ( ( $gui_history->get_defaults() )->{_flow_select_index_href} )->{_prior};
2368  
2369 # print("1. color_flow, add2flow_button, NO CHANGES within: prior_flow_index=$prior, most_recent=$most_recent\n");
2370  
2371 # print("1. color_flow, add2flow_button, print out gui_history\n");
2372 # $gui_history->view();
2373  
2374 # TBD
2375 # if there is a deletion immediately before, the
2376 # indices for recent and prior should be reduced by -1
2377 # the most recent value will be correct but
2378 # the prior and earliest will not
2379 # so always check that the prior value exists before using it
2380  
2381 $param_sunix->set_program_name( $color_flow_href->{_prog_name_sref} );
2382 $color_flow_href->{_names_aref} = $param_sunix->get_names();
2383 $color_flow_href->{_values_aref} = $param_sunix->get_values();
2384 $color_flow_href->{_check_buttons_settings_aref} =
2385 $param_sunix->get_check_buttons_settings();
2386 $color_flow_href->{_param_sunix_first_idx} =
2387 $param_sunix->first_idx(); # first index = 0
2388 $color_flow_href->{_first_idx} =
2389 $param_sunix->first_idx(); # first index = 0
2390  
2391 # print("color_flow,add2flow_button, check_buttons_settings_aref: @{$color_flow_href->{_check_buttons_settings_aref}}\n");
2392  
2393 $param_sunix->set_half_length();
2394  
2395 # values -- not #(values+labels)
2396 $color_flow_href->{_param_sunix_length} = $param_sunix->get_length();
2397  
2398 # widgets are initialized in a super class
2399 # Assign program parameters in the GUI
2400 $param_widgets->set_labels_w_aref( $color_flow_href->{_labels_w_aref} );
2401 $param_widgets->set_values_w_aref( $color_flow_href->{_values_w_aref} );
2402 $param_widgets->set_check_buttons_w_aref(
2403 $color_flow_href->{_check_buttons_w_aref} );
2404  
2405 # print(" 1. color_flow, add2flow_button, \n");
2406 $param_widgets->range($color_flow_href);
2407 $param_widgets->set_labels( $color_flow_href->{_names_aref} );
2408 $param_widgets->set_values( $color_flow_href->{_values_aref} );
2409 $param_widgets->set_check_buttons(
2410 $color_flow_href->{_check_buttons_settings_aref} );
2411  
2412 $param_widgets->redisplay_labels();
2413 $param_widgets->redisplay_values();
2414 $param_widgets->redisplay_check_buttons();
2415  
2416 # Collect and store prog versions changed in list box
2417 _stack_versions();
2418  
2419 # Add a single_program to the growing stack
2420 # store one program name, its associated parameters and their values
2421 # as well as the checkbuttons settings (on or off) in another namespace
2422 _stack_flow();
2423  
2424 # print("color_flow,add2flow_button, after stack flow but before update\n");
2425 # $param_flow_color_pkg->view_data();
2426  
2427 $gui_history->set_hash_ref($color_flow_href);
2428  
2429 # last item added is highlighted and selected conditions4flows are inherited by gui_hsitory
2430 $gui_history->set4end_of_add2flow_button($flow_color);
2431  
2432 my $flow_index = $flow_widgets->get_flow_selection(
2433 $color_flow_href->{_flow_listbox_color_w} );
2434  
2435 # done in conditions4flow, flow color is not reset
2436 $gui_history->set_flow_index_last_touched($flow_index);
2437 $color_flow_href = $gui_history->get_hash_ref();
2438  
2439 # switch between the correct index of the last parameter that was touched
2440 # as a function of the flow's color
2441 # These data are encapsulated
2442 $color_flow_href->{_last_parameter_index_touched_color} = 0; # initialize
2443 $color_flow_href->{$_is_last_parameter_index_touched_color} = $true;
2444  
2445 # print("10 color_flow,add2flow_button, after stack flow AND after update, view param_flow data:\n");
2446 # $param_flow_color_pkg->view_data();
2447  
2448 _flow_select_director('add2flow_button');
2449  
2450 # the following is also carried out in flow_select when pre_ok=true
2451 # $color_flow_href->{_last_flow_color} = $flow_color;
2452 return ();
2453 }
2454  
2455 =head2 sub delete_from_flow_button
2456  
2457 if flow_select was last clicked then
2458 $gui_history has already recorded the chosen flow color
2459  
2460 my $flow_color = $gui_history->get_flow_color();
2461
2462 =cut
2463  
2464 sub delete_from_flow_button {
2465  
2466 my ($self) = @_;
2467  
2468 my $flow_color =
2469 ( $color_flow_href->{_flow_select_color_href} )->{_most_recent};
2470  
2471 if ($flow_color) {
2472  
2473 _set_flow_color($flow_color);
2474  
2475 my $message = $message_director->null_button(0);
2476 $message_w->delete( "1.0", 'end' );
2477 $message_w->insert( 'end', $message );
2478  
2479 my $_flow_listbox_color_w = _get_flow_listbox_color_w();
2480  
2481 $gui_history->set_hash_ref($color_flow_href);
2482 $gui_history->set_defaults4start_of_delete_from_flow_button(
2483 $flow_color);
2484 $color_flow_href = $gui_history->get_hash_ref();
2485  
2486 $decisions->set4delete_from_flow_button($color_flow_href);
2487 my $pre_req_ok = $decisions->get4delete_from_flow_button();
2488  
2489 # confirm listboxes are active
2490 if ($pre_req_ok) {
2491  
2492 # location within GUI on first clicking delete button
2493 # $gui_history->set_hash_ref($color_flow_href);
2494  
2495 # flow_color is in 'color'_flow namespace
2496 my $index =
2497 $flow_widgets->get_flow_selection($_flow_listbox_color_w);
2498  
2499 if ( $index == 0
2500 and $param_flow_color_pkg->get_num_items() == 1 )
2501 {
2502  
2503 # CASE: LAST ITEM in listbox is deleted
2504 # extra checking includes verifying number of items
2505  
2506 # For Run and Save button
2507 $flow_widgets->delete_selection($_flow_listbox_color_w);
2508  
2509 # Blank out the names of the programs in the GUI
2510 _set_flow_name_color_w($flow_color);
2511 $flow_name_color_w->configure( -text => $var->{_clear_text} );
2512 $color_flow_href->{_flowNsuperflow_name_w}
2513 ->configure( -text => $var->{_clear_text} );
2514  
2515 # delete stored programs and their parameters
2516 my $index2delete = $flow_widgets->get_index2delete();
2517  
2518 # delete_from_stored_flows();
2519 $param_flow_color_pkg->delete_selection($index2delete);
2520  
2521 # collect and store latest program versions from changed list
2522 # clear all the versions from the changed list
2523 _clear_stack_versions();
2524  
2525 $gui_history->set_hash_ref($color_flow_href);
2526 $gui_history->set_defaults4last_delete_from_flow_button();
2527 $color_flow_href = $gui_history->get_hash_ref();
2528  
2529 # Blank out all the stored parameter values and names within param_flow
2530 $param_flow_color_pkg->clear();
2531  
2532 # clear the parameter values and labels from the gui
2533 # strange memory leak inside param_widgets
2534 my $save =
2535 clone( $color_flow_href->{_check_buttons_settings_aref} );
2536 $param_widgets->gui_full_clear();
2537 @{ $color_flow_href->{_check_buttons_settings_aref} } = @$save;
2538  
2539 # reinitialize flow_select_count
2540 $gui_history->set_clear('delete_from_flow_button');
2541 @{ $color_flow_href->{_occupied_listbox_aref} }
2542 [$_number_from_color] = $false;
2543 @{ $color_flow_href->{_vacant_listbox_aref} }
2544 [$_number_from_color] = $true;
2545  
2546 # print("1.color_flow, delete_from_flow_button, \n
2547 # color_flow_href->{_occupied_listbox_aref}[_number_from_color]= $color_flow_href->{_occupied_listbox_aref}[$_number_from_color]
2548 # \n");
2549 # print("1.color_flow, delete_from_flow_button, \n
2550 # color_flow_href->{_vacant_listbox_aref}[_number_from_color]= $color_flow_href->{_vacant_listbox_aref}[$_number_from_color]
2551 # \n");
2552 # print("1. last item deleted Shut down delete button\n");
2553  
2554 }
2555 elsif ( $index > 0 ) {
2556  
2557 # CASE more more than one item remains in a listbox (implied)
2558 # but selected index is not the first
2559 $flow_widgets->delete_selection($_flow_listbox_color_w);
2560  
2561 # delete stored programs and their parameters
2562 # delete_from_stored_flows();
2563 my $index2delete = $flow_widgets->get_index2delete();
2564  
2565 # print("2. color_flow deletefrom a stored flow,index2delete:$index2delete\n");
2566 $param_flow_color_pkg->delete_selection($index2delete);
2567  
2568 # keep track of flow selection clicks and colors
2569 $_flow_listbox_color_w->selectionSet( ( $index2delete - 1 ) );
2570 $gui_history->set_flow_select_color($this_color);
2571 $gui_history->set_button('flow_select');
2572  
2573 # Update the widget parameter names and values
2574 # to those of new selection after deletion
2575 # Only the chkbuttons, values and names of the last program used
2576 # are stored in param_widgets at any one time
2577 # Get parameters from storage
2578 my $next_idx_selected_after_deletion = $index2delete - 1;
2579 if ( $next_idx_selected_after_deletion == -1 ) {
2580 $next_idx_selected_after_deletion = 0;
2581 } # NOT < 0
2582 # $next_idx_selected_after_deletion\n");
2583  
2584 $param_flow_color_pkg->set_flow_index(
2585 $next_idx_selected_after_deletion);
2586 $color_flow_href->{_names_aref} =
2587 $param_flow_color_pkg->get_names_aref();
2588  
2589 $color_flow_href->{_values_aref} =
2590 $param_flow_color_pkg->get_values_aref();
2591  
2592 $color_flow_href->{_check_buttons_settings_aref} =
2593 $param_flow_color_pkg->get_check_buttons_settings();
2594  
2595 # get stored first index and num of items
2596 $color_flow_href->{_param_flow_first_idx} =
2597 $param_flow_color_pkg->first_idx();
2598 $color_flow_href->{_param_flow_length} =
2599 $param_flow_color_pkg->length();
2600 $color_flow_href->{_prog_name_sref} =
2601 $param_widgets->get_current_program(
2602 \$_flow_listbox_color_w );
2603 $param_widgets->set_current_program(
2604 $color_flow_href->{_prog_name_sref} );
2605  
2606 $param_widgets->gui_full_clear(); # formerly gui_clean
2607 $param_widgets->range($color_flow_href);
2608 $param_widgets->set_labels( $color_flow_href->{_names_aref} );
2609 $param_widgets->set_values( $color_flow_href->{_values_aref} );
2610 $param_widgets->set_check_buttons(
2611 $color_flow_href->{_check_buttons_settings_aref} );
2612  
2613 $param_widgets->redisplay_labels();
2614 $param_widgets->redisplay_values();
2615 $param_widgets->redisplay_check_buttons();
2616  
2617 # collect and store latest program versions from changed list
2618 _stack_versions();
2619  
2620 }
2621 elsif ( $index == 0
2622 and $param_flow_color_pkg->get_num_items() > 1 )
2623 {
2624  
2625 # CASE more than 1 item exists and selected index is first
2626 $flow_widgets->delete_selection($_flow_listbox_color_w);
2627  
2628 # delete stored programs and their parameters
2629 # delete_from_stored_flows();
2630 my $index2delete = $flow_widgets->get_index2delete();
2631  
2632 # print("2. color_flow delete_from_stored,index2delete:$index2delete\n");
2633 $param_flow_color_pkg->delete_selection($index2delete);
2634  
2635 # keep track of flow selection clicks and colors
2636 $_flow_listbox_color_w->selectionSet( ( $index2delete - 1 ) );
2637 $gui_history->set_flow_select_color($this_color);
2638 $gui_history->set_button('flow_select');
2639  
2640 # Update the widget parameter names and values
2641 # to those of new selection after deletion
2642 # Only the chekbuttons, values and names of the last program used
2643 # are stored in param_widgets at any one time
2644 # Get parameters from storage
2645 my $next_idx_selected_after_deletion = $index2delete - 1;
2646  
2647 # NOT < 0
2648 # $next_idx_selected_after_deletion\n");
2649 if ( $next_idx_selected_after_deletion == -1 ) {
2650  
2651 $next_idx_selected_after_deletion = 0;
2652 }
2653  
2654 $param_flow_color_pkg->set_flow_index(
2655 $next_idx_selected_after_deletion);
2656 $color_flow_href->{_names_aref} =
2657 $param_flow_color_pkg->get_names_aref();
2658  
2659 $color_flow_href->{_values_aref} =
2660 $param_flow_color_pkg->get_values_aref();
2661  
2662 $color_flow_href->{_check_buttons_settings_aref} =
2663 $param_flow_color_pkg->get_check_buttons_settings();
2664  
2665 # get stored first index and num of items
2666 $color_flow_href->{_param_flow_first_idx} =
2667 $param_flow_color_pkg->first_idx();
2668 $color_flow_href->{_param_flow_length} =
2669 $param_flow_color_pkg->length();
2670 $color_flow_href->{_prog_name_sref} =
2671 $param_widgets->get_current_program(
2672 \$_flow_listbox_color_w );
2673 $param_widgets->set_current_program(
2674 $color_flow_href->{_prog_name_sref} );
2675  
2676 #print(" 2. color_flow, delete_from-flow_button \n");
2677 $param_widgets->gui_full_clear(); # formerly gui_clean
2678 $param_widgets->range($color_flow_href);
2679 $param_widgets->set_labels( $color_flow_href->{_names_aref} );
2680 $param_widgets->set_values( $color_flow_href->{_values_aref} );
2681 $param_widgets->set_check_buttons(
2682 $color_flow_href->{_check_buttons_settings_aref} );
2683  
2684 $param_widgets->redisplay_labels();
2685 $param_widgets->redisplay_values();
2686 $param_widgets->redisplay_check_buttons();
2687  
2688 # collect and store latest program versions from changed list
2689 _stack_versions();
2690  
2691 }
2692 else {
2693 print("color_flow, delete_fro_flow_button unexpected result\n");
2694 }
2695 } # if pre_req_ok
2696  
2697 }
2698 else { # if flow_color
2699 print("color_flow, delete_from_flow_button, flow color missing: \n");
2700 }
2701  
2702 # print("color_flow, END delete_from_flow_button, print gui_history.txt\n");
2703 # $gui_history->view();
2704 }
2705  
2706 =head2 sub delete_whole_flow_button
2707  
2708 If flow_select was last clicked then
2709 $gui_history has already recorded the chosen flow color
2710
2711 =cut
2712  
2713 sub delete_whole_flow_button {
2714  
2715 my ($self) = @_;
2716  
2717 my $flow_color =
2718 ( $color_flow_href->{_flow_select_color_href} )->{_most_recent};
2719  
2720 # print(" START color_flow, delete_whole_flow_button, \n");
2721 # print("color_flow, delete_whole_flow_button, print gui_history.txt\n");
2722 # $gui_history->view();
2723  
2724 if ($flow_color) {
2725  
2726 _set_flow_color($flow_color);
2727  
2728 my $message = $message_director->null_button(0);
2729 $message_w->delete( "1.0", 'end' );
2730 $message_w->insert( 'end', $message );
2731  
2732 my $_flow_listbox_color_w = _get_flow_listbox_color_w();
2733  
2734 $gui_history->set_hash_ref($color_flow_href);
2735 $gui_history->set_defaults4start_of_delete_whole_flow_button(
2736 $flow_color);
2737 $color_flow_href = $gui_history->get_hash_ref();
2738 $decisions->set4delete_whole_flow_button($color_flow_href);
2739 my $pre_req_ok = $decisions->get4delete_whole_flow_button();
2740  
2741 # confirm listboxes are active
2742 if ($pre_req_ok) {
2743  
2744 # flow_color is in 'color'_flow namespace
2745 # index is the currently selected
2746 my $index =
2747 $flow_widgets->get_flow_selection($_flow_listbox_color_w);
2748  
2749 # print("color_flow, delete_whole_flow_button index=$index\n");
2750  
2751 if ( $index >= 0
2752 and $param_flow_color_pkg->get_num_items() >= 1 )
2753 {
2754  
2755 # CASE: DELETE ALL ITEMS in listbox
2756 # extra checking includes verifying number of items
2757 # For Run and Save button
2758 $flow_widgets->clear($_flow_listbox_color_w);
2759  
2760 # Blank out the names of the programs in the GUI
2761 _set_flow_name_color_w($flow_color);
2762 $flow_name_color_w->configure( -text => $var->{_clear_text} );
2763 $color_flow_href->{_flowNsuperflow_name_w}
2764 ->configure( -text => $var->{_clear_text} );
2765  
2766 # delete stored programs and all the stored flow parameters
2767 my $index2delete = 'all';
2768 $param_flow_color_pkg->delete_selection($index2delete);
2769  
2770 # Blank out all the stored parameter values and names within param_flow
2771 $param_flow_color_pkg->clear();
2772  
2773 $gui_history->set_hash_ref($color_flow_href);
2774 $gui_history->set_defaults4end_of_delete_whole_flow_button();
2775 $color_flow_href = $gui_history->get_hash_ref();
2776  
2777 # Blank out all the stored parameter values and names within param_flow
2778 $param_flow_color_pkg->clear();
2779  
2780 # print("5. whole flow deleted Shut down delete button\n");
2781 # clear the parameter values and labels from the gui
2782 # strange memory leak inside param_widgets
2783 my $save =
2784 clone( $color_flow_href->{_check_buttons_settings_aref} );
2785 $param_widgets->gui_full_clear();
2786 @{ $color_flow_href->{_check_buttons_settings_aref} } = @$save;
2787  
2788 # reinitialize flow_select_count
2789 $gui_history->set_clear('delete_whole_flow_button');
2790  
2791 }
2792 else {
2793 print(
2794 "color_flow, delete_whole_flow_button unexpected result\n");
2795 } # index is >= 0
2796  
2797 } # if pre_req_ok
2798  
2799 }
2800 else { # if flow_color
2801 print("color_flow, delete_whole_flow_button, flow color missing: \n");
2802 }
2803  
2804 }
2805  
2806 =head2 sub flow_item_down_arrow_button
2807  
2808 move items down in a flow listbox
2809
2810 =cut
2811  
2812 sub flow_item_down_arrow_button {
2813  
2814 my ($self) = @_;
2815 my $prog_name;
2816  
2817 if ($flow_color) {
2818  
2819 _set_flow_color($flow_color);
2820  
2821 # $conditions_gui->set4start_of_flow_item_down_arrow_button($color_flow_href);
2822  
2823 my $message = $message_director->null_button(0);
2824 $message_w->delete( "1.0", 'end' );
2825 $message_w->insert( 'end', $message );
2826  
2827 $prog_name = ${ $color_flow_href->{_prog_name_sref} };
2828  
2829 # get number of items in the flow listbox
2830 my $_flow_listbox_color_w =
2831 _get_flow_listbox_color_w(); # user-built_flow in current use
2832 my $num_items = $flow_widgets->get_num_items($_flow_listbox_color_w);
2833  
2834 # get the current index
2835 my $current_flow_listbox_index =
2836 $flow_widgets->get_flow_selection($_flow_listbox_color_w);
2837  
2838 # the destination index will be one more
2839 my $destination_index = $current_flow_listbox_index + 1;
2840  
2841 # limit max index
2842 if ( $destination_index >= $num_items ) {
2843 $destination_index = $num_items - 1;
2844 }
2845  
2846 # MEET THESE conditions, OR do NOTHING
2847 if ( $prog_name
2848 && ( $current_flow_listbox_index >= 0 )
2849 && $destination_index < $num_items )
2850 {
2851  
2852 $color_flow_href->{_index2move} = $current_flow_listbox_index;
2853 $color_flow_href->{_destination_index} = $destination_index;
2854  
2855 # get all the elements from inside the listbox
2856 my @elements = $_flow_listbox_color_w->get( 0, 'end' );
2857  
2858 # rearrange elements
2859 my $saved_item = $elements[ $color_flow_href->{_index2move} ];
2860  
2861 $color_flow_href->{_flow_listbox_color_w}
2862 ->delete( $color_flow_href->{_index2move} );
2863 $color_flow_href->{_flow_listbox_color_w}
2864 ->insert( $color_flow_href->{_destination_index}, $saved_item );
2865 $color_flow_href->{_flow_listbox_color_w}
2866 ->selectionSet( $color_flow_href->{_destination_index} );
2867  
2868 # note the last program that was touched
2869 # $color_flow_href->{_last_flow_index_touched} =
2870 # $color_flow_href->{_destination_index};
2871 # $color_flow_href->{$_is_last_flow_index_touched_color} = $true;
2872  
2873 # move stored data within arrays
2874 my $start = $color_flow_href->{_index2move};
2875 my $end = $color_flow_href->{_destination_index};
2876  
2877 $param_flow_color_pkg->set_insert_start($start);
2878 $param_flow_color_pkg->set_insert_end($end);
2879 $param_flow_color_pkg->insert_selection();
2880  
2881 # update program versions if listbox changes
2882 # stored in param_flows
2883 _stack_versions();
2884  
2885 # update the parameter widget labels and their values
2886  
2887 # highlight new index
2888 _local_set_flow_listbox_color_w($flow_color)
2889 ; # in "color"_flow namespace
2890 $_flow_listbox_color_w->selectionSet(
2891 $color_flow_href->{_destination_index}, );
2892  
2893 # carry out all gui updates needed
2894 # keep track of flow_selection clicks
2895 _flow_select_director('flow_item_down_arrow_button');
2896  
2897 }
2898 else {
2899 print(
2900 "color_flow, flow_item_down_arrow_button missing program or bad index\n"
2901 );
2902 }
2903  
2904 }
2905 else {
2906 print("color_flow, flow_item_down_arrow_button missing color \n");
2907 }
2908  
2909 }
2910  
2911 =head2 sub flow_item_up_arrow_button
2912  
2913 move items up in a flow listbox
2914
2915 =cut
2916  
2917 sub flow_item_up_arrow_button {
2918  
2919 my ($self) = @_;
2920 my $prog_name;
2921  
2922 if ($flow_color) {
2923  
2924 _set_flow_color($flow_color);
2925  
2926 # $conditions_gui->set4start_of_flow_item_up_arrow_button($color_flow_href);
2927  
2928 my $message = $message_director->null_button(0);
2929 $message_w->delete( "1.0", 'end' );
2930 $message_w->insert( 'end', $message );
2931  
2932 $prog_name = ${ $color_flow_href->{_prog_name_sref} };
2933  
2934 # get number of items in the flow listbox
2935 my $_flow_listbox_color_w =
2936 _get_flow_listbox_color_w(); # user-built_flow in current use
2937 my $num_items = $flow_widgets->get_num_items($_flow_listbox_color_w);
2938  
2939 # get the current index
2940 my $current_flow_listbox_index =
2941 $flow_widgets->get_flow_selection($_flow_listbox_color_w);
2942  
2943 # the destination index will be one less
2944 my $destination_index = $current_flow_listbox_index - 1;
2945 if ( $destination_index <= 0 ) {
2946 $destination_index = 0;
2947 } # limit min index
2948  
2949 # MEET THESE conditions, OR do NOTHING
2950 if ( $prog_name
2951 && ( $current_flow_listbox_index > 0 )
2952 && $destination_index >= 0 )
2953 {
2954  
2955 $color_flow_href->{_index2move} = $current_flow_listbox_index;
2956 $color_flow_href->{_destination_index} = $destination_index;
2957  
2958 # note the last program that was touched
2959 # $color_flow_href->{_last_flow_index_touched} =
2960 # $color_flow_href->{_destination_index};
2961 # $color_flow_href->{$_is_last_flow_index_touched_color} = $true;
2962  
2963 # get all the elements from inside the listbox
2964 my @elements = $_flow_listbox_color_w->get( 0, 'end' );
2965  
2966 # rearrange elements
2967 my $saved_item = $elements[ $color_flow_href->{_index2move} ];
2968  
2969 $color_flow_href->{_flow_listbox_color_w}
2970 ->delete( $color_flow_href->{_index2move} );
2971 $color_flow_href->{_flow_listbox_color_w}
2972 ->insert( $color_flow_href->{_destination_index}, $saved_item );
2973 $color_flow_href->{_flow_listbox_color_w}
2974 ->selectionSet( $color_flow_href->{_destination_index} );
2975  
2976 # note the last program that was touched
2977 # $color_flow_href->{_last_flow_index_touched} =
2978 # $color_flow_href->{_destination_index};
2979 # $color_flow_href->{$_is_last_flow_index_touched_color} = $true;
2980  
2981 # move stored data within arrays
2982 my $start = $color_flow_href->{_index2move};
2983 my $end = $color_flow_href->{_destination_index};
2984  
2985 $param_flow_color_pkg->set_insert_start($start);
2986 $param_flow_color_pkg->set_insert_end($end);
2987 $param_flow_color_pkg->insert_selection();
2988  
2989 # update program versions if listbox changes
2990 # stored in param_flows
2991 _stack_versions();
2992  
2993 # highlight new index
2994 $_flow_listbox_color_w->selectionSet(
2995 $color_flow_href->{_destination_index}, );
2996  
2997 # carry out all gui updates needed
2998 # keep track of flow_selection clicks
2999 _flow_select_director('flow_item_up_arrow_button');
3000  
3001 }
3002 else {
3003 }
3004  
3005 }
3006 else {
3007 print("color_flow, flow_item_up_arrow_button missing color \n");
3008 }
3009  
3010 }
3011  
3012 =head2 sub flow_select
3013  
3014 Pick a Seismic Unix module
3015 from within a (colored) flow listbox
3016
3017 Always takes focus on first entry ; index = 0
3018 If focus is on first entry then also make the
3019 $color_flow_href->{_last_parameter_index_touched_color} =0
3020  
3021 print(" flow_select, view stored param flow data before update of prior\n");
3022 $param_flow_color_pkg->view_data();
3023 my $ans = @{$color_flow_href->{_values_w_aref}}[0]->get;
3024  
3025 print("color_flow,flow_select, print gui_history\n");
3026 $gui_history->view();
3027  
3028 print("12color_flow, flow_select, extract saved values\n");
3029 $param_flow_color_pkg->view_data();
3030
3031 print(
3032 "1 color_flow, flow_select, num_items_in_flow =$num_items_in_flow\n"
3033 );
3034 print(
3035 "1 color_flow, flow_select, max_index_in_flow =$max_index_in_flow\n"
3036 );
3037 print(
3038 "1 color_flow, flow_select, most_recent_flow_index =$most_recent_flow_index\n"
3039 );
3040 print(
3041 "1 color_flow, flow_select, last_flow_color=$last_flow_color\n");
3042  
3043 print(
3044 "2 color_flow, flow_select, num_items_in_flow =$num_items_in_flow\n"
3045 );
3046 print(
3047 "2 color_flow, flow_select, max_index_in_flow =$max_index_in_flow\n"
3048 );
3049 print(
3050 "2 color_flow, flow_select, most_recent_flow_index =$most_recent_flow_index\n"
3051 );
3052 # $gui_history->set_file_status($num_items_in_flow);
3053 # gets click count?
3054 my $file_status = $gui_history->get_file_status();
3055 print( "3131 color_flow,flow_select,file_status,num_items_in_flow, last flow color:\n");
3056 print( "$file_status,$num_items_in_flow,$last_flow_color \n");
3057  
3058 $aref = $param_flow_color_pkg->get_values_aref();
3059 print("11a.color_flow,flow_select, values:@{$aref}\n");
3060
3061
3062 =cut
3063  
3064 sub flow_select {
3065 my ($self) = @_;
3066  
3067 # --- Phase 0: Initialize state and UI ---
3068 # Set flow type to user-built and sync current color into history
3069 $color_flow_href->{_flow_type} = $flow_type->{_user_built};
3070  
3071 # reset residual flow_listbox_color_w of another color
3072 # flow_color exists in current (color_flow) namespace
3073 _local_set_flow_listbox_color_w($flow_color);
3074 $gui_history->set_flow_select_color($flow_color);
3075  
3076 # Reset message panel
3077 my $message = $message_director->null_button(0);
3078 $message_w->delete( "1.0", 'end' );
3079 $message_w->insert( 'end', $message );
3080  
3081 # Share current hash state with gui_history and apply defaults
3082 $gui_history->set_hash_ref($color_flow_href);
3083 $gui_history->set_defaults_4start_of_flow_select($flow_color);
3084 $color_flow_href = $gui_history->get_hash_ref();
3085  
3086 # Determine the selected program from current color listbox
3087 my $_flow_listbox_color_w = _get_flow_listbox_color_w();
3088 $color_flow_href->{_prog_name_sref} =
3089 $flow_widgets->get_current_program( \$_flow_listbox_color_w );
3090  
3091 # Guard: prerequisites must pass before continuing
3092 $decisions->set_hash_ref($color_flow_href);
3093 my $pre_req_ok = $decisions->get4flow_select();
3094 return () unless $pre_req_ok;
3095  
3096 # --- Phase 1: Snapshot defaults / history once ---
3097 my $binding = binding->new();
3098 $gui_history->set_button('flow_select');
3099  
3100 my $defaults = $gui_history->get_defaults;
3101 my $prior_flow_type = $defaults->{_flow_type_href}->{_prior};
3102  
3103 my $prior_flow_select_color = $defaults->{_flow_select_color_href}->{_prior};
3104 my $most_recent_flow_select_color = $defaults->{_flow_select_color_href}->{_most_recent};
3105  
3106 my $most_recent_flow_index_touched = $color_flow_href->{_flow_select_index_href}->{_most_recent};
3107 my $max_saved_widget_index = scalar @save_last_param_widget_values;
3108  
3109 # print("3100. color_flow, flow_select, print out gui_history\n");
3110 # $gui_history->view();
3111  
3112 # --- Phase 2: Handle prior-state cases (1–4) ---
3113 # ==========================================================
3114 # CASE 1 Last click inside same-colored, user-built flow
3115 # Consider prior flow-color changes
3116 # that have been made to param_widgets but not updated
3117 # Unticked strings from GUI are corrected here
3118 # ==========================================================
3119  
3120 if ( $prior_flow_type eq $flow_type->{_user_built}
3121 and $most_recent_flow_select_color eq $prior_flow_select_color ) {
3122
3123 # CASE 1: Last click inside same-colored, user-built flow
3124 _update_prior_param_flow();
3125  
3126 # find which flow index is selected
3127 my $num_items_in_flow = $param_flow_color_pkg->get_num_items();
3128 my $max_index_in_flow = $num_items_in_flow - 1;
3129 $last_flow_color = $color_flow_href->{_last_flow_color};
3130  
3131 # Memory-correction logic only if not already fixed
3132 if ( not $memory_leak4flow_select_fixed ) {
3133  
3134 if ( ( $this_color eq $last_flow_color )
3135 && $most_recent_flow_index_touched == $max_index_in_flow )
3136 {
3137 # CASE 1A- NO memory correction needed
3138 # Last selected index was last in program
3139 # List and last color flow is the same as this color flow
3140 # e.g., just loaded a new flow and user clicks on last program
3141 # in flow
3142 $param_widgets->set_values(\@save_last_param_widget_values );
3143 $param_flow_color_pkg->set_flow_index($most_recent_flow_index_touched);
3144 $param_flow_color_pkg->set_values_aref(\@save_last_param_widget_values );
3145  
3146 } elsif ( ( $this_color eq $last_flow_color )
3147 && $most_recent_flow_index_touched < $max_index_in_flow
3148 )
3149  
3150 {
3151 # CASE 1B Fix memory loss when reselecting earlier index
3152 # When last selected index was last in program
3153 # list, last color flow is the same as this color flow
3154 # but index of current program is less than the last index
3155 # of the last program in the flow
3156  
3157 $param_flow_color_pkg->set_flow_index($max_index_in_flow);
3158 my $last_param_flow_values_w_strings_aref = $control->get_string_or_number4aref(
3159 \@save_last_param_widget_values );
3160  
3161 $param_flow_color_pkg->set_values_aref($last_param_flow_values_w_strings_aref);
3162  
3163 } # end of memory leak solution for flow_select
3164  
3165 $memory_leak4flow_select_fixed = $false;
3166 # print("3157 color_flow, flow_select, last click in same colored flow\n");
3167 }
3168 }
3169 elsif ( $prior_flow_type eq $flow_type->{_user_built}
3170 and $most_recent_flow_select_color ne $prior_flow_select_color ) {
3171
3172 # CASE 2: User-built, different colored flow
3173 print("3164 color_flow, flow_select, last click in different color flow; NADA\n");}
3174  
3175 elsif ( $prior_flow_type eq $flow_type->{_pre_built_superflow}
3176 and $most_recent_flow_select_color ne $prior_flow_select_color ){
3177  
3178 # CASE 3: Pre-built superflow, and a different colored flow
3179 print("3170 color_flow, flow_select, last click in different color flow; NADA\n");
3180 print("3171 color_flow, flow_select, last click was a superflow\n");
3181  
3182 } elsif ( $prior_flow_type eq $flow_type->{_pre_built_superflow}
3183 and $most_recent_flow_select_color eq $prior_flow_select_color ) {
3184  
3185 # CASE 4: Pre-built superflow, and SAME colored flow
3186 # Highlight last index
3187 $gui_history->set4superflow2user_flow_transition($flow_color);
3188 }
3189 else {
3190 # CASE 5: Undetermined
3191 print("3184 color_flow, flow_select, undetermined NADA\n");
3192 }
3193  
3194 # --- Phase 3: Update widget & GUI states
3195  
3196 # Current selection index in color flow listbox
3197 my $index = $flow_widgets->get_flow_selection($_flow_listbox_color_w);
3198  
3199 # Extract saved values and labels for the current selection
3200 $param_flow_color_pkg->set_flow_index($most_recent_flow_index_touched);
3201 $color_flow_href->{_names_aref} = $param_flow_color_pkg->get_names_aref();
3202 $color_flow_href->{_values_aref} = $param_flow_color_pkg->get_values_aref();
3203  
3204 $color_flow_href->{_check_buttons_settings_aref} = $param_flow_color_pkg->get_check_buttons_settings();
3205  
3206 # Get stored first index and num of items
3207 $color_flow_href->{_param_flow_first_idx} = $param_flow_color_pkg->first_idx();
3208 $color_flow_href->{_param_flow_length} =
3209 $param_flow_color_pkg->length();
3210  
3211 $param_widgets->set_current_program($color_flow_href->{_prog_name_sref} );
3212  
3213 # Widgets were initialized in super class
3214 # Prepare to update gui by assigning widgets
3215 # TODO are the next 3 lines needed now that we share gui_history?
3216 $param_widgets->set_labels_w_aref( $color_flow_href->{_labels_w_aref} );
3217 $param_widgets->set_values_w_aref( $color_flow_href->{_values_w_aref} );
3218 $param_widgets->set_check_buttons_w_aref($color_flow_href->{_check_buttons_w_aref} );
3219  
3220 $color_flow_href->{_prog_name_sref} =
3221 $flow_widgets->get_current_program( \$_flow_listbox_color_w );
3222  
3223 # Wipe out values labels and checkbuttons from GUI for a fresh redraw
3224 $param_widgets->range($color_flow_href);
3225  
3226 # Workaround for "strange memory leak" in param_widgets
3227 my $save = clone( $color_flow_href->{_check_buttons_settings_aref} );
3228 $param_widgets->gui_full_clear();
3229 @{ $color_flow_href->{_check_buttons_settings_aref} } = @$save;
3230  
3231 # Push data back into widgets and redraw
3232 $param_widgets->set_labels( $color_flow_href->{_names_aref} );
3233 $param_widgets->set_values( $color_flow_href->{_values_aref} );
3234 $param_widgets->set_check_buttons(
3235 $color_flow_href->{_check_buttons_settings_aref} );
3236 $param_widgets->redisplay_labels();
3237 $param_widgets->redisplay_values();
3238 $param_widgets->redisplay_check_buttons();
3239 $param_widgets->set_entry_change_status($false);
3240  
3241 # unxpectedly Entry focus is delayed until the end of this method before
3242 # completion;
3243 # that is we get to gui_history->view before we can update the focus
3244 # mysterious!!!!!
3245  
3246 # Focus first entry widget (index 0)
3247 $param_widgets->set_focus_on_Entry_w(0);
3248  
3249 # Here is where you rebind the different buttons depending on the
3250 # program name that is selected (i.e., through spec.pm)
3251 $binding->set_prog_name_sref( $color_flow_href->{_prog_name_sref} );
3252 $binding->set_values_w_aref( $param_widgets->get_values_w_aref );
3253  
3254 # Bind MB3 click to reference to a local subroutine
3255 $binding->setFileDialog_button_sub_ref( \&_FileDialog_button );
3256 $binding->set();
3257 $gui_history->set_hash_ref($color_flow_href);
3258 $gui_history->set4end_of_flow_select($flow_color);
3259 $gui_history->set_flow_index_last_touched($index);
3260 $color_flow_href = $gui_history->get_hash_ref();
3261  
3262 # Update thre entry button value displaying currently active
3263 # flow or superflow name. Use currently selected program name from the flow list
3264 # e.g. data_in, suximage, suxgraph etc.
3265 ( $color_flow_href->{_flowNsuperflow_name_w} )
3266 ->configure( -text => ${ $color_flow_href->{_prog_name_sref} } );
3267  
3268 # needed in possible export via get_hash_ref to help
3269 my $prog_name_sref = $color_flow_href->{_prog_name_sref};
3270  
3271 return ();
3272 }
3273  
3274 =head2 sub get_Flow_file_exists
3275  
3276 =cut
3277  
3278 sub get_Flow_file_exists {
3279 my ($self) = @_;
3280 my $result = $empty_string;
3281  
3282 if ( length $color_flow->{_Flow_file_exists} ) {
3283  
3284 $result = $color_flow->{_Flow_file_exists};
3285 return ($result);
3286  
3287 }
3288 else {
3289 print(" color_flow, get_Flow_file_exists, missing variable value\n");
3290 return ($result);
3291 }
3292  
3293 }
3294  
3295 =head2 sub get_hash_ref
3296 exports private hash
3297
3298 =cut
3299  
3300 sub get_hash_ref {
3301 my ($self) = @_;
3302  
3303 return ($color_flow_href);
3304  
3305 }
3306  
3307 =head2 sub get_flow_color
3308 exports private hash value
3309
3310 =cut
3311  
3312 sub get_flow_color {
3313 my ($self) = @_;
3314  
3315 if ( $color_flow_href->{_flow_color} ) {
3316 my $color;
3317  
3318 $color = $color_flow_href->{_flow_color};
3319 return ($color);
3320  
3321 }
3322 else {
3323 print("color_flow, missing flow color\n");
3324 }
3325  
3326 }
3327  
3328 =head2 sub get_flow_type
3329  
3330 exports private hash value
3331
3332 =cut
3333  
3334 sub get_flow_type {
3335 my ($self) = @_;
3336  
3337 if ( $color_flow_href->{_flow_type} ) {
3338 my $flow_type;
3339  
3340 $flow_type = $color_flow_href->{_flow_type};
3341 return ($flow_type);
3342  
3343 }
3344 else {
3345 print("color_flow, missing flow type\n");
3346 }
3347  
3348 }
3349  
3350 =head2 sub get_perl_flow_errors
3351  
3352 =cut
3353  
3354 sub get_perl_flow_errors {
3355 my ($self) = @_;
3356 my $result = $empty_string;
3357  
3358 if ( length $color_flow->{_perl_flow_errors} ) {
3359  
3360 $result = $color_flow->{_perl_flow_errors};
3361 return ($result);
3362  
3363 }
3364 else {
3365 print(" color_flow, get_perl_flow_errors, missing variable value\n");
3366 return ($result);
3367 }
3368 }
3369  
3370 =head2 sub get_prog_name_sref
3371  
3372 exports private hash value
3373
3374 =cut
3375  
3376 sub get_prog_name_sref {
3377 my ($self) = @_;
3378  
3379 if ( $color_flow_href->{_prog_name_sref} ) {
3380 my $name;
3381  
3382 $name = $color_flow_href->{_prog_name_sref};
3383 return ($name);
3384  
3385 }
3386 else {
3387 print("color_flow, missing \n");
3388 }
3389  
3390 }
3391  
3392 =head2 sub increase_vigil_on_delete_counter
3393  
3394 Helps keep check of whether an item
3395 is deleted from the listbox
3396 during dragging and dropping
3397  
3398 =cut
3399  
3400 sub increase_vigil_on_delete_counter {
3401 my ($self) = @_;
3402 $flow_widgets->inc_vigil_on_delete_counter;
3403  
3404 return ();
3405 }
3406  
3407 =head2 sub get_help
3408  
3409 Callback sequence following MB3 click
3410 activation of a sunix (Listbox) item
3411 program name is a scalar reference
3412
3413 Let help decide whether it is a superflow
3414 or a user-created flow
3415
3416 Show a window with the perldoc to the user
3417
3418 and length $color_flow_href->{_sunix_prog_group}
3419  
3420 =cut
3421  
3422 sub get_help {
3423  
3424 my ($self) = @_;
3425  
3426 my $help = help->new();
3427 my $pre_req_ok;
3428  
3429 $decisions->set4help($color_flow_href);
3430 $pre_req_ok = $decisions->get4help();
3431  
3432 if (
3433 $pre_req_ok
3434 and length $color_flow_href->{_prog_name_sref}
3435 and length $color_flow_href->{_current_program_name}
3436 and ( $color_flow_href->{_current_program_name} eq
3437 ${ $color_flow_href->{_prog_name_sref} } )
3438 )
3439 {
3440  
3441 # it is a sunix program
3442 # the program category is defined
3443  
3444 my $current_program_name = $color_flow_href->{_current_program_name};
3445 my $SeismicUnixGui = $dirs->get_path4SeismicUnixGui();
3446 my $module_name = ${ $color_flow_href->{_prog_name_sref} };
3447 my $program_category_h =
3448 $L_SU_global_constants->get_developer_sunix_category_h();
3449 my $key = '_' . $current_program_name;
3450 my $program_category = $program_category_h->{$key};
3451 my $sunix_program_group = $program_category;
3452  
3453 my $PATH = $SeismicUnixGui . '/sunix' . '/' . $program_category;
3454  
3455 my $help = help->new();
3456 my $inbound = $PATH . '/' . $module_name . $var->{_suffix_pm};
3457  
3458 $help->set_name( \$inbound );
3459 $help->tkpod();
3460  
3461 }
3462 else {
3463 print("color_flow, missing variable\n");
3464 }
3465 return ();
3466 }
3467  
3468 =head2 sub save_button
3469  
3470 topic: only 'Save'
3471 for safety, place set_hash_ref first
3472 run from L_SU.pm
3473
3474 Also save new parameter values (redisplay_values)
3475 for changes occurred
3476 immediately before the current saving
3477
3478 param_flow_color memory leak workaround
3479
3480 # print("color_flow, save_button writing gui_history.txt\n");
3481 # $gui_history->view();
3482  
3483 # print("3. color_flow, save_button, param_flow view data\n"
3484 # );
3485 # $param_flow_color_pkg->view_data();
3486
3487 print(
3488 "5. color_flow, save_button, memory fix, click count=$click_count\n"
3489 ); # =7 < 19 default OK
3490 print(
3491 "5. color_flow, save_button, most_recent_flow_index_touched=$last_flow_index\n"
3492 ); #=2 OK
3493 print(
3494 "5. color_flow, save_button, max_saved_widget_index=$max_saved_widget_index\n"
3495 ); # =1 TODO
3496 print("5 color_flow,save_last_param_widget_values=@save_last_param_widget_values\n");
3497  
3498 # print("5. color_flow, save_button, Can not fix memory leak\n");
3499 # print(
3500 print(
3501 "5. color_flow, save_button, this_color,last_flow_color are:$this_color,$last_flow_color\n"
3502 );
3503 print(
3504 "5. color_flow, save_button, most recent flow index touched is $most_recent_flow_index_touched\n"
3505 );
3506 print(
3507 "5. color_flow, save_button, max index in flow: $max_index_in_flow\n"
3508 );
3509  
3510 # print(
3511 #"5. color_flow, save_button, last flow index: $last_flow_index\n"
3512 # );
3513 # print(
3514 #"5. color_flow, save_button, max_saved_widget_index was $max_saved_widget_index\n"
3515 # );
3516 # print(
3517 #"5. color_flow, save_button, click_count:$click_count min_clicks4save_button:$min_clicks4save_button\n"
3518 # );
3519
3520  
3521 =cut
3522  
3523 sub save_button {
3524 my ( $self, $topic ) = @_;
3525  
3526 my $num_items_in_flow = $param_flow_color_pkg->get_num_items();
3527 my $max_index_in_flow = $num_items_in_flow - 1;
3528
3529 $gui_history->set_file_status($num_items_in_flow);
3530 my $file_prob_just_opened = $gui_history->get_file_status();
3531 # print("file_prob_just_opened=$true\n");
3532  
3533 $param_widgets->redisplay_values();
3534  
3535 # Double-check we are in the correct place:
3536 if ( $topic eq 'Save' ) {
3537  
3538 my $files_LSU = files_LSU->new();
3539  
3540 # user-built_flow in current use
3541 my $flow_listbox_color_w = _get_flow_listbox_color_w();
3542  
3543 # Start refocus index in flow, in case focus has been removed
3544 # e.g., by double-clicking in parameter values window
3545 my $most_recent_flow_index_touched =
3546 ( $color_flow_href->{_flow_select_index_href} )->{_most_recent};
3547 my $prior_flow_index_touched =
3548 ( $color_flow_href->{_flow_select_index_href} )->{_prior};
3549 my $most_recent_flow_color =
3550 ( $color_flow_href->{_flow_select_color_href} )->{_most_recent};
3551 my $last_flow_index = $most_recent_flow_index_touched;
3552  
3553 $last_flow_color = $color_flow_href->{_last_flow_color};
3554 my $max_saved_widget_index =
3555 ( scalar @save_last_param_widget_values ) - 1;
3556  
3557 # restore terminal ticks in strings after reading from the GUI
3558 # remove possible terminal strings
3559 $color_flow_href->{_values_aref} =
3560 $control->get_no_quotes4array( $color_flow_href->{_values_aref} );
3561  
3562 if ( length $last_flow_color
3563 && $last_flow_index >= 1
3564 && $flow_listbox_color_w )
3565 {
3566  
3567 # print("CASE 1A color_flow, save_button, last_flow_index=$last_flow_index\n");
3568 # One parameter index was previously selected
3569 # Assume that recent selection is valid for this current save
3570  
3571 # keep track of flow_selection clicks
3572 $flow_listbox_color_w->selectionSet($last_flow_index);
3573 $gui_history->set_flow_select_color($this_color);
3574 $gui_history->set_button('flow_select');
3575  
3576 }
3577 else {
3578 # print("color_flow, save_button , unexpected missing variables NADA\n");
3579 }
3580  
3581 =pod
3582  
3583 CASE common : When save_button is being used for the first time
3584 BUT when no flow has been selected previously (_last_flow_index_touched=-1)
3585 In other words: when a flow in the GUI is used
3586 for first time but no listboxes have been occupied previously
3587
3588 =cut
3589  
3590 _save_most_recent_param_flow();
3591  
3592 # find which flow index is selected
3593 my $num_items_in_flow = $param_flow_color_pkg->get_num_items();
3594 my $max_index_in_flow = $num_items_in_flow - 1;
3595 $last_flow_color = $color_flow_href->{_last_flow_color};
3596  
3597 # $gui_history->set_file_status($num_items_in_flow);
3598 # my $file_status = $gui_history->get_file_status();
3599  
3600 # print("color_flow, save_button: writing gui_history.txt\n");
3601 # $gui_history->view();
3602  
3603 if ( not $memory_leak4save_button_fixed ) {
3604  
3605 # Strange memory leak from param_flow_color_pkg
3606 # when first file is just opened.
3607 # Last element of last program disappears--
3608 # if either user clicks on an element different from
3609 # the last, or the Save button.
3610 # Conditions to detect the circumstance are:
3611 #--just having opened a file,
3612 # -- no changes have yet been made to the flow
3613 # -- $total_click_value < $very_low_click_value
3614 # if file has just been opened and is immediately saved
3615 # the set flow index is assumed = 0
3616 # just in total_click_value is still slow
3617 # and there was a change to the last parameter
3618 # in the last item of the flow, we detect this
3619 # by assuming that when the updated_parameter_index_on_exit
3620 # indicates the last parameter box was engaged then
3621 # we will not
3622  
3623 if (
3624 $this_color eq $last_flow_color
3625 && ( $most_recent_flow_index_touched == $max_index_in_flow
3626 && $file_prob_just_opened == $true)
3627 )
3628 {
3629  
3630 # CASE 1 FIX MEMORY LEAK
3631 # When last color=this_color
3632 # and we are still over the last index in GUI
3633 # e.g., when a recently opened file is
3634 # saved without any changes
3635 # (a strange but possible case)
3636 # Fix param_widget memory leak that deletes the
3637 # last element in the last flow
3638  
3639 # print(
3640 #"6 color_flow,most_recent_flow_index_touched=$most_recent_flow_index_touched\n"
3641 # );
3642  
3643 # # print("6. color_flow,@save_last_param_widget_values=$@save_last_param_widget_values\n");
3644 $param_flow_color_pkg->set_flow_index($max_index_in_flow);
3645 $param_flow_color_pkg->set_param_index($save_last_param_widget_index);
3646 $param_flow_color_pkg->set_param_value($save_last_param_widget_value);
3647  
3648 $param_widgets->redisplay_values();
3649  
3650 }
3651 else {
3652 #NADA
3653 }
3654  
3655 # needs to be fixed each time Save is used on unchanged perl flow
3656 $memory_leak4save_button_fixed = $true;
3657  
3658 # leak is now fixed going forward for the flow_select button as well.
3659 $memory_leak4flow_select_fixed = $true;
3660  
3661 } # end of memory leak solution
3662  
3663 $param_flow_color_pkg->set_flow_index($last_flow_index);
3664  
3665 # collect the values from those stored data in param_flow
3666 # because the values from the widgets have not been updated
3667 $color_flow_href->{_values_aref} =
3668 $param_flow_color_pkg->get_values_aref();
3669  
3670 # establish which program is active in the flow
3671 $color_flow_href->{_prog_names_aref} =
3672 $param_flow_color_pkg->get_flow_prog_names_aref();
3673 $control->set_flow_prog_names_aref(
3674 $color_flow_href->{_prog_names_aref} );
3675 $control->set_flow_prog_name_index($most_recent_flow_index_touched);
3676  
3677 # remove all quotes
3678 $color_flow_href->{_values_aref} =
3679 $control->get_no_quotes4array( $color_flow_href->{_values_aref} );
3680  
3681 # restore so that only strings have quotes
3682 # for the last program name that was used
3683 $color_flow_href->{_values_aref} = $control->get_string_or_number4aref(
3684 $color_flow_href->{_values_aref} );
3685  
3686 $color_flow_href->{_last_parameter_index_touched_color} = 0;
3687 $color_flow_href->{$_is_last_parameter_index_touched_color} = $true;
3688  
3689 # update changes to parameter values between 'SaveAs' and 'Save'-2
3690 # assume a parameter index has been changed so that
3691 # _save_most_recent_param_flow is forced to update previous changes before
3692 # the current "updating""
3693 # these changes occur via param_flow
3694 # _update_prior_param_flow();
3695  
3696 $color_flow_href->{_names_aref} =
3697 $param_flow_color_pkg->get_names_aref();
3698  
3699 $param_flow_color_pkg->set_good_values();
3700 $param_flow_color_pkg->set_good_labels();
3701  
3702 $color_flow_href->{_good_labels_aref2} =
3703 $param_flow_color_pkg->get_good_labels_aref2();
3704 $color_flow_href->{_items_versions_aref} =
3705 $param_flow_color_pkg->get_flow_items_version_aref();
3706 $color_flow_href->{_good_values_aref2} =
3707 $param_flow_color_pkg->get_good_values_aref2();
3708 $color_flow_href->{_prog_names_aref} =
3709 $param_flow_color_pkg->get_flow_prog_names_aref();
3710  
3711 $color_flow_href->{_prog_names_aref} =
3712 $param_flow_color_pkg->get_flow_prog_names_aref();
3713 $control->set_flow_prog_names_aref(
3714 $color_flow_href->{_prog_names_aref} );
3715  
3716 # One last check on quotes for strings
3717 # Program names help discern strings from numbers:
3718 # after memory leak correction -- one time only
3719 # and for case where file name are numeric e.g., '1000.txt'
3720  
3721 $color_flow_href->{_good_values_aref2} =
3722 $control->get_string_or_number_aref2(
3723 $color_flow_href->{_good_values_aref2} );
3724  
3725 $files_LSU->set_prog_param_labels_aref2($color_flow_href);
3726 $files_LSU->set_prog_param_values_aref2($color_flow_href);
3727 $files_LSU->set_prog_names_aref($color_flow_href);
3728 $files_LSU->set_items_versions_aref($color_flow_href);
3729 $files_LSU->set_data();
3730 $files_LSU->set_message($color_flow_href);
3731  
3732 # listbox color assignment
3733 $files_LSU->set_flow_color($this_color);
3734  
3735 # update PL_SEISMIC in case user has recently changed project area
3736 $files_LSU->set_PL_SEISMIC();
3737  
3738 # flows saved to PL_SEISMIC
3739 $files_LSU->set2pl($color_flow_href);
3740 $files_LSU->save();
3741  
3742 }
3743 else {
3744 print("color_flow, missing topic Save\n");
3745 }
3746 return ();
3747  
3748 } # ends save_button
3749  
3750 =head2 sub set_hash_ref
3751 Import external hash into private settings via gui_history
3752 hash
3753  
3754 Keys that used simplified names are also kept so later
3755 the hash can be returned to a calling module
3756
3757 print("color_flow, END of flow_select: writing gui_history.txt\n");
3758 $gui_history->view();
3759
3760 =cut
3761  
3762 sub set_hash_ref {
3763 my ( $self, $hash_ref ) = @_;
3764  
3765 $gui_history->set_defaults($hash_ref);
3766 $color_flow_href = $gui_history->get_defaults();
3767  
3768 # REALLY?
3769 # set up param_widgets for later use
3770 # give param_widgets the needed values
3771 $param_widgets->set_hash_ref($color_flow_href);
3772  
3773 $flow_color = $color_flow_href->{_flow_color};
3774  
3775 # $gui_history_aref = $color_flow_href->{_gui_history_aref};
3776  
3777 # for local use
3778 $last_flow_color =
3779 $color_flow_href->{_last_flow_color}; # used in flow_select
3780 $message_w = $color_flow_href->{_message_w};
3781 $parameter_values_frame = $color_flow_href->{_parameter_values_frame};
3782 $parameter_values_button_frame =
3783 $color_flow_href->{_parameter_values_button_frame};
3784  
3785 # $sunix_listbox = $color_flow_href->{_sunix_listbox};
3786  
3787 # print("color_flow, set_hash_ref _check_buttons_settings_aref: @{$color_flow_href->{_check_buttons_settings_aref}}\n");
3788  
3789 # print("color_flow,set_hash_ref: print gui_history->view\n");
3790 # $gui_history->view();
3791  
3792 return ();
3793 }
3794  
3795 =head2 sub set_occupied_listbox_aref
3796  
3797  
3798 =cut
3799  
3800 sub set_occupied_listbox_aref {
3801  
3802 my ( $self, $occupied_listbox_aref ) = @_;
3803  
3804 if ($occupied_listbox_aref) {
3805  
3806 $color_flow_href->{_occupied_listbox_aref} = $occupied_listbox_aref;
3807  
3808 }
3809 else {
3810 print(
3811 "color_flow,_set_occupied_listbox_aref, missing occupied_listbox_aref \n"
3812 );
3813 }
3814  
3815 }
3816  
3817 =head2 sub set_vacant_listbox_aref
3818  
3819  
3820 =cut
3821  
3822 sub set_vacant_listbox_aref {
3823  
3824 my ( $self, $vacant_listbox_aref ) = @_;
3825  
3826 if ($vacant_listbox_aref) {
3827  
3828 $color_flow_href->{_vacant_listbox_aref} = $vacant_listbox_aref;
3829  
3830 }
3831 else {
3832 print(
3833 "color_flow,_set_vacant_listbox_aref, missing vacant_listbox_aref \n"
3834 );
3835 }
3836  
3837 }
3838  
3839 __PACKAGE__->meta->make_immutable;
3840 1;