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 varargout = 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.20 2008/03/27 16:41:28 nicola Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = 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.20 2008/03/27 16:41:28 nicola Exp $
0007 
0008 global ltpdaGUIstatus LTPDAinvar LTPDAoutvar currentsystem % temp loopstatus
0009 
0010 % Initialize the list of AOs:
0011 InputObjList=''; OutputObjList='';
0012 UpdateListbox();
0013 
0014 alltimers = timerfindall;
0015 stop(alltimers(2));
0016 set(alltimers(2),'TimerFcn',@ContinuousCheck,'Period',1);
0017 start(alltimers(2));
0018 
0019 % Since the LTPDA Toolbox is now part of the Simulink Library, instead of
0020 % opening its window (which would require to open other minor windows to
0021 % access the single blocks) now the GUI will automatically open the
0022 % Simulink Library, which can be browsed more efficiently:
0023 
0024 % simulink    % commented just for debug phase, to be uncommented in the
0025               % final release
0026 
0027 %%
0028 
0029 currPanel   = varargin{1};
0030 if nargin>1, runSim = varargin{2}; else runSim = 0; end
0031 panelDimens = get(currPanel, 'Position');
0032 backColor   = get(currPanel, 'BackgroundColor');
0033 
0034                     uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[30 panelDimens(4)-52 60 30],'String','Username:','FontName','Times New Roman','FontSize',9,'FontWeight','normal','Visible','on','Style','text');
0035   hUserIDEdit   =   uicontrol('Parent',currPanel,'BackgroundColor',[0.9,0.9,0.9],'Units','pixels','HorizontalAlignment','center','Position',[95 panelDimens(4)-39 80 25],'String',ltpdaGUIstatus{1,1},'FontSize',8,'FontAngle','italic','Visible','on','Enable','off','Callback',@UserIDCallback,'Style','edit');
0036                     uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[190 panelDimens(4)-36 120 20],'String','Login / Logout','FontSize',8,'Visible','on','Enable','on','Callback',@LogoutCallback,'Style','pushbutton');
0037                     
0038                     uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[400 panelDimens(4)-42 100 20],'String','Current system:','FontName','Times New Roman','FontSize',9,'FontWeight','normal','Visible','on','Style','text');
0039   currsystem = bdroot;
0040   if isempty(currsystem) || isempty(find_system(currsystem,'FindAll','on','Type','Annotation','Tag','ltpda model')), currsystem = 'None'; end
0041                     uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[510 panelDimens(4)-42 150 20],'String',currsystem,'FontName','Times New Roman','FontSize',9,'FontWeight','normal','Visible','on','UserData','currsystem','Style','text');
0042 
0043 
0044     AnalysPanPos   = [20 panelDimens(4)-100 panelDimens(3)-40 55];
0045 
0046 uipanel('Title','Analyses Control Panel','BackgroundColor',backColor,'FontSize',7,'Units','pixels','Position',AnalysPanPos);
0047 
0048     nbuttons    = 3;
0049     buttonWidth = (AnalysPanPos(3)-10*(nbuttons+1))/nbuttons;
0050     buttonPos   = [AnalysPanPos(1)+10 AnalysPanPos(2)+10 buttonWidth 25];
0051   hNewModelButton = uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','New model','FontSize',8,'Visible','on','Enable','on','Callback',@hNewButtonCallback,'Style','pushbutton');
0052     buttonPos(1) = buttonPos(1)+buttonWidth+10;
0053   hOpenModelButton = uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Open model','FontSize',8,'Visible','on','Enable','on','Callback',@hOpenCallback,'Style','pushbutton');
0054     buttonPos(1) = buttonPos(1)+buttonWidth+10;
0055   hSaveModelButton = uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Save model','FontSize',8,'Visible','on','Enable','on','Callback',@hSaveCallback,'Style','pushbutton');
0056     clear AnalysPanPos nbuttons buttonWidth buttonPos
0057 
0058 
0059     DataPanPos   = [20 panelDimens(4)-415 panelDimens(3)-40 305];
0060   hDataPanel    =  uipanel(...
0061                       'Title','Data Control Panel',...
0062                       'BackgroundColor',[1,1,1],...
0063                       'FontSize',7,...
0064                       'Units','pixels',...
0065                       'Position',DataPanPos);
0066     nbuttons    = 5;
0067     buttonWidth = (DataPanPos(3)-10*(nbuttons+1))/nbuttons;
0068     buttonPos   = [10 DataPanPos(4)-40 buttonWidth 22];
0069   hLoadButton   =   uicontrol('Parent',hDataPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Load','FontSize',8,'Visible','on','Enable','on','Callback',@hLoadDataButtonCallback,'Style','pushbutton');
0070     buttonPos(1) = buttonPos(1)+buttonWidth+10;
0071   hCreateDataButton = uicontrol('Parent',hDataPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Create','FontSize',8,'Visible','on','Enable','off','UserData',InputObjList,'Callback',@hExploreButtonCallback,'Style','pushbutton');
0072     buttonPos(1) = buttonPos(1)+buttonWidth+10;
0073   hEditDataButton = uicontrol('Parent',hDataPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Edit','FontSize',8,'Visible','on','Enable','off','UserData',InputObjList,'Callback',@hExploreButtonCallback,'Style','pushbutton');
0074     buttonPos(1) = buttonPos(1)+buttonWidth+10;
0075   hRemoveButton =   uicontrol('Parent',hDataPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Remove','FontSize',8,'Visible','on','Enable','on','Callback',@hRemoveButtonCallback,'Style','pushbutton');
0076     buttonPos(1) = buttonPos(1)+buttonWidth+10;
0077   hExploreButton =  uicontrol('Parent',hDataPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Explore','FontSize',8,'Visible','on','Enable','on','UserData',InputObjList,'Callback',@hExploreButtonCallback,'Style','pushbutton');
0078     clear nbuttons buttonWidth buttonPos
0079 
0080     nbuttons    = 4;
0081     buttonWidth = (DataPanPos(3)-10*(nbuttons+1))/nbuttons;
0082     buttonPos   = [10 DataPanPos(4)-65 buttonWidth 22];
0083 %   hImportButton =   uicontrol('Parent',hDataPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Import','FontSize',8,'Visible','on','Enable','on','Callback',@hImportButtonCallback,'Style','pushbutton');
0084 %     buttonPos(1) = buttonPos(1)+buttonWidth+10;
0085   hExportButton =   uicontrol('Parent',hDataPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Export to workspace','FontSize',8,'Visible','on','Enable','on','Callback',@hExportButtonCallback,'Style','pushbutton');
0086     buttonPos(1) = buttonPos(1)+buttonWidth+10;
0087   hClearButton =   uicontrol('Parent',hDataPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Clear input','FontSize',8,'Visible','on','Enable','on','Callback',@hClearButtonCallback,'Style','pushbutton');
0088     buttonPos(1) = buttonPos(1)+buttonWidth+10;
0089   hSaveWorkButton =  uicontrol('Parent',hDataPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Save workspace','FontSize',8,'Visible','on','Enable','on','Callback',@SaveWorkspaceCallback,'Style','pushbutton');
0090     buttonPos(1) = buttonPos(1)+buttonWidth+10;
0091   hLoadWorkButton =  uicontrol('Parent',hDataPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Load workspace','FontSize',8,'Visible','on','Enable','on','Callback',@LoadWorkspaceCallback,'Style','pushbutton');
0092     clear nbuttons buttonWidth buttonPos
0093 
0094 
0095     ntexts    = 2;
0096     textWidth = (DataPanPos(3)-10*(ntexts+1))/ntexts;
0097     textPos   = [10 DataPanPos(4)-100 textWidth 25];
0098   hListAOText   =   uicontrol('Parent',hDataPanel,'BackgroundColor',get(hDataPanel,'BackgroundColor'),'HorizontalAlignment','center','Position',textPos,'String','Input:','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0099     clear ntexts textWidth textPos
0100 
0101 
0102     nlists    = 2;
0103     listWidth = (DataPanPos(3)-10*(nlists+1))/nlists;
0104     listPos   = [10 DataPanPos(4)-295 listWidth 200];
0105   InputObjList   = uicontrol('Parent',hDataPanel,'BackgroundColor',[0.95,0.95,0.95],'HorizontalAlignment','center','Position',listPos,'String',listInput,'Value',1,'Max',10,'Min',1,'FontSize',8,'FontWeight','normal','Visible','on','Enable','on','Callback',@hListObjsCallback,'Tag','InputObjList','Style','listbox');
0106     set(hExploreButton,'UserData',InputObjList);
0107     listPos(1) = listPos(1)+listWidth+10;
0108   % Info panel:
0109   uicontrol('Parent',hDataPanel,'BackgroundColor',[0.94,0.94,1],'Style','listbox','HorizontalAlignment', 'left','Fontsize', 8,'Units','pixels','Position',listPos,'Tag','infoPanel');
0110     hListObjsCallback(InputObjList,1);
0111     clear DataPanPos nlists listWidth listPos
0112     
0113     
0114   hExecutionPanel =  uipanel('Title','Execution control','BackgroundColor',[1,1,1],'FontSize',7,'Units','pixels','Position',[20 panelDimens(4)-485 panelDimens(3)-40 60]);
0115 
0116     if isempty(getappdata(0,'maintainresults')), setappdata(0,'maintainresults',0); end
0117   hKeepPrevData  = uicontrol('Parent',hExecutionPanel,'BackgroundColor',[1 1 1],'HorizontalAlignment','center','Position',[30 10 180 30],'Value',getappdata(0,'maintainresults'),'String',' Maintain intermediate results','ForeGroundColor','black','Visible','on','Enable','on','Callback',@MaintainResults,'Style','checkbox');
0118 
0119 % The execution of the analysis can be started using the common Start
0120 % button in the Simulink Window, but starting it from the GUI control panel
0121 % will offer a few more useful advantages, such as the autocompletion of
0122 % the model with terminators to the unconnected ports (to avoid useless
0123 % warnings). In case of programmed loop moreover it will be mandatory to
0124 % use the button in the GUI.
0125 
0126   hExecute        =   axes('Parent',findobj('Name','In GUI we trust'),'Units','pixels','Position',[panelDimens(3)-100 18 36 38]);
0127   image(imread('startgreen.jpg'),'Parent',hExecute,'AlphaData',imread('startalpha.gif'),'ButtonDownFcn',@StartExec,'Tag','StartButton1');
0128   axis(hExecute,'off');
0129  
0130 if runSim == 1, StartExec(); end
0131 
0132 %%
0133 % Define default output and return it if it is requested by users
0134 mOutputArgs{1} = currPanel;
0135 if nargout>0
0136     [varargout{1:nargout}] = mOutputArgs{:};
0137 end
0138 
0139 
0140 %%
0141 
0142 % ========================================================================
0143 % ========================================================================
0144 % ============================== FUNCTIONS ===============================
0145 % ========================================================================
0146 % ========================================================================
0147 
0148 %%
0149     %----------------------------------------------------------------------
0150     function ContinuousCheck(varargin)   
0151         % This is the function to execute a continuous timer check
0152         
0153        % Keep alive the first timer:
0154          alltimers = timerfindall;
0155          if strcmp(get(alltimers(1),'Running'),'off')
0156              start(alltimers(1))
0157          end
0158 
0159          currsys = bdroot;
0160          if ~isempty(currsys) && ~isempty(find_system(currsys,'FindAll','on','Type','Annotation','Tag','ltpda model'))
0161              set(findobj('UserData', 'currsystem'), 'String', currsys)
0162          else
0163              set(findobj('UserData', 'currsystem'), 'String', 'None')
0164          end
0165          
0166     end
0167     %----------------------------------------------------------------------
0168 
0169 %%
0170     %----------------------------------------------------------------------
0171     function UserIDCallback(hObject, varargin)   
0172     % Callback function: run when the user change the User ID
0173     
0174          if hObject~=-1
0175              ltpdaGUIstatus{1,1} = genvarname(get(hObject,'String'));
0176              set(hObject,'String',ltpdaGUIstatus{1,1});
0177          end
0178     end
0179     %----------------------------------------------------------------------
0180 
0181     %----------------------------------------------------------------------
0182     function LogoutCallback(varargin)
0183     % Callback function: run when the user click the "Logout" button
0184 
0185          setappdata(0,'ltpda_repo_pass','');
0186          userID = getappdata(0,'ltpda_repo_user');
0187          if isempty(userID), userID = ''; end
0188 
0189          [userID passwd] = loginLTPDA(userID,'');
0190          ltpdaGUIstatus{1,1} = userID;
0191          setappdata(0,'ltpda_repo_user',userID)
0192          setappdata(0,'ltpda_repo_pass',passwd)
0193 
0194          ltpdagui('Redraw',1);
0195          
0196     end
0197     %----------------------------------------------------------------------
0198 
0199 %%
0200     %----------------------------------------------------------------------
0201     function hLoadDataButtonCallback(varargin)   
0202     % Callback function: run when the user click the "Add data" button
0203     
0204          filenames = uipickfiles('REFilter','.txt');
0205          if ~isempty(filenames) && ~isnumeric(filenames(1,1))
0206              [x,y]=size(filenames);
0207              for j=1:y
0208                  ext = filenames{j}(numel(filenames{j})-2:numel(filenames{j}));
0209                  if strcmpi(ext,'xml')
0210                      try %#ok<ALIGN>
0211                          newObj = ltpda_xmlread(xmlread(filenames{j}));
0212                          if ltpda_isuserobject(newObj),
0213                              LTPDAinvar = [LTPDAinvar; {newObj,1} ];
0214                              disp('  + 1 Obj added to the global variable LTPDAinvar')
0215                          end
0216                      catch end
0217                  elseif strcmpi(ext,'mat')
0218                      varlist = whos('-file',filenames{j});
0219                      for k=1:numel(varlist)
0220                          newObj = load(filenames{j},varlist(k).name);
0221                          newObj = eval(['newObj.',varlist(k).name]);
0222                          if ltpda_isuserobject(newObj),
0223                              LTPDAinvar = [LTPDAinvar; {newObj,1} ];
0224                              disp('  + 1 Obj added to the global variable LTPDAinvar')
0225                          end
0226                      end
0227                  else
0228                      anobject={ao(filenames{j}),1};
0229                      LTPDAinvar=[LTPDAinvar;anobject];
0230                      disp('  + 1 AO added to the global variable LTPDAinvar')
0231                  end
0232              end
0233              UpdateListbox();
0234          end
0235     
0236     end
0237     %----------------------------------------------------------------------
0238 
0239     %----------------------------------------------------------------------
0240     function hRemoveButtonCallback(varargin)   
0241     % Callback function: run when the user click the "Remove data" button
0242 
0243            index_selected = get(InputObjList,'Value');
0244            listAOs = get(InputObjList,'String');
0245            if ~strcmp(listAOs,'The memory is empty')
0246                for i=1:numel(index_selected)
0247                    objSelect = str2double(strtok(listAOs{index_selected(i),1},'.'));
0248                    LTPDAinvar{objSelect,1} = [];
0249                end
0250                UpdateListbox();
0251            end
0252            set(findobj('Tag', 'infoPanel'), 'String', '')
0253 
0254     end
0255     %----------------------------------------------------------------------
0256 
0257     %----------------------------------------------------------------------
0258     function hExportButtonCallback(varargin)   
0259     % Callback function: run when the user click the "Remove data" button
0260 
0261          currSelObjs   = get(InputObjList,'Value');
0262          listAOs = get(InputObjList,'String');
0263          if ~strcmp(listAOs,'The memory is empty')
0264              selectedObjs  = {};
0265              for i=1:numel(currSelObjs)
0266                  objSelect = str2double(strtok(listAOs{currSelObjs(i),1},'.'));
0267                  selectedObjs = [selectedObjs,LTPDAinvar(objSelect,1)];
0268              end
0269              if ~isempty(selectedObjs)
0270                  for i=1:numel(selectedObjs)
0271                      objName = [class(selectedObjs{i}),'_',selectedObjs{i}.name];
0272                      objName = genvarname(objName,evalin('base','who'));
0273                      assignin('base', objName, selectedObjs{i});
0274                      disp(['Saved to workspace with name ',objName])
0275                  end
0276              end
0277          end
0278          
0279     end
0280     %----------------------------------------------------------------------
0281 
0282     %----------------------------------------------------------------------
0283     function hExploreButtonCallback(varargin)   
0284     % Callback function: run when the user click the "Update list" button
0285 
0286          currSelObjs   = get(InputObjList,'Value');
0287          listAOs = get(InputObjList,'String');
0288          if ~strcmp(listAOs,'The memory is empty')
0289              selectedObjs  = {};
0290              for i=1:numel(currSelObjs)
0291                  objSelect = str2double(strtok(listAOs{currSelObjs(i),1},'.'));
0292                  selectedObjs = [selectedObjs,LTPDAinvar(objSelect,1)];
0293              end
0294 
0295              if ~isempty(selectedObjs)
0296                  ltpda_explorer(selectedObjs);
0297              else
0298                  ltpda_explorer(LTPDAinvar);
0299              end
0300 
0301              UpdateListbox();
0302          end
0303 
0304     end
0305     %----------------------------------------------------------------------
0306 
0307     %----------------------------------------------------------------------
0308     function hClearButtonCallback(varargin)
0309     % Callback function: run when the user click the "Clear input"
0310     % button
0311 
0312          LTPDAinvar={};
0313        % LTPDAoutvar={};
0314          set(InputObjList,'Value',1)
0315          set(findobj('Tag', 'infoPanel'), 'String', '')
0316          UpdateListbox();
0317 
0318     end
0319     %----------------------------------------------------------------------
0320 
0321     %----------------------------------------------------------------------
0322     function SaveWorkspaceCallback(varargin)
0323     % Callback function: run when the user click the "Save all"
0324     % button
0325 
0326          try
0327              [FileName,PathName] = uiputfile('*.mat','Save Workspace As');
0328              if ~isa(FileName,'double'), save(strcat(PathName,FileName),'LTPDAinvar','LTPDAoutvar'); disp('Workspace saved'); end
0329          catch
0330          end
0331     end
0332     %----------------------------------------------------------------------
0333 
0334     %----------------------------------------------------------------------
0335     function LoadWorkspaceCallback(varargin)
0336     % Callback function: run when the user click the "Load workspace"
0337     % button
0338     
0339          try
0340              [FileName,PathName] = uigetfile('*.mat','Load Workspace');
0341              temp = load(strcat(PathName,FileName),'LTPDAinvar');
0342              LTPDAinvar = [LTPDAinvar ; temp.LTPDAinvar];
0343              temp = load(strcat(PathName,FileName),'LTPDAoutvar');
0344              LTPDAoutvar = [LTPDAoutvar ; temp.LTPDAoutvar];
0345              disp('Workspace loaded')
0346              clear temp
0347              UpdateListbox()
0348          catch
0349          end
0350     end
0351     %----------------------------------------------------------------------
0352 
0353 %%
0354     %----------------------------------------------------------------------
0355     function UpdateListbox(varargin)
0356     % Updates the listboxes
0357 
0358          %==================================
0359          % Update the list of active AOs
0360          xx = size(LTPDAinvar,1);
0361          listInput=cell(xx,1);
0362          if xx>0
0363              for j=1:xx
0364                  switch class(LTPDAinvar{j,1})
0365                      case 'ao'
0366                          anobject  = LTPDAinvar{j,1};
0367                          aoname    = anobject.name;
0368                          aocreated = get(get(anobject.provenance, 'created'),'time_str');
0369                          listInput{j,1} = [num2str(j) , ' . AO .' , aoname , '__' , aocreated];
0370                      case 'plist'
0371                          paramNumb = nparams(LTPDAinvar{j,1});
0372                          objcreated = get(LTPDAinvar{j,1}.created,'time_str');
0373                          listInput{j,1}=[num2str(j),' . PLIST .',num2str(paramNumb),' params','__',objcreated];
0374                      case 'specwin'
0375                          listInput{j,1}=[num2str(j),' . SPECWIN .','__','no creation time'];
0376                      case 'pzmodel'
0377                          objcreated = get(LTPDAinvar{j,1}.created,'time_str');
0378                          listInput{j,1}=[num2str(j),' . PZMODEL .','__',objcreated];
0379                      case 'miir'
0380                          objcreated = get(LTPDAinvar{j,1}.created,'time_str');
0381                          listInput{j,1}=[num2str(j),' . MIIR .','__',objcreated];
0382                      otherwise
0383                          if ltpda_isuserobject(LTPDAinvar{j,1})
0384                              objclass  = class(LTPDAinvar{j,1});
0385                              if ~isempty(LTPDAinvar{j,1}), listInput{j,1}=[num2str(j),' . ',objclass]; end
0386                          end
0387                  end
0388              end
0389              for j=xx:-1:1
0390                  if isempty(listInput{j,1})
0391                      listInput(j,:)=[];
0392                  end                     
0393              end
0394          else
0395              listInput{1,1}='The memory is empty';
0396          end
0397          
0398          InputObjList = findobj('Tag','InputObjList');
0399          if ~isempty(InputObjList)
0400              set(InputObjList,'Value',1)
0401              set(InputObjList,'String',listInput)
0402          end
0403          
0404     end
0405     %----------------------------------------------------------------------
0406 
0407     %----------------------------------------------------------------------
0408     function hListObjsCallback(hObject, varargin)   
0409     % This callback is called whenever the user double click upon one of
0410     % the AOs in use.
0411     
0412         if ~isempty(varargin{1}) && varargin{1}==1 && size(LTPDAinvar,1)>0
0413                 val = get(hObject, 'Value');
0414                 if length(val) == 1
0415                     objLines = get(hObject, 'String');
0416                     if isempty(objLines)
0417                         objtxt = '';
0418                     else
0419                         objnumb = str2double(deblank(strtok(objLines{val})));
0420                         objtxt = display(LTPDAinvar{objnumb});
0421                     end
0422                 else
0423                     objtxt = '';
0424                 end
0425                 set(findobj('Tag', 'infoPanel'), 'String', objtxt)
0426         elseif size(LTPDAinvar,1)>0
0427             if strcmp(get(gcf,'SelectionType'),'normal')
0428                 val = get(hObject, 'Value');
0429                 if length(val) == 1
0430                     objLines = get(hObject, 'String');
0431                     objnumb = str2double(deblank(strtok(objLines{val})));
0432                     try objtxt = display(LTPDAinvar{objnumb}); catch objtxt = class(LTPDAinvar{objnumb}); end
0433                 else
0434                     objtxt = '';
0435                 end
0436                 set(findobj('Tag', 'infoPanel'), 'String', objtxt)
0437             end
0438 
0439             if strcmp(get(gcf,'SelectionType'),'open') && ~isempty(get(hObject, 'String')) && ~isempty(find_system(bdroot,'FindAll','on','Type','Annotation','Tag','ltpda model'))
0440                 set_param(gcbsh,'Selected','off');
0441                 newBlkHandle=add_block('ltpda_library/Input/Object from list', strcat(bdroot,'/AO1'),'MakeNameUnique', 'on');
0442                 children=get_param(newBlkHandle,'Blocks');
0443                 inputblock=strcat(get(newBlkHandle,'Path'),'/',get(newBlkHandle,'Name'),'/',children{1});
0444                 val = get(hObject, 'Value');
0445                 objLines = get(hObject, 'String');
0446                 set_param(inputblock,'Value',deblank(strtok(objLines{val})) );
0447               % Modify the block annotation:
0448                 set_param(newBlkHandle,'AttributesFormatString',deblank(strtok(objLines{val})) );
0449                 set_param(newBlkHandle,'Selected','on');
0450             end
0451         end
0452          
0453     end
0454     %----------------------------------------------------------------------
0455 
0456 %%
0457     %----------------------------------------------------------------------
0458     function hNewButtonCallback(varargin)
0459     % Callback function: run when the user click the "New model" button.
0460     % It starts also the timer associated to the continuous selection check
0461     % (this must be changed in order to allow multiple system execution).
0462 
0463          hour          = datestr(now,13); % HH:MM:SS
0464          hour(3)       = hour(4);hour(4)=hour(5);hour(5)=hour(7);hour(6)=hour(8);
0465          currentsystem = strcat(ltpdaGUIstatus{1,1},'_',datestr(now,7),datestr(now,5),datestr(now,11),'_',hour(1:6));
0466          if ~isempty(find_system('Name',currentsystem)), return; end
0467          simulink
0468          new_system(currentsystem)
0469          open_system(currentsystem)
0470          
0471          systemHandle = get_param(gcs,'Handle');
0472          set(systemHandle,'SolverName','VariableStepDiscrete');
0473          set(systemHandle,'StopTime','0.0');
0474          set(systemHandle,'Location',[200 100 1100 600]);
0475          set(systemHandle,'Toolbar','OFF');
0476          
0477          caption = strcat(gcs,'/1');
0478          add_block('built-in/Note',caption,'Position', [100 0 0 400],'UserData',1);
0479          annotationHandle = find_system(gcs, 'FindAll', 'on', 'type', 'annotation');
0480          caption1 = ['          Analysis designed by ',ltpdaGUIstatus{1,1}];
0481        % caption1b = strcat('creator: ',char(java.lang.System.getProperties.getProperty('user.name')));
0482          caption2 = ['created (UTC): ',get(time,'time_str')];
0483          caption3 = ['                 IP: ',char(getHostAddress(java.net.InetAddress.getLocalHost))];
0484          caption4 = ['               OS: ',computer];
0485          caption5 = ['MATLAB ver: ',getappdata(0, 'matlab_version')];
0486          caption6 = ['   LTPDA ver: ',getappdata(0, 'ltpda_version')];
0487          caption = strvcat(caption1,caption2,caption3,caption4,caption5,caption6); %#ok<VCAT>
0488          set_param(annotationHandle, 'HorizontalAlignment','left','Text',caption,'Tag','ltpda model')
0489          set_param(annotationHandle,'ClickFcn','disp(''You''''re not allowed to change this'')')
0490 
0491     end
0492     %----------------------------------------------------------------------
0493 
0494     %----------------------------------------------------------------------
0495     function hSaveCallback(varargin)   
0496     % This callback is called whenever the user click the 'Save' button to
0497     % store the current model on disk.
0498     
0499          if ~isempty(bdroot) && ~isempty(find_system(bdroot,'FindAll','on','Type','Annotation','Tag','ltpda model'))
0500              inputBlockHandles = get_param(find_system(bdroot,'AncestorBlock','ltpda_library/Input/Object from list'),'handle');
0501              for i=1:numel(inputBlockHandles)
0502                  children   = get_param(inputBlockHandles{i},'Blocks');
0503                  inputblock = strcat(get(inputBlockHandles{i},'Path'),'/',get(inputBlockHandles{i},'Name'),'/',children{1});
0504                  currIndex(i)  = str2double(get_param(inputblock,'Value'));
0505                  if currIndex(i)~=0
0506                      objcommand = string(LTPDAinvar{currIndex(i)});
0507                      set_param(inputBlockHandles{i},'Description',objcommand);
0508                  end
0509              end
0510 
0511              oldName  = bdroot;
0512              if ~isempty(oldName) && ~isempty(find_system(oldName,'FindAll','on','Type','Annotation','Tag','ltpda model'))
0513                  try
0514                      try cd(getappdata(0,'DefaultAnalysesDirectory')); catch end
0515                      [fileName,filePath] = uiputfile([oldName,'.mdl'],'Choose destination folder');
0516                      fileName = [filePath,fileName];
0517                      save_system(oldName,fileName)
0518                      try cd(getappdata(0,'DefaultDataDirectory')); catch end
0519                  catch
0520                  end
0521              end
0522          end
0523          
0524     end
0525     %----------------------------------------------------------------------
0526 
0527     %----------------------------------------------------------------------
0528     function hOpenCallback(varargin)   
0529     % This callback is called whenever the user click the 'Open' button, to
0530     % retrieve a previously saved model from disk.
0531     
0532          try
0533              try cd(getappdata(0,'DefaultAnalysesDirectory')); catch end
0534              [fileName,filePath] = uigetfile('.mdl','Choose source file');
0535              try cd(getappdata(0,'DefaultDataDirectory')); catch end
0536              fileName = [filePath,fileName];
0537              open_system(fileName)
0538 
0539              inputBlockHandles = get_param(find_system(gcs,'AncestorBlock','ltpda_library/Input/Object from list'),'handle');
0540              for i=1:numel(inputBlockHandles)
0541                  objcommand = get_param(inputBlockHandles{i},'Description');
0542                  if ~isempty(objcommand)
0543                      xx         = size(LTPDAinvar,1);
0544                      objcommand = ['LTPDAinvar{',num2str(xx+1),',1}=',objcommand,';LTPDAinvar{',num2str(xx+1),',2}=0'];
0545                      eval(objcommand);
0546 
0547                      % Update the pointer inside the input block and the annotation:
0548                      children   = get_param(inputBlockHandles{i},'Blocks');
0549                      inputblock = strcat(get(inputBlockHandles{i},'Path'),'/',get(inputBlockHandles{i},'Name'),'/',children{1});
0550                      set_param(inputblock,'Value',num2str(xx+1))
0551                      set_param(inputBlockHandles{i},'AttributesFormatString',num2str(xx+1));
0552                  end
0553              end
0554              
0555              UpdateListbox()
0556          catch
0557          end
0558          
0559 %          currSelectObjs = get(InputObjList,'Value');
0560 %          try
0561 %              [fileName,filePath] = uiputfile([gcs,'.xml'],'Choose destination folder');
0562 %              for i=1:numel(currSelectObjs)
0563 %                  currAO = LTPDAinvar{currSelectObjs(i)};
0564 %                  currAO = attachmdl(currAO);
0565 %                  fileName = [filePath,'/',gcs,'_',num2str(i),'_',currAO.name,'.xml'];
0566 %                  save(currAO,fileName);
0567 %                  disp(sprintf('Object %s saved (with current Simulink model attached)',currAO.name))
0568 %              end
0569 %          catch
0570 %          end
0571          
0572     end
0573     %----------------------------------------------------------------------
0574 
0575 %%
0576     %----------------------------------------------------------------------
0577     function MaintainResults(hObject,varargin)   
0578     % This callback is called whenever the user check the 'Maintain
0579     % Results' box.
0580         setappdata(0,'maintainresults',get(hObject,'Value'));
0581     end
0582     %----------------------------------------------------------------------
0583 
0584     %----------------------------------------------------------------------
0585     function StartExec(varargin)   
0586     % This callback is called whenever the user click the 'Start' button.
0587     
0588          if isempty(bdroot) || isempty(find_system(bdroot,'FindAll','on','Type','Annotation','Tag','ltpda model')), return; end
0589              
0590          disp('============================')
0591          disp('   Beginning the analysis')
0592          disp('============================')
0593          stop(timerfindall)
0594            button = findobj('Tag','StartButton1');
0595            set(button,'CData',imread('startred.jpg'));
0596            button = findobj('Tag','StartButton2');
0597            set(button,'CData',imread('startred.jpg'));
0598          progressBar();
0599          pause(0.1);
0600          currSystem = bdroot;
0601          addterms(currSystem)
0602                   
0603 %          if isempty(loopstatus) || loopstatus==0
0604 %              [ttt,xxx,yyy] = sim(gcs);
0605 %          end
0606 
0607 %        % Now the cycle to delete the objects produced in the analysis:
0608 %        % anobY=size(LTPDAinvar,1);
0609 %          for j=anobY:-1:1
0610 %              if LTPDAinvar{j,2}==0
0611 %                  LTPDAinvar(j,:)=[];
0612 %              end
0613 %          end
0614 
0615 % % % ==================================================================
0616 % % % Execution with nested loops
0617 % % % ==================================================================
0618 % % if loopstatus==1
0619 % %
0620 % % %   Example:      n°  order    appearance
0621 % % %   paramLoop={    1   1  ...   x-------
0622 % % %                  2   2  ...    x------
0623 % % %                  3   3  ...     x-----
0624 % % %                  4   2  ...    x------
0625 % % %                  5   3  ...     x-----
0626 % % %                  6   1  ...   x-------
0627 % %
0628 % %
0629 % %     branches=[];
0630 % %     [xx,yy]=size(paramLoop);
0631 % %   % xx is the total number of parameters to change in loops.
0632 % %
0633 % %     for ii=1:xx
0634 % %         if ii==xx || paramLoop{ii+1,2}<=paramLoop{ii,2}
0635 % %             branches=[branches,ii];
0636 % %         end
0637 % %     end
0638 % %
0639 % %   % 'branches' contains the ordinal number of those rows which do not have
0640 % %   % a children row, ie. the following rows have higher order. In the
0641 % %   % example, branches = [ 3 , 5 , 6 ];
0642 % %
0643 % %     family={};
0644 % %     numbIter={};
0645 % %     for ii=1:numel(branches)
0646 % %         currOrder=paramLoop{branches(ii),2};
0647 % %         family{ii,1}  = 0;
0648 % %         numbIter{ii,1} = 1;
0649 % %         for jj=branches(ii):-1:1
0650 % %             if paramLoop{jj,2}==currOrder
0651 % %                 family{ii,currOrder+1}  = jj;
0652 % %                 family{ii,1}            = family{ii,1}+1;
0653 % %                 numbIter{ii,currOrder+1} = paramLoop{jj,6};
0654 % %                 numbIter{ii,1}           = numbIter{ii,1}*paramLoop{jj,6};
0655 % %                 currOrder               = paramLoop{jj,2}-1;
0656 % %             end
0657 % %         end
0658 % %     end
0659 % %   % 'family' contains all the parents information for each branch: the
0660 % %   % first column contains how many parents there are. In the example:
0661 % %   % family = {  3    1    2    3
0662 % %   %             3    1    4    5
0663 % %   %             1    6              }
0664 % %   % Similarly, numbIter contains the number of iteration necessary to
0665 % %   % complete each param. The first column contains the total for each
0666 % %   % branch/row.
0667 % %   % numbIter   = {  40   2    4    5
0668 % %   %                 36   2    6    3
0669 % %   %                 10   10             }
0670 % %
0671 % %     for ii=1:numel(branches)
0672 % %         x = family{ii,1}; % x = how many params to change in this branch
0673 % %         status=ones(1,x); % status shows the current step in the loop;
0674 % %                           % [2,3,5] means eg. that we've executed the 2nd
0675 % %                           % value for the first param, the 3rd for the
0676 % %                           % second param, and the 5th for the third param.
0677 % %
0678 % %         for iter=1:numbIter{ii,1}
0679 % %           % ==============================================================
0680 % %           % Here goes what must be executed
0681 % %           % ==============================================================
0682 % %
0683 % %             if x==1
0684 % %                 disp(sprintf('===== Current status is: ====== %d',status(1)));
0685 % %             elseif x==2
0686 % %                 disp(sprintf('===== Current status is: ====== %d %d',status(1),status(2)));
0687 % %             elseif x==3
0688 % %                 disp(sprintf('===== Current status is: ====== %d %d %d',status(1),status(2),status(3)));
0689 % %             end
0690 % %
0691 % %             for nn=1:numel(status)
0692 % %                 value=paramLoop{family{ii,nn+1},9}(status(nn));
0693 % %                 paramcommand = BuildCommand(value,family{ii,nn+1});
0694 % %                 set(paramLoop{family{ii,nn+1},3},'Description',paramcommand);
0695 % %             end
0696 % %
0697 
0698 try
0699     
0700 % ========================================================================
0701           % ==============================================================
0702           % ==============================================================
0703           % ==============================================================
0704                              [ttt,xxx,yyy] = sim(currSystem);  %#ok<NASGU>
0705           % ==============================================================
0706           % ==============================================================
0707           % ==============================================================
0708             
0709           % ==============================================================
0710 % ========================================================================
0711 % %             for jj=x:-1:1
0712 % %                 if status(jj)<numbIter{ii,jj+1} % then we still have to complete iterations on i-th row
0713 % %                     status(jj)=status(jj)+1;
0714 % %                     if jj~=x % if we've just increased a line which is not the last one, set to zero the lower lines
0715 % %                         for kk=jj+1:x
0716 % %                             status(kk)=1;
0717 % %                         end
0718 % %                     end
0719 % %                     break
0720 % %                 end
0721 % %             end
0722 % %         end
0723 % %     end
0724 % %
0725 % % end
0726 % % % ==================================================================
0727 % % % End of execution with nested loops
0728 % % % ==================================================================
0729 
0730     close(findobj('Name','LTPDA Progress Bar'))
0731     
0732   % Remove intermediate results:
0733     keepRes = getappdata(0,'maintainresults');
0734     if ~keepRes
0735         for i=size(LTPDAinvar,1):-1:1
0736             if LTPDAinvar{i,2}==0, LTPDAinvar(i,:)=[]; end                
0737         end
0738     end
0739 
0740   % Reshape the results:
0741     for i = size(LTPDAinvar,1):-1:1
0742         objLength = numel(LTPDAinvar{i,1});
0743         if objLength > 1 && ltpda_isuserobject(LTPDAinvar{i,1})
0744           % Create empty rows beneath:
0745             if i~=size(LTPDAinvar,1) % ie, it's not the last row
0746               % Copy down elements:
0747                 for k = (size(LTPDAinvar,1)+objLength-1):-1:(i+objLength)
0748                     LTPDAinvar{k,1} = LTPDAinvar{k-objLength+1,1};
0749                     LTPDAinvar{k,2} = LTPDAinvar{k-objLength+1,2};
0750                 end
0751               % Free copied rows:
0752                 for k = i+1:i+objLength-1
0753                     LTPDAinvar(k,:) = {[],0};
0754                 end
0755             end
0756           % Relocate vector elements:
0757             for j = objLength:-1:1
0758                 LTPDAinvar{i+j-1,1} = LTPDAinvar{i,1}(j);
0759                 LTPDAinvar{i+j-1,2} = LTPDAinvar{i,2};
0760             end
0761         end
0762     end
0763     UpdateListbox();
0764     button = findobj('Tag','StartButton1');
0765     set(button,'CData',imread('startgreen.jpg'));
0766     button = findobj('Tag','StartButton2');
0767     set(button,'CData',imread('startgreen.jpg'));
0768     start(timerfindall)
0769     
0770 % ==================================
0771 catch
0772 % ==================================
0773     
0774   % Reshape the results:
0775     for i = size(LTPDAinvar,1):-1:1
0776         objLength = numel(LTPDAinvar{i,1});
0777         if objLength > 1 && ltpda_isuserobject(LTPDAinvar{i,1})
0778           % Create empty rows beneath:
0779             if i~=size(LTPDAinvar,1) % ie, it's not the last row
0780               % Copy down elements:
0781                 for k = (size(LTPDAinvar,1)+objLength-1):-1:(i+objLength)
0782                     LTPDAinvar{k,1} = LTPDAinvar{k-objLength+1,1};
0783                     LTPDAinvar{k,2} = LTPDAinvar{k-objLength+1,2};
0784                 end
0785               % Free copied rows:
0786                 for k = i+1:i+objLength-1
0787                     LTPDAinvar(k,:) = {[],0};
0788                 end
0789             end
0790           % Relocate vector elements:
0791             for j = objLength:-1:1
0792                 LTPDAinvar{i+j-1,1} = LTPDAinvar{i,1}(j);
0793                 LTPDAinvar{i+j-1,2} = LTPDAinvar{i,2};
0794             end
0795         end
0796     end
0797     UpdateListbox();
0798     button = findobj('Tag','StartButton1');
0799     set(button,'CData',imread('startgreen.jpg'));
0800     button = findobj('Tag','StartButton2');
0801     set(button,'CData',imread('startgreen.jpg'));
0802     start(timerfindall)
0803 
0804     rethrow(lasterror)
0805 end
0806 
0807     end
0808     %----------------------------------------------------------------------
0809 
0810 %%
0811 
0812 end  % end of ltpdagui

Generated on Mon 31-Mar-2008 21:41:00 by m2html © 2003