0001 function pan2param(varargin)
0002
0003
0004
0005
0006
0007
0008 global params newparams paramEnabled oldparamEnabled paramSets
0009 global LTPDAinvar selBlocks objName noParamsReq functionName guiFontSize
0010
0011
0012
0013 currPanel = varargin{1};
0014 panelDimens = get(currPanel, 'Position');
0015 backColor = get(currPanel, 'BackgroundColor');
0016 selBlocks = 0;
0017
0018 guiFontSize = getappdata(0, 'ltpda_gui_fontsize');
0019 if isempty(guiFontSize), guiFontSize = 10; setappdata(0, 'ltpda_gui_fontsize',10); end
0020 set(gcf,'NextPlot','new')
0021 alltimers = timerfindall;
0022 stop(alltimers(1));
0023 set(alltimers(1),'TimerFcn',@ContinuousParamCheck,'Period',0.3);
0024 start(alltimers(1));
0025
0026
0027
0028
0029 function buildplistFigureParam(varargin)
0030
0031
0032 panelDimens = get(currPanel, 'Position');
0033 lineSpacing = 30 * guiFontSize/10;
0034 setappdata(0,'ltpda_gui_LineSpacing',lineSpacing);
0035 if ~isempty(findobj(gcf,'Tag','apply'))
0036 notredrawn = 0; undoStatus = get(findobj(gcf,'Tag','undo'),'enable');
0037
0038 for i = 1:numel(objName), try delete(objName{i}); catch end; end
0039 delete(findobj('Parent',currPanel,'TooltipString','Remove this parameter'))
0040 else
0041 notredrawn = 1; undoStatus = 'off';
0042
0043 delete(findobj(gcf,'Parent',currPanel));
0044 end
0045 objName = [];
0046 close(findobj('Tag','expandedEditField'))
0047 if notredrawn
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058 if isempty(params) && isempty(newparams)
0059 paramcommand = get_param(gcbh,'Description');
0060 noParamsReq=0;
0061 if isempty(paramcommand)
0062 paramcommand = RetrievePlist();
0063 selBlocks = utils.prog.gcbsh;
0064 for kk=1:length(selBlocks)
0065 set_param(selBlocks(kk),'Description',paramcommand);
0066 end
0067 end
0068 eval(paramcommand)
0069 newparams = params;
0070 oldparamEnabled = paramEnabled;
0071 end
0072
0073 if ~exist('paramEnabled','var') && isempty(find(newparams,'Sets')) && noParamsReq==0
0074 paramEnabled = zeros(1,nparams(newparams));
0075 oldparamEnabled = paramEnabled;
0076 end
0077 childpath = find_system(gcbh,'LookUnderMasks','all','BlockType','M-S-Function');
0078 if numel(get_param(childpath,'Tag'))>6 && strcmp(get_param(childpath,'Tag'),'generic')
0079
0080 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[40 panelDimens(4)-40 100 14],'FontSize',guiFontSize,'String','Function name:','TooltipString','Function name','Visible','on','Style','text');
0081
0082 uicontrol('Parent',currPanel,'Units','pixels','BackgroundColor',backColor,'HorizontalAlignment','center','Position',[150 panelDimens(4)-40 100 16],'FontSize',guiFontSize,'String', functionName,'TooltipString','Name of the function','Visible','on','Callback',@functionNameSet,'Style','edit');
0083 panelDimens = get(currPanel, 'Position');
0084 panelDimens(4) = panelDimens(4)-40;
0085 else
0086 childpath = find_system(gcbh,'LookUnderMasks','all','BlockType','M-S-Function');
0087 setappdata(0,'ltpda_currFunctionName',get_param(childpath,'Tag'));
0088 end
0089
0090 y=nparams(newparams);
0091
0092 if y==0 && ~exist('paramSets','var') && noParamsReq==0
0093 paramcommand=[paramcommand,'noParamsReq=1;'];
0094 selBlocks = utils.prog.gcbsh;
0095 for kk=1:length(selBlocks), set_param(selBlocks(kk),'Description',paramcommand); end
0096 buildplistFigureParam([],[],get(findobj('Tag','paramsPage'),'UserData'))
0097 end
0098
0099
0100
0101
0102
0103 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',@HelpButtonCallback,'Style','pushbutton');
0104
0105 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',@ResetButtonCallback,'Style','pushbutton');
0106
0107 probe = get_param(gcbh,'MaskHelp');
0108 if ~isempty(probe) && isa(probe,'char') && strcmp(probe,'probe'), keepRes = 1; else keepRes = 0; end
0109 uicontrol('Parent',currPanel,'Units','pixels','BackgroundColor',backColor,'HorizontalAlignment','left','Position',[330 10 150 guiFontSize*16/10],'FontAngle','italic','FontSize',guiFontSize,'String','Keep local result','TooltipString','Do not delete the result of this block at the end of the analysis calculation','Visible','on','Callback',@KeepResultCallback,'Value',keepRes,'Style','checkbox');
0110
0111 setName = get(gcbh,'UserData');
0112 if isempty(setName), setName = 0; end
0113 uicontrol('Parent',currPanel,'Units','pixels','BackgroundColor',backColor,'HorizontalAlignment','left','Position',[200 10 110 guiFontSize*16/10],'FontAngle','italic','FontSize',guiFontSize,'String','Set name','TooltipString','Set the signal name equal to the block name','Visible','on','Callback',@SetNameCallback,'Value',setName,'Style','checkbox');
0114
0115 uicontrol('Parent',currPanel,'TooltipString','Set the number of input expected by this block','BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[500 6 75 guiFontSize*20/10],'String','N of inputs:','FontAngle','italic','FontSize',guiFontSize,'Visible','on','Style','text');
0116 paramFromSimulink = 0;
0117 for ii=1:y
0118 paramkeys{ii} = newparams.params(ii).key;
0119 paramvals{ii} = newparams.params(ii).val;
0120 if isa(paramvals{ii},'char') && numel(paramvals{ii})>2 && strcmp(paramvals{ii},'-->'), paramFromSimulink = paramFromSimulink + 1; end
0121 end
0122 inports = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Inport');
0123 uicontrol('Parent',currPanel,'TooltipString','Set the number of input expected by this block','BackgroundColor',backColor,'Units','pixels','Position',[585 8 40 guiFontSize*20/10],'String',num2str(numel(inports)-paramFromSimulink),'FontSize',guiFontSize,'Visible','on','Enable','on','UserData',numel(inports)-paramFromSimulink,'Callback',@numberDataInput,'Tag','numbDataInputs','Style','edit');
0124
0125
0126 if exist('paramSets','var') && ~isempty(paramSets)
0127 sets = find(paramSets,'sets');
0128 currSet = find(paramSets,'currSet');
0129
0130 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-300)/2 panelDimens(4)-44 150 20],'String','Possible params sets:','Visible','on','Style','text');
0131
0132 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-300)/2+150 panelDimens(4)-40 250 20],'String',sets,'Value',currSet,'Visible','on','UserData',sets,'Callback',@SetsUpdate,'Style','popup');
0133 panelDimens(4) = panelDimens(4)-40;
0134 end
0135
0136
0137
0138
0139 paramTypes = {'double/char','specwin','pz','pzmodel','-->'};
0140 for kk=1:y, paramTypes(strmatch(class(newparams.params(kk).val),paramTypes,'exact'))=[]; end
0141
0142 hparamType = uicontrol('Parent',currPanel,'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');
0143
0144 uicontrol('Parent',currPanel,'TooltipString','Add a user-defined parameter','Units','pixels','Position',[130 40 20 20],'String','+','Visible','on','Enable','on','Callback', @AddParamCallback,'UserData',hparamType,'Style','pushbutton');
0145
0146
0147
0148
0149
0150 logosize = [30,30];
0151 dimension = [panelDimens(3)-135 , 35 , logosize];
0152 logo = axes('Parent',currPanel,'Units','pixels','Position',dimension);
0153 image(imread('buttonyes.jpg'),'Parent',logo);
0154 axis(logo,'off');
0155 logosize = [30,30];
0156 dimension = [panelDimens(3)-135 , 3 , logosize];
0157 logo = axes('Parent',currPanel,'Units','pixels','Position',dimension);
0158 image(imread('buttonno.jpg'),'Parent',logo);
0159 axis(logo,'off');
0160
0161 uicontrol('Parent',currPanel,'Units','pixels','Position',[panelDimens(3)-100 40 80 guiFontSize*20/10],'HorizontalAlignment','right','FontSize',guiFontSize,'String','Apply','Visible','on','Enable','off','Callback', @ApplyButtonCallback,'DeleteFcn',{@ApplyButtonCallback,0},'UserData',hparamType,'Tag','apply','Style','pushbutton');
0162
0163 uicontrol('Parent',currPanel,'Units','pixels','Position',[panelDimens(3)-100 10 80 guiFontSize*20/10],'HorizontalAlignment','right','FontSize',guiFontSize,'String','Undo','Visible','on','Enable',undoStatus,'Callback', @UndoButtonCallback,'UserData',hparamType,'Tag','undo','Style','pushbutton');
0164
0165 paramPagePosition = panelDimens + [3 65+guiFontSize*16/10 -6 -(80+guiFontSize*16/10)];
0166 if nargin == 0, currPage = 1;
0167 else currPage = varargin{3};
0168 end
0169 uipanel('Parent',currPanel,'BackgroundColor',backColor,'FontSize',7,'Units','pixels','Position',paramPagePosition,'Tag','paramsPage','UserData',currPage);
0170
0171 else
0172 y=nparams(newparams);
0173 for pp=1:y
0174 paramkeys{pp} = newparams.params(pp).key;
0175 paramvals{pp} = newparams.params(pp).val;
0176 end
0177 if exist('paramSets','var') && ~isempty(paramSets), panelDimens(4) = panelDimens(4)-40; end
0178 paramPagePosition = panelDimens + [3 65+guiFontSize*16/10 -6 -(80+guiFontSize*16/10)];
0179 end
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191 totalGaps = 0;
0192 paramThisPage = 0;
0193 lastParamGap = 0;
0194 paramPages = [];
0195 for ii=1:y
0196 paramThisPage = paramThisPage+1;
0197 switch class(paramvals{ii})
0198 case 'pzmodel'
0199 if numel(paramvals{ii}.poles)>1 || numel(paramvals{ii}.zeros)>1
0200 totalGaps = totalGaps+1;
0201 lastParamGap = 1;
0202 end
0203 case 'pz'
0204 if numel(paramvals{ii})>1
0205 totalGaps = totalGaps+1;
0206 lastParamGap = 1;
0207 end
0208 end
0209
0210 if (paramThisPage+totalGaps)*lineSpacing > paramPagePosition(4)-20
0211 paramPages = [paramPages , paramThisPage-1];
0212 if ii==y, paramPages = [paramPages,1]; end
0213 paramThisPage = 1;
0214 totalGaps = lastParamGap;
0215 lastParamGap = 0;
0216 elseif ii==y
0217 paramPages = [paramPages , paramThisPage];
0218 end
0219 end
0220 currGap = 0;
0221
0222 if numel(paramPages) > 1
0223 set(findobj('Tag','paramsPage'),'Title',['Page number ', num2str(currPage)] );
0224 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[200 39 100 20],'String','Go to page: ','FontName','Times New Roman','FontSize',guiFontSize+2,'FontWeight','bold','Visible','on','Style','text');
0225 for ii = 0:numel(paramPages)-1
0226 uicontrol('Parent',currPanel,'Units','pixels','Position',[300+ii*(30) 40 20 20],'String',num2str(ii+1),'Visible','on','Enable','on','Callback', {@buildplistFigureParam,ii+1},'Style','pushbutton');
0227 end
0228 elseif isempty(paramPages)
0229 paramPages = 0;
0230 end
0231 firstParam = 1;
0232 if nargin>1
0233 if varargin{3}>numel(paramPages), varargin{3} = numel(paramPages); end
0234 for ii = 1:varargin{3}-1
0235 firstParam = firstParam + paramPages(ii);
0236 end
0237 lastParam = firstParam + paramPages(varargin{3})-1;
0238 else
0239 lastParam = paramPages(1);
0240 end
0241
0242 currParam = 0;
0243 for ii = firstParam:lastParam
0244 currParam = currParam + 1;
0245 addedPar = 0;
0246
0247 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', @EnableCallback,'Tag',paramkeys{ii},'UserData',ii,'Style','checkbox');
0248
0249 try
0250 if strcmpi(paramkeys{ii}(1:7),'addPar_')
0251 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', @RemParamCallback,'Style','pushbutton');
0252 addedPar = 1;
0253 paramkeys{ii}(1:7) = [];
0254 end
0255 catch end
0256
0257 switch class(paramvals{ii})
0258
0259
0260 case {'double'}
0261
0262
0263 objName{ii,2} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[40 panelDimens(4)-(4+lineSpacing*(currParam+1+currGap)) 70 20*guiFontSize/10],'String','Name:','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Visible','on','Style','text');
0264
0265 objName{ii,3} = uicontrol('Parent',currPanel,'Units','pixels','Position',[120 panelDimens(4)-lineSpacing*(currParam+1+currGap) 60 guiFontSize*20/10],'String',paramkeys{ii},'FontSize',guiFontSize+1,'Visible','on','Enable','off','UserData',ii,'Callback',@editNameCallback,'Style','edit');
0266 if ~noParamsReq && ~addedPar
0267 set(objName{ii,2},'Visible','off');
0268 set(objName{ii,3},'Style','text','BackgroundColor',backColor,'Position',[50 panelDimens(4)-(4+lineSpacing*(currParam+1+currGap)) 120 20]);
0269 end
0270
0271
0272 objName{ii,4} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[205 panelDimens(4)-(4+lineSpacing*(currParam+1+currGap)) 40 20*guiFontSize/10],'String','Value:','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Visible','on','Style','text');
0273
0274 data = mat2str(paramvals{ii});
0275 objName{ii,5} = uicontrol('Parent',currPanel,'Units','pixels','Position',[250 panelDimens(4)-lineSpacing*(currParam+1+currGap) 200 guiFontSize*20/10],'String',data,'Fontsize',guiFontSize+1,'Visible','on','Enable','off','UserData',ii,'Callback',@editValueCallback,'Style','edit');
0276 objName{ii,6} = 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',[],'Callback',@fromSimulinkCallback,'Style','checkbox');
0277
0278 objName{ii,8} = uicontrol('UserData',objName{ii,5},'TooltipString','Expand the edit field','Parent',currPanel,'BackgroundColor',[0.7 0.7 0.7],'HorizontalAlignment','left','Position',[455 panelDimens(4)+3-lineSpacing*(currParam+1+currGap) 13 13],'Visible','on','Callback',@ExpandEdit,'Style','pushbutton');
0279
0280
0281 if strcmp(paramvals{ii},'-->')
0282 set(objName{ii,4},'Visible','off');
0283 set(objName{ii,5},'Visible','off');
0284 set(objName{ii,6},'Value',1);
0285 set(objName{ii,8},'Visible','off');
0286 end
0287
0288
0289 case {'char'}
0290
0291
0292 objName{ii,2} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[40 panelDimens(4)-(4+lineSpacing*(currParam+1+currGap)) 70 20],'String','Name:','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Visible','on','Style','text');
0293
0294 objName{ii,3} = 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',@editNameCallback,'Style','edit');
0295 if ~noParamsReq && ~addedPar
0296 set(objName{ii,2},'Visible','off');
0297 set(objName{ii,3},'Style','text','BackgroundColor',backColor,'Position',[50 panelDimens(4)-(4+lineSpacing*(currParam+1+currGap)) 120 20]);
0298 end
0299
0300
0301 objName{ii,4} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[205 panelDimens(4)-(4+lineSpacing*(currParam+1+currGap)) 40 20],'String','Value:','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Visible','on','Style','text');
0302
0303 objName{ii,5} = uicontrol('Parent',currPanel,'Units','pixels','Position',[250 panelDimens(4)-lineSpacing*(currParam+1+currGap) 200 20],'String',['''',paramvals{ii},''''],'Fontsize',guiFontSize+1,'Visible','on','Enable','off','UserData',ii,'Callback',@editValueCallback,'Style','edit');
0304 objName{ii,6} = 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',[],'Callback',@fromSimulinkCallback,'Style','checkbox');
0305
0306 objName{ii,8} = uicontrol('UserData',objName{ii,5},'TooltipString','Expand the edit field','Parent',currPanel,'BackgroundColor',[0.7 0.7 0.7],'HorizontalAlignment','left','Position',[455 panelDimens(4)+3-lineSpacing*(currParam+1+currGap) 13 13],'Visible','on','Callback',@ExpandEdit,'Style','pushbutton');
0307
0308
0309 if strcmpi(paramkeys{ii},'filename')
0310 objName{ii,7} = uicontrol('Parent',currPanel,'Units','pixels','Position',[560 panelDimens(4)-lineSpacing*(currParam+1+currGap) 90 20],'String','Browse','Visible','on','Enable','off','UserData',objName{ii,5},'Callback',@browseCallback,'Style','pushbutton');
0311 set(objName{ii,5},'Position',[250 panelDimens(4)-lineSpacing*(currParam+1+currGap) 300 20]);
0312 set(objName{ii,6},'Position',[670 panelDimens(4)-lineSpacing*(currParam+1+currGap) 120 20]);
0313 delete(objName{ii,8});
0314 end
0315
0316
0317 if strcmp(paramvals{ii},'-->')
0318 set(objName{ii,4},'Visible','off');
0319 set(objName{ii,5},'Visible','off');
0320 set(objName{ii,7},'Visible','off');
0321 try set(objName{ii,8},'Visible','off'); catch end
0322 set(objName{ii,6},'Value',1);
0323 end
0324
0325
0326 case 'specwin'
0327
0328 selectWind = paramvals{ii}.type;
0329 listWindows = ['Kaiser',specwin.getTypes];
0330 selectWindValue = strmatch(selectWind,listWindows,'exact');
0331
0332 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');
0333
0334 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', @WindListCallback,'Style','popupmenu');
0335
0336 objName{ii,4} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[220 panelDimens(4)-lineSpacing*(currParam+1+currGap)-5 60 20],'String','Length:','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Visible','on','Style','text');
0337
0338 currLength = num2str(length(newparams.params(ii).val.win));
0339 objName{ii,5} = uicontrol('Parent',currPanel,'Units','pixels','Position',[280 panelDimens(4)-lineSpacing*(currParam+1+currGap)-2 70 20],'String',num2str(currLength),'TooltipString','Window Length','Visible','on','Enable','off','UserData',ii,'Callback', @WindlengthCallback,'Style','edit');
0340 if strcmp(selectWind,'Kaiser')
0341
0342 objName{ii,6} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[365 panelDimens(4)-lineSpacing*(currParam+1+currGap)-5 60 20],'String','PSL:','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Visible','on','Style','text');
0343
0344 currPSL = newparams.params(ii).val.psll;
0345 objName{ii,7} = uicontrol('Parent',currPanel,'Units','pixels','Position',[415 panelDimens(4)-lineSpacing*(currParam+1+currGap)-2 60 20],'String',num2str(currPSL),'TooltipString','Peak Sidelobe','Visible','on','Enable','off','UserData',ii,'Callback',@WindPSLCallback,'Style','edit');
0346 end
0347
0348 objName{ii,8} = 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',@fromSimulinkCallback,'Style','checkbox');
0349
0350
0351 case 'pzmodel'
0352
0353
0354 objName{ii,6} = 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',@fromSimulinkCallback,'Style','checkbox');
0355
0356 clear pzObj currPoles poleFreqs poleQs poleFQs currZeros zeroFreqs zeroQs zeroFQs
0357 pzObj = newparams.params(ii).val;
0358 currPoles = pzObj.poles;
0359 currZeros = pzObj.zeros;
0360
0361 objName{ii,2} = 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',@pzmodelLoad,'enable','off','Style','pushbutton');
0362
0363 objName{ii,3} = 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');
0364
0365 currGain = pzObj.gain;
0366 objName{ii,4} = 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',@pzmodelGainEdit,'Style','edit');
0367
0368 objName{ii,5} = 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');
0369
0370 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');
0371
0372 for kk=1:numel(currPoles)
0373 poleFreqs(kk,1) = currPoles(kk).f;
0374 poleQs(kk,1) = currPoles(kk).q;
0375 if ~isnan(poleQs(kk,1))
0376 poleFQs{kk,1}=strcat(num2str(poleFreqs(kk,1)),',',num2str(poleQs(kk,1)));
0377 else
0378 poleFQs{kk,1}=num2str(poleFreqs(kk,1));
0379 end
0380 end
0381 if numel(currPoles)>1 || numel(currZeros)>1
0382 currGap=currGap+1;
0383 end
0384 if isempty(currPoles)
0385 poleFQs = '';
0386 else
0387 poleFQs=char(poleFQs);
0388 end
0389 objName{ii,6} = 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',{@pzmodelPZEdit,1},'Style','edit');
0390
0391 for kk=1:numel(currZeros)
0392 zeroFreqs(kk,1) = currZeros(kk).f;
0393 zeroQs(kk,1) = currZeros(kk).q;
0394 if ~isnan(zeroQs(kk,1))
0395 zeroFQs{kk,1}=strcat(num2str(zeroFreqs(kk,1)),',',num2str(zeroQs(kk,1)));
0396 else
0397 zeroFQs{kk,1}=num2str(zeroFreqs(kk,1));
0398 end
0399 end
0400 if isempty(currZeros)
0401 zeroFQs = '';
0402 else
0403 zeroFQs = char(zeroFQs);
0404 end
0405 objName{ii,8} = 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',{@pzmodelPZEdit,0},'Style','edit');
0406
0407
0408 case 'pz'
0409
0410
0411 objName{ii,6} = 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',@fromSimulinkCallback,'Style','checkbox');
0412
0413 currPoles = newparams.params(ii).val;
0414 clear poleFreqs poleQs poleFQs
0415 for kk=1:numel(currPoles)
0416 poleFreqs(kk,1) = currPoles(kk).f;
0417 poleQs(kk,1) = currPoles(kk).q;
0418 if isnan(poleQs(kk,1))
0419 poleFQs{kk,1}=num2str(poleFreqs(kk,1));
0420 else
0421 poleFQs{kk,1}=strcat(num2str(poleFreqs(kk,1)),',',num2str(poleQs(kk,1)));
0422 end
0423
0424 end
0425 poleFQs=char(poleFQs);
0426
0427 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');
0428 if numel(currPoles)>1, currGap=currGap+1; end
0429
0430 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',@poleEdit,'Style','edit');
0431
0432
0433 case 'cell'
0434
0435 if isa(paramvals{ii}{1},'char') && strcmp(paramvals{ii}{1},'-->')
0436
0437 objName{ii,3} = 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',@editNameCallback,'Style','text');
0438
0439 objName{ii,4} = 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');
0440 fromSimulink = 1;
0441 else
0442
0443 objName{ii,2} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[40 panelDimens(4)-6-lineSpacing*(currParam+1+currGap) 70 20],'String','Name:','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Visible','on','Style','text');
0444
0445 objName{ii,3} = 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',@editNameCallback,'Style','edit');
0446 if ~noParamsReq && ~addedPar
0447 set(objName{ii,2},'Visible','off');
0448 set(objName{ii,3},'Style','text','BackgroundColor',backColor,'Position',[50 panelDimens(4)-5-lineSpacing*(currParam+1+currGap) 120 20]);
0449 end
0450
0451
0452 objName{ii,4} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[205 panelDimens(4)-6-lineSpacing*(currParam+1+currGap) 40 20],'String','Value:','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Visible','on','Style','text');
0453
0454 data = utils.prog.cell2str(paramvals{ii});
0455 objName{ii,5} = uicontrol('Parent',currPanel,'Units','pixels','Position',[250 panelDimens(4)-lineSpacing*(currParam+1+currGap) 130 20],'String',data,'Visible','on','Enable','on','UserData',ii,'Callback',@editValueCallback,'Style','edit');
0456 fromSimulink = 0;
0457 end
0458
0459
0460 objName{ii,6} = 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',@fromSimulinkCallback,'Style','checkbox');
0461
0462
0463
0464 otherwise
0465
0466
0467 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',@editNameCallback,'Style','text');
0468
0469 objName{ii,4} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[310 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');
0470 fromSimulink = 0;
0471
0472
0473 objName{ii,6} = 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',@fromSimulinkCallback,'Style','checkbox');
0474
0475
0476 end
0477
0478 if paramEnabled(ii) || noParamsReq==1
0479 [xx,yy] = size(objName);
0480 jj=2;
0481 while jj<=yy && ~isempty(objName{ii,jj})
0482 try set(objName{ii,jj},'Enable','on'); set(objName{ii,jj},'ForegroundColor',[0 0 0]); catch end
0483 jj=jj+1;
0484 end
0485 end
0486
0487 end
0488
0489 end
0490
0491
0492
0493
0494
0495 function ContinuousParamCheck(varargin)
0496
0497
0498
0499 currSelection = utils.prog.gcbsh;
0500
0501 if isempty(selBlocks) && isempty(currSelection), return; end
0502 if (~isempty(selBlocks) && isempty(currSelection)) || strcmp(get_param(gcs,'BlockDiagramType'),'library')
0503 delete(findobj(gcf,'Parent',currPanel))
0504 selBlocks = [];
0505 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-300)/2 panelDimens(4)-100-100 300 30],'String','Nothing currently selected','Visible','on','Style','text');
0506 return
0507 end
0508
0509 if ~isempty(bdroot) && ~isempty(find_system(bdroot,'FindAll','on','Type','Annotation','Tag','ltpda model'))
0510
0511
0512 if ((numel(selBlocks)==1 && selBlocks~=gcbh) || length(selBlocks)~=length(currSelection)) && ~isempty(currSelection)
0513 for i=1:length(currSelection)
0514 set_param(currSelection(i),'LinkStatus','inactive');
0515 currentTags{i}=get_param(currSelection(i),'Tag');
0516 end
0517
0518
0519 if numel(currSelection)>1
0520
0521
0522 for i=1:numel(currentTags)
0523 if ~strcmp(currentTags{i},currentTags{1})
0524 ErrorSelectionInconsistent();
0525 selBlocks = currSelection;
0526 return;
0527 end
0528 end
0529
0530 for i=1:numel(currSelection)
0531 childpath = find_system(currSelection(i),'LookUnderMasks','all','BlockType','M-S-Function');
0532 functionname{i}=get_param(childpath,'Tag');
0533 if ~strcmp(functionname{i},functionname{1})
0534 ErrorSelectionInconsistent();
0535 selBlocks = currSelection;
0536 return;
0537 end
0538 end
0539 end
0540
0541
0542 delete(findobj(gcf,'Parent',currPanel))
0543 selBlocks = currSelection;
0544 params = []; newparams = []; paramEnabled = []; oldparamEnabled = []; functionName = ''; paramSets = [];
0545 if getappdata(0,'hidenames') && strcmp(get(gcbh,'ShowName'),'on'), for i=1:length(selBlocks), set_param(selBlocks(i),'ShowName','off'); end;
0546 elseif ~getappdata(0,'hidenames') && strcmp(get(gcbh,'ShowName'),'off'), for i=1:length(selBlocks), set_param(selBlocks(i),'ShowName','on'); end;
0547 end
0548
0549
0550 childpath = find_system(gcbh,'LookUnderMasks','all','BlockType','M-S-Function');
0551 functionName = get_param(childpath,'Tag');
0552 if isempty(functionName)
0553 description = get_param(gcbh,'Description');
0554 funcname = findstr('functionName=',description);
0555 if funcname
0556 i = funcname+14;
0557 while ~strcmp(description(i),';'), i=i+1; end
0558 functionName = description(funcname+14:i-2);
0559 end
0560 end
0561
0562 switch strtok(get(gcbh,'Tag'))
0563
0564 case {'function','freepl','method'}
0565 buildplistFigureParam()
0566
0567 case 'arithmetic'
0568 arithmetic();
0569
0570 case 'input'
0571 LoadInputParamCallback();
0572
0573 case {'mux','demux'}
0574 LoadMuxParamCallback();
0575
0576 case 'from'
0577 LoadFromBlockCallback();
0578
0579 end
0580
0581 end
0582 end
0583
0584 end
0585
0586
0587
0588
0589
0590 function editNameCallback(hObject, varargin)
0591 currParamIndex = get(hObject,'UserData');
0592 newName = get(hObject,'String');
0593 oldName = newparams.params(currParamIndex).key;
0594 addedPar = 0;
0595 try if strcmpi(oldName(1:7),'addPar_'), addedPar = 1; oldName(1:7)=[]; end; catch end
0596
0597 if strcmp(newparams.params(currParamIndex).val,'-->')
0598 block2change = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','Name',lower(oldName));
0599 while ~isempty(find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','Name',lower(newName))), newName = [newName,'x']; end
0600 set_param(block2change{1},'Name',lower(newName))
0601 end
0602
0603 if addedPar, newName = ['addPar_',newName]; end
0604 setKey(newparams.params(currParamIndex),newName);
0605
0606 if strcmp(newparams.params(currParamIndex).val,'-->'), UpdateInports(lower(newName),2); end
0607
0608 set(findobj('Tag','apply'),'Enable','on');
0609 set(findobj('Tag','undo'),'Enable','on');
0610
0611 end
0612
0613
0614 function editValueCallback(hObject, varargin)
0615
0616 expandedEdit = 0;
0617 if numel(get(hObject,'UserData'))>1
0618 hObject = get(hObject,'UserData');
0619 orighObject = hObject(2);
0620 hObject = hObject(1);
0621 expandedEdit = 1;
0622 else
0623 orighObject = hObject;
0624 end
0625 currParamIndex = get(hObject,'UserData');
0626 newValue = get(hObject,'String');
0627
0628 if isempty(newValue), set(orighObject,'String',num2str(newparams.params(currParamIndex).val)); return; end
0629 if strcmp(newValue(1),''''),
0630 paramType = 'char';
0631 newValue(1) = []; newValue(end) = [];
0632 for j = numel(newValue)-1:-1:2
0633 if strcmp(newValue(j),'''') && (~strcmp(newValue(j-1),'''') && ~strcmp(newValue(j+1),''''))
0634 newValue = [newValue(1:j),'''',newValue(j+1:end)];
0635 end
0636 end
0637 elseif ~strcmp(newValue(1),'{'),
0638 paramType = 'double';
0639 else
0640 paramType = 'double';
0641 end
0642
0643 switch paramType
0644 case 'double'
0645 try
0646 newValue = evalin('base',newValue);
0647 if isnumeric(newValue)
0648 set(orighObject,'String',mat2str(newValue))
0649 else
0650 newparams = pset(newparams,newparams.params(currParamIndex).key,newValue);
0651 paramcommand = BuildParamCommand(newparams);
0652 for kk=1:length(selBlocks)
0653 set_param(selBlocks(kk),'Description',paramcommand);
0654 end
0655 AnnotationUpdate(newparams);
0656 buildplistFigureParam([],[],get(findobj('Tag','paramsPage'),'UserData'))
0657 return
0658 end
0659 catch
0660 oldValue = newparams.params(currParamIndex).val;
0661 if ~isa(oldValue,'char'), mat2str(oldValue); end
0662 set(orighObject,'String',oldValue)
0663 return
0664 end
0665 end
0666
0667 if expandedEdit, paramEnabled(currParamIndex) = 1; end
0668 newparams = pset(newparams,newparams.params(currParamIndex).key,newValue);
0669
0670 set(findobj('Tag','apply'),'Enable','on');
0671 set(findobj('Tag','undo'),'Enable','on');
0672
0673 end
0674
0675
0676 function browseCallback(hObject, varargin)
0677
0678 [meth,clas] = strtok(get_param(gcbh,'Tag'),' ');
0679 categ = 'none';
0680 if strcmp(meth,'method')
0681 clas = strtrim(clas);
0682 infoObj = eval([clas,'.getInfo(''',functionName,''')']);
0683 categ = infoObj.mcategory;
0684 end
0685
0686 if strcmp(categ,'Output')
0687 [fileName,filePath] = uiputfile('*.*','Choose destination file');
0688 else
0689 [fileName,filePath] = uigetfile('*.*','Choose source file');
0690 end
0691
0692 if fileName==0
0693 return
0694 else
0695 [file , ext] = strtok(fileName,'.');
0696 if strcmp(ext,'.*'), fileName(end)=[]; fileName=[fileName,'dat']; end
0697 fileName = [filePath,fileName];
0698 end
0699 editFieldHandle = get(hObject,'UserData');
0700 set(editFieldHandle,'String',fileName);
0701
0702 newValue = fileName;
0703 newparams = pset(newparams,'FILENAME',newValue);
0704
0705 set(findobj('Tag','apply'),'Enable','on');
0706 set(findobj('Tag','undo'),'Enable','on');
0707
0708 end
0709
0710
0711
0712
0713 function WindListCallback(hObject, varargin)
0714 currParamID = get(hObject,'UserData');
0715 currWindValue = get(hObject,'Value');
0716 listWindows = ['Kaiser',specwin.getTypes];
0717 currWindow = listWindows{currWindValue};
0718 oldWindObj = newparams.params(currParamID).val;
0719 oldWindow = oldWindObj.type;
0720 if strcmp(currWindow,oldWindow), return;
0721 else
0722 currWindLength = str2double(get(objName{currParamID,5},'String'));
0723 if strcmp(currWindow,'Kaiser'), windobj = specwin(currWindow,currWindLength,round(oldWindObj.psll));
0724 else windobj = specwin(currWindow,currWindLength);
0725 end
0726 end
0727
0728 newparams=pset(newparams,newparams.params(currParamID).key,windobj);
0729
0730 set(findobj('Tag','apply'),'Enable','on');
0731 set(findobj('Tag','undo'),'Enable','on');
0732
0733 if strcmp(currWindow,'Kaiser') || strcmp(oldWindow,'Kaiser'), buildplistFigureParam([],[],get(findobj('Tag','paramsPage'),'UserData')); end
0734
0735 end
0736
0737
0738 function WindlengthCallback(hObject,varargin)
0739
0740
0741
0742 currParamID = get(hObject,'UserData');
0743 selectedWind = newparams.params(currParamID).val.type;
0744 currWindLength = str2double(get(hObject,'String'));
0745
0746
0747 if strcmp(selectedWind,'Kaiser')
0748 windobj = specwin(selectedWind,currWindLength, newparams.params(currParamID).val.psll);
0749 else
0750 windobj = specwin(selectedWind,currWindLength);
0751 end
0752
0753 newparams=pset(newparams,newparams.params(currParamID).key,windobj);
0754
0755 set(findobj('Tag','apply'),'Enable','on');
0756 set(findobj('Tag','undo'),'Enable','on');
0757
0758 end
0759
0760
0761 function WindPSLCallback(hObject,varargin)
0762
0763
0764
0765 currParamID = get(hObject,'UserData');
0766 selectedWind = newparams.params(currParamID).val.type;
0767 currWindLength = numel(newparams.params(currParamID).val.win);
0768 currPSL = round(str2double(get(hObject,'String')));
0769 set(hObject,'String',num2str(currPSL))
0770
0771 windobj = specwin(selectedWind,currWindLength, currPSL);
0772 newparams = pset(newparams,newparams.params(currParamID).key,windobj);
0773
0774 set(findobj('Tag','apply'),'Enable','on');
0775 set(findobj('Tag','undo'),'Enable','on');
0776
0777 end
0778
0779
0780
0781
0782
0783 function pzmodelLoad(hObject, varargin)
0784 currParamIndex = get(hObject,'UserData');
0785
0786 try [FileName,PathName] = uigetfile('*.xml','Select the .XML pzmodel file');
0787 FileAddress = strcat(PathName,FileName);
0788 pzObj = pzmodel(FileAddress);
0789 if isempty(pzObj), return; end
0790 newparams = pset(newparams,newparams.params(currParamIndex).key,pzObj);
0791 catch
0792 end
0793
0794 set(findobj('Tag','apply'),'Enable','on');
0795 set(findobj('Tag','undo'),'Enable','on');
0796
0797
0798 end
0799
0800
0801 function pzmodelGainEdit(hObject, varargin)
0802 currParamIndex = get(hObject,'UserData');
0803 pzGain = str2double(get(hObject,'String'));
0804
0805 pzObj = newparams.params(currParamIndex);
0806 pzKey = pzObj.key;
0807 pzObj = pzObj.val;
0808 pzObj = pzmodel(pzGain,pzObj.poles,pzObj.zeros);
0809 newparams = pset(newparams,pzKey,pzObj);
0810
0811 set(findobj('Tag','apply'),'Enable','on');
0812 set(findobj('Tag','undo'),'Enable','on');
0813
0814 end
0815
0816
0817 function pzmodelPZEdit(hObject,varargin)
0818 currParamIndex = get(hObject,'UserData');
0819 poleORzero = varargin{2};
0820 pzes = get(hObject,'String');
0821 pzes = readInput(pzes,2);
0822 [xx,yy] = size(pzes);
0823 pzList = pz();
0824 for kk = 1:xx
0825 if (yy>1 && pzes(kk,2)==0) || yy==1 , pzList(kk) = pz(pzes(kk,1));
0826 else pzList(kk) = pz(pzes(kk,1),pzes(kk,2));
0827 end
0828 end
0829
0830 pzObj = newparams.params(currParamIndex);
0831 pzKey = pzObj.key;
0832 pzObj = pzObj.val;
0833 if poleORzero, pzObj = pzmodel(pzObj.gain,pzList,pzObj.zeros);
0834 else pzObj = pzmodel(pzObj.gain,pzObj.poles,pzList);
0835 end
0836 newparams = pset(newparams,pzKey,pzObj);
0837
0838 set(findobj('Tag','apply'),'Enable','on');
0839 set(findobj('Tag','undo'),'Enable','on');
0840
0841 if numel(pzObj.poles)>1 || numel(pzObj.zeros)>1, buildplistFigureParam([],[],get(findobj('Tag','paramsPage'),'UserData')); end
0842
0843 end
0844
0845
0846
0847
0848
0849 function poleEdit(hObject, varargin)
0850 currParamIndex = get(hObject,'UserData');
0851 poles = get(hObject,'String');
0852 poles = readInput(poles,2);
0853 [xx,yy] = size(poles);
0854 poleList = pz();
0855 for kk=1:xx
0856 if (yy>1 && poles(kk,2)==0) || yy==1 , poleList(kk) = pz(poles(kk,1));
0857 else poleList(kk) = pz(poles(kk,1),poles(kk,2));
0858 end
0859 end
0860 newparams = pset(newparams,newparams.params(currParamIndex).key,poleList);
0861
0862 set(findobj('Tag','apply'),'Enable','on');
0863 set(findobj('Tag','undo'),'Enable','on');
0864
0865 end
0866
0867
0868
0869
0870
0871 function zeroEdit(hObject, varargin)
0872 currParamIndex = get(hObject,'UserData');
0873 zeros = get(hObject,'String');
0874 zeros = readInput(zeros,2);
0875 [xx,yy] = size(zeros);
0876 zeroList = pz();
0877 for kk=1:xx
0878 if (yy>1 && zeros(kk,2)==0) || yy==1 , zeroList(kk)=pz(zeros(kk,1));
0879 else zeroList(kk)=pz(zeros(kk,1),zeros(kk,2));
0880 end
0881 end
0882 newparams = pset(newparams,newparams.params(currParamIndex).key,zeroList);
0883
0884 set(findobj('Tag','apply'),'Enable','on');
0885 set(findobj('Tag','undo'),'Enable','on');
0886
0887 end
0888
0889
0890
0891
0892
0893 function AddParamCallback(hObject,varargin)
0894
0895 hparamType = get(hObject,'UserData');
0896 if isa(hparamType,'char') && strcmp(hparamType,'input')
0897 key = 'input';
0898 while ~isempty(find(newparams,key)), key =[key,'x']; end
0899 newparams = append(newparams, param(key,'-->'));
0900 UpdateInports(key,1);
0901 paramcommand = BuildParamCommand(newparams);
0902 for kk=1:length(selBlocks)
0903 set_param(selBlocks(kk),'Description',paramcommand);
0904 end
0905 arithmetic();
0906
0907 else
0908 paramTypes = get(hparamType,'String');
0909 paramType = paramTypes{get(hparamType,'Value')};
0910
0911 switch paramType
0912 case {'double','double/char'}
0913 key = 'addPar_name';
0914 while ~isempty(find(newparams,key))
0915 key =[key,'x'];
0916 end
0917 newparams = append(newparams, param(key,1));
0918 case 'specwin'
0919 newParam = param('addPar_Win',specwin('Kaiser',1000,200));
0920 newparams = append(newparams, newParam);
0921 case 'pzmodel'
0922 pzObj = pzmodel(1,[pz(10,2),pz(100)],pz(1));
0923 newParam = param('addPar_pzmodel',pzObj);
0924 newparams = append(newparams, newParam);
0925 case '-->'
0926 key = 'addPar_name';
0927 while find(newparams,key)
0928 key = [key,'x'];
0929 end
0930 newparams = append(newparams, param(key,'-->'));
0931 UpdateInports(key,1)
0932 case 'pz'
0933 newparams = append(newparams, param('addPar_pz',pz(1)));
0934
0935 end
0936
0937 if nparams(newparams)==1, paramEnabled=1;
0938 else paramEnabled=[paramEnabled,1];
0939 end
0940
0941 set(findobj('Tag','apply'),'Enable','on');
0942 set(findobj('Tag','undo'),'Enable','on');
0943
0944 buildplistFigureParam([],[],get(findobj('Tag','paramsPage'),'UserData'))
0945 end
0946 end
0947
0948
0949
0950 function RemParamCallback(hObject, varargin)
0951
0952 currParamIndex = get(hObject,'UserData');
0953
0954 paramKey = newparams.params(currParamIndex).key;
0955 paramVal = newparams.params(currParamIndex).val;
0956 newparams = remove(newparams,paramKey);
0957 if ~strcmp(get_param(gcbh,'Tag'),'arithmetic'), paramEnabled(currParamIndex)=[]; end
0958
0959 if strcmp(paramVal,'-->')
0960 UpdateInports(paramKey,-1);
0961 end
0962 delete(hObject)
0963
0964 set(findobj('Tag','apply'),'Enable','on');
0965 set(findobj('Tag','undo'),'Enable','on');
0966
0967 if strcmp(get_param(gcbh,'Tag'),'arithmetic'), arithmetic();
0968 else buildplistFigureParam([],[],get(findobj('Tag','paramsPage'),'UserData'))
0969 end
0970 end
0971
0972
0973
0974 function fromSimulinkCallback(hObject, varargin)
0975 currParamIndex = str2double(get(hObject,'Tag'));
0976 status = get(hObject,'Value');
0977
0978 paramval = get(hObject,'UserData');
0979 paramKey = newparams.params(currParamIndex).key;
0980 if status
0981 if ~isempty(paramval)
0982 newparams = pset(newparams,paramKey,{'-->'});
0983 else
0984 newparams = pset(newparams,paramKey,'-->');
0985 end
0986 paramEnabled(currParamIndex) = 1;
0987 UpdateInports(paramKey,1)
0988 else
0989
0990 [func,currClass] = strtok(get(gcbh,'Tag'));
0991 infoObj = eval([currClass,'.getInfo(''',functionName,''')']);
0992
0993 if numel(infoObj.sets) > 1
0994 currSet = find(paramSets,'currSet');
0995 origParams = infoObj.plists(currSet);
0996 else
0997 origParams = infoObj.plists;
0998 end
0999
1000 paramKey = newparams.params(currParamIndex).key;
1001 origPar = find(origParams,paramKey);
1002 if isempty(origPar), origPar = 1; end
1003 newparams = pset(newparams,paramKey,origPar);
1004 paramEnabled(currParamIndex) = 0;
1005 UpdateInports(paramKey,-1)
1006 end
1007
1008 buildplistFigureParam([],[],get(findobj('Tag','paramsPage'),'UserData'))
1009
1010 end
1011
1012
1013
1014 function UpdateInports(varargin)
1015
1016
1017
1018 paramKey = varargin{1};
1019 if numel(paramKey)>7 && strcmpi(paramKey(1:7),'addPar_'), paramKey(1:7)=[]; end
1020
1021
1022 simKey = {};
1023 for i=1:nparams(newparams)
1024 if isa(newparams.params(i).val,'char') && strcmp(newparams.params(i).val,'-->')
1025 name = newparams.params(i).key;
1026 try if strcmpi(name(1:7),'addPar_'), name(1:7)=[]; end; catch end
1027 simKey{end+1} = name;
1028 elseif isa(newparams.params(i).val,'cell') && isa(newparams.params(i).val{1},'char') && strcmp(newparams.params(i).val{1},'-->')
1029 name = newparams.params(i).key;
1030 try if strcmpi(name(1:7),'addPar_'), name(1:7)=[]; end; catch end
1031 simKey{end+1} = name;
1032 end
1033 end
1034
1035
1036
1037
1038
1039 if varargin{2}~=2
1040
1041
1042 if varargin{2}==-1, simKey2remove = [simKey,{paramKey}]; else simKey2remove= simKey; end
1043 for i=1:numel(simKey2remove)
1044 try
1045 block2delete = utils.prog.find_in_models(gcb,'SearchDepth',1,'LookUnderMasks','all','Name',lower(simKey2remove{i}));
1046 if numel(block2delete)>1, block2delete(1)=[]; end
1047 blockLines = get_param(block2delete{1},'LineHandles');
1048 if (blockLines.Outport(1)~=-1 && ~isempty(blockLines.Outport(1))), delete_line(blockLines.Outport(1)); end
1049 delete_block(block2delete);
1050 catch end
1051 end
1052
1053
1054 for i=1:numel(simKey)
1055 newBlock = add_block('simulink/Sources/In1', [gcb,'/Inport1'],'MakeNameUnique','on');
1056 nameAlreadyPresent = utils.prog.find_in_models(gcb,'SearchDepth',1,'LookUnderMasks','all','Name',lower(simKey{i}));
1057 if ~isempty(nameAlreadyPresent)
1058 for j=1:numel(nameAlreadyPresent)
1059 if ~strcmp(nameAlreadyPresent{j},gcb),
1060 set_param(nameAlreadyPresent{j},'Name',[lower(simKey{i}),'_fun']);
1061 end
1062 end
1063 end
1064 set(newBlock,'Name',lower(simKey{i}))
1065 end
1066
1067
1068 muxblock = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Mux');
1069 try
1070 muxLines = get_param(muxblock{1},'LineHandles');
1071 for k=1:numel(muxLines.Inport), if (muxLines.Inport(k)~=-1 && ~isempty(muxLines.Inport(k))), delete_line(muxLines.Inport(k)); end
1072 end
1073 for k=1:numel(muxLines.Outport), if (muxLines.Outport(k)~=-1 && ~isempty(muxLines.Outport(k))), delete_line(muxLines.Outport(k)); end
1074 end
1075 catch end
1076 delete_block(muxblock);
1077 inports = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Inport');
1078 fakeInp = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Ground');
1079 inports = [fakeInp;inports];
1080 if numel(inports)>1
1081 muxblock = add_block('built-in/Mux', [gcb,'/Mux']);
1082 set(muxblock,'Position',[70 , 10 , 73 , 150])
1083 set(muxblock,'Inputs',num2str(numel(inports)))
1084 end
1085 for k=1:numel(inports)
1086 inports{k}=get_param(inports{k},'Handle');
1087 blkLines = get(inports{k},'LineHandles');
1088 for j=1:numel(blkLines.Outport), if (blkLines.Outport(j)~=-1 && ~isempty(blkLines.Outport(j))), delete_line(blkLines.Outport(j)); end
1089 end
1090 set(inports{k},'Position',[10 , 10+30*(k-1) , 30 , 30+30*(k-1)])
1091 set(inports{k},'Tag',num2str(k))
1092 if numel(inports)>1
1093 add_line(gcb,[get(inports{k},'Name'),'/1'],[get(muxblock,'Name'),'/',num2str(k)]);
1094 end
1095 end
1096 funcBlock = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','M-S-Function');
1097 funcBlock = get_param(funcBlock,'Name');
1098 if numel(inports)>1
1099 add_line(gcb,[get(muxblock,'Name'),'/1'],[funcBlock{1},'/1']);
1100 else
1101 add_line(gcb,[get(inports{1},'Name'),'/1'],[funcBlock{1},'/1']);
1102 end
1103
1104 end
1105
1106
1107
1108
1109 fakeInp = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Ground');
1110 drawingCom = '';
1111 if numel(simKey)>0
1112 if numel(fakeInp)>0 || strcmp(get_param(gcbh,'Tag'),'arithmetic'), currInp=1; else currInp=str2double(get(findobj('Tag','numbDataInputs'),'String'))+1; end
1113 for nn=1:numel(simKey)
1114 drawingCom = [drawingCom,'port_label(''input'',',num2str(currInp),',''',lower(simKey{1}),''');'];
1115 simKey(1) = [];
1116 currInp = currInp+1;
1117 end
1118 else
1119 funcBlock = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','M-S-Function');
1120 funcName = get_param(funcBlock{1},'Tag');
1121 if numel(funcName)>6 && strcmp(funcName(1:6),'ltpda_'), funcName(1:6)=[]; end
1122 drawingCom = strcat('disp(''',lower(funcName),''')');
1123 end
1124 set(gcbh,'MaskDisplay',drawingCom)
1125
1126 end
1127
1128
1129
1130 function numberDataInput(hObject,varargin)
1131
1132
1133 prevNumb = get(hObject,'UserData');
1134 newNumb = str2double(get(hObject,'String'));
1135 if isnan(newNumb), set(hObject,'String',num2str(prevNumb)); return; end
1136
1137 fakeInp = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Ground');
1138 if ~isempty(fakeInp) && newNumb>0
1139 blockLines = get_param(fakeInp{1},'LineHandles');
1140 if (blockLines.Outport(1)~=-1 && ~isempty(blockLines.Outport(1))), delete_line(blockLines.Outport(1)); end
1141 delete_block(fakeInp{1})
1142 end
1143
1144 dataInports = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Inport');
1145
1146 paramFromSimulink = 0;
1147 for ii=1:nparams(newparams)
1148 paramvals{ii} = newparams.params(ii).val;
1149 if isa(paramvals{ii},'char') && numel(paramvals{ii})>2 && strcmp(paramvals{ii},'-->'), paramFromSimulink = paramFromSimulink + 1; end
1150 end
1151
1152
1153 for ii=1:paramFromSimulink
1154 set_param(dataInports{end-paramFromSimulink+ii},'Port',num2str(newNumb+11));
1155 end
1156
1157 dataInports(end-paramFromSimulink+1:end) = [];
1158
1159
1160 for ii=1:numel(dataInports)
1161 try
1162 blockLines = get_param(dataInports{ii},'LineHandles');
1163 if (blockLines.Outport(1)~=-1 && ~isempty(blockLines.Outport(1))), delete_line(blockLines.Outport(1)); end
1164 delete_block(dataInports{ii});
1165 catch end
1166 end
1167
1168
1169 if newNumb==0, add_block('simulink/Sources/Ground', [gcb,'/data_input'],'MakeNameUnique','on','Name','data'); end
1170 for ii=1:newNumb
1171 newBlock = add_block('simulink/Sources/In1', [gcb,'/Inport1'],'MakeNameUnique','on','Name',['data',num2str(ii)]);
1172 set_param(newBlock,'Port',num2str(ii));
1173 end
1174
1175 UpdateInports('',1)
1176
1177 end
1178
1179
1180
1181 function EnableCallback(hObject,varargin)
1182
1183
1184
1185 currParamID = get(hObject,'UserData');
1186 [xx,yy] = size(objName);
1187 switch get(hObject,'Value')
1188 case 1
1189 jj=2;
1190 while jj<=yy && ~isempty(objName{currParamID,jj})
1191 try set(objName{currParamID,jj},'Enable','on'); set(objName{currParamID,jj},'ForegroundColor',[0 0 0]); catch end
1192 jj=jj+1;
1193 end
1194 paramEnabled(currParamID)=1;
1195 case 0
1196 jj=2;
1197 while jj<=yy && ~isempty(objName{currParamID,jj})
1198 try
1199 if strcmp(get(objName{currParamID,jj},'Style'),'checkbox') && strcmp(get(objName{currParamID,jj},'String'),'From Simulink')
1200 else
1201 set(objName{currParamID,jj},'Enable','off');
1202 set(objName{currParamID,jj},'ForegroundColor',[0.7 0.7 0.7]);
1203 end
1204 catch end
1205 jj=jj+1;
1206 end
1207 paramEnabled(currParamID)=0;
1208 end
1209
1210 set(findobj('Tag','apply'),'Enable','on');
1211 set(findobj('Tag','undo'),'Enable','on');
1212
1213 end
1214
1215
1216
1217 function ExpandEdit(hObject,varargin)
1218
1219
1220
1221 origEditField = get(hObject,'UserData');
1222 currParamIndex = get(origEditField,'UserData');
1223 paramkey = newparams.params(currParamIndex).key;
1224 if numel(paramkey)>6 && strcmpi(paramkey(1:7),'addpar_'), paramkey(1:7)=[]; end
1225 paramval = get(origEditField,'String');
1226
1227 editFigPos = [200,200,800,300];
1228
1229 editFigure = figure('Name',paramkey,'Tag','expandedEditField','MenuBar','none','Toolbar','none','NumberTitle','off','Units','pixels','Position',editFigPos,'Resize','on','ResizeFcn','refresh(gcf)','Color', get(0, 'defaultuicontrolbackgroundcolor'));
1230
1231 uicontrol('Parent',editFigure,'HorizontalAlignment','left','Position',[5 editFigPos(4)-30 editFigPos(3)-10 20],'String','Use this box to type in the value of the selected parameter:','FontName','Times New Roman','FontSize',9,'FontWeight','normal','Visible','on','Style','text');
1232
1233 editField = uicontrol('Parent',editFigure,'String',paramval,'UserData',currParamIndex,'Units','pixels','HorizontalAlignment','left','Position',[5 30 editFigPos(3)-7 editFigPos(4)-60],'FontSize',guiFontSize+1,'Visible','on','max',100,'Style','edit');
1234
1235 uicontrol('UserData',[editField,origEditField],'TooltipString','Accept this setting','String','Ok','Parent',editFigure,'BackgroundColor',[0.7 0.7 0.7],'HorizontalAlignment','center','Position',[editFigPos(3)-150 5 70 20],'Visible','on','Callback',@editValueCallback,'Style','pushbutton');
1236
1237 uicontrol('TooltipString','Discard this setting','String','Cancel','Parent',editFigure,'BackgroundColor',[0.7 0.7 0.7],'HorizontalAlignment','center','Position',[editFigPos(3)-75 5 70 20],'Visible','on','Callback','closereq','Style','pushbutton');
1238 end
1239
1240
1241
1242
1243
1244 function [array]=readInput(inputdata, maxnumb, varargin)
1245 [xx,yy]=size(inputdata);
1246
1247
1248 array=[];
1249 for i=1:xx
1250 rowpos=1;
1251 elemidx(i)=1;
1252 for j=1:yy+1
1253 if (j==yy+1 || inputdata(i,j)==',' || strcmp(inputdata(i,j),' ') ) && (j==1 || (j>1 && (~strcmp(inputdata(i,j-1),' '))))
1254 if (j==1 || strcmp(inputdata(i,j-1),',')) && strcmp(inputdata(i,j),',')
1255 array(i,elemidx(i))=0;
1256 elemidx(i)=elemidx(i)+1;
1257 rowpos=j+1;
1258 else
1259
1260
1261
1262
1263 array(i,elemidx(i))=eval(inputdata(i,rowpos:j-1));
1264 rowpos=j+1;
1265 elemidx(i)=elemidx(i)+1;
1266 end
1267 elseif j<yy+1 && strcmp(inputdata(i,j),' ')
1268 rowpos=j+1;
1269 end
1270 if maxnumb~=0
1271 if elemidx(i)==maxnumb+1, break; end
1272 end
1273 end
1274 elemidx(i)=elemidx(i)-1;
1275 end
1276 end
1277
1278
1279
1280 function paramcommand = BuildParamCommand(paramlist,varargin)
1281
1282
1283
1284 paramcommand = strcat('params=',string(paramlist),';');
1285
1286 if strcmpi(get_param(gcbh,'Tag'),'arithmetic'), return; end
1287
1288 if exist('paramEnabled','var') && ~isempty(paramEnabled)
1289 paramcommand = [paramcommand,' paramEnabled=',mat2str(paramEnabled),';'];
1290 end
1291
1292 if ~exist('newparams','var') || nparams(paramlist)==0, paramcommand='params=plist(); paramEnabled=[];'; end
1293
1294 if exist('noParamsReq','var') && noParamsReq==1
1295 paramcommand = [paramcommand,' noParamsReq=1;'];
1296 end
1297
1298 description = get_param(gcbh,'Description');
1299 funcname = findstr('functionName=',description);
1300 if funcname
1301 i = funcname+14;
1302 while ~strcmp(description(i),';'), i=i+1; end
1303 funcname = description(funcname+13:i-1);
1304 paramcommand = [paramcommand,' functionName=',funcname,';'];
1305 end
1306
1307 if exist('paramSets','var') && ~isempty(paramSets)
1308 paramcommand = [paramcommand,' paramSets=',string(paramSets),';'];
1309 end
1310
1311 end
1312
1313
1314
1315 function paramcommand = RetrievePlist(varargin)
1316
1317
1318
1319 try functionname = varargin{1};
1320 catch
1321 childpath = find_system(gcbh,'LookUnderMasks','all','BlockType','M-S-Function');
1322 functionname=get_param(childpath,'Tag');
1323 end
1324
1325 if isempty(functionname)
1326 description = get_param(gcbh,'Description');
1327 funcname = findstr('functionName=',description);
1328 if funcname
1329 i = funcname+14;
1330 while ~strcmp(description(i),';'), i=i+1; end
1331 functionname = description(funcname+14:i-2);
1332 end
1333 end
1334
1335 setappdata(0,'ltpda_currFunctionName',functionname);
1336
1337 try
1338 switch functionname
1339 case 'generic'
1340 paramcommand = 'functionName=''generic'';params=plist();paramEnabled=[];';
1341 return
1342 case 'arithmetic'
1343 paramcommand = 'functionName=''arithmetic'';params=plist(''alpha'',''-->'',''beta'',''-->'');';
1344 return
1345 otherwise
1346 [func,currClass] = strtok(get(gcbh,'Tag'));
1347 currClass(1)=[];
1348 infoObj = eval([currClass,'.getInfo(''',functionname,''')']);
1349
1350 if numel(infoObj.sets) > 1
1351 paramSets = plist('sets',infoObj.sets,'currSet',1);
1352 paramcommand = ['paramSets=',string(paramSets),';','params=plist();'];
1353 elseif numel(infoObj.sets) == 1 && nparams(infoObj.plists)
1354 paramEnabled = zeros(1,nparams(infoObj.plists));
1355 paramcommand = ['params=',string(infoObj.plists),'; paramEnabled=',mat2str(paramEnabled),';'];
1356 else
1357 paramcommand = 'params=plist();';
1358 end
1359
1360 end
1361 catch ME
1362 disp(sprintf('Error: unable to retrieve the parameters required by the function "%s". Maybe it''s not supported yet?',functionname));
1363 ErrorFuncNotSupported();
1364 rethrow(ME)
1365 end
1366
1367 end
1368
1369
1370
1371 function AnnotationUpdate(paramlist,varargin)
1372
1373
1374
1375 annotation = '';
1376 numparams = nparams(paramlist);
1377 firstpar = 1;
1378
1379 if strcmpi(get_param(gcbh,'Tag'),'arithmetic')
1380 eq = get(findobj('Tag','equationField'),'String');
1381 if ~isempty(eq)
1382 if numel(eq)>40, eq(1:end-25) = []; eq = ['...',eq]; end
1383 for nn=1:length(selBlocks)
1384 set_param(selBlocks(nn),'AttributesFormatString',eq);
1385 end
1386 end
1387 return
1388 end
1389
1390 for kk=1:numparams
1391 if paramEnabled(kk)
1392 paramkey = paramlist.params(kk).key;
1393 try
1394 if strcmpi(paramkey(1:7),'addPar_'), paramkey(1:7)=[]; end
1395 catch end
1396 paramval = paramlist.params(kk).val;
1397 switch class(paramval)
1398 case 'specwin'
1399 windowName = paramval.type;
1400 windowlength = size(paramval.win,2);
1401 if firstpar==1
1402 annotation = ['(specwin) ',windowName,',',num2str(windowlength)];
1403 firstpar=2;
1404 else
1405 annotation = [annotation,'\n','(specwin) ',windowName,',',num2str(windowlength)];
1406 end
1407 if strcmp(windowName,'Kaiser')
1408 windowPsll = paramval.psll;
1409 annotation = [annotation,',',num2str(windowPsll)];
1410 end
1411 case 'double'
1412 paramval = mat2str(paramval);
1413 if numel(paramval)>25, paramval=['...',paramval(end-25:end)]; end
1414 if firstpar==1, annotation=[lower(paramkey),' ',paramval]; firstpar=2;
1415 else annotation = [annotation,'\n',lower(paramkey),' ',num2str(paramval)];
1416 end
1417 case 'char'
1418 if numel(paramval)>25, paramval=['...',paramval(end-25:end)]; end
1419 paramval = strrep(paramval,'''''','''');
1420 if firstpar==1, annotation=[lower(paramkey),' ',paramval]; firstpar=2;
1421 else annotation = [annotation,'\n',lower(paramkey),' ',paramval];
1422 end
1423 case 'pzmodel'
1424 if firstpar==1, annotation='(pzmodel)'; firstpar=2;
1425 else annotation = [annotation,'\n','(pzmodel)'];
1426 end
1427 case 'cell'
1428 if isa(paramval{1},'char') && strcmp(paramval{1},'(-->)'), strParKey = '(-->)';
1429 else strParKey = utils.prog.cell2str(paramval);
1430 end
1431 if firstpar==1
1432 annotation = [lower(paramkey),' ',strParKey]; firstpar=2;
1433 else annotation = [annotation,'\n',lower(paramkey),' ',strParKey];
1434 end
1435 case 'pz'
1436 for mm=1:numel(paramval)
1437 poleFreqs(mm,1) = paramval(mm).f;
1438 poleQs(mm,1) = paramval(mm).q;
1439 if ~isnan(poleQs(mm,1))
1440 poleFQs{mm,1}=strcat(num2str(poleFreqs(mm,1)),',',num2str(poleQs(mm,1)));
1441 else
1442 poleFQs{mm,1}=num2str(poleFreqs(mm,1));
1443 end
1444 end
1445 poleFQs=char(poleFQs);
1446 if firstpar==1
1447 annotation = ['pz ',poleFQs(1,:)]; firstpar=2;
1448 for j=2:size(poleFQs,1), annotation = [annotation,'\n','(pz) ',poleFQs(j,:)]; end
1449 else
1450 annotation = [annotation,'\n','pole ',poleFQs(1,:)];
1451 for j=2:size(poleFQs,1), annotation = [annotation,'\n','(pz) ',poleFQs(j,:)]; end
1452 end
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471 end
1472 end
1473 end
1474
1475 for nn=1:length(selBlocks), set_param(selBlocks(nn),'AttributesFormatString',annotation); end
1476 end
1477
1478
1479
1480 function functionNameSet(hObject, varargin)
1481
1482
1483 functionName2 = get(hObject,'String');
1484 classes = utils.helper.ltpda_userclasses;
1485 for i=1:numel(classes)
1486 if ismethod(eval(classes{i}),functionName2)
1487 currSel = utils.prog.gcbsh;
1488 for j=1:numel(currSel), set(currSel(j),'Tag',['method ',classes{i}]); end
1489 break
1490 else
1491 currSel = utils.prog.gcbsh;
1492 for j=1:numel(currSel), set(currSel(j),'Tag','function'); end
1493 end
1494 end
1495 paramcommand = RetrievePlist(functionName2);
1496
1497 if ~isempty(paramcommand)
1498 functionName = functionName2;
1499
1500 paramcommand = strcat(paramcommand,'functionName=''',functionName2,''';');
1501 for i=1:1000
1502 try
1503 for kk=1:length(selBlocks), set_param(selBlocks(kk),'Name',functionName2); end
1504 break;
1505 catch
1506 functionName2 = strcat(functionName,'_',num2str(i));
1507 end
1508 end
1509 for kk=1:length(selBlocks), set_param(selBlocks(kk),'Description',paramcommand); end
1510 delete(findobj(gcf,'Parent',currPanel))
1511 buildplistFigureParam([],[],get(findobj('Tag','paramsPage'),'UserData'))
1512
1513 else
1514 description = get_param(gcbh,'Description');
1515 funcname = findstr('functionName=',description);
1516 if funcname
1517 i = funcname+14;
1518 while ~strcmp(description(i),';'), i=i+1; end
1519 functionName = description(funcname+14:i-2);
1520 end
1521 set(hObject,'String',functionName);
1522
1523 end
1524
1525
1526 end
1527
1528
1529
1530
1531
1532 function SetsUpdate(hObject,varargin)
1533
1534 currSet = get(hObject,'Value');
1535 paramSets = pset(paramSets,'currSet',currSet);
1536 functionname = getappdata(0,'ltpda_currFunctionName');
1537
1538 [func,currClass] = strtok(get(gcbh,'Tag'));
1539 infoObj = eval([currClass,'.getInfo(''',functionname,''')']);
1540
1541 newparams = infoObj.plists(currSet);
1542 paramEnabled = zeros(1,nparams(newparams));
1543
1544 paramcommand = BuildParamCommand(newparams);
1545 for kk=1:length(selBlocks), set_param(selBlocks(kk),'Description',paramcommand); end
1546
1547
1548 for nn=1:length(selBlocks), set_param(selBlocks(nn),'AttributesFormatString',''); end
1549
1550 buildplistFigureParam([],[],get(findobj('Tag','paramsPage'),'UserData'));
1551 end
1552
1553
1554
1555
1556
1557 function HelpButtonCallback(varargin)
1558
1559
1560 try
1561 childpath = find_system(gcbh,'LookUnderMasks','all','BlockType','M-S-Function');
1562 functionname = get_param(childpath,'Tag');
1563
1564 description = get_param(gcbh,'Description');
1565 funcname = findstr('functionName=',description);
1566 if funcname
1567 i = funcname+14;
1568 while ~strcmp(description(i),';'), i=i+1; end
1569 functionname = description(funcname+14:i-2);
1570 end
1571
1572 [func,classes] = strtok(get(gcbh,'Tag'));
1573 if strcmp(func,'method')
1574 helptext = help([strtrim(classes),'/',functionname]);
1575 else
1576 helptext = help(functionname);
1577 end
1578
1579 helpFigure = figure('MenuBar','none','Toolbar','none','Name',strcat(functionname,' help'),'NumberTitle','off','Units','pixels','Position',[200,200,500,300],'Resize','on','ResizeFcn','refresh(gcf)','Color', get(0, 'defaultuicontrolbackgroundcolor'));
1580
1581 uicontrol('Parent',helpFigure,'Units','normalized','HorizontalAlignment','left','Position',[0 0 1 1],'FontSize',guiFontSize+1,'String',helptext,'Visible','on','max',100,'Style','edit');
1582 catch
1583 disp('Something''s wrong with the creation of the Help figure. Please check ''HelpButtonCallback''')
1584 end
1585 end
1586
1587
1588
1589 function ResetButtonCallback(varargin)
1590
1591
1592
1593 screenSize = get(0,'ScreenSize');
1594 backColor = [1 1 1];
1595 position = [(screenSize(3)-250)/2,(screenSize(4)-160)/2,250,160];
1596 confirmFig = figure('Position',position,'Name','Please confirm reset','Tag','ConfirmReset','Resize','off','NumberTitle','off','Toolbar','none','Menubar','none');
1597
1598 uicontrol('Parent',confirmFig,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[0 position(4)-40 position(3) 20],'String','Are you sure?','FontName','Times New Roman','FontSize',13,'FontWeight','normal','Visible','on','Style','text');
1599
1600 dimension = position;
1601 logosize = [77 95];
1602 dimension = [50 , dimension(4)-logosize(2)-50 , logosize];
1603 yesbut = axes('Parent',confirmFig,'Units','pixels','Position',dimension,'Tag','Yes');
1604 image(imread('buttonyes2.jpg'),'Parent',yesbut,'ButtonDownFcn','set(findobj(''Tag'',''ConfirmReset''),''UserData'',0); uiresume;','Tag','YesButton');
1605 axis(yesbut,'off');
1606
1607 dimension = position;
1608 logosize = [77 95];
1609 dimension = [127 , dimension(4)-logosize(2)-50 , logosize];
1610 nobut = axes('Parent',confirmFig,'Units','pixels','Position',dimension,'Tag','No');
1611 image(imread('buttonno2.jpg'),'Parent',nobut,'ButtonDownFcn','set(findobj(''Tag'',''ConfirmReset''),''UserData'',1); uiresume;','Tag','NoButton');
1612 axis(nobut,'off');
1613
1614 uiwait;
1615
1616 if get(confirmFig,'UserData'), delete(confirmFig); return; end
1617 delete(confirmFig);
1618
1619 for i=1:length(selBlocks), set_param(selBlocks(i),'Description',''); set_param(selBlocks(i),'AttributesFormatString',''); end
1620 params = []; newparams = []; paramEnabled = []; oldparamEnabled = []; functionName = '';
1621 delete(findobj(gcf,'Parent',currPanel));
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634 buildplistFigureParam()
1635
1636 end
1637
1638
1639
1640 function KeepResultCallback(hObject,varargin)
1641
1642
1643 switch get(hObject,'Value')
1644 case 0
1645
1646 [meth,clas] = strtok(get_param(gcbh,'Tag'),' ');
1647 infoObj = eval([clas,'.getInfo(''',getappdata(0,'ltpda_currFunctionName'),''')']);
1648 switch infoObj.mcategory
1649 case 'Constructor'
1650 set_param(gcbh,'Backgroundcolor','green')
1651 set_param(gcbh,'MaskHelp','')
1652 case 'Output'
1653 set_param(gcbh,'Backgroundcolor','lightBlue')
1654 set_param(gcbh,'MaskHelp','')
1655 otherwise
1656 set_param(gcbh,'Backgroundcolor','red')
1657 set_param(gcbh,'MaskHelp','')
1658 end
1659 case 1
1660 set_param(gcbh,'Backgroundcolor','magenta')
1661 set_param(gcbh,'MaskHelp','probe')
1662 end
1663 end
1664
1665
1666
1667 function SetNameCallback(hObject,varargin)
1668
1669
1670 setName = get(hObject,'Value');
1671 set(gcbh,'UserData',setName);
1672 set(gcbh,'UserDataPersistent','on');
1673
1674 end
1675
1676
1677
1678 function ApplyButtonCallback(hObject,varargin)
1679
1680
1681
1682
1683
1684 if strcmp(get(hObject,'enable'),'off'), return; end
1685
1686
1687
1688 temp = paramEnabled;
1689 paramcommand = get_param(gcbh,'Description');
1690 eval(paramcommand)
1691 oldparamEnabled = paramEnabled;
1692 paramEnabled = temp;
1693
1694
1695 paramcommand = BuildParamCommand(newparams);
1696 for kk=1:length(selBlocks)
1697 set_param(selBlocks(kk),'Description',paramcommand);
1698 end
1699 AnnotationUpdate(newparams);
1700
1701 set(hObject,'enable','off')
1702
1703
1704
1705 if nargin>2 && varargin{2}, buildplistFigureParam([],[],get(findobj('Tag','paramsPage'),'UserData')); end
1706
1707 end
1708
1709
1710
1711 function UndoButtonCallback(varargin)
1712
1713
1714 temp = paramEnabled;
1715 paramEnabled = oldparamEnabled;
1716 oldparamEnabled = temp;
1717
1718 paramcommand = BuildParamCommand(params);
1719 for kk=1:length(selBlocks)
1720 set_param(selBlocks(kk),'Description',paramcommand);
1721 end
1722 AnnotationUpdate(params);
1723
1724
1725 temp = newparams;
1726 newparams = params;
1727 params = temp;
1728 clear temp;
1729
1730 buildplistFigureParam([],[],get(findobj('Tag','paramsPage'),'UserData'))
1731
1732 end
1733
1734
1735
1736
1737
1738
1739 function LoadInputParamCallback(varargin)
1740
1741
1742
1743
1744 if length(LTPDAinvar)<1
1745
1746 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');
1747
1748 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');
1749 else
1750
1751 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','left','Position',[100 panelDimens(4)-60 80 20],'String','Object input:','Visible','on','Style','text');
1752
1753 children = get_param(gcb,'Blocks');
1754 inputblock = strcat(gcb,'/',children{1});
1755 currAOinput = get_param(inputblock,'Value');
1756 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');
1757
1758
1759 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','left','Position',[100 panelDimens(4)-135 50 20],'String','Object list:','Visible','on','Style','text');
1760
1761 xx = size(LTPDAinvar,1);
1762 listInput = cell(xx,1);
1763 for j=1:xx
1764 switch class(LTPDAinvar{j,1})
1765 case 'ao'
1766 anobject = LTPDAinvar{j,1};
1767 aoname = anobject.name;
1768 aocreated = char(anobject.created);
1769 listInput{j,1} = [num2str(j) , ' . AO .' , aoname , '__' , aocreated];
1770 case 'plist'
1771 paramNumb = nparams(LTPDAinvar{j,1});
1772 objcreated = char(LTPDAinvar{j,1}.created);
1773 listInput{j,1}=[num2str(j),' . PLIST .',num2str(paramNumb),' params','__',objcreated];
1774 case 'specwin'
1775 listInput{j,1}=[num2str(j),' . SPECWIN .','__','no creation time'];
1776 case 'pzmodel'
1777 objcreated = char(LTPDAinvar{j,1}.created);
1778 listInput{j,1}=[num2str(j),' . PZMODEL .','__',objcreated];
1779 otherwise
1780 if isa(LTPDAinvar{j,1},'ltpda_uo')
1781 objclass = class(LTPDAinvar{j,1});
1782 if ~isempty(LTPDAinvar{j,1}), listInput{j,1}=[num2str(j),' . ',objclass]; end
1783 end
1784 end
1785 end
1786 for j=xx:-1:1
1787 if isempty(listInput{j,1})
1788 listInput(j,:)=[];
1789 end
1790 end
1791 inputPopup = uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[170 panelDimens(4)-130 500 20],'String',listInput,'Visible','on','Enable','on','Callback',@InputPopupCallback,'Tag','inputPopupField','Style','popup');
1792
1793
1794 for ii = 1:size(listInput,1)
1795 if str2double(deblank(strtok(listInput{ii}))) == str2double(currAOinput), break; end
1796 end
1797 set(inputPopup,'Value',ii);
1798 end
1799 end
1800
1801
1802
1803 function InputEditCallback(hObject, varargin)
1804
1805
1806
1807 if ~isempty(varargin{1}), newValue = varargin{1};
1808 else newValue = str2double(get(hObject,'String'));
1809 end
1810
1811 newValue = round(newValue);
1812
1813
1814 if newValue>length(LTPDAinvar)
1815 newValue=length(LTPDAinvar);
1816 end
1817
1818 if ~isa(LTPDAinvar{newValue,1},'ltpda_uo')
1819 children = get_param(gcbh,'Blocks');
1820 inputblock = strcat(strcat(get(gcbh,'Path'),'/',get(gcbh,'Name')),'/',children{1});
1821 oldValue = get_param(inputblock,'Value');
1822 set(findobj('Tag','inputEditField'),'String',oldValue);
1823 return
1824 end
1825
1826 set(hObject,'String',num2str(newValue));
1827
1828
1829 inputPopup = findobj('Tag','inputPopupField');
1830 listInput = get(inputPopup,'String');
1831 for ii = 1:size(listInput,1)
1832 if str2double(deblank(strtok(listInput{ii}))) == newValue, break; end
1833 end
1834 set(inputPopup,'Value',ii);
1835
1836
1837 objName = LTPDAinvar{newValue,1}.name;
1838 if numel(objName)>3 && strcmpi(objName,'none'), objName = class(LTPDAinvar{newValue,1}); end
1839 if numel(objName)>20, objName = ['...',LTPDAinvar{newValue,1}.name(end-20:end)]; end
1840 objName = [num2str(newValue),': ',objName];
1841
1842 for i=1:length(selBlocks)
1843
1844
1845
1846 children{i}=get_param(selBlocks(i),'Blocks');
1847 inputblock=strcat(strcat(get(selBlocks(i),'Path'),'/',get(selBlocks(i),'Name')),'/',children{i}{1});
1848 set_param(inputblock,'Value',num2str(newValue));
1849
1850 set_param(selBlocks(i),'AttributesFormatString',objName);
1851 end
1852 end
1853
1854
1855
1856 function InputPopupCallback(hObject, varargin)
1857
1858
1859
1860 val = get(hObject, 'Value');
1861 objLines = get(hObject, 'String');
1862 objnumb = str2double(deblank(strtok(objLines{val})));
1863
1864 InputEditCallback(findobj('Tag','inputEditField'),objnumb);
1865
1866 end
1867
1868
1869
1870 function AddButtonCallback(varargin)
1871
1872
1873 filenames = uipickfiles('REFilter','.txt');
1874 if ~isempty(filenames) && ~isnumeric(filenames(1,1))
1875 [x,y]=size(filenames);
1876 for j=1:y
1877 anobject={ao(filenames{j})};
1878 LTPDAinvar=[LTPDAinvar;anobject];
1879 end
1880 disp(sprintf(' + %g AOs added to the global variable LTPDAinvar', y))
1881 buildplistFigureParam([],[],get(findobj('Tag','paramsPage'),'UserData'));
1882 end
1883 end
1884
1885
1886
1887 function LoadMuxParamCallback(varargin)
1888
1889
1890
1891
1892
1893 if strcmp(get(gcbh,'Tag'),'mux'),
1894
1895 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','left','Position',[100 panelDimens(4)-60 100 20],'String','Number of inputs:','Visible','on','Style','text');
1896
1897 uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[210 panelDimens(4)-57 50 20],'String',get(gcbh,'Inputs'),'Visible','on','Enable','on','Callback',@MuxEditCallback,'Style','edit');
1898 elseif strcmp(get(gcbh,'Tag'),'demux'),
1899
1900 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','left','Position',[100 panelDimens(4)-60 100 20],'String','Number of outputs:','Visible','on','Style','text');
1901
1902 uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[210 panelDimens(4)-57 50 20],'String',get(gcbh,'Outputs'),'Visible','on','Enable','on','Callback',@MuxEditCallback,'Style','edit');
1903 end
1904 end
1905
1906
1907
1908 function MuxEditCallback(hObject, varargin)
1909
1910
1911
1912 newValue = str2double(get(hObject,'String'));
1913
1914 newValue = round(newValue);
1915 set(hObject,'String',num2str(newValue));
1916 for i=1:length(selBlocks)
1917 newDimens=get(selBlocks(i),'Position');
1918 newDimens(4)=newDimens(2)+25*(newValue+1);
1919 if strcmp(get(gcbh,'Tag'),'mux'),
1920 set(selBlocks(i),'Inputs',num2str(newValue));
1921 elseif strcmp(get(gcbh,'Tag'),'demux'),
1922 set(selBlocks(i),'Outputs',num2str(newValue));
1923 end
1924 set(selBlocks(i),'Position',newDimens);
1925 end
1926 end
1927
1928
1929
1930 function LoadFromBlockCallback(varargin)
1931
1932
1933
1934 uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-200)/2 panelDimens(4)-100 200 30],'String','Find origin','FontSize',guiFontSize+1,'Visible','on','Enable','on','Callback',@FindOriginCallback,'Style','pushbutton');
1935 end
1936
1937
1938
1939 function FindOriginCallback(varargin)
1940
1941
1942
1943 varName = get(gcbh,'GotoTag');
1944 origin = utils.prog.find_in_models(bdroot,'LookUnderMasks','all','BlockType','Goto','GotoTag',varName);
1945 if numel(origin)>1
1946
1947 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-400)/2 panelDimens(4)-160 400 30],'String','Error: there are multiple sources','Visible','on','Style','text');
1948 elseif numel(origin)==1
1949
1950 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-400)/2 panelDimens(4)-160 400 30],'String',origin{1},'Visible','on','Style','text');
1951 else
1952
1953 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-400)/2 panelDimens(4)-160 400 30],'String','Error: no source found','Visible','on','Style','text');
1954 end
1955
1956
1957
1958 end
1959
1960
1961
1962 function arithmetic(varargin)
1963
1964
1965 delete(findobj(gcf,'Parent',currPanel))
1966 lineSpacing = getappdata(0,'ltpda_gui_LineSpacing');
1967 paramcommand = get_param(gcbh,'Description');
1968 noParamsReq=0;
1969 if isempty(paramcommand)
1970 paramcommand = RetrievePlist('arithmetic');
1971 selBlocks = utils.prog.gcbsh;
1972 for kk=1:length(selBlocks)
1973 set_param(selBlocks(kk),'Description',paramcommand);
1974 end
1975 end
1976 eval(paramcommand)
1977
1978 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','Position',[20 panelDimens(4)-55 100 20],'String','List of input:','HorizontalAlignment','left','FontSize',guiFontSize+1,'Visible','on','Style','text');
1979 y = nparams(newparams);
1980 for i=1:y
1981 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','Position',[7 panelDimens(4)-lineSpacing*(i+2)-4 8 20],'String','>','FontSize',guiFontSize+1,'FontWeight','Bold','Visible','on','Style','text');
1982 uicontrol('Parent',currPanel,'Units','pixels','Position',[20 panelDimens(4)-lineSpacing*(i+2) 100 20],'String',lower(newparams.params(i).key),'FontSize',guiFontSize+1,'Visible','on','Enable','on','UserData',i,'Callback',@editNameCallback,'Style','edit');
1983
1984 if i>1
1985 uicontrol('Parent',currPanel,'Units','pixels','Position',[125 panelDimens(4)-lineSpacing*(i+2) 20 20],'String','-','Visible','on','Enable','on','Callback', @RemParamCallback,'UserData',i,'Style','pushbutton');
1986 end
1987 end
1988
1989 uicontrol('Parent',currPanel,'Units','pixels','Position',[20 panelDimens(4)-40-lineSpacing*(y+2) 20 20],'String','+','Visible','on','Enable','on','Callback', @AddParamCallback,'UserData','input','Style','pushbutton');
1990
1991
1992 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','Position',[20 panelDimens(4)-47-lineSpacing*(y+3) 140 20],'String','Output name:','HorizontalAlignment','left','FontSize',guiFontSize+1,'Visible','on','Style','text');
1993 outName = get(gcbh,'UserData');
1994 if isempty(outName), outName = get(gcbh,'Name'); end
1995 uicontrol('Parent',currPanel,'Units','pixels','Position',[20 panelDimens(4)-40-lineSpacing*(y+4) 100 20],'String',outName,'FontSize',guiFontSize+1,'Visible','on','Enable','on','UserData',i,'Callback','set(gcbh,''UserData'',get(gco,''String''));set(gcbh,''UserDataPersistent'',''on'')','Style','edit');
1996
1997
1998 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','Position',[180 panelDimens(4)-50 400 20],'String','Type in the equation, using as an example:','HorizontalAlignment','left','FontSize',guiFontSize+1,'Visible','on','Style','text');
1999
2000 uicontrol('Parent',currPanel,'TooltipString','This in an example of how to type in an equation','BackgroundColor',[0.97 0.97 0.97],'Units','pixels','Position',[180 panelDimens(4)-72 500 20],'String','(alpha+beta)/2+alpha^2','FontSize',guiFontSize+1,'Visible','on','Enable','on','Callback','set(gco,''String'',''(alpha+beta)/2+alpha^2'')','Style','edit');
2001
2002
2003 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','Position',[180 panelDimens(4)-100 400 20],'String','Output =','HorizontalAlignment','left','FontSize',guiFontSize+1,'Visible','on','Style','text');
2004
2005 eqString = get_param(gcbh,'MaskDescription');
2006 if numel(eqString)>16 && strcmp(eqString(1:17),'Arithmetic block:'), eqString = ''; end
2007 uicontrol('Parent',currPanel,'BackgroundColor',[0.9 0.9 0.9],'Units','pixels','Position',[180 panelDimens(4)-300 500 200],'String',eqString,'Max',2,'FontSize',guiFontSize+1,'Visible','on','Enable','on','Callback',@eqEdit,'Tag','equationField','Style','edit');
2008
2009 end
2010
2011
2012
2013 function eqEdit(hObject,varargin)
2014
2015 eq = get(hObject,'String');
2016 if ~isempty(eq)
2017 if numel(eq)>40, eq(1:end-25) = []; eq = ['...',eq]; end
2018 for nn=1:length(selBlocks)
2019 set_param(selBlocks(nn),'MaskDescription',get(hObject,'String'));
2020 set_param(selBlocks(nn),'AttributesFormatString',eq);
2021 end
2022 else
2023 eqString = get_param(gcbh,'MaskDescription');
2024 if numel(eqString)>16 && strcmp(eqString(1:17),'Arithmetic block:'), eqString = ''; end
2025 set(hObject,'String',eqString);
2026 end
2027
2028 end
2029
2030
2031
2032
2033
2034 function ErrorFuncNotSupported(varargin)
2035
2036
2037
2038 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-300)/2 panelDimens(4)-100-100 300 30],'String','Error: unable to retrieve the parameters required by this function. Maybe it''s not supported yet?','Visible','on','Style','text');
2039 end
2040
2041
2042
2043 function ErrorSelectionInconsistent(varargin)
2044
2045 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-300)/2 panelDimens(4)-100-100 300 30],'String','Error: impossible to set unique parameters for the selected blocks','Visible','on','Style','text');
2046 end
2047
2048
2049
2050
2051
2052 end