| 1 | % ----------------------------------------------------------------------- |
|---|
| 2 | % --- read a GUI with handle 'handle' producing a structure 'struct' |
|---|
| 3 | function errormsg=fill_GUI(Param,handles) |
|---|
| 4 | %------------------------------------------------------------------------ |
|---|
| 5 | errormsg=''; |
|---|
| 6 | fields=fieldnames(Param); |
|---|
| 7 | for ifield=1:numel(fields) |
|---|
| 8 | if isstruct(Param.(fields{ifield})) |
|---|
| 9 | if isfield(handles,fields{ifield}) |
|---|
| 10 | set(handles.(fields{ifield}),'Visible','on') |
|---|
| 11 | children=get(handles.(fields{ifield}),'children'); |
|---|
| 12 | for ichild=1:numel(children) |
|---|
| 13 | hchild.(get(children(ichild),'tag'))=children(ichild); |
|---|
| 14 | end |
|---|
| 15 | errormsg=fill_GUI(Param.(fields{ifield}),hchild); |
|---|
| 16 | end |
|---|
| 17 | else |
|---|
| 18 | hh=[]; |
|---|
| 19 | input_data=Param.(fields{ifield}); |
|---|
| 20 | if isfield(handles,fields{ifield}) |
|---|
| 21 | hh=handles.(fields{ifield}); |
|---|
| 22 | if strcmp(get(hh,'Type'),'uitable') |
|---|
| 23 | set(hh,'Data',input_data) |
|---|
| 24 | break |
|---|
| 25 | end |
|---|
| 26 | elseif isnumeric(input_data) && isfield(handles,['num_' fields{ifield}]) |
|---|
| 27 | hh=handles.(['num_' fields{ifield}]); |
|---|
| 28 | end |
|---|
| 29 | if ~isempty(hh) |
|---|
| 30 | set(hh,'Visible','on') |
|---|
| 31 | get(hh,'style') |
|---|
| 32 | input_data |
|---|
| 33 | switch get(hh,'style') |
|---|
| 34 | case {'checkbox','radiobutton','togglebutton'} |
|---|
| 35 | if isnumeric(input_data) |
|---|
| 36 | set(hh,'Value',input_data) |
|---|
| 37 | end |
|---|
| 38 | case 'edit' |
|---|
| 39 | if isnumeric(input_data) |
|---|
| 40 | input_data=num2str(input_data); |
|---|
| 41 | end |
|---|
| 42 | set(hh,'String',input_data) |
|---|
| 43 | case{'Listbox','popupmenu'} |
|---|
| 44 | if isnumeric(input_data) |
|---|
| 45 | input_data=num2str(input_data); |
|---|
| 46 | end |
|---|
| 47 | menu=get(hh,'String'); |
|---|
| 48 | iline=find(strcmp(input_data,menu)); |
|---|
| 49 | if isempty(iline) |
|---|
| 50 | iline=numel(menu)+1; |
|---|
| 51 | set(hh,'String',[menu;{input_data}]) |
|---|
| 52 | end |
|---|
| 53 | set(hh,'Value',iline) |
|---|
| 54 | end |
|---|
| 55 | end |
|---|
| 56 | end |
|---|
| 57 | end |
|---|
| 58 | |
|---|