[497] | 1 | %'fill_GUI': fill a GUI with a set of parameters from a Matlab structure |
---|
[360] | 2 | % ----------------------------------------------------------------------- |
---|
[497] | 3 | % function errormsg=fill_GUI(Param,handles) |
---|
| 4 | % OUPUT: |
---|
| 5 | % errormsg: error message, ='' by default |
---|
| 6 | % |
---|
| 7 | % INPUT: |
---|
| 8 | % Param: matlab structure containing the information to display in the GUI |
---|
| 9 | % handles: Matlab structure containing the handles of the GUI elements |
---|
| 10 | % |
---|
| 11 | % see also the reverse function read_GUI.m |
---|
| 12 | % |
---|
[360] | 13 | function errormsg=fill_GUI(Param,handles) |
---|
| 14 | %------------------------------------------------------------------------ |
---|
| 15 | errormsg=''; |
---|
[461] | 16 | fields=fieldnames(Param);%list of fields in Param |
---|
[472] | 17 | % loop on the elements of the input structure Param |
---|
[360] | 18 | for ifield=1:numel(fields) |
---|
[500] | 19 | % case of a sub-structure --> fill a panel |
---|
| 20 | if isstruct(Param.(fields{ifield}))% case of a sub-structure |
---|
[360] | 21 | if isfield(handles,fields{ifield}) |
---|
[361] | 22 | set(handles.(fields{ifield}),'Visible','on') |
---|
| 23 | children=get(handles.(fields{ifield}),'children'); |
---|
| 24 | for ichild=1:numel(children) |
---|
| 25 | hchild.(get(children(ichild),'tag'))=children(ichild); |
---|
| 26 | end |
---|
[472] | 27 | errormsg=fill_GUI(Param.(fields{ifield}),hchild);% apply the function to the substructure |
---|
[360] | 28 | end |
---|
[500] | 29 | % case of an element |
---|
[360] | 30 | else |
---|
[361] | 31 | hh=[]; |
---|
[497] | 32 | input_data=Param.(fields{ifield}); |
---|
[379] | 33 | check_done=0; |
---|
[361] | 34 | if isfield(handles,fields{ifield}) |
---|
[497] | 35 | hh=handles.(fields{ifield}); |
---|
[361] | 36 | if strcmp(get(hh,'Type'),'uitable') |
---|
[379] | 37 | set(hh,'Visible','on') |
---|
[427] | 38 | if ischar(input_data) |
---|
[460] | 39 | input_data={input_data};% transform string to a single cell if needed |
---|
[427] | 40 | end |
---|
[363] | 41 | set(hh,'Data',input_data) |
---|
[379] | 42 | check_done=1; |
---|
[360] | 43 | end |
---|
[500] | 44 | elseif isnumeric(input_data) |
---|
| 45 | if numel(input_data)>1 |
---|
| 46 | %deals with array displayed in multiple boxes labeled by an index |
---|
| 47 | for ibox=1:numel(input_data) |
---|
| 48 | if isfield(handles,['num_' fields{ifield} '_' num2str(ibox)]) |
---|
| 49 | hh(ibox)=handles.(['num_' fields{ifield} '_' num2str(ibox)]); |
---|
| 50 | end |
---|
| 51 | end |
---|
| 52 | else % single box (usual case) |
---|
| 53 | if isfield(handles,['num_' fields{ifield}]) |
---|
| 54 | hh=handles.(['num_' fields{ifield}]); |
---|
| 55 | end |
---|
| 56 | end |
---|
[361] | 57 | end |
---|
[500] | 58 | for ibox=1:numel(hh) |
---|
| 59 | if ~isempty(hh(ibox))&& ~check_done |
---|
| 60 | set(hh(ibox),'Visible','on') |
---|
[368] | 61 | % input_data |
---|
[500] | 62 | switch get(hh(ibox),'Style') |
---|
[363] | 63 | case {'checkbox','radiobutton','togglebutton'} |
---|
| 64 | if isnumeric(input_data) |
---|
[500] | 65 | set(hh(ibox),'Value',input_data(ibox)) |
---|
[361] | 66 | end |
---|
| 67 | case 'edit' |
---|
[515] | 68 | input_string=''; |
---|
[363] | 69 | if isnumeric(input_data) |
---|
[515] | 70 | if numel(input_data)>0 |
---|
[500] | 71 | input_string=num2str(input_data(ibox)); |
---|
[515] | 72 | end |
---|
[500] | 73 | else |
---|
| 74 | input_string=input_data; |
---|
[361] | 75 | end |
---|
[500] | 76 | set(hh(ibox),'String',input_string) |
---|
[472] | 77 | case{'listbox','popupmenu'} |
---|
[363] | 78 | if isnumeric(input_data) |
---|
| 79 | input_data=num2str(input_data); |
---|
[361] | 80 | end |
---|
[500] | 81 | menu=get(hh(ibox),'String'); |
---|
[472] | 82 | if ischar(input_data) |
---|
| 83 | input_data={input_data}; |
---|
[361] | 84 | end |
---|
[472] | 85 | values=zeros(size(input_data)); |
---|
| 86 | for idata=1:numel(input_data) |
---|
| 87 | iline=find(strcmp(input_data{idata},menu)); |
---|
| 88 | if isempty(iline) |
---|
[476] | 89 | values(idata)=1; |
---|
| 90 | menu=[input_data(idata);menu]; |
---|
[472] | 91 | else |
---|
[476] | 92 | values(idata)=iline(1); |
---|
[472] | 93 | end |
---|
| 94 | end |
---|
[500] | 95 | set(hh(ibox),'String',menu) |
---|
| 96 | set(hh(ibox),'Value',values) |
---|
[360] | 97 | end |
---|
| 98 | end |
---|
[500] | 99 | end |
---|
[360] | 100 | end |
---|
| 101 | end |
---|
| 102 | |
---|