Home > m > gui > gltpda > ltpdagui.m

ltpdagui

PURPOSE ^

=========================================================================

SYNOPSIS ^

function ltpdagui(varargin)

DESCRIPTION ^

=========================================================================
                               LTPDA GUI
=========================================================================
 
  Open the tabbed main figure for the LTPDA GUI.

  $Id: ltpdagui.m,v 1.3 2008/03/04 05:00:52 nicola Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function ltpdagui(varargin)
0002 
0003 %=========================================================================
0004 %                               LTPDA GUI
0005 %=========================================================================
0006 %
0007 %  Open the tabbed main figure for the LTPDA GUI.
0008 %
0009 %  $Id: ltpdagui.m,v 1.3 2008/03/04 05:00:52 nicola Exp $
0010 
0011 warning off all
0012 
0013 global ltpdaGUIstatus LTPDAinvar LTPDAoutvar
0014 
0015 if isempty(LTPDAinvar),  LTPDAinvar  = {}; end
0016 if isempty(LTPDAoutvar), LTPDAoutvar = {}; end
0017 
0018 userID = getappdata(0,'ltpda_repo_user');
0019   if isempty(userID), userID = ''; end
0020 passwd = getappdata(0,'ltpda_repo_pass');
0021   if isempty(passwd), passwd = ''; end
0022 
0023 if nargin==0, [userID passwd] = loginLTPDA(userID,''); end
0024   if isempty(userID), userID = 'JohnDoe'; passwd=''; end
0025 
0026 ltpdaGUIstatus{1,1} = userID;
0027 setappdata(0,'ltpda_repo_user',userID)
0028 setappdata(0,'ltpda_repo_pass',passwd)
0029 
0030 if nargin==0
0031     clc
0032     disp('Please wait: starting LTPDA GUI...')
0033     disp('Loading Simulink...')
0034     pause(0.01);
0035     load_system('simulink')
0036      % Creator name
0037     ltpdaGUIstatus{2,1} = {}; % Panel handle
0038     ltpdaGUIstatus{3,1} = {}; % Current selection
0039      % {currTabName,currAnalysis,currBlock, ... }
0040     ltpdaGUIstatus{4,1} = {}; % Analysis names
0041      % {analisysName1 ; analisysName2 ; ... }
0042     ltpdaGUIstatus{5,1} = {}; % Objects arrays
0043      % {Obj1 ; Obj2 ; Obj3 ; ...}
0044     ltpdaGUIstatus{6,1} = {}; % Results arrays
0045      % {ResultObj1 ; ResultObj2 ; ... }
0046     ltpdaGUIstatus{7,1} = {}; % Loop status
0047      % { 1 , paramLoop1;
0048      %   0 , paramLoop2;
0049      %   1 , paramLoop3; ...}
0050 end
0051 
0052 try stop(timerfindall); delete(timerfindall); catch end
0053 t1 = timer('TimerFcn',@CheckTimerAlive,'ExecutionMode','fixedRate','Period',0.3);
0054 t2 = timer('TimerFcn',@CheckTimerAlive,'ExecutionMode','fixedRate','Period',1);
0055 start(t1)
0056 start(t2)
0057 
0058 %%
0059 
0060 tag = '';
0061 tabbedFigName = 'In GUI we trust';
0062 units = 'normalized';
0063 position = [0,0,1,1];
0064 
0065 % text color in the label:
0066   foregroundcolor = [0.2,0.2,0.2];
0067 % color in the background, behind tabs:
0068   backgroundcolor = [0.7,0.7,1];
0069 % background color, inside every tab:
0070   panelbackgroundcolor = [0.98,0.98,0.98];
0071 % color of the small highlight line, above the selected tab
0072   titlehighlightcolor = [1,0.3,0];
0073 
0074 horizontalalignment = 'center';
0075 
0076 active = 0;
0077 string = {'Main LTPDA panel','Output';'Parameters','Nested loops';'Repository','Import from workspace'};
0078    nrows = size(string,1);
0079    if nrows>1
0080        for nn=1:nrows, labels{nn} = string(nn,:); end
0081        string = string(1,:);
0082    end
0083    ntab = numel(string);
0084    for jj=ntab:-1:1, ntab = ntab - strcmp(string(jj),''); end
0085    
0086 % Cycle to retrieve parameters from the user:
0087   for mm=1:2:nargin
0088       property = lower(varargin{mm});
0089       value = varargin{mm+1};
0090       switch property
0091           case {'title','string'}
0092               string = value;
0093               nrows = size(string,1);
0094               if nrows>1
0095                   for nn=1:nrows, labels{nn} = string(nn,:);end
0096                   string = string(1,:);
0097               end
0098               ntab = numel(string);
0099               for jj=ntab:-1:1, ntab = ntab - strcmp(string(jj),''); end
0100           case {'frameposition','position'}
0101               position = value;
0102           case {'framebackgroundcolor','backgroundcolor'}
0103               backgroundcolor = value;
0104           case {'framebordertype','bordertype'}
0105               bordertype = value;
0106           case {'titleforegroundcolor','foregroundcolor'}
0107               foregroundcolor = value;
0108           case {'selecteditem','active'}
0109               active = value;
0110           case 'redraw'
0111               if value == 1 % main panel
0112                   TopBottomTabCbk([],[],1,1)
0113                   active = 1;
0114                   return
0115               end
0116               if value == 1.1 % the user clicked the Start button
0117                   TopBottomTabCbk([],[],1,1)
0118                   active = 1;
0119                   runSim = 1;
0120               end
0121               if value == 2 % Parameters panel
0122                   TopBottomTabCbk([],[],1,2)
0123                   active = 1;
0124                   return
0125               end
0126           otherwise
0127               eval([property '= value;']);
0128       end
0129   end
0130 
0131 parent   = findobj('Name',tabbedFigName);
0132 if ~isempty(parent), clf(parent);
0133 else parent = figure('Position',[100,50,800,550],'Name',tabbedFigName,'Resize','off','NumberTitle','off','Toolbar','none','Menubar','none');
0134 end
0135 set(parent,'Tag','LTPDAGUI','NextPlot','new');
0136 set(parent,'CloseRequestFcn','disp(''Closing LTPDA GUI...'');delete(timerfindall); clear global LTPDAinvar LTPDAoutvar ltpdaGUIstatus; setappdata(0,''ltpda_repo_user'',''''); setappdata(0,''ltpda_repo_pass'',''''); closereq')
0137 
0138 if ~exist('margins','var'), margins = {1,'pixels'}; end
0139 if ~iscell(margins), margins = {margins,units}; end
0140 if ~exist('bordertype','var'), bordertype = 'none'; end
0141 if ~exist('titlebackgroundcolor','var'), titlebackgroundcolor = 0.95*panelbackgroundcolor; end
0142 if ~active, active = 1; end
0143 
0144 htab = uipanel( ...
0145   'Parent',parent, ...
0146   'Units',units, ...
0147   'Position',position, ...
0148   'BackgroundColor',backgroundcolor, ...
0149   'BorderType',bordertype, ...
0150   'Visible','on', ...
0151   'Tag',tag);
0152 
0153   set(htab,'Units','pixels');
0154   tabpos = get(htab,'Position');
0155 
0156 status = uicontainer( ...
0157   'Parent',htab, ...
0158   'BackgroundColor',backgroundcolor, ...
0159   'Units',margins{2}, ...
0160   'Position',[1,1,1,1], ...
0161   'Visible','off');
0162 
0163   set(status,'Units','pixels');
0164   charsz = get(status,'Position');
0165 
0166 margins = [charsz(1:2),charsz(1:2)].*margins{1};
0167 set(status,'Units','characters');
0168 set(status,'Position',[1,1,1,1]);
0169 set(status,'Units','pixels');
0170 charsz = get(status,'Position');
0171 titleheight = 1.5*charsz(4);
0172 
0173 margins(3:4) = -(margins(1:2)+margins(3:4));
0174 [loop,sign] = deal(1:ntab,[1,ntab,1,0]);
0175 
0176 addtitle = 2*[sign(3:4),-1,-1];
0177 ttextpos = [0.05,0.08,0.9,0.76];
0178     
0179   for kk=1:ntab
0180     title(kk) = uipanel( ...
0181       'Parent',htab, ...
0182       'Units','pixels', ...
0183       'BackgroundColor',titlebackgroundcolor, ...
0184       'BorderType','beveledout', ...
0185       'ButtonDownFcn',{@TopBottomTabCbk,kk,1}, ...
0186       'Visible','on');
0187 
0188     ttext(kk) = uicontrol( ...
0189       'Parent',title(kk), ...
0190       'Units','normalized', ...
0191       'Position',ttextpos, ...
0192       'ForegroundColor',foregroundcolor, ...
0193       'BackgroundColor',titlebackgroundcolor, ...
0194       'HorizontalAlignment',horizontalalignment, ...
0195       'Style','text', ...
0196       'String',string{kk}, ...
0197       'Enable','inactive', ...
0198       'HitTest','off',...
0199       'Visible','on');
0200 
0201   end
0202   set(htab,'Units','pixels');
0203   dimension = get(htab,'Position');
0204   dimension(4) = dimension(4)-nrows*20+5;
0205   panel = uipanel( ...
0206       'Parent',htab, ...
0207       'Units','pixels', ...
0208       'Position',dimension,...
0209       'BackgroundColor',panelbackgroundcolor, ...
0210       'BorderType','beveledout', ...
0211       'Visible','on');
0212   
0213   ltpdaGUIstatus{2,1} = panel;
0214   
0215   dimension = get(htab,'Position');
0216   logosize = [53,50];
0217   dimension = [dimension(3)-logosize(1)+1 , dimension(4)-logosize(2) , logosize];
0218   logo = axes('Parent',htab,'Units','pixels','Position',dimension);
0219   image(imread('ltp.jpg'),'Parent',logo,'AlphaData',imread('ltpalpha.gif'));
0220   axis off; axis square;
0221 
0222   dimension = get(parent,'Position');
0223   logosize = [36 38];
0224   dimension = [dimension(3)-logosize(1)-70 , dimension(4)-logosize(2)-9 , logosize];
0225   logo = axes('Parent',parent,'Units','pixels','Position',dimension);
0226   image(imread('startgreen.jpg'),'Parent',logo,'AlphaData',imread('startalpha.gif'),'ButtonDownFcn','ltpdagui(''redraw'',1.1);','Tag','StartButton2');
0227   axis off;
0228   
0229   if active>ntab, active=ntab; end
0230   
0231   inset(1) = uicontrol( ...
0232     'Parent',htab, ...
0233     'Units','pixels', ...
0234     'BackgroundColor',panelbackgroundcolor, ...
0235     'Style','text', ...
0236     'Visible','on');
0237   if ~isnan(titlehighlightcolor)
0238     inset(2) = uicontrol( ...
0239       'Parent',htab, ...
0240       'Units','pixels', ...
0241       'BackgroundColor',titlehighlightcolor, ...
0242       'Style','text', ...
0243       'Visible','on');
0244     inset(3) = uicontrol( ...
0245       'Parent',htab, ...
0246       'Units','pixels', ...
0247       'BackgroundColor',0.85*titlehighlightcolor, ...
0248       'Style','text', ...
0249       'Visible','on');
0250   end
0251   
0252 % =======================================================================
0253 %                             OTHER BUTTONS
0254   for xx=2:nrows
0255       localString = labels{xx};
0256       ntab = numel(localString);
0257       for tt=1:ntab
0258         titles(xx,tt) = uipanel( ...
0259           'Parent',htab, ...
0260           'Units','pixels', ...
0261           'BackgroundColor',titlebackgroundcolor, ...
0262           'BorderType','beveledout', ...
0263           'ButtonDownFcn',{@TopBottomTabCbk,tt,xx}, ...
0264           'Visible','on');
0265 
0266         ttexts(xx,tt) = uicontrol( ...
0267           'Parent',titles(xx,tt), ...
0268           'Units','normalized', ...
0269           'Position',ttextpos, ...
0270           'ForegroundColor',foregroundcolor, ...
0271           'BackgroundColor',titlebackgroundcolor, ...
0272           'HorizontalAlignment',horizontalalignment, ...
0273           'Style','text', ...
0274           'String',localString{tt}, ...
0275           'Enable','inactive', ...
0276           'HitTest','off',...
0277           'Visible','on');
0278      end
0279   end
0280 % =======================================================================
0281 
0282   TopBottomTabResizeCbk();
0283 
0284 panelTitle = get(ttext(active),'string');
0285 panelDimens = get(panel, 'Position');
0286   setappdata(0, 'ltpda_currPanel', panel);
0287   setappdata(0, 'ltpda_currPanelDimens', panelDimens);
0288 
0289 % =======================================================================
0290 % =======================================================================
0291 % =======================================================================
0292 CheckTimerAlive()
0293 switch panelTitle
0294     case 'Main LTPDA panel'
0295         if exist('runSim','var') && runSim==1
0296             runSim = 0;
0297             pan1main(panel,1)
0298         else pan1main(panel)
0299         end
0300     case 'Output'
0301         pan5output(panel)
0302     case 'Parameters'
0303         pan2param(panel)
0304     case 'Nested loops'
0305         panXyettocome(panel)
0306       % pan3nested(panel)
0307     case 'Repository'
0308       % pan4repo(panel)
0309     case 'Import from workspace'
0310         pan4import(panel)
0311 end
0312 % =======================================================================
0313 % =======================================================================
0314 % =======================================================================
0315 
0316 
0317 %%
0318     %--------------------------------------------------------------------------
0319     function TopBottomTabCbk(hobj,evdt,indx,numbrow)
0320       
0321     if numbrow>1 % the user clicked on another row
0322         for pp=ntab:-1:1, ntab = ntab - strcmp(string(pp),''); end
0323         if ntab==1, active=1; end
0324 
0325       % Swop rows:
0326         temp = labels(1);
0327         labels(1) = labels(numbrow);
0328         labels(numbrow) = temp;
0329         clear temp
0330       % Rebuild the proper list:
0331         for ii=1:nrows
0332             temp(ii,1:numel(labels{ii}))=labels{ii};
0333         end
0334     else
0335         active = indx;
0336         for ii=1:nrows
0337             temp(ii,1:numel(labels{ii}))=labels{ii};
0338         end
0339     end
0340     
0341   % ======================================
0342     ltpdagui('title',temp,'active',indx);
0343   % ======================================
0344 
0345     end
0346     %--------------------------------------------------------------------------
0347 
0348      %--------------------------------------------------------------------------
0349      function TopBottomTabResizeCbk(varargin)
0350 
0351     units = get(htab,'Units');
0352     set(htab,'Units','pixels');
0353     tabpos = get(htab,'Position');
0354     tabpos(3) = tabpos(3)*0.85;
0355     set(htab,'Units',units);
0356     ntab = numel(string);
0357     for oo=ntab:-1:1, ntab = ntab - strcmp(string(oo),''); end
0358 
0359     titlepos = [0,0,0,titleheight];
0360     panelpos = [0,0,tabpos(3),tabpos(4)-titleheight]+margins;
0361     titlepos(2) = panelpos(2)+panelpos(4);
0362     panelpos(2) = panelpos(2)-titleheight*(nrows-1)+6;
0363   % set(panel,'Position',dimension);
0364     
0365     n = sum(cellfun('length',string))+2*ntab;
0366     titlepos(1) = panelpos(1)+(1-sign(3))*panelpos(3);
0367     upperpos = titlepos(2);
0368     for k=loop
0369         titlepos(3) = panelpos(3)*(length(string{k})+2)/n;
0370         addtopos = addtitle.*[k==1,1,k==1|k==ntab,1];
0371         titlepos(1) = titlepos(1)-(1-sign(3))*titlepos(3);
0372         titlepos(2) = upperpos - titlepos(4)*(nrows-1)+3;
0373         set(title(k),'Position',titlepos+addtopos);
0374         titlepos(1) = titlepos(1)+sign(3)*titlepos(3);
0375     end
0376     
0377   % =======================================================================
0378 
0379     if nrows>1
0380         for xxx=2:nrows
0381             localString = labels{xxx};
0382             ntab = numel(localString);
0383             for i=ntab:-1:1, ntab = ntab - strcmp(localString(i),''); end
0384             n = sum(cellfun('length',localString))+2*ntab;
0385             titlepos(1) = panelpos(1)+(1-sign(3))*panelpos(3);
0386             titlepos(2) = titlepos(2) + titlepos(4)-2;
0387             for k=1:ntab
0388                 titlepos(3) = panelpos(3)*(length(localString{k})+2)/n;
0389                 addtopos = addtitle.*[k==1,1,k==1|k==ntab,1];
0390                 titlepos(1) = titlepos(1)-(1-sign(3))*titlepos(3);
0391                 if ntab==1, titlepos(3)=titlepos(3)-2; end
0392                 set(titles(xxx,k),'Position',titlepos+addtopos);
0393                 titlepos(1) = titlepos(1)+sign(3)*titlepos(3);
0394             end
0395             if ntab<numel(localString)
0396                 for qq=ntab+1:numel(localString)
0397                     nullpos=[0,0,1,1];
0398                     set(titles(xxx,qq),'Position',nullpos);
0399                 end
0400             end
0401         end
0402     end
0403   
0404   % =======================================================================
0405 
0406     titlepos = get(title(active),'Position');
0407     titlepos = titlepos-addtitle.*[active==sign(1),1,active==sign(1),1];
0408     titlepos(3) = titlepos(3)-addtitle(3)*(active==sign(2));
0409     ntab = numel(string);
0410     for i=ntab:-1:1, ntab = ntab - strcmp(string(i),''); end
0411     if ntab==1, titlepos(3) = titlepos(3)-4; end
0412     
0413     set(title(active),'Position',titlepos,'BackgroundColor',panelbackgroundcolor);
0414     set(ttext(active),'FontWeight','bold','BackgroundColor',panelbackgroundcolor);
0415 
0416     insetpos = [titlepos(1)+1,titlepos(2)+sign(4)*titlepos(4)-2,titlepos(3)-1,3];
0417     set(inset(1),'Position',insetpos);
0418     try
0419       insetpos = insetpos+[0,(1-2*sign(4))*titleheight+2*sign(4),0,-2];
0420       set(inset(2),'Position',insetpos);
0421       set(inset(3),'Position',insetpos+[2,1-2*sign(4),-4,0]);
0422     catch
0423     end
0424      end
0425      %--------------------------------------------------------------------------
0426 
0427 %%
0428     %----------------------------------------------------------------------
0429     function CheckTimerAlive(varargin)   
0430         % This is the function to execute a continuous timer check
0431         
0432         % Keep alive the first timer:
0433           alltimers = timerfindall;
0434           if strcmp(get(alltimers(1),'Running'),'off')
0435               start(alltimers(1))
0436           end
0437     end
0438     %----------------------------------------------------------------------
0439 
0440 %%
0441 end

Generated on Fri 07-Mar-2008 15:46:43 by m2html © 2003