1 | function varargout = addmenuad(h, Command) |
---|
2 | % ADDMENUAD - Menu to tune AD parameters |
---|
3 | % |
---|
4 | % INPUTS |
---|
5 | % 1. h - handles to the parent figure |
---|
6 | % 2. Command - Build {Default} builds menu |
---|
7 | % Action used for callback (edition, ...) |
---|
8 | % NoAction |
---|
9 | % 3. LabelString - if Build command |
---|
10 | % 4. ParentLabelString - if Build command |
---|
11 | % |
---|
12 | % OUPUTS |
---|
13 | % 1. hmenu - handles to admenu |
---|
14 | % |
---|
15 | % See Also addmenuad |
---|
16 | |
---|
17 | % |
---|
18 | % Written by Gregory J. Portmann |
---|
19 | |
---|
20 | if nargin < 1 |
---|
21 | h = gcf; |
---|
22 | end |
---|
23 | if nargin < 2 |
---|
24 | Command = 'Build'; |
---|
25 | end |
---|
26 | |
---|
27 | %% switchyard |
---|
28 | switch lower(Command) |
---|
29 | case 'build' |
---|
30 | |
---|
31 | if nargin < 3 |
---|
32 | LabelString = 'Middle Layer Parameter Setup'; |
---|
33 | end |
---|
34 | if nargin < 4 |
---|
35 | ParentLabelString = 'MiddleLayer'; |
---|
36 | end |
---|
37 | |
---|
38 | if strcmpi(get(h,'Type'), 'figure') |
---|
39 | h_childen = get(gcf,'children'); |
---|
40 | EditMenuFlag = 0; |
---|
41 | for i = 1:length(h_childen) |
---|
42 | if ~strcmpi(get(h_childen(i),'Type'),'uicontrol') && ... |
---|
43 | strcmpi(get(h_childen(i),'label'), ParentLabelString) |
---|
44 | EditMenuFlag = 1; |
---|
45 | h = h_childen(i); |
---|
46 | break; |
---|
47 | end |
---|
48 | end |
---|
49 | if ~EditMenuFlag |
---|
50 | % Make an edit menu |
---|
51 | h = uimenu(h, 'Label', ParentLabelString, 'Callback',''); |
---|
52 | end |
---|
53 | hmenu = uimenu(h, 'Label', LabelString, 'Callback',''); |
---|
54 | elseif strcmpi(get(h,'Type'), 'uimenu') |
---|
55 | if isempty(findstr(get(h, 'Label'), 'Middle Layer')) |
---|
56 | hmenu = uimenu(h, 'Label', LabelString, 'Callback',''); |
---|
57 | else |
---|
58 | hmenu = h; |
---|
59 | end |
---|
60 | else |
---|
61 | hmenu = h; |
---|
62 | end |
---|
63 | |
---|
64 | varargout{1} = hmenu; |
---|
65 | |
---|
66 | DataStructure0 = getad; |
---|
67 | if isempty(DataStructure0) |
---|
68 | error('Middle layer initialization needed'); |
---|
69 | end |
---|
70 | |
---|
71 | |
---|
72 | % Build middle menu tree |
---|
73 | DataStructFieldName1 = fieldnames(DataStructure0); |
---|
74 | for i = 1:length(DataStructFieldName1) |
---|
75 | DataStructure1 = DataStructure0.(DataStructFieldName1{i}); |
---|
76 | if isstruct(DataStructure1) |
---|
77 | hmenu1 = uimenu(hmenu, 'Label',DataStructFieldName1{i}, 'Callback',''); |
---|
78 | DataStructFieldName2 = fieldnames(DataStructure1); |
---|
79 | for j = 1:length(DataStructFieldName2) |
---|
80 | DataStructure2 = DataStructure1.(DataStructFieldName2{j}); |
---|
81 | if isstruct(DataStructure2) |
---|
82 | hmenu2 = uimenu(hmenu1, 'Label',DataStructFieldName2{j}, 'Callback',''); |
---|
83 | DataStructFieldName3 = fieldnames(DataStructure2); |
---|
84 | for k = 1:length(DataStructFieldName3) |
---|
85 | DataStructure3 = DataStructure2.(DataStructFieldName3{k}); |
---|
86 | if isstruct(DataStructure3) |
---|
87 | hmenu3 = uimenu(hmenu2, 'Label',DataStructFieldName3{k}, 'Callback',''); |
---|
88 | DataStructFieldName4 = fieldnames(DataStructure3); |
---|
89 | for l = 1:length(DataStructFieldName4) |
---|
90 | hmenu4 = uimenu(hmenu3, 'Label', DataStructFieldName4{l}); |
---|
91 | set(hmenu4,'UserData', {DataStructure3.(DataStructFieldName4{l}) , DataStructFieldName1{l}, DataStructFieldName2{k}, DataStructFieldName3{k}, DataStructFieldName4{i}}); |
---|
92 | set(hmenu4,'Callback', 'addmenuad(gcbo,''Action'')'); |
---|
93 | end |
---|
94 | else |
---|
95 | hmenu3 = uimenu(hmenu2, 'Label',DataStructFieldName3{k}); |
---|
96 | set(hmenu3,'UserData', {DataStructure3, DataStructFieldName1{i}, DataStructFieldName2{j}, DataStructFieldName3{k}}); |
---|
97 | set(hmenu3,'Callback', 'addmenuad(gcbo,''Action'')'); |
---|
98 | end |
---|
99 | end |
---|
100 | else |
---|
101 | hmenu2 = uimenu(hmenu1, 'Label',DataStructFieldName2{j}); |
---|
102 | set(hmenu2,'UserData', {DataStructure2, DataStructFieldName1{i}, DataStructFieldName2{j}}); |
---|
103 | set(hmenu2,'Callback', 'addmenuad(gcbo,''Action'')'); |
---|
104 | end |
---|
105 | end |
---|
106 | else |
---|
107 | hmenu1 = uimenu(hmenu, 'Label', DataStructFieldName1{i}); |
---|
108 | set(hmenu1,'UserData', {DataStructure1, DataStructFieldName1{i}}); |
---|
109 | set(hmenu1,'Callback', 'addmenuad(gcbo,''Action'')'); |
---|
110 | end |
---|
111 | end |
---|
112 | |
---|
113 | case 'action' |
---|
114 | |
---|
115 | Data = get(h, 'UserData'); |
---|
116 | |
---|
117 | % Get up-to-date data |
---|
118 | Data{1} = getfamilydata(Data{2:end}); |
---|
119 | |
---|
120 | %Label = get(h, 'Label'); |
---|
121 | TitleString = sprintf('%s ',Data{2:end}); |
---|
122 | AddOpts.Resize='on'; |
---|
123 | AddOpts.WindowStyle='normal'; |
---|
124 | AddOpts.Interpreter='tex'; |
---|
125 | if isnumeric(Data{1}) |
---|
126 | answer = inputdlg({sprintf('Change %s',TitleString)}, 'Edit Middle Layer Parameter', size(Data{1},1), {num2str(Data{1})}, AddOpts); |
---|
127 | if isempty(answer) |
---|
128 | return |
---|
129 | end |
---|
130 | Data{1} = str2num(answer{1}); |
---|
131 | set(h, 'UserData', Data); |
---|
132 | setfamilydata(Data{1:end}); |
---|
133 | elseif strcmpi(Data{2},'Directory') |
---|
134 | answer = uigetdir(Data{1}, sprintf('Change directory location for %s', Data{3})); |
---|
135 | if answer == 0 |
---|
136 | return |
---|
137 | end |
---|
138 | Data{1} = answer; |
---|
139 | set(h, 'UserData', Data); |
---|
140 | setfamilydata(Data{1:end}); |
---|
141 | elseif ischar(Data{1}) |
---|
142 | answer = inputdlg({sprintf('Change %s',TitleString)}, 'Edit Middle Layer Parameter', size(Data{1},1), {num2str(Data{1})}, AddOpts); |
---|
143 | if isempty(answer) |
---|
144 | return |
---|
145 | end |
---|
146 | Data{1} = answer{1}; |
---|
147 | set(h, 'UserData', Data); |
---|
148 | setfamilydata(Data{1:end}); |
---|
149 | end |
---|
150 | |
---|
151 | case {'noaction', 'no action'} |
---|
152 | otherwise |
---|
153 | disp('Unknown action') |
---|
154 | end |
---|