Initial commit
[pftoolbox.git] / GUI / sir_edit.m
blob0628af65b61c0087cc622373b9c3bafd3fb21960
1 function sir_edit(action, varargin)\r
2 % Sorry, I didn't have enough time to write nice and documented GUI code.\r
3 \r
4 % Toolbox for nonlinear filtering.\r
5 % Copyright (C) 2005  Jakob Rosén <jakob.rosen@gmail.com>\r
6 %\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
11 %\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
16 %\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='default';\r
22 %myfont='FixedWidth';\r
24 if strcmp(action,'init');\r
25         parentfig=varargin{1};\r
26         obj=varargin{2};\r
27         caller=varargin{3};\r
28         callback=varargin{4};\r
30         resample_functions={@rs_regularized, @rs_simple, @rs_stratified, @rs_systematic};\r
31         resample_names={'Residual resampling', 'Simple resampling', 'Stratified resampling', 'Systematic resampling'};\r
32         resample_str=cell2str(resample_names);\r
34         resampler_str=func2str(obj.resampler);\r
36         resample_value=2;\r
37         for i=1:length(resample_functions)\r
38                 if strcmp(resampler_str, func2str(resample_functions{i}))\r
39                         resample_value=i;\r
40                         break;\r
41                 end;\r
42         end;\r
44         N=obj.N;\r
46 %       hf=figure('Name','SIR object editor','NumberTitle','off','Units','normalized','Position',[0.3 0.5 0.5 0.4]);\r
47         hf=figure('Name','SIR object editor');\r
49 p=0.6;\r
51         uicontrol(hf,'Style','Text','String','Number of particles:','Units','normalized','Position',[0 p+0.15 0.3 0.05],'Fontname',myfont);\r
52         uicontrol(hf,'Style','Edit','String',num2str(N),'Units','normalized','Position',[0.3 p+0.15 0.18 0.05],'Callback',['sir_edit(''N_edit'',',num2str(hf),')'],'Tag','N_edit','Fontname',myfont);\r
54         uicontrol(hf,'Style','Text','String','Resampling function:','Units','normalized','Position',[0.0 p+0.07 0.3 0.05],'Fontname',myfont);\r
55         uicontrol(hf,'Style','Popup','String',resample_str,'Value',resample_value,'Units','normalized','Position',[0.3 p+0.07 0.4 0.05],'Tag','resampler_select','Fontname',myfont);\r
57 %       uicontrol(hf,'Style','Frame','Units','Characters','Position',[55 0 0.1 5]);\r
59         uicontrol('Style','Pushbutton','String','Save','Units','normalized','Position',[0.5,p+0.15,0.1,0.05],'Callback',['sir_edit(''save'',',num2str(hf),')'],'Fontname',myfont);\r
60         uicontrol('Style','Pushbutton','String','Cancel','Units','normalized','Position',[0.6,p+0.15,0.1,0.05],'Callback',['delete(',num2str(hf),')'],'Fontname',myfont);\r
62         handles=guihandles(hf);\r
63         handles.obj=obj;\r
64         handles.caller=caller;\r
65         handles.callback=callback;\r
66         handles.parentfig=parentfig;\r
67         handles.N=N;\r
68         handles.resample_functions=resample_functions;\r
69         guidata(hf,handles);\r
71 elseif strcmp(action,'save');\r
73         hf=varargin{1};\r
74         handles=guidata(hf);\r
76         caller=handles.caller;\r
77         obj=handles.obj;\r
79         resampler_index=get(handles.resampler_select,'value');\r
81         set(obj,'N',handles.N);\r
82         set(obj,'resampler',handles.resample_functions{resampler_index});\r
84         parentfig=handles.parentfig;\r
85         parenthandles=guidata(parentfig);\r
87         parenthandles.(caller)=obj;\r
88         guidata(parentfig,parenthandles);       % Save data\r
89         \r
90         eval(handles.callback);\r
91         close(hf)\r
93 elseif strcmp(action,'N_edit');\r
94         hf=varargin{1};\r
95         handles=guidata(hf);\r
97         N_str=get(handles.N_edit,'String');\r
98         if isempty(N_str)\r
99                 msgbox('Please enter a value');\r
100         end;\r
101         N=str2num(N_str);\r
102         if N<1\r
103                 msgbox('Please enter a POSITIVE value');\r
104                 return;\r
105         elseif round(N)~=N\r
106                 msgbox('Please enter a positive INTEGER');\r
107                 return;\r
108         end     \r
109         handles.N=N;\r
110         set(handles.N_edit,'String',num2str(N));        % Format\r
111         guidata(hf,handles);\r
112 end\r