Mercurial > hg > ltpda
comparison m-toolbox/m/gui/gltpda/pan2param.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 pan2param(varargin) | |
2 % This is the GUI m-file able to read the list of parameters to be set for | |
3 % the function/block currently selected and to build the window with the | |
4 % parameters panel accordingly. | |
5 % | |
6 % $Id: pan2param.m,v 1.64 2009/02/01 17:20:04 nicola Exp $ | |
7 | |
8 global oldparams params paramEnabled oldparamEnabled paramSets currPanel | |
9 global LTPDAinvar selBlocks objName noParamsReq functionName guiFontSize %#ok<NUSED> | |
10 | |
11 %% | |
12 | |
13 currPanel = varargin{1}; | |
14 panelDimens = get(currPanel, 'Position'); | |
15 backColor = get(currPanel, 'BackgroundColor'); | |
16 selBlocks = 0; | |
17 set(gcf,'NextPlot','new'); | |
18 GUIprefs = getappdata(0, 'GUIpreferences'); | |
19 if ~isfield(GUIprefs,'CAD'), GUIprefs.CAD = 0; end | |
20 if ~isfield(GUIprefs,'Copied'), GUIprefs.Copied = 0; end | |
21 if ~isfield(GUIprefs,'Detach'), GUIprefs.Detach = 0; end | |
22 setappdata(0, 'GUIpreferences',GUIprefs); | |
23 | |
24 guiFontSize = getappdata(0, 'ltpda_gui_fontsize'); | |
25 if isempty(guiFontSize), guiFontSize = 10; setappdata(0, 'ltpda_gui_fontsize',10); end | |
26 set(gcf,'NextPlot','new') | |
27 alltimers = timerfindall; | |
28 stop(alltimers(1)); | |
29 set(alltimers(1),'TimerFcn',@g_ContinuousParamCheck,'Period',0.3); | |
30 start(alltimers(1)); | |
31 | |
32 | |
33 %% | |
34 %---------------------------------------------------------------------- | |
35 function buildplistFigureParam(varargin) | |
36 %---------------------------------------------------------------------- | |
37 panelDimens = get(currPanel, 'Position'); | |
38 lineSpacing = 25 * guiFontSize/10; | |
39 setappdata(0,'ltpda_gui_LineSpacing',lineSpacing); | |
40 if ~isempty(findobj(gcf,'Tag','apply')) | |
41 notredrawn = 0; undoStatus = get(findobj(gcf,'Tag','undo'),'enable'); | |
42 % deletes only the dynamical part of the panel: | |
43 for i = 1:numel(objName), try delete(objName{i}); catch, end; end | |
44 delete(findobj('Parent',currPanel,'TooltipString','Remove this parameter')) | |
45 else | |
46 notredrawn = 1; undoStatus = 'off'; | |
47 % deletes all, to redraw the entire panel: | |
48 delete(findobj(gcf,'Parent',currPanel)); | |
49 end | |
50 objName = []; | |
51 close(findobj('Tag','expandedEditField')) | |
52 if notredrawn % Executes the STATIC part too only if it's not just an update of the panel | |
53 | |
54 % ========================================================================= | |
55 % ========================================================================= | |
56 % ========================== Build STATIC panel =========================== | |
57 % ========================================================================= | |
58 % ========================================================================= | |
59 | |
60 % ------------------------------------------------------------------------- | |
61 % Retrieve the parameters: | |
62 % ------------------------------------------------------------------------- | |
63 if isempty(oldparams) && isempty(params) % the user has just selected another block | |
64 paramcommand = get_param(gcbh,'Description'); | |
65 noParamsReq=0; | |
66 if isempty(paramcommand) | |
67 paramcommand = g_RetrievePlist(); | |
68 selBlocks = utils.prog.gcbsh; | |
69 for kk=1:length(selBlocks) | |
70 set_param(selBlocks(kk),'Description',paramcommand); | |
71 end | |
72 end | |
73 eval(paramcommand) | |
74 if ~isempty(oldparams), params = oldparams; end | |
75 oldparamEnabled = paramEnabled; | |
76 end | |
77 | |
78 if ~exist('paramEnabled','var') && isempty(find(params,'Sets')) && noParamsReq==0 | |
79 paramEnabled = zeros(1,nparams(params)); | |
80 oldparamEnabled = paramEnabled; | |
81 end | |
82 childpath = find_system(gcbh,'LookUnderMasks','all','BlockType','M-S-Function'); | |
83 setappdata(0,'ltpda_currFunctionName',get_param(childpath,'Tag')); | |
84 | |
85 y = nparams(params); | |
86 | |
87 if y==0 && ~exist('paramSets','var') && noParamsReq==0 | |
88 paramcommand=[paramcommand,'noParamsReq=1;']; | |
89 selBlocks = utils.prog.gcbsh; | |
90 for kk=1:length(selBlocks), set_param(selBlocks(kk),'Description',paramcommand); end | |
91 buildplistFigureParam([],[],get(findobj('Tag','paramsPage'),'UserData')) | |
92 end | |
93 | |
94 % ------------------------------------------------------------------------- | |
95 % Fixed buttons: | |
96 % ------------------------------------------------------------------------- | |
97 % Help Button | |
98 uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[20 10 45 guiFontSize*16/10],'FontAngle','italic','FontSize',guiFontSize,'String','?','TooltipString','Open the Help associated to this function','Visible','on','Callback',@g_HelpButtonCallback,'Style','pushbutton'); | |
99 % Reset Parameters Button | |
100 uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[75 10 75 guiFontSize*16/10],'FontAngle','italic','FontSize',guiFontSize,'String','Reset','TooltipString','Reset the parameters for this block','Visible','on','Callback',@g_ResetButtonCallback,'Style','pushbutton'); | |
101 % 'Set name' checkbox: | |
102 setName = get(gcbh,'UserData'); | |
103 if isempty(setName), setName = 0; end | |
104 uicontrol('Parent',currPanel,'Units','pixels','BackgroundColor',backColor,'HorizontalAlignment','left','Position',[170 10 140 guiFontSize*16/10],'FontAngle','italic','FontSize',guiFontSize-2,'String','Set name','TooltipString','Set the signal name equal to the block name','Visible','on','Callback',@g_SetNameCallback,'Value',setName,'Style','checkbox'); | |
105 % Keep local result | |
106 probe = get_param(gcbh,'MaskHelp'); | |
107 if ~isempty(probe) && isa(probe,'char') && strcmp(probe,'probe'), keepRes = 1; else keepRes = 0; end | |
108 uicontrol('Parent',currPanel,'Units','pixels','BackgroundColor',backColor,'HorizontalAlignment','left','Position',[250 10 220 guiFontSize*16/10],'FontAngle','italic','FontSize',guiFontSize-2,'String','Keep local result','TooltipString','Do not delete the result of this block at the end of the analysis calculation','Visible','on','Callback',@g_KeepResultCallback,'Value',keepRes,'Style','checkbox'); | |
109 % Number of data inputs: | |
110 uicontrol('Parent',currPanel,'TooltipString','Set the number of input expected by this block','BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','right','Position',[370 5 70 guiFontSize*20/10],'String','Inputs: ','FontAngle','italic','FontSize',guiFontSize-2,'Visible','on','Style','text'); | |
111 paramFromSimulink = 0; | |
112 for ii=1:y | |
113 paramkeys{ii} = params.params(ii).key; | |
114 paramvals{ii} = params.params(ii).val; | |
115 if isa(paramvals{ii},'char') && numel(paramvals{ii})>2 && strcmp(paramvals{ii},'-->'), paramFromSimulink = paramFromSimulink + 1; end | |
116 end | |
117 inports = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Inport'); | |
118 uicontrol('Parent',currPanel,'TooltipString','Set the number of input expected by this block','BackgroundColor',backColor,'Units','pixels','Position',[450 8 40 guiFontSize*20/10],'String',num2str(numel(inports)-paramFromSimulink),'FontSize',guiFontSize,'Visible','on','Enable','on','UserData',numel(inports)-paramFromSimulink,'Callback',@g_numberDataInput,'Tag','numbDataInputs','Style','edit'); | |
119 | |
120 % The function has different sets of parameters: | |
121 if exist('paramSets','var') && ~isempty(paramSets) | |
122 sets = find(paramSets,'sets'); | |
123 currSet = find(paramSets,'currSet'); | |
124 % Sets popup menu: | |
125 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[40 panelDimens(4)-30 250 20],'String',sets,'Value',currSet,'Visible','on','UserData',sets,'Callback',@g_SetsUpdate,'Style','popup'); | |
126 panelDimens(4) = panelDimens(4)-20; | |
127 end | |
128 | |
129 % ------------------------------------------------------------------------- | |
130 % Button to add user-defined params: | |
131 % ------------------------------------------------------------------------- | |
132 paramTypes = {'double/char','specwin','pzmodel','-->'}; | |
133 for kk=1:y, paramTypes(strmatch(class(params.params(kk).val),paramTypes,'exact'))=[]; end | |
134 paramTypes = [paramTypes(1:end-1),{'pz','unit'},paramTypes(end)]; | |
135 % ParamType popup | |
136 hparamType = uicontrol('Parent',currPanel,'Tag','addparamspopup','TooltipString','Add a user-defined parameter','BackgroundColor',backColor,'Units','pixels','Position',[20 40 100 20],'String',paramTypes,'Value',1,'Visible','on','Enable','on','Style','popupmenu'); | |
137 % Add params button | |
138 uicontrol('Parent',currPanel,'TooltipString','Add a user-defined parameter','Units','pixels','Position',[130 40 20 20],'String','+','Visible','on','Enable','on','Callback', @g_AddParamCallback,'UserData',hparamType,'Style','pushbutton'); | |
139 | |
140 % ------------------------------------------------------------------------- | |
141 % Buttons to apply or undo: | |
142 % ------------------------------------------------------------------------- | |
143 % Apply button | |
144 uicontrol('Parent',currPanel,'Units','pixels','Position',[panelDimens(3)-70 40 60 guiFontSize*20/10],'HorizontalAlignment','right','FontSize',guiFontSize,'String','Apply','Visible','on','Enable','off','Callback', @g_ApplyButtonCallback,'DeleteFcn',{@g_ApplyButtonCallback,0},'UserData',hparamType,'Tag','apply','Style','pushbutton'); | |
145 % Undo button | |
146 uicontrol('Parent',currPanel,'Units','pixels','Position',[panelDimens(3)-70 10 60 guiFontSize*20/10],'HorizontalAlignment','right','FontSize',guiFontSize,'String','Undo','Visible','on','Enable',undoStatus,'Callback', @g_UndoButtonCallback,'UserData',hparamType,'Tag','undo','Style','pushbutton'); | |
147 | |
148 | |
149 paramPagePosition = panelDimens + [3 65+guiFontSize*16/10 -6 -(80+guiFontSize*16/10)]; | |
150 | |
151 else % The part above was executed only if it's not an update of the panel | |
152 y = nparams(params); | |
153 for pp=1:y | |
154 paramkeys{pp} = params.params(pp).key; | |
155 paramvals{pp} = params.params(pp).val; | |
156 end | |
157 if exist('paramSets','var') && ~isempty(paramSets), panelDimens(4) = panelDimens(4)-20; end | |
158 paramPagePosition = panelDimens + [3 65+guiFontSize*16/10 -6 -(80+guiFontSize*16/10)]; | |
159 end | |
160 | |
161 | |
162 if nargin>2 && isa(varargin{3},'cell'), varargin{3} = varargin{3}{1}; end | |
163 if nargin<3, currPage = 1; else currPage = varargin{3}; if isa(currPage,'cell'), currPage = currPage{1}; end; end | |
164 uipanel('Parent',currPanel,'BackgroundColor',backColor,'FontSize',7,'Units','pixels','Position',paramPagePosition,'Tag','paramsPage','UserData',currPage); | |
165 | |
166 GUIprefs = getappdata(0, 'GUIpreferences'); | |
167 % Check if the parameters panel has to be drawn detached: | |
168 if GUIprefs.Detach | |
169 drawn = g_drawParPanel(); | |
170 if drawn, return; end; | |
171 end | |
172 | |
173 | |
174 | |
175 % ========================================================================= | |
176 % ========================================================================= | |
177 % ========================= Build DYNAMIC panel =========================== | |
178 % ========================================================================= | |
179 % ========================================================================= | |
180 | |
181 totalGaps = 0; | |
182 paramThisPage = 0; | |
183 lastParamGap = 0; | |
184 paramPages = []; | |
185 for ii=1:y | |
186 paramThisPage = paramThisPage+1; | |
187 % ------------------------------------------------------------------------- | |
188 % Cycle to verify whether gaps (= extra lines for complex params, such as | |
189 % pzmodels) are necessary or not: | |
190 switch class(paramvals{ii}) | |
191 case 'pzmodel' | |
192 if numel(paramvals{ii}.poles)>1 || numel(paramvals{ii}.zeros)>1 | |
193 totalGaps = totalGaps+1; | |
194 lastParamGap = 1; | |
195 end | |
196 case 'pz' | |
197 if numel(paramvals{ii})>1 | |
198 totalGaps = totalGaps+1; | |
199 lastParamGap = 1; | |
200 end | |
201 end | |
202 % ------------------------------------------------------------------------- | |
203 % Check if it's necessary to draw multiple parameters pages: | |
204 if (paramThisPage+totalGaps)*lineSpacing > paramPagePosition(4)-20 | |
205 paramPages = [paramPages , paramThisPage-1]; | |
206 if ii==y, paramPages = [paramPages,1]; end | |
207 paramThisPage = 1; | |
208 totalGaps = lastParamGap; | |
209 lastParamGap = 0; | |
210 elseif ii==y | |
211 paramPages = [paramPages , paramThisPage]; | |
212 end | |
213 end | |
214 | |
215 currGap = 0; | |
216 % The vector 'paramPages' contains how many params are contained into every page. | |
217 if numel(paramPages) > 1 | |
218 set(findobj('Tag','paramsPage'),'Title',['Page number ', num2str(currPage)] ); | |
219 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Tag','gotoparamspage','HorizontalAlignment','left','Position',[200 39 100 20],'String','Go to page: ','FontName','Times New Roman','FontSize',guiFontSize+2,'FontWeight','bold','Visible','on','Style','text'); | |
220 for ii = 0:numel(paramPages)-1 | |
221 uicontrol('Parent',currPanel,'Tag','gotoparamspage','Units','pixels','Position',[300+ii*(30) 40 20 20],'String',num2str(ii+1),'Visible','on','Enable','on','Callback', {@buildplistFigureParam,ii+1},'Style','pushbutton'); | |
222 end | |
223 elseif numel(paramPages) == 1 | |
224 delete(findobj('Tag','gotoparamspage')) | |
225 elseif isempty(paramPages) | |
226 paramPages = 0; | |
227 end | |
228 firstParam = 1; | |
229 if nargin>1 | |
230 if varargin{3}>numel(paramPages), varargin{3} = numel(paramPages); end | |
231 for ii = 1:varargin{3}-1 | |
232 firstParam = firstParam + paramPages(ii); | |
233 end | |
234 lastParam = firstParam + paramPages(varargin{3})-1; | |
235 else | |
236 lastParam = paramPages(1); | |
237 end | |
238 currParam = 0; | |
239 | |
240 for ii = firstParam:lastParam | |
241 currParam = currParam + 1; | |
242 addedPar = 0; | |
243 % Checkbox to enable input setting: | |
244 objName{ii,1} = uicontrol('Parent',currPanel,'Units','pixels','Position',[10,panelDimens(4)-lineSpacing*(currParam+1+currGap),14,14],'Value',paramEnabled(ii),'Visible','on','Enable','on','Callback', @g_EnableCallback,'Tag',paramkeys{ii},'UserData',ii,'Style','checkbox'); | |
245 % Remove Param Button: | |
246 try %#ok<ALIGN> | |
247 if strcmpi(paramkeys{ii}(1:7),'addPar_') | |
248 uicontrol('Parent',currPanel,'Units','pixels','Position',[panelDimens(3)-30 panelDimens(4)-lineSpacing*(currParam+1+currGap) 20 20],'String','-','TooltipString','Remove this parameter','Visible','on','Enable','on','UserData',ii,'Callback', @g_RemParamCallback,'Style','pushbutton'); | |
249 addedPar = 1; | |
250 paramkeys{ii}(1:7) = []; | |
251 end | |
252 catch, end | |
253 | |
254 switch class(paramvals{ii}) | |
255 | |
256 % ========================================================================== | |
257 case {'double'} | |
258 % ========================================================================== | |
259 % Key value: | |
260 objName{ii,2} = uicontrol('Parent',currPanel,'TooltipString','Key (name of the parameter)','Units','pixels','Position',[50 panelDimens(4)-lineSpacing*(currParam+1+currGap) 120 guiFontSize*20/10],'String',paramkeys{ii},'FontSize',guiFontSize+1,'Visible','on','Enable','off','UserData',ii,'Callback',@g_editNameCallback,'Style','edit'); | |
261 if ~noParamsReq && ~addedPar | |
262 set(objName{ii,2},'Style','text','BackgroundColor',backColor,'Position',[50 panelDimens(4)-(4+lineSpacing*(currParam+1+currGap)) 120 20]); | |
263 end | |
264 % Val value: | |
265 data = mat2str(paramvals{ii}); | |
266 objName{ii,3} = uicontrol('Parent',currPanel,'TooltipString','Val (value of the parameter)','Units','pixels','Position',[200 panelDimens(4)-lineSpacing*(currParam+1+currGap) 200 guiFontSize*20/10],'String',data,'Fontsize',guiFontSize+1,'Visible','on','Enable','off','UserData',ii,'Callback',@g_editValueCallback,'Style','edit'); | |
267 objName{ii,4} = uicontrol('UserData',objName{ii,3},'TooltipString','Expand the edit field','Parent',currPanel,'BackgroundColor',[0.7 0.7 0.7],'HorizontalAlignment','left','Position',[405 panelDimens(4)+3-lineSpacing*(currParam+1+currGap) 13 13],'Visible','on','Callback',@g_ExpandEdit,'Style','pushbutton'); | |
268 % Enable parameters from Simulink: | |
269 objName{ii,10} = uicontrol('TooltipString','Retrieve from Simulink','String','From Simulink','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[450 panelDimens(4)-lineSpacing*(currParam+1+currGap) 120 20],'Max',1,'Min',0,'Value',0,'Visible','on','Tag',num2str(ii),'UserData',[],'Callback',@g_fromSimulinkCallback,'Style','checkbox'); | |
270 if strcmp(paramvals{ii},'-->') | |
271 set(objName{ii,3},'Visible','off'); | |
272 set(objName{ii,4},'Visible','off'); | |
273 set(objName{ii,10},'Value',1); | |
274 end | |
275 | |
276 % ========================================================================== | |
277 case {'char'} | |
278 % ========================================================================== | |
279 % Key value: | |
280 objName{ii,2} = uicontrol('Parent',currPanel,'Units','pixels','Position',[120 panelDimens(4)-lineSpacing*(currParam+1+currGap) 60 20],'String',paramkeys{ii},'FontSize',guiFontSize+1,'Visible','on','Enable','off','UserData',ii,'Callback',@g_editNameCallback,'Style','edit'); | |
281 if ~noParamsReq && ~addedPar | |
282 set(objName{ii,2},'Style','text','BackgroundColor',backColor,'Position',[50 panelDimens(4)-(4+lineSpacing*(currParam+1+currGap)) 120 20]); | |
283 end | |
284 if strcmpi(paramkeys{ii},'filename') | |
285 % Browse button: | |
286 currFilename = paramvals{ii}; | |
287 if isempty(currFilename), currFilename = 'Browse'; end | |
288 if numel(currFilename)>30, currFilename = ['...',currFilename(end-29:end)]; end | |
289 objName{ii,3} = uicontrol('Parent',currPanel,'Units','pixels','Position',[200 panelDimens(4)-lineSpacing*(currParam+1+currGap) 300 20],'String',currFilename,'Visible','on','Enable','off','Callback',@g_browseCallback,'Style','pushbutton'); | |
290 else | |
291 % Val value: | |
292 objName{ii,3} = uicontrol('Parent',currPanel,'Units','pixels','Position',[200 panelDimens(4)-lineSpacing*(currParam+1+currGap) 200 20],'String',['''',strrep(paramvals{ii},'''',''''''),''''],'Fontsize',guiFontSize+1,'Visible','on','Enable','off','UserData',ii,'Callback',@g_editValueCallback,'Style','edit'); | |
293 objName{ii,4} = uicontrol('UserData',objName{ii,3},'TooltipString','Expand the edit field','Parent',currPanel,'BackgroundColor',[0.7 0.7 0.7],'HorizontalAlignment','left','Position',[405 panelDimens(4)+3-lineSpacing*(currParam+1+currGap) 13 13],'Visible','on','Callback',@g_ExpandEdit,'Style','pushbutton'); | |
294 end | |
295 objName{ii,10} = uicontrol('TooltipString','Retrieve from Simulink','String','From Simulink','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[450 panelDimens(4)-lineSpacing*(currParam+1+currGap) 120 20],'Max',1,'Min',0,'Value',0,'Visible','on','Tag',num2str(ii),'UserData',[],'Callback',@fromSimulinkCallback,'Style','checkbox'); | |
296 if strcmp(paramvals{ii},'-->') | |
297 set(objName{ii,3},'Visible','off'); | |
298 set(objName{ii,4},'Visible','off'); | |
299 set(objName{ii,10},'Value',1); | |
300 else | |
301 set(objName{ii,10},'Visible','off'); | |
302 end | |
303 | |
304 % ========================================================================== | |
305 case {'unit'} | |
306 % ========================================================================== | |
307 % Key value: | |
308 objName{ii,2} = uicontrol('Parent',currPanel,'Units','pixels','Position',[120 panelDimens(4)-lineSpacing*(currParam+1+currGap) 60 20],'String',paramkeys{ii},'FontSize',guiFontSize+1,'Visible','on','Enable','off','UserData',ii,'Callback',@g_editNameCallback,'Style','edit'); | |
309 if ~noParamsReq && ~addedPar | |
310 set(objName{ii,2},'Style','text','BackgroundColor',backColor,'Position',[50 panelDimens(4)-(4+lineSpacing*(currParam+1+currGap)) 120 20]); | |
311 end | |
312 % Val value: | |
313 unitVal = paramvals{ii}.strs; if isempty(unitVal), unitVal = {''}; end | |
314 allunits = unit.supportedUnits; | |
315 unitsTooltip = 'Supported units: '; | |
316 for kk=1:numel(allunits), unitsTooltip = [unitsTooltip,allunits{kk},',']; end | |
317 unitsTooltip(end)=[]; | |
318 objName{ii,3} = uicontrol('Parent',currPanel,'TooltipString',unitsTooltip,'Units','pixels','Position',[200 panelDimens(4)-lineSpacing*(currParam+1+currGap) 200 20],'String',['''',unitVal{1},''''],'Fontsize',guiFontSize+1,'Visible','on','Enable','off','UserData',ii,'Callback',@g_unitValCallback,'Style','edit'); | |
319 | |
320 % ========================================================================== | |
321 case {'logical'} | |
322 % ========================================================================== | |
323 % Key value: | |
324 objName{ii,2} = uicontrol('Parent',currPanel,'Units','pixels','Position',[120 panelDimens(4)-lineSpacing*(currParam+1+currGap) 60 20],'String',paramkeys{ii},'FontSize',guiFontSize+1,'Visible','on','Enable','off','UserData',ii,'Callback',@g_editNameCallback,'Style','edit'); | |
325 if ~noParamsReq && ~addedPar | |
326 set(objName{ii,2},'Style','text','BackgroundColor',backColor,'Position',[50 panelDimens(4)-(4+lineSpacing*(currParam+1+currGap)) 120 20]); | |
327 end | |
328 % Val value: | |
329 objName{ii,3} = uicontrol('Parent',currPanel,'Units','pixels','Position',[200 panelDimens(4)-lineSpacing*(currParam+1+currGap) 100 20],'String',{'false','true'},'Value',paramvals{ii}+1,'Fontsize',guiFontSize+1,'Visible','on','Enable','off','UserData',ii,'Callback',@g_logicValCallback,'Style','popupmenu'); | |
330 | |
331 % ========================================================================== | |
332 case 'specwin' | |
333 % ========================================================================== | |
334 selectWind = paramvals{ii}.type; | |
335 listWindows = ['Kaiser',specwin.getTypes]; | |
336 selectWindValue = strmatch(selectWind,listWindows,'exact'); | |
337 % Window text: | |
338 objName{ii,2} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[40 panelDimens(4)-lineSpacing*(currParam+1+currGap)-5 60 20],'String','Window:','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Visible','on','Style','text'); | |
339 % Window type popup: | |
340 objName{ii,3} = uicontrol('Parent',currPanel,'Units','pixels','Position',[105 panelDimens(4)-lineSpacing*(currParam+1+currGap)-2 90 20],'String',listWindows,'TooltipString','Window names','Value',selectWindValue,'Visible','on','Enable','off','Tag',paramkeys{ii},'UserData',ii,'Callback', @g_WindListCallback,'Style','popupmenu'); | |
341 % Length value: | |
342 currLength = num2str(length(params.params(ii).val.win)); | |
343 objName{ii,4} = uicontrol('Parent',currPanel,'Units','pixels','Position',[200 panelDimens(4)-lineSpacing*(currParam+1+currGap)-2 70 20],'String',num2str(currLength),'TooltipString','Window Length','Visible','on','Enable','off','UserData',ii,'Callback', @g_WindlengthCallback,'Style','edit'); | |
344 if strcmp(selectWind,'Kaiser') | |
345 % PSL value if Kaiser: | |
346 currPSL = params.params(ii).val.psll; | |
347 objName{ii,5} = uicontrol('Parent',currPanel,'Units','pixels','Position',[275 panelDimens(4)-lineSpacing*(currParam+1+currGap)-2 60 20],'String',num2str(currPSL),'TooltipString','Peak Sidelobe','Visible','on','Enable','off','UserData',ii,'Callback',@g_WindPSLCallback,'Style','edit'); | |
348 end | |
349 % Simulink checkbox: | |
350 objName{ii,10} = uicontrol('TooltipString','Retrieve from Simulink','String','From Simulink','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[450 panelDimens(4)-lineSpacing*(currParam+1+currGap) 120 20],'Max',1,'Min',0,'Value',0,'Visible','on','Tag',num2str(ii),'UserData',paramvals{ii},'Callback',@g_fromSimulinkCallback,'Style','checkbox'); | |
351 | |
352 % ========================================================================== | |
353 case 'pzmodel' | |
354 % ========================================================================== | |
355 % Simulink checkbox: | |
356 objName{ii,10} = uicontrol('TooltipString','Retrieve from Simulink','String','From Simulink','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[500 panelDimens(4)-lineSpacing*(currParam+1+currGap) 120 20],'Max',1,'Min',0,'Value',0,'Visible','on','Tag',num2str(ii),'UserData',paramvals{ii},'Callback',@g_fromSimulinkCallback,'Style','checkbox'); | |
357 | |
358 clear pzObj currPoles poleFreqs poleQs poleFQs currZeros zeroFreqs zeroQs zeroFQs | |
359 pzObj = params.params(ii).val; | |
360 currPoles = pzObj.poles; | |
361 currZeros = pzObj.zeros; | |
362 % Load button: | |
363 objName{ii,3} = uicontrol('Parent',currPanel,'HorizontalAlignment','left','Position',[50 panelDimens(4)-(3+lineSpacing*(currParam+1+currGap)) 50 20],'String','Load','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Visible','on','UserData',ii,'Callback',@g_pzmodelLoad,'enable','off','Style','pushbutton'); | |
364 % Gain text: | |
365 objName{ii,4} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[120 panelDimens(4)-lineSpacing*(currParam+1+currGap)-5 40 20*guiFontSize/10],'String','Gain:','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Visible','on','Style','text'); | |
366 % Gain value: | |
367 currGain = pzObj.gain; | |
368 objName{ii,5} = uicontrol('Parent',currPanel,'Units','pixels','Position',[155 panelDimens(4)-(2+lineSpacing*(currParam+1+currGap)) 60 20],'String',num2str(currGain),'FontSize',guiFontSize+1,'Visible','on','Enable','off','UserData',ii,'Callback',@g_pzmodelGainEdit,'Style','edit'); | |
369 % Poles text: | |
370 objName{ii,6} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[240 panelDimens(4)-lineSpacing*(currParam+1+currGap)-5 40 20],'String','Poles:','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Visible','on','Style','text'); | |
371 % Zeros text: | |
372 objName{ii,7} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[355 panelDimens(4)-lineSpacing*(currParam+1+currGap)-5 40 20],'String','Zeros:','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Visible','on','Style','text'); | |
373 % Poles value: | |
374 for kk=1:numel(currPoles) | |
375 poleFreqs(kk,1) = currPoles(kk).f; | |
376 poleQs(kk,1) = currPoles(kk).q; | |
377 if ~isnan(poleQs(kk,1)) | |
378 poleFQs{kk,1}=strcat(num2str(poleFreqs(kk,1)),',',num2str(poleQs(kk,1))); | |
379 else | |
380 poleFQs{kk,1}=num2str(poleFreqs(kk,1)); | |
381 end | |
382 end | |
383 if numel(currPoles)>1 || numel(currZeros)>1 | |
384 currGap=currGap+1; | |
385 end | |
386 if isempty(currPoles) | |
387 poleFQs = ''; | |
388 else | |
389 poleFQs=char(poleFQs); | |
390 end | |
391 objName{ii,8} = uicontrol('Parent',currPanel,'Units','pixels','Position',[280 panelDimens(4)-(2+lineSpacing*(currParam+1+currGap))-(lineSpacing-30)*(max(numel(currPoles),numel(currZeros))>1) 60 (20+(max(numel(currPoles),numel(currZeros))>1)*lineSpacing)*guiFontSize/10],'Max',2,'String',poleFQs,'FontSize',guiFontSize+1,'TooltipString','Insert ''freq'' or ''freq,q'' on multiple lines','Visible','on','Enable','off','UserData',ii,'Callback',{@g_pzmodelPZEdit,1},'Style','edit'); | |
392 % Zeros value: | |
393 for kk=1:numel(currZeros) | |
394 zeroFreqs(kk,1) = currZeros(kk).f; | |
395 zeroQs(kk,1) = currZeros(kk).q; | |
396 if ~isnan(zeroQs(kk,1)) | |
397 zeroFQs{kk,1}=strcat(num2str(zeroFreqs(kk,1)),',',num2str(zeroQs(kk,1))); | |
398 else | |
399 zeroFQs{kk,1}=num2str(zeroFreqs(kk,1)); | |
400 end | |
401 end | |
402 if isempty(currZeros) | |
403 zeroFQs = ''; | |
404 else | |
405 zeroFQs = char(zeroFQs); | |
406 end | |
407 objName{ii,9} = uicontrol('Parent',currPanel,'Units','pixels','Position',[395 panelDimens(4)-(2+lineSpacing*(currParam+1+currGap))-(lineSpacing-30)*(max(numel(currPoles),numel(currZeros))>1) 60 (20+(max(numel(currPoles),numel(currZeros))>1)*lineSpacing)*guiFontSize/10],'Max',2,'String',zeroFQs,'FontSize',guiFontSize+1,'TooltipString','Insert ''freq'' or ''freq,q'' on multiple lines','Visible','on','Enable','off','UserData',ii,'Callback',{@g_pzmodelPZEdit,0},'Style','edit'); | |
408 | |
409 % ========================================================================== | |
410 case 'pz' | |
411 % ========================================================================== | |
412 % Simulink checkbox: | |
413 objName{ii,10} = uicontrol('TooltipString','Retrieve from Simulink','String','From Simulink','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[500 panelDimens(4)-lineSpacing*(currParam+1+currGap) 120 20],'Max',1,'Min',0,'Value',0,'Visible','on','Tag',num2str(ii),'UserData',paramvals{ii},'Callback',@g_fromSimulinkCallback,'Style','checkbox'); | |
414 | |
415 currPoles = params.params(ii).val; | |
416 clear poleFreqs poleQs poleFQs | |
417 for kk=1:numel(currPoles) | |
418 poleFreqs(kk,1) = currPoles(kk).f; | |
419 poleQs(kk,1) = currPoles(kk).q; | |
420 if isnan(poleQs(kk,1)) | |
421 poleFQs{kk,1}=num2str(poleFreqs(kk,1)); | |
422 else | |
423 poleFQs{kk,1}=strcat(num2str(poleFreqs(kk,1)),',',num2str(poleQs(kk,1))); | |
424 end | |
425 | |
426 end | |
427 poleFQs=char(poleFQs); | |
428 % Poles text: | |
429 objName{ii,2} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[50 panelDimens(4)-(4+lineSpacing*(currParam+1+currGap)) 120 20],'String','PZ','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Visible','on','Enable','off','Style','text'); | |
430 if numel(currPoles)>1, currGap=currGap+1; end | |
431 % Poles value: | |
432 objName{ii,3} = uicontrol('Parent',currPanel,'Units','pixels','Position',[250 panelDimens(4)-(2+lineSpacing*(currParam+1+currGap))-(lineSpacing-30)*(numel(currPoles)>1) 100 (20+(numel(currPoles)>1)*lineSpacing)*guiFontSize/10],'String',poleFQs,'Max',2,'FontSize',guiFontSize,'TooltipString','Insert ''freq'' or ''freq,q''','Visible','on','Enable','on','UserData',ii,'Callback',@g_poleEdit,'Style','edit'); | |
433 | |
434 % ========================================================================== | |
435 case 'cell' | |
436 % ========================================================================== | |
437 if isa(paramvals{ii}{1},'char') && strcmp(paramvals{ii}{1},'-->') | |
438 % Key value: | |
439 objName{ii,2} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','Position',[50 panelDimens(4)-5-lineSpacing*(currParam+1+currGap) 120 20],'String',paramkeys{ii},'Visible','on','Enable','on','UserData',ii,'Callback',@g_editNameCallback,'Style','text'); | |
440 % Text: from Simulink environment: | |
441 objName{ii,3} = uicontrol('TooltipString','Retrieve from Simulink','Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[230 panelDimens(4)-6-lineSpacing*(currParam+1+currGap) 200 20],'String','From Simulink environment','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Visible','on','Style','text'); | |
442 fromSimulink = 1; | |
443 else | |
444 % Key value: | |
445 objName{ii,2} = uicontrol('Parent',currPanel,'Units','pixels','Position',[120 panelDimens(4)-lineSpacing*(currParam+1+currGap) 60 20],'String',paramkeys{ii},'Visible','on','Enable','off','UserData',ii,'Callback',@g_editNameCallback,'Style','edit'); | |
446 if ~noParamsReq && ~addedPar | |
447 set(objName{ii,2},'Style','text','BackgroundColor',backColor,'Position',[50 panelDimens(4)-5-lineSpacing*(currParam+1+currGap) 120 20]); | |
448 end | |
449 % Val value: | |
450 data = utils.prog.cell2str(paramvals{ii}); | |
451 objName{ii,3} = uicontrol('Parent',currPanel,'Units','pixels','Position',[250 panelDimens(4)-lineSpacing*(currParam+1+currGap) 130 20],'String',data,'Visible','on','Enable','on','UserData',ii,'Callback',@g_editValueCallback,'Style','edit'); | |
452 fromSimulink = 0; | |
453 end | |
454 | |
455 % Simulink checkbox: | |
456 objName{ii,10} = uicontrol('TooltipString','Retrieve from Simulink','String','From Simulink','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[500 panelDimens(4)-lineSpacing*(currParam+1+currGap) 120 20],'Max',1,'Min',0,'Value',fromSimulink,'Visible','on','Tag',num2str(ii),'UserData',paramvals{ii},'Callback',@g_fromSimulinkCallback,'Style','checkbox'); | |
457 | |
458 | |
459 % ========================================================================== | |
460 otherwise % Other types of param? | |
461 % ========================================================================== | |
462 % Key value: | |
463 objName{ii,3} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','Position',[50 panelDimens(4)-5-lineSpacing*(currParam+1+currGap) 120 20],'String',paramkeys{ii},'FontSize',guiFontSize+1,'Visible','on','Enable','off','UserData',ii,'Callback',@g_editNameCallback,'Style','text'); | |
464 % Text: input not supported. Please construct by proper block. | |
465 objName{ii,4} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[250 panelDimens(4)-4-lineSpacing*(currParam+1+currGap) 200 20],'String','Unsupported yet','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Visible','on','Style','text'); | |
466 fromSimulink = 0; | |
467 | |
468 % Simulink checkbox: | |
469 objName{ii,10} = uicontrol('TooltipString','Retrieve from Simulink','String','From Simulink','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[450 panelDimens(4)-lineSpacing*(currParam+1+currGap) 120 20],'Max',1,'Min',0,'Value',fromSimulink,'Visible','on','Tag',num2str(ii),'UserData',paramvals{ii},'Callback',@g_fromSimulinkCallback,'Style','checkbox'); | |
470 | |
471 % ============================================================================== | |
472 end % of SWITCH the param type | |
473 % Cycle to activate enabled params: | |
474 if paramEnabled(ii) || noParamsReq==1 | |
475 [xx,yy] = size(objName); | |
476 jj=2; | |
477 while jj<=yy && ~isempty(objName{ii,jj}) | |
478 try set(objName{ii,jj},'Enable','on'); set(objName{ii,jj},'ForegroundColor',[0 0 0]); catch, end | |
479 jj=jj+1; | |
480 end | |
481 end | |
482 | |
483 end % of cycle among params | |
484 | |
485 end % of buildplistFigureParam function | |
486 %---------------------------------------------------------------------- | |
487 | |
488 %% ========================= Selection Check ============================== | |
489 % ========================================================================= | |
490 %---------------------------------------------------------------------- | |
491 function g_ContinuousParamCheck(varargin) | |
492 % This is the function to execute a continuous check on the status | |
493 % of the current selection (system and block). | |
494 | |
495 currSelection = utils.prog.gcbsh; | |
496 % set(findobj('Tag','LTPDAGUI'),'Name',[strtok(get(findobj('Tag','LTPDAGUI'),'Name'),' - '),' - ',bdroot]); | |
497 if isnan(selBlocks), buildplistFigureParam([],[],get(findobj('Tag','paramsPage'),'UserData')); end | |
498 | |
499 % Clear the figure if nothing is and was selected OR nothing is and something was selected OR is selected a library | |
500 if (isempty(selBlocks) && isempty(currSelection)) || (~isempty(selBlocks) && isempty(currSelection)) || strcmp(get_param(bdroot,'BlockDiagramType'),'library') | |
501 delete(findobj(gcf,'Parent',currPanel)) | |
502 try close(findobj('Tag','parampanelFigure')); catch, end; | |
503 selBlocks = []; | |
504 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[0 (panelDimens(4)+30)/2 panelDimens(3) 30],'String','Nothing currently selected','Visible','on','Style','text'); | |
505 return | |
506 end | |
507 | |
508 % Check that it's selected a ltpda simulink analysis diagram: | |
509 if ~isempty(bdroot) && ~isempty(find_system(bdroot,'FindAll','on','Type','Annotation','Tag','ltpda model')) | |
510 | |
511 if ((numel(selBlocks)==1 && selBlocks~=gcbh) || length(selBlocks)~=length(currSelection)) || selBlocks(1)~=currSelection(1) && ~isempty(currSelection) | |
512 delete(findobj(gcf,'Parent',currPanel)) | |
513 try close(findobj('Tag','parampanelFigure')); catch, end; | |
514 GUIprefs = getappdata(0, 'GUIpreferences'); | |
515 if GUIprefs.CAD | |
516 if GUIprefs.Copied | |
517 if length(currSelection)<1, return; end | |
518 currSelection = g_copyfcnCallback(selBlocks,currSelection); | |
519 GUIprefs.Copied = 0; | |
520 setappdata(0, 'GUIpreferences',GUIprefs) | |
521 end | |
522 end | |
523 for i=1:length(currSelection) | |
524 set_param(currSelection(i),'LinkStatus','inactive'); | |
525 currentTags{i}=get_param(currSelection(i),'Tag'); | |
526 end | |
527 | |
528 if strcmp(currentTags{1},'') | |
529 delete(findobj(gcf,'Parent',currPanel)) | |
530 selBlocks = currSelection; | |
531 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[0 (panelDimens(4)+30)/2 panelDimens(3) 30],'String','Not a valid LTPDA block','Visible','on','Style','text'); | |
532 return | |
533 end | |
534 | |
535 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
536 if numel(currSelection)>1 % then the user has selected multiple blocks | |
537 % Check for consistency: all methods? same class? | |
538 for i=1:numel(currentTags) | |
539 if ~strcmp(currentTags{i},currentTags{1}) | |
540 g_ErrorSelectionInconsistent(currPanel); | |
541 selBlocks = currSelection; | |
542 return; | |
543 end | |
544 end | |
545 % Check for consistency: same method?: | |
546 for i=1:numel(currSelection) | |
547 childpath = find_system(currSelection(i),'LookUnderMasks','all','BlockType','M-S-Function'); | |
548 functionname{i}=get_param(childpath,'Tag'); | |
549 if ~strcmp(functionname{i},functionname{1}) % different functions, inconsistent selection | |
550 g_ErrorSelectionInconsistent(currPanel); | |
551 selBlocks = currSelection; | |
552 return; | |
553 end | |
554 end | |
555 end | |
556 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
557 | |
558 delete(findobj(gcf,'Parent',currPanel)) | |
559 selBlocks = currSelection; | |
560 oldparams = []; params = []; paramEnabled = []; oldparamEnabled = []; functionName = ''; paramSets = []; | |
561 | |
562 % Get the new functionName: | |
563 childpath = find_system(gcbh,'LookUnderMasks','all','BlockType','M-S-Function'); | |
564 functionName = get_param(childpath,'Tag'); | |
565 if isempty(functionName) | |
566 description = get_param(gcbh,'Description'); | |
567 funcname = findstr('functionName=',description); | |
568 if funcname | |
569 i = funcname+14; | |
570 while ~strcmp(description(i),';'), i=i+1; end | |
571 functionName = description(funcname+14:i-2); | |
572 end | |
573 end | |
574 funcType = strtok(get(gcbh,'Tag')); | |
575 if isempty(functionName) && strcmp(funcType,'method') | |
576 functionName = g_setmethod(); | |
577 end | |
578 | |
579 switch funcType | |
580 % ========================================================= | |
581 case {'function','freepl','method'} | |
582 buildplistFigureParam() | |
583 % ========================================================= | |
584 case 'arithmetic' | |
585 g_arithmetic(currPanel); | |
586 % ========================================================= | |
587 case 'input' | |
588 g_LoadInputParamCallback(currPanel); | |
589 % ========================================================= | |
590 case {'mux','demux'} | |
591 g_LoadMuxParamCallback(); | |
592 % ========================================================= | |
593 case 'from' | |
594 g_LoadFromBlockCallback(currPanel); | |
595 % ========================================================= | |
596 end % of switch | |
597 | |
598 end % end of blocks selection | |
599 end % end of system selection check | |
600 | |
601 end | |
602 %---------------------------------------------------------------------- | |
603 | |
604 end |