1 function dnl_action(hObject,action,varargin)
\r
2 % Sorry, I didn't have enough time to write nice and documented GUI code.
\r
4 % Toolbox for nonlinear filtering.
\r
5 % Copyright (C) 2005 Jakob Rosén <jakob.rosen@gmail.com>
\r
7 % This program is free software; you can redistribute it and/or
\r
8 % modify it under the terms of the GNU General Public License
\r
9 % as published by the Free Software Foundation; either version 2
\r
10 % of the License, or (at your option) any later version.
\r
12 % This program is distributed in the hope that it will be useful,
\r
13 % but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 % GNU General Public License for more details.
\r
17 % You should have received a copy of the GNU General Public License
\r
18 % along with this program; if not, write to the Free Software
\r
19 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
21 handles=guidata(hObject);
\r
23 if strcmp(action,'check')
\r
28 if strcmp(action,'edit_data')
\r
30 str=get(handles.([caller, '_edit']),'String');
\r
33 % Undefined object! We'll try to assign the expression to the correct class
\r
34 if isa(handles.(caller), 'double')
\r
35 % The object is undefined!
\r
36 tc=eval('str2num(str)',[]);
\r
38 handles.(caller)=xsymbolic;
\r
40 handles.(caller)=xlinear;
\r
41 if strcmp(caller,'f')||strcmp(caller,'h')
\r
42 handles.(caller)=set(handles.(caller),'evalvar',1);
\r
45 guidata(hObject,handles);
\r
46 model_action_update_select(hObject,caller,'datatypes','str');
\r
47 handles=guidata(hObject);
\r
51 handles.(caller)=set(handles.(caller),'str',str);
\r
52 str=get(handles.(caller),'str');
\r
53 set(handles.([caller, '_edit']),'String',str); % FORMAT DATA
\r
57 if strcmp(action,'save')
\r
59 % Check for empty objects
\r
60 needed_objects={'f','h','w','e','p0'};
\r
61 for i=1:length(needed_objects);
\r
62 if isempty(handles.(needed_objects{i}))
\r
63 msgbox([needed_objects{i},' must not be undefined!']);
\r
68 % Assign the saved properties to local variables
\r
70 props={'f','h','w','e','p0','xvars','uvars','wvars','x0','T'};
\r
71 for i=1:length(props)
\r
72 eval([props{i},'=handles.',props{i},';']);
\r
75 % Insert xvars into the data objects
\r
76 data_objects={'f','h'};
\r
77 for i=1:length(data_objects)
\r
78 eval(['set(obj, ''', props{i}, ''', ', props{i}, ');']);
\r
79 eval(['set(', data_objects{i}, ', ''xvars'', xvars);']);
\r
80 eval(['set(', data_objects{i}, ', ''uvars'', uvars);']);
\r
81 eval(['set(', data_objects{i}, ', ''wvars'', wvars);']);
\r
84 % Fix the correct varsize
\r
85 % FÖR PRESENTATION!!
\r
86 % varsize=[handles.states, 1, parenthandles.usize, get(handles.w,'n')];
\r
87 varsize=[handles.states, 1, 0, get(handles.w,'n')];
\r
89 eval(['set(f, ''varsize'', varsize);'], ';'); % Try / Catch
\r
90 eval(['set(h, ''varsize'', varsize);'], ';'); % Try / Catch
\r
92 % Insert the new objects into the model
\r
93 for i=1:length(props)
\r
94 eval(['set(obj, ''', props{i}, ''', ', props{i}, ');']);
\r
97 parentfig=handles.parentfig;
\r
98 parenthandles=guidata(parentfig);
\r
99 model_objects=parenthandles.model_objects;
\r
100 model_objects{handles.caller}=obj;
\r
101 parenthandles.model_objects=model_objects;
\r
102 guidata(parentfig,parenthandles);
\r
104 eval(handles.callback);
\r
111 if strcmp(action,'rnd_edit')
\r
113 caller=varargin{1};
\r
114 rnd_edit_property=[caller, '_edit'];
\r
115 str=get(handles.(rnd_edit_property),'String');
\r
118 % Undefined object! We'll try to assign the expression to the correct class
\r
119 if isa(handles.(caller), 'double')
\r
120 % The object is undefined!
\r
121 handles.(caller)=gauss;
\r
122 guidata(hObject,handles);
\r
123 model_action_update_select(hObject,caller,'rndtypes','R_str');
\r
124 handles=guidata(hObject);
\r
128 handles.(caller)=set(handles.(caller),'R_str',str);
\r
129 str=get(handles.(caller),'R_str');
\r
130 set(handles.(rnd_edit_property),'String',str);
\r
132 guidata(hObject,handles);
\r
133 dnl_action_noise_update(hObject,caller);
\r
134 handles=guidata(hObject); % UGLY FIX LAST ROW BLAH BLAH
\r
139 if strcmp(action,'states_edit')
\r
140 handles.x0=str2num(get(handles.edit_x0,'String'));
\r
141 handles.states=str2num(get(handles.edit_states,'String'));
\r
142 handles.xvars=cellstr2cell(get(handles.xvars_edit,'String'));
\r
143 guidata(hObject,handles);
\r
145 model_edit_states('init', hObject, ['dnl_action(',num2str(hObject),',''states_refresh'')']);
\r
148 if strcmp(action,'states_refresh')
\r
150 set(handles.edit_states,'String',num2str(handles.states));
\r
151 set(handles.edit_x0,'String',num2str2(handles.x0));
\r
152 set(handles.xvars_edit,'String',cell2cellstr(handles.xvars));
\r
154 guidata(hObject,handles);
\r
155 model_generate_p0(hObject);
\r
156 handles=guidata(hObject);
\r
159 if strcmp(action,'uvars_edit_button')
\r
160 handles.uvars=cellstr2cell(get(handles.uvars_edit,'String'));
\r
161 guidata(hObject,handles);
\r
163 model_edit_uvars('init', hObject, ['dnl_action(',num2str(hObject),',''uvars_refresh'')']);
\r
166 if strcmp(action,'uvars_refresh')
\r
168 set(handles.uvars_edit,'String',cell2cellstr(handles.uvars));
\r
169 guidata(hObject,handles);
\r
173 if strcmp(action,'wvars_edit_button')
\r
174 handles.wvars=cellstr2cell(get(handles.wvars_edit,'String'));
\r
175 guidata(hObject,handles);
\r
177 model_edit_wvars('init', hObject, ['dnl_action(',num2str(hObject),',''wvars_refresh'')']);
\r
180 if strcmp(action,'wvars_refresh')
\r
182 set(handles.wvars_edit,'String',cell2cellstr(handles.wvars));
\r
183 guidata(hObject,handles);
\r
187 if strcmp(action,'T_edit')
\r
188 T=str2num(get(handles.T_edit,'String'));
\r
190 msgbox('T must be positive!');
\r
194 set(handles.T_edit,'String',num2str(T)); % Format data
\r
197 if strcmp(action,'statenr_edit')
\r
198 states=str2num(get(handles.edit_states,'String'));
\r
200 msgbox('The amount of states must be positive!');
\r
204 % x0=str2num(get(handles.x0,'String'));
\r
205 % xvars=cellstr2cell(get(handles.xvars,'String'));
\r
208 xvars=handles.xvars;
\r
210 states_old=length(xvars);
\r
211 sdiff=states-states_old;
\r
215 x0(end+1:states)=0;
\r
216 for i=states_old+1:states
\r
217 xvars{i}=['x',num2str(i)];
\r
220 % Delete some states
\r
222 xvars=xvars(1:states);
\r
224 % Nothing has changed. Do nothing.
\r
229 % A row vector! Let's transpone it.
\r
233 set(handles.xvars_edit,'String',cell2cellstr(xvars));
\r
234 set(handles.edit_x0,'String',num2str2(x0));
\r
236 handles.states=states;
\r
238 handles.xvars=xvars;
\r
240 guidata(hObject,handles);
\r
241 model_generate_p0(hObject);
\r
242 handles=guidata(hObject);
\r
245 if strcmp(action,'xvars_edit')
\r
246 xvars=cellstr2cell(get(handles.xvars_edit,'String'));
\r
247 if length(xvars)~=handles.states
\r
248 msgbox('Error! The amount of elements in ''xvars'' must be equal to the amount of states.');
\r
251 handles.xvars=xvars;
\r
253 set(handles.xvars_edit,'String',cell2cellstr(xvars)); % Format data
\r
256 if strcmp(action,'uvars_edit')
\r
257 uvars=cellstr2cell(get(handles.uvars_edit,'String'));
\r
258 handles.uvars=uvars;
\r
259 set(handles.uvars_edit,'String',cell2cellstr(uvars)); % Format data
\r
262 if strcmp(action,'wvars_edit')
\r
263 wvars=cellstr2cell(get(handles.wvars_edit,'String'));
\r
264 handles.wvars=wvars;
\r
265 set(handles.wvars_edit,'String',cell2cellstr(wvars)); % Format data
\r
268 if strcmp(action,'x0_edit')
\r
269 x0=str2num(get(handles.edit_x0,'String'));
\r
272 msgbox('''x0'' must be one-dimensional!');
\r
276 if length(x0)~=handles.states
\r
277 msgbox('Error! The amount of elements in ''x0'' must be equal to the amount of states.');
\r
282 % A row vector! Let's transpone it.
\r
288 set(handles.edit_x0,'String',num2str2(x0)); % Format data
\r
291 if strcmp(action,'objedit')
\r
292 caller=varargin{1};
\r
293 dobj=handles.(caller);
\r
294 if isa(dobj,'double')
\r
295 msgbox('Error! Can not edit an undefined object.');
\r
297 function_str=[class(dobj),'_edit'];
\r
298 feval(function_str,'init',hObject,dobj,caller,['dnl_action(',num2str(hObject),',''obj_refresh'',''',caller,''')']);
\r
302 if strcmp(action,'rnd_objedit')
\r
303 caller=varargin{1};
\r
304 robj=handles.(caller);
\r
305 if isa(robj,'double')
\r
306 msgbox('Error! Can not edit an undefined object.');
\r
308 function_str=[class(robj),'_edit'];
\r
309 feval(function_str,'init',hObject,robj,caller,['dnl_action(',num2str(hObject),',''rnd_refresh'',''',caller,''')']);
\r
314 if strcmp(action,'obj_refresh')
\r
315 caller=varargin{1};
\r
316 str=get(handles.(caller),'str');
\r
317 rnd_edit_property=[caller,'_edit'];
\r
318 set(handles.(rnd_edit_property),'String',str);
\r
320 obj=handles.(caller);
\r
323 if strcmp(action,'rnd_refresh')
\r
324 caller=varargin{1};
\r
325 str=get(handles.(caller),'R_str');
\r
326 rnd_edit_property=[caller,'_edit'];
\r
327 set(handles.(rnd_edit_property),'String',str);
\r
328 guidata(hObject,handles);
\r
329 dnl_action_noise_update(hObject,caller);
\r
330 handles=guidata(hObject); % UGLY FIX LAST ROW BLAH BLAH
\r
334 if strcmp(action,'select')
\r
336 caller=varargin{1};
\r
337 select_property=[caller, '_select'];
\r
338 edit_property=[caller, '_edit'];
\r
340 datatypes=handles.datatypes;
\r
341 index=get(handles.(select_property),'value')-1;
\r
342 % set(handles.(edit_property),'String','');
\r
345 handles.(caller)=eval(datatypes{index});
\r
346 % Default f and h xlinear objects have evalvar=1
\r
347 if isa(handles.(caller),'xlinear');
\r
348 if findcstr({'f','h'},caller)
\r
349 obj=handles.(caller);
\r
350 set(obj,'evalvar',1);
\r
351 handles.(caller)=obj;
\r
355 handles.(caller)=[];
\r
357 set(handles.(edit_property),'String',get(handles.(caller),'str'));
\r
359 guidata(hObject,handles);
\r
362 if strcmp(action,'rnd_select')
\r
363 caller=varargin{1};
\r
364 select_property=[caller, '_select'];
\r
365 edit_property=[caller, '_edit'];
\r
367 rndtypes=handles.rndtypes;
\r
368 index=get(handles.(select_property),'value')-1;
\r
369 % set(handles.(edit_property),'String','');
\r
372 handles.(caller)=eval(rndtypes{index});
\r
374 handles.(caller)=[];
\r
376 set(handles.(edit_property),'String',get(handles.(caller),'R_str'));
\r
380 if strcmp(action,'import_button')
\r
382 objects={'f','h','w','e','p0'};
\r
383 import_select=get(handles.import_select,'Value');
\r
384 caller=objects{import_select};
\r
385 import_edit=get(handles.import_edit,'String');
\r
387 if isempty(import_edit)
\r
388 % The edit control is blank
\r
389 msgbox('No object name was specified!');
\r
391 data=evalin('base',import_edit,'[]');
\r
392 if isa(data,'logical')
\r
393 msgbox('Error! There was no object returned.');
\r
395 % Object imported successfully
\r
396 if isa(data,'double')
\r
400 data=xlinear(data);
\r
402 elseif isa(data,'char')||isa(data,'inline')||isa(data,'sym')||isa(data,'cell')
\r
404 msgbox('Sorry, this datatype is not convertable to a noise object');
\r
407 data=xsymbolic(data);
\r
410 handles.(caller)=data;
\r
411 guidata(hObject,handles);
\r
413 model_action_update_select(hObject,caller,'rndtypes','R_str');
\r
415 model_action_update_select(hObject,caller,'datatypes','str');
\r
417 handles=guidata(hObject); % FIX: UGLY (last row...)
\r
422 guidata(hObject,handles);