Home > m > gui > gltpda > pan2param.m

pan2param

PURPOSE ^

This is the GUI m-file able to read the list of parameters to be set for

SYNOPSIS ^

function pan2param(varargin)

DESCRIPTION ^

 This is the GUI m-file able to read the list of parameters to be set for
 the function/block currently selected and to build the window with the
 parameters panel accordingly.

  $Id: pan2param.m,v 1.45 2008/08/25 13:55:07 nicola Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function pan2param(varargin)
0002 % This is the GUI m-file able to read the list of parameters to be set for
0003 % the function/block currently selected and to build the window with the
0004 % parameters panel accordingly.
0005 %
0006 %  $Id: pan2param.m,v 1.45 2008/08/25 13:55:07 nicola Exp $
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   % params = []; paramEnabled = []; functionName = []; paramSets = [];
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      % deletes only the dynamical part of the panel:
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      % deletes all, to redraw the entire panel:
0043        delete(findobj(gcf,'Parent',currPanel));
0044     end
0045     objName = [];
0046     close(findobj('Tag','expandedEditField'))
0047 if notredrawn % Executes the STATIC part too only if it's not just an update of the panel
0048    
0049 % =========================================================================
0050 % =========================================================================
0051 % ========================== Build STATIC panel ===========================
0052 % =========================================================================
0053 % =========================================================================
0054 
0055 % -------------------------------------------------------------------------
0056 % Retrieve the parameters:
0057 % -------------------------------------------------------------------------
0058   if isempty(params) && isempty(newparams) % the user has just selected another block
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     % Text:
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     % Edit field:
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 % Fixed buttons:
0101 % -------------------------------------------------------------------------
0102 % Help Button
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 % Reset Parameters Button
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 % Keep local result
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 % 'Set name' checkbox:
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 % Number of data inputs:
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 % The function has different sets of parameters:
0126   if exist('paramSets','var') && ~isempty(paramSets)
0127       sets = find(paramSets,'sets');
0128       currSet = find(paramSets,'currSet');
0129     % Sets text:
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     % Sets popup menu:
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 % Button to add user-defined params:
0138 % -------------------------------------------------------------------------
0139   paramTypes      = {'double/char','specwin','pole','zero','pzmodel','-->'};
0140   for kk=1:y, paramTypes(strmatch(class(newparams.params(kk).val),paramTypes,'exact'))=[]; end
0141 % ParamType popup
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 % Add params button
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 % Buttons to apply or undo:
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 % Apply button
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 % Undo button
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 % The part above was executed only if it's not an update of the panel
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 % ========================= Build DYNAMIC panel ===========================
0184 % =========================================================================
0185 % =========================================================================
0186 
0187 % -------------------------------------------------------------------------
0188 % Cycle to verify whether gaps (= extra lines for complex params, such as
0189 % pzmodels) are necessary or not:
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     % Check if it's necessary to draw multiple parameters pages:
0210       if (paramThisPage+totalGaps)*lineSpacing > paramPagePosition(4)-20   % panelDimens(4)-40-guiFontSize*16/10
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 % The vector 'paramPages' contains how many params are contained into every page.
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   % Checkbox to enable input setting:
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   % Remove Param Button:
0249     try %#ok<ALIGN>
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           % Key text:
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           % Key value:
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           % Val text:
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           % Val value:
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           % Val button to expand the edit field:
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           % Enable parameters from Simulink:
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           % Key text:
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           % Key value:
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           % Val text:
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           % Val value:
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           % Val button to expand the edit field:
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           % Browse button:
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             % Enable parameters from Simulink:
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           % Window text:
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           % Window type popup:
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           % Length text:
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           % Length value:
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              % PSL text if Kaiser:
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              % PSL value if Kaiser:
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           % Simulink checkbox:
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           % Simulink checkbox:
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           % Load button:
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           % Gain text:
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           % Gain value:
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           % Poles text:
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           % Zeros text:
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           % Poles value:
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           % Zeros value:
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 'pole'
0409       % ==========================================================================
0410           % Simulink checkbox:
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             for kk=1:numel(currPoles)
0415                 poleFreqs(kk,1) = currPoles(kk).f;
0416                 poleQs(kk,1)    = currPoles(kk).q;
0417                 if ~isnan(poleQs(kk,1))
0418                     poleFQs{kk,1}=strcat(num2str(poleFreqs(kk,1)),',',num2str(poleQs(kk,1)));
0419                 else
0420                     poleFQs{kk,1}=num2str(poleFreqs(kk,1));
0421                 end
0422             end
0423             poleFQs=char(poleFQs);
0424           % Poles text:
0425             objName{ii,2} =   uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[50 panelDimens(4)-(4+lineSpacing*(currParam+1+currGap)) 120 20],'String','POLES','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Visible','on','Enable','off','Style','text');
0426             if numel(currPoles)>1
0427                 currGap=currGap+1;
0428             end
0429           % Poles value:
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 'zero'
0434       % ==========================================================================
0435           % Simulink checkbox:
0436             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');
0437 
0438             currZeros = newparams.params(ii).val;
0439             for kk=1:numel(currZeros)
0440                 zeroFreqs(kk,1) = get(currZeros(kk),'f');
0441                 zeroQs(kk,1)    = get(currZeros(kk),'q');
0442                 if ~isnan(zeroQs(kk,1))
0443                     zeroFQs{kk,1}=strcat(num2str(zeroFreqs(kk,1)),',',num2str(zeroQs(kk,1)));
0444                 else
0445                     zeroFQs{kk,1}=num2str(zeroFreqs(kk,1));
0446                 end
0447             end
0448             zeroFQs=char(zeroFQs);
0449           % Zeros text:
0450             objName{ii,2} =   uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[50 panelDimens(4)-(4+lineSpacing*(currParam+1+currGap)) 120 20],'String','ZEROS','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Visible','on','Enable','off','Style','text');
0451             if numel(currZeros)>1
0452                 currGap=currGap+1;
0453             end
0454           % Zeros value:
0455             objName{ii,3} =  uicontrol('Parent',currPanel,'Units','pixels','Position',[250 panelDimens(4)-(2+lineSpacing*(currParam+1+currGap))-(lineSpacing-30)*(numel(currZeros)>1) 100 (20+(numel(currZeros)>1)*lineSpacing)*guiFontSize/10],'String',zeroFQs,'Max',2,'FontSize',guiFontSize,'TooltipString','Insert ''freq'' or ''freq,q''','Visible','on','Enable','on','UserData',ii,'Callback',@zeroEdit,'Style','edit'); 
0456       
0457       % ==========================================================================
0458         case 'cell'
0459       % ==========================================================================
0460             if isa(paramvals{ii}{1},'char') && strcmp(paramvals{ii}{1},'-->')
0461               % Key value:
0462                 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');
0463               % Text: from Simulink environment:
0464                 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');
0465                 fromSimulink = 1;
0466             else
0467               % Key text:
0468                 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');
0469               % Key value:
0470                 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');
0471                 if ~noParamsReq && ~addedPar
0472                     set(objName{ii,2},'Visible','off');
0473                     set(objName{ii,3},'Style','text','BackgroundColor',backColor,'Position',[50 panelDimens(4)-5-lineSpacing*(currParam+1+currGap) 120 20]);
0474                 end
0475 
0476               % Val text:
0477                 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');
0478               % Val value:
0479                 data = utils.prog.cell2str(paramvals{ii});
0480                 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');
0481                 fromSimulink = 0;
0482             end
0483                 
0484           % Simulink checkbox:
0485             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');
0486             
0487 
0488       % ==========================================================================
0489         otherwise % Other types of param?
0490       % ==========================================================================
0491           % Key value:
0492             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');
0493           % Text: input not supported. Please construct by proper block.
0494             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');
0495             fromSimulink = 0;
0496             
0497           % Simulink checkbox:
0498             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');
0499             
0500   % ==============================================================================
0501     end % of SWITCH the param type
0502   % Cycle to activate enabled params:
0503     if paramEnabled(ii) || noParamsReq==1
0504         [xx,yy]       = size(objName);
0505         jj=2;
0506         while jj<=yy && ~isempty(objName{ii,jj})
0507             try set(objName{ii,jj},'Enable','on'); set(objName{ii,jj},'ForegroundColor',[0 0 0]); catch end
0508             jj=jj+1;
0509         end
0510     end
0511     
0512 end % of cycle among params
0513 
0514     end % of buildplistFigureParam function
0515     %----------------------------------------------------------------------
0516 
0517 %% ========================= Selection Check ==============================
0518 % =========================================================================
0519     %----------------------------------------------------------------------
0520     function ContinuousParamCheck(varargin)
0521   % This is the function to execute a continuous check on the status
0522   % of the current selection (system and block).
0523   
0524          currSelection = utils.prog.gcbsh;
0525        % Clear the figure if nothing's selected
0526          if isempty(selBlocks) && isempty(currSelection), return; end
0527          if (~isempty(selBlocks) && isempty(currSelection)) || strcmp(get_param(gcs,'BlockDiagramType'),'library')
0528              delete(findobj(gcf,'Parent',currPanel))
0529              selBlocks = [];
0530              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');   
0531              return
0532          end
0533 
0534          if ~isempty(bdroot) && ~isempty(find_system(bdroot,'FindAll','on','Type','Annotation','Tag','ltpda model'))
0535        % it's selected a ltpda simulink analysis diagram.
0536 
0537          if ((numel(selBlocks)==1 && selBlocks~=gcbh) || length(selBlocks)~=length(currSelection)) && ~isempty(currSelection)
0538                 for i=1:length(currSelection)
0539                     set_param(currSelection(i),'LinkStatus','inactive');
0540                     currentTags{i}=get_param(currSelection(i),'Tag');
0541                 end
0542                 
0543                 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0544                 if numel(currSelection)>1 % then the user has selected multiple blocks
0545                 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0546                   % Check for consistency: all methods? same class?
0547                     for i=1:numel(currentTags)
0548                         if ~strcmp(currentTags{i},currentTags{1})
0549                             ErrorSelectionInconsistent();
0550                             selBlocks = currSelection;
0551                             return;
0552                         end
0553                     end
0554                   % Check for consistency: same method?:
0555                     for i=1:numel(currSelection)
0556                        childpath = find_system(currSelection(i),'LookUnderMasks','all','BlockType','M-S-Function');
0557                        functionname{i}=get_param(childpath,'Tag');
0558                        if ~strcmp(functionname{i},functionname{1}) % different functions, inconsistent selection
0559                           ErrorSelectionInconsistent();
0560                           selBlocks = currSelection;
0561                           return;
0562                        end
0563                     end
0564                 end
0565                 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0566 
0567              delete(findobj(gcf,'Parent',currPanel))
0568              selBlocks = currSelection;
0569              params = []; newparams = []; paramEnabled = []; oldparamEnabled = []; functionName = ''; paramSets = [];
0570              if getappdata(0,'hidenames') && strcmp(get(gcbh,'ShowName'),'on'), for i=1:length(selBlocks), set_param(selBlocks(i),'ShowName','off'); end;
0571              elseif ~getappdata(0,'hidenames') && strcmp(get(gcbh,'ShowName'),'off'), for i=1:length(selBlocks), set_param(selBlocks(i),'ShowName','on'); end;
0572              end
0573              
0574            % Get the new functionName:
0575              childpath    = find_system(gcbh,'LookUnderMasks','all','BlockType','M-S-Function');
0576              functionName = get_param(childpath,'Tag');
0577              if isempty(functionName)
0578                 description = get_param(gcbh,'Description');
0579                 funcname = findstr('functionName=',description);
0580                 if funcname
0581                    i = funcname+14;
0582                    while ~strcmp(description(i),';'), i=i+1; end
0583                    functionName = description(funcname+14:i-2);
0584                 end
0585              end
0586                 
0587              switch strtok(get(gcbh,'Tag'))
0588                % =========================================================
0589                  case {'function','freepl','method'}
0590                      buildplistFigureParam()
0591                % =========================================================
0592                  case 'arithmetic'
0593                      arithmetic();
0594                % =========================================================
0595                  case 'input'
0596                      LoadInputParamCallback();
0597                % =========================================================
0598                  case {'mux','demux'}
0599                      LoadMuxParamCallback();
0600                % =========================================================
0601                  case 'from'
0602                      LoadFromBlockCallback();
0603                % =========================================================
0604              end % of switch
0605 
0606         end % end of blocks selection
0607         end   % end of system selection check
0608         
0609     end
0610     %----------------------------------------------------------------------
0611 
0612 %% ======================== Double functions ==============================
0613 %  ========================================================================
0614     %----------------------------------------------------------------------
0615     function editNameCallback(hObject, varargin)   
0616          currParamIndex = get(hObject,'UserData');
0617          newName  = get(hObject,'String');
0618          oldName  = newparams.params(currParamIndex).key;
0619          addedPar = 0;
0620          try if strcmpi(oldName(1:7),'addPar_'), addedPar = 1; oldName(1:7)=[]; end; catch end
0621          
0622          if strcmp(newparams.params(currParamIndex).val,'-->')
0623              block2change = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','Name',lower(oldName));
0624              while ~isempty(find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','Name',lower(newName))),  newName = [newName,'x']; end
0625              set_param(block2change{1},'Name',lower(newName))
0626          end
0627 
0628          if addedPar, newName = ['addPar_',newName]; end
0629          setKey(newparams.params(currParamIndex),newName);
0630        % To change the drawing command:
0631          if strcmp(newparams.params(currParamIndex).val,'-->'), UpdateInports(lower(newName),2); end
0632          
0633          set(findobj('Tag','apply'),'Enable','on');
0634          set(findobj('Tag','undo'),'Enable','on');
0635          
0636     end
0637     %----------------------------------------------------------------------
0638     %----------------------------------------------------------------------
0639     function editValueCallback(hObject, varargin) 
0640         
0641         expandedEdit = 0;
0642         if numel(get(hObject,'UserData'))>1
0643             hObject = get(hObject,'UserData');
0644             orighObject = hObject(2);
0645             hObject = hObject(1);
0646             expandedEdit = 1;
0647         else
0648             orighObject = hObject;
0649         end
0650         currParamIndex = get(hObject,'UserData');
0651         newValue = get(hObject,'String');
0652          
0653         if isempty(newValue), set(orighObject,'String',num2str(newparams.params(currParamIndex).val)); return; end
0654         if strcmp(newValue(1),''''),
0655             paramType = 'char';
0656             newValue(1) = []; newValue(end) = [];
0657             for j = numel(newValue)-1:-1:2
0658                 if strcmp(newValue(j),'''') && (~strcmp(newValue(j-1),'''') && ~strcmp(newValue(j+1),''''))
0659                     newValue = [newValue(1:j),'''',newValue(j+1:end)];
0660                 end
0661             end
0662         elseif ~strcmp(newValue(1),'{'),
0663             paramType = 'double';
0664         else
0665             paramType = 'double';
0666         end
0667         
0668         switch paramType
0669             case 'double'
0670                 try
0671                     newValue = evalin('base',newValue);
0672                     if isnumeric(newValue)
0673                         set(orighObject,'String',mat2str(newValue))
0674                     else
0675                         newparams = pset(newparams,newparams.params(currParamIndex).key,newValue);
0676                         paramcommand = BuildParamCommand(newparams);
0677                         for kk=1:length(selBlocks)
0678                             set_param(selBlocks(kk),'Description',paramcommand);
0679                         end
0680                         AnnotationUpdate(newparams);
0681                         buildplistFigureParam([],[],get(findobj('Tag','paramsPage'),'UserData'))
0682                         return
0683                     end
0684                 catch
0685                     oldValue = newparams.params(currParamIndex).val;
0686                     if ~isa(oldValue,'char'), mat2str(oldValue); end
0687                     set(orighObject,'String',oldValue)
0688                     return
0689                 end
0690         end
0691         
0692         if expandedEdit, paramEnabled(currParamIndex) = 1; end
0693         newparams = pset(newparams,newparams.params(currParamIndex).key,newValue);
0694         
0695         set(findobj('Tag','apply'),'Enable','on');
0696         set(findobj('Tag','undo'),'Enable','on');
0697         
0698     end
0699     %----------------------------------------------------------------------
0700     %----------------------------------------------------------------------
0701     function browseCallback(hObject, varargin)
0702         
0703         [meth,clas] = strtok(get_param(gcbh,'Tag'),' ');
0704         categ = 'none';
0705         if strcmp(meth,'method')
0706            clas = strtrim(clas);
0707            infoObj = eval([clas,'.getInfo(''',functionName,''')']);
0708            categ = infoObj.mcategory;
0709         end
0710 
0711         if strcmp(categ,'Output')
0712             [fileName,filePath] = uiputfile('*.*','Choose destination file');
0713         else
0714             [fileName,filePath] = uigetfile('*.*','Choose source file');
0715         end
0716         
0717         if fileName==0
0718             return
0719         else
0720             [file , ext] = strtok(fileName,'.');
0721             if strcmp(ext,'.*'), fileName(end)=[]; fileName=[fileName,'dat']; end
0722             fileName = [filePath,fileName];
0723         end
0724         editFieldHandle = get(hObject,'UserData');
0725         set(editFieldHandle,'String',fileName);
0726 
0727         newValue = fileName;
0728         newparams = pset(newparams,'FILENAME',newValue);
0729         
0730         set(findobj('Tag','apply'),'Enable','on');
0731         set(findobj('Tag','undo'),'Enable','on');
0732         
0733     end
0734     %----------------------------------------------------------------------
0735 %% ======================= Specwin functions ==============================
0736 %  ========================================================================
0737     %----------------------------------------------------------------------
0738     function WindListCallback(hObject, varargin)   
0739         currParamID   = get(hObject,'UserData');
0740         currWindValue = get(hObject,'Value');
0741         listWindows   = ['Kaiser',specwin.getTypes];
0742         currWindow    = listWindows{currWindValue};
0743         oldWindObj    = newparams.params(currParamID).val;        
0744         oldWindow     = oldWindObj.type;
0745         if strcmp(currWindow,oldWindow), return;
0746         else
0747             currWindLength = str2double(get(objName{currParamID,5},'String'));
0748             if strcmp(currWindow,'Kaiser'), windobj = specwin(currWindow,currWindLength,round(oldWindObj.psll));
0749             else windobj = specwin(currWindow,currWindLength);
0750             end
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         if strcmp(currWindow,'Kaiser') || strcmp(oldWindow,'Kaiser'), buildplistFigureParam([],[],get(findobj('Tag','paramsPage'),'UserData')); end
0759         
0760     end
0761     %----------------------------------------------------------------------
0762     %----------------------------------------------------------------------
0763     function WindlengthCallback(hObject,varargin)   
0764     % Callback function: run when the user change the value in the Length
0765     % editable field for a specwin object
0766     
0767          currParamID    = get(hObject,'UserData');
0768          selectedWind   = newparams.params(currParamID).val.type;
0769          currWindLength = str2double(get(hObject,'String'));
0770          
0771         
0772          if strcmp(selectedWind,'Kaiser')
0773              windobj = specwin(selectedWind,currWindLength, newparams.params(currParamID).val.psll);
0774          else
0775              windobj = specwin(selectedWind,currWindLength);
0776          end
0777          
0778          newparams=pset(newparams,newparams.params(currParamID).key,windobj);
0779 
0780          set(findobj('Tag','apply'),'Enable','on');
0781          set(findobj('Tag','undo'),'Enable','on');
0782         
0783     end
0784     %----------------------------------------------------------------------
0785     %----------------------------------------------------------------------
0786     function WindPSLCallback(hObject,varargin)   
0787     % Callback function: run when the user change the value in the PSL
0788     % editable field for a specwin object
0789 
0790          currParamID    = get(hObject,'UserData');
0791          selectedWind   = newparams.params(currParamID).val.type;
0792          currWindLength = numel(newparams.params(currParamID).val.win);
0793          currPSL        = round(str2double(get(hObject,'String')));
0794          set(hObject,'String',num2str(currPSL))
0795          
0796          windobj    = specwin(selectedWind,currWindLength, currPSL);
0797          newparams  = pset(newparams,newparams.params(currParamID).key,windobj);
0798 
0799          set(findobj('Tag','apply'),'Enable','on');
0800          set(findobj('Tag','undo'),'Enable','on');
0801         
0802     end
0803     %----------------------------------------------------------------------
0804 
0805 %% ======================= Pzmodel functions ==============================
0806 %  ========================================================================
0807     %----------------------------------------------------------------------
0808     function pzmodelLoad(hObject, varargin)
0809          currParamIndex = get(hObject,'UserData');
0810          
0811          try [FileName,PathName] = uigetfile('*.xml','Select the .XML pzmodel file');
0812                      FileAddress = strcat(PathName,FileName);
0813                      pzObj = pzmodel(FileAddress);
0814                      if isempty(pzObj), return; end
0815                      newparams = pset(newparams,newparams.params(currParamIndex).key,pzObj);
0816          catch
0817          end
0818 
0819          set(findobj('Tag','apply'),'Enable','on');
0820          set(findobj('Tag','undo'),'Enable','on');
0821 %          buildplistFigureParam([],[],get(findobj('Tag','paramsPage'),'UserData'))
0822 
0823     end
0824     %----------------------------------------------------------------------
0825     %----------------------------------------------------------------------
0826     function pzmodelGainEdit(hObject, varargin)
0827          currParamIndex = get(hObject,'UserData');
0828          pzGain         = str2double(get(hObject,'String'));
0829          
0830          pzObj        = newparams.params(currParamIndex);
0831          pzKey        = pzObj.key;
0832          pzObj        = pzObj.val;
0833          pzObj      = pzmodel(pzGain,pzObj.poles,pzObj.zeros);
0834          newparams    = pset(newparams,pzKey,pzObj);
0835 
0836          set(findobj('Tag','apply'),'Enable','on');
0837          set(findobj('Tag','undo'),'Enable','on');
0838 
0839     end
0840     %----------------------------------------------------------------------
0841     %----------------------------------------------------------------------
0842     function pzmodelPZEdit(hObject,varargin)
0843          currParamIndex = get(hObject,'UserData');
0844          poleORzero     = varargin{2};
0845          pzes           = get(hObject,'String');
0846          pzes          = readInput(pzes,2);
0847          [xx,yy]  = size(pzes);
0848          pzList = pz();
0849          for kk = 1:xx
0850              if (yy>1 && pzes(kk,2)==0) || yy==1 ,  pzList(kk) = pz(pzes(kk,1));
0851              else pzList(kk) = pz(pzes(kk,1),pzes(kk,2));
0852              end
0853          end
0854          
0855          pzObj     = newparams.params(currParamIndex);
0856          pzKey     = pzObj.key;
0857          pzObj     = pzObj.val;
0858          if poleORzero, pzObj     = pzmodel(pzObj.gain,pzList,pzObj.zeros);
0859          else pzObj     = pzmodel(pzObj.gain,pzObj.poles,pzList);
0860          end
0861          newparams    = pset(newparams,pzKey,pzObj);
0862          
0863          set(findobj('Tag','apply'),'Enable','on');
0864          set(findobj('Tag','undo'),'Enable','on');
0865          
0866         if numel(pzObj.poles)>1 || numel(pzObj.zeros)>1, buildplistFigureParam([],[],get(findobj('Tag','paramsPage'),'UserData')); end
0867 
0868     end
0869     %----------------------------------------------------------------------
0870 
0871 %% ========================== Pole functions ==============================
0872 %  ========================================================================
0873     %----------------------------------------------------------------------
0874     function poleEdit(hObject, varargin)
0875         currParamIndex = get(hObject,'UserData');
0876         poles          = get(hObject,'String');
0877         poles          = readInput(poles,2);
0878         [xx,yy]  = size(poles);
0879         poleList = pole();
0880         for kk=1:xx
0881             if (yy>1 && poles(kk,2)==0) || yy==1 , poleList(kk) = pole(poles(kk,1));
0882             else poleList(kk) = pole(poles(kk,1),poles(kk,2));
0883             end
0884         end
0885         newparams = pset(newparams,newparams.params(currParamIndex).key,poleList);
0886 
0887         set(findobj('Tag','apply'),'Enable','on');
0888         set(findobj('Tag','undo'),'Enable','on');
0889 
0890     end
0891     %----------------------------------------------------------------------
0892     
0893 %% ========================== Zero functions ==============================
0894 %  ========================================================================
0895     %----------------------------------------------------------------------
0896     function zeroEdit(hObject, varargin)
0897         currParamIndex = get(hObject,'UserData');
0898         zeros          = get(hObject,'String');
0899         zeros          = readInput(zeros,2);
0900         [xx,yy]  = size(zeros);
0901         zeroList = zero();
0902         for kk=1:xx
0903             if (yy>1 && zeros(kk,2)==0) || yy==1 , zeroList(kk)=zero(zeros(kk,1));
0904             else zeroList(kk)=zero(zeros(kk,1),zeros(kk,2));
0905             end
0906         end
0907         newparams = pset(newparams,newparams.params(currParamIndex).key,zeroList);
0908 
0909         set(findobj('Tag','apply'),'Enable','on');
0910         set(findobj('Tag','undo'),'Enable','on');
0911 
0912     end
0913     %----------------------------------------------------------------------
0914     
0915 %% ====================== Fixed Buttons Callbacks =========================
0916 % =========================================================================
0917     %----------------------------------------------------------------------
0918     function AddParamCallback(hObject,varargin)
0919         
0920         hparamType = get(hObject,'UserData');
0921         if isa(hparamType,'char') && strcmp(hparamType,'input')
0922             key = 'input';
0923             while ~isempty(find(newparams,key)), key =[key,'x']; end
0924             newparams = append(newparams, param(key,'-->'));
0925             UpdateInports(key,1);
0926             paramcommand = BuildParamCommand(newparams);
0927             for kk=1:length(selBlocks)
0928                 set_param(selBlocks(kk),'Description',paramcommand);
0929             end
0930             arithmetic();
0931 
0932         else
0933             paramTypes = get(hparamType,'String');
0934             paramType = paramTypes{get(hparamType,'Value')};
0935 
0936             switch paramType
0937                 case {'double','double/char'}
0938                     key = 'addPar_name';
0939                     while ~isempty(find(newparams,key))
0940                         key =[key,'x'];
0941                     end
0942                     newparams = append(newparams, param(key,1));
0943                 case 'specwin'
0944                     newParam = param('addPar_Win',specwin('Kaiser',1000,200));
0945                     newparams = append(newparams, newParam);
0946                 case 'pzmodel'
0947                     pzObj = pzmodel(1,[pole(10,2),pole(100)],zero(1));
0948                     newParam = param('addPar_pzmodel',pzObj);
0949                     newparams = append(newparams, newParam);
0950                 case '-->'
0951                     key = 'addPar_name';
0952                     while find(newparams,key)
0953                         key = [key,'x'];
0954                     end
0955                     newparams = append(newparams, param(key,'-->'));
0956                     UpdateInports(key,1)
0957                 case 'pole'
0958                     newparams = append(newparams, param('addPar_poles',pole(1)));
0959                 case 'zero'
0960                     newparams = append(newparams, param('addPar_zeros',zero(1)));
0961 
0962             end
0963 
0964             if nparams(newparams)==1, paramEnabled=1;
0965             else paramEnabled=[paramEnabled,1];
0966             end
0967             
0968             set(findobj('Tag','apply'),'Enable','on');
0969             set(findobj('Tag','undo'),'Enable','on');
0970 
0971             buildplistFigureParam([],[],get(findobj('Tag','paramsPage'),'UserData'))
0972         end
0973     end
0974     %----------------------------------------------------------------------
0975 
0976     %----------------------------------------------------------------------
0977     function RemParamCallback(hObject, varargin)
0978        
0979          currParamIndex = get(hObject,'UserData');
0980          
0981          paramKey = newparams.params(currParamIndex).key;
0982          paramVal = newparams.params(currParamIndex).val;
0983          newparams = remove(newparams,paramKey);
0984          if ~strcmp(get_param(gcbh,'Tag'),'arithmetic'), paramEnabled(currParamIndex)=[]; end
0985          
0986          if strcmp(paramVal,'-->') % it's a data from Simulink: delete the relative inport block.
0987              UpdateInports(paramKey,-1);
0988          end
0989          delete(hObject)
0990 
0991          set(findobj('Tag','apply'),'Enable','on');
0992          set(findobj('Tag','undo'),'Enable','on');
0993 
0994          if strcmp(get_param(gcbh,'Tag'),'arithmetic'), arithmetic();
0995          else buildplistFigureParam([],[],get(findobj('Tag','paramsPage'),'UserData'))
0996          end
0997     end
0998     %----------------------------------------------------------------------
0999 
1000     %----------------------------------------------------------------------
1001     function fromSimulinkCallback(hObject, varargin)
1002         currParamIndex = str2double(get(hObject,'Tag'));
1003         status = get(hObject,'Value'); % 1 activated, 0 deactivated
1004         
1005         paramval = get(hObject,'UserData');
1006         paramKey = newparams.params(currParamIndex).key;
1007         if status %activated
1008             if ~isempty(paramval)
1009                 newparams = pset(newparams,paramKey,{'-->'});
1010             else
1011                 newparams = pset(newparams,paramKey,'-->');
1012             end
1013             paramEnabled(currParamIndex) = 1;
1014             UpdateInports(paramKey,1)
1015         else %deactivated
1016           % Retrieve the original param:
1017             [func,currClass] = strtok(get(gcbh,'Tag'));
1018             infoObj = eval([currClass,'.getInfo(''',functionName,''')']);
1019             
1020             if numel(infoObj.sets) > 1
1021                currSet   = find(paramSets,'currSet');
1022                origParams = infoObj.plists(currSet);
1023             else
1024                origParams = infoObj.plists;
1025             end
1026             
1027             paramKey = newparams.params(currParamIndex).key;
1028             origPar = find(origParams,paramKey);
1029             if isempty(origPar), origPar = 1; end
1030             newparams = pset(newparams,paramKey,origPar);
1031             paramEnabled(currParamIndex) = 0;
1032             UpdateInports(paramKey,-1)
1033         end
1034 
1035         buildplistFigureParam([],[],get(findobj('Tag','paramsPage'),'UserData'))
1036         
1037     end
1038     %----------------------------------------------------------------------
1039 
1040     %----------------------------------------------------------------------
1041     function UpdateInports(varargin)
1042     % Update the MaskDisplay and the number of inports when the user
1043     % changes the params from Simulink.
1044     
1045         paramKey = varargin{1};
1046         if numel(paramKey)>7 && strcmpi(paramKey(1:7),'addPar_'), paramKey(1:7)=[]; end
1047         
1048       % List of parameters coming from Simulink:
1049         simKey = {};
1050         for i=1:nparams(newparams)
1051             if isa(newparams.params(i).val,'char') && strcmp(newparams.params(i).val,'-->')
1052                 name = newparams.params(i).key;
1053                 try if strcmpi(name(1:7),'addPar_'), name(1:7)=[];  end; catch end
1054                 simKey{end+1} = name;
1055             elseif isa(newparams.params(i).val,'cell') && isa(newparams.params(i).val{1},'char') && strcmp(newparams.params(i).val{1},'-->')
1056                 name = newparams.params(i).key;
1057                 try if strcmpi(name(1:7),'addPar_'), name(1:7)=[];  end; catch end
1058                 simKey{end+1} = name;
1059             end
1060         end
1061 
1062       % ===================================================================
1063       % If varargin{2}==2 no block has been added or subtracted, just
1064       % renamed an existing param; the only thing to perform is update the
1065       % drawing command.
1066         if varargin{2}~=2
1067             
1068           % Remove ALL inner inport blocks.
1069             if varargin{2}==-1, simKey2remove = [simKey,{paramKey}]; else simKey2remove= simKey; end
1070             for i=1:numel(simKey2remove)
1071                 try %#ok<ALIGN>
1072                     block2delete = find_in_models(gcb,'SearchDepth',1,'LookUnderMasks','all','Name',lower(simKey2remove{i}));
1073                     if numel(block2delete)>1, block2delete(1)=[]; end
1074                     blockLines   = get_param(block2delete{1},'LineHandles');
1075                     if (blockLines.Outport(1)~=-1 && ~isempty(blockLines.Outport(1))),   delete_line(blockLines.Outport(1)); end
1076                     delete_block(block2delete);
1077                 catch end
1078             end
1079 
1080           % Add ALL inner inport blocks anew:
1081             for i=1:numel(simKey)
1082                 newBlock = add_block('simulink/Sources/In1', [gcb,'/Inport1'],'MakeNameUnique','on');
1083                 nameAlreadyPresent = find_in_models(gcb,'SearchDepth',1,'LookUnderMasks','all','Name',lower(simKey{i}));
1084                 if ~isempty(nameAlreadyPresent)
1085                     for j=1:numel(nameAlreadyPresent)
1086                         if ~strcmp(nameAlreadyPresent{j},gcb),
1087                             set_param(nameAlreadyPresent{j},'Name',[lower(simKey{i}),'_fun']);
1088                         end
1089                     end
1090                 end
1091                 set(newBlock,'Name',lower(simKey{i}))
1092             end
1093 
1094           % Now update the inner structure of lines and mux.
1095             muxblock   = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Mux');
1096             try %#ok<ALIGN>
1097                 muxLines = get_param(muxblock{1},'LineHandles');
1098                 for k=1:numel(muxLines.Inport),  if (muxLines.Inport(k)~=-1 && ~isempty(muxLines.Inport(k))),   delete_line(muxLines.Inport(k)); end
1099                 end
1100                 for k=1:numel(muxLines.Outport), if (muxLines.Outport(k)~=-1 && ~isempty(muxLines.Outport(k))), delete_line(muxLines.Outport(k)); end
1101                 end
1102             catch end
1103             delete_block(muxblock);
1104             inports  = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Inport');
1105             fakeInp  = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Ground');
1106             inports  = [fakeInp;inports];
1107             if numel(inports)>1
1108                 muxblock = add_block('built-in/Mux', [gcb,'/Mux']);
1109                 set(muxblock,'Position',[70 , 10 , 73 , 150])
1110                 set(muxblock,'Inputs',num2str(numel(inports)))
1111             end
1112             for k=1:numel(inports)
1113                 inports{k}=get_param(inports{k},'Handle');
1114                 blkLines = get(inports{k},'LineHandles');
1115                 for j=1:numel(blkLines.Outport), if (blkLines.Outport(j)~=-1 && ~isempty(blkLines.Outport(j))), delete_line(blkLines.Outport(j)); end
1116                 end
1117                 set(inports{k},'Position',[10 , 10+30*(k-1) , 30 , 30+30*(k-1)])
1118                 set(inports{k},'Tag',num2str(k))
1119                 if numel(inports)>1
1120                     add_line(gcb,[get(inports{k},'Name'),'/1'],[get(muxblock,'Name'),'/',num2str(k)]);
1121                 end
1122             end
1123             funcBlock = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','M-S-Function');
1124             funcBlock = get_param(funcBlock,'Name');
1125             if numel(inports)>1
1126                 add_line(gcb,[get(muxblock,'Name'),'/1'],[funcBlock{1},'/1']);
1127             else
1128                 add_line(gcb,[get(inports{1},'Name'),'/1'],[funcBlock{1},'/1']);
1129             end
1130 
1131         end
1132       % ===================================================================
1133 
1134         
1135       % Updating the drawing command for the block Mask:
1136         fakeInp  = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Ground');
1137         drawingCom = '';
1138         if numel(simKey)>0 % then there are params 'from simulink' added
1139             if numel(fakeInp)>0 || strcmp(get_param(gcbh,'Tag'),'arithmetic'), currInp=1; else currInp=str2double(get(findobj('Tag','numbDataInputs'),'String'))+1; end
1140             for nn=1:numel(simKey)
1141                 drawingCom = [drawingCom,'port_label(''input'',',num2str(currInp),',''',lower(simKey{1}),''');'];
1142                 simKey(1)  = [];
1143                 currInp    = currInp+1;
1144             end
1145         else % then the only inport is the regular one
1146             funcBlock  = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','M-S-Function');
1147             funcName   = get_param(funcBlock{1},'Tag');
1148             if numel(funcName)>6 && strcmp(funcName(1:6),'ltpda_'), funcName(1:6)=[]; end
1149             drawingCom = strcat('disp(''',lower(funcName),''')');
1150         end
1151         set(gcbh,'MaskDisplay',drawingCom)
1152         
1153     end
1154     %----------------------------------------------------------------------
1155 
1156     %----------------------------------------------------------------------
1157     function numberDataInput(hObject,varargin)
1158     % Called whenever the user changes the number of data inputs:
1159        
1160        prevNumb = get(hObject,'UserData');
1161        newNumb  = str2double(get(hObject,'String'));
1162        if isnan(newNumb), set(hObject,'String',num2str(prevNumb)); return; end
1163        
1164        fakeInp  = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Ground');
1165        if ~isempty(fakeInp) && newNumb>0
1166           blockLines   = get_param(fakeInp{1},'LineHandles');
1167           if (blockLines.Outport(1)~=-1 && ~isempty(blockLines.Outport(1))),   delete_line(blockLines.Outport(1)); end
1168           delete_block(fakeInp{1})
1169        end
1170        
1171        dataInports  = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Inport');
1172        
1173        paramFromSimulink = 0;
1174        for ii=1:nparams(newparams)
1175           paramvals{ii} = newparams.params(ii).val;
1176           if isa(paramvals{ii},'char') && numel(paramvals{ii})>2 && strcmp(paramvals{ii},'-->'), paramFromSimulink = paramFromSimulink + 1; end
1177        end
1178 
1179        % To set the proper port number for parameters inport:
1180        for ii=1:paramFromSimulink
1181           set_param(dataInports{end-paramFromSimulink+ii},'Port',num2str(newNumb+11));
1182        end
1183        % To avoid considering inports for parameters:
1184        dataInports(end-paramFromSimulink+1:end) = [];
1185        
1186        % To remove all previous data inports:
1187        for ii=1:numel(dataInports)
1188           try %#ok<ALIGN>
1189              blockLines   = get_param(dataInports{ii},'LineHandles');
1190              if (blockLines.Outport(1)~=-1 && ~isempty(blockLines.Outport(1))),   delete_line(blockLines.Outport(1)); end
1191              delete_block(dataInports{ii});
1192           catch end
1193        end
1194        
1195        % To add new inports for all data expected:
1196        if newNumb==0, add_block('simulink/Sources/Ground', [gcb,'/data_input'],'MakeNameUnique','on','Name','data'); end
1197        for ii=1:newNumb
1198           newBlock = add_block('simulink/Sources/In1', [gcb,'/Inport1'],'MakeNameUnique','on','Name',['data',num2str(ii)]);
1199           set_param(newBlock,'Port',num2str(ii));
1200        end
1201        
1202        UpdateInports('',1)
1203        
1204     end
1205     %----------------------------------------------------------------------
1206       
1207     %----------------------------------------------------------------------
1208     function EnableCallback(hObject,varargin)   
1209     % Callback function: run when the user click on the checkbox associated
1210     % to each parameter, to enable its setting.
1211     
1212          currParamID   = get(hObject,'UserData');
1213          [xx,yy]       = size(objName);
1214          switch get(hObject,'Value')
1215              case 1 % enable parameter change
1216                  jj=2;
1217                  while jj<=yy && ~isempty(objName{currParamID,jj})
1218                      try set(objName{currParamID,jj},'Enable','on'); set(objName{currParamID,jj},'ForegroundColor',[0 0 0]); catch end
1219                      jj=jj+1;
1220                  end
1221                  paramEnabled(currParamID)=1;
1222              case 0 % disable parameter change
1223                  jj=2;
1224                  while jj<=yy && ~isempty(objName{currParamID,jj})
1225                          try %#ok<ALIGN>
1226                              if strcmp(get(objName{currParamID,jj},'Style'),'checkbox') && strcmp(get(objName{currParamID,jj},'String'),'From Simulink')
1227                              else
1228                                  set(objName{currParamID,jj},'Enable','off');
1229                                  set(objName{currParamID,jj},'ForegroundColor',[0.7 0.7 0.7]);
1230                              end
1231                          catch end
1232                          jj=jj+1;
1233                  end
1234                  paramEnabled(currParamID)=0;
1235          end
1236          
1237         set(findobj('Tag','apply'),'Enable','on');
1238         set(findobj('Tag','undo'),'Enable','on');
1239          
1240     end
1241     %----------------------------------------------------------------------
1242 
1243     %----------------------------------------------------------------------
1244     function ExpandEdit(hObject,varargin)
1245     % Callback function: run when the user click on the checkbox associated
1246     % to each parameter, to enable its setting.
1247 
1248         origEditField = get(hObject,'UserData');
1249         currParamIndex = get(origEditField,'UserData');
1250         paramkey = newparams.params(currParamIndex).key;
1251         if numel(paramkey)>6 && strcmpi(paramkey(1:7),'addpar_'), paramkey(1:7)=[]; end
1252         paramval = get(origEditField,'String');
1253         
1254         editFigPos = [200,200,800,300];
1255         
1256         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'));
1257       % Edit field title:
1258         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');
1259       % Edit field:
1260         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');
1261       % Ok button:
1262         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');
1263       % Cancel button:
1264         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');
1265     end
1266     %----------------------------------------------------------------------
1267     
1268 %% ==================== General subfunctions ==============================
1269 % =========================================================================
1270     %----------------------------------------------------------------------
1271     function [array]=readInput(inputdata, maxnumb, varargin)
1272           [xx,yy]=size(inputdata);
1273         % xx is the number or rows, yy is the number of characters in the longest row
1274         % array={};
1275           array=[];
1276           for i=1:xx
1277               rowpos=1;
1278               elemidx(i)=1;
1279               for j=1:yy+1
1280                   if (j==yy+1 || inputdata(i,j)==',' || strcmp(inputdata(i,j),' ') ) && (j==1 || (j>1 && (~strcmp(inputdata(i,j-1),' '))))
1281                       if (j==1 || strcmp(inputdata(i,j-1),',')) && strcmp(inputdata(i,j),',')
1282                           array(i,elemidx(i))=0;
1283                           elemidx(i)=elemidx(i)+1;
1284                           rowpos=j+1;
1285                       else
1286                         % To consider numbers, eg [1]:
1287                         % try array{i,elemidx(i)}=eval(inputdata(i,rowpos:j-1));  catch elemidx(i)=elemidx(i)-1; end
1288                         % To consider strings, eg '1':
1289                         % array{i,elemidx(i)}=inputdata(i,rowpos:j-1);
1290                           array(i,elemidx(i))=eval(inputdata(i,rowpos:j-1));
1291                           rowpos=j+1;
1292                           elemidx(i)=elemidx(i)+1;
1293                       end
1294                   elseif j<yy+1 && strcmp(inputdata(i,j),' ')
1295                       rowpos=j+1;
1296                   end
1297               if maxnumb~=0 
1298                   if elemidx(i)==maxnumb+1, break; end
1299               end
1300               end
1301               elemidx(i)=elemidx(i)-1;
1302           end
1303     end
1304     %----------------------------------------------------------------------
1305 
1306     %----------------------------------------------------------------------
1307     function paramcommand = BuildParamCommand(paramlist,varargin)
1308     % Reconstruct the command line necessary to build a given plist
1309     
1310        % Initialize of the paramcommand ojbect:
1311          paramcommand = strcat('params=',string(paramlist),';');
1312          
1313          if strcmpi(get_param(gcbh,'Tag'),'arithmetic'), return; end
1314          
1315          if exist('paramEnabled','var') && ~isempty(paramEnabled)
1316              paramcommand = [paramcommand,' paramEnabled=',mat2str(paramEnabled),';'];
1317          end
1318 
1319          if ~exist('newparams','var') || nparams(paramlist)==0, paramcommand='params=plist(); paramEnabled=[];'; end
1320          
1321          if exist('noParamsReq','var') && noParamsReq==1
1322              paramcommand = [paramcommand,' noParamsReq=1;'];
1323          end
1324 
1325          description = get_param(gcbh,'Description');
1326          funcname = findstr('functionName=',description);
1327          if funcname
1328              i = funcname+14;
1329              while ~strcmp(description(i),';'), i=i+1; end
1330              funcname = description(funcname+13:i-1);
1331              paramcommand = [paramcommand,' functionName=',funcname,';'];
1332          end
1333         
1334          if exist('paramSets','var') && ~isempty(paramSets)
1335              paramcommand = [paramcommand,' paramSets=',string(paramSets),';'];
1336          end
1337          
1338     end
1339     %----------------------------------------------------------------------
1340 
1341     %----------------------------------------------------------------------
1342     function paramcommand = RetrievePlist(varargin)   
1343     % Retrieve the name of the function from the block, then asks for
1344     % parameters.
1345     
1346     try functionname = varargin{1};
1347     catch
1348         childpath = find_system(gcbh,'LookUnderMasks','all','BlockType','M-S-Function');
1349         functionname=get_param(childpath,'Tag');
1350     end
1351 
1352     if isempty(functionname)
1353         description = get_param(gcbh,'Description');
1354         funcname = findstr('functionName=',description);
1355         if funcname
1356             i = funcname+14;
1357             while ~strcmp(description(i),';'), i=i+1; end
1358             functionname = description(funcname+14:i-2);
1359         end
1360     end
1361 
1362     setappdata(0,'ltpda_currFunctionName',functionname);
1363 
1364     try
1365         switch functionname
1366             case 'generic'
1367                 paramcommand = 'functionName=''generic'';params=plist();paramEnabled=[];';
1368                 return
1369             case 'arithmetic'
1370                 paramcommand = 'functionName=''arithmetic'';params=plist(''alpha'',''-->'',''beta'',''-->'');';
1371                 return
1372             otherwise
1373                 [func,currClass] = strtok(get(gcbh,'Tag'));
1374                 currClass(1)=[];
1375                 infoObj = eval([currClass,'.getInfo(''',functionname,''')']);
1376                 
1377                 if numel(infoObj.sets) > 1
1378                    paramSets = plist('sets',infoObj.sets,'currSet',1);
1379                    paramcommand = ['paramSets=',string(paramSets),';','params=plist();'];
1380                 elseif numel(infoObj.sets) == 1 && nparams(infoObj.plists)
1381                    paramEnabled = zeros(1,nparams(infoObj.plists));
1382                    paramcommand = ['params=',string(infoObj.plists),'; paramEnabled=',mat2str(paramEnabled),';'];
1383                 else
1384                    paramcommand = 'params=plist();';
1385                 end
1386                 
1387         end
1388     catch ME
1389         disp(sprintf('Error: unable to retrieve the parameters required by the function "%s". Maybe it''s not supported yet?',functionname));
1390         ErrorFuncNotSupported();
1391         rethrow(ME)
1392     end
1393     
1394     end
1395     %----------------------------------------------------------------------
1396 
1397     %----------------------------------------------------------------------
1398     function AnnotationUpdate(paramlist,varargin)
1399     % Update the block annotation (the text below the block) with all the
1400     % current parameters
1401     
1402          annotation = '';
1403          numparams  = nparams(paramlist);
1404          firstpar   = 1;
1405          
1406          if strcmpi(get_param(gcbh,'Tag'),'arithmetic')
1407              eq = get(findobj('Tag','equationField'),'String');
1408              if ~isempty(eq)
1409             if numel(eq)>40, eq(1:end-25) = []; eq = ['...',eq]; end
1410                  for nn=1:length(selBlocks)
1411                      set_param(selBlocks(nn),'AttributesFormatString',eq);
1412                  end
1413              end
1414              return
1415          end
1416              
1417          for kk=1:numparams
1418              if paramEnabled(kk)
1419                  paramkey = paramlist.params(kk).key;
1420                  try %#ok<ALIGN>
1421                  if strcmpi(paramkey(1:7),'addPar_'), paramkey(1:7)=[]; end
1422                  catch end
1423                  paramval = paramlist.params(kk).val;
1424                  switch class(paramval)
1425                      case 'specwin'
1426                          windowName = paramval.type;
1427                          windowlength = size(paramval.win,2);
1428                          if firstpar==1 % it's the first parameter
1429                              annotation = ['(specwin) ',windowName,',',num2str(windowlength)];
1430                              firstpar=2;
1431                          else % it's not the first parameter
1432                              annotation = [annotation,'\n','(specwin) ',windowName,',',num2str(windowlength)];
1433                          end
1434                          if strcmp(windowName,'Kaiser')
1435                              windowPsll = paramval.psll;
1436                              annotation = [annotation,',',num2str(windowPsll)];
1437                          end
1438                      case 'double'
1439                          paramval = mat2str(paramval);
1440                          if numel(paramval)>25, paramval=['...',paramval(end-25:end)]; end
1441                          if firstpar==1, annotation=[lower(paramkey),' ',paramval]; firstpar=2;
1442                          else annotation = [annotation,'\n',lower(paramkey),' ',num2str(paramval)];
1443                          end
1444                      case 'char'
1445                          if numel(paramval)>25, paramval=['...',paramval(end-25:end)]; end
1446                          paramval = strrep(paramval,'''''','''');
1447                          if firstpar==1, annotation=[lower(paramkey),' ',paramval]; firstpar=2;
1448                          else annotation = [annotation,'\n',lower(paramkey),' ',paramval];
1449                          end
1450                      case 'pzmodel'
1451                          if firstpar==1, annotation='(pzmodel)'; firstpar=2;
1452                          else annotation = [annotation,'\n','(pzmodel)'];
1453                          end
1454                      case 'cell'
1455                          if isa(paramval{1},'char') && strcmp(paramval{1},'(-->)'), strParKey = '(-->)';
1456                          else strParKey = utils.prog.cell2str(paramval);
1457                          end
1458                          if firstpar==1
1459                              annotation = [lower(paramkey),' ',strParKey]; firstpar=2;
1460                          else annotation = [annotation,'\n',lower(paramkey),' ',strParKey];
1461                          end
1462                      case 'pole'
1463                          for mm=1:numel(paramval)
1464                              poleFreqs(mm,1) = paramval(mm).f;
1465                              poleQs(mm,1)    = paramval(mm).q;
1466                              if ~isnan(poleQs(mm,1))
1467                                  poleFQs{mm,1}=strcat(num2str(poleFreqs(mm,1)),',',num2str(poleQs(mm,1)));
1468                              else
1469                                  poleFQs{mm,1}=num2str(poleFreqs(mm,1));
1470                              end
1471                          end
1472                          poleFQs=char(poleFQs);
1473                          if firstpar==1
1474                              annotation = ['pole ',poleFQs(1,:)]; firstpar=2;
1475                              for j=2:size(poleFQs,1), annotation = [annotation,'\n','(pole) ',poleFQs(j,:)]; end
1476                          else
1477                              annotation = [annotation,'\n','pole ',poleFQs(1,:)];
1478                              for j=2:size(poleFQs,1), annotation = [annotation,'\n','(pole) ',poleFQs(j,:)]; end
1479                          end
1480                      case 'zero'
1481                          for mm=1:numel(paramval)
1482                              zeroFreqs(mm,1) = paramval(mm).f;
1483                              zeroQs(mm,1)    = paramval(mm).q;
1484                              if ~isnan(zeroQs(mm,1))
1485                                  zeroFQs{mm,1}=strcat(num2str(zeroFreqs(mm,1)),',',num2str(zeroQs(mm,1)));
1486                              else
1487                                  zeroFQs{mm,1}=num2str(zeroFreqs(mm,1));
1488                              end
1489                          end
1490                          zeroFQs=char(zeroFQs);
1491                          if firstpar==1
1492                              annotation = ['zero ',zeroFQs(1,:)]; firstpar=2;
1493                              for j=2:size(zeroFQs,1), annotation = [annotation,'\n','(zero) ',zeroFQs(j,:)]; end
1494                          else
1495                              annotation = [annotation,'\n','zero ',zeroFQs(1,:)];
1496                              for j=2:size(zeroFQs,1), annotation = [annotation,'\n','(zero) ',zeroFQs(j,:)]; end
1497                          end
1498                  end
1499              end
1500          end
1501          % Finally set the block annotation:
1502          for nn=1:length(selBlocks)
1503              set_param(selBlocks(nn),'AttributesFormatString',annotation);
1504          end
1505     end
1506     %----------------------------------------------------------------------
1507 
1508     %----------------------------------------------------------------------
1509     function functionNameSet(hObject, varargin)
1510     % Setting the name of the function in the 'generic' block.
1511     
1512        functionName2 = get(hObject,'String');
1513        classes = utils.helper.ltpda_userclasses;
1514        for i=1:numel(classes)
1515            if ismethod(eval(classes{i}),functionName2)
1516                currSel = utils.prog.gcbsh;
1517                for j=1:numel(currSel), set(currSel(j),'Tag',['method ',classes{i}]); end
1518                break
1519            else
1520                currSel = utils.prog.gcbsh;
1521                for j=1:numel(currSel), set(currSel(j),'Tag','function'); end
1522            end
1523        end
1524        paramcommand = RetrievePlist(functionName2);
1525         
1526       if ~isempty(paramcommand)
1527         functionName = functionName2;
1528       % setappdata(0,'ltpda_currFunctionName',functionName);
1529         paramcommand = strcat(paramcommand,'functionName=''',functionName2,''';');
1530         for i=1:1000
1531             try
1532                 for kk=1:length(selBlocks), set_param(selBlocks(kk),'Name',functionName2); end
1533                 break;
1534             catch
1535                 functionName2 = strcat(functionName,'_',num2str(i));
1536             end
1537         end
1538         for kk=1:length(selBlocks)
1539             set_param(selBlocks(kk),'Description',paramcommand);
1540         end
1541         delete(findobj(gcf,'Parent',currPanel))
1542         buildplistFigureParam([],[],get(findobj('Tag','paramsPage'),'UserData'))
1543         
1544       else % the functionName inserted it's not valid
1545           description = get_param(gcbh,'Description');
1546           funcname = findstr('functionName=',description);
1547           if funcname
1548               i = funcname+14;
1549               while ~strcmp(description(i),';'), i=i+1; end
1550               functionName = description(funcname+14:i-2);
1551           end
1552           set(hObject,'String',functionName);
1553         % setappdata(0,'ltpda_currFunctionName',functionName);
1554       end
1555       
1556       
1557     end
1558     %----------------------------------------------------------------------
1559 
1560 %% ============================= Sets =====================================
1561 % =========================================================================
1562      %----------------------------------------------------------------------
1563     function SetsUpdate(hObject,varargin)
1564     % Whenever the user select a different set of params
1565          currSet   = get(hObject,'Value');
1566          paramSets = pset(paramSets,'currSet',currSet);
1567          sets      = get(hObject,'UserData');
1568          functionname = getappdata(0,'ltpda_currFunctionName');
1569          
1570          [func,currClass] = strtok(get(gcbh,'Tag'));
1571          infoObj = eval([currClass,'.getInfo(''',functionname,''')']);
1572 
1573          newparams = infoObj.plists(currSet);
1574          paramEnabled = zeros(1,nparams(newparams));
1575          
1576          paramcommand = BuildParamCommand(newparams);
1577          for kk=1:length(selBlocks)
1578              set_param(selBlocks(kk),'Description',paramcommand);
1579          end
1580          
1581        % Finally set the block annotation:
1582          for nn=1:length(selBlocks)
1583              set_param(selBlocks(nn),'AttributesFormatString','');
1584          end
1585          
1586          buildplistFigureParam([],[],get(findobj('Tag','paramsPage'),'UserData'));
1587     end
1588     %----------------------------------------------------------------------
1589 
1590 %% ========= Special buttons: Help, Reset, KeepResults, SetName, ==========
1591 % ========================== Apply, Undo ==================================
1592     %----------------------------------------------------------------------
1593     function HelpButtonCallback(varargin)
1594     % Whenever the user click the Help button
1595     
1596          try
1597              childpath = find_system(gcbh,'LookUnderMasks','all','BlockType','M-S-Function');
1598              functionname = get_param(childpath,'Tag');
1599              
1600              description = get_param(gcbh,'Description');
1601              funcname = findstr('functionName=',description);
1602              if funcname
1603                  i = funcname+14;
1604                  while ~strcmp(description(i),';'), i=i+1; end
1605                  functionname = description(funcname+14:i-2);
1606              end
1607              
1608              [func,classes] = strtok(get(gcbh,'Tag'));
1609              if strcmp(func,'method')
1610                  helptext = help([strtrim(classes),'/',functionname]);
1611              else
1612                  helptext = help(functionname);
1613              end
1614              
1615              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'));
1616            % Help text:
1617              uicontrol('Parent',helpFigure,'Units','normalized','HorizontalAlignment','left','Position',[0 0 1 1],'FontSize',guiFontSize+1,'String',helptext,'Visible','on','max',100,'Style','edit');
1618          catch
1619              disp('Something''s wrong with the creation of the Help figure. Please check ''HelpButtonCallback''')
1620          end
1621     end
1622     %----------------------------------------------------------------------
1623 
1624     %----------------------------------------------------------------------
1625     function ResetButtonCallback(varargin)
1626     % Whenever the user click the Reset Parameters button
1627     
1628        % Ask for confirmation:
1629          screenSize = get(0,'ScreenSize');
1630          backColor   = [1 1 1];
1631          position   = [(screenSize(3)-250)/2,(screenSize(4)-160)/2,250,160];
1632          confirmFig = figure('Position',position,'Name','Please confirm reset','Tag','ConfirmReset','Resize','off','NumberTitle','off','Toolbar','none','Menubar','none');
1633        % Text
1634          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');
1635        % Button Yes
1636          dimension = position;
1637          logosize = [77 95];
1638          dimension = [50 , dimension(4)-logosize(2)-50 , logosize];
1639          yesbut = axes('Parent',confirmFig,'Units','pixels','Position',dimension,'Tag','Yes');
1640          image(imread('buttonyes2.jpg'),'Parent',yesbut,'ButtonDownFcn','set(findobj(''Tag'',''ConfirmReset''),''UserData'',0); uiresume;','Tag','YesButton');
1641          axis(yesbut,'off');
1642        % Button No
1643          dimension = position;
1644          logosize = [77 95];
1645          dimension = [127 , dimension(4)-logosize(2)-50 , logosize];
1646          nobut = axes('Parent',confirmFig,'Units','pixels','Position',dimension,'Tag','No');
1647          image(imread('buttonno2.jpg'),'Parent',nobut,'ButtonDownFcn','set(findobj(''Tag'',''ConfirmReset''),''UserData'',1); uiresume;','Tag','NoButton');
1648          axis(nobut,'off');
1649 
1650          uiwait;
1651          
1652          if get(confirmFig,'UserData'), delete(confirmFig); return; end
1653          delete(confirmFig);
1654          
1655          for i=1:length(selBlocks), set_param(selBlocks(i),'Description',''); set_param(selBlocks(i),'AttributesFormatString',''); end
1656          params = []; newparams = []; paramEnabled = []; oldparamEnabled = []; functionName = '';
1657          delete(findobj(gcf,'Parent',currPanel));
1658 %          paramcommand = RetrievePlist();
1659 %
1660 %          if findstr(paramcommand,'functionName=''generic''')
1661 %              for i=1:length(selBlocks), set_param(selBlocks(i),'Name','generic'); end
1662 %          end
1663 %          eval(paramcommand)
1664 %          paramEnabled = zeros(1,nparams(newparams));
1665 %          for kk=1:length(selBlocks)
1666 %              set_param(selBlocks(kk),'Description',paramcommand);
1667 %          end
1668 %          AnnotationUpdate(newparams);
1669 %          buildplistFigureParam([],[],get(findobj('Tag','paramsPage'),'UserData'))
1670          buildplistFigureParam()
1671 
1672     end
1673     %----------------------------------------------------------------------
1674 
1675     %----------------------------------------------------------------------
1676     function KeepResultCallback(hObject,varargin)
1677     % Whenever the user clicks on the checkbox to maintain local results.
1678     
1679          switch get(hObject,'Value')
1680              case 0
1681                % Cycle to restore proper color
1682                  [meth,clas] = strtok(get_param(gcbh,'Tag'),' ');
1683                  infoObj = eval([clas,'.getInfo(''',getappdata(0,'ltpda_currFunctionName'),''')']);
1684                  switch infoObj.mcategory
1685                      case 'Constructor'
1686                          set_param(gcbh,'Backgroundcolor','green')
1687                          set_param(gcbh,'MaskHelp','')
1688                      case 'Output'
1689                          set_param(gcbh,'Backgroundcolor','lightBlue')
1690                          set_param(gcbh,'MaskHelp','')
1691                      otherwise
1692                          set_param(gcbh,'Backgroundcolor','red')
1693                          set_param(gcbh,'MaskHelp','')
1694                  end
1695              case 1
1696                  set_param(gcbh,'Backgroundcolor','magenta')
1697                  set_param(gcbh,'MaskHelp','probe')
1698          end
1699     end
1700     %----------------------------------------------------------------------
1701 
1702     %----------------------------------------------------------------------
1703     function SetNameCallback(hObject,varargin)
1704     % Whenever the user clicks on the checkbox to maintain local results.
1705     
1706          setName = get(hObject,'Value');
1707          set(gcbh,'UserData',setName);
1708          set(gcbh,'UserDataPersistent','on');
1709 
1710     end
1711     %----------------------------------------------------------------------
1712 
1713     %----------------------------------------------------------------------
1714     function ApplyButtonCallback(hObject,varargin)
1715     % Whenever the user clicks on the 'Apply' button.
1716     
1717    
1718        % If it's executed automacally (upon button deletion), check whether
1719        % there's something to apply or not:
1720          if strcmp(get(hObject,'enable'),'off'), return; end
1721     
1722        % This is to update the old params with those currently stored into
1723        % the block:
1724          temp = paramEnabled;
1725          paramcommand = get_param(gcbh,'Description');
1726          eval(paramcommand) % This overwrites also the current 'paramEnabled'
1727          oldparamEnabled = paramEnabled;
1728          paramEnabled = temp;
1729          
1730        % Now to update the block with the latest changed newparams:
1731          paramcommand = BuildParamCommand(newparams);
1732          for kk=1:length(selBlocks)
1733             set_param(selBlocks(kk),'Description',paramcommand);
1734          end
1735          AnnotationUpdate(newparams);
1736          
1737          set(hObject,'enable','off')
1738          
1739        % Redraw the panel only if the user hasn't changed selection or
1740        % clicked on a different tab:
1741          if nargin>2 && varargin{2}, buildplistFigureParam([],[],get(findobj('Tag','paramsPage'),'UserData')); end
1742 
1743     end
1744     %----------------------------------------------------------------------
1745 
1746     %----------------------------------------------------------------------
1747     function UndoButtonCallback(varargin)
1748     % Whenever the user clicks on the 'Undo' button.
1749     
1750          temp = paramEnabled;
1751          paramEnabled = oldparamEnabled;
1752          oldparamEnabled = temp;
1753 
1754          paramcommand = BuildParamCommand(params);
1755          for kk=1:length(selBlocks)
1756             set_param(selBlocks(kk),'Description',paramcommand);
1757          end
1758          AnnotationUpdate(params);
1759          
1760        % This to swap params and newparams, so it's possible to undo the undo:
1761          temp = newparams;
1762          newparams = params;
1763          params = temp;
1764          clear temp;
1765 
1766          buildplistFigureParam([],[],get(findobj('Tag','paramsPage'),'UserData'))
1767          
1768     end
1769     %----------------------------------------------------------------------
1770 
1771     
1772 %% =========== Input, Mux, Demux, From, Arithmetic block ==================
1773 % =========================================================================
1774     %----------------------------------------------------------------------
1775     function LoadInputParamCallback(varargin)   
1776     % This callback is called whenever the user selects an Input block. The
1777     % callback draws the panel to set the only parameter associated to this
1778     % type of block: the ordinal number of AO.
1779     
1780         if length(LTPDAinvar)<1
1781           % Text: 'Please load at least one AO in memory'
1782             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');
1783           % Button: 'Add data'
1784             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');
1785         else
1786           % Text: 'Obj input:'
1787             uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','left','Position',[100 panelDimens(4)-60 80 20],'String','Object input:','Visible','on','Style','text');
1788           % Edit field:
1789             children    = get_param(gcb,'Blocks');
1790             inputblock  = strcat(gcb,'/',children{1});
1791             currAOinput = get_param(inputblock,'Value');
1792             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');
1793             
1794           % Text: 'Objs list:'
1795             uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','left','Position',[100 panelDimens(4)-135 50 20],'String','Object list:','Visible','on','Style','text');
1796           % Popup input objs list:
1797             xx = size(LTPDAinvar,1);
1798             listInput = cell(xx,1);
1799             for j=1:xx
1800                 switch class(LTPDAinvar{j,1})
1801                     case 'ao'
1802                         anobject  = LTPDAinvar{j,1};
1803                         aoname    = anobject.name;
1804                         aocreated = char(anobject.created);
1805                         listInput{j,1} = [num2str(j) , ' . AO .' , aoname , '__' , aocreated];
1806                     case 'plist'
1807                         paramNumb = nparams(LTPDAinvar{j,1});
1808                         objcreated = char(LTPDAinvar{j,1}.created);
1809                         listInput{j,1}=[num2str(j),' . PLIST .',num2str(paramNumb),' params','__',objcreated];
1810                     case 'specwin'
1811                         listInput{j,1}=[num2str(j),' . SPECWIN .','__','no creation time'];
1812                     case 'pzmodel'
1813                         objcreated = char(LTPDAinvar{j,1}.created);
1814                         listInput{j,1}=[num2str(j),' . PZMODEL .','__',objcreated];
1815                     otherwise
1816                         if isa(LTPDAinvar{j,1},'ltpda_uo')
1817                             objclass  = class(LTPDAinvar{j,1});
1818                             if ~isempty(LTPDAinvar{j,1}), listInput{j,1}=[num2str(j),' . ',objclass]; end
1819                         end
1820                 end
1821             end
1822             for j=xx:-1:1
1823                 if isempty(listInput{j,1})
1824                     listInput(j,:)=[];
1825                 end
1826             end
1827             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');
1828             
1829           % Set the popup list on the proper line:
1830             for ii = 1:size(listInput,1)
1831                 if str2double(deblank(strtok(listInput{ii}))) == str2double(currAOinput), break; end
1832             end
1833             set(inputPopup,'Value',ii);
1834         end
1835     end
1836     %----------------------------------------------------------------------
1837 
1838     %----------------------------------------------------------------------
1839     function InputEditCallback(hObject, varargin)   
1840     % This callback is called whenever the user modify the input parameter
1841     % associated to an Input block
1842     
1843          if ~isempty(varargin{1}), newValue = varargin{1};
1844          else newValue   = str2double(get(hObject,'String'));
1845          end
1846        % Check it's an integer:
1847          newValue = round(newValue);
1848        % Check if the value is acceptable, ie:
1849        % - if it's <length(LTPDAinvar)
1850          if newValue>length(LTPDAinvar)
1851              newValue=length(LTPDAinvar);
1852          end
1853        % - if it's a LTPDA valid object:
1854          if ~isa(LTPDAinvar{newValue,1},'ltpda_uo')
1855              children   = get_param(gcbh,'Blocks');
1856              inputblock = strcat(strcat(get(gcbh,'Path'),'/',get(gcbh,'Name')),'/',children{1});
1857              oldValue   = get_param(inputblock,'Value');
1858              set(findobj('Tag','inputEditField'),'String',oldValue);
1859              return
1860          end
1861          
1862          set(hObject,'String',num2str(newValue));
1863          
1864        % Set the popup list on the proper line:
1865          inputPopup = findobj('Tag','inputPopupField');
1866          listInput = get(inputPopup,'String');
1867          for ii = 1:size(listInput,1)
1868              if str2double(deblank(strtok(listInput{ii}))) == newValue, break; end
1869          end
1870          set(inputPopup,'Value',ii);
1871 
1872        % Object name for the annotation:
1873          objName = LTPDAinvar{newValue,1}.name;
1874          if numel(objName)>3 && strcmpi(objName,'none'), objName = class(LTPDAinvar{newValue,1}); end
1875          if numel(objName)>20, objName = ['...',LTPDAinvar{newValue,1}.name(end-20:end)]; end
1876          objName = [num2str(newValue),': ',objName];
1877          
1878          for i=1:length(selBlocks)
1879            % Since all input blocks are masks, and we want to change the
1880            % value deep inside a block INSIDE this mask, we can't use the
1881            % direct handles but the following:
1882              children{i}=get_param(selBlocks(i),'Blocks');
1883              inputblock=strcat(strcat(get(selBlocks(i),'Path'),'/',get(selBlocks(i),'Name')),'/',children{i}{1});
1884              set_param(inputblock,'Value',num2str(newValue));
1885            % Set the annotation:
1886              set_param(selBlocks(i),'AttributesFormatString',objName);
1887          end
1888     end
1889     %----------------------------------------------------------------------
1890 
1891     %----------------------------------------------------------------------
1892     function InputPopupCallback(hObject, varargin)  
1893     % This callback is called whenever the user clicks on the input list in
1894     % the parameters panel asociated to the 'Input Obj' block
1895     
1896         val = get(hObject, 'Value');
1897         objLines = get(hObject, 'String');
1898         objnumb = str2double(deblank(strtok(objLines{val})));
1899         
1900         InputEditCallback(findobj('Tag','inputEditField'),objnumb);
1901         
1902     end
1903     %----------------------------------------------------------------------
1904 
1905     %----------------------------------------------------------------------
1906     function AddButtonCallback(varargin)   
1907     % Callback function: run when the user click the "Add data" button
1908     
1909          filenames = uipickfiles('REFilter','.txt');
1910          if ~isempty(filenames) && ~isnumeric(filenames(1,1))
1911              [x,y]=size(filenames);
1912              for j=1:y
1913                  anobject={ao(filenames{j})};
1914                  LTPDAinvar=[LTPDAinvar;anobject];
1915              end
1916              disp(sprintf('  + %g AOs added to the global variable LTPDAinvar', y))
1917              buildplistFigureParam([],[],get(findobj('Tag','paramsPage'),'UserData'));
1918          end
1919     end   
1920     %----------------------------------------------------------------------
1921     
1922     %----------------------------------------------------------------------
1923     function LoadMuxParamCallback(varargin)   
1924     % This callback is called whenever the user selects a Mux block (or
1925     % Demux). The callback opens the panel to set the only parameter
1926     % associated to this type of block: the number of inputs.
1927     % The function sets also the dimension of the block accordingly.
1928         
1929         if strcmp(get(gcbh,'Tag'),'mux'),
1930           % Text: 'Number of inputs:'
1931             uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','left','Position',[100 panelDimens(4)-60 100 20],'String','Number of inputs:','Visible','on','Style','text');
1932           % Edit field:
1933             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');
1934         elseif strcmp(get(gcbh,'Tag'),'demux'),
1935           % Text: 'Number of outputs:'
1936             uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','left','Position',[100 panelDimens(4)-60 100 20],'String','Number of outputs:','Visible','on','Style','text');
1937           % Edit field:
1938             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');
1939         end
1940     end
1941     %----------------------------------------------------------------------
1942 
1943     %----------------------------------------------------------------------
1944     function MuxEditCallback(hObject, varargin)   
1945     % This callback is called whenever the user modify the number of inputs
1946     % associated to a Mux block (or outputs to a Demux)
1947     
1948          newValue   = str2double(get(hObject,'String'));
1949        % Check it's an integer:
1950          newValue = round(newValue);
1951          set(hObject,'String',num2str(newValue));
1952          for i=1:length(selBlocks)
1953              newDimens=get(selBlocks(i),'Position');
1954              newDimens(4)=newDimens(2)+25*(newValue+1);
1955              if strcmp(get(gcbh,'Tag'),'mux'),
1956                  set(selBlocks(i),'Inputs',num2str(newValue));
1957              elseif strcmp(get(gcbh,'Tag'),'demux'),
1958                  set(selBlocks(i),'Outputs',num2str(newValue));
1959              end
1960              set(selBlocks(i),'Position',newDimens);
1961          end
1962     end
1963     %----------------------------------------------------------------------
1964     
1965     %----------------------------------------------------------------------
1966     function LoadFromBlockCallback(varargin)   
1967     % This callback is called whenever the user selects a From block.
1968         
1969       % Button: 'Find origin'
1970         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');
1971     end
1972     %----------------------------------------------------------------------
1973 
1974     %----------------------------------------------------------------------
1975     function FindOriginCallback(varargin)   
1976     % This callback is called whenever click on the 'Find Origin' button,
1977     % having selected a 'From' block.
1978     
1979         varName = get(gcbh,'GotoTag');
1980         origin = find_in_models(bdroot,'LookUnderMasks','all','BlockType','Goto','GotoTag',varName);
1981         if numel(origin)>1
1982           % Error text: there are multiple origins.
1983             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');
1984         elseif numel(origin)==1
1985           % Text: full path of the origin.
1986             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');
1987         else
1988           % Error text: no origin found.
1989             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');
1990         end
1991             
1992         
1993         
1994     end
1995     %----------------------------------------------------------------------
1996 
1997     %----------------------------------------------------------------------
1998     function arithmetic(varargin)   
1999     % This callback is called whenever the user selects an arithmetic block.
2000         
2001         delete(findobj(gcf,'Parent',currPanel))
2002         lineSpacing = getappdata(0,'ltpda_gui_LineSpacing');
2003         paramcommand = get_param(gcbh,'Description');
2004         noParamsReq=0;
2005         if isempty(paramcommand)
2006             paramcommand = RetrievePlist('arithmetic');
2007             selBlocks = utils.prog.gcbsh;
2008             for kk=1:length(selBlocks)
2009                 set_param(selBlocks(kk),'Description',paramcommand);
2010             end
2011         end
2012         eval(paramcommand)
2013 
2014         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');  
2015         y = nparams(newparams);
2016         for i=1:y
2017             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');
2018             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');
2019           % Remove input button
2020             if i>1
2021                 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');
2022             end
2023         end
2024       % Add input button
2025         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');
2026 
2027       % Output name:
2028         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');
2029         outName = get(gcbh,'UserData');
2030         if isempty(outName), outName = get(gcbh,'Name'); end
2031         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');
2032 
2033       % 'Type in the equation' text
2034         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');  
2035       % Example edit field
2036         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');
2037 
2038       % 'output =' text
2039         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');  
2040       % Main edit field
2041         eqString = get_param(gcbh,'MaskDescription');
2042         if numel(eqString)>16 && strcmp(eqString(1:17),'Arithmetic block:'), eqString = ''; end
2043         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');
2044 
2045     end
2046     %----------------------------------------------------------------------
2047 
2048     %----------------------------------------------------------------------
2049     function eqEdit(hObject,varargin)
2050         
2051         eq = get(hObject,'String');
2052         if ~isempty(eq)
2053             if numel(eq)>40, eq(1:end-25) = []; eq = ['...',eq]; end
2054             for nn=1:length(selBlocks)
2055                 set_param(selBlocks(nn),'MaskDescription',get(hObject,'String'));
2056                 set_param(selBlocks(nn),'AttributesFormatString',eq);
2057             end
2058         else
2059             eqString = get_param(gcbh,'MaskDescription');
2060             if numel(eqString)>16 && strcmp(eqString(1:17),'Arithmetic block:'), eqString = ''; end
2061             set(hObject,'String',eqString);
2062         end
2063         
2064     end
2065     %----------------------------------------------------------------------
2066 
2067 %% ============================== Errors ==================================
2068 % =========================================================================
2069     %----------------------------------------------------------------------
2070     function ErrorFuncNotSupported(varargin)   
2071     % Recalled whenever the parameters call fails
2072     
2073       % Text: '[...] Maybe it''s not supported yet?'
2074         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');   
2075     end
2076     %----------------------------------------------------------------------
2077 
2078     %----------------------------------------------------------------------
2079     function ErrorSelectionInconsistent(varargin)   
2080     % Recalled whenever the user selects inconsistent multiple blocks
2081         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');   
2082     end
2083     %----------------------------------------------------------------------
2084 
2085 % =========================================================================
2086 %%
2087 
2088 end

Generated on Mon 25-Aug-2008 22:39:29 by m2html © 2003