1 function xltv_edit(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 %myfont='FixedWidth';
\r
24 if strcmp(action,'init');
\r
25 parentfig=varargin{1};
\r
28 callback=varargin{4};
\r
30 % Make the GUI show the correct information
\r
31 if strcmp(caller,'h')||strcmp(caller,'hu')
\r
32 if strcmp(obj.wchar,'w')
\r
33 set(obj,'wchar','e');
\r
36 if strcmp(obj.wchar,'e')
\r
37 set(obj,'wchar','w');
\r
42 evalvar=obj.evalvar;
\r
44 evalvarvec=zeros(1,4);
\r
46 if sum(find(evalvar==i))
\r
53 interpolate=obj.interpolate;
\r
60 t_first=num2str(Ts(1));
\r
61 t_last=num2str(Ts(end));
\r
64 hf=figure('Name','xltv object editor');
\r
66 uicontrol('Style','Text','String','3d expression matrix:','Units','normalized','Position',[0.0,0.8,0.4,0.05],'HorizontalAlign','Left','Fontname',myfont);
\r
67 uicontrol('Style','Edit','String','','Units','normalized','Position',[0.4,0.8,0.4,0.05],'Tag','expression_edit','Callback',['xltv_edit(''expression_import'',',num2str(hf),')'],'Fontname',myfont);
\r
68 uicontrol('Style','Pushbutton','String','Import','Units','normalized','Position',[0.85,0.8,0.15,0.05],'Callback',['xltv_edit(''expression_import'',',num2str(hf),')'],'Fontname',myfont);
\r
70 uicontrol('Style','Text','String','Sample point vector:','Units','normalized','Position',[0.0,0.72,0.4,0.05],'HorizontalAlign','Left','Fontname',myfont);
\r
71 uicontrol('Style','Edit','String','','Units','normalized','Position',[0.4,0.72,0.4,0.05],'Tag','Ts_edit','Callback',['xltv_edit(''Ts_import'',',num2str(hf),')'],'Fontname',myfont);
\r
72 uicontrol('Style','Pushbutton','String','Import','Units','normalized','Position',[0.85,0.72,0.15,0.05],'Callback',['xltv_edit(''Ts_import'',',num2str(hf),')'],'Fontname',myfont);
\r
80 uicontrol('Style','Text','String','Expression size:','Units','normalized','Position',[0.0,0.60,0.4,0.05],'HorizontalAlign','Left','Fontname',myfont);
\r
81 uicontrol('Style','Text','String',sprintf('%d x %d',size(array,1),size(array,2)),'Units','normalized','Position',[0.4,0.60,0.4,0.05],'Tag','expression_size','HorizontalAlign','Left','Fontname',myfont);
\r
82 uicontrol('Style','Text','String','Number of expressions:','Units','normalized','Position',[0.0,0.55,0.4,0.05],'HorizontalAlign','Left','Fontname',myfont);
\r
83 uicontrol('Style','Text','String',num2str(n),'Units','normalized','Position',[0.4,0.55,0.4,0.05],'Tag','expression_number','HorizontalAlign','Left','Fontname',myfont);
\r
84 uicontrol('Style','Text','String','Number of sample points:','Units','normalized','Position',[0.0,0.5,0.4,0.05],'HorizontalAlign','Left','Fontname',myfont);
\r
85 uicontrol('Style','Text','String',num2str(length(Ts)),'Units','normalized','Position',[0.4,0.5,0.4,0.05],'Tag','Ts_number','HorizontalAlign','Left','Fontname',myfont);
\r
86 uicontrol('Style','Text','String','First sample point:','Units','normalized','Position',[0.0,0.45,0.4,0.05],'HorizontalAlign','Left','Fontname',myfont);
\r
87 uicontrol('Style','Text','String',t_first,'Units','normalized','Position',[0.4,0.45,0.4,0.05],'Tag','Ts_first','HorizontalAlign','Left','Fontname',myfont);
\r
88 uicontrol('Style','Text','String','Last sample point:','Units','normalized','Position',[0.0,0.4,0.4,0.05],'HorizontalAlign','Left','Fontname',myfont);
\r
89 uicontrol('Style','Text','String',t_last,'Units','normalized','Position',[0.4,0.4,0.4,0.05],'Tag','Ts_last','HorizontalAlign','Left','Fontname',myfont);
\r
91 uicontrol('Style','Text','String','Interpolation:','Units','normalized','Position',[0.0,0.3,0.4,0.05],'HorizontalAlign','Left','Fontname',myfont);
\r
94 uicontrol('Style','Radiobutton','String','None','Value',~interpolate,'Units','normalized','Position',[0.4,0.3,0.2,0.05],'Tag','radio1','Callback',['xltv_edit(''radio1'',',num2str(hf),')'],'HorizontalAlign','Left','Fontname',myfont);
\r
95 uicontrol('Style','Radiobutton','String','Linear','Value',interpolate,'Units','normalized','Position',[0.6,0.3,0.2,0.05],'Tag','radio2','Callback',['xltv_edit(''radio2'',',num2str(hf),')'],'HorizontalAlign','Left','Fontname',myfont);
\r
97 uicontrol('Style','Text','String','Multiply by:','Units','normalized','Position',[0.0,0.2,0.2,0.05],'Fontname',myfont);
\r
98 % uicontrol('Style','Text','String','','Units','normalized','Position',[0.8,0.2,0.2,0.05],'Tag','vars','Fontname',myfont);
\r
99 uicontrol('Style','Text','String','','Units','normalized','Position',[0.0,0.15,0.2,0.05],'Tag','vars','Fontname',myfont);
\r
101 uicontrol('Style','Checkbox','String','x','Units','normalized','Value',evalvarvec(1),'Position',[0.4,0.2,0.06,0.05],'Tag','check_1','callback',['xltv_edit(''check'',',num2str(hf),')'],'Fontname',myfont);
\r
102 uicontrol('Style','Checkbox','String','t','Units','normalized','Value',evalvarvec(2),'Position',[0.5,0.2,0.06,0.05],'Tag','check_2','callback',['xltv_edit(''check'',',num2str(hf),')'],'Fontname',myfont);
\r
103 uicontrol('Style','Checkbox','String','u','Units','normalized','Value',evalvarvec(3),'Position',[0.6,0.2,0.06,0.05],'Tag','check_3','callback',['xltv_edit(''check'',',num2str(hf),')'],'Fontname',myfont);
\r
104 uicontrol('Style','Checkbox','String',obj.wchar,'Units','normalized','Value',evalvarvec(4),'Position',[0.7,0.2,0.06,0.05],'Tag','check_4','callback',['xltv_edit(''check'',',num2str(hf),')'],'Fontname',myfont);
\r
106 uicontrol('Style','Pushbutton','String','Save','Units','normalized','Position',[0.8,0.02,0.1,0.05],'Callback',['xltv_edit(''save'',',num2str(hf),')'],'Fontname',myfont);
\r
107 uicontrol('Style','Pushbutton','String','Cancel','Units','normalized','Position',[0.9,0.02,0.1,0.05],'Callback',['delete(',num2str(hf),')'],'Fontname',myfont);
\r
110 handles=guihandles(hf);
\r
111 handles.array=array;
\r
113 handles.caller=caller;
\r
114 handles.callback=callback;
\r
115 handles.parentfig=parentfig;
\r
116 handles.evalvar=evalvar;
\r
117 handles.interpolate=interpolate;
\r
119 handles.wchar=obj.wchar;
\r
120 guidata(hf,handles);
\r
122 xltv_edit('check',hf);
\r
125 elseif strcmp(action,'radio1')
\r
127 handles=guidata(hf);
\r
128 set(handles.radio1,'value',1);
\r
129 set(handles.radio2,'value',0);
\r
130 handles.interpolate=false;
\r
131 guidata(hf,handles);
\r
133 elseif strcmp(action,'radio2')
\r
135 handles=guidata(hf);
\r
136 set(handles.radio2,'value',1);
\r
137 set(handles.radio1,'value',0);
\r
138 handles.interpolate=true;
\r
139 guidata(hf,handles);
\r
141 elseif strcmp(action,'expression_import')
\r
143 handles=guidata(hf);
\r
144 expr_str=get(handles.expression_edit,'String');
\r
145 if isempty(expr_str)
\r
146 msgbox('Error! Empty field');
\r
149 array=evalin('base',expr_str,'[]');
\r
151 % An error occured while importing
\r
152 msgbox('Error! Did you type the correct name of the object?');
\r
154 elseif ~isa(array,'double')
\r
155 msgbox('Error! The object must be a matrix consisting of doubles!');
\r
157 elseif ndims(array)~=3
\r
158 msgbox('The data matrix must be three-dimensional!');
\r
161 set(handles.expression_size,'String',sprintf('%d x %d',size(array,1),size(array,2)));
\r
162 set(handles.expression_number,'String',num2str(size(array,3)));
\r
165 handles.array=array;
\r
166 guidata(hf,handles);
\r
168 elseif strcmp(action,'Ts_import')
\r
170 handles=guidata(hf);
\r
171 expr_str=get(handles.Ts_edit,'String');
\r
172 if isempty(expr_str)
\r
173 msgbox('Error! Empty field');
\r
176 Ts=evalin('base',expr_str,'[]');
\r
178 % An error occured while importing
\r
179 msgbox('Error! Did you type the correct name of the object?');
\r
181 elseif ~isa(Ts,'double')
\r
182 msgbox('Error! The object must be a matrix consisting of doubles!');
\r
184 elseif min(size(Ts,1),size(Ts,2))~=1||ndims(Ts)>2
\r
185 msgbox('The data matrix must be one-dimensional!');
\r
188 set(handles.Ts_number,'String',num2str(length(Ts)));
\r
189 set(handles.Ts_first,'String',num2str(Ts(1)));
\r
190 set(handles.Ts_last,'String',num2str(Ts(end)));
\r
194 guidata(hf,handles);
\r
196 elseif strcmp(action,'save')
\r
199 handles=guidata(hf);
\r
201 caller=handles.caller;
\r
204 if isempty(handles.array)
\r
205 msgbox('The expression array must not be empty!');
\r
209 if isempty(handles.Ts)
\r
210 msgbox('The sample points vector must not be empty!');
\r
214 if length(handles.Ts)~=size(handles.array,3)
\r
215 msgbox('Error! The number of expressions and the number of sample points must be equal!');
\r
219 if isempty(handles.evalvar)
\r
220 msgbox('An evaluation variable must be selected. Use ''xtable'' if no variable multiplication is desired.');
\r
224 % if handles.interpolation&&size(array,3)<2
\r
225 % msgbox('The number of expressions must be at least 2 in interpolation mode.');
\r
228 set(obj,'array',handles.array);
\r
229 set(obj,'Ts',handles.Ts);
\r
230 set(obj,'evalvar',handles.evalvar);
\r
231 set(obj,'interpolate',handles.interpolate);
\r
233 parentfig=handles.parentfig;
\r
234 parenthandles=guidata(parentfig);
\r
236 parenthandles.(caller)=obj;
\r
237 guidata(parentfig,parenthandles); % Save data
\r
239 eval(handles.callback);
\r
242 elseif strcmp(action,'check')
\r
245 handles=guidata(hf);
\r
248 varnames={'x','t','u',handles.wchar};
\r
250 for i=1:length(varnames)
\r
251 if get(handles.(['check_',num2str(i)]),'value')
\r
252 str=[str, varnames{i}, '; '];
\r
253 evalvar=[evalvar,i];
\r
259 str=['[', str, ']'];
\r
267 set(handles.vars,'String',str);
\r
268 handles.evalvar=evalvar;
\r
269 guidata(hf,handles);
\r