1 function model_edit_uvars(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 % replace 'uvars', 'u'
\r
25 if strcmp(action,'init')
\r
26 callback=varargin{2};
\r
27 parentfig=varargin{1};
\r
28 parenthandles=guidata(parentfig);
\r
30 uvars=parenthandles.uvars;
\r
32 hf=figure('Name','u(t) component editor');
\r
34 uicontrol('Style','Pushbutton','String','Save','Units','Normalized','Position',[0.8,0.02,0.1,0.05],'Callback',['model_edit_uvars(''save'',',num2str(hf),')'],'Fontname',myfont);
\r
35 uicontrol('Style','Pushbutton','String','Cancel','Units','Normalized','Position',[0.9,0.02,0.1,0.05],'Callback',['delete(',num2str(hf),')'],'Fontname',myfont);
\r
37 uicontrol(hf,'Style','Text','String','Element','Units','normalized','Position',[0.0 0.9 0.2 0.05],'HorizontalAlign','Left','Fontname',myfont);
\r
38 uicontrol(hf,'Style','Text','String','Name','Units','normalized','Position',[0.2 0.9 0.3 0.05],'HorizontalAlign','Left','Fontname',myfont);
\r
40 uicontrol(hf,'Style','Frame','Units','normalized','Position',[0.0 0.88 1 0.003]);
\r
43 uicontrol(hf,'Style','Frame','Units','normalized','Position',[0.0 0.1 1 0.003]);
\r
44 uicontrol(hf,'Style','Text','String','Elements:','Units','normalized','Position',[0.0 0.02 0.20 0.05],'HorizontalAlign','Left','Fontname',myfont);
\r
45 handles=guihandles(hf);
\r
46 handles.edit_statenumber=uicontrol(hf,'Style','Edit','String',num2str(length(uvars)),'Units','normalized','Position',[0.2 0.02 0.1 0.05],'callback',['model_edit_uvars(''changenumber'',' ,num2str(hf), ')'],'Fontname',myfont);
\r
48 handles.uvars=uvars;
\r
49 handles.states=length(uvars);
\r
50 handles.parentfig=parentfig;
\r
51 handles.callback=callback;
\r
52 guidata(hf,handles);
\r
54 model_edit_uvars('update',hf);
\r
56 elseif strcmp(action,'save')
\r
59 handles=guidata(hf);
\r
61 uvars=cell(1,handles.states);
\r
63 for i=1:handles.states
\r
64 name_str=get(handles.(['name_',num2str(i)]),'String');
\r
66 if isempty(name_str)
\r
67 msgbox('Error! A field is empty');
\r
74 parentfig=handles.parentfig;
\r
75 parenthandles=guidata(parentfig);
\r
77 parenthandles.uvars=uvars;
\r
79 guidata(parentfig,parenthandles); % Save data
\r
81 eval(handles.callback);
\r
84 elseif strcmp(action,'changenumber')
\r
88 handles=guidata(hf);
\r
89 states=str2num(get(handles.edit_statenumber,'String'));
\r
90 states_old=length(handles.uvars);
\r
91 sdiff=states-states_old;
\r
93 uvars=handles.uvars;
\r
97 for i=states_old+1:states
\r
98 uvars{i}=['u',num2str(i)];
\r
101 % Delete some states
\r
102 uvars=uvars(1:states);
\r
104 % Nothing has changed. Do nothing.
\r
108 handles.uvars=uvars;
\r
109 handles.states=states;
\r
110 guidata(hf,handles);
\r
113 model_edit_uvars('update',hf);
\r
115 elseif strcmp(action,'update')
\r
118 handles=guidata(hf);
\r
120 uvars=handles.uvars;
\r
122 % Remove old controls
\r
124 while isfield(handles,['number_',num2str(i)])
\r
125 delete(handles.(['number_',num2str(i)]));
\r
126 delete(handles.(['name_',num2str(i)]));
\r
127 handles=rmfield(handles,['number_',num2str(i)]);
\r
128 handles=rmfield(handles,['name_',num2str(i)]);
\r
137 for i=1:length(uvars)
\r
140 handles.(['number_',num2str(i)])=uicontrol(hf,'Style','Text','String',num2str(i),'Units','normalized','Position',[0.0 postop-space*pos 0.1 0.05],'Fontname',myfont);
\r
141 handles.(['name_',num2str(i)])=uicontrol(hf,'Style','Edit','String',str,'Units','normalized','Position',[0.2 postop-space*pos 0.6 0.05],'Fontname',myfont);
\r
145 guidata(hf,handles);
\r