comparison m-toolbox/m/gui/gltpda/g_LoadInputParamCallback.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 function g_LoadInputParamCallback(currPanel,varargin)
2 % This callback is called whenever the user selects an Input block. The
3 % callback draws the panel to set the only parameter associated to this
4 % type of block: the ordinal number of AO.
5
6 global LTPDAinvar selBlocks
7
8 backColor = get(currPanel, 'BackgroundColor');
9 panelDimens = get(currPanel, 'Position');
10
11 if length(LTPDAinvar)<1
12 % Text: 'Please load at least one AO in memory'
13 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-200)/2 panelDimens(4)-100 200 30],'String','Please load at least one AO in memory','Visible','on','Style','text');
14 % Button: 'Add data'
15 uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-200)/2 panelDimens(4)-150 200 30],'String','Add data','FontSize',guiFontSize+1,'Visible','on','Enable','on','Callback',@AddButtonCallback,'Style','pushbutton');
16 else
17 % Text: 'Obj input:'
18 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','left','Position',[100 panelDimens(4)-60 80 20],'String','Object input:','Visible','on','Style','text');
19 % Edit field:
20 children = get_param(gcb,'Blocks');
21 inputblock = strcat(gcb,'/',children{1});
22 currAOinput = get_param(inputblock,'Value');
23 uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[190 panelDimens(4)-57 50 20],'String',currAOinput,'Visible','on','Enable','on','Callback',@InputEditCallback,'Tag','inputEditField','Style','edit');
24
25 % Text: 'Objs list:'
26 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','left','Position',[20 panelDimens(4)-135 50 20],'String','Object list:','Visible','on','Style','text');
27 % Popup input objs list:
28 xx = size(LTPDAinvar,1);
29 listInput = cell(xx,1);
30 for j=1:xx
31 switch class(LTPDAinvar{j,1})
32 case 'ao'
33 anobject = LTPDAinvar{j,1};
34 aoname = anobject.name;
35 aocreated = char(anobject.created);
36 listInput{j,1} = [num2str(j) , ' . AO .' , aoname , '__' , aocreated];
37 case 'plist'
38 paramNumb = nparams(LTPDAinvar{j,1});
39 objcreated = char(LTPDAinvar{j,1}.created);
40 listInput{j,1}=[num2str(j),' . PLIST .',num2str(paramNumb),' params','__',objcreated];
41 case 'specwin'
42 listInput{j,1}=[num2str(j),' . SPECWIN .','__','no creation time'];
43 case 'pzmodel'
44 objcreated = char(LTPDAinvar{j,1}.created);
45 listInput{j,1}=[num2str(j),' . PZMODEL .','__',objcreated];
46 otherwise
47 if isa(LTPDAinvar{j,1},'ltpda_uo')
48 objclass = class(LTPDAinvar{j,1});
49 if ~isempty(LTPDAinvar{j,1}), listInput{j,1}=[num2str(j),' . ',objclass]; end
50 end
51 end
52 end
53 for j=xx:-1:1
54 if isempty(listInput{j,1})
55 listInput(j,:)=[];
56 end
57 end
58 inputPopup = uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[80 panelDimens(4)-130 500 20],'String',listInput,'Visible','on','Enable','on','Callback',@InputPopupCallback,'Tag','inputPopupField','Style','popup');
59
60 % Set the popup list on the proper line:
61 for ii = 1:size(listInput,1)
62 if str2double(deblank(strtok(listInput{ii}))) == str2double(currAOinput), break; end
63 end
64 set(inputPopup,'Value',ii);
65 end
66
67
68
69 %----------------------------------------------------------------------
70 function InputEditCallback(hObject, varargin)
71 % This callback is called whenever the user modify the input parameter
72 % associated to an Input block
73
74 if ~isempty(varargin{1}), newValue = varargin{1};
75 else newValue = str2double(get(hObject,'String'));
76 end
77 % Check it's an integer:
78 newValue = round(newValue);
79 % Check if the value is acceptable, ie:
80 % - if it's <length(LTPDAinvar)
81 if newValue>length(LTPDAinvar)
82 newValue=length(LTPDAinvar);
83 end
84 % - if it's a LTPDA valid object:
85 if ~isa(LTPDAinvar{newValue,1},'ltpda_uo')
86 children = get_param(gcbh,'Blocks');
87 inputblock = strcat(strcat(get(gcbh,'Path'),'/',get(gcbh,'Name')),'/',children{1});
88 oldValue = get_param(inputblock,'Value');
89 set(findobj('Tag','inputEditField'),'String',oldValue);
90 return
91 end
92
93 set(hObject,'String',num2str(newValue));
94
95 % Set the popup list on the proper line:
96 inputPopup = findobj('Tag','inputPopupField');
97 listInput = get(inputPopup,'String');
98 for mm = 1:size(listInput,1)
99 if str2double(deblank(strtok(listInput{mm}))) == newValue, break; end
100 end
101 set(inputPopup,'Value',mm);
102
103 % Object name for the annotation:
104 objName = LTPDAinvar{newValue,1}.name;
105 if numel(objName)>3 && strcmpi(objName,'none'), objName = class(LTPDAinvar{newValue,1}); end
106 if numel(objName)>20, objName = ['...',LTPDAinvar{newValue,1}.name(end-20:end)]; end
107 objName = [num2str(newValue),': ',objName];
108
109 for i=1:length(selBlocks)
110 % Since all input blocks are masks, and we want to change the
111 % value deep inside a block INSIDE this mask, we can't use the
112 % direct handles but the following:
113 children{i}=get_param(selBlocks(i),'Blocks');
114 inputblock=strcat(strcat(get(selBlocks(i),'Path'),'/',get(selBlocks(i),'Name')),'/',children{i}{1});
115 set_param(inputblock,'Value',num2str(newValue));
116 % Set the annotation:
117 set_param(selBlocks(i),'AttributesFormatString',objName);
118 % Set the MaskDisplay = n° of input
119 set_param(selBlocks(i),'MaskDisplay',sprintf('disp(''%s'')',num2str(newValue)));
120 end
121 end
122 %----------------------------------------------------------------------
123
124 %----------------------------------------------------------------------
125 function InputPopupCallback(hObject, varargin)
126 % This callback is called whenever the user clicks on the input list in
127 % the parameters panel asociated to the 'Input Obj' block
128
129 val = get(hObject, 'Value');
130 objLines = get(hObject, 'String');
131 objnumb = str2double(deblank(strtok(objLines{val})));
132
133 InputEditCallback(findobj('Tag','inputEditField'),objnumb);
134
135 end
136 %----------------------------------------------------------------------
137
138 %----------------------------------------------------------------------
139 function AddButtonCallback(varargin)
140 % Callback function: run when the user click the "Add data" button
141
142 filenames = uipickfiles('REFilter','.txt');
143 if ~isempty(filenames) && ~isnumeric(filenames(1,1))
144 [x,y]=size(filenames);
145 for nn=1:y
146 anobject = {ao(filenames{nn}),1,'From file'};
147 LTPDAinvar = [LTPDAinvar;anobject];
148 end
149 disp(sprintf(' + %g AOs added to the global variable LTPDAinvar', y))
150 ltpdagui('Redraw',2);
151 end
152 end
153 %----------------------------------------------------------------------
154
155
156 end