Home > m > gui > gltpda > pan1main.m

pan1main

PURPOSE ^

This is the function for the main panel of the GUI LTPDA, the package of

SYNOPSIS ^

function pan1main(varargin)

DESCRIPTION ^

 This is the function for the main panel of the GUI LTPDA, the package of
 data analysis functions developed for the LISA Pathfinder Mission / LISA
 Technology Package.

  $Id: pan1main.m,v 1.36 2008/08/25 14:27:52 nicola Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function pan1main(varargin)
0002 % This is the function for the main panel of the GUI LTPDA, the package of
0003 % data analysis functions developed for the LISA Pathfinder Mission / LISA
0004 % Technology Package.
0005 %
0006 %  $Id: pan1main.m,v 1.36 2008/08/25 14:27:52 nicola Exp $
0007 
0008 global LTPDAinvar LTPDAoutvar currentsystem gl
0009 
0010 % Initialize the list of AOs:
0011 InputObjList=''; % OutputObjList='';
0012 UpdateListbox();
0013 
0014 scaleX = getappdata(0, 'ltpda_gui_scalefactor');
0015 guiFontSize = round(8*scaleX);
0016 
0017 alltimers = timerfindall;
0018 stop(alltimers(2));
0019 set(alltimers(2),'TimerFcn',@ContinuousCheck,'Period',1);
0020 start(alltimers(2));
0021 set(gcf,'NextPlot','new')
0022 set(gcf,'CloseRequestFcn',{@AskConfirm,'close'})
0023 
0024 %%
0025 
0026 currPanel   = varargin{1};
0027 if nargin>1, runSim = varargin{2}; else runSim = 0; end
0028 panelDimens = get(currPanel, 'Position');
0029 backColor   = get(currPanel, 'BackgroundColor');
0030 
0031   uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Units','normalized','Position',[0.0375 0.895 0.075 0.06],'String','Username:','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Visible','on','Style','text');
0032   uicontrol('Parent',currPanel,'BackgroundColor',[0.9,0.9,0.9],'Units','normalized','HorizontalAlignment','center','Position',[0.1187 0.9213 0.1 0.050],'String',getappdata(0,'ltpda_repo_user'),'FontSize',guiFontSize,'FontAngle','italic','Visible','on','Enable','off','Callback',@UserIDCallback,'Style','edit');
0033   uicontrol('Parent',currPanel,'Units','normalized','HorizontalAlignment','center','Position',[0.2375 0.9274 0.15 0.040],'String','Login / Logout','FontSize',guiFontSize,'Visible','on','Enable','on','Callback',@LogoutCallback,'Style','pushbutton');
0034                     
0035     uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Units','normalized','Position',[0.5 0.915 0.125 0.040],'String','Current system:','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Visible','on','Style','text');
0036   currsystem = bdroot;
0037     if isempty(currsystem) || isempty(find_system(currsystem,'FindAll','on','Type','Annotation','Tag','ltpda model')), currsystem = 'None'; end
0038   uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Units','normalized','Position',[0.6375 0.915 0.1875 0.040],'String',currsystem,'FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Visible','on','UserData','currsystem','Style','text');
0039 
0040 
0041     AnalysPanPos   = [.0125 .7983 .975 .111]; % in pixels: [10 panelDimens(4)-100 panelDimens(3)-20 55]
0042 
0043   hanalysisPanel = uipanel('Parent',currPanel,'Title','Analyses Control Panel','BackgroundColor',backColor,'FontSize',guiFontSize-1,'Units','normalized','Position',AnalysPanPos);
0044     logosize = [40 35]*scaleX;
0045     icon1 = axes('Parent',hanalysisPanel,'Units','normalized','Position',[.01 .05 0.3 0.3]);
0046     iconSize = getpixelposition(icon1); iconSize(3:4) = logosize; setpixelposition(icon1,iconSize);
0047     image(imread('icongraph.jpg'),'Parent',icon1);
0048     axis(icon1,'off');
0049     clear logosize icon1
0050 
0051     nbuttons    = 3;
0052     buttonWidth = (AnalysPanPos(3)-.0625-.0125*(nbuttons+1))/nbuttons;
0053     buttonPos   = [AnalysPanPos(1)+.075 .2 buttonWidth .6];
0054   uicontrol('Parent',hanalysisPanel,'Units','pixels','Units','normalized','Position',buttonPos,'String','New model','TooltipString','Create a new LTPDA Simulink model','HorizontalAlignment','center','FontSize',guiFontSize,'Visible','on','Enable','on','Callback',@hNewButtonCallback,'Style','pushbutton');
0055     buttonPos(1) = buttonPos(1)+buttonWidth+.0125;
0056   uicontrol('Parent',hanalysisPanel,'Units','pixels','Units','normalized','Position',buttonPos,'String','Open model','TooltipString','Open an existing LTPDA Simulink model','HorizontalAlignment','center','FontSize',guiFontSize,'Visible','on','Enable','on','Callback',@hOpenCallback,'Style','pushbutton');
0057     buttonPos(1) = buttonPos(1)+buttonWidth+.0125;
0058   uicontrol('Parent',hanalysisPanel,'Units','pixels','Units','normalized','Position',buttonPos,'String','Save model','TooltipString','Save the currently selected LTPDA Simulink model','HorizontalAlignment','center','FontSize',guiFontSize,'Visible','on','Enable','on','Callback',@hSaveCallback,'Style','pushbutton');
0059     clear AnalysPanPos nbuttons buttonWidth buttonPos
0060 
0061 
0062     DataPanPos   = [.015 .1633 .975 .615]; % in pixels [10 panelDimens(4)-415 panelDimens(3)-20 305];
0063   hDataPanel    =  uipanel('Parent',currPanel,'Title','Data Control Panel','BackgroundColor',[1,1,1],'FontSize',guiFontSize-1,'Units','normalized','Position',DataPanPos);
0064     logosize = [48 39]*scaleX;
0065     icon2 = axes('Parent',hDataPanel,'Units','normalized','Position',[.01 0.81 0.3 0.3]);
0066     iconSize = getpixelposition(icon2); iconSize(3:4) = logosize; setpixelposition(icon2,iconSize);
0067     image(imread('icondata.jpg'),'Parent',icon2);
0068     axis(icon2,'off');
0069     clear logosize icon2
0070    
0071     nbuttons    = 3;
0072     buttonWidth = (DataPanPos(3)-.0625-.0125*(nbuttons+1))/nbuttons;
0073     buttonPos   = [DataPanPos(1)+.075 .9 buttonWidth .08];
0074   uicontrol('Parent',hDataPanel,'Units','normalized','HorizontalAlignment','center','Position',buttonPos,'String','Load','TooltipString','Load data from file','FontSize',guiFontSize,'Visible','on','Enable','on','Callback',@hLoadDataButtonCallback,'Style','pushbutton');
0075 %   buttonPos(1) = buttonPos(1)+buttonWidth+.0125;
0076 % uicontrol('Parent',hDataPanel,'Units','normalized','HorizontalAlignment','center','Position',buttonPos,'String','Create','FontSize',guiFontSize,'Visible','on','Enable','off','UserData',InputObjList,'Callback',@hExploreButtonCallback,'Style','pushbutton');
0077 %   buttonPos(1) = buttonPos(1)+buttonWidth+.0125;
0078 % uicontrol('Parent',hDataPanel,'Units','normalized','HorizontalAlignment','center','Position',buttonPos,'String','Edit','FontSize',guiFontSize,'Visible','on','Enable','off','UserData',InputObjList,'Callback',@hExploreButtonCallback,'Style','pushbutton');
0079     buttonPos(1) = buttonPos(1)+buttonWidth+.0125;
0080   uicontrol('Parent',hDataPanel,'Units','normalized','HorizontalAlignment','center','Position',buttonPos,'String','Remove','TooltipString','Clear the selected object from memory','FontSize',guiFontSize,'Visible','on','Enable','on','Callback',@hRemoveButtonCallback,'Style','pushbutton');
0081     buttonPos(1) = buttonPos(1)+buttonWidth+.0125;
0082   hExploreButton =  uicontrol('Parent',hDataPanel,'Units','normalized','HorizontalAlignment','center','Position',buttonPos,'String','Explore','TooltipString','Explore the selected objects with the LTPDA Explorer','FontSize',guiFontSize,'Visible','on','Enable','on','UserData',InputObjList,'Callback',@hExploreButtonCallback,'Style','pushbutton');
0083     clear nbuttons buttonWidth buttonPos
0084 
0085     nbuttons    = 4;
0086     buttonWidth = (DataPanPos(3)-.0625-.012510*(nbuttons+1))/nbuttons;
0087     buttonPos   = [DataPanPos(1)+.075 .8 buttonWidth .08];
0088 % hImportButton =   uicontrol('Parent',hDataPanel,'Units','normalized','HorizontalAlignment','center','Position',buttonPos,'String','Import','FontSize',guiFontSize,'Visible','on','Enable','on','Callback',@hImportButtonCallback,'Style','pushbutton');
0089 %   buttonPos(1) = buttonPos(1)+buttonWidth+.0125;
0090   uicontrol('Parent',hDataPanel,'Units','normalized','HorizontalAlignment','center','Position',buttonPos,'String','Clear all input','TooltipString','Clear from memory the entire list of input objects','FontSize',guiFontSize,'Visible','on','Enable','on','Callback',{@AskConfirm,'clear'},'Style','pushbutton');
0091     buttonPos(1) = buttonPos(1)+buttonWidth+.0125;
0092   uicontrol('Parent',hDataPanel,'Units','normalized','HorizontalAlignment','center','Position',buttonPos,'String','Export to workspace','TooltipString','Export the selected objects from LTPDA to MATLAB workspace','FontSize',guiFontSize,'Visible','on','Enable','on','Callback',@hExportButtonCallback,'Style','pushbutton');
0093     buttonPos(1) = buttonPos(1)+buttonWidth+.0125;
0094   uicontrol('Parent',hDataPanel,'Units','normalized','HorizontalAlignment','center','Position',buttonPos,'String','Save workspace','TooltipString','Save the LTPDA Workspace as .MAT file','FontSize',guiFontSize,'Visible','on','Enable','on','Callback',@SaveWorkspaceCallback,'Style','pushbutton');
0095     buttonPos(1) = buttonPos(1)+buttonWidth+.0125;
0096   uicontrol('Parent',hDataPanel,'Units','normalized','HorizontalAlignment','center','Position',buttonPos,'String','Load workspace','TooltipString','Load a workspace from a .MAT file','FontSize',guiFontSize,'Visible','on','Enable','on','Callback',@LoadWorkspaceCallback,'Style','pushbutton');
0097     clear nbuttons buttonWidth buttonPos
0098 
0099 
0100     textPos   = [.0125 .67 .5 .083];
0101   uicontrol('Parent',hDataPanel,'BackgroundColor',get(hDataPanel,'BackgroundColor'),'HorizontalAlignment','center','Units','normalized','Position',textPos,'String','Input:','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Visible','on','Style','text');
0102     clear textPos
0103 
0104     nlists    = 2;
0105     listWidth = (DataPanPos(3)-.0125*(nlists+1))/nlists;
0106     listPos   = [.0125 .03 listWidth .66];
0107   InputObjList   = uicontrol('Parent',hDataPanel,'BackgroundColor',[0.95,0.95,0.95],'HorizontalAlignment','center','Units','normalized','Position',listPos,'String',listInput,'Value',1,'Max',10,'Min',1,'FontSize',guiFontSize,'FontWeight','normal','Visible','on','Enable','on','Callback',@hListObjsCallback,'Tag','InputObjList','Style','listbox');
0108     set(hExploreButton,'UserData',InputObjList);
0109     listPos(1) = listPos(1)+listWidth+.0125;
0110   % Info panel:
0111   uicontrol('Parent',hDataPanel,'BackgroundColor',[0.94,0.94,1],'Style','listbox','HorizontalAlignment', 'left','Fontsize', guiFontSize,'Units','pixels','Units','normalized','Position',listPos,'Tag','infoPanel');
0112     hListObjsCallback(InputObjList,1);
0113     clear DataPanPos nlists listWidth listPos
0114     
0115     
0116   hExecutionPanel =  uipanel('Parent',currPanel,'Title','Execution control','BackgroundColor',[1,1,1],'FontSize',guiFontSize-1,'Units','normalized','Position',[.0125 .0222 .975 .121]);
0117    logosize = [46 40]*scaleX;
0118    icon3 = axes('Parent',hExecutionPanel,'Units','normalized','Position',[.01 .05 0.3 0.3]);
0119    iconSize = getpixelposition(icon3); iconSize(3:4) = logosize; setpixelposition(icon3,iconSize);
0120    image(imread('iconsettings.jpg'),'Parent',icon3);
0121    axis(icon3,'off');
0122    clear logosize icon3
0123    
0124     if isempty(getappdata(0,'maintainresults')), setappdata(0,'maintainresults',0); end
0125   uicontrol('Parent',hExecutionPanel,'BackgroundColor',[1 1 1],'HorizontalAlignment','left','Units','normalized','Position',[.1 .166 .3 .5],'Value',getappdata(0,'maintainresults'),'String',' Maintain all results','FontSize',guiFontSize+1,'TooltipString','Enable this if you want to maintain the results from all blocks at the end of the analysis calculation','ForeGroundColor','black','Visible','on','Enable','on','Callback','setappdata(0,''maintainresults'',get(gco,''Value''))','Style','checkbox');
0126     if isempty(getappdata(0,'hidenames')), setappdata(0,'hidenames',0); end
0127   uicontrol('Parent',hExecutionPanel,'BackgroundColor',[1 1 1],'HorizontalAlignment','left','Units','normalized','Position',[.4 0.166 .23 .5],'Value',getappdata(0,'hidenames'),'String',' Hide block names','FontSize',guiFontSize+1,'TooltipString','Enable this to hide blocks names for clarity; this will work only in the parameters panel','ForeGroundColor','black','Visible','on','Enable','on','Callback','setappdata(0,''hidenames'',get(gco,''Value''))','Style','checkbox');
0128  
0129 if runSim == 1, StartExec(); end
0130 
0131 %%
0132 
0133 % ========================================================================
0134 % ========================================================================
0135 % ============================== FUNCTIONS ===============================
0136 % ========================================================================
0137 % ========================================================================
0138 
0139 %%
0140     %----------------------------------------------------------------------
0141     function ContinuousCheck(varargin)   
0142         % This is the function to execute a continuous timer check
0143         
0144        % Keep alive the first timer:
0145          alltimers = timerfindall;
0146          if strcmp(get(alltimers(1),'Running'),'off')
0147              start(alltimers(1))
0148          end
0149 
0150          currsys = bdroot;
0151          if ~isempty(currsys) && ~isempty(find_system(currsys,'FindAll','on','Type','Annotation','Tag','ltpda model'))
0152              set(findobj('UserData', 'currsystem'), 'String', currsys)
0153          else
0154              set(findobj('UserData', 'currsystem'), 'String', 'None')
0155          end
0156          
0157     end
0158     %----------------------------------------------------------------------
0159 
0160 %%
0161     %----------------------------------------------------------------------
0162     function LogoutCallback(varargin)
0163     % Callback function: run when the user click the "Logout" button
0164 
0165          setappdata(0,'ltpda_repo_pass','');
0166          userID = getappdata(0,'ltpda_repo_user');
0167          if isempty(userID), userID = ''; end
0168 
0169          [userID passwd] = loginLTPDA(userID,'');
0170          setappdata(0,'ltpda_repo_user',userID)
0171          setappdata(0,'ltpda_repo_pass',passwd)
0172 
0173          ltpdagui('Redraw',1);
0174          
0175     end
0176     %----------------------------------------------------------------------
0177 
0178     %----------------------------------------------------------------------
0179     function AskConfirm(varargin)
0180     % Whenever the user click the Reset Parameters button
0181     
0182        % Ask for confirmation:
0183          screenSize = get(0,'ScreenSize');
0184          backColor   = [1 1 1];
0185          position   = [(screenSize(3)-250)/2,(screenSize(4)-160)/2,250,160];
0186          confirmFig = figure('Position',position,'Name','Please confirm','Tag','ConfirmReset','Resize','off','NumberTitle','off','Toolbar','none','Menubar','none');
0187        % Text
0188          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');
0189        % Button Yes
0190          dimension = position;
0191          logosize = [77 95];
0192          dimension = [50 , dimension(4)-logosize(2)-50 , logosize];
0193          yesbut = axes('Parent',confirmFig,'Units','pixels','Position',dimension,'Tag','Yes');
0194          image(imread('buttonyes2.jpg'),'Parent',yesbut,'ButtonDownFcn','set(findobj(''Tag'',''ConfirmReset''),''UserData'',0); uiresume;','Tag','YesButton');
0195          axis(yesbut,'off');
0196        % Button No
0197          dimension = position;
0198          logosize = [77 95];
0199          dimension = [127 , dimension(4)-logosize(2)-50 , logosize];
0200          nobut = axes('Parent',confirmFig,'Units','pixels','Position',dimension,'Tag','No');
0201          image(imread('buttonno2.jpg'),'Parent',nobut,'ButtonDownFcn','set(findobj(''Tag'',''ConfirmReset''),''UserData'',1); uiresume;','Tag','NoButton');
0202          axis(nobut,'off');
0203 
0204          uiwait;
0205          
0206          if get(confirmFig,'UserData'), delete(confirmFig); return; end
0207          
0208          if strcmp(varargin{3},'close')
0209             delete(confirmFig);
0210             disp('Closing LTPDA GUI...');
0211             delete(timerfindall);
0212             clear global LTPDAinvar LTPDAoutvar;
0213             setappdata(0,'ltpda_repo_user',''); setappdata(0,'ltpda_repo_pass','');
0214             closereq
0215          elseif strcmp(varargin{3},'clear')
0216             delete(confirmFig);
0217             LTPDAinvar={};
0218             set(InputObjList,'Value',1)
0219             set(findobj('Tag', 'infoPanel'), 'String', '')
0220             set_param(find_system(bdroot,'FindAll','on','Type','Annotation','Tag','ltpda model'),'UserData','');
0221             UpdateListbox();
0222          end
0223          
0224     end
0225     %----------------------------------------------------------------------
0226     
0227 %%
0228     %----------------------------------------------------------------------
0229     function hLoadDataButtonCallback(varargin)   
0230     % Callback function: run when the user click the "Add data" button
0231     
0232          filenames = uipickfiles('REFilter','.txt');
0233          if ~isempty(filenames) && ~isnumeric(filenames(1,1))
0234              [x,y]=size(filenames);
0235              for j=1:y
0236                  ext = filenames{j}(end-2:end);
0237                  if strcmpi(ext,'mat')
0238                      varlist = whos('-file',filenames{j});
0239                      for k=1:numel(varlist)
0240                          newObj = load(filenames{j},varlist(k).name); %#ok<NASGU>
0241                          newObj = eval(['newObj.',varlist(k).name]);
0242                          if isa(newObj,'ltpda_uo')
0243                              LTPDAinvar = [LTPDAinvar; {newObj,1} ];
0244                              disp('  + 1 Obj added to the global variable LTPDAinvar')
0245                          end
0246                      end
0247                  else
0248                      anobject={ao(filenames{j}),1};
0249                      LTPDAinvar=[LTPDAinvar;anobject];
0250                      disp('  + 1 AO added to the global variable LTPDAinvar')
0251                  end
0252              end
0253              UpdateListbox();
0254          end
0255     
0256     end
0257     %----------------------------------------------------------------------
0258 
0259     %----------------------------------------------------------------------
0260     function hRemoveButtonCallback(varargin)   
0261     % Callback function: run when the user click the "Remove data" button
0262 
0263            index_selected = get(InputObjList,'Value');
0264            listObjs = get(InputObjList,'String');
0265            if ~strcmp(listObjs,'The memory is empty')
0266                for i=1:numel(index_selected)
0267                    objSelect = str2double(strtok(listObjs{index_selected(i),1},'.'));
0268                    LTPDAinvar{objSelect,1} = [];
0269                end
0270                UpdateListbox();
0271            end
0272            set(findobj('Tag', 'infoPanel'), 'String', '')
0273 
0274     end
0275     %----------------------------------------------------------------------
0276 
0277     %----------------------------------------------------------------------
0278     function hExportButtonCallback(varargin)   
0279     % Callback function: run when the user click the "Export data" button
0280 
0281          currSelObjs   = get(InputObjList,'Value');
0282          listObjs = get(InputObjList,'String');
0283          if ~strcmp(listObjs,'The memory is empty')
0284              selectedObjs  = {};
0285              for i=1:numel(currSelObjs)
0286                  objSelect = str2double(strtok(listObjs{currSelObjs(i),1},'.'));
0287                  selectedObjs = [selectedObjs,LTPDAinvar(objSelect,1)];
0288              end
0289              if ~isempty(selectedObjs)
0290                  for i=1:numel(selectedObjs)
0291                      objName = [class(selectedObjs{i}),'_',selectedObjs{i}.name];
0292                      objName = genvarname(objName,evalin('base','who'));
0293                      assignin('base', objName, selectedObjs{i});
0294                      disp(['Saved to workspace with name ',objName])
0295                  end
0296              end
0297          end
0298          
0299     end
0300     %----------------------------------------------------------------------
0301 
0302     %----------------------------------------------------------------------
0303     function hExploreButtonCallback(varargin)   
0304     % Callback function: run when the user click the "Update list" button
0305 
0306          currSelObjs   = get(InputObjList,'Value');
0307          listObjs = get(InputObjList,'String');
0308          if ~strcmp(listObjs,'The memory is empty')
0309              selectedObjs  = {};
0310              for i=1:numel(currSelObjs)
0311                  objSelect = str2double(strtok(listObjs{currSelObjs(i),1},'.'));
0312                  selectedObjs = [selectedObjs,LTPDAinvar(objSelect,1)];
0313              end
0314 
0315              if ~isempty(selectedObjs)
0316                  ltpda_explorer(selectedObjs);
0317              else
0318                  ltpda_explorer(LTPDAinvar);
0319              end
0320 
0321              UpdateListbox();
0322          end
0323 
0324     end
0325     %----------------------------------------------------------------------
0326 
0327     %----------------------------------------------------------------------
0328     function SaveWorkspaceCallback(varargin)
0329     % Callback function: run when the user click the "Save all"
0330     % button
0331 
0332          try
0333              [FileName,PathName] = uiputfile('*.mat','Save Workspace As');
0334              if ~isa(FileName,'double'), save(strcat(PathName,FileName),'LTPDAinvar','LTPDAoutvar'); disp('Workspace saved'); end
0335          catch
0336          end
0337     end
0338     %----------------------------------------------------------------------
0339 
0340     %----------------------------------------------------------------------
0341     function LoadWorkspaceCallback(varargin)
0342     % Callback function: run when the user click the "Load workspace"
0343     % button
0344     
0345          try
0346              [FileName,PathName] = uigetfile('*.mat','Load Workspace');
0347              temp = load(strcat(PathName,FileName),'LTPDAinvar');
0348              LTPDAinvar = [LTPDAinvar ; temp.LTPDAinvar];
0349              temp = load(strcat(PathName,FileName),'LTPDAoutvar');
0350              LTPDAoutvar = [LTPDAoutvar ; temp.LTPDAoutvar];
0351              disp('Workspace loaded')
0352              clear temp
0353              UpdateListbox()
0354          catch
0355          end
0356     end
0357     %----------------------------------------------------------------------
0358 
0359 %%
0360     %----------------------------------------------------------------------
0361     function UpdateListbox(varargin)
0362     % Updates the listboxes
0363 
0364          %==================================
0365          % Update the list of active AOs
0366          xx = size(LTPDAinvar,1);
0367          listInput=cell(xx,1);
0368          if xx>0
0369              for j=1:xx
0370                  listInput{j,1} = num2str(j);
0371                  [rows,columns] = size(LTPDAinvar{j,1});
0372                  if (rows>1 && columns==1) || (rows==1 && columns>1), listInput{j,1} = [listInput{j,1}, ' .(Vector ',num2str(rows),'x',num2str(columns),') '];
0373                  elseif rows>1 && columns>1, listInput{j,1} = [listInput{j,1}, ' .(Matrix ',num2str(rows),'x',num2str(columns),') '];
0374                  end
0375                  switch class(LTPDAinvar{j,1})
0376                      case 'ao'
0377                          anobject  = LTPDAinvar{j,1};
0378                          aoname    = anobject.name;
0379                          aocreated = char(anobject.created);
0380                          listInput{j,1} = [listInput{j,1}, ' . AO .' , aoname , '__' , aocreated];
0381                      case 'plist'
0382                          paramNumb = nparams(LTPDAinvar{j,1});
0383                          objcreated = char(LTPDAinvar{j,1}.created);
0384                          listInput{j,1}=[listInput{j,1}, ' . PLIST .',num2str(paramNumb),' params','__',objcreated];
0385                      case 'specwin'
0386                          listInput{j,1}=[listInput{j,1}, ' . SPECWIN .','__','no creation time'];
0387                      case 'pzmodel'
0388                          objcreated = char(LTPDAinvar{j,1}.created);
0389                          listInput{j,1}=[listInput{j,1}, ' . PZMODEL .','__',objcreated];
0390                      case 'miir'
0391                          objcreated = char(LTPDAinvar{j,1}.created);
0392                          listInput{j,1}=[listInput{j,1}, ' . MIIR .','__',objcreated];
0393                      otherwise
0394                          if isa(LTPDAinvar{j,1},'ltpda_uo')
0395                              objclass  = class(LTPDAinvar{j,1});
0396                              if ~isempty(LTPDAinvar{j,1}), listInput{j,1}=[listInput{j,1}, ' . ',objclass]; end
0397                          end
0398                  end
0399              end
0400              for j=xx:-1:1
0401                  if isempty(listInput{j,1})
0402                      listInput(j,:)=[];
0403                  end                     
0404              end
0405          else
0406              listInput{1,1}='The memory is empty';
0407          end
0408          
0409          InputObjList = findobj('Tag','InputObjList');
0410          if ~isempty(InputObjList)
0411              set(InputObjList,'Value',1)
0412              set(InputObjList,'String',listInput)
0413          end
0414          
0415     end
0416     %----------------------------------------------------------------------
0417 
0418     %----------------------------------------------------------------------
0419     function hListObjsCallback(hObject, varargin)   
0420     % This callback is called whenever the user double click upon one of
0421     % the AOs in use.
0422     
0423         if ~isempty(varargin{1}) && varargin{1}==1 && size(LTPDAinvar,1)>0
0424                 val = get(hObject, 'Value');
0425                 if length(val) == 1
0426                     objLines = get(hObject, 'String');
0427                     if isempty(objLines) || isempty(LTPDAinvar{str2double(deblank(strtok(objLines{val}))) ,1})
0428                         objtxt = '';
0429                     else
0430                         objnumb = str2double(deblank(strtok(objLines{val})));
0431                         objtxt = display(LTPDAinvar{objnumb});
0432                     end
0433                 else
0434                     objtxt = '';
0435                 end
0436                 set(findobj('Tag', 'infoPanel'), 'String', objtxt)
0437         elseif size(LTPDAinvar,1)>0
0438             if strcmp(get(gcf,'SelectionType'),'normal')
0439                 val = get(hObject, 'Value');
0440                 if length(val) == 1
0441                     objLines = get(hObject, 'String');
0442                     objnumb = str2double(deblank(strtok(objLines{val})));
0443                     try
0444                         objtxt = display(LTPDAinvar{objnumb});
0445                     catch
0446                         objtxt = class(LTPDAinvar{objnumb});
0447                     end
0448                 else
0449                     objtxt = '';
0450                 end
0451                 set(findobj('Tag', 'infoPanel'), 'String', objtxt)
0452             end
0453 
0454             if strcmp(get(gcf,'SelectionType'),'open') && ~isempty(get(hObject, 'String')) && ~isempty(find_system(bdroot,'FindAll','on','Type','Annotation','Tag','ltpda model'))
0455                 set_param(utils.prog.gcbsh,'Selected','off');
0456                 newBlkHandle=add_block('ltpda_library/Input/Object from list', strcat(bdroot,'/AO1'),'MakeNameUnique', 'on');
0457                 children=get_param(newBlkHandle,'Blocks');
0458                 inputblock=strcat(get(newBlkHandle,'Path'),'/',get(newBlkHandle,'Name'),'/',children{1});
0459                 val = get(hObject, 'Value');
0460                 objLines = get(hObject, 'String');
0461                 number = deblank(strtok(objLines{val}));
0462                 set_param(inputblock,'Value',number );
0463               % Modify the block annotation:
0464                 objName = LTPDAinvar{str2double(number),1}.name;
0465                 if numel(objName)>3 && strcmpi(objName,'none'), objName = class(LTPDAinvar{str2double(number),1}); end
0466                 if numel(objName)>20, objName = ['...',LTPDAinvar{str2double(number),1}.name(end-20:end)]; end
0467                 set_param(newBlkHandle,'AttributesFormatString',[number,': ',objName]);
0468                 set_param(newBlkHandle,'Selected','on');
0469             end
0470         end
0471          
0472     end
0473     %----------------------------------------------------------------------
0474 
0475 %%
0476     %----------------------------------------------------------------------
0477     function hNewButtonCallback(varargin)
0478     % Callback function: run when the user click the "New model" button.
0479     % It starts also the timer associated to the continuous selection check
0480     % (this must be changed in order to allow multiple system execution).
0481 
0482          hour          = datestr(now,13); % HH:MM:SS
0483          hour(3)       = hour(4);hour(4)=hour(5);hour(5)=hour(7);hour(6)=hour(8);
0484          currentsystem = strcat(getappdata(0,'ltpda_repo_user'),'_',datestr(now,7),datestr(now,5),datestr(now,11),'_',hour(1:6));
0485          if ~isempty(find_system('Name',currentsystem)), return; end
0486          simulink
0487          new_system(currentsystem)
0488          open_system(currentsystem)
0489          
0490          systemHandle = get_param(gcs,'Handle');
0491          evalin('base','load ltpdaSimConfigSet.mat;');
0492          ltpdaSimConfigSet = evalin('base','ltpdaSimConfigSet');
0493          attachConfigSetCopy(systemHandle, ltpdaSimConfigSet);
0494          setActiveConfigSet(systemHandle, 'LTPDA');
0495          detachConfigSet(systemHandle, 'Configuration');
0496          evalin('base','clear ltpdaSimConfigSet;');
0497          
0498          set(systemHandle,'Location',[200 100 1100 600]);
0499          set(systemHandle,'Toolbar','OFF');
0500          
0501          caption = strcat(gcs,'/1');
0502          add_block('built-in/Note',caption,'Position', [100 0 0 400],'UserData',1);
0503          annotationHandle = find_system(gcs, 'FindAll', 'on', 'type', 'annotation');
0504          caption1 = ['          Analysis designed by ',getappdata(0,'ltpda_repo_user')];
0505        % caption1b = strcat('creator: ',char(java.lang.System.getProperties.getProperty('user.name')));
0506          caption2 = ['created (UTC): ',char(time)];
0507          caption3 = ['                 IP: ',char(getHostAddress(java.net.InetAddress.getLocalHost))];
0508          caption4 = ['               OS: ',computer];
0509          caption5 = ['MATLAB ver: ',getappdata(0, 'matlab_version')];
0510          caption6 = ['   LTPDA ver: ',getappdata(0, 'ltpda_version')];
0511          caption = strvcat(caption1,caption2,caption3,caption4,caption5,caption6); %#ok<VCAT>
0512          set_param(annotationHandle, 'HorizontalAlignment','left','Text',caption,'Tag','ltpda model')
0513          set_param(annotationHandle,'ClickFcn','disp(''You''''re not allowed to change this'')')
0514 
0515     end
0516     %----------------------------------------------------------------------
0517 
0518     %----------------------------------------------------------------------
0519     function hSaveCallback(varargin)   
0520     % This callback is called whenever the user click the 'Save' button to
0521     % store the current model on disk.
0522     
0523          if ~isempty(bdroot) && ~isempty(find_system(bdroot,'FindAll','on','Type','Annotation','Tag','ltpda model'))
0524              inputBlockHandles = get_param(find_system(bdroot,'AncestorBlock','ltpda_library/Input/Object from list'),'handle');
0525              for i=1:numel(inputBlockHandles)
0526                  children   = get_param(inputBlockHandles{i},'Blocks');
0527                  inputblock = strcat(get(inputBlockHandles{i},'Path'),'/',get(inputBlockHandles{i},'Name'),'/',children{1});
0528                  currIndex(i)  = str2double(get_param(inputblock,'Value'));
0529                  if currIndex(i)~=0
0530                      objcommand = string(LTPDAinvar{currIndex(i)});
0531                      set_param(inputBlockHandles{i},'Description',objcommand);
0532                  end
0533              end
0534 
0535              oldName  = bdroot;
0536              if ~isempty(oldName) && ~isempty(find_system(oldName,'FindAll','on','Type','Annotation','Tag','ltpda model'))
0537                  try
0538                      try cd(getappdata(0,'DefaultAnalysesDirectory')); catch end
0539                      [fileName,filePath] = uiputfile([oldName,'.mdl'],'Choose destination folder');
0540                      fileName = [filePath,fileName];
0541                      save_system(oldName,fileName)
0542                      try cd(getappdata(0,'DefaultDataDirectory')); catch end
0543                  catch
0544                  end
0545              end
0546          end
0547          
0548     end
0549     %----------------------------------------------------------------------
0550 
0551     %----------------------------------------------------------------------
0552     function hOpenCallback(varargin)   
0553     % This callback is called whenever the user click the 'Open' button, to
0554     % retrieve a previously saved model from disk.
0555     
0556          try
0557              try cd(getappdata(0,'DefaultAnalysesDirectory')); catch end
0558              [fileName,filePath] = uigetfile('.mdl','Choose source file');
0559              try cd(getappdata(0,'DefaultDataDirectory')); catch end
0560              fileName = [filePath,fileName];
0561              open_system(fileName)
0562              simulink
0563              
0564            % Load the globals into memory:
0565              globBlock = find_system(bdroot,'BlockType','SubSystem','Tag','globals');
0566              if ~isempty(globBlock), gl = get_param(globBlock{1},'UserData'); end
0567 
0568 
0569            % Update the indexes inside 'Object from list':
0570              inputBlockHandles = get_param(find_system(gcs,'AncestorBlock','ltpda_library/Input/Object from list'),'handle');
0571              for i=1:numel(inputBlockHandles)
0572                  objcommand = get_param(inputBlockHandles{i},'Description');
0573                  if ~isempty(objcommand)
0574                      xx         = size(LTPDAinvar,1);
0575                      objcommand = ['LTPDAinvar{',num2str(xx+1),',1}=',objcommand,';LTPDAinvar{',num2str(xx+1),',2}=0'];
0576                      eval(objcommand);
0577 
0578                      % Update the pointer inside the input block and the annotation:
0579                      children   = get_param(inputBlockHandles{i},'Blocks');
0580                      inputblock = strcat(get(inputBlockHandles{i},'Path'),'/',get(inputBlockHandles{i},'Name'),'/',children{1});
0581                      set_param(inputblock,'Value',num2str(xx+1))
0582                      set_param(inputBlockHandles{i},'AttributesFormatString',num2str(xx+1));
0583                  end
0584              end
0585              
0586              UpdateListbox()
0587          catch
0588          end
0589          
0590          
0591     end
0592     %----------------------------------------------------------------------
0593 
0594 %%
0595     %----------------------------------------------------------------------
0596     function StartExec(varargin)   
0597     % This callback is called whenever the user click the 'Start' button.
0598     
0599          if isempty(bdroot) || isempty(find_system(bdroot,'FindAll','on','Type','Annotation','Tag','ltpda model')), return; end
0600              
0601          disp('============================')
0602          disp('   Beginning the analysis')
0603          disp('============================')
0604          stop(timerfindall)
0605            button = findobj('Tag','StartButton');
0606            set(button,'CData',imread('startred.jpg'));
0607            drawnow
0608          progressBar();
0609          drawnow
0610          currSystem = bdroot;
0611             allBlocks = find_system(currSystem,'LookUnderMasks','all');
0612             for i=2:numel(allBlocks), set_param(allBlocks{i},'LinkStatus','inactive'); set_param(allBlocks{i},'MaskVariables',''); end
0613          addterms(currSystem)
0614          
0615        % Check if it's a partial execution:
0616          if ismember('executionList',evalin('base','who')), partialExecution = 1;
0617           % evalin('base','executionList')
0618          else partialExecution = 0;
0619          end
0620          
0621        % Clear the previous execution history:
0622          if ~partialExecution
0623             set_param(find_system(bdroot,'FindAll','on','Type','Annotation','Tag','ltpda model'),'UserData','');
0624          end
0625 
0626          
0627        % Set all objects present at the startup to be maintained:
0628          if size(LTPDAinvar,1)>0, LTPDAinvar(:,2) = {1}; end
0629 
0630        % Load the globals from the current model:
0631          globBlock = find_system(bdroot,'BlockType','SubSystem','Tag','globals');
0632          if ~isempty(globBlock), gl = get_param(globBlock{1},'UserData'); end
0633          
0634 %          if isempty(loopstatus) || loopstatus==0
0635 %              [ttt,xxx,yyy] = sim(gcs);
0636 %          end
0637 
0638 %        % Now the cycle to delete the objects produced in the analysis:
0639 %        % anobY=size(LTPDAinvar,1);
0640 %          for j=anobY:-1:1
0641 %              if LTPDAinvar{j,2}==0
0642 %                  LTPDAinvar(j,:)=[];
0643 %              end
0644 %          end
0645 
0646 % % % ==================================================================
0647 % % % Execution with nested loops
0648 % % % ==================================================================
0649 % % if loopstatus==1
0650 % %
0651 % % %   Example:      n  order    appearance
0652 % % %   paramLoop={    1   1  ...   x-------
0653 % % %                  2   2  ...    x------
0654 % % %                  3   3  ...     x-----
0655 % % %                  4   2  ...    x------
0656 % % %                  5   3  ...     x-----
0657 % % %                  6   1  ...   x-------
0658 % %
0659 % %
0660 % %     branches=[];
0661 % %     [xx,yy]=size(paramLoop);
0662 % %   % xx is the total number of parameters to change in loops.
0663 % %
0664 % %     for ii=1:xx
0665 % %         if ii==xx || paramLoop{ii+1,2}<=paramLoop{ii,2}
0666 % %             branches=[branches,ii];
0667 % %         end
0668 % %     end
0669 % %
0670 % %   % 'branches' contains the ordinal number of those rows which do not have
0671 % %   % a children row, ie. the following rows have higher order. In the
0672 % %   % example, branches = [ 3 , 5 , 6 ];
0673 % %
0674 % %     family={};
0675 % %     numbIter={};
0676 % %     for ii=1:numel(branches)
0677 % %         currOrder=paramLoop{branches(ii),2};
0678 % %         family{ii,1}  = 0;
0679 % %         numbIter{ii,1} = 1;
0680 % %         for jj=branches(ii):-1:1
0681 % %             if paramLoop{jj,2}==currOrder
0682 % %                 family{ii,currOrder+1}  = jj;
0683 % %                 family{ii,1}            = family{ii,1}+1;
0684 % %                 numbIter{ii,currOrder+1} = paramLoop{jj,6};
0685 % %                 numbIter{ii,1}           = numbIter{ii,1}*paramLoop{jj,6};
0686 % %                 currOrder               = paramLoop{jj,2}-1;
0687 % %             end
0688 % %         end
0689 % %     end
0690 % %   % 'family' contains all the parents information for each branch: the
0691 % %   % first column contains how many parents there are. In the example:
0692 % %   % family = {  3    1    2    3
0693 % %   %             3    1    4    5
0694 % %   %             1    6              }
0695 % %   % Similarly, numbIter contains the number of iteration necessary to
0696 % %   % complete each param. The first column contains the total for each
0697 % %   % branch/row.
0698 % %   % numbIter   = {  40   2    4    5
0699 % %   %                 36   2    6    3
0700 % %   %                 10   10             }
0701 % %
0702 % %     for ii=1:numel(branches)
0703 % %         x = family{ii,1}; % x = how many params to change in this branch
0704 % %         status=ones(1,x); % status shows the current step in the loop;
0705 % %                           % [2,3,5] means eg. that we've executed the 2nd
0706 % %                           % value for the first param, the 3rd for the
0707 % %                           % second param, and the 5th for the third param.
0708 % %
0709 % %         for iter=1:numbIter{ii,1}
0710 % %           % ==============================================================
0711 % %           % Here goes what must be executed
0712 % %           % ==============================================================
0713 % %
0714 % %             if x==1
0715 % %                 disp(sprintf('===== Current status is: ====== %d',status(1)));
0716 % %             elseif x==2
0717 % %                 disp(sprintf('===== Current status is: ====== %d %d',status(1),status(2)));
0718 % %             elseif x==3
0719 % %                 disp(sprintf('===== Current status is: ====== %d %d %d',status(1),status(2),status(3)));
0720 % %             end
0721 % %
0722 % %             for nn=1:numel(status)
0723 % %                 value=paramLoop{family{ii,nn+1},9}(status(nn));
0724 % %                 paramcommand = BuildCommand(value,family{ii,nn+1});
0725 % %                 set(paramLoop{family{ii,nn+1},3},'Description',paramcommand);
0726 % %             end
0727 % %
0728 
0729 try
0730     
0731 % ========================================================================
0732           % ==============================================================
0733           % ==============================================================
0734           % ==============================================================
0735                              [ttt,xxx,yyy] = sim(currSystem);  %#ok<NASGU>
0736           % ==============================================================
0737           % ==============================================================
0738           % ==============================================================
0739             
0740           % ==============================================================
0741 % ========================================================================
0742 % %             for jj=x:-1:1
0743 % %                 if status(jj)<numbIter{ii,jj+1} % then we still have to complete iterations on i-th row
0744 % %                     status(jj)=status(jj)+1;
0745 % %                     if jj~=x % if we've just increased a line which is not the last one, set to zero the lower lines
0746 % %                         for kk=jj+1:x
0747 % %                             status(kk)=1;
0748 % %                         end
0749 % %                     end
0750 % %                     break
0751 % %                 end
0752 % %             end
0753 % %         end
0754 % %     end
0755 % %
0756 % % end
0757 % % % ==================================================================
0758 % % % End of execution with nested loops
0759 % % % ==================================================================
0760 
0761     close(findobj('Name','LTPDA Progress Bar'))
0762     
0763   % Remove final results (intermediate were removed during analysis, as
0764   % soon as they become not useful anymore):
0765     if ~getappdata(0,'maintainresults') % && ~partialExecution
0766         for i=size(LTPDAinvar,1):-1:1
0767             if LTPDAinvar{i,2}==0
0768                LTPDAinvar(i,:)=[];
0769              % Update the execution history:
0770                ltpda_annotation = find_system(bdroot,'FindAll','on','Type','Annotation','Tag','ltpda model');
0771                execHistory = get_param(ltpda_annotation,'UserData');
0772                for xx=1:size(execHistory,1)
0773                   for yy=3:size(execHistory,2),
0774                      if execHistory{xx,yy} == i, execHistory{xx,yy} = -1; end
0775                      if execHistory{xx,yy} > i, execHistory{xx,yy} = execHistory{xx,yy}-1; end
0776                   end
0777                   if execHistory{xx,1} == i, execHistory{xx,1} = -1; end
0778                   if execHistory{xx,1} > i, execHistory{xx,1} = execHistory{xx,1}-1; end
0779                end
0780                set_param(ltpda_annotation,'UserData',execHistory);
0781             
0782             end                
0783         end
0784     end
0785     
0786     
0787   % Reshape the results:
0788 %     for i = size(LTPDAinvar,1):-1:1
0789 %         objLength = numel(LTPDAinvar{i,1});
0790 %         if objLength > 1 && isa(LTPDAinvar{i,1},'ltpda_uo')
0791 %           % Create empty rows beneath:
0792 %             if i~=size(LTPDAinvar,1) % ie, it's not the last row
0793 %               % Copy down elements:
0794 %                 for k = (size(LTPDAinvar,1)+objLength-1):-1:(i+objLength)
0795 %                     LTPDAinvar{k,1} = LTPDAinvar{k-objLength+1,1};
0796 %                     LTPDAinvar{k,2} = LTPDAinvar{k-objLength+1,2};
0797 %                 end
0798 %               % Free copied rows:
0799 %                 for k = i+1:i+objLength-1
0800 %                     LTPDAinvar(k,:) = {[],0};
0801 %                 end
0802 %             end
0803 %           % Relocate vector elements:
0804 %             for j = objLength:-1:1
0805 %                 LTPDAinvar{i+j-1,1} = LTPDAinvar{i,1}(j);
0806 %                 LTPDAinvar{i+j-1,2} = LTPDAinvar{i,2};
0807 %             end
0808 %         end
0809 %     end
0810     UpdateListbox();
0811     button = findobj('Tag','StartButton');
0812     set(button,'CData',imread('startgreen.jpg'));
0813     evalin('base','clear executionList');
0814     disp('============================')
0815     disp('     Analysis concluded')
0816     disp('============================')
0817     start(timerfindall)
0818     
0819 % ==================================
0820 catch ME
0821 % ==================================
0822     
0823   % Remove intermediate results:
0824     keepRes = getappdata(0,'maintainresults');
0825     if ~keepRes
0826         for i=size(LTPDAinvar,1):-1:1
0827             if LTPDAinvar{i,2}==0, LTPDAinvar(i,:)=[]; end                
0828         end
0829     end
0830 % % %   % Reshape the results:
0831 % % %     allclasses = utils.helper.ltpda_classes;
0832 % % %     for i = size(LTPDAinvar,1):-1:1
0833 % % %         objLength = numel(LTPDAinvar{i,1});
0834 % % %         if objLength > 1 && isa(LTPDAinvar{j,1},'ltpda_uo')
0835 % % %           % Create empty rows beneath:
0836 % % %             if i~=size(LTPDAinvar,1) % ie, it's not the last row
0837 % % %               % Copy down elements:
0838 % % %                 for k = (size(LTPDAinvar,1)+objLength-1):-1:(i+objLength)
0839 % % %                     LTPDAinvar{k,1} = LTPDAinvar{k-objLength+1,1};
0840 % % %                     LTPDAinvar{k,2} = LTPDAinvar{k-objLength+1,2};
0841 % % %                 end
0842 % % %               % Free copied rows:
0843 % % %                 for k = i+1:i+objLength-1
0844 % % %                     LTPDAinvar(k,:) = {[],0};
0845 % % %                 end
0846 % % %             end
0847 % % %           % Relocate vector elements:
0848 % % %             for j = objLength:-1:1
0849 % % %                 LTPDAinvar{i+j-1,1} = LTPDAinvar{i,1}(j);
0850 % % %                 LTPDAinvar{i+j-1,2} = LTPDAinvar{i,2};
0851 % % %             end
0852 % % %         end
0853 % % %     end
0854     UpdateListbox();
0855     button = findobj('Tag','StartButton');
0856     set(button,'CData',imread('startgreen.jpg'));
0857     start(timerfindall)
0858 
0859     rethrow(ME)
0860 end
0861 
0862     end
0863     %----------------------------------------------------------------------
0864 
0865 %%
0866 
0867 end  % end of ltpdagui

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