Home > m > gui > gltpda > ltpdagui.m

ltpdagui

PURPOSE ^

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

SYNOPSIS ^

function ltpdagui(varargin)

DESCRIPTION ^

 =========================================================================
                               LTPDA GUI
 =========================================================================
 
  Open the main LTPDA GUI.

  $Id: ltpdagui.m,v 1.20 2008/08/16 03:33:40 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 main LTPDA GUI.
0008 %
0009 %  $Id: ltpdagui.m,v 1.20 2008/08/16 03:33:40 nicola Exp $
0010 
0011 warning off all
0012 global LTPDAinvar LTPDAoutvar active labels scaleX
0013 
0014 tabbedFigName = 'GUI Fawkes';
0015    screenSize = get(0,'screensize');
0016    scaleX     = screenSize(3)/1280;
0017    if scaleX<1, scaleX = 1; end
0018    setappdata(0, 'ltpda_gui_scalefactor',scaleX);
0019    guiSize = [1 1 800*scaleX 550*scaleX];
0020 guiSize = round([(screenSize(3)-guiSize(3))/2 , (screenSize(4)-guiSize(4))/2 , guiSize(3) , guiSize(4)]);
0021 
0022 if ~isempty(findobj('Name',tabbedFigName)) && nargin==0, return; end
0023 
0024 if isempty(LTPDAinvar),  LTPDAinvar  = {}; end
0025 if isempty(LTPDAoutvar), LTPDAoutvar = {}; end
0026 
0027 userID = getappdata(0,'ltpda_repo_user');
0028   if isempty(userID), userID = ''; end
0029 passwd = getappdata(0,'ltpda_repo_pass');
0030   if isempty(passwd), passwd = ''; end
0031   
0032 if nargin==0, [userID passwd] = loginLTPDA(userID,'',1,tabbedFigName,guiSize); try cd(getappdata(0,'DefaultDataDirectory')); catch end; end
0033   if isempty(userID), userID = 'JohnDoe'; passwd=''; end
0034 
0035 setappdata(0,'ltpda_repo_user',userID)
0036 setappdata(0,'ltpda_repo_pass',passwd)
0037 
0038 if nargin==0
0039     clc
0040     disp('Please wait: starting LTPDA GUI...')
0041     disp('Loading Simulink...')
0042     drawnow
0043     load_system('simulink')
0044     load_system('ltpda_library')
0045 end
0046 
0047 try stop(timerfindall); delete(timerfindall); catch end
0048 t1 = timer('TimerFcn',@CheckTimerAlive,'ExecutionMode','fixedRate','Period',0.3);
0049 t2 = timer('TimerFcn',@CheckTimerAlive,'ExecutionMode','fixedRate','Period',1);
0050 start(t1)
0051 start(t2)
0052 
0053 %%
0054 
0055 tag = '';
0056 units = 'normalized';
0057 position = [0,0,1,1];
0058 
0059 % text color in the label:
0060   foregroundcolor = [0.2,0.2,0.2];
0061 % color in the background, behind tabs:
0062   backgroundcolor = [0.7,0.7,1];
0063 % background color, inside every tab:
0064   panelbackgroundcolor = [0.98,0.98,0.98];
0065 % color of the small highlight line, above the selected tab
0066   titlehighlightcolor = [1,0.3,0];
0067 
0068 horizontalalignment = 'center';
0069 
0070 active = 0;
0071 string = {'Main LTPDA panel','Partial execution','Output';'Parameters','Nested loops','';'Repository','Import from workspace','Globals'};
0072    nrows = size(string,1);
0073    if nrows>1
0074        for nn=1:nrows, labels{nn} = string(nn,:); end
0075        string = string(1,:);
0076    end
0077    ntab = numel(string);
0078    for jj=ntab:-1:1, ntab = ntab - strcmp(string(jj),''); end
0079      
0080 % Cycle to retrieve parameters from the user:
0081   for mm=1:2:nargin
0082       property = lower(varargin{mm});
0083       value = varargin{mm+1};
0084       switch property
0085           case {'title','string'}
0086               string = value;
0087               nrows = size(string,1);
0088               if nrows>1
0089                   for nn=1:nrows, labels{nn} = string(nn,:);end
0090                   string = string(1,:);
0091               end
0092               ntab = numel(string);
0093               for jj=ntab:-1:1, ntab = ntab - strcmp(string(jj),''); end
0094           case {'frameposition','position'}
0095               position = value;
0096           case {'framebackgroundcolor','backgroundcolor'}
0097               backgroundcolor = value;
0098           case {'framebordertype','bordertype'}
0099               bordertype = value;
0100           case {'titleforegroundcolor','foregroundcolor'}
0101               foregroundcolor = value;
0102           case {'selecteditem','active'}
0103               active = value;
0104           case 'redraw'
0105               if value == 1 % main panel
0106                   TopBottomTabCbk([],[],1,1)
0107                   active = 1;
0108                   return
0109               end
0110               if value == 1.1 % the user clicked the Start button
0111                   TopBottomTabCbk([],[],1,1)
0112                   active = 1;
0113                   runSim = 1;
0114               end
0115               if value == 2 % Parameters panel
0116                   TopBottomTabCbk([],[],1,2)
0117                   active = 1;
0118                   return
0119               end
0120               if value == 6 % globals panel
0121                   TopBottomTabCbk([],[],3,3)
0122                   active = 1;
0123                   return
0124               end
0125           case 'callback'
0126               if value==1 && strcmp(bdroot,'ltpda_library')
0127                   HelpCallback();
0128                   return;
0129               end
0130               if value==1 && isempty(findobj('Name',tabbedFigName))
0131                   return;
0132               end
0133           otherwise
0134               eval([property '= ' value ';']);
0135       end
0136   end
0137 
0138 parent   = findobj('Name',tabbedFigName);
0139 if ~isempty(parent), clf(parent); set(parent,'Resize','on','ResizeFcn',{@GUIResize,guiSize});
0140 else parent = figure('Position',guiSize,'Name',tabbedFigName,'Resize','on','ResizeFcn',{@GUIResize,guiSize},'NumberTitle','off','Toolbar','none','Menubar','none');
0141 end
0142 
0143 set(parent,'Tag','LTPDAGUI','NextPlot','new');
0144 
0145 if ~exist('margins','var'), margins = {1,'pixels'}; end
0146 if ~iscell(margins), margins = {margins,units}; end
0147 if ~exist('bordertype','var'), bordertype = 'none'; end
0148 if ~exist('titlebackgroundcolor','var'), titlebackgroundcolor = 0.95*panelbackgroundcolor; end
0149 if ~active, active = 1; end
0150 
0151 clear htab
0152 htab = uipanel( ...
0153   'Parent',parent, ...
0154   'Units',units, ...
0155   'Position',position, ...
0156   'BackgroundColor',backgroundcolor, ...
0157   'BorderType',bordertype, ...
0158   'Visible','on', ...
0159   'Tag',tag);
0160 
0161   set(htab,'Units','pixels');
0162   tabpos = get(htab,'Position');
0163   
0164 
0165 status = uicontainer( ...
0166   'Parent',htab, ...
0167   'BackgroundColor',backgroundcolor, ...
0168   'Units',margins{2}, ...
0169   'Position',[1,1,1,1], ...
0170   'Visible','off');
0171 
0172   set(status,'Units','pixels');
0173   charsz = get(status,'Position');
0174 
0175 margins = [charsz(1:2),charsz(1:2)].*margins{1};
0176 set(status,'Units','characters');
0177 set(status,'Position',[1,1,1,1]);
0178 set(status,'Units','pixels');
0179 charsz = get(status,'Position');
0180 titleheight = 1.5*charsz(4);
0181 titleheight = titleheight*scaleX;
0182 
0183 margins(3:4) = -(margins(1:2)+margins(3:4));
0184 [loop,sign] = deal(1:ntab,[1,ntab,1,0]);
0185 
0186 addtitle = 2*[sign(3:4),-1,-1];
0187 ttextpos = [0.05,0.08,0.9,0.76];
0188     
0189   for kk=1:ntab
0190     title(kk) = uipanel( ...
0191       'Parent',htab, ...
0192       'Units','pixels', ...
0193       'BackgroundColor',titlebackgroundcolor, ...
0194       'BorderType','beveledout', ...
0195       'ButtonDownFcn',{@TopBottomTabCbk,kk,1}, ...
0196       'Visible','on');
0197 
0198     ttext(kk) = uicontrol( ...
0199       'Parent',title(kk), ...
0200       'Units','normalized', ...
0201       'Position',ttextpos, ...
0202       'ForegroundColor',foregroundcolor, ...
0203       'BackgroundColor',titlebackgroundcolor, ...
0204       'HorizontalAlignment',horizontalalignment, ...
0205       'Style','text', ...
0206       'String',string{kk}, ...
0207       'FontSize',8*scaleX,...
0208       'Enable','inactive', ...
0209       'HitTest','off',...
0210       'Visible','on');
0211 
0212   end
0213 
0214   set(htab,'Units','pixels');
0215   dimension = get(htab,'Position');
0216   dimension(4) = dimension(4)-nrows*titleheight+5;
0217   panel = uipanel('Parent',htab,'Units','pixels','Position',dimension,'BackgroundColor',panelbackgroundcolor,'BorderType','beveledout','Visible','on');
0218   
0219   dimension = get(htab,'Position');
0220   logosize = [52,52];
0221   dimension = [dimension(3)-logosize(1)-3 , dimension(4)-logosize(2) , logosize];
0222   logo = axes('Parent',htab,'Units','pixels','Position',dimension,'Tag','Logo');
0223   image(imread('iconltp.jpg'),'Parent',logo,'AlphaData',imread('iconltpalpha.gif'));
0224   axis(logo,'off'); axis(logo,'square');
0225   set(logo,'HandleVisibility','callback');
0226 
0227   dimension = get(htab,'Position');
0228   logosize = [40 40];
0229   dimension = [dimension(3)-logosize(1)-70 , dimension(4)-logosize(2)-9 , logosize];
0230   start2 = axes('Parent',htab,'Units','pixels','Position',dimension,'Tag','Start2');
0231   image(imread('startgreen.jpg'),'Parent',start2,'AlphaData',imread('startalpha.gif'),'ButtonDownFcn','ltpdagui(''redraw'',1.1);','Tag','StartButton');
0232   axis(start2,'off');
0233   set(start2,'HandleVisibility','callback');
0234   
0235   if active>ntab, active=ntab; end
0236   
0237   inset(1) = uicontrol( ...
0238     'Parent',htab, ...
0239     'Units','pixels', ...
0240     'BackgroundColor',panelbackgroundcolor, ...
0241     'Style','text', ...
0242     'Visible','on');
0243   if ~isnan(titlehighlightcolor)
0244     inset(2) = uicontrol( ...
0245       'Parent',htab, ...
0246       'Units','pixels', ...
0247       'BackgroundColor',titlehighlightcolor, ...
0248       'Style','text', ...
0249       'Visible','on');
0250     inset(3) = uicontrol( ...
0251       'Parent',htab, ...
0252       'Units','pixels', ...
0253       'BackgroundColor',0.85*titlehighlightcolor, ...
0254       'Style','text', ...
0255       'Visible','on');
0256   end
0257  
0258 % =======================================================================
0259 %                             OTHER BUTTONS
0260   for xx=2:nrows
0261       localString = labels{xx};
0262       ntab = numel(localString);
0263       for tt=1:ntab
0264         titles(xx,tt) = uipanel( ...
0265           'Parent',htab, ...
0266           'Units','pixels', ...
0267           'BackgroundColor',titlebackgroundcolor, ...
0268           'BorderType','beveledout', ...
0269           'ButtonDownFcn',{@TopBottomTabCbk,tt,xx}, ...
0270           'Visible','on');
0271 
0272         uicontrol( ...
0273           'Parent',titles(xx,tt), ...
0274           'Units','normalized', ...
0275           'Position',ttextpos, ...
0276           'ForegroundColor',foregroundcolor, ...
0277           'BackgroundColor',titlebackgroundcolor, ...
0278           'HorizontalAlignment',horizontalalignment, ...
0279           'Style','text', ...
0280           'String',localString{tt}, ...
0281           'Enable','inactive', ...
0282           'FontSize',8*scaleX,...
0283           'HitTest','off',...
0284           'Visible','on');
0285        
0286      end
0287   end
0288 % =======================================================================
0289 
0290   TopBottomTabResizeCbk();
0291 
0292 panelTitle = get(ttext(active),'string');
0293 setappdata(0, 'ltpda_currPanel', panel);
0294 
0295 % =======================================================================
0296 % =======================================================================
0297 % =======================================================================
0298 CheckTimerAlive()
0299 
0300    switch panelTitle
0301       case 'Main LTPDA panel'
0302          if exist('runSim','var') && runSim==1
0303             runSim = 0; %#ok<NASGU>
0304             pan1main(panel,1)
0305          else pan1main(panel)
0306          end
0307       case 'Output'
0308          pan5output(panel)
0309       case 'Parameters'
0310          pan2param(panel)
0311       case 'Nested loops'
0312          panXyettocome(panel)
0313        % pan3nested(panel)
0314       case 'Repository'
0315        % pan4repo(panel)
0316       case 'Import from workspace'
0317          pan4import(panel)
0318       case 'Globals'
0319          pan6globals(panel)
0320       case 'Partial execution'
0321          pan7partial(panel)
0322 
0323    end
0324 
0325 % =======================================================================
0326 % =======================================================================
0327 % =======================================================================
0328 
0329 
0330 %%
0331     %--------------------------------------------------------------------------
0332     function TopBottomTabCbk(hobj,evdt,indx,numbrow) %#ok<INUSL>
0333     % Executed when the user clicks on a another tab.
0334         
0335     if ~numbrow, return; end
0336         
0337     if numbrow>1 % the user clicked on another row
0338         for pp=ntab:-1:1, ntab = ntab - strcmp(string(pp),''); end
0339         if ntab==1, active=1; end
0340 
0341       % Swop rows:
0342         temp = labels(1);
0343         labels(1) = labels(numbrow);
0344         labels(numbrow) = temp;
0345         clear temp
0346       % Rebuild the proper list:
0347         for ii=1:nrows
0348             temp(ii,1:numel(labels{ii}))=labels{ii};
0349         end
0350     else
0351         active = indx;
0352         for ii=1:nrows
0353             temp(ii,1:numel(labels{ii}))=labels{ii};
0354         end
0355     end
0356     
0357   % ======================================
0358     ltpdagui('title',temp,'active',indx);
0359   % ======================================
0360 
0361     end
0362     %--------------------------------------------------------------------------
0363 
0364     %--------------------------------------------------------------------------
0365     function TopBottomTabResizeCbk(varargin)
0366     % Properly draws the panels.
0367 
0368     units = get(htab,'Units');
0369     set(htab,'Units','pixels');
0370     tabpos = get(htab,'Position');
0371     tabpos(3) = tabpos(3)*0.85;
0372     set(htab,'Units',units);
0373     ntab = numel(string);
0374     for oo=ntab:-1:1, ntab = ntab - strcmp(string(oo),''); end
0375 
0376     titlepos = [0,0,0,titleheight];
0377     panelpos = [0,0,tabpos(3),tabpos(4)-titleheight]+margins;
0378     titlepos(2) = panelpos(2)+panelpos(4);
0379     panelpos(2) = panelpos(2)-titleheight*(nrows-1)+6;
0380     
0381     n = sum(cellfun('length',string))+2*ntab;
0382     titlepos(1) = panelpos(1)+(1-sign(3))*panelpos(3);
0383     upperpos = titlepos(2);
0384     for k=loop
0385         titlepos(3) = panelpos(3)*(length(string{k})+2)/n;
0386         addtopos = addtitle.*[k==1,1,k==1|k==ntab,1];
0387         titlepos(1) = titlepos(1)-(1-sign(3))*titlepos(3);
0388         titlepos(2) = upperpos - titlepos(4)*(nrows-1)+3;
0389         set(title(k),'Position',titlepos+addtopos);
0390         titlepos(1) = titlepos(1)+sign(3)*titlepos(3);
0391     end
0392     
0393   % =======================================================================
0394 
0395     if nrows>1
0396         for xxx=2:nrows
0397             localString = labels{xxx};
0398             ntab = numel(localString);
0399             for i=ntab:-1:1, ntab = ntab - strcmp(localString(i),''); end
0400             n = sum(cellfun('length',localString))+2*ntab;
0401             titlepos(1) = panelpos(1)+(1-sign(3))*panelpos(3);
0402             titlepos(2) = titlepos(2) + titlepos(4)-2;
0403             for k=1:ntab
0404                 titlepos(3) = panelpos(3)*(length(localString{k})+2)/n;
0405                 addtopos = addtitle.*[k==1,1,k==1|k==ntab,1];
0406                 titlepos(1) = titlepos(1)-(1-sign(3))*titlepos(3);
0407                 if ntab==1, titlepos(3)=titlepos(3)-2; end
0408                 set(titles(xxx,k),'Position',titlepos+addtopos);
0409                 titlepos(1) = titlepos(1)+sign(3)*titlepos(3);
0410             end
0411             if ntab<numel(localString)
0412                 for qq=ntab+1:numel(localString)
0413                     nullpos=[0,0,1,1];
0414                     set(titles(xxx,qq),'Position',nullpos);
0415                 end
0416             end
0417         end
0418     end
0419   
0420   % =======================================================================
0421 
0422     titlepos = get(title(active),'Position');
0423     titlepos = titlepos-addtitle.*[active==sign(1),1,active==sign(1),1];
0424     titlepos(3) = titlepos(3)-addtitle(3)*(active==sign(2));
0425     ntab = numel(string);
0426     for i=ntab:-1:1, ntab = ntab - strcmp(string(i),''); end
0427     if ntab==1, titlepos(3) = titlepos(3)-4; end
0428     
0429     set(title(active),'Position',titlepos,'BackgroundColor',panelbackgroundcolor);
0430     set(ttext(active),'FontWeight','bold','BackgroundColor',panelbackgroundcolor);
0431 
0432     insetpos = [titlepos(1)+1,titlepos(2)+sign(4)*titlepos(4)-2,titlepos(3)-1,3];
0433     set(inset(1),'Position',insetpos);
0434     try
0435       insetpos = insetpos+[0,(1-2*sign(4))*titleheight+2*sign(4),0,-2];
0436       set(inset(2),'Position',insetpos);
0437       set(inset(3),'Position',insetpos+[2,1-2*sign(4),-4,0]);
0438     catch
0439     end
0440      end
0441     %--------------------------------------------------------------------------
0442 
0443     %--------------------------------------------------------------------------
0444     function GUIResize(varargin)
0445     % Called whenever the user resize the GUI window.
0446     
0447         guiSize = varargin{3};
0448         newSize = get(findobj('Tag','LTPDAGUI'),'Position');
0449         
0450       % To avoid a width lower than the fixed minimum:
0451         if newSize(3)<guiSize(3), newSize(3)=guiSize(3); end
0452       % To avoid an height lower than the fixed minimum:
0453         if newSize(4)<guiSize(4), newSize(4)=guiSize(4); end
0454       % To avoid a window moved outside the screen border:
0455         screenSize = get(0,'screensize');
0456         if newSize(2)+newSize(4)+30>screenSize(4), newSize(2)=screenSize(4)-newSize(4)-40; end
0457         if newSize(1)+newSize(3)>screenSize(3), newSize(1)=screenSize(3)-newSize(3)-5; end
0458        
0459         set(findobj('Tag','LTPDAGUI'),'Position',newSize);
0460         
0461       % Redraw the GUI on the current panel:
0462         TopBottomTabCbk([],[],active,0)
0463                 
0464     end
0465     %--------------------------------------------------------------------------
0466 
0467 %%
0468     %----------------------------------------------------------------------
0469     function CheckTimerAlive(varargin)   
0470         % This is the function to execute a continuous timer check
0471         
0472         % Keep alive the first timer:
0473           alltimers = timerfindall;
0474           if strcmp(get(alltimers(1),'Running'),'off')
0475               start(alltimers(1))
0476           end
0477     end
0478     %----------------------------------------------------------------------
0479     
0480     %----------------------------------------------------------------------
0481     function HelpCallback(varargin)
0482     % Whenever the user doubleclick a block in the library window (ie, the
0483     % OpeFcn callback is executed from the library).
0484     
0485          try
0486              childpath = find_system(gcbh,'LookUnderMasks','all','BlockType','M-S-Function');
0487              functionname = get_param(childpath,'Tag');
0488              
0489              description = get_param(gcbh,'Description');
0490              funcname = findstr('functionName=',description);
0491              if funcname
0492                  i = funcname+14;
0493                  while ~strcmp(description(i),';'), i=i+1; end
0494                  functionname = description(funcname+14:i-2);
0495              end
0496              
0497              [func,classes] = strtok(get(gcbh,'Tag'));
0498              if strcmp(func,'method')
0499                  helptext = help([strtrim(classes),'/',functionname]);
0500              else
0501                  helptext = help(functionname);
0502              end
0503              
0504              helpFigure    =   figure('MenuBar','none','Toolbar','none','Name',strcat(functionname,' help'),'NumberTitle','off','Units','pixels','Position',[200,200,500,300],'Resize','on','ResizeFcn','refresh(gcf)','Tag','helpwindow','Color', get(0, 'defaultuicontrolbackgroundcolor'));
0505            % Help text:
0506              uicontrol('Parent',helpFigure,'Units','normalized','HorizontalAlignment','left','Position',[0 0 1 1],'FontSize',8,'String',helptext,'Visible','on','max',100,'Style','edit');
0507          catch
0508          end
0509     end
0510     %----------------------------------------------------------------------
0511 
0512 end

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