1 function danl_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
27 evalcheck=get(handles.([caller,'_checkbox']),'Value');
\r
29 evalvar=get(handles.(caller),'evalvar');
\r
30 pos=find(evalvar==1);
\r
34 evalvar=[1,evalvar];
\r
38 evalvar=[evalvar(1:pos-1),evalvar(pos+1:end)];
\r
42 handles.(caller)=set(handles.(caller),'evalvar',evalvar);
\r
45 if strcmp(action,'edit_data')
\r
47 str=get(handles.([caller, '_edit']),'String');
\r
50 % Undefined object! We'll try to assign the expression to the correct class
\r
51 if isa(handles.(caller), 'double')
\r
52 % The object is undefined!
\r
53 tc=eval('str2num(str)',[]);
\r
55 handles.(caller)=xsymbolic;
\r
57 handles.(caller)=xlinear;
\r
58 if strcmp(caller,'f')||strcmp(caller,'h')
\r
59 handles.(caller)=set(handles.(caller),'evalvar',1);
\r
62 guidata(hObject,handles);
\r
63 model_action_update_select(hObject,caller,'datatypes','str');
\r
64 danl_update_checkbox(hObject,caller);
\r
65 handles=guidata(hObject);
\r
69 handles.(caller)=set(handles.(caller),'str',str);
\r
70 str=get(handles.(caller),'str');
\r
71 set(handles.([caller, '_edit']),'String',str); % FORMAT DATA
\r
75 if strcmp(action,'save')
\r
77 parentfig=handles.parentfig;
\r
78 parenthandles=guidata(parentfig);
\r
80 % Check for empty objects
\r
81 needed_objects={'f','gw','h','w','e','p0'};
\r
82 for i=1:length(needed_objects);
\r
83 if isempty(handles.(needed_objects{i}))
\r
84 msgbox([needed_objects{i},' must not be undefined!']);
\r
89 % Assign the saved properties to local variables
\r
91 props={'f','gw','gu','h','hu','w','e','p0','xvars','x0','T'};
\r
92 for i=1:length(props)
\r
93 eval([props{i},'=handles.',props{i},';']);
\r
96 % Insert xvars into the data objects
\r
97 data_objects={'f','gu','gw','h','hu'};
\r
98 for i=1:length(data_objects)
\r
99 eval(['set(', data_objects{i}, ', ''xvars'', xvars);']);
\r
102 % Set the varsize, if it exists. If not - do nothing!
\r
103 noise={'w','w','w','e','e'};
\r
104 for i=1:length(data_objects)
\r
105 varsize=[handles.states, 1, parenthandles.usize, eval(sprintf('get(%s,''n'')',noise{i}))];
\r
107 eval(['set(', data_objects{i}, ', ''varsize'', varsize);'], ';');
\r
110 % Insert the new objects into the model
\r
111 for i=1:length(props)
\r
112 eval(['set(obj, ''', props{i}, ''', ', props{i}, ');']);
\r
115 model_objects=parenthandles.model_objects;
\r
116 model_objects{handles.caller}=obj;
\r
117 parenthandles.model_objects=model_objects;
\r
118 guidata(parentfig,parenthandles);
\r
120 eval(handles.callback);
\r
127 if strcmp(action,'rnd_edit')
\r
129 caller=varargin{1};
\r
130 rnd_edit_property=[caller, '_edit'];
\r
131 str=get(handles.(rnd_edit_property),'String');
\r
134 % Undefined object! We'll try to assign the expression to the correct class
\r
135 if isa(handles.(caller), 'double')
\r
136 % The object is undefined!
\r
137 handles.(caller)=gauss;
\r
138 guidata(hObject,handles);
\r
139 model_action_update_select(hObject,caller,'rndtypes','R_str');
\r
140 handles=guidata(hObject);
\r
144 handles.(caller)=set(handles.(caller),'R_str',str);
\r
145 str=get(handles.(caller),'R_str');
\r
146 set(handles.(rnd_edit_property),'String',str);
\r
151 % set(handles.(rnd_edit_property),'String',num2str2(R));
\r
152 % dobj=handles.(caller);
\r
154 % handles.(caller)=dobj;
\r
156 % msgbox('Error! Not a valid covariance matrix');
\r
162 if strcmp(action,'states_edit')
\r
163 handles.x0=str2num(get(handles.edit_x0,'String'));
\r
164 handles.states=str2num(get(handles.edit_states,'String'));
\r
165 handles.xvars=cellstr2cell(get(handles.edit_xvars,'String'));
\r
166 guidata(hObject,handles);
\r
168 model_edit_states('init', hObject, ['danl_action(',num2str(hObject),',''states_refresh'')']);
\r
171 if strcmp(action,'states_refresh')
\r
172 % handles.x0=str2num(get(handles.edit_x0,'String'));
\r
173 % handles.states=str2num(get(handles.edit_states,'String'));
\r
174 % handles.xvars=cellstr2cell(get(handles.edit_xvars,'String'));
\r
175 % guidata(hObject,handles);
\r
177 % model_edit_states('init', hObject);
\r
179 set(handles.edit_states,'String',num2str(handles.states));
\r
180 set(handles.edit_x0,'String',num2str2(handles.x0));
\r
181 set(handles.edit_xvars,'String',cell2cellstr(handles.xvars));
\r
183 guidata(hObject,handles);
\r
184 model_generate_p0(hObject);
\r
185 handles=guidata(hObject);
\r
188 if strcmp(action,'T_edit')
\r
189 T=str2num(get(handles.T_edit,'String'));
\r
191 msgbox('T must be positive!');
\r
195 set(handles.T_edit,'String',num2str(T)); % Format data
\r
198 if strcmp(action,'statenr_edit')
\r
199 states=str2num(get(handles.edit_states,'String'));
\r
201 msgbox('The amount of states must be positive!');
\r
205 % x0=str2num(get(handles.x0,'String'));
\r
206 % xvars=cellstr2cell(get(handles.xvars,'String'));
\r
209 xvars=handles.xvars;
\r
211 states_old=length(xvars);
\r
212 sdiff=states-states_old;
\r
216 x0(end+1:states)=0;
\r
217 for i=states_old+1:states
\r
218 xvars{i}=['x',num2str(i)];
\r
221 % Delete some states
\r
223 xvars=xvars(1:states);
\r
225 % Nothing has changed. Do nothing.
\r
230 % A row vector! Let's transpone it.
\r
234 set(handles.edit_xvars,'String',cell2cellstr(xvars));
\r
235 set(handles.edit_x0,'String',num2str2(x0));
\r
237 handles.states=states;
\r
239 handles.xvars=xvars;
\r
241 guidata(hObject,handles);
\r
242 model_generate_p0(hObject);
\r
243 handles=guidata(hObject);
\r
246 if strcmp(action,'xvars_edit')
\r
247 xvars=cellstr2cell(get(handles.edit_xvars,'String'));
\r
248 if length(xvars)~=handles.states
\r
249 msgbox('Error! The amount of elements in ''xvars'' must be equal to the amount of states.');
\r
252 handles.xvars=xvars;
\r
254 set(handles.edit_xvars,'String',cell2cellstr(xvars)); % Format data
\r
257 if strcmp(action,'x0_edit')
\r
258 x0=str2num(get(handles.edit_x0,'String'));
\r
261 msgbox('''x0'' must be one-dimensional!');
\r
265 if length(x0)~=handles.states
\r
266 msgbox('Error! The amount of elements in ''x0'' must be equal to the amount of states.');
\r
271 % A row vector! Let's transpone it.
\r
277 set(handles.edit_x0,'String',num2str2(x0)); % Format data
\r
280 if strcmp(action,'objedit')
\r
281 caller=varargin{1};
\r
282 dobj=handles.(caller);
\r
283 if isa(dobj,'double')
\r
284 msgbox('Error! Can not edit an undefined object.');
\r
286 function_str=[class(dobj),'_edit'];
\r
287 feval(function_str,'init',hObject,dobj,caller,['danl_action(',num2str(hObject),',''obj_refresh'',''',caller,''')']);
\r
291 if strcmp(action,'rnd_objedit')
\r
292 caller=varargin{1};
\r
293 robj=handles.(caller);
\r
294 if isa(robj,'double')
\r
295 msgbox('Error! Can not edit an undefined object.');
\r
297 function_str=[class(robj),'_edit'];
\r
298 feval(function_str,'init',hObject,robj,caller,['danl_action(',num2str(hObject),',''rnd_refresh'',''',caller,''')']);
\r
303 if strcmp(action,'obj_refresh')
\r
304 caller=varargin{1};
\r
305 str=get(handles.(caller),'str');
\r
306 rnd_edit_property=[caller,'_edit'];
\r
307 set(handles.(rnd_edit_property),'String',str);
\r
309 obj=handles.(caller);
\r
311 if isa(obj,'xlinear')
\r
312 evalvar=get(obj,'evalvar');
\r
313 if sum(find(evalvar==1))>0
\r
318 set(handles.([caller,'_checkbox']),'value',evalvar);
\r
322 if strcmp(action,'rnd_refresh')
\r
323 caller=varargin{1};
\r
324 str=get(handles.(caller),'R_str');
\r
325 rnd_edit_property=[caller,'_edit'];
\r
326 set(handles.(rnd_edit_property),'String',str);
\r
330 if strcmp(action,'select')
\r
332 caller=varargin{1};
\r
333 select_property=[caller, '_select'];
\r
334 edit_property=[caller, '_edit'];
\r
336 datatypes=handles.datatypes;
\r
337 index=get(handles.(select_property),'value')-1;
\r
338 % set(handles.(edit_property),'String','');
\r
341 handles.(caller)=eval(datatypes{index});
\r
342 % Default f and h xlinear objects have evalvar=1
\r
343 if isa(handles.(caller),'xlinear');
\r
344 if findcstr({'f','h'},caller)
\r
345 obj=handles.(caller);
\r
346 set(obj,'evalvar',1);
\r
347 handles.(caller)=obj;
\r
351 handles.(caller)=[];
\r
353 set(handles.(edit_property),'String',get(handles.(caller),'str'));
\r
355 guidata(hObject,handles);
\r
356 i=findcstr(handles.dnames,caller);
\r
357 danl_update_checkbox(hObject,i);
\r
358 handles=guidata(hObject); % FIX: UGLY (last row...)
\r
361 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
379 if strcmp(action,'import_button')
\r
380 objects={'f','gw','gu','h','hu','w','e','p0'};
\r
381 import_select=get(handles.import_select,'Value');
\r
382 caller=objects{import_select};
\r
383 import_edit=get(handles.import_edit,'String');
\r
385 if isempty(import_edit)
\r
386 % The edit control is blank
\r
387 msgbox('No object name was specified!');
\r
389 data=evalin('base',import_edit,'[]');
\r
390 if isa(data,'logical')
\r
391 msgbox('Error! There was no object returned.');
\r
393 % Object imported successfully
\r
394 if isa(data,'double')
\r
398 data=xlinear(data);
\r
399 if strcmp(caller,'f')||strcmp(caller,'h')
\r
400 set(data,'evalvar',1);
\r
403 elseif isa(data,'char')||isa(data,'inline')||isa(data,'sym')||isa(data,'cell')
\r
405 msgbox('Sorry, this datatype is not convertable to a noise object');
\r
408 data=xsymbolic(data);
\r
411 handles.(caller)=data;
\r
412 guidata(hObject,handles);
\r
414 model_action_update_select(hObject,caller,'rndtypes','R_str');
\r
416 model_action_update_select(hObject,caller,'datatypes','str');
\r
417 danl_update_checkbox(hObject,caller);
\r
419 handles=guidata(hObject); % FIX: UGLY (last row...)
\r
425 guidata(hObject,handles);